/* PS1 Generator — "Steep" aesthetic: daylight, editorial, achromatic + rust accent.
   Signifier/Sohne are commercial; under our strict CSP (no external font CDNs) we use
   a system serif/sans pairing. To use the real faces, self-host the .woff2 under
   /static/fonts and @font-face them (same-origin, CSP-allowed), then swap the vars. */
:root {
  --ink: #17191c;
  --white: #ffffff;
  --fog: #f7f7f8;
  --ash: #4c4c4c;
  --graphite: #777b86;
  --dove: #a3a6af;
  --rust: #5d2a1a;
  --accent: #c66a4a;
  --apricot: #fbe1d1;
  --sky: #d3e3fc;

  --line: #ececee;          /* hairline */
  --line-strong: #dfe0e3;

  --font-display: ui-serif, Georgia, "Times New Roman", Cambria, serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --r-card: 24px;
  --r-input: 16px;
  --r-pill: 9999px;
  --r-img: 12px;

  --shadow: rgba(4,23,43,.05) 0 0 0 1px, rgba(0,0,0,.10) 0 20px 25px -5px,
            rgba(0,0,0,.10) 0 8px 10px -6px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  color: var(--ink); background: var(--fog);
  font-family: var(--font-body); font-size: 16px; line-height: 1.4;
  letter-spacing: -0.009em; -webkit-font-smoothing: antialiased;
}
a { color: var(--ink); text-decoration: none; }
a:hover { color: var(--rust); }
h1, h2 { letter-spacing: -0.02em; }
h2 { font-size: 17px; font-weight: 500; margin: 0 0 16px; }
.muted { color: var(--graphite); }
.small { font-size: 14px; }
.nowrap { white-space: nowrap; }
.error { color: #7a2718; font-weight: 500; background: var(--apricot);
  border: 1px solid #f1c7b2; padding: 11px 14px; border-radius: 14px; }
.notice { color: #1f3b6e; font-weight: 500; background: var(--sky);
  border: 1px solid #bcd3f6; padding: 11px 14px; border-radius: 14px; }

/* ---- App shell ---- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; flex-shrink: 0; position: sticky; top: 0; height: 100vh;
  background: var(--fog); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 22px 16px;
}
.logo { font-family: var(--font-display); font-size: 20px; color: var(--ink);
  padding: 6px 10px 22px; display: flex; align-items: center; }
.logo .mark, .auth-brand .mark {
  background: var(--rust); color: #fff; font-size: 11px; font-weight: 600;
  font-family: var(--font-body); letter-spacing: .04em; padding: 3px 8px;
  border-radius: var(--r-pill); margin-right: 9px;
}
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a { color: var(--ash); padding: 9px 12px; border-radius: 12px;
  font-size: 15px; font-weight: 450; }
.side-nav a:hover { background: rgba(0,0,0,.035); color: var(--ink); }
.side-nav a.active { background: var(--white); color: var(--ink); box-shadow: var(--shadow); }
.side-foot { margin-top: auto; padding-top: 14px; }
.side-foot .who { color: var(--graphite); font-size: 13px; padding: 0 10px 6px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot form { margin: 0; }
button.link { background: none; border: 0; color: var(--ash); cursor: pointer;
  font: inherit; font-size: 15px; padding: 8px 10px; border-radius: 12px;
  width: 100%; text-align: left; }
button.link:hover { background: rgba(0,0,0,.035); color: var(--ink); }

.content { flex: 1; padding: 36px 44px 72px; max-width: 1200px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 28px; }
.page-head h1 { font-family: var(--font-display); font-weight: 400; font-size: 40px;
  line-height: 1.1; letter-spacing: -0.022em; margin: 0; }
.page-head .sub { color: var(--graphite); margin: 8px 0 0; font-size: 15px; }

/* ---- Buttons (one Ink fill per screen; rest are quiet) ---- */
button, .button {
  display: inline-block; padding: 9px 20px; border: 0; border-radius: var(--r-pill);
  background: var(--ink); color: #fff; font: inherit; font-size: 15px; font-weight: 450;
  letter-spacing: -0.009em; cursor: pointer; transition: background .12s ease;
}
button:hover, .button:hover { background: #2c2f34; color: #fff; }
.button.ghost { background: var(--white); color: var(--ink); border: 1px solid var(--dove); }
.button.ghost:hover { background: var(--fog); }
.row-link { font-size: 15px; font-weight: 450; white-space: nowrap; }

/* ---- Cards ---- */
.card { background: var(--white); border-radius: var(--r-card); padding: 24px;
  box-shadow: var(--shadow); margin-bottom: 24px; }
.card.warm { background: var(--apricot); box-shadow: none; }
.card.cool { background: var(--sky); box-shadow: none; }
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 24px; }

/* ---- Stat cards ---- */
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; margin-bottom: 24px; }
.stat { background: var(--white); border-radius: var(--r-card); padding: 22px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; }
.stat.accent { background: var(--apricot); box-shadow: none; }
.stat.cool { background: var(--sky); box-shadow: none; }
.stat-num { font-size: 40px; font-weight: 480; letter-spacing: -0.03em; line-height: 1.05; }
.stat.accent .stat-num { color: var(--rust); }
.stat-num .unit { font-size: 16px; font-weight: 450; color: var(--graphite); margin-left: 5px;
  letter-spacing: 0; }
.stat.accent .stat-num .unit { color: #8a5a45; }
.stat-label { margin-top: 10px; font-weight: 480; font-size: 15px; }
.stat-sub { color: var(--graphite); font-size: 13px; margin-top: 3px; }

/* ---- Chart (warm rust voice) ---- */
.chart { display: flex; gap: 8px; align-items: stretch; margin: 6px 0 2px; }
.col { flex: 1; display: flex; flex-direction: column; align-items: center; }
.col .track { width: 100%; height: 150px; display: flex; align-items: flex-end; }
.col .bar { width: 100%; min-height: 3px; border-radius: 6px 6px 0 0; background: var(--rust); }
.warm .col .bar { background: var(--rust); }
.col-label { margin-top: 8px; font-size: 12px; color: var(--graphite); }

/* ---- Facts + meter ---- */
.facts { list-style: none; margin: 0 0 18px; padding: 0; }
.facts li { display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--line); }
.facts li:last-child { border-bottom: 0; }
.facts span { color: var(--graphite); font-size: 14px; }
.facts strong { font-size: 15px; font-weight: 480; }
.meter-head { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 7px; }
.meter-head strong { font-weight: 480; }
.progress { height: 9px; background: #efe7e3; border-radius: var(--r-pill); overflow: hidden; }
.fill { height: 100%; background: var(--rust); border-radius: var(--r-pill); }

/* ---- Table ---- */
table.grid { width: 100%; border-collapse: collapse; }
.grid th, .grid td { text-align: left; padding: 12px 12px; border-bottom: 1px solid var(--line);
  font-size: 14px; }
.grid th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--graphite);
  font-weight: 500; }
