/* ==========================================================================
   Ashaca Corporation — Salary & Expense Management
   Design system: tokens, layout shell, components, charts, print.
   Mobile-first. Light and dark are both selected palettes, not a filter flip.
   ========================================================================== */

/* ----------------------------------------------------------------- tokens */

:root {
  color-scheme: light;

  /* surfaces & ink */
  --page:            #f4f4f1;
  --surface:         #ffffff;
  --surface-2:       #f9f9f7;
  --surface-sunken:  #f0efec;
  --chart-surface:   #ffffff;
  --text-primary:    #0b0b0b;
  --text-secondary:  #52514e;
  --text-muted:      #898781;
  --border:          rgba(11, 11, 11, 0.10);
  --border-strong:   rgba(11, 11, 11, 0.18);
  --grid:            #e1e0d9;
  --axis:            #c3c2b7;
  --overlay:         rgba(11, 11, 11, 0.55);

  /* categorical series (validated order — never reorder or cycle) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;

  /* brand accent = series slot 1 */
  --accent:        #2a78d6;
  --accent-hover:  #256abf;
  --accent-ink:    #ffffff;
  --accent-wash:   #eaf2fd;
  --accent-border: #b7d3f6;

  /* status (reserved — never used as a series colour) */
  --good:     #0ca30c;
  --warning:  #fab219;
  --serious:  #ec835a;
  --critical: #d03b3b;
  --good-text:     #006300;
  --critical-text: #b02a2a;
  --good-wash:     #e7f6e7;
  --warning-wash:  #fdf3dd;
  --critical-wash: #fbeaea;

  /* geometry */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-pill: 999px;
  --shadow-1: 0 1px 2px rgba(11, 11, 11, 0.05), 0 1px 3px rgba(11, 11, 11, 0.04);
  --shadow-2: 0 4px 12px rgba(11, 11, 11, 0.08), 0 1px 3px rgba(11, 11, 11, 0.04);
  --shadow-3: 0 12px 32px rgba(11, 11, 11, 0.16);

  --sidebar-w: 248px;
  --topbar-h: 60px;
  --tabbar-h: 62px;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page:            #0d0d0d;
    --surface:         #1a1a19;
    --surface-2:       #141413;
    --surface-sunken:  #232322;
    --chart-surface:   #1a1a19;
    --text-primary:    #ffffff;
    --text-secondary:  #c3c2b7;
    --text-muted:      #898781;
    --border:          rgba(255, 255, 255, 0.11);
    --border-strong:   rgba(255, 255, 255, 0.20);
    --grid:            #2c2c2a;
    --axis:            #383835;
    --overlay:         rgba(0, 0, 0, 0.7);

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;

    --accent:        #3987e5;
    --accent-hover:  #5598e7;
    --accent-ink:    #ffffff;
    --accent-wash:   #16283f;
    --accent-border: #1c5cab;

    --good-text:     #0ca30c;
    --critical-text: #e66767;
    --good-wash:     #10240f;
    --warning-wash:  #2b2410;
    --critical-wash: #2c1616;

    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 4px 14px rgba(0, 0, 0, 0.45);
    --shadow-3: 0 14px 36px rgba(0, 0, 0, 0.6);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page:            #0d0d0d;
  --surface:         #1a1a19;
  --surface-2:       #141413;
  --surface-sunken:  #232322;
  --chart-surface:   #1a1a19;
  --text-primary:    #ffffff;
  --text-secondary:  #c3c2b7;
  --text-muted:      #898781;
  --border:          rgba(255, 255, 255, 0.11);
  --border-strong:   rgba(255, 255, 255, 0.20);
  --grid:            #2c2c2a;
  --axis:            #383835;
  --overlay:         rgba(0, 0, 0, 0.7);

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;

  --accent:        #3987e5;
  --accent-hover:  #5598e7;
  --accent-ink:    #ffffff;
  --accent-wash:   #16283f;
  --accent-border: #1c5cab;

  --good-text:     #0ca30c;
  --critical-text: #e66767;
  --good-wash:     #10240f;
  --warning-wash:  #2b2410;
  --critical-wash: #2c1616;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 4px 14px rgba(0, 0, 0, 0.45);
  --shadow-3: 0 14px 36px rgba(0, 0, 0, 0.6);
}

