/* =========================================================================
   AKEFIN — Colors & Type
   Light theme primary; dark theme via [data-theme="dark"].
   ========================================================================= */

/* ---- Fonts ------------------------------------------------------------- */
/* Display serif (italic-leaning) — substitute for Plantin MT Pro */
@import url("https://fonts.googleapis.com/css2?family=Spectral:ital,wght@0,300;0,400;0,500;0,600;1,300;1,400;1,500&display=swap");
/* UI sans (Latin) */
@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@300;400;500;600;700&display=swap");
/* UI sans (Korean) — IBM Plex Sans KR for chrome, Pretendard for body */
@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+KR:wght@300;400;500;600;700&display=swap");
@import url("https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/static/pretendard.min.css");
/* Mono / data */
@import url("https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500;600;700&display=swap");

/* =========================================================================
   1. COLOR SYSTEM
   ========================================================================= */
:root {
  /* ---- Base neutrals (light) ------------------------------------------- */
  --bg:           #ECE7DC; /* cream paper — primary page */
  --bg-deep:      #E2DCCC; /* recessed cream — sidebar / panels */
  --surface:      #EBEEF1; /* cool pale ink-grey — code/data blocks */
  --surface-deep: #DEE3E8; /* recessed ink-grey */
  --paper:        #F5F1E8; /* lifted paper — cards on cream */
  --black:        #1A1814; /* primary ink */

  /* ---- Foreground ramp ------------------------------------------------- */
  --fg:           #1A1814; /* primary text */
  --fg-strong:    #0A0907; /* headings */
  --fg-muted:     #5A5347; /* secondary text */
  --fg-subtle:    #8A8377; /* tertiary / metadata */
  --fg-faint:     #B5AE9F; /* placeholder / disabled */
  --fg-on-ink:    #2A2E33; /* text on --surface */
  --fg-on-ink-muted: #6B7178;

  /* ---- Structural ------------------------------------------------------ */
  --rule:         #D5CFC2; /* hairline on cream */
  --rule-ink:     #D7DCE2; /* hairline on ink-grey */
  --rule-strong:  #B5AE9F;
  --focus:        #3A6FB0; /* focus ring */
  --selection:    rgba(58, 111, 176, 0.18);

  /* ---- Grid texture --------------------------------------------------- */
  --grid-line:    rgba(26, 24, 20, 0.045);
  --grid-step:    24px;
  --bg-translucent: rgba(236, 231, 220, 0.92);

  /* ---- Confidence spectrum (semantic) --------------------------------- */
  --conf-rules:   #2F7D55; /* Tier 1, deterministic rules — forest green */
  --conf-rules-bg: #DCE9DF;
  --conf-high:    #2A6FB0; /* Tier 2 LLM ≥0.85 — blue */
  --conf-high-bg: #DCE5EE;
  --conf-mid:     #B5740A; /* Tier 2/3 0.70–0.85 — amber */
  --conf-mid-bg:  #EFE2C8;
  --conf-low:     #B8362B; /* <0.70 or unmatched — red */
  --conf-low-bg:  #ECD5D1;

  /* ---- Entity hues (badge accent ONLY — never page tint) -------------- */
  --entity-personal: #3D6E70; /* slate teal */
  --entity-personal-bg: #DCE5E5;
  --entity-9tfox:    #B4541A; /* rust orange */
  --entity-9tfox-bg: #EFDDCB;
  --entity-finacode: #5A4FA3; /* indigo */
  --entity-finacode-bg: #DEDAEE;

  /* ---- Signed amounts ------------------------------------------------- */
  --amount-pos:   #2F7D55; /* income / credit */
  --amount-neg:   #1A1814; /* expense / debit — neutral ink */
  --amount-warn:  #B8362B; /* unbalanced / error */

  /* ---- Interactive ---------------------------------------------------- */
  --link:         #2A6FB0;
  --link-hover:   #1A4F8A;
  --btn-bg:       #1A1814;
  --btn-fg:       #ECE7DC;
  --btn-bg-hover: #2A2620;
  --btn-ghost-hover: rgba(26, 24, 20, 0.06);

  /* ---- Shadow --------------------------------------------------------- */
  --shadow-pop: 0 1px 0 rgba(20,18,12,.04), 0 8px 24px -8px rgba(20,18,12,.16);
  --shadow-inset-press: inset 0 1px 0 rgba(20,18,12,.18);

  /* ---- Radius --------------------------------------------------------- */
  --r-sm: 2px;
  --r-md: 3px;
  --r-lg: 4px;
  --r-pill: 999px;

  /* ---- Spacing scale (4px base) --------------------------------------- */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 40px;
  --s-8: 56px;

  /* ---- Row densities (review queue, tables) --------------------------- */
  --row-compact: 32px;
  --row-default: 40px;
  --row-roomy:   48px;

  /* ---- Motion --------------------------------------------------------- */
  --ease: cubic-bezier(0.2, 0, 0.2, 1);
  --dur-fast: 80ms;
  --dur-mid: 140ms;
  --dur-slow: 220ms;
}

