/* Sava console styling.
 *
 * Design tokens, component classes, and the light/dark variable split are carried over
 * from the SmileSet Intelligence Hub so the two apps read as one family. Written as
 * plain CSS rather than Tailwind: this is one page, and a build step would mean putting
 * a Node toolchain on a box with ~1 GB of free memory to compile it.
 */

/* ─── Theme variables ──────────────────────────────────────────────────────── */
:root {
  --bg:       #F8FAF9;
  --bg2:      #F8FAF9;
  --surface:  #ffffff;
  --surface2: #F1F5F4;
  --border1:  rgba(0,0,0,0.07);
  --border2:  rgba(0,0,0,0.12);
  --text:     #1C2030;
  --text2:    #495753;
  --muted:    #9AA0B2;
  --muted2:   #C5CAD4;
  --scrollbar:#D1D9D6;
  --grain:    rgba(0,0,0,0.02);
  --blue:     #138DFF;
  --accent:   #138DFF;
  --c-green:  #16A34A;
  --c-red:    #DC2626;
  --c-amber:  #D97706;
  --green-badge-bg: #ECFDF3; --green-badge-text: #067647; --green-badge-border: #ABEFC6;
  --amber-badge-bg: #FFFAEB; --amber-badge-text: #B54708; --amber-badge-border: #FEDF89;
  --red-badge-bg:   #FEF3F2; --red-badge-text:   #B42318; --red-badge-border:   #FECDCA;
}

:root[data-theme="dark"] {
  --bg:       #0E1116;
  --bg2:      #0E1116;
  --surface:  #141619;
  --surface2: #1F242E;
  --border1:  rgba(255,255,255,0.08);
  --border2:  rgba(255,255,255,0.15);
  --text:     #E7E9EF;
  --text2:    #AAB1C0;
  --muted:    #7C8494;
  --muted2:   #AAB1C0;
  --scrollbar:rgba(255,255,255,0.15);
  --grain:    rgba(255,255,255,0.015);
  --blue:     #3B9BFF;
  --accent:   #3B9BFF;
  --c-green:  #5FD08A;
  --c-red:    #F5897F;
  --c-amber:  #F5A623;
  --green-badge-bg: #10261A; --green-badge-text: #5FD08A; --green-badge-border: #1E5436;
  --amber-badge-bg: #2A2110; --amber-badge-text: #F5A623; --amber-badge-border: #5A4424;
  --red-badge-bg:   #2A1414; --red-badge-text:   #F5897F; --red-badge-border:   #5A2424;
}

/* ─── Base ─────────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }
html, body, #root { height: 100%; margin: 0; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', 'Syne', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background .2s, color .2s;
}
::-webkit-scrollbar { width: 3px; height: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 2px; }
.num-display { font-family: 'Epilogue', 'Syne', sans-serif; }

/* ─── Shell ────────────────────────────────────────────────────────────────── */
.shell { display: flex; height: 100%; overflow: hidden; background: var(--bg); }

.sidebar {
  width: 224px; flex-shrink: 0; display: flex; flex-direction: column;
  background: var(--bg2); border-right: 1px solid var(--border1);
  position: relative;
}
.sidebar-grain {
  position: absolute; inset: 0; pointer-events: none;
  background-image: repeating-linear-gradient(-45deg, transparent, transparent 2px,
                    var(--grain) 2px, var(--grain) 4px);
}
.brand {
  display: flex; align-items: center; gap: 10px; padding: 20px;
  border-bottom: 1px solid var(--border1); position: relative; z-index: 1;
}
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 16px;
  background: linear-gradient(135deg, #3B9BFF, #0C6FE8);
  box-shadow: 0 0 16px rgba(59,155,255,.3); color: #fff;
}
.brand-name { font-weight: 800; font-size: 14px; letter-spacing: -.3px; color: var(--text); }
.brand-sub {
  font-family: 'Space Mono', monospace; font-size: 8px; letter-spacing: 2.5px;
  color: var(--blue); text-transform: uppercase;
}
.nav { flex: 1; overflow-y: auto; padding: 8px 10px; position: relative; z-index: 1; }
.nav-section-label {
  font-family: 'Space Mono', monospace; font-size: 8px; letter-spacing: 2px;
  color: var(--muted); text-transform: uppercase; padding: 8px 10px;
}
.nav-item {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 7px;
  cursor: pointer; color: var(--text2); font-size: 12.5px; font-weight: 500;
  transition: all .14s; position: relative; margin-bottom: 1px; user-select: none;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: rgba(59,155,255,.1); color: var(--blue); font-weight: 600; }