/* ------------------------------------------------------------------ reset */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text-primary);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
p  { margin: 0 0 12px; }
a  { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; display: block; }
code {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.9em; background: var(--surface-sunken);
  padding: 1px 5px; border-radius: 5px;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.muted { color: var(--text-secondary); }
.small { font-size: 13px; }
.center { text-align: center; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.hide { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.pos { color: var(--good-text); }
.neg { color: var(--critical-text); }

/* ------------------------------------------------------------ app shell */

.app { min-height: 100vh; }

.sidebar {
  display: none;
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  overflow-y: auto;
  z-index: 40;
}

.brand {
  display: flex; align-items: center; gap: 11px;
  padding: 4px 8px 18px;
}
.brand-mark {
  width: 36px; height: 36px; flex: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: 18px; letter-spacing: -0.02em;
}
.brand-mark--lg { width: 46px; height: 46px; font-size: 22px; border-radius: 13px; }
.brand-name { font-weight: 650; font-size: 15px; line-height: 1.15; }
.brand-sub  { font-size: 11.5px; color: var(--text-muted); letter-spacing: 0.02em; text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-section {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); font-weight: 650;
  padding: 16px 10px 6px;
}
.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  color: var(--text-secondary);
  font-weight: 500; font-size: 14.5px;
  text-decoration: none;
}
.nav-link:hover { background: var(--surface-sunken); color: var(--text-primary); text-decoration: none; }
.nav-link.is-active { background: var(--accent-wash); color: var(--accent); font-weight: 600; }
.nav-link .ico { width: 20px; text-align: center; font-size: 16px; flex: none; }
.nav-badge {
  margin-left: auto; font-size: 11px; font-weight: 650;
  background: var(--warning-wash); color: var(--text-primary);
  padding: 1px 7px; border-radius: var(--r-pill);
}

.sidebar-foot { margin-top: 22px; padding: 12px 10px 0; border-top: 1px solid var(--border); }

/* top bar (mobile + desktop) */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(150%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 17px; }
.topbar-sub { font-size: 12px; color: var(--text-muted); line-height: 1.2; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.icon-btn {
  width: 38px; height: 38px; flex: none;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: 10px; cursor: pointer;
  font-size: 16px; line-height: 1;
}
.icon-btn:hover { background: var(--surface-sunken); color: var(--text-primary); }

.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 12.5px; font-weight: 650; color: #fff;
  background: var(--series-7); flex: none;
}
.avatar--sm { width: 28px; height: 28px; font-size: 11px; }

.main { padding: 16px 14px calc(var(--tabbar-h) + 78px); }
.page-head { margin-bottom: 16px; }
.page-head h1 { margin-bottom: 2px; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* bottom tab bar (mobile only) */
.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 40;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(150%) blur(12px);
  border-top: 1px solid var(--border);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: var(--text-muted); font-size: 10.5px; font-weight: 550;
  text-decoration: none; padding-top: 6px;
}
.tab .ico { font-size: 19px; line-height: 1; }
.tab.is-active { color: var(--accent); }
.tab:hover { text-decoration: none; }

/* floating "add expense" button */
.fab {
  position: fixed;
  right: 16px;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  z-index: 45;
  height: 54px; padding: 0 20px 0 17px;
  display: inline-flex; align-items: center; gap: 9px;
  background: var(--accent); color: var(--accent-ink);
  border: none; border-radius: var(--r-pill);
  font-size: 15px; font-weight: 650; font-family: inherit;
  box-shadow: var(--shadow-3);
  cursor: pointer; text-decoration: none;
}
.fab:hover { background: var(--accent-hover); text-decoration: none; color: #fff; }
.fab .ico { font-size: 21px; line-height: 1; }

/* ------------------------------------------------------------- surfaces */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  margin-bottom: 14px;
  overflow: hidden;
}
.card--pad { padding: 18px; }
.card--flush { overflow: visible; }
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
}
.card-head h2, .card-head h3 { font-size: 15.5px; }
.card-head .card-tools { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.card-body { padding: 18px; }
.card-foot {
  padding: 12px 18px; border-top: 1px solid var(--border);
  background: var(--surface-2);
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}

.section-title {
  font-size: 12px; font-weight: 650; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-muted);
  margin: 22px 2px 10px;
}

/* --------------------------------------------------------- stat tiles */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 13px 14px;
  box-shadow: var(--shadow-1);
  min-width: 0;
}
.stat-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-secondary); font-weight: 550;
  margin-bottom: 6px;
}
.stat-value {
  font-size: 22px; font-weight: 680; letter-spacing: -0.02em;
  line-height: 1.15; word-break: break-word;
}
.stat-meta { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }
.stat--hero {
  grid-column: 1 / -1;
  background: linear-gradient(140deg, var(--accent) 0%, var(--accent-hover) 100%);
  border-color: transparent; color: #fff;
}
.stat--hero .stat-label,
.stat--hero .stat-meta { color: rgba(255, 255, 255, 0.85); }
.stat--hero .stat-value { font-size: 34px; }
.stat--negative { background: linear-gradient(140deg, #b02a2a 0%, #8f2020 100%); }

.stat-dot {
  width: 9px; height: 9px; border-radius: 50%; flex: none;
  display: inline-block;
}

/* ------------------------------------------------------------- buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 15px;
  min-height: 40px;
  font: inherit; font-size: 14.5px; font-weight: 600;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-primary);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-sunken); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn--danger { background: var(--critical); border-color: var(--critical); color: #fff; }
.btn--danger:hover { background: #b02a2a; border-color: #b02a2a; color: #fff; }
.btn--ghost { background: transparent; border-color: transparent; color: var(--text-secondary); }
.btn--ghost:hover { background: var(--surface-sunken); color: var(--text-primary); }
.btn--outline { background: transparent; }
.btn--sm { min-height: 34px; padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn--block { display: flex; width: 100%; margin-top: 10px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* -------------------------------------------------------------- badges */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px;
  font-size: 12px; font-weight: 600;
  border-radius: var(--r-pill);
  background: var(--surface-sunken);
  color: var(--text-secondary);
  white-space: nowrap;
}
.badge--paid    { background: var(--good-wash);     color: var(--good-text); }
.badge--pending { background: var(--warning-wash);  color: #7a5600; }
.badge--in      { background: var(--good-wash);     color: var(--good-text); }
.badge--out     { background: var(--critical-wash); color: var(--critical-text); }
.badge--archived{ background: var(--surface-sunken); color: var(--text-muted); }
.badge--role    { background: var(--accent-wash);   color: var(--accent); }

/* "Pending" amber reads too dark on the dark surface — lift it to the status step. */
:root[data-theme="dark"] .badge--pending,
:root[data-theme="dark"] .segmented input:checked + label.seg-pending { color: var(--warning); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .badge--pending,
  :root:not([data-theme="light"]) .segmented input:checked + label.seg-pending { color: var(--warning); }
}

.badge-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; font-size: 12.5px; font-weight: 550;
  border-radius: var(--r-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  text-decoration: none;
}
.chip:hover { background: var(--surface-sunken); text-decoration: none; }
.chip.is-on { background: var(--accent-wash); border-color: var(--accent-border); color: var(--accent); }
.chip-row { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
.chip-row::-webkit-scrollbar { height: 0; }

/* --------------------------------------------------------------- forms */

.field { margin-bottom: 14px; }
.field > label,
.label {
  display: block;
  font-size: 13px; font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.req { color: var(--critical-text); }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="month"], input[type="search"], input[type="tel"],
select, textarea {
  width: 100%;
  font: inherit; font-size: 16px; /* 16px stops iOS zooming on focus */
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
}
textarea { min-height: 84px; resize: vertical; line-height: 1.5; }
select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath fill='%23898781' d='M1 1.5 6 6.5l5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 11px;
  padding-right: 34px;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-wash);
}
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] {
  border-color: var(--critical);
}
.field-error { color: var(--critical-text); font-size: 12.5px; margin-top: 5px; font-weight: 550; }
.field-hint  { color: var(--text-muted); font-size: 12.5px; margin-top: 5px; }