/* =========================================================================
   1b. DARK THEME (inverted; same hues, same hierarchy)
   ========================================================================= */
[data-theme="dark"] {
  --bg:           #13120F;
  --bg-deep:      #0C0B09;
  --surface:      #1B1E22;
  --surface-deep: #14171A;
  --paper:        #21201C; /* lifted paper on dark — visibly above bg */
  --fg:           #ECE7DC;
  --fg-strong:    #F5F1E8;
  --fg-muted:     #A29B8C;
  --fg-subtle:    #6F6A5E;
  --fg-faint:     #4C4940;
  --fg-on-ink:    #D5DAE0;
  --fg-on-ink-muted: #8A9098;
  --rule:         #2A2620;
  --rule-ink:     #2A2E33;
  --rule-strong:  #4C4940;
  --grid-line:    rgba(236, 231, 220, 0.04);
  --bg-translucent: rgba(19, 18, 15, 0.92);

  --conf-rules-bg: #1A2B22;
  --conf-high-bg:  #182434;
  --conf-mid-bg:   #2D2415;
  --conf-low-bg:   #2A1714;
  --entity-personal-bg: #1B2828;
  --entity-9tfox-bg:    #2A1B0F;
  --entity-finacode-bg: #1F1B30;

  --btn-bg:       #ECE7DC;
  --btn-fg:       #1A1814;
  --btn-bg-hover: #D5CFC2;
  --btn-ghost-hover: rgba(236, 231, 220, 0.06);
}

/* =========================================================================
   2. TYPE SYSTEM
   ========================================================================= */
:root {
  --font-display: "Spectral", "Plantin MT Pro", "Source Serif Pro", Georgia, serif;
  --font-sans:    "IBM Plex Sans", "IBM Plex Sans KR", "Pretendard", system-ui, -apple-system, sans-serif;
  --font-sans-kr: "Pretendard", "IBM Plex Sans KR", "IBM Plex Sans", system-ui, sans-serif;
  --font-mono:    "JetBrains Mono", "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* Latin type ramp */
  --t-display-xl: 56px;
  --t-display-l:  40px;
  --t-display-m:  28px;
  --t-h1:         22px;
  --t-h2:         18px;
  --t-h3:         15px;
  --t-body:       14px;
  --t-body-sm:    13px;
  --t-caption:    12px;
  --t-eyebrow:    11px;

  /* Mono ramp (data) */
  --t-mono-amount: 14px;
  --t-mono-table:  13px;
  --t-mono-code:   13px;
  --t-mono-meta:   12px;

  /* Line heights */
  --lh-display: 1.1;
  --lh-heading: 1.25;
  --lh-body:    1.45;
  --lh-mono:    1.4;
  --lh-tight:   1.2;
}

/* ---- Reset-ish defaults ------------------------------------------------ */
html {
  font-family: var(--font-sans);
  font-size: var(--t-body);
  line-height: var(--lh-body);
  color: var(--fg);
  background: var(--bg);
  font-feature-settings: "ss01", "cv11"; /* IBM Plex stylistic alts */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
body { margin: 0; }
::selection { background: var(--selection); }

/* =========================================================================
   3. SEMANTIC TYPE CLASSES
   ========================================================================= */
.display-xl, .display-l, .display-m {
  font-family: var(--font-display);
  font-weight: 400;
  font-style: italic;
  color: var(--fg-strong);
  line-height: var(--lh-display);
  letter-spacing: -0.01em;
  margin: 0;
}
.display-xl { font-size: var(--t-display-xl); }
.display-l  { font-size: var(--t-display-l); }
.display-m  { font-size: var(--t-display-m); }

h1, .h1 {
  font-family: var(--font-sans);
  font-size: var(--t-h1);
  font-weight: 500;
  line-height: var(--lh-heading);
  color: var(--fg-strong);
  margin: 0;
  letter-spacing: -0.005em;
}
h2, .h2 {
  font-family: var(--font-sans);
  font-size: var(--t-h2);
  font-weight: 500;
  line-height: var(--lh-heading);
  color: var(--fg-strong);
  margin: 0;
}
h3, .h3 {
  font-family: var(--font-sans);
  font-size: var(--t-h3);
  font-weight: 600;
  line-height: var(--lh-heading);
  color: var(--fg-strong);
  margin: 0;
}

p, .p {
  font-family: var(--font-sans);
  font-size: var(--t-body);
  line-height: var(--lh-body);
  color: var(--fg);
  margin: 0 0 var(--s-3);
}

.body-sm  { font-size: var(--t-body-sm); line-height: var(--lh-body); }
.caption  { font-size: var(--t-caption); color: var(--fg-muted); line-height: var(--lh-body); }
.muted    { color: var(--fg-muted); }
.subtle   { color: var(--fg-subtle); }

/* The pi.dev-style chrome label */
.eyebrow, .label-up {
  font-family: var(--font-mono);
  font-size: var(--t-eyebrow);
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg-muted);
}

