/* =============================================================
   KESTRL — design system
   Identity: the common kestrel — warm paper + rufous (chestnut)
   accent + slate blue, cream light theme ("Kestrel Light") and
   a deep night theme ("Kestrel Night"). Toggled via
   html[data-theme="dark"], applied pre-paint by k_shell.php.
   ============================================================= */

/* ------------------------------------------------- tokens -- */
:root {
  --k-bg:        #f5f3ee;
  --k-surface:   #ffffff;
  --k-surface-2: #efece5;
  --k-ink:       #262a31;
  --k-ink-soft:  #5d6570;
  --k-ink-mute:  #6b7280;   /* ~5.2:1 on the cream, ~4.4 on tinted cards — carries 11px labels, th, tab text */
  --k-border:    #e5e1d8;
  --k-line:      #eceae3;

  --k-accent:      #b0532a;   /* kestrel rufous */
  --k-accent-hi:   #9a4823;
  --k-accent-soft: #f6e8e0;
  --k-slate:       #48657f;   /* kestrel slate-blue */
  --k-slate-soft:  #e7edf2;
  --k-gold:        #cf9a3a;
  --k-gold-soft:   #f7efdd;

  --k-ok:       #2e7d5b;
  --k-ok-soft:  #e3f1ea;
  --k-err:      #b3382c;
  --k-err-soft: #f7e6e3;
  --k-warn:     #a8721f;

  --k-dr:      var(--k-slate);
  --k-dr-soft: var(--k-slate-soft);
  --k-cr:      var(--k-accent);
  --k-cr-soft: var(--k-accent-soft);

  --k-radius:    14px;
  --k-radius-sm: 9px;
  --k-ease:      cubic-bezier(.22, .61, .36, 1);
  --k-shadow:    0 1px 2px rgba(38, 42, 49, .05), 0 6px 24px -12px rgba(38, 42, 49, .14);
  --k-shadow-lg: 0 4px 12px rgba(38, 42, 49, .07), 0 24px 60px -24px rgba(38, 42, 49, .25);

  --k-side-w: 236px;
  /* real measured height: 46px tab + 2×7px bar padding. Was 64px, left
     over from the taller icon+label tab. Only consumer is the sticky
     totals bar in journal_form_inc.php. */
  --k-tabbar-h:  60px;
  --k-spring:      cubic-bezier(.34, 1.40, .50, 1);   /* gentle overshoot */
  --k-spring-soft: cubic-bezier(.34, 1.20, .58, 1);
  color-scheme: light;
}

html[data-theme="dark"] {
  --k-bg:        #14171c;
  --k-surface:   #1c2128;
  --k-surface-2: #242b34;
  --k-ink:       #e7e5e0;
  --k-ink-soft:  #a8adb5;
  --k-ink-mute:  #8a919b;   /* lifted from #767d87 — keeps muted hierarchy but clears ~4.2:1 on tinted card fills */
  --k-border:    #2e3540;
  --k-line:      #272e38;

  --k-accent:      #e0855a;
  --k-accent-hi:   #e89468;
  --k-accent-soft: #33261f;
  --k-slate:       #82a7c9;
  --k-slate-soft:  #22303c;
  --k-gold:        #d9a441;
  --k-gold-soft:   #322a1a;

  --k-ok:       #4bc396;
  --k-ok-soft:  #1d3229;
  --k-err:      #e0857b;
  --k-err-soft: #3a2422;
  --k-warn:     #d9a441;

  --k-shadow:    0 1px 2px rgba(0, 0, 0, .35), 0 8px 28px -14px rgba(0, 0, 0, .6);
  --k-shadow-lg: 0 6px 16px rgba(0, 0, 0, .4), 0 28px 70px -28px rgba(0, 0, 0, .7);
  color-scheme: dark;
}

/* -------------------------------------------------- reset -- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--k-ink);
  background: var(--k-bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  text-size-adjust: 100%;
}
img, svg { display: block; max-width: 100%; }
a { color: var(--k-slate); text-decoration: none; }
a:hover { color: var(--k-accent); }
::selection { background: var(--k-accent-soft); color: var(--k-ink); }
:focus-visible { outline: 2px solid var(--k-slate); outline-offset: 2px; border-radius: 4px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--k-border); border-radius: 8px; border: 2px solid var(--k-bg); }
::-webkit-scrollbar-track { background: transparent; }

/* Theme crossfade (class added briefly by JS on toggle) */
html.k-theme-anim, html.k-theme-anim *, html.k-theme-anim *::before, html.k-theme-anim *::after {
  transition: background-color .3s var(--k-ease), border-color .3s var(--k-ease),
              color .3s var(--k-ease), fill .3s var(--k-ease), box-shadow .3s var(--k-ease) !important;
}

/* ---------------------------------------------- app shell -- */
.k-app { display: block; }

.k-side {
  position: fixed; inset: 0 auto 0 0;
  width: var(--k-side-w);
  background: var(--k-surface);
  border-right: 1px solid var(--k-border);
  display: flex; flex-direction: column;
  z-index: 50;
  transition: transform .32s var(--k-ease);
}
.k-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 18px 14px;
}
.k-brand-mark {
  width: 34px; height: 34px; flex: 0 0 auto;
  color: var(--k-accent);
}
.k-brand-name {
  font-size: 19px; font-weight: 750; letter-spacing: .16em;
  color: var(--k-ink);
}
.k-brand-sub {
  font-size: 10px; letter-spacing: .22em; text-transform: uppercase;
  color: var(--k-ink-mute); margin-top: -3px;
}

.k-nav { flex: 1; overflow-y: auto; padding: 6px 12px 12px; }
.k-nav-sec {
  font-size: 10.5px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
  color: var(--k-ink-mute);
  margin: 16px 8px 6px;
}
.k-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; margin: 1px 0;
  border-radius: var(--k-radius-sm);
  color: var(--k-ink-soft); font-weight: 550; font-size: 14px;
  position: relative;
  transition: background .18s var(--k-ease), color .18s var(--k-ease), transform .18s var(--k-ease);
}
.k-nav a svg { width: 15px; height: 15px; opacity: .8; flex: 0 0 auto; }
.k-nav a span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.k-nav a:hover { background: var(--k-surface-2); color: var(--k-ink); transform: translateX(2px); }
.k-nav a.is-active {
  background: var(--k-accent-soft); color: var(--k-accent);
}
.k-nav a.is-active::before {
  content: ""; position: absolute; left: -12px; top: 20%; bottom: 20%;
  width: 3px; border-radius: 0 3px 3px 0; background: var(--k-accent);
}

