/* UI_MIGRATION_PLAN.md F4 — the 6 primitives every NEW_UI screen is
   composed from (plan §2/§7.1: "section card / list row / labeled field /
   chip / accent panel / page shell"). NEW_UI/KlearScreen.dc.html has no
   CSS classes at all — every screen there uses one-off inline styles via
   a prototyping DSL — so these class names and the radius/spacing scale
   below are this migration's own codification of the repeated inline
   patterns found there, not a 1:1 lift. Preview all of these live at
   /_styleguide/ (DEBUG only). Page shell itself is in 05-layout.css. */

/* ---- 0. Button ---------------------------------------------------------
   Not one of the plan's 6 named primitives, but every screen needs one —
   added ad hoc (Phase 1) the moment a real form needed it. Radius/height
   match .k-field so a button under a field lines up visually. */

.k-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  height: 52px;
  border-radius: 14px;
  border: 1px solid var(--k-line);
  background: var(--k-surface);
  color: var(--k-ink);
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  text-decoration: none;
  cursor: pointer;
  box-sizing: border-box;
}

/* Icon-only button sized to sit beside a .k-field control (the expense
   form's add-a-category "+"), matching the 52px control height so the two
   line up on their baseline rather than the label above them. */
.k-btn--square {
  width: 52px;
  flex: none;
  padding: 0;
}

.k-btn:hover {
  border-color: var(--k-accentLine);
  /* Restated so the bare a:hover in 03-base.css can't repaint it. */
  color: var(--k-ink);
}

.k-btn--primary {
  background: var(--k-primary);
  color: var(--k-onPrimary);
  border-color: var(--k-primary);
}

.k-btn--primary:hover {
  opacity: 0.92;
  color: var(--k-onPrimary);
}

.k-btn--dashed {
  border-style: dashed;
}

/* "You haven't finished the form yet" — dimmed, but still clickable on
   purpose. A disabled button swallows the click and explains nothing; this
   one submits, gets cancelled by the page's submit guard, and the guard
   then says exactly what's missing. */
.k-btn--incomplete {
  opacity: 0.55;
}

/* Provider buttons. Colours are dictated by each provider's branding
   guidelines, so they're literals rather than tokens and deliberately do
   NOT follow the Klear palette — but they keep .k-btn's height/radius so
   they line up with everything else in the stack.
   Google: https://developers.google.com/identity/branding-guidelines
   LINE:   https://developers.line.biz/en/docs/line-login/login-button/ */

.k-btn--google {
  background: #ffffff;
  border-color: #747775;
  color: #1f1f1f;
}

.k-btn--google:hover {
  background: #f7f8f8;
  border-color: #747775;
  color: #1f1f1f;
}

/* Google's dark-theme button spec. Matched to the resolved colour scheme
   the same way 01-tokens.css does it, so it tracks the theme switch. */
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] .k-btn--google,
  :root:not([data-theme]) .k-btn--google {
    background: #131314;
    border-color: #8e918f;
    color: #e3e3e3;
  }
  :root[data-theme="auto"] .k-btn--google:hover,
  :root:not([data-theme]) .k-btn--google:hover {
    background: #1e1f20;
    color: #e3e3e3;
  }
}

:root[data-theme="dark"] .k-btn--google {
  background: #131314;
  border-color: #8e918f;
  color: #e3e3e3;
}

:root[data-theme="dark"] .k-btn--google:hover {
  background: #1e1f20;
  color: #e3e3e3;
}

:root[data-theme="light"] .k-btn--google {
  background: #ffffff;
  border-color: #747775;
  color: #1f1f1f;
}

/* LINE green is the same in both themes — the guidelines give one base
   colour plus a darker pressed state, and no dark-mode variant. */
.k-btn--line {
  background: #06c755;
  border-color: #06c755;
  color: #ffffff;
}

.k-btn--line:hover {
  background: #05b54c;
  border-color: #05b54c;
  color: #ffffff;
}

.k-btn--line:active {
  background: #04a544;
  border-color: #04a544;
  color: #ffffff;
}

/* ---- 1. Card --------------------------------------------------------- */

.k-card {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  padding: 1rem;
  border-radius: 18px;
  background: var(--k-surface);
  border: 1px solid var(--k-line);
}

.k-card--lg {
  border-radius: 20px;
}