.input-money { position: relative; }
.input-money .cur {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); font-size: 15px; pointer-events: none;
}
.input-money input { padding-left: 30px; font-weight: 600; }

.grid-2 { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr; gap: 0 14px; }

.check-row {
  display: flex; align-items: flex-start; gap: 11px;
  padding: 12px; margin: 4px 0 14px;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface-2);
  cursor: pointer;
}
.check-row input { width: 19px; height: 19px; margin: 2px 0 0; flex: none; accent-color: var(--accent); }
.check-row span { display: block; }
.check-row .small { display: block; margin-top: 2px; }

.segmented {
  display: grid; grid-auto-flow: column; gap: 4px;
  background: var(--surface-sunken);
  border-radius: 11px; padding: 4px;
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label {
  text-align: center; padding: 8px 10px; border-radius: 8px;
  font-size: 14px; font-weight: 600; color: var(--text-secondary);
  cursor: pointer; margin: 0;
}
.segmented input:checked + label { background: var(--surface); color: var(--text-primary); box-shadow: var(--shadow-1); }
.segmented input:checked + label.seg-paid    { color: var(--good-text); }
.segmented input:checked + label.seg-pending { color: #7a5600; }

.form-actions {
  display: flex; gap: 10px; flex-wrap: wrap;
  padding-top: 6px;
}
.form-actions .btn { flex: 1 1 auto; }

/* ------------------------------------------------------- bill uploader */

.uploader {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface-2);
  padding: 16px;
  text-align: center;
}
.uploader.has-file { border-style: solid; text-align: left; }
.upload-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 12px; }
.upload-btn {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 14px 8px;
  border: 1px solid var(--border-strong); border-radius: 11px;
  background: var(--surface); color: var(--text-primary);
  font-size: 13.5px; font-weight: 600; cursor: pointer;
}
.upload-btn:hover { background: var(--surface-sunken); }
.upload-btn .ico { font-size: 22px; }
.uploader input[type="file"] { position: absolute; width: 1px; height: 1px; opacity: 0; }

