/*
  Dime Intercompany. One stylesheet, brand from dimeaccounting.com, calmer use of it.
  Rules for every screen:
  - Colors, fonts, radii, shadows and spacing come from the tokens below. Nothing hardcoded.
  - Purple is for AI only (phase 8 "AI decides" mode and Claude evidence).
  - A status color always comes with a text label.
  - Small text never uses --green; it uses --green-dark. --green is for buttons, bars and large accents.
  - One Playfair page title per screen. Everything else is Plus Jakarta Sans.
*/

@font-face {
  font-family: 'Plus Jakarta Sans';
  src: url('fonts/plus-jakarta-sans-latin.woff2') format('woff2');
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Playfair Display';
  src: url('fonts/playfair-display-latin.woff2') format('woff2');
  font-weight: 700 900;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  /* Brand */
  --green: #31A449;
  --green-dark: #27873C;
  --green-light: #EBF6ED;
  --black: #0D0D0D;
  --ink: #1A1A1A;
  --stone: #5A5A5A;
  --border: #E5E5E5;
  --mist: #F5F5F5;
  --white: #FFFFFF;

  /* AI only */
  --ai-purple: #6D28D9;
  --ai-purple-bg: #F5F3FF;
  --ai-purple-border: #DDD6FE;

  /* Status */
  --warn: #B45309;
  --warn-bg: #FEF3C7;
  --danger: #B91C1C;
  --danger-bg: #FEE2E2;

  /* Type */
  --font-display: 'Playfair Display', Georgia, serif;
  --font-body: 'Plus Jakarta Sans', Arial, sans-serif;
  --text-body: 15px;
  --text-small: 13px;
  --text-label: 12px;
  --text-eyebrow: 11px;
  --text-title: 30px;

  /* 8px spacing scale */
  --space-half: 4px;
  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 32px;
  --space-5: 40px;
  --space-6: 48px;
  --space-8: 64px;

  /* Shape */
  --radius: 8px;
  --radius-card: 12px;
  --radius-pill: 20px;
  --shadow-card: 0 8px 32px rgba(0, 0, 0, 0.07);
  --focus-ring: 0 0 0 2px var(--green);

  /* Layout */
  --max: 1160px;
  --topbar-h: 72px;
  --bottombar-h: 64px;

  color-scheme: light;
}

/* Base */

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

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

body {
  margin: 0;
  background: var(--mist);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--text-body);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { color: var(--black); margin: 0; }

h2 { font-size: 18px; font-weight: 700; line-height: 1.4; }

h3 { font-size: var(--text-body); font-weight: 700; }

p { margin: 0; }

a { color: var(--green-dark); }

img { display: block; max-width: 100%; }

code {
  font-family: var(--font-body);
  font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
}

:focus-visible { outline: none; box-shadow: var(--focus-ring); }

[hidden] { display: none !important; }

.num { font-variant-numeric: tabular-nums; }

.muted, .secondary {
  color: var(--stone);
  font-size: var(--text-small);
}

.stack { display: grid; gap: var(--space-2); }

.stack-lg { display: grid; gap: var(--space-3); }

/* Page title and eyebrow */

.page-head { display: grid; gap: var(--space-1); margin-bottom: var(--space-3); }

.page-title {
  font-family: var(--font-display);
  font-size: var(--text-title);
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1.2;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  color: var(--green-dark);
  font-size: var(--text-eyebrow);
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.eyebrow::before {
  content: '';
  width: 28px;
  height: 2px;
  background: var(--green);
}

/* Buttons */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  min-height: 48px;
  padding: 14px var(--space-3);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: var(--text-body);
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 120ms, border-color 120ms, transform 120ms;
}

.button:disabled { opacity: 0.55; cursor: default; transform: none; }

.button-primary {
  background: var(--green);
  border: 0;
  color: var(--white);
  font-weight: 700;
}

.button-primary:hover:not(:disabled) {
  background: var(--green-dark);
  transform: translateY(-1px);
}

.button-primary:active:not(:disabled) { background: var(--green-dark); transform: none; }

.button-secondary, .button-destructive {
  background: transparent;
  border: 2px solid var(--border);
  color: var(--ink);
  font-weight: 600;
  padding: 12px 22px;
}

.button-secondary:hover:not(:disabled),
.button-destructive:hover:not(:disabled) { border-color: var(--ink); }

.button-destructive { color: var(--danger); }

.button-destructive:hover:not(:disabled) { border-color: var(--danger); }