.k-card--accent {
  border-color: var(--k-accentLine);
}

.k-card--dashed {
  border-style: dashed;
  background: var(--k-bg);
  border-radius: 14px;
}

.k-card--muted {
  background: transparent;
  opacity: 0.75;
}

.k-card--muted:hover {
  opacity: 1;
}

.k-card--clickable {
  cursor: pointer;
}

.k-card--clickable:hover {
  border-color: var(--k-accent);
}

/* ---- 2. Row -----------------------------------------------------------
   .k-row is a divider row inside a .k-card (e.g. a member list); .k-row--card
   is a standalone row that's its own card (e.g. an expense list item). */

.k-row {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--k-line);
}

.k-row:last-child {
  border-bottom: none;
}

.k-row--card {
  padding: 0.75rem 0.8125rem;
  border-radius: 16px;
  background: var(--k-surface);
  border: 1px solid var(--k-line);
  cursor: pointer;
}

.k-row--card:hover {
  border-color: var(--k-accentLine);
}

.k-row--selected {
  background: var(--k-accentSoft);
  border-color: var(--k-accentLine);
}

/* A member nested under their settlement group on the trip dashboard. The
   rail is what carries the nesting — indentation alone reads as a stray
   margin once a row wraps onto two lines, which Thai display names do. */
.k-row--sub {
  padding-left: 1.375rem;
  margin-left: 0.5rem;
  border-left: 2px solid var(--k-line);
}

.k-row--group {
  background: var(--k-accentSoft);
  border-radius: 12px;
  padding-left: 0.625rem;
  padding-right: 0.625rem;
  border-bottom: none;
}

.k-row--dashed {
  border: 1px dashed var(--k-line);
  border-radius: 16px;
  color: var(--k-soft);
  cursor: pointer;
}

.k-row--dashed:hover {
  opacity: 0.75;
}

/* A .k-row that is itself a <button> (e.g. each friend in the add-member
   picker, where the whole row submits its own form). Resets the button
   chrome that would otherwise fight the row layout. */
.k-row--button {
  width: 100%;
  background: none;
  border: none;
  border-bottom: 1px solid var(--k-line);
  font: inherit;
  color: inherit;
  cursor: pointer;
  text-align: left;
}

.k-row--button:hover {
  color: inherit;
}

form:last-child .k-row--button {
  border-bottom: none;
}

.k-row__avatar {
  width: 2.125rem;
  height: 2.125rem;
  flex: none;
  border-radius: 999px;
  background: var(--k-accentSoft);
  color: var(--k-accent);
  font-size: 0.875rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.k-row__icon-btn {
  flex: none;
  width: 1.875rem;
  height: 1.875rem;
  border-radius: 10px;
  border: 1px solid var(--k-line);
  color: var(--k-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: none;
}

.k-row__icon-btn:hover {
  color: var(--k-accent);
  border-color: var(--k-accentLine);
}

/* Active/pressed state for a toggle icon button (the favourite star). */
.k-row__icon-btn--on {
  color: var(--k-cat3);
  border-color: var(--k-cat3);
}

.k-row__icon-btn--on:hover {
  color: var(--k-cat3);
  border-color: var(--k-cat3);
  opacity: 0.8;
}

/* ---- 3. Field ---------------------------------------------------------- */

.k-field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.k-field__label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--k-soft);
}

.k-field input,
.k-field select,
.k-field textarea {
  height: 52px;
  border-radius: 14px;
  border: 1px solid var(--k-line);
  background: var(--k-field);
  color: var(--k-ink);
  padding: 0 0.9375rem;
  font-size: 1rem;
  font-family: inherit;
  box-sizing: border-box;
  width: 100%;
}

.k-field textarea {
  height: auto;
  min-height: 6rem;
  padding: 0.75rem 0.9375rem;
}

.k-field input:focus,
.k-field select:focus,
.k-field textarea:focus {
  outline: 2px solid var(--k-accent);
  outline-offset: 1px;
}

/* Set by the sign-up page's submit guard. Uses aria-invalid rather than a
   class so the visual state and the accessibility state can't drift apart. */
.k-field input[aria-invalid="true"] {
  border-color: var(--k-warn);
}