.upload-preview { display: flex; gap: 12px; align-items: center; }
.upload-preview img {
  width: 76px; height: 76px; object-fit: cover;
  border-radius: 10px; border: 1px solid var(--border); flex: none;
}
.upload-preview .file-meta { min-width: 0; flex: 1; }
.upload-preview .file-name {
  font-weight: 600; font-size: 14px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.bill-thumb {
  width: 100%; max-width: 320px;
  border-radius: var(--r-md); border: 1px solid var(--border);
  cursor: zoom-in; display: block;
}
.bill-file {
  display: flex; align-items: center; gap: 11px;
  padding: 14px; border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface-2); text-decoration: none; color: var(--text-primary);
}
.bill-file .ico { font-size: 26px; }

/* ------------------------------------------------------------- tables */

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  text-align: left; font-size: 11.5px; font-weight: 650;
  text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 10px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
tfoot td {
  padding: 12px 14px; font-weight: 650;
  background: var(--surface-2);
  border-top: 1px solid var(--border-strong);
}
.t-primary { font-weight: 600; }
.t-sub { font-size: 12.5px; color: var(--text-muted); }

/* record list — the mobile-native alternative to a table */
.rec-list { display: flex; flex-direction: column; }
.rec {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  text-decoration: none; color: inherit;
}
.rec:last-child { border-bottom: none; }
.rec:hover { background: var(--surface-2); text-decoration: none; }

/* A row with its own delete control. The link and the button are siblings —
   a form cannot legally live inside the anchor that wraps the row. */
.rec-wrap {
  display: flex; align-items: stretch;
  border-bottom: 1px solid var(--border);
}
.rec-wrap:last-child { border-bottom: none; }
.rec-wrap:hover { background: var(--surface-2); }
.rec-wrap .rec { flex: 1; min-width: 0; border-bottom: none; }
.rec-wrap .rec:hover { background: none; }