.k-side-foot {
  border-top: 1px solid var(--k-border);
  padding: 12px; display: flex; align-items: center; gap: 10px;
}
.k-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--k-slate-soft); color: var(--k-slate);
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700; flex: 0 0 auto;
}
.k-side-foot .k-who { flex: 1; min-width: 0; }
.k-side-foot .k-who b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.k-side-foot .k-who span { font-size: 11px; color: var(--k-ink-mute); text-transform: capitalize; }

.k-main { margin-left: var(--k-side-w); min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.k-top {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 28px;
  background: color-mix(in srgb, var(--k-bg) 82%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--k-line);
}
.k-top h1 { font-size: 19px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.k-top .k-top-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.k-content { padding: 24px 28px 60px; max-width: 1240px; width: 100%; margin: 0 auto; flex: 1; }

.k-burger { display: none; }
.k-scrim {
  position: fixed; inset: 0; z-index: 45;
  background: rgba(20, 23, 28, .45);
  opacity: 0; pointer-events: none;
  transition: opacity .3s var(--k-ease);
}

@media (max-width: 960px) {
  .k-side { transform: translateX(calc(-1 * var(--k-side-w) - 10px)); box-shadow: none; }
  html.k-side-open .k-side { transform: translateX(0); box-shadow: var(--k-shadow-lg); }
  html.k-side-open .k-scrim { opacity: 1; pointer-events: auto; }
  .k-main { margin-left: 0; }
  .k-top { padding: 12px 16px; }
  .k-content { padding: 18px 16px 48px; }
  .k-burger {
    display: grid; place-items: center;
    width: 36px; height: 36px; border: 1px solid var(--k-border);
    background: var(--k-surface); border-radius: 10px; cursor: pointer;
    color: var(--k-ink-soft);
  }
}

/* -------------------------------------------------- cards -- */
.k-card {
  background: var(--k-surface);
  border: 1px solid var(--k-border);
  border-radius: var(--k-radius);
  box-shadow: var(--k-shadow);
  padding: 20px;
}
.k-card + .k-card { margin-top: 16px; }
.k-card-title {
  font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--k-ink-mute); margin: 0 0 14px;
  display: flex; align-items: center; gap: 8px;
}
.k-card-title .spacer { margin-left: auto; }

.k-grid { display: grid; gap: 16px; }
.k-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.k-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.k-grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
/* Tuned so iPad-portrait (768px) still uses two columns where it reads
   well, and phones fall to a single column. */
@media (max-width: 1100px) { .k-grid.cols-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 1000px) { .k-grid.cols-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 760px)  { .k-grid.cols-2 { grid-template-columns: 1fr; } }
@media (max-width: 640px)  { .k-grid.cols-3 { grid-template-columns: 1fr; } }
@media (max-width: 560px)  { .k-grid.cols-4 { grid-template-columns: 1fr; } }

/* ------------------------------------------------ buttons -- */
.k-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  font: inherit; font-size: 14px; font-weight: 620;
  cursor: pointer; user-select: none;
  background: var(--k-accent); color: #fff;
  transition: background .18s var(--k-ease), transform .14s var(--k-ease),
              box-shadow .18s var(--k-ease), border-color .18s var(--k-ease), color .18s var(--k-ease);
}
.k-btn svg { width: 14px; height: 14px; }
.k-btn:hover { background: var(--k-accent-hi); transform: translateY(-1px); box-shadow: var(--k-shadow); color: #fff; }
.k-btn:active { transform: translateY(0) scale(.98); }
.k-btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

/* ---- busy ------------------------------------------------- *
 * Saving used to mean the button faded to .55 and then nothing
 * happened for the length of a round trip, which on a phone on
 * mobile data is long enough to press again. K.busy(btn) swaps
 * the label for a spinner and keeps the button's width, so the
 * layout never jumps. Label text is preserved for screen
 * readers via aria-label on the button itself. */
.k-btn.is-busy { position: relative; color: transparent !important; pointer-events: none; }
.k-btn.is-busy > * { visibility: hidden; }
.k-btn.is-busy::after {
  content: ""; position: absolute; top: 50%; left: 50%;
  width: 15px; height: 15px; margin: -7.5px 0 0 -7.5px;
  border: 2px solid currentColor; border-radius: 50%;
  border-top-color: transparent;
  color: #fff;
  animation: k-spin .62s linear infinite;
}
/* ghost/soft buttons paint their spinner in the accent, not white */
.k-btn.ghost.is-busy::after,
.k-btn.soft.is-busy::after,
.k-btn.danger-soft.is-busy::after { color: var(--k-accent); }
@keyframes k-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  /* a rotating ring is exactly the kind of thing this setting is for —
     keep the affordance, drop the rotation */
  .k-btn.is-busy::after {
    animation: none; border-top-color: currentColor; opacity: .5;
  }
}