.k-field--accent input {
  border-color: var(--k-accentLine);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.k-field--compact input {
  height: 46px;
  border-radius: 13px;
  padding: 0 0.75rem;
}

/* ---- 4. Chip -----------------------------------------------------------
   Pill-shaped status/role/filter labels. Base is the neutral outline
   variant; add a modifier for accent/warn/owner/dashed. See the {% chip %}
   inclusion tag (apps/accounts/templatetags/ui_components.py) for the
   templated version of this. */

.k-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  flex: none;
  padding: 0.3rem 0.625rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
  border: 1px solid var(--k-line);
  color: var(--k-soft);
  background: transparent;
}

.k-chip--accent {
  background: var(--k-accentSoft);
  color: var(--k-accent);
  border-color: transparent;
}

.k-chip--warn {
  background: var(--k-warnSoft);
  color: var(--k-warn);
  border-color: transparent;
}

.k-chip--owner {
  background: var(--k-ownerBg);
  color: var(--k-ownerFg);
  border-color: transparent;
}

/* Amber, for the private-expense padlock. Deliberately not --k-warn (which is
   the red used for "you owe" and for errors): private isn't a problem, it's a
   state worth noticing. Its own token pair so light and dark both stay
   legible against --k-surface. */
.k-chip--private {
  background: var(--k-privateBg);
  color: var(--k-privateFg);
  border-color: transparent;
}

.k-chip--outline-accent {
  background: transparent;
  color: var(--k-accent);
  border-color: var(--k-accentLine);
}

/* An applied-filter chip with its own clear-this-one ×. Extra right padding
   is unnecessary — .k-chip is already a flex row with a gap, so the × just
   becomes its second child. */
.k-chip--removable {
  padding-right: 0.375rem;
}

.k-chip__remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.125rem;
  height: 1.125rem;
  flex: none;
  border-radius: 999px;
  color: inherit;
  text-decoration: none;
  opacity: 0.7;
}

.k-chip__remove:hover {
  /* Restates colour: 03-base.css's a:hover sets --k-ink, which on an accent
     chip would swap the label colour out from under the chip. */
  color: inherit;
  opacity: 1;
  background: color-mix(in srgb, currentColor 18%, transparent);
}

/* Django renders a CheckboxSelectMultiple as a bare <ul> of <li><label>, which
   looks nothing like the rest of the app's controls. Styling it here rather
   than overriding the widget's template keeps it to CSS — and it's what
   partials/form_field.html wraps a multi-checkbox field in. */
.k-checklist ul,
.k-checklist {
  list-style: none;
  margin: 0;
  padding: 0;
}

.k-checklist li {
  border-bottom: 1px solid var(--k-line);
}

.k-checklist li:last-child {
  border-bottom: none;
}

.k-checklist label {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.6875rem 0.25rem;
  cursor: pointer;
}

.k-checklist input[type="checkbox"] {
  flex: none;
  /* The .k-field wrapper this list sits in styles its inputs as full-width
     52px text boxes, and a checkbox inherits every bit of that — it rendered
     as a huge rounded square filling the row. `flex: none` stops it growing
     in the flex row but says nothing about width or height, so those have to
     be stated. The attribute selector out-specifies `.k-field input`. */
  width: 1.125rem;
  height: 1.125rem;
  min-width: 1.125rem;
  padding: 0;
  border-radius: 0.25rem;
  accent-color: var(--k-primary);
}

/* Select-all sits above the list, separated from it rather than reading as
   the first person in it. */
.k-checklist__all {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 0.25rem;
  border-bottom: 1px solid var(--k-line);
  cursor: pointer;
  font-weight: 700;
  font-size: 0.8125rem;
}

.k-checklist__all input[type="checkbox"] {
  flex: none;
  width: 1.125rem;
  height: 1.125rem;
  min-width: 1.125rem;
  padding: 0;
  border-radius: 0.25rem;
  accent-color: var(--k-primary);
}

/* Row-label size, for chips that annotate a row rather than being its
   content — the members roster stacks these under the display name, where
   the default 0.75rem/700 competes with the name itself for attention. */
.k-chip--xs {
  padding: 0.1rem 0.4rem;
  font-size: 0.625rem;
  letter-spacing: 0.02em;
}

.k-chip--dashed {
  border-style: dashed;
  cursor: pointer;
}

.k-chip--dashed:hover {
  color: var(--k-ink);
  border-color: var(--k-ink);
}