.rec-del { display: flex; align-items: center; padding: 0 12px 0 4px; }
.rec-del button {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: 1px solid transparent;
  border-radius: 10px;
  background: none;
  color: var(--text-muted);
  font-size: 17px; line-height: 1;
  cursor: pointer;
}
.rec-del button:hover {
  background: var(--critical-wash);
  border-color: rgba(208, 59, 59, 0.35);
  color: var(--critical-text);
}
.rec-icon {
  width: 38px; height: 38px; flex: none;
  border-radius: 11px; display: grid; place-items: center;
  font-size: 17px; background: var(--surface-sunken);
}
.rec-main { flex: 1; min-width: 0; }
.rec-title {
  font-weight: 600; font-size: 14.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rec-sub {
  font-size: 12.5px; color: var(--text-muted);
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  margin-top: 1px;
}
.rec-sub .sep { opacity: 0.5; }
.rec-amount { text-align: right; flex: none; }
.rec-amount .amt { font-weight: 650; font-size: 15px; font-variant-numeric: tabular-nums; }
.rec-amount .sub { font-size: 11.5px; color: var(--text-muted); }
.rec-clip { font-size: 12px; color: var(--text-muted); }

/* ---------------------------------------------------------- data views */

.dl { display: grid; grid-template-columns: 1fr; gap: 0; }
.dl-row {
  display: flex; justify-content: space-between; gap: 16px;
  padding: 11px 0; border-bottom: 1px solid var(--border);
}
.dl-row:last-child { border-bottom: none; }
.dl-key { color: var(--text-secondary); font-size: 13.5px; flex: none; }
.dl-val { text-align: right; font-weight: 550; min-width: 0; overflow-wrap: anywhere; }

.kv-strip {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 1px; background: var(--border);
  border-radius: var(--r-md); overflow: hidden;
}
.kv-strip > div { background: var(--surface); padding: 12px 14px; }
.kv-strip .k { font-size: 11.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.kv-strip .v { font-weight: 650; font-size: 16px; font-variant-numeric: tabular-nums; margin-top: 2px; }

/* -------------------------------------------------------------- filters */

.filters { padding: 14px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.filter-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
.filter-grid .field { margin-bottom: 0; }
.filter-actions { display: flex; gap: 8px; margin-top: 12px; }
.filter-summary {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 13px; color: var(--text-secondary);
  padding: 10px 16px; border-bottom: 1px solid var(--border);
}
details.filter-panel > summary {
  list-style: none; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; font-weight: 600; font-size: 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
details.filter-panel > summary::-webkit-details-marker { display: none; }
details.filter-panel > summary::after { content: "▾"; margin-left: auto; color: var(--text-muted); }
details.filter-panel[open] > summary::after { content: "▴"; }

/* period (month / date range) selector */
.period-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
  padding: 10px 12px;
  margin-bottom: 12px;
}
.period-row { display: flex; align-items: center; gap: 10px; }
.period-icon { font-size: 16px; flex: none; }
.period-row select { flex: 1; min-height: 40px; font-size: 15px; padding: 8px 34px 8px 10px; }
.period-custom {
  margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--border);
  display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap;
}
/* An author `display` beats the UA stylesheet's [hidden] rule, so the hidden
   attribute has to be honoured explicitly or the date fields never collapse. */
.period-custom[hidden] { display: none; }
.period-dates { display: flex; gap: 10px; flex: 1 1 auto; min-width: 0; }
.period-dates label { flex: 1; min-width: 0; }
.period-dates span {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--text-secondary); margin-bottom: 4px;
}
.period-dates input { min-height: 40px; }

/* the "you are looking at X" strip above a set of totals */
.period-note {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 13px; color: var(--text-secondary);
  margin: 0 2px 10px;
}
.period-note .chip { pointer-events: none; }

.pagination {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 13px; color: var(--text-secondary);
}
.pagination .pages { display: flex; gap: 6px; }

/* ------------------------------------------------------------ messages */

.flash-stack { position: sticky; top: var(--topbar-h); z-index: 25; padding: 10px 0 0; }
.flash {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px; margin-bottom: 10px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  font-size: 14px; font-weight: 500;
}
.flash .ico { flex: none; font-size: 16px; line-height: 1.3; }
.flash--success { background: var(--good-wash);     border-color: rgba(12, 163, 12, 0.35); }
.flash--error   { background: var(--critical-wash); border-color: rgba(208, 59, 59, 0.35); }
.flash--warning { background: var(--warning-wash);  border-color: rgba(250, 178, 25, 0.4); }
.flash--info    { background: var(--accent-wash);   border-color: var(--accent-border); }
.flash-close { margin-left: auto; background: none; border: none; cursor: pointer; color: inherit; opacity: 0.6; font-size: 16px; }

.callout {
  padding: 13px 15px; border-radius: var(--r-md);
  border: 1px solid var(--border); background: var(--surface-2);
  font-size: 14px; margin-bottom: 14px;
}
.callout--warn  { background: var(--warning-wash);  border-color: rgba(250, 178, 25, 0.4); }
.callout--error { background: var(--critical-wash); border-color: rgba(208, 59, 59, 0.35); }
.callout--info  { background: var(--accent-wash);   border-color: var(--accent-border); }

.empty {
  text-align: center; padding: 42px 22px; color: var(--text-secondary);
}
.empty .ico { font-size: 34px; display: block; margin-bottom: 10px; opacity: 0.55; }
.empty h3 { margin-bottom: 5px; }

/* --------------------------------------------------------------- charts */

.dv-figure { min-width: 0; }
.dv-donut-wrap { display: grid; place-items: center; padding: 6px 0 12px; }
.dv-donut-value { font-size: 21px; font-weight: 680; fill: var(--text-primary); }
.dv-donut-label { font-size: 11px; fill: var(--text-muted); letter-spacing: 0.03em; }
.dv-arc { transition: opacity 0.12s ease; }
.dv-donut:hover .dv-arc { opacity: 0.45; }
.dv-donut .dv-arc:hover { opacity: 1; }

.dv-legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-bottom: 12px; }
.dv-legend-item { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text-secondary); }
.dv-legend-label { color: var(--text-secondary); }
.dv-legend-value { font-weight: 650; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.dv-legend-meta  { color: var(--text-muted); font-size: 12px; }
.dv-key { width: 10px; height: 10px; border-radius: 3px; flex: none; display: inline-block; }
.dv-key--line { height: 3px; border-radius: 2px; width: 14px; }

.dv-bars { display: flex; flex-direction: column; gap: 13px; }
.dv-bar-row { min-width: 0; }
.dv-bar-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 5px; }
.dv-bar-label {
  display: flex; align-items: center; gap: 7px;
  font-size: 13.5px; color: var(--text-secondary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dv-bar-value {
  margin-left: auto; font-size: 13.5px; font-weight: 650;
  color: var(--text-primary); font-variant-numeric: tabular-nums; flex: none;
}
.dv-bar-meta { font-size: 11.5px; color: var(--text-muted); margin-top: 3px; }
.dv-track { height: 10px; background: var(--surface-sunken); border-radius: 5px; overflow: hidden; }
.dv-fill {
  height: 100%; border-radius: 0 4px 4px 0; position: relative;
  min-width: 3px;
}
.dv-tip {
  position: absolute; left: 0; bottom: 14px;
  background: var(--text-primary); color: var(--page);
  font-size: 12px; padding: 4px 8px; border-radius: 6px;
  white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity 0.12s;
  z-index: 5;
}
.dv-bar-row:hover .dv-tip { opacity: 1; }

.dv-line-wrap { position: relative; width: 100%; }
.dv-line, .dv-cols { width: 100%; height: auto; display: block; overflow: visible; }
.dv-grid { stroke: var(--grid); stroke-width: 1; }
.dv-baseline { stroke: var(--axis); stroke-width: 1; }
.dv-axis-text { font-size: 11px; fill: var(--text-muted); font-family: var(--font); }
.dv-crosshair { stroke: var(--axis); stroke-width: 1; pointer-events: none; }
.dv-hit { cursor: crosshair; }
.dv-seg { transition: opacity 0.12s ease; }
.dv-cols:hover .dv-seg { opacity: 0.5; }
.dv-cols .dv-seg:hover { opacity: 1; }

.dv-tooltip {
  position: absolute; z-index: 8; pointer-events: none;
  background: var(--surface); color: var(--text-primary);
  border: 1px solid var(--border-strong); border-radius: 9px;
  box-shadow: var(--shadow-2);
  padding: 9px 11px; font-size: 12.5px; min-width: 148px;
  transform: translate(-50%, -100%);
}
.dv-tooltip .tt-title { font-weight: 650; margin-bottom: 5px; }
.dv-tooltip .tt-row { display: flex; align-items: center; gap: 7px; }
.dv-tooltip .tt-row .v { margin-left: auto; font-weight: 650; font-variant-numeric: tabular-nums; }

.dv-table { margin-top: 14px; }
.dv-table > summary {
  cursor: pointer; font-size: 12.5px; color: var(--text-secondary);
  padding: 6px 0; font-weight: 550;
}
.dv-table table { font-size: 13px; margin-top: 6px; }
.dv-table thead th, .dv-table tbody td { padding: 7px 10px; }
.dv-empty {
  padding: 34px 16px; text-align: center;
  color: var(--text-muted); font-size: 13.5px;
  background: var(--surface-2); border-radius: var(--r-md);
}

.chart-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }

/* ------------------------------------------------------------- lightbox */

.lightbox {
  position: fixed; inset: 0; z-index: 90;
  background: var(--overlay);
  display: none; align-items: center; justify-content: center;
  padding: 16px;
}
.lightbox.is-open { display: flex; }
.lightbox img {
  max-width: 100%; max-height: 88vh;
  border-radius: var(--r-md); box-shadow: var(--shadow-3);
  object-fit: contain;
}
.lightbox-bar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; color: #fff;
  background: linear-gradient(rgba(0, 0, 0, 0.55), transparent);
  font-size: 14px;
}
.lightbox-bar a, .lightbox-bar button {
  color: #fff; background: rgba(255, 255, 255, 0.16);
  border: none; border-radius: 8px; padding: 7px 12px;
  font: inherit; font-size: 13px; cursor: pointer; text-decoration: none;
}
.lightbox-bar .spacer { margin-left: auto; }

