/* ==========================================================================
   Contract Monitor - styles
   Mobile first. Light + dark tokens (OS preference, overridable via toggle).
   ========================================================================== */

:root {
  color-scheme: light;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --bg: #f4f5f9;
  --glow-1: rgba(99, 102, 241, .13);
  --glow-2: rgba(14, 165, 233, .09);
  --surface: #ffffff;
  --surface-2: #f7f8fc;
  --surface-3: #eef0f7;
  --topbar-bg: rgba(244, 245, 249, .8);
  --text: #0f1729;
  --text-2: #4a5570;
  --text-3: #6b7590;
  --border: #e3e6ef;
  --border-strong: #cfd4e2;

  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-on: #ffffff;
  --accent-text: #4338ca;
  --accent-soft: rgba(79, 70, 229, .1);

  --good: #0ca30c;
  --good-text: #0a6a0a;
  --good-soft: rgba(12, 163, 12, .12);
  --good-track: rgba(12, 163, 12, .16);
  --bad: #d03b3b;
  --bad-text: #b3262d;
  --bad-soft: rgba(208, 59, 59, .1);
  --bad-track: rgba(208, 59, 59, .16);

  --shadow-sm: 0 1px 2px rgba(15, 23, 41, .05);
  --shadow: 0 1px 2px rgba(15, 23, 41, .04), 0 8px 24px rgba(15, 23, 41, .06);
  --shadow-lg: 0 24px 64px rgba(15, 23, 41, .28);
  --scrim: rgba(10, 14, 28, .45);

  --r: 16px;
  --r-sm: 12px;
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0a0e1a;
    --glow-1: rgba(99, 102, 241, .16);
    --glow-2: rgba(14, 165, 233, .08);
    --surface: #111729;
    --surface-2: #151c33;
    --surface-3: #1c2542;
    --topbar-bg: rgba(10, 14, 26, .78);
    --text: #e9edf8;
    --text-2: #aeb7cf;
    --text-3: #8892ac;
    --border: #222b47;
    --border-strong: #323d60;

    --accent: #6366f1;
    --accent-hover: #7478f5;
    --accent-on: #ffffff;
    --accent-text: #a5b4fc;
    --accent-soft: rgba(129, 140, 248, .16);

    --good: #0ca30c;
    --good-text: #4ade80;
    --good-soft: rgba(74, 222, 128, .13);
    --good-track: rgba(74, 222, 128, .17);
    --bad: #e24d4d;
    --bad-text: #ff8d8d;
    --bad-soft: rgba(255, 120, 120, .13);
    --bad-track: rgba(255, 120, 120, .18);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .28);
    --shadow-lg: 0 24px 64px rgba(0, 0, 0, .6);
    --scrim: rgba(3, 5, 12, .62);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0e1a;
  --glow-1: rgba(99, 102, 241, .16);
  --glow-2: rgba(14, 165, 233, .08);
  --surface: #111729;
  --surface-2: #151c33;
  --surface-3: #1c2542;
  --topbar-bg: rgba(10, 14, 26, .78);
  --text: #e9edf8;
  --text-2: #aeb7cf;
  --text-3: #8892ac;
  --border: #222b47;
  --border-strong: #323d60;

  --accent: #6366f1;
  --accent-hover: #7478f5;
  --accent-on: #ffffff;
  --accent-text: #a5b4fc;
  --accent-soft: rgba(129, 140, 248, .16);

  --good: #0ca30c;
  --good-text: #4ade80;
  --good-soft: rgba(74, 222, 128, .13);
  --good-track: rgba(74, 222, 128, .17);
  --bad: #e24d4d;
  --bad-text: #ff8d8d;
  --bad-soft: rgba(255, 120, 120, .13);
  --bad-track: rgba(255, 120, 120, .18);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .28);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, .6);
  --scrim: rgba(3, 5, 12, .62);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(900px 420px at 12% -10%, var(--glow-1), transparent 70%),
    radial-gradient(700px 360px at 96% -6%, var(--glow-2), transparent 70%);
}
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.ic { display: inline-flex; flex: none; line-height: 0; }
.ic svg { width: 1.15em; height: 1.15em; }
.grow { flex: 1 1 auto; }
.noscript { padding: 24px; text-align: center; }

:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; border-radius: 6px; }