/* Chips are often <a> (the expense-list category filters), so each coloured
   variant has to hold its colour on hover — see the note in 03-base.css. */
a.k-chip:hover {
  color: var(--k-soft);
}

a.k-chip--accent:hover {
  color: var(--k-accent);
}

a.k-chip--warn:hover {
  color: var(--k-warn);
}

a.k-chip--owner:hover {
  color: var(--k-ownerFg);
}

a.k-chip--outline-accent:hover {
  color: var(--k-accent);
}

/* ---- 5. Panel ----------------------------------------------------------
   Accent-tinted informational callout. */

.k-panel {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.9375rem;
  border-radius: 18px;
  background: var(--k-accentSoft);
  border: 1px solid var(--k-accentLine);
}

.k-panel--row {
  flex-direction: row;
  align-items: center;
}

.k-panel--dashed {
  border-style: dashed;
  border-radius: 14px;
}

.k-panel--dashed:hover {
  border-style: solid;
}

.k-panel__eyebrow {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--k-accent);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ---- 6. Tab bar / FAB ---------------------------------------------------
   Page shell furniture that pairs with .k-app (05-layout.css). Wired up
   in Phase 3.5 via templates/partials/tabbar.html across the 4 trip
   screens (Trip/Expenses/Members/Settle). position:sticky (rather than
   restructuring every page into the full flex-column-with-scrollable-
   middle shell from the design source) keeps this a small, low-risk
   change on top of already-shipped pages. */

.k-tabbar {
  /* Not sticky — it's the fixed last row of the .k-app flex column
     (05-layout.css), which is how the design builds it and what keeps it
     stable while the iOS URL bar collapses. */
  flex: none;
  display: flex;
  align-items: flex-start;
  gap: 2px;
  padding: 0.5625rem 0.75rem calc(env(safe-area-inset-bottom, 0px) + 0.75rem);
  background: var(--k-surface);
  border-top: 1px solid var(--k-line);
}

.k-tabbar__slot {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  color: var(--k-soft);
  cursor: pointer;
  text-decoration: none;
}

.k-tabbar__slot:hover {
  color: var(--k-ink);
}

.k-tabbar__slot--active,
.k-tabbar__slot--active:hover {
  /* :hover restated so the active tab keeps its accent when the pointer is
     over it, instead of falling through to .k-tabbar__slot:hover. */
  color: var(--k-accent);
}

.k-tabbar__slot span {
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.k-tabbar__fab-slot {
  flex: none;
  width: 56px;
  display: flex;
  justify-content: center;
}

.k-fab {
  width: 48px;
  height: 48px;
  margin-top: -16px;
  border-radius: 999px;
  background: var(--k-primary);
  color: var(--k-onPrimary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  text-decoration: none;
}

.k-fab:hover {
  opacity: 0.92;
  color: var(--k-onPrimary);
}

/* The Klear mark inside the FAB (26px per the design, L696). */
.k-fab__mark {
  width: 26px;
  height: 26px;
  object-fit: contain;
  display: block;
}

/* ---------------------------------------------------------------------------
   Scanning state (§9.2) — the Klear mark with a ring turning around it while
   Gemini reads a receipt. Built from the FAB's own vocabulary (same 48px
   primary disc, same mark) so it reads as the app thinking rather than as a
   generic spinner dropped in.

   The ring is a bordered circle with three sides transparent, which is the
   cheapest honest spinner there is: no SVG, no JS, no extra request. Sized
   larger than the disc so it orbits rather than overlaps.
   --------------------------------------------------------------------------- */
.k-scanning {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.875rem;
  padding: 2.25rem 1rem;
  text-align: center;
}

.k-scanning__badge {
  position: relative;
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
}

.k-scanning__disc {
  width: 48px;
  height: 48px;
  border-radius: 999px;
  background: var(--k-primary);
  display: grid;
  place-items: center;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}

.k-scanning__disc img {
  width: 26px;
  height: 26px;
  object-fit: contain;
  display: block;
}

.k-scanning__ring {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  border: 3px solid var(--k-line);
  border-top-color: var(--k-primary);
  animation: k-spin 0.9s linear infinite;
}

@keyframes k-spin {
  to { transform: rotate(360deg); }
}

/* Vestibular disorders make continuous rotation genuinely unpleasant, and the
   ring carries no information a pulse can't — it only has to say "working". */
@media (prefers-reduced-motion: reduce) {
  .k-scanning__ring {
    animation: k-pulse 1.6s ease-in-out infinite;
    border-color: var(--k-primary);
    opacity: 0.35;
  }
  @keyframes k-pulse {
    50% { opacity: 0.9; }
  }
}

.k-fab--disabled {
  background: var(--k-line);
  color: var(--k-soft);
  box-shadow: none;
  cursor: default;
}

/* ---- 7. Icon -----------------------------------------------------------
   One sprite symbol (templates/partials/icons.html) rendered by the
   {% icon %} tag. Colour always comes from the parent via currentColor. */

.k-icon {
  flex: none;
  display: block;
  color: inherit;
}

/* ---- 8. Section header -------------------------------------------------
   The uppercase letter-spaced eyebrow above every list in the design
   (L350-L353, L832, L1030), optionally with a count on the right. */

.k-section {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.625rem;
  padding-top: 0.25rem;
}

.k-section__label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--k-soft);
}