/* ---------------------------------------------------------- auth screens */

.auth-body {
  display: grid; place-items: center; min-height: 100vh;
  padding: 24px 16px;
  background:
    radial-gradient(1100px 460px at 50% -10%, var(--accent-wash), transparent 70%),
    var(--page);
}
.auth-shell, .install-shell { width: 100%; max-width: 440px; }
.install-shell { max-width: 560px; }
.auth-head, .install-head {
  display: flex; align-items: center; gap: 13px;
  margin-bottom: 20px;
}
.auth-head h1, .install-head h1 { font-size: 20px; }
.auth-foot { text-align: center; margin-top: 18px; font-size: 12.5px; color: var(--text-muted); }

.check-list { list-style: none; margin: 0 0 10px; padding: 0; }
.check-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 14px;
}
.check-list li:last-child { border-bottom: none; }
.check-icon {
  width: 22px; height: 22px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #fff;
}
.check-list .ok  .check-icon { background: var(--good); }
.check-list .bad .check-icon { background: var(--critical); }
.check-detail {
  margin-left: auto; font-size: 12px; color: var(--text-muted);
  max-width: 46%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.success-title { color: var(--good-text); margin-bottom: 8px; }
.cred-box {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 12px 14px; margin: 12px 0;
  display: grid; gap: 6px;
}
.cred-box > div { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }

/* -------------------------------------------------------------- reports */

.report-month-nav {
  display: flex; align-items: center; gap: 8px;
  overflow-x: auto; padding-bottom: 6px;
}
.total-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 11px 0; border-bottom: 1px solid var(--border); font-size: 14.5px;
}
.total-row:last-child { border-bottom: none; }
.total-row.is-total { font-weight: 680; font-size: 16px; border-top: 2px solid var(--border-strong); border-bottom: none; padding-top: 13px; }
.total-row .amt { font-variant-numeric: tabular-nums; font-weight: 650; }