.k-btn.ghost {
  background: var(--k-surface); color: var(--k-ink-soft);
  border-color: var(--k-border);
}
.k-btn.ghost:hover { color: var(--k-ink); border-color: var(--k-ink-mute); background: var(--k-surface); }
.k-btn.soft { background: var(--k-accent-soft); color: var(--k-accent); }
.k-btn.soft:hover { background: var(--k-accent-soft); color: var(--k-accent-hi); }
.k-btn.danger { background: var(--k-err); color: #fff; }
.k-btn.danger:hover { background: color-mix(in srgb, var(--k-err) 85%, #000); }
.k-btn.danger-soft { background: var(--k-err-soft); color: var(--k-err); }
.k-btn.sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.k-btn.icon { padding: 8px; }

.k-iconbtn {
  display: grid; place-items: center; width: 36px; height: 36px;
  border-radius: 10px; border: 1px solid var(--k-border);
  background: var(--k-surface); color: var(--k-ink-soft); cursor: pointer;
  transition: color .18s, border-color .18s, transform .14s var(--k-ease);
}
.k-iconbtn:hover { color: var(--k-ink); border-color: var(--k-ink-mute); transform: translateY(-1px); }
.k-iconbtn svg { width: 15px; height: 15px; }

/* -------------------------------------------------- forms -- */
.k-field { display: flex; flex-direction: column; gap: 6px; }
.k-label { font-size: 12.5px; font-weight: 650; color: var(--k-ink-soft); }
.k-input, .k-select, .k-textarea {
  width: 100%;
  padding: 9px 12px;
  font: inherit; font-size: 14px;
  color: var(--k-ink);
  background: var(--k-surface);
  border: 1px solid var(--k-border);
  border-radius: 10px;
  transition: border-color .18s var(--k-ease), box-shadow .18s var(--k-ease);
}
.k-textarea { resize: vertical; min-height: 70px; }
.k-input:hover, .k-select:hover, .k-textarea:hover { border-color: var(--k-ink-mute); }
.k-input:focus, .k-select:focus, .k-textarea:focus {
  outline: none;
  border-color: var(--k-slate);
  box-shadow: 0 0 0 3px var(--k-slate-soft);
}
.k-input.amount { text-align: right; font-variant-numeric: tabular-nums; }
.k-input.is-bad { border-color: var(--k-err); box-shadow: 0 0 0 3px var(--k-err-soft); }
.k-help { font-size: 12px; color: var(--k-ink-mute); }
.k-form-row { display: flex; gap: 14px; flex-wrap: wrap; }
.k-form-row > * { flex: 1; min-width: 160px; }

/* segmented control */
.k-seg {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--k-surface-2);
  border: 1px solid var(--k-border);
  border-radius: 10px;
}
.k-seg button, .k-seg a {
  border: 0; background: transparent; cursor: pointer;
  padding: 6px 12px; border-radius: 8px;
  font: inherit; font-size: 13px; font-weight: 620; color: var(--k-ink-soft);
  transition: background .18s var(--k-ease), color .18s var(--k-ease), box-shadow .18s var(--k-ease);
}
.k-seg .is-on { background: var(--k-surface); color: var(--k-ink); box-shadow: var(--k-shadow); }
.k-seg .is-on.dr { color: var(--k-dr); }
.k-seg .is-on.cr { color: var(--k-cr); }

/* ------------------------------------------------- tables -- */
.k-table-wrap { overflow-x: auto; border-radius: var(--k-radius-sm); }
.k-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.k-table th {
  text-align: left; font-size: 11.5px; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--k-ink-mute);
  padding: 8px 12px;
  border-bottom: 1px solid var(--k-border);
  white-space: nowrap;
}
.k-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--k-line);
  vertical-align: middle;
}
.k-table tbody tr { transition: background .15s var(--k-ease); }
.k-table tbody tr:hover { background: var(--k-surface-2); }
.k-table tbody tr:last-child td { border-bottom: 0; }
.k-table .num, .k-amount { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.k-table tr.k-row-link { cursor: pointer; }
.k-table tfoot td {
  border-top: 2px solid var(--k-border); border-bottom: 0;
  font-weight: 700; padding-top: 10px;
}
.k-table .subtle { color: var(--k-ink-mute); font-size: 12.5px; }

/* -------------------------------------------------- chips -- */
.k-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700; letter-spacing: .04em;
  background: var(--k-surface-2); color: var(--k-ink-soft);
  white-space: nowrap;
}
.k-chip.dr { background: var(--k-dr-soft); color: var(--k-dr); }
.k-chip.cr { background: var(--k-cr-soft); color: var(--k-cr); }
.k-chip.ok { background: var(--k-ok-soft); color: var(--k-ok); }
.k-chip.err { background: var(--k-err-soft); color: var(--k-err); }
.k-chip.gold { background: var(--k-gold-soft); color: var(--k-warn); }
.k-chip.slate { background: var(--k-slate-soft); color: var(--k-slate); }

/* --------------------------------------------- stat tiles -- */
.k-stat {
  background: var(--k-surface);
  border: 1px solid var(--k-border);
  border-radius: var(--k-radius);
  box-shadow: var(--k-shadow);
  padding: 18px 20px;
  position: relative; overflow: hidden;
}
/* The tone rail is what colour-codes a tile — rufous for spend, slate
   for neutral, green for surplus. It used to be revealed on :hover,
   which meant it never appeared at all on a touch device, where most
   of these tiles are actually read. It is always on now; hover only
   thickens it, and only where hover really exists. */
.k-stat::after {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: var(--k-accent); opacity: 1;
  transition: height .25s var(--k-ease), opacity .25s var(--k-ease);
}
@media (hover: hover) {
  .k-stat:hover::after { height: 5px; }
}
.k-stat.slate::after { background: var(--k-slate); }
.k-stat.ok::after { background: var(--k-ok); }
.k-stat.err::after { background: var(--k-err); }
.k-stat-label {
  font-size: 11.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--k-ink-mute);
}
.k-stat-value {
  font-size: 26px; font-weight: 750; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  margin-top: 6px; color: var(--k-ink);
}
.k-stat-sub { font-size: 12.5px; color: var(--k-ink-mute); margin-top: 4px; }
.k-stat-sub b.up { color: var(--k-ok); }
.k-stat-sub b.down { color: var(--k-err); }

/* ------------------------------------------------- toasts -- */
.k-toasts {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
.k-toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 10px;
  background: var(--k-ink); color: var(--k-bg);
  padding: 10px 18px; border-radius: 12px;
  font-size: 14px; font-weight: 550;
  box-shadow: var(--k-shadow-lg);
  animation: k-toast-in .35s var(--k-ease);
}
.k-toast.err { background: var(--k-err); color: #fff; }
.k-toast.is-out { animation: k-toast-out .3s var(--k-ease) forwards; }
@keyframes k-toast-in { from { opacity: 0; transform: translateY(14px) scale(.96); } }
@keyframes k-toast-out { to { opacity: 0; transform: translateY(10px) scale(.96); } }

/* -------------------------------------------------- modal -- */
.k-modal-backdrop {
  position: fixed; inset: 0; z-index: 150;
  background: rgba(20, 23, 28, .5);
  backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 20px;
  opacity: 0; pointer-events: none;
  transition: opacity .25s var(--k-ease);
}
.k-modal-backdrop.is-open { opacity: 1; pointer-events: auto; }
.k-modal {
  width: 100%; max-width: 460px;
  background: var(--k-surface);
  border: 1px solid var(--k-border);
  border-radius: var(--k-radius);
  box-shadow: var(--k-shadow-lg);
  padding: 22px;
  transform: translateY(12px) scale(.97);
  transition: transform .28s var(--k-ease);
  max-height: 90vh; overflow-y: auto;
}
.k-modal-backdrop.is-open .k-modal { transform: none; }
.k-modal h3 { margin: 0 0 6px; font-size: 17px; }
.k-modal .k-modal-sub { color: var(--k-ink-mute); font-size: 13.5px; margin: 0 0 16px; }
.k-modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* -------------------------------------------- empty state -- */
.k-empty {
  text-align: center; padding: 44px 20px; color: var(--k-ink-mute);
}
.k-empty svg { width: 36px; height: 36px; margin: 0 auto 12px; opacity: .5; }
.k-empty b { display: block; color: var(--k-ink-soft); font-size: 15px; margin-bottom: 4px; }
.k-empty p { margin: 0 0 14px; font-size: 13.5px; }

/* ---------------------------------------------- skeletons -- */
.k-skel {
  position: relative; overflow: hidden;
  background: var(--k-surface-2); border-radius: 8px;
}
.k-skel::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--k-surface) 70%, transparent), transparent);
  transform: translateX(-100%);
  animation: k-shimmer 1.4s infinite;
}
@keyframes k-shimmer { to { transform: translateX(100%); } }

