/* =========================================================================
   The Pro Accountants — Statement Analysis dashboard
   Design system: navy (#1E2356) primary dark tone, blue gradient
   (#2F5FE0 -> #5B8DEF) accent. Light and dark palettes are each designed
   deliberately around the brand, not inverted from one another.
   ========================================================================= */

:root {
  /* brand constants (same in both themes) */
  --brand-navy: #1E2356;
  --brand-navy-2: #2A2F6B;
  --grad-a: #2F5FE0;
  --grad-b: #5B8DEF;
  --brand-gradient: linear-gradient(120deg, #2F5FE0 0%, #5B8DEF 100%);

  /* status semantics */
  --ok: #16A34A;      --ok-bg: #E7F6ED;      --ok-ring: #16A34A33;
  --warn: #C77A08;    --warn-bg: #FDF3E0;    --warn-ring: #D9770633;
  --bad: #DC2626;     --bad-bg: #FCEBEB;     --bad-ring: #DC262633;

  --radius: 14px;
  --radius-sm: 10px;
  --ease: cubic-bezier(.4, 0, .2, 1);
  --shadow-sm: 0 1px 2px rgba(20, 26, 60, .06), 0 1px 3px rgba(20, 26, 60, .08);
  --shadow-md: 0 4px 12px rgba(20, 26, 60, .08), 0 2px 6px rgba(20, 26, 60, .06);
  --shadow-lg: 0 12px 32px rgba(20, 26, 60, .14);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

/* ---- LIGHT (default) ---- */
:root[data-theme="light"] {
  --bg: #EEF2FA;
  --surface: #FFFFFF;
  --surface-2: #F7F9FE;
  --sidebar-bg: #FFFFFF;
  --ink: #1E2356;          /* headings */
  --ink-2: #464C74;        /* body */
  --ink-3: #7A80A3;        /* muted */
  --border: #E3E8F4;
  --border-strong: #CED6EA;
  --logo-ink: #1E2356;
  --dropzone-bg: #F7F9FE;
  --dropzone-hover: #EFF4FF;
  --scrim: rgba(20, 26, 60, .38);
  --code-bg: #F0F3FB;
}

/* ---- DARK (deliberate navy palette, not an inversion) ---- */
:root[data-theme="dark"] {
  --bg: #0E1124;
  --surface: #171B36;
  --surface-2: #1E2445;
  --sidebar-bg: #12162E;
  --ink: #EAEDFA;
  --ink-2: #AEB5D6;
  --ink-3: #7E86AD;
  --border: #272D52;
  --border-strong: #333A63;
  --logo-ink: #EAEDFA;
  --dropzone-bg: #1A1F3E;
  --dropzone-hover: #1F2650;
  --scrim: rgba(4, 6, 18, .6);
  --code-bg: #1B2143;
  --ok-bg: #123122;    --warn-bg: #362813;    --bad-bg: #3A1A1C;
  --ok: #34D399;       --warn: #F0A93B;       --bad: #F87171;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, .35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink-2);
  -webkit-font-smoothing: antialiased;
  transition: background .3s var(--ease), color .3s var(--ease);
}

.app { display: flex; min-height: 100vh; }

/* ============================ SIDEBAR ============================ */
.sidebar {
  width: 288px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 20px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  transition: transform .28s var(--ease), background .3s var(--ease);
}

.brand { display: flex; gap: 13px; align-items: flex-start; padding: 0 4px 22px; }
.brand-mark { width: 46px; height: 46px; flex-shrink: 0; }
.brand-words { padding-top: 2px; }
.brand-name {
  font-weight: 800;
  font-size: 17px;
  line-height: 1.05;
  letter-spacing: .06em;
  color: var(--ink);
}
.grad-text {
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand-tagline {
  margin-top: 6px;
  font-size: 11px;
  letter-spacing: .04em;
  color: var(--grad-a);
  font-weight: 600;
}
:root[data-theme="dark"] .brand-tagline { color: var(--grad-b); }

.history { flex: 1; display: flex; flex-direction: column; min-height: 0; margin-top: 6px; }
.history-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-3);
  padding: 8px 6px 10px;
}
.history-list { list-style: none; overflow-y: auto; flex: 1; margin: 0 -6px; padding: 0 6px; }
.history-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s var(--ease);
  border: 1px solid transparent;
}
.history-item:hover { background: var(--surface-2); }
.history-item.active { background: var(--surface-2); border-color: var(--border); }
.history-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.history-dot.verified { background: var(--ok); }
.history-dot.caution { background: var(--warn); }
.history-dot.review { background: var(--bad); }
.history-meta { min-width: 0; flex: 1; }
.history-bank {
  font-size: 13px; font-weight: 600; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.history-time { font-size: 11px; color: var(--ink-3); margin-top: 1px; }
.history-empty { font-size: 12.5px; color: var(--ink-3); padding: 4px 8px; }

.device-note {
  display: flex; align-items: center; gap: 7px;
  margin-top: 14px; padding: 11px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 11.5px; color: var(--ink-3);
}
.device-note svg { flex-shrink: 0; opacity: .8; }

.link-btn {
  background: none; border: none; padding: 0; cursor: pointer;
  color: var(--grad-a); font: inherit; font-weight: 600; font-size: inherit;
}
.link-btn:hover { text-decoration: underline; }
:root[data-theme="dark"] .link-btn { color: var(--grad-b); }
.history-head .link-btn { font-size: 11px; text-transform: none; letter-spacing: 0; }

/* ============================ MAIN ============================ */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 18px 30px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
  transition: background .3s var(--ease), border-color .3s var(--ease);
}
.topbar-title { flex: 1; }
.topbar-title h1 { font-size: 19px; font-weight: 700; color: var(--ink); letter-spacing: -.01em; }
.topbar-title p { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; }