.grid tbody tr:hover { background: var(--fog); }
.grid tr:last-child td { border-bottom: 0; }
.grid td.files { color: var(--graphite); max-width: 340px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.pill { padding: 3px 11px; border-radius: var(--r-pill); font-size: 13px; font-weight: 480; }
.pill.ok { background: var(--fog); color: var(--graphite); }
.pill.warn { background: var(--apricot); color: var(--rust); }
.empty { text-align: center; padding: 28px 0; color: var(--graphite); }
.empty p { margin-bottom: 16px; }

/* ---- Forms ---- */
label { display: block; margin: 16px 0; font-weight: 480; font-size: 15px; }
.hint { color: var(--graphite); font-weight: 400; }
input[type=email], input[type=password] {
  display: block; width: 100%; margin-top: 7px; padding: 12px 14px; font: inherit; font-weight: 400;
  border: 1px solid var(--dove); border-radius: var(--r-input); background: var(--white);
  letter-spacing: -0.009em;
}
input:focus { outline: 2px solid #e7d4cc; border-color: var(--rust); }
.form-card { max-width: 660px; }
.dropzone { border: 1.5px dashed var(--dove); border-radius: var(--r-input); padding: 8px;
  margin: 6px 0 20px; background: var(--fog); }
.dropzone label { display: block; margin: 0; padding: 20px; cursor: pointer; }
.dz-title { display: block; font-weight: 480; font-size: 16px; }
.dz-sub { display: block; color: var(--graphite); font-weight: 400; font-size: 14px; margin: 5px 0 14px; }
input[type=file] { font: inherit; }
.downloads { display: flex; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
pre.review { background: var(--ink); color: #e6e2dc; border-radius: var(--r-input); padding: 16px;
  overflow-x: auto; font-size: 13px; line-height: 1.5; white-space: pre-wrap; }

/* ---- Field review ---- */
.review-card .rh { display: flex; align-items: center; gap: 9px; }
.rh-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.rh-dot.warn { background: var(--rust); }
.rh-dot.ok { background: var(--graphite); }
.rh .count { margin-left: 6px; background: var(--fog); color: var(--graphite); font-size: 13px;
  font-weight: 480; padding: 1px 10px; border-radius: var(--r-pill); }
.review-list { display: flex; flex-direction: column; gap: 10px; }
.review-item { border: 1px solid var(--line); border-radius: var(--r-input); padding: 13px 16px;
  background: var(--white); }
.review-item.flag { background: var(--apricot); border-color: #f1cdb9; }
.ri-main { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; }
.ri-label { color: var(--graphite); font-size: 13px; font-weight: 480; flex-shrink: 0; }
.ri-value { font-weight: 480; text-align: right; }
.ri-value.missing { color: var(--rust); font-weight: 450; font-style: italic; }
.ri-source { margin-top: 7px; font-size: 13px; color: var(--ash); line-height: 1.45; }
.ri-source.muted { color: var(--graphite); font-style: italic; }
.ri-doc { display: inline-block; background: var(--white); color: var(--ash); font-size: 12px;
  font-weight: 480; padding: 1px 8px; border-radius: 7px; margin-right: 7px; border: 1px solid var(--line); }
.review-item.flag .ri-doc { background: rgba(255,255,255,.6); border-color: #f1cdb9; }

/* ---- Auth pages (hero context: soft apricot glow allowed) ---- */
.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 18px; padding: 24px; background: var(--white);
  background-image: radial-gradient(60% 50% at 50% 22%, rgba(251,225,209,.55), rgba(255,255,255,0) 70%); }
.auth-brand { font-family: var(--font-display); font-size: 24px; display: flex; align-items: center; }
.auth-card { background: var(--white); border-radius: var(--r-card); box-shadow: var(--shadow);
  padding: 30px; width: 100%; max-width: 410px; }
.auth-card h1 { font-family: var(--font-display); font-weight: 400; font-size: 30px;
  letter-spacing: -0.02em; margin: 0 0 18px; }
.auth-card button { width: 100%; margin-top: 10px; }
.auth-foot { color: var(--graphite); font-size: 13px; }

/* ---- Responsive ---- */
@media (max-width: 980px) {
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .shell { flex-direction: column; }
  .sidebar { width: auto; height: auto; position: static; flex-direction: row; align-items: center;
    flex-wrap: wrap; gap: 8px; border-right: 0; border-bottom: 1px solid var(--line); }
  .logo { padding: 6px 10px; }
  .side-nav { flex-direction: row; }
  .side-foot { margin: 0 0 0 auto; padding-top: 0; }
  .side-foot .who { display: none; }
  .content { padding: 24px; }
}
@media (max-width: 540px) { .stat-row { grid-template-columns: 1fr; } }

/* ---- Width / height utilities (CSP-safe charts & meters) ---- */
.w-0{width:0}.w-5{width:5%}.w-10{width:10%}.w-15{width:15%}.w-20{width:20%}
.w-25{width:25%}.w-30{width:30%}.w-35{width:35%}.w-40{width:40%}.w-45{width:45%}
.w-50{width:50%}.w-55{width:55%}.w-60{width:60%}.w-65{width:65%}.w-70{width:70%}
.w-75{width:75%}.w-80{width:80%}.w-85{width:85%}.w-90{width:90%}.w-95{width:95%}.w-100{width:100%}
.h-0{height:0}.h-5{height:5%}.h-10{height:10%}.h-15{height:15%}.h-20{height:20%}
.h-25{height:25%}.h-30{height:30%}.h-35{height:35%}.h-40{height:40%}.h-45{height:45%}
.h-50{height:50%}.h-55{height:55%}.h-60{height:60%}.h-65{height:65%}.h-70{height:70%}
.h-75{height:75%}.h-80{height:80%}.h-85{height:85%}.h-90{height:90%}.h-95{height:95%}.h-100{height:100%}

/* --- Dropbox round-trip --- */
form.inline { display: inline; margin: 0; }

.dropbox-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  flex-wrap: wrap; padding: 18px 20px; margin-bottom: 18px;
  background: var(--sky); border-radius: var(--r-input);
}
.dbx-status { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; min-width: 0; }
.dbx-mark { font-weight: 600; color: var(--ink); display: inline-flex; align-items: center; gap: 8px; }
.dbx-glyph { width: 20px; height: 20px; fill: #0061ff; flex: none; vertical-align: middle; }
.page-head h1 .dbx-glyph { width: 26px; height: 26px; }
.dbx-actions { display: flex; align-items: center; gap: 10px; }

.dbx-steps { margin: 4px 0 18px; padding-left: 0; list-style: none; counter-reset: step; }
.dbx-steps li { position: relative; padding: 6px 0 6px 40px; color: var(--ash); font-size: 14px; }
.dbx-steps li::before {
  counter-increment: step; content: counter(step);
  position: absolute; left: 0; top: 4px; width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  background: var(--sky); color: var(--ink); border-radius: var(--r-pill);
  font-size: 13px; font-weight: 600;
}
.dbx-steps strong { color: var(--ink); }

.or-divider { text-align: center; margin: 6px 0 18px; position: relative; }
.or-divider::before { content: ""; position: absolute; top: 50%; left: 0; right: 0; height: 1px; background: var(--line); }
.or-divider span { position: relative; background: var(--white); padding: 0 12px; color: var(--graphite); font-size: 13px; }

.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 16px; font-size: 14px; }
.crumbs a { color: var(--rust); text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }
.crumbs .sep { color: var(--dove); }

.dbx-list { display: flex; flex-direction: column; }
.dbx-row { display: flex; align-items: center; gap: 12px; padding: 12px 8px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.dbx-row:last-child { border-bottom: none; }
.dbx-row.folder:hover { background: var(--fog); border-radius: 12px; }
.dbx-ico { color: var(--rust); width: 18px; text-align: center; }
.dbx-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }

.dbx-files { display: flex; flex-direction: column; margin-bottom: 18px; }
.dbx-file { display: flex; align-items: center; gap: 12px; padding: 12px 8px; border-bottom: 1px solid var(--line); cursor: pointer; }
.dbx-file:last-child { border-bottom: none; }
.dbx-file:hover { background: var(--fog); border-radius: 12px; }
.dbx-file input { width: 18px; height: 18px; accent-color: var(--rust); }

/* Rendered extraction review (markdown -> HTML) */
.md-review h1 { display: none; }  /* page already has the heading */
.md-review h2 { font-family: var(--font-display); font-size: 16px; margin: 24px 0 8px; color: var(--ink); }
.md-review table { width: 100%; border-collapse: collapse; margin: 8px 0 18px; font-size: 13px; }
.md-review th { text-align: left; padding: 8px 10px; background: var(--fog);
  border-bottom: 1px solid var(--line-strong); color: var(--graphite); font-weight: 600; }
.md-review td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top;
  overflow-wrap: anywhere; }
.md-review tr:hover td { background: var(--fog); }
.md-review blockquote { margin: 12px 0; padding: 10px 14px; background: var(--apricot);
  border-radius: var(--r-input); color: #7a2718; font-size: 13px; }
.md-review blockquote p { margin: 0; color: #7a2718; }
.md-review ul { margin: 6px 0 18px; padding-left: 18px; }
.md-review li { margin: 5px 0; font-size: 13.5px; color: var(--ash); }
.md-review p { font-size: 13.5px; color: var(--ash); }

/* Confidence pills + flag badges in the extraction review */
.md-review .conf { display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; line-height: 1.5; white-space: nowrap; }
.md-review .conf-high { background: #e3f3e8; color: #1f6b3b; }
.md-review .conf-medium { background: #fdf0d9; color: #8a5a13; }
.md-review .conf-low { background: #fbe3e1; color: #9a2a1f; }
.md-review .flag { display: inline; padding: 1px 5px; border-radius: 4px;
  font-size: 12px; font-weight: 600; }
.md-review .flag-todo { background: #fbe0dd; color: #9a2a1f; }
.md-review .flag-review { background: #fdf0d9; color: #8a5a13; }
/* Tint whole rows by confidence using a leading cell colour cue */
.md-review td:has(.conf-low) { box-shadow: inset 3px 0 0 #e7a59c; }
.md-review td:has(.conf-medium) { box-shadow: inset 3px 0 0 #e6c478; }
.md-review strong { color: var(--ink); }
.md-review em { color: var(--graphite); }
.md-review code { background: var(--fog); padding: 1px 5px; border-radius: 6px; font-size: 12px; }

/* Live generation progress */
.progress-card { padding-top: 22px; }
.progress-top { display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 8px; }
.progress-pct { font-family: var(--font-display); font-size: 26px; color: var(--ink);
  font-variant-numeric: tabular-nums; }
.progress-track { height: 8px; border-radius: 999px; background: var(--fog);
  overflow: hidden; box-shadow: inset 0 0 0 1px var(--line); }
.progress-fill { height: 100%; width: 0; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent, #c66a4a), #e08a64);
  background-size: 200% 100%;
  transition: width .5s cubic-bezier(.4, 0, .2, 1);
  animation: progress-shimmer 1.4s linear infinite; }
@keyframes progress-shimmer { 0% { background-position: 200% 0; } 100% { background-position: 0 0; } }

.progress-steps { list-style: none; margin: 20px 0 0; padding: 0; }
.progress-steps .step { display: flex; align-items: center; gap: 13px; padding: 12px 4px;
  border-bottom: 1px solid var(--line); font-size: 14px; transition: opacity .3s ease; }
.progress-steps .step:last-child { border-bottom: none; }
.progress-steps .step-dot { width: 18px; height: 18px; border-radius: 999px; flex: none;
  border: 2px solid var(--line-strong); background: #fff; box-sizing: border-box;
  position: relative; transition: all .25s ease; }
.progress-steps .step-label { flex: 1; color: var(--ash); transition: color .25s ease; }
.progress-steps .step-state { font-size: 12px; font-weight: 600; letter-spacing: .02em; }

/* pending — dim, hollow */
.progress-steps .step-pending { opacity: .5; }
.progress-steps .step-pending .step-label { color: var(--graphite); }

/* active — spinning ring + bold label */
.progress-steps .step-active .step-dot { border-color: var(--line);
  border-top-color: var(--accent, #c66a4a); background: #fff;
  animation: step-spin .7s linear infinite; }
.progress-steps .step-active .step-label { color: var(--ink); font-weight: 600; }
.progress-steps .step-active .step-state { color: var(--accent, #c66a4a); }
.progress-steps .step-active .step-state::after { content: "working"; }
@keyframes step-spin { to { transform: rotate(360deg); } }

/* done — filled green check */
.progress-steps .step-done .step-dot { border-color: #1f6b3b; background: #1f6b3b; }
.progress-steps .step-done .step-dot::after { content: "✓"; position: absolute; inset: 0;
  color: #fff; font-size: 12px; line-height: 14px; text-align: center; font-weight: 700; }
.progress-steps .step-done .step-label { color: var(--ash); }
.progress-steps .step-done .step-state { color: #1f6b3b; }
.progress-steps .step-done .step-state::after { content: "done"; }

/* animated "Working..." ellipsis */
.dots span { animation: dot-blink 1.4s infinite both; }
.dots span:nth-child(2) { animation-delay: .2s; }
.dots span:nth-child(3) { animation-delay: .4s; }
@keyframes dot-blink { 0%, 80%, 100% { opacity: 0; } 40% { opacity: 1; } }
.error-note { color: #9a2a1f; font-weight: 600; }