/* --------------------------------------------- animations -- */
.k-up {
  opacity: 0; transform: translateY(14px);
  animation: k-up .55s var(--k-ease) forwards;
  animation-delay: calc(var(--i, 0) * 60ms);
}
@keyframes k-up { to { opacity: 1; transform: none; } }

.k-in {
  opacity: 0;
  animation: k-in .5s var(--k-ease) forwards;
  animation-delay: calc(var(--i, 0) * 60ms);
}
@keyframes k-in { to { opacity: 1; } }

/* bar charts (pure CSS bars inside .k-bars) */
.k-bars { display: flex; align-items: flex-end; gap: 6px; height: 150px; }
.k-bars .bar {
  flex: 1; min-width: 6px; border-radius: 5px 5px 2px 2px;
  background: var(--k-slate);
  transform-origin: bottom;
  transform: scaleY(0);
  transition: transform .7s var(--k-ease), opacity .2s;
  transition-delay: calc(var(--i, 0) * 45ms);
}
.k-bars .bar.alt { background: var(--k-accent); }
.k-bars.is-in .bar { transform: scaleY(1); }
.k-bars .bar:hover { opacity: .8; }

/* donut (SVG circle with pathLength=100) */
.k-donut-seg {
  fill: none; stroke-width: 3.6; stroke-linecap: butt;
  stroke-dasharray: 0 100;
  transition: stroke-dasharray .9s var(--k-ease);
  transition-delay: calc(var(--i, 0) * 120ms);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-delay: 0ms !important;
    transition-duration: .01ms !important;
    /* transition-delay was missing here, so anything staggered with a
       delay (donut segments, reveals, nav rows) still trickled in over
       a second even for someone who asked for no motion. */
    transition-delay: 0ms !important;
  }
  .k-up, .k-in { opacity: 1; transform: none; }
  .k-bars .bar { transform: scaleY(1); }
}

/* ------------------------------------------------ helpers -- */
.k-flex { display: flex; align-items: center; gap: 10px; }
.k-flex .spacer { margin-left: auto; }
.k-muted { color: var(--k-ink-mute); }
.k-soft { color: var(--k-ink-soft); }
.k-small { font-size: 12.5px; }
.k-right { text-align: right; }
.k-center { text-align: center; }
.k-mono { font-variant-numeric: tabular-nums; }
.k-pos { color: var(--k-ok); }
.k-neg { color: var(--k-err); }
.k-mt { margin-top: 16px; }
.k-mb { margin-bottom: 16px; }
.k-hide { display: none !important; }
.k-page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.k-page-head .spacer { margin-left: auto; }

