/* ==========================================================================
   MemoIQ design system — hand-rolled, dependency-free, server-rendered.
   Loaded on every page via base.html. No build step.
   Sections: tokens · reset/base · layout/chrome · typography · components
   (buttons, forms, tables, cards, alerts, badges, empty states) · portal
   · auth · print guard.
   ========================================================================== */

/* ── Design tokens ──────────────────────────────────────────────────────── */
:root {
  /* Brand: THE MEMO'S OWN LANGUAGE — the deck's deep Knollgate green,
     paper tint, serif display type and amber accents, so the product and
     its artifact read as one thing. */
  --brand:        #1C4E2E;
  --brand-700:    #143C22;
  --brand-050:    #F5FAF5;
  --accent:       #D68910;   /* the memo's amber */

  --ink:          #1C2A22;
  --text:         #2A362E;
  --muted:        #5C6B61;
  --faint:        #8B968E;

  --bg:           #ffffff;
  --surface:      #F6F8F6;
  --surface-2:    #EDF3EE;
  --border:       #E3E9E4;
  --border-strong:#C9D1CB;

  --success:      #1C4E2E;
  --success-bg:   #EAF4EC;
  --danger:       #C0392B;
  --danger-bg:    #FBECEA;
  --warn:         #8A5C00;
  --warn-bg:      #FCF3E3;

  --radius:       8px;
  --radius-sm:    5px;
  --shadow-sm:    0 1px 2px rgba(20, 40, 28, 0.06);
  --shadow:       0 2px 8px rgba(20, 40, 28, 0.08);
  --maxw:         64rem;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
          Arial, system-ui, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ── Reset / base ───────────────────────────────────────────────────────── */
*, *::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.5;
  color: var(--text);
  background: var(--surface);
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
hr { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }

/* ── App chrome (internal nav) ──────────────────────────────────────────── */
.app-nav {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.app-nav__inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
}
.app-nav__brand {
  font-family: var(--serif);
  font-weight: 700;
  color: var(--brand);
  letter-spacing: 0;
  font-size: 1.12rem;
}
.app-nav__brand:hover { text-decoration: none; }
.app-nav__links {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: center;
}
.app-nav__links a { color: var(--muted); font-weight: 500; font-size: 0.92rem; }
.app-nav__links a:hover { color: var(--brand); text-decoration: none; }
.app-nav__spacer { margin-left: auto; }
.app-nav__logout button {
  background: none;
  border: 1px solid var(--border-strong);
  color: var(--muted);
  padding: 0.35rem 0.7rem;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.app-nav__logout button:hover { background: var(--surface); color: var(--text); }

/* ── Main container ─────────────────────────────────────────────────────── */
.container {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}
.container--narrow { max-width: 42rem; }

.app-footer { max-width: var(--maxw); margin: 0 auto; width: 100%;
              padding: 1.5rem 1.25rem 2.5rem; color: var(--faint);
              font-size: 0.82rem; border-top: 1px solid var(--border);
              text-align: center; }
.app-footer a { color: var(--muted); }
.app-footer a:hover { color: var(--brand); }
.app-footer__sep { color: var(--border-strong); margin: 0 0.5rem; }

/* ── Typography ─────────────────────────────────────────────────────────── */
h1 { font-family: var(--serif); font-size: 1.65rem; line-height: 1.22;
     margin: 0 0 0.35rem; color: var(--brand); letter-spacing: 0; }
h2 { font-family: var(--serif); font-size: 1.25rem; margin: 1.75rem 0 0.5rem;
     color: var(--brand); }
h3 { font-family: var(--serif); font-size: 1.02rem; margin: 0 0 0.25rem;
     color: var(--ink); }
/* the memo's eyebrow kicker: small caps over a headline */
.eyebrow { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.09em;
           text-transform: uppercase; color: #3E7A55; margin-bottom: 0.15rem; }
.subtitle { color: var(--muted); margin: 0 0 1.5rem; font-size: 1rem; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.crumb { font-size: 0.9rem; margin-bottom: 1rem; }
.crumb a { color: var(--muted); }
.page-head { display: flex; align-items: flex-start; justify-content: space-between;
             gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head h1 { margin-bottom: 0; }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-block;
  font: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  line-height: 1.2;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-700); color: #fff; }
.btn-ghost { background: var(--bg); color: var(--text); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--surface); }
.btn-danger { background: var(--bg); color: var(--danger); border-color: var(--border-strong); }
.btn-danger:hover { background: var(--danger-bg); border-color: var(--danger); }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.82rem; }
.btn-block { display: block; width: 100%; text-align: center; }

/* ── Segmented on/off toggle (CSS-only; no JS) ────────────────────────────── */
/* Two radio inputs rendered as Include/Exclude buttons. The checked option
   lights up; deterministic on submit (value "1" = on, "0" = off). */
.toggle-group { display: inline-flex; border: 1px solid var(--border-strong);
                border-radius: var(--radius-sm); overflow: hidden; }
.toggle-group input[type="radio"] { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-group label { margin: 0; padding: 0.4rem 0.95rem; font-size: 0.85rem;
                      font-weight: 600; cursor: pointer; background: var(--bg);
                      color: var(--text); border-right: 1px solid var(--border-strong); }
.toggle-group label:last-of-type { border-right: 0; }
.toggle-group input[value="1"]:checked + label { background: var(--brand); color: #fff; }
.toggle-group input[value="0"]:checked + label { background: var(--danger-bg); color: var(--danger); }

/* ── Forms ──────────────────────────────────────────────────────────────── */
form { margin: 0; }
.field { margin-bottom: 1.1rem; }
.field > label { display: block; font-weight: 600; color: var(--text);
                 margin-bottom: 0.35rem; font-size: 0.9rem; }
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="url"], select, textarea {
  width: 100%;
  padding: 0.55rem 0.65rem;
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-050);
}
textarea { min-height: 8rem; resize: vertical; }
textarea.code, textarea.mono { font-family: var(--mono); font-size: 0.9rem; }
.help { color: var(--muted); font-size: 0.82rem; margin: 0.3rem 0 0; }
.errors { list-style: none; padding: 0; margin: 0.35rem 0 0; }
.errors li { color: var(--danger); font-size: 0.85rem; }
.form-actions { margin-top: 1.25rem; display: flex; gap: 0.6rem; align-items: center; }

/* ── Tables ─────────────────────────────────────────────────────────────── */
.table { width: 100%; border-collapse: collapse; background: var(--bg);
         border: 1px solid var(--border); border-radius: var(--radius);
         overflow: hidden; }
.table th, .table td { text-align: left; padding: 0.6rem 0.85rem;
                       border-bottom: 1px solid var(--border); font-size: 0.92rem; }
.table thead th { background: var(--brand); color: #fff;
                  font-weight: 600; font-size: 0.8rem; text-transform: uppercase;
                  letter-spacing: 0.05em; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface); }
.table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table .mono { font-family: var(--mono); font-size: 0.85rem; word-break: break-all; }

/* ── Cards / definition lists ───────────────────────────────────────────── */
.card { background: var(--bg); border: 1px solid var(--border);
        border-radius: var(--radius); box-shadow: var(--shadow-sm);
        padding: 1.5rem; margin-bottom: 1.25rem; }
.card--pad-lg { padding: 2rem; }
dl.kv { display: grid; grid-template-columns: minmax(8rem, 12rem) 1fr;
        gap: 0.5rem 1.25rem; margin: 0; }
dl.kv dt { font-weight: 600; color: var(--muted); font-size: 0.9rem; }
dl.kv dd { margin: 0; }
.section { border-top: 1px solid var(--border); padding-top: 1rem; margin-top: 1.25rem; }
.section:first-child { border-top: none; padding-top: 0; margin-top: 0; }
.prose { white-space: pre-wrap; line-height: 1.55; }

/* ── Alerts / banners ───────────────────────────────────────────────────── */
.alert { border: 1px solid var(--border); border-radius: var(--radius);
         padding: 0.9rem 1.1rem; margin-bottom: 1.25rem; font-size: 0.92rem; }
.alert strong { font-weight: 700; }
.alert-info    { background: var(--brand-050); border-color: #C9D9CC; color: var(--brand-700); }
.alert-success { background: var(--success-bg); border-color: #bfe3c9; color: var(--success); }
.alert-warn    { background: var(--warn-bg); border-color: #f0e0a8; color: var(--warn); }
.alert-error   { background: var(--danger-bg); border-color: #f2c4bf; color: var(--danger); }
.alert code { display: block; margin-top: 0.5rem; padding: 0.55rem 0.7rem;
              background: var(--bg); border: 1px solid var(--border);
              border-radius: var(--radius-sm); font-family: var(--mono);
              font-size: 0.85rem; word-break: break-all; color: var(--ink); }

/* ── Badges ─────────────────────────────────────────────────────────────── */
.badge { display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px;
         font-size: 0.78rem; font-weight: 600; line-height: 1.4; }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger  { background: var(--danger-bg); color: var(--danger); }
.badge-muted   { background: var(--surface-2); color: var(--muted); }

/* ── Empty states ───────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 2.5rem 1.5rem; color: var(--muted);
               background: var(--bg); border: 1px dashed var(--border-strong);
               border-radius: var(--radius); }
.empty-state h3 { color: var(--text); margin-bottom: 0.35rem; }
.empty-state p { margin: 0 0 1rem; }
.empty { color: var(--faint); }

/* ── Lists of links (simple index pages) ────────────────────────────────── */
.stack { display: flex; flex-direction: column; gap: 0.75rem; }
.row-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

/* ── Portal (external-facing) ───────────────────────────────────────────── */
.portal-shell { min-height: 100vh; display: flex; flex-direction: column;
                background: var(--surface); }
.portal-header { background: var(--ink); color: #fff; }
.portal-header__inner { max-width: 52rem; margin: 0 auto; padding: 1rem 1.5rem;
                        display: flex; align-items: center; gap: 0.6rem; }
.portal-header__brand { font-weight: 700; letter-spacing: -0.01em; font-size: 1.05rem; }
.portal-header__tag { color: #aeb8cc; font-size: 0.85rem; }
.portal-main { flex: 1; max-width: 52rem; width: 100%; margin: 0 auto;
               padding: 2rem 1.5rem 3rem; }
.portal-footer { max-width: 52rem; margin: 0 auto; width: 100%;
                 padding: 1.25rem 1.5rem 2.5rem; color: var(--faint);
                 font-size: 0.82rem; border-top: 1px solid var(--border); }
.portal-footer__legal { margin-top: 0.5rem; }
.portal-footer__legal span { color: var(--border-strong); margin: 0 0.4rem; }

/* ── Auth (centered card) ───────────────────────────────────────────────── */
/* Column layout: the card centers via margin:auto; the footer (a flex
   sibling rendered by base.html) sits below instead of beside the card. */
.auth-shell { min-height: 100vh; display: flex; flex-direction: column;
              padding: 2rem 1.25rem;
              background: linear-gradient(180deg, #faf9f5 0%, #f4f1ea 100%); }
.auth-shell main.auth-card { margin: auto; }
.auth-card { width: 100%; max-width: 25rem; background: #ffffff;
             border: 1px solid #e8e4d8; border-radius: 10px;
             box-shadow: 0 12px 32px rgba(11, 26, 44, 0.08); padding: 2.5rem 2.25rem; }
.auth-card__brand { text-align: center; font-family: Georgia, "Times New Roman", serif;
                    font-weight: 700; font-size: 1.65rem; letter-spacing: 0.04em;
                    color: #0b1a2c; margin-bottom: 0.3rem; }
.auth-card__brand .dot { color: #c8a44a; }
.auth-card__sub { text-align: center; color: #4a5a72; margin-bottom: 1.75rem;
                  font-size: 0.95rem; }
.auth-shell .field label { color: #0b1a2c; }
.auth-shell input:focus { border-color: #c8a44a; outline: none;
                          box-shadow: 0 0 0 3px rgba(200, 164, 74, 0.22); }
.auth-shell .btn-primary { background: #c8a44a; border-color: #c8a44a; color: #0b1a2c;
                           font-weight: 600; }
.auth-shell .btn-primary:hover { background: #e8d090; border-color: #e8d090; }
.auth-shell .app-footer { text-align: center; padding-top: 1rem; }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 36rem) {
  dl.kv { grid-template-columns: 1fr; gap: 0.15rem 0; }
  dl.kv dd { margin-bottom: 0.6rem; }
  .app-nav__inner { flex-wrap: wrap; gap: 0.6rem 1rem; }
  .page-head { flex-direction: column; }
}

/* Flash messages (rendered in base.html main) */
.flashes { margin: 0 0 1rem; display: flex; flex-direction: column; gap: 0.5rem; }
.flash { padding: 0.6rem 0.85rem; border-radius: 6px; font-size: 0.92rem; border: 1px solid; }
.flash--success { background: #f0f7f2; border-color: #1C4E2E; color: #143620; }
.flash--error { background: #fdf0ee; border-color: #C0392B; color: #7d2218; }
.flash--warn { background: #fdf6ec; border-color: #B7791F; color: #744210; }

/* Pure-CSS spinner for the memo "generating" state (no JS — CSP script-src 'self') */
.generating-row { display: flex; align-items: flex-start; gap: 1rem; }
.spinner { flex: none; width: 2.4rem; height: 2.4rem; border-radius: 50%;
  border: 4px solid #e8e4d8; border-top-color: #1C4E2E;
  animation: memoiq-spin 0.9s linear infinite; }
@keyframes memoiq-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

/* ── New Deal form — Knollgate dataroom visual parity ──────────────────────
   Scoped to `.deal-new` (set on <main>) so these styles never leak onto other
   pages. Recreates the legacy Knollgate look: near-white page, narrow centered
   column, green left-accent page title, serif uppercase card headings, green
   outlined Existing/New toggle pills, green primary CTA. Pure CSS — the app
   ships no JS (CSP script-src 'self'), so the legacy JS pill toggle is
   recreated with radio + label. Green continuity tokens are local here. */
.deal-new {
  --kw-green:     #1C4E2E;
  --kw-green-dk:  #14392a;
  --kw-green-bg:  #f5faf5;
  --kw-navy:      #002855;
  --kw-divider:   #e8e8e8;
  /* solid surface + own stacking context: no transparent/overlay bleed-through
     from any ancestor, predictable z-index for the form column. */
  position: relative;
  z-index: 0;
  background: var(--surface);
}
.deal-new .crumb a { color: var(--muted); }

/* Page header — green left-line accent, navy serif-ish title (the app has no
   serif webfont; use the system stack at the legacy weight/size). */
.deal-new .page-header {
  margin-bottom: 1.6rem;
  padding: 0.25rem 0 0.25rem 0.9rem;
  border-left: 4px solid var(--kw-green);
}
.deal-new .page-header h1 {
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--kw-navy);
  letter-spacing: -0.01em;
  margin: 0;
}
.deal-new .page-header .subtitle {
  color: var(--muted);
  font-size: 0.95rem;
  margin: 0.35rem 0 0;
}

/* Cards — solid white, numbered green serif-uppercase heading w/ divider. */
.deal-new .card { background: var(--bg); border: 1px solid var(--kw-divider); }
.deal-new .card-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--kw-green);
  margin: 0 0 0.9rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--kw-divider);
}

/* Existing / New company — green outlined toggle pills (CSS-only). The two
   radios are visually hidden; the checked one's label fills green. */
.deal-new .mode-pills { display: flex; gap: 0.4rem; margin-bottom: 1rem; }
.deal-new .mode-pills input[type="radio"] {
  position: absolute; opacity: 0; width: 0; height: 0;
}
.deal-new .mode-pills label {
  display: inline-block;
  padding: 0.4rem 1rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid transparent;
  cursor: pointer;
  user-select: none;
}
.deal-new .mode-pills input[type="radio"]:checked + label {
  background: var(--kw-green-bg);
  color: var(--kw-green);
  border-color: var(--kw-green);
}
.deal-new .mode-pills input[type="radio"]:focus-visible + label {
  outline: 2px solid var(--kw-green);
  outline-offset: 2px;
}

/* Compact professional inputs + focus ring in the green family. */
.deal-new .field { margin-bottom: 0.95rem; }
.deal-new .field > label {
  font-size: 0.82rem; font-weight: 600; color: var(--ink); margin-bottom: 0.3rem;
}
.deal-new .field input + input,
.deal-new .field input + label { margin-top: 0.45rem; }
.deal-new input:focus, .deal-new select:focus, .deal-new textarea:focus {
  border-color: var(--kw-green);
  box-shadow: 0 0 0 3px var(--kw-green-bg);
}
.deal-new .req { color: var(--danger); }

/* Inline radio/checkbox labels (Primary, Auto-send) read as one compact line. */
.deal-new .field label.inline {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-weight: 500; color: var(--text); font-size: 0.88rem; margin: 0;
}
.deal-new .field label.inline input { width: auto; margin: 0; }

/* Primary CTA in green; Cancel subdued; small side-effect note alongside. */
.deal-new .btn-primary { background: var(--kw-green); color: #fff; }
.deal-new .btn-primary:hover { background: var(--kw-green-dk); }
.deal-new .form-actions { flex-wrap: wrap; }
.deal-new .side-note {
  color: var(--faint); font-size: 0.8rem; margin-left: 0.4rem;
}

/* ── Deal lifecycle sub-nav (memo-styled) ─────────────────────────────────
   Grouped stage bar rendered under the app header on every deal-scoped
   page: PRE-TERM SHEET · DATA ROOM · IC MEMO · POST-CLOSE, each stage an
   eyebrow label over its pages. The active page carries the green rule —
   the same visual grammar as the memo's action titles. */
.deal-nav { background: var(--bg); border-bottom: 1.5px solid var(--brand); }
.deal-nav__inner { max-width: var(--maxw); margin: 0 auto;
                   padding: 0.55rem 1.25rem 0; display: flex; gap: 1.75rem;
                   flex-wrap: wrap; align-items: flex-end; }
.deal-nav__deal { font-family: var(--serif); font-weight: 700;
                  color: var(--brand); font-size: 0.98rem;
                  padding-bottom: 0.55rem; white-space: nowrap; }
.deal-nav__deal a { color: var(--brand); }
.deal-nav__group { display: flex; flex-direction: column; gap: 0.1rem; }
.deal-nav__stage { font-size: 0.62rem; font-weight: 700; letter-spacing: 0.09em;
                   text-transform: uppercase; color: var(--faint); }
.deal-nav__links { display: flex; gap: 0.9rem; }
.deal-nav__links a { color: var(--muted); font-size: 0.86rem; font-weight: 500;
                     padding: 0.15rem 0 0.5rem; border-bottom: 3px solid transparent;
                     white-space: nowrap; }
.deal-nav__links a:hover { color: var(--brand); text-decoration: none; }
.deal-nav__links a.active { color: var(--brand); font-weight: 700;
                            border-bottom-color: var(--brand); }

/* ── Memo-style stat band ────────────────────────────────────────────────
   Big serif numbers under small-caps labels — the deck's KPI grammar. */
.statband { display: flex; gap: 2rem; flex-wrap: wrap; margin: 0.5rem 0 1rem; }
.stat { min-width: 7rem; }
.stat__label { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.05em;
               text-transform: uppercase; color: var(--muted); }
.stat__value { font-family: var(--serif); font-size: 1.7rem; font-weight: 700;
               color: var(--brand); line-height: 1.15; }
.stat__sub { font-size: 0.75rem; color: var(--muted); }

/* ── Status chips (memo tag grammar) ─────────────────────────────────────── */
.chip { display: inline-block; font-size: 0.72rem; font-weight: 700;
        letter-spacing: 0.04em; padding: 0.12rem 0.55rem; border-radius: 10px;
        text-transform: uppercase; }
.chip--green { background: var(--success-bg); color: var(--brand); }
.chip--amber { background: var(--warn-bg); color: var(--warn); }
.chip--red   { background: var(--danger-bg); color: var(--danger); }
.chip--gray  { background: var(--surface-2); color: var(--muted); }

/* ── Card header in the memo's panel grammar ─────────────────────────────── */
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card--tint { background: var(--brand-050); border-color: #C9D9CC; }
.card--accent { border-left: 3px solid var(--brand); }