.splash { min-height: 100dvh; display: grid; place-items: center; }
.spinner, .btn.is-busy::after {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2.5px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px;
  border: 1px solid var(--border-strong); border-radius: 12px;
  background: var(--surface); color: var(--text);
  font-weight: 600; font-size: 14px; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: transparent; color: var(--accent-on); box-shadow: 0 1px 2px rgba(79, 70, 229, .35); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-3); }
.btn-danger { background: var(--bad); border-color: transparent; color: #fff; }
.btn-danger:hover { background: #b93030; }
.btn-danger-ghost { background: transparent; border-color: transparent; color: var(--bad-text); }
.btn-danger-ghost:hover { background: var(--bad-soft); }
.btn-icon { width: 40px; padding: 0; }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn-sm.btn-icon { width: 34px; padding: 0; }
.btn-block { width: 100%; height: 46px; }
.btn.is-busy { color: transparent !important; position: relative; pointer-events: none; }
.btn.is-busy > * { visibility: hidden; }
.btn.is-busy::after { position: absolute; inset: 0; margin: auto; }
.btn-primary.is-busy::after { border-color: rgba(255, 255, 255, .4); border-top-color: #fff; }

/* ---------- Forms ---------- */
.field { display: grid; gap: 6px; margin-top: 14px; }
.field:first-child { margin-top: 0; }
.lbl { font-size: 13px; font-weight: 600; color: var(--text-2); }
.hint { font-size: 12.5px; color: var(--text-3); }
input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="number"],
select, textarea {
  width: 100%; height: 44px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: 12px;
  background: var(--surface); color: var(--text);
  font-size: 16px; /* >=16px stops iOS zooming into fields */
  transition: border-color .15s, box-shadow .15s;
}
textarea { height: auto; min-height: 84px; padding: 10px 12px; resize: vertical; line-height: 1.45; }
select { appearance: none; -webkit-appearance: none; padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238892ac' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder, textarea::placeholder { color: var(--text-3); }
.form-error { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: var(--bad-soft); color: var(--bad-text); font-size: 13.5px; font-weight: 500; }
.money { position: relative; }
.money > span { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); font-weight: 600; pointer-events: none; }
.money input { padding-left: 28px; font-variant-numeric: tabular-nums; }
.pw { position: relative; }
.pw input { padding-right: 46px; }
.pw button { position: absolute; right: 4px; top: 4px; width: 36px; height: 36px; border: 0; background: transparent; border-radius: 9px; color: var(--text-3); display: grid; place-items: center; }
.pw button:hover { background: var(--surface-3); color: var(--text); }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.roles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.role-opt { position: relative; display: grid; gap: 2px; padding: 12px 14px; border: 1.5px solid var(--border-strong); border-radius: 12px; background: var(--surface); cursor: pointer; }
.role-opt input { position: absolute; opacity: 0; pointer-events: none; }
.role-opt b { font-size: 14px; }
.role-opt small { color: var(--text-3); font-size: 12.5px; line-height: 1.35; }
.role-opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.role-opt:has(input:focus-visible) { outline: 2px solid var(--accent-text); outline-offset: 2px; }

/* ---------- Auth ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: calc(24px + var(--safe-t)) 16px calc(24px + var(--safe-b)); }
.auth-card { width: min(420px, 100%); padding: 28px 24px; background: var(--surface); border: 1px solid var(--border); border-radius: 24px; box-shadow: var(--shadow); }
.auth-card .logo { width: 48px; height: 48px; border-radius: 14px; margin-bottom: 18px; }
.auth-card h1 { font-size: 24px; letter-spacing: -.02em; }
.auth-card .sub { margin: 6px 0 22px; color: var(--text-2); }
.auth-card .btn-block { margin-top: 20px; }

/* ---------- Top bar & navigation ---------- */
.topbar { position: sticky; top: 0; z-index: 30; background: var(--topbar-bg); border-bottom: 1px solid var(--border);
  -webkit-backdrop-filter: saturate(1.4) blur(14px); backdrop-filter: saturate(1.4) blur(14px); padding-top: var(--safe-t); }
.topbar-in { max-width: 1180px; margin: 0 auto; height: 60px; padding: 0 16px; display: flex; align-items: center; gap: 8px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.01em; margin-right: 8px; }
.logo { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #6366f1, #4338ca); box-shadow: 0 2px 8px rgba(79, 70, 229, .35); flex: none; }
.logo svg { width: 60%; height: 60%; }
.nav { display: none; gap: 4px; }
.nav-btn { display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 14px; border: 0; background: transparent; border-radius: 10px; color: var(--text-2); font-weight: 600; font-size: 14px; }
.nav-btn:hover { background: var(--surface-3); color: var(--text); }
.nav-btn[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); }
.avatar { width: 36px; height: 36px; border-radius: 50%; border: 0; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 14px;
  background: linear-gradient(135deg, #6366f1, #0ea5e9); }
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 10px); width: min(300px, calc(100vw - 24px)); padding: 8px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg); animation: pop .14s ease-out; }
.menu-head { padding: 10px 12px 12px; }
.menu-name { font-weight: 700; }
.menu-email { color: var(--text-3); font-size: 13px; overflow-wrap: anywhere; }
.menu-sep { height: 1px; background: var(--border); margin: 6px 0; }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; height: 44px; padding: 0 12px; border: 0; background: transparent; border-radius: 10px; text-align: left; font-weight: 500; }
.menu-item:hover { background: var(--surface-3); }
.menu-label { padding: 6px 12px 4px; font-size: 12px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; }
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-3); border-radius: 12px; }
.seg-btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border: 0; background: transparent; border-radius: 9px; color: var(--text-2); font-weight: 600; font-size: 13.5px; white-space: nowrap; }
.seg-btn:hover { color: var(--text); }
.seg-btn[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.menu .seg { display: flex; margin: 0 8px 6px; }
.menu .seg-btn { flex: 1; justify-content: center; }
.role-badge { display: inline-flex; align-items: center; height: 22px; padding: 0 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; letter-spacing: .02em; background: var(--surface-3); color: var(--text-2); }
.role-badge.admin { background: var(--accent-soft); color: var(--accent-text); }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; justify-content: space-around; gap: 4px;
  padding: 6px 10px calc(6px + var(--safe-b)); background: var(--topbar-bg); border-top: 1px solid var(--border);
  -webkit-backdrop-filter: saturate(1.4) blur(14px); backdrop-filter: saturate(1.4) blur(14px); }