.nav-item.active::after {
  content: ''; position: absolute; left: 0; top: 6px; bottom: 6px; width: 2px;
  background: var(--blue); border-radius: 0 2px 2px 0;
}
.nav-item.disabled { opacity: .38; cursor: not-allowed; }
.nav-item.disabled:hover { background: transparent; color: var(--text2); }
.sidebar-foot {
  border-top: 1px solid var(--border1); padding: 12px; position: relative; z-index: 1;
  display: flex; align-items: center; gap: 8px;
}
.avatar {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface2); border: .5px solid var(--border2);
  font-size: 11px; font-weight: 600; color: var(--text2);
}
.foot-name { font-size: 11.5px; font-weight: 500; color: var(--text); line-height: 1.25; }
.foot-sub  { font-size: 9.5px; color: var(--muted); }

/* ─── Main ─────────────────────────────────────────────────────────────────── */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  height: 52px; flex-shrink: 0; display: flex; align-items: center; gap: 12px;
  padding: 0 20px; border-bottom: 1px solid var(--border1); background: var(--surface);
}
.topbar-title { font-family: 'Epilogue','Syne',sans-serif; font-size: 15px; font-weight: 500; }
.spacer { flex: 1; }
.content { flex: 1; overflow-y: auto; padding: 22px 24px 40px; }

.icon-btn {
  width: 30px; height: 30px; border-radius: 7px; border: .5px solid var(--border1);
  background: var(--surface); color: var(--text2); cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 14px;
  transition: all .14s; padding: 0;
}
.icon-btn:hover { background: var(--surface2); color: var(--text); }

/* ─── Section headers ──────────────────────────────────────────────────────── */
.sec-label {
  font-size: 10px; font-weight: 500; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 3px;
}
.sec-title {
  font-family: 'Epilogue','Syne',sans-serif; font-size: 18px; font-weight: 500;
  color: var(--text); margin-bottom: 2px;
}
.sec-sub { font-size: 11px; color: var(--muted); margin-bottom: 16px; }

/* ─── KPI cards ────────────────────────────────────────────────────────────── */
.kpi-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
  gap: 10px; margin-bottom: 20px;
}
.kpi {
  background: var(--surface); border: .5px solid var(--border1); border-radius: 12px;
  padding: 14px 16px;
}
.kpi.primary { border-color: rgba(59,155,255,.35); }
.kpi-lbl {
  font-size: 11px; color: var(--muted); margin-bottom: 5px;
  display: flex; align-items: center; gap: 4px;
}
.kpi-val {
  font-family: 'Epilogue','Syne',sans-serif; font-size: 21px; font-weight: 500;
  letter-spacing: -.5px; color: var(--text); line-height: 1.15;
}
.kpi.primary .kpi-val { font-size: 26px; color: var(--text); }
.kpi-cmp { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* ─── Card ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: .5px solid var(--border1); border-radius: 12px;
  overflow: hidden;
}
.card-pad { padding: 16px 18px; }
.card-head {
  padding: 11px 16px; border-bottom: .5px solid var(--border1); background: var(--surface2);
  display: flex; align-items: center; gap: 8px;
}
.card-label { font-size: 11px; font-weight: 500; color: var(--text); flex: 1; }