/* Mono / data */
code, .mono, .code {
  font-family: var(--font-mono);
  font-size: var(--t-mono-code);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum", "zero", "ss02";
}
.amount {
  font-family: var(--font-mono);
  font-size: var(--t-mono-amount);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum", "zero";
  font-weight: 500;
  text-align: right;
  white-space: nowrap;
  color: var(--fg);
}
.amount.pos { color: var(--amount-pos); }
.amount.pos::before { content: "+ "; }
.amount.neg::before { content: "− "; }
.amount .ccy { color: var(--fg-subtle); margin-left: 0.4em; font-weight: 400; }

/* Korean text helper */
.ko, [lang="ko"] {
  font-family: var(--font-sans-kr);
  font-feature-settings: normal;
  letter-spacing: -0.005em;
}

/* Link */
a, .link {
  color: var(--link);
  text-decoration: none;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
  transition: color var(--dur-fast) var(--ease);
}
a:hover, .link:hover { color: var(--link-hover); text-decoration: underline; }

/* =========================================================================
   4. GRID BACKGROUND (load-bearing motif — apply to body or page wrapper)
   ========================================================================= */
.grid-bg {
  background-color: var(--bg);
  background-image:
    linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
  background-size: var(--grid-step) var(--grid-step);
}

/* =========================================================================
   5. PRIMITIVES — used everywhere
   ========================================================================= */

/* Hairline rule */
.hr { border: 0; border-top: 1px solid var(--rule); margin: 0; }
.hr-ink { border: 0; border-top: 1px solid var(--rule-ink); margin: 0; }

/* Card (1px border, 2-4px radius, no shadow) */
.card {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  padding: var(--s-4);
}

/* Terminal / data frame (the pi.dev look) */
.term {
  background: var(--surface);
  border: 1px solid var(--rule-ink);
  border-radius: var(--r-sm);
  font-family: var(--font-mono);
  font-size: var(--t-mono-code);
  color: var(--fg-on-ink);
  padding: var(--s-3) var(--s-4);
  position: relative;
}
.term-title {
  font-family: var(--font-mono);
  font-size: var(--t-eyebrow);
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg-on-ink-muted);
  padding: var(--s-2) var(--s-4);
  border-bottom: 1px solid var(--rule-ink);
  display: flex;
  align-items: center;
  gap: var(--s-2);
}
.term-title::after {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--conf-rules);
  margin-left: auto;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  height: 32px;
  padding: 0 var(--s-3);
  font-family: var(--font-mono);
  font-size: var(--t-eyebrow);
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
  user-select: none;
}
.btn:hover { background: var(--btn-ghost-hover); }
.btn:active { transform: scale(0.99); box-shadow: var(--shadow-inset-press); }
.btn.primary {
  background: var(--btn-bg);
  color: var(--btn-fg);
  border-color: var(--btn-bg);
}
.btn.primary:hover { background: var(--btn-bg-hover); }
.btn.bracket::before { content: "[ "; }
.btn.bracket::after  { content: " ]"; }
.btn.bracket { border: none; padding: 0; height: auto; background: transparent; }
.btn.bracket:hover { background: transparent; color: var(--fg-strong); }

/* Chips */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 20px;
  padding: 0 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  border-radius: var(--r-pill);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.chip.rules  { background: var(--conf-rules-bg); color: var(--conf-rules); }
.chip.high   { background: var(--conf-high-bg);  color: var(--conf-high); }
.chip.mid    { background: var(--conf-mid-bg);   color: var(--conf-mid); }
.chip.low    { background: var(--conf-low-bg);   color: var(--conf-low); }

/* Entity badge */
.entity-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 20px;
  padding: 0 8px 0 6px;
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--fg);
}
.entity-badge::before {
  content: "";
  width: 4px;
  height: 12px;
  border-radius: 1px;
  background: var(--entity-personal);
}
.entity-badge.personal { background: var(--entity-personal-bg); color: var(--entity-personal); }
.entity-badge.personal::before { background: var(--entity-personal); }
.entity-badge.tfox     { background: var(--entity-9tfox-bg); color: var(--entity-9tfox); }
.entity-badge.tfox::before     { background: var(--entity-9tfox); }
.entity-badge.finacode { background: var(--entity-finacode-bg); color: var(--entity-finacode); }
.entity-badge.finacode::before { background: var(--entity-finacode); }

/* Tier badge */
.tier {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  border-radius: var(--r-sm);
  border: 1px solid currentColor;
  background: transparent;
}
.tier.rules     { color: var(--conf-rules); }
.tier.llm       { color: var(--conf-high); }
.tier.agent     { color: var(--conf-mid); }
.tier.unmatched { color: var(--conf-low); }

/* Inputs */
.input {
  height: 32px;
  padding: 0 10px;
  font-family: var(--font-sans);
  font-size: var(--t-body-sm);
  background: var(--bg);
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-sm);
  color: var(--fg);
  transition: border-color var(--dur-fast) var(--ease);
}
.input:focus { outline: 2px solid var(--focus); outline-offset: 1px; border-color: var(--focus); }
.input.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