.tab { flex: 1; max-width: 220px; display: grid; justify-items: center; gap: 2px; padding: 6px 0; border: 0; background: transparent; border-radius: 12px; color: var(--text-3); font-size: 12px; font-weight: 600; }
.tab .ic svg { width: 22px; height: 22px; }
.tab[aria-current="page"] { color: var(--accent-text); }
.tab[aria-current="page"] .ic { background: var(--accent-soft); border-radius: 999px; padding: 3px 16px; margin: -3px 0; }

/* ---------- Page ---------- */
.main { max-width: 1180px; margin: 0 auto; padding: 20px 16px calc(var(--tabbar-h) + var(--safe-b) + 96px); }
.main.no-tabs { padding-bottom: calc(var(--safe-b) + 40px); }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 14px 16px; margin-bottom: 18px; }
.page-title { font-size: 26px; font-weight: 750; letter-spacing: -.025em; line-height: 1.15; }
.page-sub { margin-top: 4px; color: var(--text-2); }
.head-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.head-actions .only-desktop { display: none; }

.monthsw { display: flex; align-items: center; gap: 2px; padding: 3px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-sm); }
.monthsw .month-label { min-width: 138px; flex: 1; text-align: center; font-weight: 700; letter-spacing: -.01em; }
.monthsw .btn { height: 36px; }
.head-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; width: 100%; }
.today-link { border: 0; background: transparent; color: var(--accent-text); font-weight: 600; font-size: 13.5px; padding: 6px 8px; border-radius: 8px; }
.today-link:hover { background: var(--accent-soft); }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile { padding: 16px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow-sm); min-width: 0; }
.tile-lbl { font-size: 13px; font-weight: 600; color: var(--text-2); }
.tile-val { margin-top: 6px; font-size: 24px; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; overflow-wrap: anywhere; }
.tile-sub { margin-top: 6px; font-size: 13px; color: var(--text-3); }
.tile.hero { grid-column: 1 / -1; padding: 20px; }
.tile.hero .tile-val { font-size: clamp(2.5rem, 9vw + .5rem, 3.6rem); font-weight: 750; letter-spacing: -.035em; line-height: 1.05; margin-top: 8px; }
.tile.hero { container-type: inline-size; }
.tile.hero .tile-val { font-size: clamp(2rem, 15cqw, 3.6rem); }
.tile.hero.is-short .tile-val { color: var(--bad-text); }
.tile.hero.is-ok .tile-val { color: var(--good-text); }
.tile.wide { grid-column: 1 / -1; }
.hero-meta { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 14px; color: var(--text-2); }
.hero-meta .ic { color: var(--good-text); }
.hero-meta.is-short .ic { color: var(--bad-text); }
.cover { margin-top: 16px; }
.cover-top { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-2); margin-bottom: 6px; font-weight: 600; }
.cover-top span:last-child { font-variant-numeric: tabular-nums; }