.button-text {
  background: none;
  border: 0;
  padding: 0;
  min-height: 0;
  color: var(--green-dark);
  font-size: var(--text-small);
  font-weight: 600;
}

.button-text:hover { text-decoration: underline; text-underline-offset: 3px; }

.button-block { width: 100%; }

.button-row { display: flex; flex-wrap: wrap; gap: var(--space-2); }

/* Forms */

.field { display: grid; gap: var(--space-1); }

.field-label { font-size: var(--text-small); font-weight: 600; color: var(--ink); }

.field-help { font-size: var(--text-small); color: var(--stone); }

.input, .select {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--ink);
  font-family: inherit;
  font-size: 16px; /* 16px or more stops iOS zooming into the field */
  line-height: 1.4;
}

.input:focus, .select:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: var(--focus-ring);
}

.input[aria-invalid="true"] { border-color: var(--danger); }

.select {
  appearance: none;
  padding-right: var(--space-5);
  background-image: linear-gradient(45deg, transparent 50%, var(--stone) 50%), linear-gradient(135deg, var(--stone) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}

.input-code {
  font-size: 24px;
  letter-spacing: 6px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  padding-left: calc(14px + 6px); /* balance the trailing letter-spacing */
}

.form { display: grid; gap: var(--space-3); }

.form-error {
  padding: 12px 14px;
  background: var(--danger-bg);
  border-radius: var(--radius);
  color: var(--danger);
  font-size: var(--text-small);
  font-weight: 500;
}

/* Cards */

.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--space-3);
}

.card .card { box-shadow: none; } /* no stacked shadows */

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.card-flush { padding: 0; overflow: hidden; }

/* Status pills. Always text plus color, never color alone. */

.pill {
  display: inline-flex;
  align-items: center;
  padding: var(--space-half) 10px;
  border-radius: var(--radius-pill);
  font-size: var(--text-label);
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
  background: var(--mist);
  color: var(--stone);
}

.pill-posted { background: var(--green-light); color: var(--green-dark); }

.pill-held, .pill-needs-input { background: var(--warn-bg); color: var(--warn); }

.pill-half-posted, .pill-lapsed { background: var(--danger-bg); color: var(--danger); }

.pill-ai {
  background: var(--ai-purple-bg);
  color: var(--ai-purple);
  box-shadow: inset 0 0 0 1px var(--ai-purple-border);
}

/* Tables */

.table { width: 100%; border-collapse: collapse; }

.table th {
  background: var(--mist);
  color: var(--stone);
  font-size: var(--text-label);
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  text-align: left;
  padding: 12px var(--space-2);
  white-space: nowrap;
}

.table td {
  padding: 14px var(--space-2);
  border-top: 1px solid var(--border);
  vertical-align: middle;
}

.table tbody tr:hover { background: var(--mist); }

.table .num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }

.table .row-held td:first-child { box-shadow: inset 3px 0 0 var(--warn); }

.table .row-half-posted td:first-child { box-shadow: inset 3px 0 0 var(--danger); }

.cell-main { font-weight: 600; color: var(--ink); }

.cell-sub { display: block; font-size: var(--text-small); color: var(--stone); font-weight: 400; }

/* Phone: each row becomes a two-line block. Cells name their slot:
   line 1 is title and amount, line 2 is meta and status. */
@media (max-width: 640px) {
  .table thead { display: none; }
  .table, .table tbody { display: block; }
  .table tr {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas: "title amount" "meta status";
    gap: var(--space-half) var(--space-2);
    padding: 14px var(--space-2);
    border-top: 1px solid var(--border);
  }
  .table tbody tr:first-child { border-top: 0; }
  .table td { display: block; padding: 0; border: 0; }
  .table .slot-title { grid-area: title; }
  .table .slot-amount { grid-area: amount; }
  .table .slot-meta { grid-area: meta; font-size: var(--text-small); color: var(--stone); }
  .table .slot-status { grid-area: status; justify-self: end; }
  .table .row-held { box-shadow: inset 3px 0 0 var(--warn); }
  .table .row-half-posted { box-shadow: inset 3px 0 0 var(--danger); }
  .table .row-held td:first-child, .table .row-half-posted td:first-child { box-shadow: none; }
}

/* Empty state */

.empty {
  display: grid;
  justify-items: start;
  gap: var(--space-2);
  padding: var(--space-5) var(--space-3);
}

.empty p { max-width: 36rem; }