/* ------------------------------------------------- print --- */
@media print {
  .k-side, .k-top, .k-burger, .k-scrim, .k-noprint { display: none !important; }
  .k-main { margin: 0; }
  .k-content { max-width: none; padding: 0; }
  body { background: #fff; }
  .k-card, .k-stat { box-shadow: none; border-color: #ddd; break-inside: avoid; }
  .k-up, .k-in { opacity: 1; transform: none; animation: none; }
  .k-bars .bar { transform: scaleY(1); }
}

/* =============================================================
   MOBILE · TOUCH · MOTION   (responsive pass — 2026)
   Bottom tab bar, card-reflow tables, touch sizing, the iOS
   focus-zoom fix, safe-area insets, cross-page View Transitions
   and springy press micro-interactions. The Kestrel identity and
   palette above are untouched; this only adds adaptive behaviour.
   ============================================================= */

/* ---- iOS: 16px controls stop focus-zoom on phones ---------- */
@media (max-width: 700px) {
  .k-input, .k-select, .k-textarea { font-size: 16px; }
}

/* ---- comfortable hit areas on touch devices --------------- */
@media (hover: none) and (pointer: coarse) {
  .k-iconbtn { width: 42px; height: 42px; }
  .k-btn.sm  { padding: 9px 15px; }
  .k-seg button, .k-seg a { padding: 9px 14px; }
  .k-nav a { padding: 11px 12px; }
  .k-table tbody tr:hover { background: transparent; }   /* no stuck hover */

  /* Small always-visible controls keep their drawn size but gain an
     invisible 40px hit slop, so a thumb can't miss (or worse, hit the
     neighbouring delete). Opt in by adding .k-tap to the control. */
  .k-tap { position: relative; }
  .k-tap::after {
    content: ""; position: absolute; left: 50%; top: 50%;
    width: 40px; height: 40px; transform: translate(-50%, -50%);
  }
  .ks-file-x { width: 30px; height: 30px; position: relative; }
  .ks-file-x::after {
    content: ""; position: absolute; left: 50%; top: 50%;
    width: 42px; height: 42px; transform: translate(-50%, -50%);
  }
}

/* ---- full-height sidebar that survives the mobile URL bar -- */
@supports (height: 100dvh) { .k-side { height: 100dvh; } }

/* ---- safe-area insets (notch / home indicator) ------------ */
/* viewport-fit=cover + black-translucent status bar means the page
   paints under the clock/battery when installed to the home screen,
   so the sticky header and the drawer must inset from the top too. */
.k-side { padding-left: env(safe-area-inset-left); padding-top: env(safe-area-inset-top); }
.k-top  { padding-left:  max(28px, env(safe-area-inset-left));
          padding-right: max(28px, env(safe-area-inset-right));
          padding-top:   calc(14px + env(safe-area-inset-top)); }
@media (max-width: 960px) {
  .k-top { padding-left:  max(16px, env(safe-area-inset-left));
           padding-right: max(16px, env(safe-area-inset-right));
           padding-top:   calc(12px + env(safe-area-inset-top)); }
}

/* ---- segmented controls: never clip; scroll if too wide --- */
@media (max-width: 640px) {
  .k-seg {
    display: flex; width: 100%;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none; scroll-snap-type: x proximity;
  }
  .k-seg::-webkit-scrollbar { display: none; }
  .k-seg button, .k-seg a {
    flex: 1 0 auto; white-space: nowrap; text-align: center;
    scroll-snap-align: center;
  }
}

/* =============================================================
   Card-reflow tables:  <table class="k-table k-cards"> with a
   data-label on each <td>.  At <=640px each row becomes a
   tappable card, the thead is visually hidden, and each cell
   prints its label.  A cell marked .cell-head spans the full
   width as the card's title; naturally-empty cells drop out.
   ============================================================= */
@media (max-width: 640px) {
  .k-table.k-cards { display: block; font-size: 14.5px; }
  .k-table.k-cards thead {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
  }
  .k-table.k-cards tbody, .k-table.k-cards tfoot { display: block; }
  .k-table.k-cards tr {
    /* column flex (not block) purely so .cell-head can be pulled to the
       top with `order`: pages put the title cell 2nd or 3rd to keep the
       desktop column order sensible, and a card's title must lead. */
    display: flex; flex-direction: column; position: relative;
    background: var(--k-surface);
    border: 1px solid var(--k-border);
    border-radius: var(--k-radius-sm);
    box-shadow: var(--k-shadow);
    padding: 13px 15px; margin-bottom: 10px;
    animation: k-card-in .4s var(--k-ease) both;
  }
  /* stagger the first screenful of cards; the rest arrive together */
  .k-table.k-cards tbody tr:nth-child(2) { animation-delay: 45ms; }
  .k-table.k-cards tbody tr:nth-child(3) { animation-delay: 90ms; }
  .k-table.k-cards tbody tr:nth-child(4) { animation-delay: 135ms; }
  .k-table.k-cards tbody tr:nth-child(5) { animation-delay: 180ms; }
  .k-table.k-cards tbody tr:nth-child(6) { animation-delay: 225ms; }
  .k-table.k-cards tbody tr:nth-child(n+7) { animation-delay: 260ms; }
  .k-table.k-cards td {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 7px 0; border: 0; text-align: right; white-space: normal; min-height: 0;
  }
  .k-table.k-cards td + td { border-top: 1px dashed var(--k-line); }
  .k-table.k-cards td::before {
    content: attr(data-label);
    flex: 0 0 auto; text-align: left;
    font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
    color: var(--k-ink-mute);
  }
  .k-table.k-cards td:empty { display: none; }
  /* title cell: full-width, prominent, no label, no divider */
  .k-table.k-cards td.cell-head {
    display: block; text-align: left; padding: 0 0 9px; border: 0;
    font-size: 15.5px; font-weight: 650;
    order: -1;
  }
  .k-table.k-cards td.cell-head::before { display: none; }
  .k-table.k-cards td.cell-head + td { border-top: 0; }
  .k-table.k-cards td.num, .k-table.k-cards td.k-amount { font-variant-numeric: tabular-nums; }
  /* tappable rows feel like cards */
  .k-table.k-cards tr.k-row-link { cursor: pointer;
    transition: transform .18s var(--k-spring), box-shadow .2s var(--k-ease); }
  .k-table.k-cards tr.k-row-link:active { transform: scale(.985); box-shadow: var(--k-shadow-lg); }
  /* footer reads as a summary card */
  .k-table.k-cards tfoot tr { background: var(--k-surface-2); }
  .k-table.k-cards tfoot td { font-weight: 700; }
  .k-table.k-cards tfoot td[colspan]::before { content: ""; }
}
@keyframes k-card-in { from { opacity: 0; transform: translateY(8px); } }

/* =============================================================
   Bottom tab bar (phones only).  Rendered by k_shell.php; the
   centre "New" is an elevated FAB.  The drawer stays reachable
   through the "More" tab for the full menu.
   ============================================================= */
.k-tabbar { display: none; }
@media (max-width: 680px) {
  .k-tabbar {
    display: flex; align-items: center; justify-content: space-around; gap: 2px;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 44;
    padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--k-surface) 86%, transparent);
    backdrop-filter: saturate(1.3) blur(16px);
    border-top: 1px solid var(--k-border);
  }
  .k-tab {
    flex: 1 1 0; min-width: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    padding: 5px 2px; min-height: 50px;
    background: none; border: 0; cursor: pointer; text-decoration: none;
    color: var(--k-ink-mute); font: inherit; font-size: 10.5px; font-weight: 650;
    transition: color .2s var(--k-ease), transform .25s var(--k-spring);
    -webkit-tap-highlight-color: transparent;
  }
  .k-tab span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .k-tab.is-active { color: var(--k-accent); }
  .k-tab:active { transform: scale(.88); }
  .k-tab-new { flex: 0 0 auto; padding: 0; }
  .k-tab-new .fab {
    width: 54px; height: 54px; margin-top: -20px; border-radius: 50%;
    display: grid; place-items: center;
    background: linear-gradient(140deg, var(--k-accent), var(--k-accent-hi));
    color: #fff; border: 3px solid var(--k-bg);
    box-shadow: 0 10px 22px -8px color-mix(in srgb, var(--k-accent) 75%, transparent);
    transition: transform .3s var(--k-spring), box-shadow .3s var(--k-ease);
  }
  .k-tab-new:active .fab { transform: scale(.9); }

  .k-content { padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
  .k-toasts  { bottom: calc(82px + env(safe-area-inset-bottom)); }
  .k-burger  { display: none; }               /* "More" replaces the top burger */
  html.k-side-open .k-side  { z-index: 70; }   /* drawer above the tab bar */
  html.k-side-open .k-scrim { z-index: 65; }
}

/* ---- springy press micro-interactions (playful) ----------- */
.k-btn, .k-iconbtn, .kd-tile, a.sd-card, .k-seg button, .k-seg a,
.k-tab, .kbs-row { -webkit-tap-highlight-color: transparent; }
.k-btn:active { transform: translateY(0) scale(.96); }
@media (hover: hover) { .k-btn:hover { transform: translateY(-1.5px); } }

/* tap ripple (added by kestrl.js on .k-btn / .k-tab / tiles) */
.k-ripple {
  position: absolute; border-radius: 50%; transform: scale(0);
  background: currentColor; opacity: .22; pointer-events: none;
  animation: k-ripple .55s var(--k-ease) forwards;
}
@keyframes k-ripple { to { transform: scale(2.6); opacity: 0; } }

/* ---- cross-page View Transitions (this is a multi-page app) - */
@view-transition { navigation: auto; }
::view-transition-old(root) { animation: k-vt-out .24s var(--k-ease) both; }
::view-transition-new(root) { animation: k-vt-in  .34s var(--k-ease) both; }
@keyframes k-vt-out { to   { opacity: 0; transform: translateY(-8px) scale(.994); } }
@keyframes k-vt-in  { from { opacity: 0; transform: translateY(10px) scale(.994); } }
/* keep the persistent chrome pinned instead of cross-fading with the page */
.k-top { view-transition-name: k-top; }
@media (min-width: 961px) { .k-side   { view-transition-name: k-side; } }
@media (max-width: 680px) { .k-tabbar { view-transition-name: k-tabbar; } }

/* ---- richer entrance for hero blocks (rise + settle) ------- */
.k-rise {
  opacity: 0; transform: translateY(18px) scale(.99);
  animation: k-rise .6s var(--k-spring-soft) forwards;
  animation-delay: calc(var(--i, 0) * 70ms);
}
@keyframes k-rise { to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  /* .k-tab svg used to be listed here; the nav is text-only now, and
     the active-tab pill is what moves in its place. */
  .k-tab, .k-tab::before, .k-tab-new .fab, .k-btn,
  .k-table.k-cards tr, .k-ripple { transition: none !important; animation: none !important; }
  ::view-transition-old(root), ::view-transition-new(root) { animation: none !important; }
  .k-rise { opacity: 1; transform: none; animation: none; }
}

/* the tab bar must never show in print */
@media print { .k-tabbar { display: none !important; } }

/* ---- phones: nothing may clip off the right edge ------------ */
/* grid children default to min-width:auto, which stops them
   shrinking below their content — so inner overflow-x scrollers
   (heatmaps, wide charts) never get to scroll and the card just
   pokes off-screen. Let them shrink. */
.k-grid > * { min-width: 0; }

/* card-title rows (icon + chips + trailing link) wrap instead of
   pushing the link past the clipped page edge */
@media (max-width: 640px) {
  .k-card-title { flex-wrap: wrap; row-gap: 6px; }
}

/* top bar on small phones: the page title truncates and icon'd
   action buttons drop their text (icon-only) so nothing clips */
@media (max-width: 560px) {
  .k-top h1 { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .k-top-actions { flex: 0 0 auto; }
  .k-top-actions .k-btn:has(svg) > span { display: none; }
  .k-top-actions .k-btn:has(svg) { padding: 8px 10px; }
}

/* =============================================================
   DOCUMENTS · SCAN · OCR   (ks-* — shared by k_scan.js and every
   page that attaches files: the library, vouchers, staff entry,
   vehicle papers. Same identity, new furniture.)
   ============================================================= */

html.ks-noscroll, html.ks-noscroll body { overflow: hidden; }

/* ---------------------------------------------- camera UI --- */
.ks-cam {
  position: fixed; inset: 0; z-index: 300;
  background: #0c0e11;
  display: flex; flex-direction: column;
  opacity: 0; transition: opacity .22s var(--k-ease);
}
.ks-cam.is-in { opacity: 1; }
.ks-cam.is-out { opacity: 0; }
.ks-cam-video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover;
}
.ks-cam-video.is-mirror { transform: scaleX(-1); }
.ks-cam-frame { position: absolute; inset: 0; pointer-events: none; }
.ks-cam-frame i {
  position: absolute; width: 34px; height: 34px;
  border: 3px solid rgba(255, 255, 255, .85); border-radius: 2px;
  animation: ks-frame-breathe 2.6s ease-in-out infinite;
}
.ks-cam-frame i:nth-child(1) { top: 12%; left: 8%;  border-right: 0; border-bottom: 0; border-top-left-radius: 10px; }
.ks-cam-frame i:nth-child(2) { top: 12%; right: 8%; border-left: 0;  border-bottom: 0; border-top-right-radius: 10px; }
.ks-cam-frame i:nth-child(3) { bottom: 22%; left: 8%;  border-right: 0; border-top: 0; border-bottom-left-radius: 10px; }
.ks-cam-frame i:nth-child(4) { bottom: 22%; right: 8%; border-left: 0;  border-top: 0; border-bottom-right-radius: 10px; }
@keyframes ks-frame-breathe { 50% { opacity: .55; } }
.ks-cam-hint {
  position: absolute; top: max(18px, env(safe-area-inset-top)); left: 0; right: 0;
  text-align: center; color: rgba(255, 255, 255, .8);
  font-size: 13px; font-weight: 600; letter-spacing: .04em;
  text-shadow: 0 1px 6px rgba(0, 0, 0, .5);
}
.ks-cam-flash {
  position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none;
}
.ks-cam-flash.is-on { animation: ks-flash .32s var(--k-ease); }
@keyframes ks-flash { 12% { opacity: .9; } 100% { opacity: 0; } }
.ks-cam-bar {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; justify-content: space-around;
  padding: 22px 30px calc(26px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0, 0, 0, .55));
}
.ks-cam-btn {
  width: 48px; height: 48px; border-radius: 50%;
  border: 0; cursor: pointer;
  background: rgba(255, 255, 255, .16); color: #fff;
  display: grid; place-items: center;
  backdrop-filter: blur(6px);
  transition: transform .2s var(--k-spring), background .2s;
}
.ks-cam-btn:active { transform: scale(.88); }
.ks-cam-btn svg { width: 21px; height: 21px; }
.ks-cam-shutter {
  width: 74px; height: 74px; border-radius: 50%;
  border: 4px solid #fff; background: transparent; cursor: pointer;
  display: grid; place-items: center; padding: 0;
  transition: transform .22s var(--k-spring);
}
.ks-cam-shutter span {
  width: 56px; height: 56px; border-radius: 50%; background: #fff;
  transition: transform .18s var(--k-spring), background .18s;
}
.ks-cam-shutter:active { transform: scale(.94); }
.ks-cam-shutter:active span { transform: scale(.82); background: var(--k-accent); }