.meter { height: 8px; border-radius: 999px; background: var(--track, var(--surface-3)); overflow: hidden; }
.meter-fill { display: block; height: 100%; width: 0; border-radius: 999px; background: var(--fill, var(--accent)); transition: width .45s cubic-bezier(.2, .8, .2, 1); }
.is-ok, .m-ok { --fill: var(--good); --track: var(--good-track); }
.is-short, .m-short { --fill: var(--bad); --track: var(--bad-track); }

.notice { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 12px; padding: 10px 14px; background: var(--surface); border: 1px dashed var(--border-strong); border-radius: 12px; color: var(--text-2); font-size: 13.5px; }
.notice .ic { color: var(--text-3); }
.notice button { border: 0; background: transparent; color: var(--accent-text); font-weight: 600; padding: 0; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Toolbar ---------- */
.toolbar { display: grid; gap: 10px; margin: 22px 0 14px; grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "search" "tools" "seg" "sel"; }
.toolbar > .search { grid-area: search; }
.toolbar > .tool-actions { grid-area: tools; }
.toolbar > .seg-scroll { grid-area: seg; }
.toolbar > .toolbar-row { grid-area: sel; }
.search { position: relative; }
.search .ic { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.search input { padding-left: 38px; }
.toolbar-row { display: flex; gap: 10px; align-items: center; }
.toolbar-row > select { flex: 1; min-width: 0; }
.seg-scroll { overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.seg-scroll::-webkit-scrollbar { display: none; }
.seg-scroll .seg { min-width: max-content; }
.count { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--surface-3); color: var(--text-2); font-size: 11.5px; font-weight: 700; font-variant-numeric: tabular-nums; }
.seg-btn[aria-pressed="true"] .count { background: var(--accent-soft); color: var(--accent-text); }
.seg-btn[data-s="short"][aria-pressed="true"] .count { background: var(--bad-soft); color: var(--bad-text); }
.seg-btn[data-s="ok"][aria-pressed="true"] .count { background: var(--good-soft); color: var(--good-text); }
.tool-actions { display: flex; gap: 8px; }
.tool-actions .btn:not(.btn-icon) { flex: 1; }

/* ---------- Account list ---------- */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.list-cols { display: none; }
.group-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; padding: 0 4px; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-2); }
.group-head:first-child { margin-top: 0; }
.group-head .g-sum { letter-spacing: 0; text-transform: none; font-size: 12.5px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.g-sum.is-short { color: var(--bad-text); }
.g-sum.is-ok { color: var(--good-text); }
.g-sum.is-none { color: var(--text-3); }

.acct { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-areas: "name name status" "meter meter meter" "min paid short" "actions actions actions";
  gap: 12px 10px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow-sm); cursor: pointer; transition: border-color .15s, box-shadow .15s; }