.k-section__count {
  font-size: 0.75rem;
  color: var(--k-soft);
}

/* ---- 9. Avatar ---------------------------------------------------------
   Colour comes from --k-av-bg/--k-av-fg, set per member by the
   {% avatar %} tag (deterministic from TripMember.pk so nobody changes
   colour between screens). --self and --shadow are the two fixed
   exceptions from the design (L317/L1156 and L1192). */

/* A photo fills the circle its initial would otherwise sit in — same element,
   same size rules, so nothing shifts between the two states. object-fit
   because the stored image is square but the circle may not be exactly its
   pixel size at every call site. */
.k-avatar__img {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  object-fit: cover;
  display: block;
}

.k-avatar {
  flex: none;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.625rem;
  height: 1.625rem;
  border-radius: 999px;
  background: var(--k-av-bg, var(--k-line));
  color: var(--k-av-fg, var(--k-soft));
  font-size: 0.6875rem;
  font-weight: 700;
  line-height: 1;
}

.k-avatar--sm {
  width: 1.375rem;
  height: 1.375rem;
  font-size: 0.5625rem;
}

.k-avatar--lg {
  width: 3.125rem;
  height: 3.125rem;
  font-size: 1.1875rem;
}

.k-avatar--self {
  background: var(--k-accentSoft);
  color: var(--k-accent);
}

.k-avatar--shadow {
  background: transparent;
  color: var(--k-soft);
  border: 1px dashed var(--k-line);
}

/* Overlapping stack. The surface-coloured ring is what makes the overlap
   read as depth rather than as a rendering glitch — don't drop it.
   (The prototype also has `gap:-6px` at L364; that's invalid CSS and does
   nothing — the real overlap is this negative margin.) */
.k-avatars {
  display: flex;
  align-items: center;
  flex: none;
}

.k-avatars .k-avatar + .k-avatar {
  margin-left: -7px;
  border: 2px solid var(--k-surface);
}

/* ---- 10. Meter ---------------------------------------------------------
   The thin progress/proportion bar (L51-L55, L546-L549). --segments is the
   multi-colour variant on the landing card; the plain one takes a single
   fill whose width is set inline. */

.k-meter {
  display: flex;
  gap: 0.375rem;
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--k-line);
}

.k-meter--segments {
  background: none;
  margin-top: 2px;
}

.k-meter > span {
  border-radius: 999px;
  display: block;
}

.k-meter__fill {
  background: var(--k-accent);
  border-radius: 999px;
}

/* ---- 11. Numbered step -------------------------------------------------
   The three how-it-works rows on the landing screen (L63-L83). */

.k-step {
  display: flex;
  gap: 0.8125rem;
  align-items: flex-start;
}

.k-step__num {
  flex: none;
  width: 2rem;
  height: 2rem;
  border-radius: 10px;
  background: var(--k-accentSoft);
  color: var(--k-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
}

/* ---- 11b. Logo ---------------------------------------------------------
   partials/logo.html renders both variants; these rules pick one. The
   selector logic mirrors 01-tokens.css exactly (OS preference unless
   data-theme overrides it) so the mark can never contradict the palette. */

.k-logo {
  display: inline-flex;
  align-items: center;
  flex: none;
}

.k-logo__img {
  height: var(--k-logo-h, 34px);
  width: auto;
  display: block;
}

/* Default (light): show the navy mark. */
.k-logo__img--dark {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] .k-logo__img--light,
  :root:not([data-theme]) .k-logo__img--light {
    display: none;
  }
  :root[data-theme="auto"] .k-logo__img--dark,
  :root:not([data-theme]) .k-logo__img--dark {
    display: block;
  }
}