/* Auth screens (login, MFA enroll, MFA code) */

.auth {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--space-3) var(--space-2);
}

.auth-card { width: 100%; max-width: 420px; padding: var(--space-4) var(--space-3); }

.auth-brand {
  display: grid;
  justify-items: center;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
}

.auth-brand img { width: 160px; height: auto; }

.auth-wordmark {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--black);
  line-height: 1.2;
}

.auth-head { display: grid; gap: var(--space-1); margin-bottom: var(--space-3); }

.auth-head h2 { font-size: 20px; }

.auth-foot { margin-top: var(--space-3); text-align: center; }

.steps { display: grid; gap: var(--space-3); margin: 0; padding: 0; list-style: none; counter-reset: step; }

.steps > li { display: grid; gap: var(--space-2); counter-increment: step; }

.step-title { display: flex; align-items: center; gap: var(--space-1); font-weight: 600; }

.step-title::before {
  content: counter(step);
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--green-light);
  color: var(--green-dark);
  font-size: var(--text-label);
  font-weight: 700;
}

.qr {
  width: 184px;
  height: 184px;
  padding: var(--space-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--white);
  justify-self: center;
}

.secret {
  display: block;
  padding: var(--space-1) 12px;
  background: var(--mist);
  border-radius: var(--radius);
  color: var(--ink);
  font-size: var(--text-small);
  word-break: break-all;
}

/* App shell */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--white);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: var(--max);
  height: var(--topbar-h);
  margin: 0 auto;
  padding: 0 var(--space-3);
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.brand-mark { display: block; flex: none; }

.brand-mark img { height: 48px; width: auto; }

.nav {
  display: flex;
  align-items: stretch;
  gap: var(--space-1);
  margin-left: auto;
  height: 100%;
}

.nav a {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0 12px;
  color: var(--stone);
  font-size: var(--text-body);
  font-weight: 500;
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.nav a:hover { color: var(--ink); }

.nav a[aria-current="page"] {
  color: var(--green-dark);
  font-weight: 600;
  border-bottom-color: var(--green);
}

.nav svg { display: none; }

.topbar .sign-out { flex: none; }

.page {
  max-width: var(--max);
  margin: 0 auto;
  padding: var(--space-5) var(--space-3) var(--space-8);
}

/* Phone: nav moves to a bottom bar, reachable with a thumb. */
@media (max-width: 760px) {
  :root { --text-title: 28px; --topbar-h: 56px; }

  .topbar-inner { padding: 0 var(--space-2); justify-content: space-between; }

  .brand-mark img { height: 40px; }

  .nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    height: auto;
    margin: 0;
    gap: 0;
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--white);
    border-top: 1px solid var(--border);
  }

  .nav a {
    flex: 1;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    min-height: var(--bottombar-h);
    padding: 0;
    font-size: var(--text-eyebrow);
    font-weight: 600;
    border-bottom: 0;
    margin: 0;
  }

  .nav a[aria-current="page"] { color: var(--green-dark); box-shadow: inset 0 2px 0 var(--green); }

  .nav svg { display: block; width: 22px; height: 22px; }

  .page { padding: var(--space-3) var(--space-2) calc(var(--bottombar-h) + env(safe-area-inset-bottom) + var(--space-4)); }

  .card { padding: var(--space-2); }

  .empty { padding: var(--space-3) var(--space-2); }

  .auth-card { padding: var(--space-3) var(--space-2); }

  .button-row .button { flex: 1; }
}

/* Style guide page only */

.guide-section { display: grid; gap: var(--space-2); margin-bottom: var(--space-5); }

.guide-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }

.swatch {
  display: grid;
  gap: var(--space-half);
  width: 132px;
  font-size: var(--text-label);
}

.swatch span:first-child {
  height: 56px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.sw-green { background: var(--green); }
.sw-green-dark { background: var(--green-dark); }
.sw-green-light { background: var(--green-light); }
.sw-black { background: var(--black); }
.sw-ink { background: var(--ink); }
.sw-stone { background: var(--stone); }
.sw-border { background: var(--border); }
.sw-mist { background: var(--mist); }
.sw-white { background: var(--white); }
.sw-warn { background: var(--warn); }
.sw-warn-bg { background: var(--warn-bg); }
.sw-danger { background: var(--danger); }
.sw-danger-bg { background: var(--danger-bg); }
.sw-ai { background: var(--ai-purple); }
.sw-ai-bg { background: var(--ai-purple-bg); }