.acct:hover { border-color: var(--border-strong); box-shadow: var(--shadow); }
.editing .acct { cursor: default; }
.c-name { grid-area: name; min-width: 0; }
.name-btn { display: block; max-width: 100%; padding: 0; border: 0; background: transparent; text-align: left; font-weight: 650; font-size: 15px; line-height: 1.3; color: var(--text); letter-spacing: -.005em; }
.name-btn:hover { color: var(--accent-text); }
.c-name .sub { margin-top: 2px; font-size: 13px; color: var(--text-3); }
.c-status { grid-area: status; justify-self: end; align-self: start; }
.c-meter { grid-area: meter; display: flex; align-items: center; gap: 10px; }
.c-meter .meter { flex: 1; }
.pct { width: 42px; text-align: right; font-size: 12.5px; font-weight: 600; color: var(--text-2); font-variant-numeric: tabular-nums; }
.c-min { grid-area: min; }
.c-paid { grid-area: paid; }
.c-short { grid-area: short; }
.cap { display: block; font-size: 11.5px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 2px; }
.val { display: block; font-weight: 650; font-variant-numeric: tabular-nums; font-size: 14.5px; overflow-wrap: anywhere; }
.val.muted, .muted-text { color: var(--text-3); font-weight: 500; }
.val.bad { color: var(--bad-text); }
.val.good { color: var(--good-text); }
.c-actions { grid-area: actions; display: flex; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.c-actions .btn { flex: 1; }
.c-actions .btn .lbl { color: inherit; font-size: 13px; }
.acct.is-unset .c-meter { display: none; }
.acct.is-unset { grid-template-areas: "name name status" "min paid short" "actions actions actions"; }
.acct .amt { height: 38px; text-align: right; font-size: 15px; font-variant-numeric: tabular-nums; padding: 0 10px; border-radius: 10px; }
.acct .amt.changed { border-color: var(--accent); background: var(--accent-soft); }
.acct .amt.invalid { border-color: var(--bad); background: var(--bad-soft); }

.editing .acct, .editing .acct.is-unset { grid-template-areas: "name name" "min paid" "short short"; grid-template-columns: 1fr 1fr; }
.editing .c-meter, .editing .c-status, .editing .c-actions { display: none; }
.editing .c-short { display: flex; align-items: center; gap: 8px; }
.editing .c-short .cap { margin: 0; }

.pill { display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 10px 0 8px; border-radius: 999px; font-size: 12.5px; font-weight: 650; white-space: nowrap; }
.pill .ic svg { width: 14px; height: 14px; stroke-width: 2.6; }
.pill.ok { background: var(--good-soft); color: var(--good-text); }
.pill.short { background: var(--bad-soft); color: var(--bad-text); }
.pill.unset { background: var(--surface-3); color: var(--text-2); }

.skel { height: 118px; border-radius: var(--r); background: linear-gradient(90deg, var(--surface) 0%, var(--surface-3) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.3s linear infinite; border: 1px solid var(--border); }
@keyframes shimmer { to { background-position: -200% 0; } }

.empty { display: grid; justify-items: center; gap: 8px; padding: 48px 20px; text-align: center; background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--r); color: var(--text-2); }
.empty .ic svg { width: 32px; height: 32px; color: var(--text-3); }
.empty h3 { font-size: 16px; color: var(--text); }

/* ---------- Floating actions ---------- */
.fab { position: fixed; right: 16px; bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); z-index: 25; width: 56px; height: 56px; border-radius: 18px; border: 0;
  display: grid; place-items: center; background: var(--accent); color: var(--accent-on); box-shadow: 0 8px 24px rgba(79, 70, 229, .45); }
.fab .ic svg { width: 26px; height: 26px; }
.fab:active { transform: scale(.96); }
.main.no-tabs ~ .fab { bottom: calc(var(--safe-b) + 18px); }
.editbar { position: fixed; left: 12px; right: 12px; bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px); z-index: 26; display: flex; align-items: center; gap: 10px;
  padding: 10px 10px 10px 16px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 18px; box-shadow: var(--shadow-lg); }
.editbar .msg { flex: 1; font-weight: 600; font-size: 14px; }
.editbar .msg small { display: block; font-weight: 400; color: var(--text-3); font-size: 12.5px; }
.main.no-tabs ~ .editbar { bottom: calc(var(--safe-b) + 14px); }

/* ---------- Users ---------- */
.urow { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 4px 14px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow-sm); }
.urow .avatar { width: 42px; height: 42px; font-size: 16px; grid-row: span 2; }
.u-name { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 650; }
.u-email { color: var(--text-3); font-size: 13.5px; overflow-wrap: anywhere; }
.u-meta { grid-column: 2 / -1; font-size: 12.5px; color: var(--text-3); }
.u-actions { display: flex; gap: 4px; grid-column: 3; grid-row: 1 / span 2; }
.you { font-size: 11.5px; font-weight: 700; color: var(--text-3); }

/* ---------- Dialogs ---------- */
dialog.dlg { border: 0; padding: 0; background: var(--surface); color: var(--text); border-radius: 22px; width: min(540px, calc(100vw - 24px)); max-height: min(90dvh, 860px);
  box-shadow: var(--shadow-lg); overflow: hidden; }