/* ----------------------------------------------- lightbox --- */
.ks-lb {
  position: fixed; inset: 0; z-index: 280;
  background: rgba(12, 14, 17, .82);
  backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity .22s var(--k-ease);
}
.ks-lb.is-in { opacity: 1; }
.ks-lb-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 2;
  display: flex; align-items: center; gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  background: linear-gradient(rgba(0, 0, 0, .45), transparent);
}
.ks-lb-meta { min-width: 0; flex: 1; color: #fff; }
.ks-lb-meta b { display: block; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ks-lb-meta span { font-size: 12px; opacity: .75; }
.ks-lb-acts { display: flex; gap: 8px; }
.ks-lb .k-iconbtn {
  background: rgba(255, 255, 255, .14); border-color: transparent; color: #fff;
  backdrop-filter: blur(6px);
}
.ks-lb .k-iconbtn:hover { background: rgba(255, 255, 255, .26); color: #fff; transform: none; }
.ks-lb-stage {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  padding: 58px 14px calc(30px + env(safe-area-inset-bottom));
}
.ks-lb-stage.ks-anim > * { animation: ks-lb-swap .28s var(--k-ease); }
@keyframes ks-lb-swap { from { opacity: 0; transform: scale(.96); } }
.ks-lb-img {
  max-width: 100%; max-height: 100%;
  border-radius: 10px;
  box-shadow: 0 24px 80px -20px rgba(0, 0, 0, .8);
  transition: transform .18s var(--k-ease);
  cursor: zoom-in; user-select: none; touch-action: none;
  animation: ks-lb-in .3s var(--k-ease);
}
.ks-lb-img.is-zoomed { cursor: grab; transition: none; }
@keyframes ks-lb-in { from { opacity: 0; transform: scale(.94) translateY(10px); } }
.ks-lb-frame {
  width: min(960px, 100%); height: 100%;
  border: 0; border-radius: 12px; background: #fff;
  box-shadow: 0 24px 80px -20px rgba(0, 0, 0, .8);
  animation: ks-lb-in .3s var(--k-ease);
}
.ks-lb-nofile {
  background: var(--k-surface); border-radius: var(--k-radius);
  padding: 36px 44px; text-align: center; color: var(--k-ink);
  box-shadow: var(--k-shadow-lg);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  animation: ks-lb-in .3s var(--k-ease);
}
.ks-lb-noicon {
  width: 74px; height: 88px; border-radius: 10px;
  background: var(--k-surface-2); border: 1px solid var(--k-border);
  display: grid; place-items: center;
  font-weight: 800; font-size: 15px; letter-spacing: .04em; color: var(--k-ink-soft);
  text-transform: uppercase; margin-bottom: 6px; position: relative; overflow: hidden;
}
.ks-lb-noicon::before {
  content: ""; position: absolute; top: 0; right: 0;
  border: 11px solid var(--k-border);
  border-left-color: transparent; border-bottom-color: transparent;
}
.ks-lb-nofile p { margin: 0 0 10px; color: var(--k-ink-mute); font-size: 13px; }
.ks-lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 2;
  width: 46px; height: 46px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(255, 255, 255, .12); color: #fff;
  display: grid; place-items: center; backdrop-filter: blur(6px);
  transition: background .2s, transform .2s var(--k-spring);
}
.ks-lb-nav:hover { background: rgba(255, 255, 255, .26); }
.ks-lb-nav:active { transform: translateY(-50%) scale(.86); }
.ks-lb-nav svg { width: 22px; height: 22px; }
.ks-lb-nav.prev { left: 14px; }
.ks-lb-nav.next { right: 14px; }
@media (max-width: 640px) { .ks-lb-nav { display: none; } }   /* swipe instead */
.ks-lb-count {
  position: absolute; bottom: calc(12px + env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, .8); font-size: 12.5px; font-weight: 650;
  font-variant-numeric: tabular-nums;
}

/* ----------------------------------------------- dropzone --- */
.ks-drop {
  border: 1.5px dashed var(--k-border);
  border-radius: var(--k-radius);
  background: color-mix(in srgb, var(--k-surface-2) 55%, transparent);
  padding: 26px 18px;
  text-align: center; cursor: pointer;
  transition: border-color .2s var(--k-ease), background .2s var(--k-ease),
              transform .25s var(--k-spring), box-shadow .2s var(--k-ease);
}
.ks-drop:hover { border-color: var(--k-ink-mute); background: var(--k-surface-2); }
.ks-drop.is-drag {
  border-color: var(--k-accent); background: var(--k-accent-soft);
  transform: scale(1.012);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--k-accent) 14%, transparent);
}
.ks-drop-ic {
  width: 46px; height: 46px; margin: 0 auto 10px; border-radius: 14px;
  background: var(--k-surface); border: 1px solid var(--k-border);
  display: grid; place-items: center; color: var(--k-accent);
  box-shadow: var(--k-shadow);
  transition: transform .25s var(--k-spring);
}
.ks-drop:hover .ks-drop-ic { transform: translateY(-2px) rotate(-3deg); }
.ks-drop.is-drag .ks-drop-ic { transform: translateY(-3px) scale(1.08); }
.ks-drop-ic svg { width: 22px; height: 22px; }
.ks-drop b { display: block; font-size: 14px; }
.ks-drop b u { color: var(--k-slate); text-decoration-style: dotted; text-underline-offset: 3px; }
.ks-drop p { margin: 3px 0 0; font-size: 12px; color: var(--k-ink-mute); }