/* ─── Filters ──────────────────────────────────────────────────────────────── */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label {
  font-size: 9px; letter-spacing: 1.2px; text-transform: uppercase; color: var(--muted);
}
.field input, .field select {
  background: var(--bg); color: var(--text); border: .5px solid var(--border2);
  border-radius: 7px; padding: 6px 9px; font-size: 12px; font-family: inherit;
  min-width: 132px; outline: none; transition: border-color .14s;
}
.field input:focus, .field select:focus { border-color: var(--blue); }
.btn {
  background: var(--surface2); color: var(--text); border: .5px solid var(--border2);
  border-radius: 7px; padding: 7px 13px; font-size: 12px; font-weight: 500;
  font-family: inherit; cursor: pointer; transition: all .14s;
}
.btn:hover { border-color: var(--blue); color: var(--blue); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { opacity: .9; color: #fff; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 9px;
  border-radius: 20px; font-size: 10.5px; font-weight: 500;
  background: var(--surface2); border: .5px solid var(--border2); color: var(--text2);
  cursor: pointer; transition: all .14s;
}
.chip:hover { border-color: var(--blue); color: var(--blue); }
.chip.active { background: rgba(59,155,255,.12); border-color: var(--blue); color: var(--blue); }

/* ─── Table ────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.ih-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.ih-table th {
  text-align: left; padding: 8px 12px; background: var(--surface2); color: var(--text2);
  font-family: 'Syne', sans-serif; font-size: 11px; font-weight: 500;
  border-bottom: .5px solid var(--border2); white-space: nowrap;
  cursor: pointer; user-select: none; position: sticky; top: 0; z-index: 2;
}
.ih-table th:hover { color: var(--text); }
.ih-table th.numeric, .ih-table td.numeric { text-align: right; }
.ih-table th .sort-arrow { color: var(--blue); margin-left: 3px; font-size: 9px; }
.ih-table td {
  padding: 7px 12px; border-bottom: .5px solid var(--border1); color: var(--text);
  white-space: nowrap; font-size: 11px; vertical-align: top;
}
.ih-table tbody tr:hover td { background: var(--surface2); }
.ih-table tfoot td {
  padding: 9px 12px; background: var(--surface2); font-weight: 600;
  border-top: .5px solid var(--border2); border-bottom: none;
  position: sticky; bottom: 0;
}
.col-name {
  font-weight: 500; min-width: 220px; max-width: 440px;
  overflow: hidden; text-overflow: ellipsis;
}
/* The description truncates on its own so a long item name cannot push the inline
   note out of the row. */
.item-desc {
  display: inline-block; max-width: 250px; overflow: hidden;
  text-overflow: ellipsis; vertical-align: bottom;
}
.col-mono { font-family: 'Space Mono', monospace; font-size: 10px; color: var(--text2); }
.col-muted { color: var(--muted); }
.row-clickable { cursor: pointer; }

.badge {
  font-size: 9px; font-weight: 500; padding: 2px 6px; border-radius: 4px; white-space: nowrap;
  display: inline-block;
}
.badge-ok    { background: var(--green-badge-bg); color: var(--green-badge-text);
               border: .5px solid var(--green-badge-border); }
.badge-warn  { background: var(--amber-badge-bg); color: var(--amber-badge-text);
               border: .5px solid var(--amber-badge-border); }
.badge-muted { background: var(--surface2); color: var(--muted); border: .5px solid var(--border2); }

.icon-btn.danger:hover { color: var(--c-red); border-color: var(--c-red); }
.btn.danger { background: var(--c-red); border-color: var(--c-red); color: #fff; }
.btn.danger:hover { opacity: .9; color: #fff; }

/* Inline confirm rather than a modal: a destructive step should say what it does,
   and there is room to say it here. */
.confirm-box {
  background: var(--red-badge-bg); border: .5px solid var(--red-badge-border);
  border-radius: 10px; padding: 14px 16px; margin-bottom: 16px;
}
.confirm-title {
  font-family: 'Epilogue','Syne',sans-serif; font-size: 14px; font-weight: 500;
  color: var(--red-badge-text); margin-bottom: 6px;
}
.confirm-body { font-size: 11.5px; line-height: 1.55; color: var(--text2); margin-bottom: 12px; }
.confirm-actions { display: flex; gap: 8px; }

/* ─── Inline editing (items view) ─────────────────────────────────────────── */
.item-note {
  /* Inline, not block: a note on its own line doubles the height of every row in a
     long list, and comments are short. */
  display: inline-block; margin-left: 8px; font-size: 10px; color: var(--text2);
  cursor: text; max-width: 200px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; vertical-align: baseline;
}
.item-note.empty {
  /* display:none, not opacity:0. An invisible inline-block still takes part in
     layout, and a narrow one wrapped its placeholder text one character per line,
     making every row 122px tall. Removing it from layout cannot do that. */
  display: none;
  color: var(--muted2); font-style: italic;
}
tr:hover .item-note.empty { display: inline-block; }
.item-note:hover { color: var(--blue); }
.inline-input {
  background: var(--bg); color: var(--text); border: .5px solid var(--blue);
  border-radius: 5px; padding: 2px 6px; font-size: 10.5px; font-family: inherit;
  max-width: 220px; margin-left: 8px; outline: none;
}
.inline-input.wide { max-width: none; font-size: 12px; padding: 6px 9px; }
.inline-select {
  background: var(--bg); color: var(--text); border: .5px solid var(--blue);
  border-radius: 5px; padding: 2px 4px; font-size: 10.5px; font-family: inherit;
  outline: none; max-width: 170px;
}
.editable-cell { cursor: pointer; }
.editable-cell:hover { color: var(--blue); text-decoration: underline dotted; }
.row-busy { opacity: .5; pointer-events: none; }

/* Farm flag. The '?' marks a model guess that nobody has confirmed -- these figures
   can end up in a tax return, so an unreviewed flag must not look settled. */
.farm-cell { text-align: center; }
.farm-toggle { display: inline-flex; align-items: center; gap: 3px; cursor: pointer; }
.farm-toggle input { cursor: pointer; accent-color: var(--c-green); margin: 0; }
.guess-dot {
  font-size: 8px; font-weight: 700; color: var(--c-amber);
  border: .5px solid var(--c-amber); border-radius: 50%;
  width: 11px; height: 11px; display: inline-flex;
  align-items: center; justify-content: center; line-height: 1;
}
.kpi.farm { border-color: rgba(22,163,74,.35); }

.table-note {
  font-size: 10.5px; color: var(--muted); line-height: 1.5;
  border-top: .5px solid var(--border1);
}

/* ─── Evidence ─────────────────────────────────────────────────────────────── */
.evidence-text {
  font-size: 11.5px; line-height: 1.6; color: var(--text2);
  background: var(--surface2); border: .5px solid var(--border1);
  border-radius: 8px; padding: 10px 12px; white-space: pre-wrap;
  max-height: 260px; overflow-y: auto;
}
.evidence-img {
  width: 100%; border-radius: 9px; border: .5px solid var(--border2); display: block;
}
.evidence-audio { width: 100%; }
.evidence-details { margin-top: 8px; }
.evidence-details summary {
  font-size: 10.5px; color: var(--muted); cursor: pointer; margin-bottom: 6px;
}
.evidence-details summary:hover { color: var(--blue); }

/* ─── Quarantine ───────────────────────────────────────────────────────────── */
.quarantine-card { margin-bottom: 14px; }
.compare { display: flex; align-items: stretch; gap: 14px; flex-wrap: wrap; }
.compare-side {
  flex: 1; min-width: 200px; background: var(--surface2);
  border: .5px solid var(--border1); border-radius: 9px; padding: 12px 14px;
}
/* The held side is tinted so it is obvious at a glance which row is not counted. */
.compare-side.held {
  background: var(--amber-badge-bg); border-color: var(--amber-badge-border);
}
.compare-label {
  font-size: 9px; letter-spacing: 1.2px; text-transform: uppercase;
  color: var(--muted); margin-bottom: 6px;
}
.compare-merchant { font-size: 12.5px; font-weight: 500; margin-bottom: 4px; }
.compare-amount {
  font-size: 19px; font-weight: 500; letter-spacing: -.5px; margin-bottom: 4px;
}
.compare-meta { font-size: 10.5px; color: var(--muted); line-height: 1.5; }
.compare-arrow {
  display: flex; align-items: center; font-size: 10px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 1px;
}
.reason-list {
  margin: 0; padding-left: 18px; font-size: 11px; color: var(--text2); line-height: 1.7;
}

/* ─── Category manager ─────────────────────────────────────────────────────── */
.cat-row-inactive { opacity: .45; }
.cat-actions { display: flex; gap: 6px; justify-content: flex-end; }
.btn-sm { padding: 3px 8px; font-size: 10.5px; }

/* ─── States ───────────────────────────────────────────────────────────────── */
.empty { padding: 44px 20px; text-align: center; color: var(--muted); font-size: 12px; }
.empty-title { font-family: 'Epilogue','Syne',sans-serif; font-size: 14px;
               color: var(--text2); margin-bottom: 6px; }
.error-banner {
  background: var(--red-badge-bg); border: .5px solid var(--red-badge-border);
  color: var(--red-badge-text); border-radius: 9px; padding: 11px 14px;
  font-size: 12px; margin-bottom: 16px;
}
.skeleton {
  background: linear-gradient(90deg, var(--surface2) 25%, var(--border1) 50%, var(--surface2) 75%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 4px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ─── Login ────────────────────────────────────────────────────────────────── */
.login-wrap {
  height: 100%; display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 20px;
}
.login-card {
  background: var(--surface); border: .5px solid var(--border1); border-radius: 14px;
  padding: 34px 32px; width: 100%; max-width: 372px; text-align: center;
}
.login-card .brand-mark { margin: 0 auto 16px; width: 42px; height: 42px; font-size: 20px; }
.login-title { font-family: 'Epilogue','Syne',sans-serif; font-size: 19px; font-weight: 500;
               margin-bottom: 6px; }
.login-sub { font-size: 12px; color: var(--muted); margin-bottom: 22px; line-height: 1.55; }

/* ─── Drawer (expense detail) ──────────────────────────────────────────────── */
.drawer-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 60; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 100%);
  background: var(--surface); border-left: 1px solid var(--border1); z-index: 61;
  display: flex; flex-direction: column; animation: slidein .18s ease-out;
}
@keyframes slidein { from { transform: translateX(16px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer-head {
  padding: 15px 18px; border-bottom: .5px solid var(--border1);
  display: flex; align-items: center; gap: 10px;
}
.drawer-body { flex: 1; overflow-y: auto; padding: 18px; }
.detail-row {
  display: flex; justify-content: space-between; gap: 14px; padding: 6px 0;
  border-bottom: .5px solid var(--border1); font-size: 12px;
}
.detail-row .k { color: var(--muted); }
.detail-row .v { color: var(--text); text-align: right; font-weight: 500; }

@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 50; height: 100%; transform: translateX(-100%);
             transition: transform .2s; }
  .sidebar.open { transform: none; }
  .content { padding: 16px 14px 32px; }
}
