/* app.css — phone-first, accessible. Knolled Data design system; tokens in brand.css.
 *
 * Fonts: Inter (the instrument — every screen, label, control), Fraunces italic (the read —
 * the single insight line only), Space Mono (the proof layer — citations, source paths,
 * confidence, refs). THE SIGNAL DISCIPLINE: teal (--signal) marks only the read — the
 * auto-resolved winner and the engine's recommendation. Chrome, clusters, and generic
 * buttons stay muted (slate / paper / hairlines / cluster palette). */

@import url("./brand.css");

/* slate ground, paper text — the brand doing on a screen what the product does to a pile. */
:root {
  --bg: var(--slate);
  --surface: var(--slate-2);
  --surface-2: var(--slate-3);
  --line: var(--slate-hair);
  --text: var(--paper);
  --radius: 12px;
  --tap: 44px; /* min touch target */
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--ui);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ── sign-in gate: the lock before the pile ──────────────────────────────────── */
/* Full-screen, branded, muted. The primary action is paper/outline — the signal
 * (teal) is reserved for the read, never for sign-in chrome. */
.gate {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); color: var(--text);
  padding: 24px max(16px, env(safe-area-inset-left)) calc(24px + env(safe-area-inset-bottom));
}
.gate[hidden] { display: none; }
.gate__panel {
  width: 100%; max-width: 380px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 28px 22px;
}
.gate__lockup { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 14px; }
.gate__mark { display: block; }
.gate__title { font-size: 1.4rem; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
.gate__lede { color: var(--mid); text-align: center; margin: 0 0 18px; font-size: 0.92rem; }
.gate__form { display: grid; gap: 4px; }
/* The unlock button: paper outline on slate, muted — never the signal teal. */
.gate__submit {
  margin-top: 8px; width: 100%;
  background: transparent; color: var(--text);
  border: 1px solid var(--hair); font-weight: 600;
}
.gate__submit:hover:not(:disabled), .gate__submit:focus-visible { background: var(--surface-2); }
.gate__submit:disabled { opacity: 0.55; cursor: progress; }
.gate__status { color: var(--mid); font-size: 0.86rem; margin: 10px 0 0; min-height: 1.2em; }

.app-shell[hidden] { display: none; }
.topbar__actions { display: flex; gap: 8px; }

/* ── header lockup: KD monogram + wordmark ───────────────────────────────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px calc(12px + env(safe-area-inset-top));
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.lockup { display: flex; align-items: center; gap: 12px; }
.lockup__mark { display: block; flex-shrink: 0; }
.topbar__title { font-size: 1.05rem; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
.topbar__btn {
  min-height: var(--tap); padding: 0 14px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text); border-radius: var(--radius); cursor: pointer;
  font: inherit;
}

/* tabs — chrome stays muted; the active tab is marked with paper, not signal. */
.tabs { display: flex; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 53px; z-index: 4; }
.tab {
  flex: 1; min-height: var(--tap); border: 0; background: transparent; color: var(--mid);
  font: inherit; font-size: 0.95rem; cursor: pointer; border-bottom: 2px solid transparent;
}
.tab.active { color: var(--text); border-bottom-color: var(--hair); }

main { max-width: 560px; margin: 0 auto; }
.surface { padding: 16px; }
.lede { color: var(--mid); margin-top: 0; }

/* mode picker — cards are muted chrome; selection uses a paper hairline, never the signal. */
.mode-list { display: grid; gap: 10px; margin-bottom: 18px; }
.mode-card {
  display: grid; gap: 4px; text-align: left; padding: 14px; min-height: var(--tap);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--text); cursor: pointer; font: inherit;
}
.mode-card[aria-pressed="true"] { border-color: var(--hair); box-shadow: 0 0 0 1px var(--hair) inset; }
.mode-card__label { font-weight: 600; }
.mode-card__blurb { color: var(--mid); font-size: 0.9rem; }
.mode-card__tag { color: var(--mid); font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.04em; }

.field { display: grid; gap: 6px; margin: 12px 0; }
.field > span { font-size: 0.9rem; color: var(--mid); }
input, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px; font-size: 16px; /* 16px prevents iOS zoom */
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius);
  font-family: var(--ui);
}
textarea { min-height: 120px; resize: vertical; font-family: var(--mono); font-size: 13px; }

/* buttons — generic buttons are muted. The one signal button is the accept-the-read action below. */
.btn {
  min-height: var(--tap); padding: 0 16px; border-radius: var(--radius); cursor: pointer;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line); font: inherit; font-size: 0.95rem;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