.icon-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
  transition: all .15s var(--ease);
}
.icon-btn:hover { color: var(--ink); border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.menu-btn { display: none; }

.theme-btn .icon-moon { display: none; }
:root[data-theme="dark"] .theme-btn .icon-sun { display: none; }
:root[data-theme="dark"] .theme-btn .icon-moon { display: block; }

.content { padding: 30px; max-width: 900px; width: 100%; margin: 0 auto; }

/* ============================ DROPZONE ============================ */
.dropzone {
  border: 2px dashed var(--border-strong);
  background: var(--dropzone-bg);
  border-radius: var(--radius);
  padding: 40px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color .18s var(--ease), background .18s var(--ease), transform .18s var(--ease);
  outline: none;
}
.dropzone:hover, .dropzone:focus-visible { background: var(--dropzone-hover); border-color: var(--grad-a); }
.dropzone.dragover {
  border-color: var(--grad-a);
  background: var(--dropzone-hover);
  box-shadow: 0 0 0 4px var(--ok-ring), 0 0 0 4px color-mix(in srgb, var(--grad-a) 22%, transparent);
  transform: translateY(-1px);
}
.dropzone-inner { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.dropzone-icon {
  width: 60px; height: 60px; border-radius: 16px;
  display: grid; place-items: center;
  background: var(--brand-gradient);
  color: #fff;
  box-shadow: 0 8px 18px color-mix(in srgb, var(--grad-a) 35%, transparent);
}
.dropzone-text strong { display: block; font-size: 16px; color: var(--ink); font-weight: 650; }
.dropzone-text span { display: block; font-size: 13px; color: var(--ink-3); margin-top: 4px; }

/* ============================ RESULTS / CARDS ============================ */
.results { margin-top: 22px; display: flex; flex-direction: column; gap: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  animation: rise .32s var(--ease) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.card-head {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 18px;
}
.card-fileicon {
  width: 42px; height: 42px; border-radius: 11px; flex-shrink: 0;
  display: grid; place-items: center;
  background: var(--surface-2); color: var(--grad-a);
  border: 1px solid var(--border);
}
.card-headmeta { flex: 1; min-width: 0; }
.card-bank { font-size: 16px; font-weight: 680; color: var(--ink); line-height: 1.2; }
.card-sub {
  font-size: 12.5px; color: var(--ink-3); margin-top: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* status badge */
.badge {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 12px 6px 10px;
  border-radius: 999px;
  font-size: 12px; font-weight: 700; letter-spacing: .01em;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; }
.badge.verified { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-ring); }
.badge.verified::before { background: var(--ok); }
.badge.caution { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-ring); }
.badge.caution::before { background: var(--warn); }
.badge.review { background: var(--bad-bg); color: var(--bad); border-color: var(--bad-ring); }
.badge.review::before { background: var(--bad); }

.card-body { padding: 0 18px 18px; }
.meta-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px 18px;
  padding: 14px 0;
  border-top: 1px solid var(--border);
}
.meta-item .meta-label {
  font-size: 10.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--ink-3);
}
.meta-item .meta-value { font-size: 13.5px; color: var(--ink); font-weight: 550; margin-top: 3px; }