:root[data-theme="dark"] .k-logo__img--light {
  display: none;
}

:root[data-theme="dark"] .k-logo__img--dark {
  display: block;
}

:root[data-theme="light"] .k-logo__img--light {
  display: block;
}

:root[data-theme="light"] .k-logo__img--dark {
  display: none;
}

/* ---- 12. Selection action bar ------------------------------------------
   The contextual "N selected · Export · Delete" bar on the expenses list
   (NEW_UI L1090-L1104). Sticky to the bottom of .k-scroll, not fixed to
   the viewport — the tab bar already owns the viewport's last row. */

.k-actionbar {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding: 0.75rem 0.875rem;
  border-radius: 16px;
  background: var(--k-surface);
  border: 1px solid var(--k-accentLine);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}

/* ---- 12b. Two-position sliding toggle ----------------------------------
   Used by the language switch. The moving pill is a ::before on the track,
   translated by the --b modifier, so the two options stay real <button>s
   and the whole thing still works with JS disabled. */

.k-toggle2 {
  position: relative;
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: var(--k-field);
  border: 1px solid var(--k-line);
}

.k-toggle2::before {
  content: "";
  position: absolute;
  z-index: 0;
  top: 3px;
  left: 3px;
  width: calc(50% - 3px);
  height: calc(100% - 6px);
  border-radius: 999px;
  background: var(--k-primary);
  transition: transform 160ms ease;
}

.k-toggle2--b::before {
  transform: translateX(100%);
}

@media (prefers-reduced-motion: reduce) {
  .k-toggle2::before {
    transition: none;
  }
}

.k-toggle2__opt {
  position: relative;
  z-index: 1;
  flex: 1;
  min-width: 2.75rem;
  padding: 0.25rem 0.625rem;
  border: none;
  background: none;
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--k-soft);
  cursor: pointer;
  white-space: nowrap;
}

.k-toggle2__opt[aria-current="true"] {
  color: var(--k-onPrimary);
}

/* ---- 12c. Checkbox -----------------------------------------------------
   Real <input type="checkbox">, visually hidden but still focusable and
   clickable (opacity:0, not display:none — display:none would take it out
   of the tab order and stop @change firing). The tick is a sibling span
   styled off :checked. */

.k-check {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  cursor: pointer;
}

.k-check input[type="checkbox"] {
  position: absolute;
  width: 1.25rem;
  height: 1.25rem;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.k-check__box {
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
  margin-top: 0.0625rem;
  border-radius: 6px;
  border: 1px solid var(--k-line);
  background: var(--k-field);
  display: flex;
  align-items: center;
  justify-content: center;
  color: transparent;
}

.k-check input[type="checkbox"]:checked + .k-check__box {
  background: var(--k-primary);
  border-color: var(--k-primary);
  color: var(--k-onPrimary);
}

.k-check input[type="checkbox"]:focus-visible + .k-check__box {
  outline: 2px solid var(--k-accent);
  outline-offset: 2px;
}

.k-check input[type="checkbox"][aria-invalid="true"] + .k-check__box {
  border-color: var(--k-warn);
}

.k-check__label {
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--k-soft);
}

/* An inline text button that reads as a link (opens the terms modal). */
.k-link {
  padding: 0;
  border: none;
  background: none;
  font: inherit;
  color: var(--k-accent);
  text-decoration: underline;
  cursor: pointer;
}

/* ---- 12d. Modal --------------------------------------------------------
   Native <dialog>: the browser supplies focus trapping, Esc-to-close and
   the backdrop, so no JS beyond showModal()/close(). */

.k-modal {
  width: min(calc(100vw - 2rem), 26.875rem);
  max-height: 82dvh;
  padding: 0;
  border: 1px solid var(--k-line);
  border-radius: 20px;
  background: var(--k-surface);
  color: var(--k-ink);
  overflow: hidden;
}