/* --------------------------------------- upload progress ---- */
.ks-ups { display: flex; flex-direction: column; gap: 8px; }
.ks-ups:not(:empty) { margin-top: 12px; }
.ks-up {
  display: flex; align-items: center; gap: 11px;
  background: var(--k-surface); border: 1px solid var(--k-border);
  border-radius: var(--k-radius-sm);
  padding: 9px 12px;
  animation: k-up .35s var(--k-ease);
  position: relative; overflow: hidden;
}
.ks-up::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0;
  width: calc(var(--pct, 0) * 1%);
  background: color-mix(in srgb, var(--k-accent) 9%, transparent);
  transition: width .25s var(--k-ease);
}
.ks-up.is-done::before { background: color-mix(in srgb, var(--k-ok) 10%, transparent); width: 100%; }
.ks-up.is-err::before { background: color-mix(in srgb, var(--k-err) 10%, transparent); width: 100%; }
.ks-up > * { position: relative; }
.ks-up-ic {
  width: 34px; height: 34px; flex: none; border-radius: 9px;
  display: grid; place-items: center;
  background: var(--k-surface-2); color: var(--k-ink-soft);
}
.ks-up-ic svg { width: 17px; height: 17px; }
.ks-up.is-done .ks-up-ic { background: var(--k-ok-soft); color: var(--k-ok); animation: ks-pop .4s var(--k-spring); }
.ks-up.is-err .ks-up-ic { background: var(--k-err-soft); color: var(--k-err); }
@keyframes ks-pop { 45% { transform: scale(1.22); } }
.ks-up-name { flex: 1; min-width: 0; font-size: 13px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ks-up-name span { display: block; font-weight: 500; font-size: 11.5px; color: var(--k-ink-mute); }
.ks-up-pct { font-size: 12px; font-weight: 700; color: var(--k-ink-soft); font-variant-numeric: tabular-nums; }

/* --------------------------- attachment strip (vouchers) ---- */
.ks-files { display: flex; flex-wrap: wrap; gap: 9px; }
.ks-files:not(:empty) { margin-top: 12px; }
.ks-file {
  display: flex; align-items: center; gap: 9px;
  background: var(--k-surface); border: 1px solid var(--k-border);
  border-radius: 11px; padding: 6px 9px 6px 6px;
  max-width: 240px; cursor: pointer;
  transition: transform .2s var(--k-spring), box-shadow .2s var(--k-ease), border-color .2s;
  animation: k-up .35s var(--k-ease);
}
.ks-file:hover { transform: translateY(-2px); box-shadow: var(--k-shadow); border-color: var(--k-ink-mute); }
.ks-file-th {
  width: 40px; height: 40px; flex: none; border-radius: 8px;
  background: var(--k-surface-2); color: var(--k-ink-soft);
  display: grid; place-items: center; overflow: hidden;
  font-size: 9.5px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase;
}
.ks-file-th img { width: 100%; height: 100%; object-fit: cover; }
.ks-file-th svg { width: 19px; height: 19px; }
.ks-file-name { min-width: 0; font-size: 12.5px; font-weight: 600; line-height: 1.25;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ks-file-name span { display: block; font-weight: 500; font-size: 11px; color: var(--k-ink-mute); }
.ks-file-x {
  width: 24px; height: 24px; flex: none; border: 0; border-radius: 50%;
  background: transparent; color: var(--k-ink-mute); cursor: pointer;
  display: grid; place-items: center;
  transition: background .15s, color .15s, transform .2s var(--k-spring);
}
.ks-file-x:hover { background: var(--k-err-soft); color: var(--k-err); transform: scale(1.1); }
.ks-file-x svg { width: 13px; height: 13px; }

/* OCR reading state + the little "found it" fill flash */
.ks-ocr {
  display: flex; align-items: center; gap: 12px;
  background: var(--k-slate-soft);
  border: 1px solid color-mix(in srgb, var(--k-slate) 25%, transparent);
  border-radius: var(--k-radius-sm);
  padding: 10px 14px; margin-top: 12px;
  animation: k-up .3s var(--k-ease);
}
.ks-ocr-eye {
  width: 34px; height: 34px; flex: none; border-radius: 9px; overflow: hidden;
  background: var(--k-surface); display: grid; place-items: center; position: relative;
  color: var(--k-slate);
}
.ks-ocr-eye svg { width: 18px; height: 18px; }
.ks-ocr-eye::after {
  content: ""; position: absolute; left: 8%; right: 8%; height: 2px;
  background: var(--k-accent); border-radius: 2px;
  box-shadow: 0 0 8px var(--k-accent);
  animation: ks-scanline 1.4s ease-in-out infinite;
}
@keyframes ks-scanline { 0%, 100% { top: 18%; } 50% { top: 78%; } }
.ks-ocr-msg { flex: 1; min-width: 0; font-size: 13px; font-weight: 600; color: var(--k-slate); }
.ks-ocr-msg span { display: block; font-weight: 500; font-size: 11.5px; color: var(--k-ink-mute); }
.ks-ocr-bar { height: 4px; border-radius: 99px; background: var(--k-surface); overflow: hidden; margin-top: 5px; }
.ks-ocr-bar i { display: block; height: 100%; width: 0; border-radius: 99px;
  background: linear-gradient(90deg, var(--k-slate), var(--k-accent));
  transition: width .3s var(--k-ease); }
.ks-filled {
  animation: ks-filled .9s var(--k-ease);
  border-radius: 10px;
}
@keyframes ks-filled {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--k-ok) 45%, transparent); background: var(--k-ok-soft); }
  100% { box-shadow: 0 0 0 9px transparent; }
}