/* ---------------------------------------------------------------- misc */

.progress-track { height: 8px; background: var(--surface-sunken); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 0 4px 4px 0; background: var(--accent); }

.audit-item { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.audit-item:last-child { border-bottom: none; }
.audit-meta { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.audit-diff { font-size: 12.5px; color: var(--text-secondary); margin-top: 6px; }
.audit-diff code { font-size: 11.5px; }

/* ------------------------------------------------------------ responsive */

@media (min-width: 560px) {
  .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .filter-grid { grid-template-columns: 1fr 1fr; }
  .kv-strip { grid-template-columns: repeat(4, 1fr); }
  .form-actions .btn { flex: 0 0 auto; min-width: 150px; }
}

@media (min-width: 900px) {
  body { font-size: 15px; }
  .sidebar { display: block; }
  .app { padding-left: var(--sidebar-w); }
  .tabbar, .fab { display: none; }
  .main { padding: 22px 26px 60px; max-width: 1320px; }
  .topbar { padding: 0 26px; height: 64px; }
  .flash-stack { top: 64px; }
  .stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
  .stat--hero { grid-column: span 2; }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .filter-grid { grid-template-columns: repeat(4, 1fr); }
  .chart-grid { grid-template-columns: 1fr 1fr; }
  .chart-grid .span-2 { grid-column: 1 / -1; }
  h1 { font-size: 24px; }
}

@media (min-width: 1180px) {
  .stat-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}

/* --------------------------------------------------------------- print */

@media print {
  .sidebar, .topbar, .tabbar, .fab, .filters, .filter-panel,
  .page-actions, .pagination, .btn, .dv-table, .flash-stack { display: none !important; }
  .app { padding: 0; }
  .main { padding: 0; max-width: none; }
  .card { break-inside: avoid; box-shadow: none; border-color: #ccc; }
  body { background: #fff; font-size: 12px; }
  a { color: inherit; text-decoration: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