dialog.dlg[open] { display: flex; flex-direction: column; animation: pop .18s ease-out; }
dialog.dlg::backdrop { background: var(--scrim); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
dialog.dlg.wide { width: min(640px, calc(100vw - 24px)); }
.dlg-form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.dlg-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 20px 12px; }
.dlg-head h2 { font-size: 19px; letter-spacing: -.02em; line-height: 1.25; }
.dlg-sub { margin-top: 3px; color: var(--text-3); font-size: 13.5px; }
.dlg-body { padding: 4px 20px 20px; overflow-y: auto; overscroll-behavior: contain; flex: 1; min-height: 0; }
.dlg-foot { display: flex; gap: 10px; justify-content: flex-end; align-items: center; padding: 14px 20px calc(14px + var(--safe-b)); border-top: 1px solid var(--border); background: var(--surface); }
.dlg-foot .spacer { flex: 1; }
.confirm-msg { color: var(--text-2); line-height: 1.55; overflow-wrap: anywhere; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes sheet { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 6px 0 16px; }
.stat { padding: 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); min-width: 0; }
.stat .val { font-size: 15px; overflow-wrap: anywhere; }
.h3 .pill { text-transform: none; letter-spacing: 0; }
.detail-notes { margin: 0 0 16px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); color: var(--text-2); font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.h3 { margin: 4px 0 8px; font-size: 13px; font-weight: 700; color: var(--text-2); text-transform: uppercase; letter-spacing: .05em; display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.h3 small { text-transform: none; letter-spacing: 0; font-weight: 600; font-size: 12.5px; }
.hist { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.hist li { display: grid; grid-template-columns: 1.1fr 1.2fr 1fr; gap: 8px; align-items: center; padding: 10px 12px; border-top: 1px solid var(--border); font-size: 14px; font-variant-numeric: tabular-nums; }
.hist li:first-child { border-top: 0; }
.hist .hm { font-weight: 600; }
.hist .hs { text-align: right; font-weight: 650; }
.hist .hs.bad { color: var(--bad-text); }
.hist .hs.good { color: var(--good-text); }
.hist .hs.none { color: var(--text-3); font-weight: 500; }
.hist button.hrow { all: unset; display: contents; }
.hist li.can-edit { cursor: pointer; }
.hist li.can-edit:hover { background: var(--surface-2); }
.pay-result { display: flex; align-items: center; gap: 8px; margin-top: 12px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); font-weight: 600; font-size: 14px; min-height: 42px; }
.pay-result.is-short { background: var(--bad-soft); color: var(--bad-text); }
.pay-result.is-ok { background: var(--good-soft); color: var(--good-text); }
.dlg-body .btn-sm { margin-top: 8px; }
.pay-line { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; color: var(--text-2); font-size: 14px; }
.pay-line b { color: var(--text); font-variant-numeric: tabular-nums; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + var(--safe-b) + 92px); z-index: 100; display: grid; justify-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { display: inline-flex; align-items: center; gap: 10px; max-width: 460px; padding: 11px 16px; border-radius: 14px; background: #121a30; color: #f1f4fb; font-size: 14px; font-weight: 500; box-shadow: var(--shadow-lg); animation: pop .18s ease-out; border: 1px solid rgba(255, 255, 255, .08); }
.toast.error { background: #3a1216; border-color: rgba(255, 120, 120, .35); color: #ffd9d9; }
.toast .ic { color: #4ade80; }
.toast.error .ic { color: #ff8d8d; }

/* ---------- Desktop ---------- */
@media (min-width: 720px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .tile.wide { grid-column: auto; }
  .tile-val { font-size: 26px; }
  .toolbar { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "search tools" "seg seg" "sel sel"; align-items: center; }
  .toolbar .seg-scroll { margin: 0; padding: 0; overflow: visible; }
  .tool-actions .btn:not(.btn-icon) { flex: none; }
}

@media (min-width: 860px) {
  .nav { display: flex; }
  .tabbar { display: none; }
  .main { padding: 28px 24px 56px; }
  .topbar-in { padding: 0 24px; }
  .fab { display: none; }
  .head-actions .only-desktop { display: inline-flex; }
  .head-row { width: auto; }
  .editbar { left: 50%; right: auto; width: min(560px, calc(100vw - 48px)); transform: translateX(-50%); bottom: 24px; }
  #toasts { top: calc(var(--safe-t) + 74px); bottom: auto; }

  .list-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow-sm); overflow: hidden; }
  .list { gap: 0; }
  /* Columns: account | minimum | paid | (progress, wide screens only) | status | shortfall | (admin actions) */
  .list-cols, .acct { display: grid; align-items: center; gap: 0 14px; padding: 0 18px;
    grid-template-columns: minmax(0, 1.8fr) 120px 120px 112px 120px; }
  .is-admin .list-cols, .is-admin .acct { grid-template-columns: minmax(0, 1.8fr) 120px 120px 112px 120px 112px; }
  .list-cols > *, .acct > * { min-width: 0; }
  .c-meter, .list-cols .col-meter { display: none; }
  .list-cols { padding-top: 11px; padding-bottom: 11px; background: var(--surface-2); border-bottom: 1px solid var(--border);
    font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }
  .list-cols .r { text-align: right; }
  .acct { grid-template-areas: none; min-height: 66px; padding-top: 12px; padding-bottom: 12px; border: 0; border-bottom: 1px solid var(--border); border-radius: 0; box-shadow: none; background: transparent; }
  .acct:hover { background: var(--surface-2); box-shadow: none; }
  .acct:last-child { border-bottom: 0; }
  .c-name, .c-min, .c-paid, .c-meter, .c-status, .c-short, .c-actions { grid-area: auto; }
  .acct.is-unset { grid-template-areas: none; }
  .acct .cap { display: none; }
  .c-min, .c-paid, .c-short { text-align: right; }
  .c-status { justify-self: start; }
  .c-actions { padding: 0; border: 0; justify-content: flex-end; gap: 2px; }
  .c-actions .btn { flex: none; width: 34px; padding: 0; }
  .c-actions .btn .lbl { display: none; }
  .group-head { margin: 0; padding: 9px 18px; background: var(--surface-3); border-bottom: 1px solid var(--border); }
  .group-head:first-child { margin: 0; }
  .editing .acct, .editing .acct.is-unset { grid-template-areas: none; }
  .is-admin.editing .list-cols, .is-admin.editing .acct, .is-admin.editing .acct.is-unset { grid-template-columns: minmax(0, 1.8fr) 150px 150px 112px 120px 0; }
  .editing .c-meter { display: none; }
  .editing .c-status { display: block; }
  .editing .c-actions { display: none; }
  .editing .c-short { display: block; }

  .stat-grid { grid-template-columns: repeat(3, 1fr); }
  .urow { grid-template-columns: auto 1fr auto auto; padding: 14px 18px; }
  .u-meta { grid-column: auto; grid-row: auto; text-align: right; }
  .urow .avatar { grid-row: span 2; }
  .u-actions { grid-column: 4; }
}

@media (min-width: 1000px) {
  .kpis { grid-template-columns: 1.8fr 1fr 1fr 1fr; }
  .tile.hero { grid-column: auto; }
  .toolbar { grid-template-areas: "search tools" "seg sel"; }
  .toolbar > .toolbar-row { justify-self: end; }
  .toolbar-row > select { flex: 0 0 190px; }
}

@media (min-width: 1100px) {
  .list-cols, .acct { grid-template-columns: minmax(0, 1.8fr) 120px 120px minmax(120px, 1fr) 112px 120px; }
  .is-admin .list-cols, .is-admin .acct { grid-template-columns: minmax(0, 1.8fr) 120px 120px minmax(120px, 1fr) 112px 120px 112px; }
  .is-admin.editing .list-cols, .is-admin.editing .acct, .is-admin.editing .acct.is-unset { grid-template-columns: minmax(0, 1.8fr) 150px 150px minmax(120px, 1fr) 112px 120px 0; }
  .c-meter, .editing .c-meter { display: flex; }
  .list-cols .col-meter { display: block; }
  .acct.is-unset .c-meter { display: flex; visibility: hidden; }
}

/* ---------- Phones: dialogs become bottom sheets ---------- */
@media (max-width: 640px) {
  dialog.dlg, dialog.dlg.wide { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 24px 24px 0 0; max-height: 92dvh; }
  dialog.dlg[open] { animation: sheet .24s cubic-bezier(.2, .8, .2, 1); }
  .dlg-foot .btn { flex: 1; }
  .dlg-foot .btn-danger-ghost { flex: none; }
  .main { padding-top: 16px; }
  .head-row .monthsw { flex: 1; }
  .head-row .grow, .head-row .head-actions:empty { display: none; }
}
@media (max-width: 380px) {
  .brand-name { display: none; }
  .pair { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