/* The primary action (consolidate) is chrome, not the read — paper-on-slate, not teal. */
.btn--primary { background: var(--paper); border-color: var(--paper); color: var(--ink); font-weight: 600; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.status, .deck-meta { color: var(--mid); font-size: 0.9rem; }

/* ── uploader — the default way in. Chrome only: muted slate/paper/hairlines, no
 * signal teal (teal is reserved for the read). The dropzone is a dashed paper
 * hairline that firms on hover/drag; nothing here glows. */
.uploader { margin: 4px 0 12px; }
.dropzone {
  display: grid; gap: 6px; justify-items: center; text-align: center;
  padding: 26px 18px; min-height: var(--tap);
  background: var(--surface); color: var(--text);
  border: 1px dashed var(--line); border-radius: var(--radius);
  cursor: pointer;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--hair); outline: none; }
.dropzone--over { border-color: var(--hair); background: var(--surface-2); }
.dropzone--busy { opacity: 0.6; cursor: progress; }
.dropzone__lede { margin: 0; font-weight: 600; }
.dropzone__hint { margin: 0; color: var(--mid); font-size: 0.86rem; }
.dropzone__actions { justify-content: center; margin-top: 6px; }

/* the file inputs are driven by the buttons / drop — hidden but accessible */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* advanced: server-path affordance — collapsed by default, muted chrome */
.advanced { margin: 6px 0 4px; }
.advanced > summary {
  cursor: pointer; color: var(--mid); font-size: 0.86rem; padding: 6px 0;
  list-style: revert;
}
.advanced > summary:hover, .advanced > summary:focus-visible { color: var(--text); }

/* reader */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 12px 0; }
.panel h3 { margin: 0 0 8px; font-size: 1rem; }
.muted { color: var(--mid); }
.reader__title { font-size: 1.2rem; letter-spacing: -0.02em; }
.auto-card { border-top: 1px solid var(--line); padding: 10px 0; }
.auto-card__head { font-weight: 600; margin-bottom: 6px; }
/* The insight line — Fraunces italic, the read's voice. Reserved for the engine's reasoning. */
.auto-card__read { font-family: var(--disp); font-style: italic; color: var(--signal); margin-top: 6px; }

.opt { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 4px 0; }
/* proof layer — the value is shown in the mono proof type, muted by default. */
.opt__val { font-family: var(--mono); background: var(--surface-2); padding: 2px 6px; border-radius: 6px; }
.opt__meta { color: var(--mid); font-family: var(--mono); font-size: 0.8rem; }
/* THE READ on this surface: the auto-resolved winner. The one teal mark — the layer that means something. */
.opt--win .opt__val { color: var(--signal); outline: 1px solid var(--signal); }

/* citation chips — proof layer (source paths). Muted mono, never the signal. */
.cite { border: 1px solid var(--line); background: var(--bg); color: var(--mid); border-radius: 6px; padding: 2px 8px; font-family: var(--mono); font-size: 0.78rem; cursor: pointer; min-height: 28px; }
.cite:hover, .cite:focus-visible { color: var(--paper); border-color: var(--hair); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.cite-detail { display: none; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; font-family: var(--mono); font-size: 0.82rem; color: var(--mid); }
.cite-detail.show { display: block; }

/* swipe deck — every card is a muted, sourced conflict; the signal marks only the engine's lean (the read). */
.deck { margin-top: 8px; }
.swipe-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.swipe-card__subject { font-weight: 600; font-size: 1.05rem; margin-bottom: 10px; }
/* The engine's lean is the read on the deck — Fraunces italic + teal, the single signal per card. */
.lean { margin: 10px 0; color: var(--signal); background: var(--surface-2); border: 1px solid var(--signal-dim); border-radius: var(--radius); padding: 8px 12px; font-family: var(--disp); font-style: italic; font-size: 0.95rem; }
.swipe-actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-top: 14px; }
/* Accept = take the read. The one signal-colored button on this surface. */
.btn--accept { background: var(--signal); border-color: var(--signal); color: var(--slate); font-weight: 600; }
/* Override and Defer are muted chrome — cluster-toned, never the signal. */
.btn--override { background: var(--surface-2); border-color: var(--c2); color: var(--text); }
.btn--defer { background: var(--surface-2); border-color: var(--line); color: var(--mid); }

/* dialogs */
.dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); max-width: 90vw; width: 380px; padding: 0; }
.dialog::backdrop { background: rgba(0,0,0,0.55); }
.dialog__form { padding: 18px; display: grid; gap: 4px; }
.dialog__form h2 { margin: 0 0 8px; font-size: 1.1rem; letter-spacing: -0.02em; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 16px; max-width: 90vw; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 10;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast[data-kind="error"] { border-color: var(--c1); }
/* a resolved "win" is the read landing — the one place chrome borrows the signal. */
.toast[data-kind="win"] { border-color: var(--signal); }

@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