.k-modal::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.k-modal[open] {
  display: flex;
  flex-direction: column;
}

.k-modal__head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1rem 0.75rem 1.25rem;
  border-bottom: 1px solid var(--k-line);
}

.k-modal__title {
  flex: 1;
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  line-height: var(--k-lh-heading);
}

.k-modal__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1rem 1.25rem;
}

.k-modal__foot {
  flex: none;
  padding: 0.75rem 1.25rem calc(env(safe-area-inset-bottom, 0px) + 1rem);
  border-top: 1px solid var(--k-line);
}

.k-terms h3 {
  margin: 0 0 0.75rem;
  font-size: 0.9375rem;
  line-height: var(--k-lh-heading);
}

.k-terms p {
  margin: 0 0 0.75rem;
  font-size: 0.8125rem;
  line-height: 1.6;
  color: var(--k-soft);
}

.k-terms strong {
  color: var(--k-ink);
}

/* Show the copy matching the page language. Both are in the DOM so the
   modal never disagrees with the surrounding UI. */
.k-terms--th {
  display: none;
}

html[lang="th"] .k-terms--th {
  display: block;
}

html[lang="th"] .k-terms--en {
  display: none;
}

/* LINE's mark is white-on-green, so on a neutral row it needs its own green
   puck to stay legible and on-brand. */
.k-provider-dot {
  flex: none;
  width: 1.625rem;
  height: 1.625rem;
  border-radius: 6px;
  background: #06c755;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ---- 12e. Disclosure ---------------------------------------------------
   A collapsible section built on <details>/<summary>: open/closed is the
   browser's own state, so it needs no JS and works with JS disabled. */

.k-disclosure {
  padding: 0;
}

.k-disclosure__summary {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 1rem;
  cursor: pointer;
  list-style: none;
}

/* Hide the native triangle in both engines — the chevron replaces it. */
.k-disclosure__summary::-webkit-details-marker {
  display: none;
}

.k-disclosure__summary::marker {
  content: "";
}

.k-disclosure__chevron {
  color: var(--k-soft);
  transition: transform 160ms ease;
}

.k-disclosure[open] .k-disclosure__chevron {
  transform: rotate(180deg);
}

@media (prefers-reduced-motion: reduce) {
  .k-disclosure__chevron {
    transition: none;
  }
}

.k-disclosure__body {
  padding: 0 1rem 1rem;
  border-top: 1px solid var(--k-line);
}

/* ---- 13. Search field --------------------------------------------------
   A .k-field with a leading icon tucked inside the input box. */

.k-field--search {
  position: relative;
}

.k-field--search .k-field__icon {
  position: absolute;
  left: 0.8125rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--k-soft);
  pointer-events: none;
}

.k-field--search input[type="search"] {
  padding-left: 2.375rem;
}

/* Search field with an advanced-filter disclosure hung on its right edge
   (expenses/expense_list.html). The <summary> is absolutely positioned into
   the field so the toggle reads as part of the input, while the panel below
   still flows at full width — a flex row can't do both, because <details>
   owns the summary and the panel together.

   The panel is closed by default and opens itself whenever a filter inside
   is active, so an applied filter is never hidden. No JS: <details> already
   holds the open state (§2.1.4 keeps Alpine for real client state). */

.k-filterbar {
  position: relative;
}

.k-filterbar .k-field--search input[type="search"] {
  padding-right: 3rem;
}

.k-filterbar__more > summary {
  position: absolute;
  top: 0;
  right: 0;
  width: 3rem;
  height: 52px; /* matches .k-field input */
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--k-soft);
  list-style: none;
  border-radius: 0 14px 14px 0;
}

.k-filterbar__more > summary::-webkit-details-marker {
  display: none;
}

.k-filterbar__more > summary::marker {
  content: "";
}

.k-filterbar__more > summary:hover {
  color: var(--k-ink);
}

.k-filterbar__more > summary svg {
  transition: transform 160ms ease;
}

.k-filterbar__more[open] > summary svg {
  transform: rotate(180deg);
}

@media (prefers-reduced-motion: reduce) {
  .k-filterbar__more > summary svg {
    transition: none;
  }
}

.k-filterbar__panel {
  margin-top: 0.625rem;
  padding: 0.875rem;
  border: 1px solid var(--k-line);
  border-radius: 16px;
  background: var(--k-surface);
}