.explanation {
  font-size: 12.5px; line-height: 1.55; color: var(--ink-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-top: 4px;
}
.explanation.review { border-left: 3px solid var(--bad); }
.explanation.caution { border-left: 3px solid var(--warn); }
.explanation.verified { border-left: 3px solid var(--ok); }

.sheets-note {
  font-size: 11.5px; color: var(--ink-3); margin-top: 12px; line-height: 1.5;
}
.sheets-note a { color: var(--grad-a); text-decoration: none; }
.sheets-note a:hover { text-decoration: underline; }
:root[data-theme="dark"] .sheets-note a { color: var(--grad-b); }

.drive-block {
  display: flex; align-items: center; gap: 8px;
  margin-top: 12px; padding: 9px 12px; border-radius: 10px;
  font-size: 12.5px; line-height: 1.4; border: 1px solid var(--border);
}
.drive-block.ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-ring); }
.drive-block.fail { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-ring); }
.drive-block svg { flex: none; }
.drive-block a { color: inherit; font-weight: 650; text-decoration: underline; }
.drive-block a:hover { opacity: .8; }

.card-actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px; border-radius: 11px;
  font: inherit; font-weight: 600; font-size: 13.5px;
  cursor: pointer; border: 1px solid transparent;
  transition: all .15s var(--ease);
}
.btn-primary { background: var(--brand-gradient); color: #fff; box-shadow: 0 6px 14px color-mix(in srgb, var(--grad-a) 30%, transparent); }
.btn-primary:hover { filter: brightness(1.05); transform: translateY(-1px); box-shadow: 0 8px 20px color-mix(in srgb, var(--grad-a) 38%, transparent); }
.btn-ghost { background: var(--surface-2); color: var(--ink-2); border-color: var(--border); }
.btn-ghost:hover { color: var(--ink); border-color: var(--border-strong); }
.btn:disabled { opacity: .55; cursor: default; transform: none; box-shadow: none; filter: none; }

/* ---- processing state ---- */
.card.processing .card-head { padding-bottom: 16px; }
.progress-wrap { padding: 0 18px 18px; }
.progress-label {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12.5px; color: var(--ink-2); margin-bottom: 8px;
}
.progress-label .phase { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.progress-track { height: 7px; border-radius: 99px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--border); }
.progress-fill {
  height: 100%; border-radius: 99px;
  background: var(--brand-gradient);
  width: 0%;
  transition: width .25s var(--ease);
}
.progress-fill.indeterminate {
  width: 40% !important;
  animation: indet 1.15s var(--ease) infinite;
}
@keyframes indet {
  0% { margin-left: -40%; }
  100% { margin-left: 100%; }
}

.spinner {
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--grad-a) 30%, transparent);
  border-top-color: var(--grad-a);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.warn-list { margin-top: 10px; font-size: 11.5px; color: var(--ink-3); }
.warn-list li { margin-left: 16px; margin-top: 2px; }

/* ============================ BATCH (COMBINED) CARD ============================ */
.batch-section-title {
  margin-top: 16px; font-size: 11px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--ink-3);
}
.batch-months { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.batch-month {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 12px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px;
}
.batch-month-name { font-size: 13px; color: var(--ink); font-weight: 550; }
.mini-badge {
  font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 99px;
  border: 1px solid transparent; white-space: nowrap;
}
.mini-badge.verified { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-ring); }
.mini-badge.caution { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-ring); }
.mini-badge.review { background: var(--bad-bg); color: var(--bad); border-color: var(--bad-ring); }
.batch-files { list-style: none; margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.batch-files li { display: flex; gap: 10px; align-items: baseline; font-size: 12px; color: var(--ink-2); }
.file-status {
  flex: none; font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .03em; padding: 2px 7px; border-radius: 6px;
  min-width: 66px; text-align: center;
}
.file-status.processed { background: var(--ok-bg); color: var(--ok); }
.file-status.duplicate, .file-status.not_pdf { background: var(--warn-bg); color: var(--warn); }
.file-status.unreadable { background: var(--bad-bg); color: var(--bad); }
.file-detail { color: var(--ink-2); }

/* ============================ RESPONSIVE ============================ */
@media (max-width: 820px) {
  .menu-btn { display: grid; }
  .sidebar {
    position: fixed; z-index: 40; left: 0; top: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 35; }
  .content { padding: 20px 16px; }
  .topbar { padding: 14px 16px; }
}

/* Narrow cards: the badge (which can be as long as "RECONCILED
   (AI-EXTRACTED)") drops to its own line under the bank name rather than
   overflowing the card's right edge. Header text fills the rest of line 1
   next to the 42px file icon, which forces the badge to wrap. */
@media (max-width: 560px) {
  .card-head { flex-wrap: wrap; }
  .card-headmeta { flex: 1 1 calc(100% - 56px); }
  .badge { order: 3; margin-left: 56px; }
}

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