/* paperclip count badge on list rows */
.ks-clip {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 11px; font-weight: 700; color: var(--k-ink-mute);
  background: var(--k-surface-2); border-radius: 999px; padding: 1px 7px;
  vertical-align: 1px;
}
.ks-clip svg { width: 11px; height: 11px; }

@media (prefers-reduced-motion: reduce) {
  .ks-cam, .ks-lb, .ks-lb-img, .ks-lb-frame, .ks-lb-nofile,
  .ks-drop, .ks-drop-ic, .ks-up, .ks-file, .ks-ocr, .ks-filled,
  .ks-cam-frame i, .ks-ocr-eye::after { animation: none !important; transition: none !important; }
}

/* ============================================================
   PET-TRAIN — clip recorder + video playback (ks-*)
   ============================================================ */
.ks-lb-video { max-width: min(92vw, 1040px); max-height: 80vh; border-radius: 12px; background: #000;
  box-shadow: 0 18px 60px rgba(0, 0, 0, .5); outline: none; }
.ks-cam-shutter span { transition: transform .2s ease, border-radius .2s, background .2s; }
.ks-cam-shutter.is-rec span { border-radius: 7px; transform: scale(.55); background: #ff5147; }
.ks-rec-bar { position: absolute; left: 0; right: 0; top: 0; height: 4px;
  background: rgba(255, 255, 255, .16); z-index: 2; }
.ks-rec-bar i { display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, #ff5147, #ffb199); transition: width .12s linear; }
.ks-rec-timer { position: absolute; top: calc(16px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 14px; border-radius: 999px;
  background: rgba(20, 16, 14, .66); color: #fff; font-size: .82rem; font-weight: 700;
  font-variant-numeric: tabular-nums; letter-spacing: .04em; backdrop-filter: blur(6px); z-index: 2; }
.ks-rec-timer i { width: 9px; height: 9px; border-radius: 50%; background: #ff5147; opacity: .35; }
.ks-cam.is-rec .ks-rec-timer i { opacity: 1; animation: ks-rec-blink 1s steps(2, start) infinite; }
@keyframes ks-rec-blink { 50% { opacity: .25; } }
.ks-rec-review { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: #0d0a09; z-index: 3; }
.ks-rec-review video { max-width: 100%; max-height: 100%; }
.ks-rec-actions { position: absolute; bottom: calc(30px + env(safe-area-inset-bottom)); left: 0; right: 0;
  display: flex; gap: 12px; justify-content: center; }
.ks-rec-btn { padding: 12px 24px; border-radius: 999px; border: 0; font: inherit; font-size: .92rem;
  font-weight: 750; cursor: pointer; transition: transform .18s ease; }
.ks-rec-btn:active { transform: scale(.94); }
.ks-rec-btn.use { background: linear-gradient(135deg, #ff8a5c, #ff5147); color: #fff; }
.ks-rec-btn.retake { background: rgba(255, 255, 255, .14); color: #fff; }
@media (prefers-reduced-motion: reduce) {
  .ks-rec-bar i, .ks-cam-shutter span, .ks-rec-btn { transition: none !important; }
  .ks-cam.is-rec .ks-rec-timer i { animation: none !important; }
}
