/* =========================================================================
   Oracle — design system
   A private counsel: calm, confident, discreet. Ink & parchment with an
   aged-brass accent. Editorial serif display + refined sans for UI chrome.
   Self-contained: no external CSS or font dependencies.
   ========================================================================= */

/* ---- Tokens: light (parchment study) — default ------------------------- */
:root {
  /* Type */
  --font-display: ui-serif, "New York", "Iowan Old Style", "Palatino Linotype",
    Palatino, "Book Antiqua", Georgia, serif;
  --font-sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;

  /* Surfaces & ink */
  --bg:            #ece5d6;
  --bg-glow:       #f5efe3;
  --surface:       #fbf8f1;
  --surface-2:     #fffdf8;
  --surface-inset: #f2ecdf;

  --text:          #211d16;
  --text-soft:     #4a4235;
  --text-muted:    #7a7060;

  --border:        #dcd2bd;
  --border-strong: #c8bca0;

  /* Aged brass accent */
  --accent:         #8a6a2c;
  --accent-strong:  #6f5320;
  --accent-tint:    rgba(138, 106, 44, 0.10);
  --accent-tint-2:  rgba(138, 106, 44, 0.18);
  --on-accent:      #fbf8f1;

  --error:      #9a2b25;
  --error-tint: rgba(154, 43, 37, 0.10);

  /* Radius */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --r-pill: 999px;

  /* Spacing scale */
  --s-1: 0.25rem;
  --s-2: 0.5rem;
  --s-3: 0.75rem;
  --s-4: 1rem;
  --s-5: 1.5rem;
  --s-6: 2rem;
  --s-7: 3rem;

  /* Elevation */
  --shadow-sm: 0 1px 2px rgba(45, 35, 15, 0.06);
  --shadow-md: 0 6px 20px -8px rgba(45, 35, 15, 0.18),
               0 2px 6px -3px rgba(45, 35, 15, 0.12);
  --shadow-lg: 0 24px 48px -20px rgba(45, 35, 15, 0.28),
               0 8px 20px -12px rgba(45, 35, 15, 0.16);
  --ring: 0 0 0 3px var(--accent-tint-2);

  --grain-opacity: 0.035;
  color-scheme: light;
}

/* ---- Tokens: dark (ink study) ------------------------------------------ */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:            #14120d;
    --bg-glow:       #1c1811;
    --surface:       #1e1a13;
    --surface-2:     #26211896;
    --surface-inset: #17140e;

    --text:          #ece2cf;
    --text-soft:     #c5bba6;
    --text-muted:    #968b76;

    --border:        #322c20;
    --border-strong: #453d2c;

    --accent:         #cfa869;
    --accent-strong:  #e0bd84;
    --accent-tint:    rgba(207, 168, 105, 0.12);
    --accent-tint-2:  rgba(207, 168, 105, 0.24);
    --on-accent:      #17130c;

    --error:      #e8897a;
    --error-tint: rgba(232, 137, 122, 0.12);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 8px 24px -10px rgba(0, 0, 0, 0.7),
                 0 2px 6px -3px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 28px 60px -24px rgba(0, 0, 0, 0.8),
                 0 10px 24px -14px rgba(0, 0, 0, 0.6);

    --grain-opacity: 0.05;
    color-scheme: dark;
  }
}

/* ---- Base -------------------------------------------------------------- */
* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    radial-gradient(120% 80% at 50% -10%, var(--bg-glow) 0%, transparent 60%),
    radial-gradient(100% 60% at 100% 0%, var(--accent-tint) 0%, transparent 45%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Faint paper grain for atmosphere */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

body > * { position: relative; z-index: 1; }

::selection { background: var(--accent-tint-2); color: var(--text); }

/* ---- Typography -------------------------------------------------------- */
h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.01em;
  color: var(--text);
  margin: 0 0 var(--s-3);
}

h1 { font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.1rem); }
h2 { font-size: 1.45rem; }
h3 { font-size: 1.12rem; letter-spacing: 0; }

p { margin: 0 0 var(--s-3); }
p:last-child { margin-bottom: 0; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-strong); }

strong { color: var(--text); font-weight: 650; }

/* ---- Top bar ----------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--s-5);
  padding: var(--s-3) clamp(var(--s-4), 4vw, var(--s-7));
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(140%) blur(12px);
  -webkit-backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--border);
}
/* Thin brass hairline under the bar */
.topbar::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg, transparent,
    var(--accent-tint-2) 20%, var(--accent-tint-2) 80%, transparent);
}

.brand {
  font-family: var(--font-display);
  font-size: 1.32rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
}
.brand:hover { color: var(--text); }
/* Small brass lozenge mark */
.brand::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  background: var(--accent);
  transform: rotate(45deg);
  border-radius: 1px;
  box-shadow: 0 0 0 3px var(--accent-tint);
  transition: transform 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.brand:hover::before { transform: rotate(225deg); }

/* ---- Navigation -------------------------------------------------------- */
nav {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: clamp(var(--s-3), 2.5vw, var(--s-5));
}

nav a {
  position: relative;
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0.35rem 0;
  transition: color 0.2s ease;
}
nav a:hover { color: var(--text); }
/* Growing brass underline */
nav a::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -2px;
  height: 1.5px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}
nav a:hover::after,
nav a:focus-visible::after { transform: scaleX(1); }

/* ---- Main layout ------------------------------------------------------- */
main {
  max-width: 760px;
  margin: clamp(var(--s-5), 5vw, var(--s-7)) auto var(--s-7);
  padding: 0 clamp(var(--s-4), 4vw, var(--s-6));
  animation: page-in 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes page-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- Cards ------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: clamp(var(--s-4), 3vw, var(--s-6));
  margin-bottom: var(--s-5);
  box-shadow: var(--shadow-md);
}
.card > :last-child { margin-bottom: 0; }

.card.narrow {
  max-width: 400px;
  margin: clamp(var(--s-6), 12vh, 8rem) auto var(--s-6);
}

/* ---- Forms ------------------------------------------------------------- */
label {
  display: block;
  margin-bottom: var(--s-4);
  font-size: 0.9rem;
  font-weight: 550;
  letter-spacing: 0.01em;
  color: var(--text-soft);
}
label:last-child { margin-bottom: 0; }

input[type="text"],
input[type="password"],
input[type="email"],
input[type="search"],
input[type="number"],
input:not([type]),
textarea,
select {
  display: block;
  width: 100%;
  margin-top: var(--s-2);
  padding: 0.68rem 0.8rem;
  font-family: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface-inset);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  appearance: none;
}

textarea {
  min-height: 8.5rem;
  line-height: 1.55;
  resize: vertical;
}

input::placeholder,
textarea::placeholder { color: var(--text-muted); opacity: 0.85; }

input[type="text"]:focus,
input[type="password"]:focus,
input[type="email"]:focus,
input[type="search"]:focus,
input[type="number"]:focus,
input:not([type]):focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface-2);
  box-shadow: var(--ring);
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%238a6a2c' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.9rem center;
  padding-right: 2.2rem;
  cursor: pointer;
}

/* File input */
input[type="file"] {
  display: block;
  width: 100%;
  margin-top: var(--s-2);
  font-family: inherit;
  font-size: 0.92rem;
  color: var(--text-muted);
}
input[type="file"]::file-selector-button {
  margin-right: var(--s-3);
  padding: 0.5rem 0.9rem;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 550;
  color: var(--text);
  background: var(--surface-inset);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-pill);
  cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease;
}
input[type="file"]::file-selector-button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---- Buttons ----------------------------------------------------------- */
button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  padding: 0.66rem 1.35rem;
  font-family: var(--font-sans);
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--on-accent);
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  border: 1px solid var(--accent-strong);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
  box-shadow: var(--shadow-sm);
}
button:hover,
.button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
  filter: brightness(1.04);
}
button:active,
.button:active { transform: translateY(0); filter: brightness(0.98); }

/* Text button (logout, tertiary actions) */
.linkbtn {
  padding: 0.35rem 0;
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: none;
  border: none;
  border-radius: 0;
  box-shadow: none;
  cursor: pointer;
  transition: color 0.2s ease;
}
.linkbtn:hover {
  color: var(--accent);
  transform: none;
  box-shadow: none;
  filter: none;
}

/* ---- Pills / tags ------------------------------------------------------ */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.7rem;
  margin: 0 0.25rem 0.25rem 0;
  font-size: 0.76rem;
  font-weight: 550;
  letter-spacing: 0.03em;
  color: var(--accent);
  background: var(--accent-tint);
  border: 1px solid var(--accent-tint-2);
  border-radius: var(--r-pill);
  white-space: nowrap;
}

/* ---- Checklist (selectable chips) -------------------------------------- */
.checklist {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3);
  margin: var(--s-2) 0 var(--s-5);
}

.checklist label {
  display: inline-flex;
  align-items: center;
  gap: 0.55em;
  margin: 0;
  padding: 0.5rem 0.95rem;
  font-size: 0.92rem;
  font-weight: 550;
  color: var(--text-soft);
  background: var(--surface-inset);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-pill);
  cursor: pointer;
  user-select: none;
  transition: border-color 0.2s ease, color 0.2s ease,
    background 0.2s ease, box-shadow 0.2s ease;
}
.checklist label:hover { border-color: var(--accent); color: var(--text); }

/* Custom check dot */
.checklist input[type="checkbox"] {
  appearance: none;
  width: 1.05rem;
  height: 1.05rem;
  margin: 0;
  border: 1.5px solid var(--border-strong);
  border-radius: 50%;
  background: transparent;
  display: grid;
  place-content: center;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.checklist input[type="checkbox"]::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  transform: scale(0);
  background: var(--on-accent);
  transition: transform 0.18s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.checklist input[type="checkbox"]:checked {
  border-color: var(--accent);
  background: var(--accent);
}
.checklist input[type="checkbox"]:checked::before { transform: scale(1); }

/* Whole chip reflects selection */
.checklist label:has(input:checked) {
  color: var(--text);
  border-color: var(--accent);
  background: var(--accent-tint);
  box-shadow: inset 0 0 0 1px var(--accent-tint-2);
}

/* ---- Advice result ----------------------------------------------------- */
.advice {
  position: relative;
  overflow: hidden;
  background: var(--surface-2);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-lg);
  animation: advice-in 0.55s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
/* Brass rule down the left edge */
.advice::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: linear-gradient(180deg, var(--accent), transparent);
}

@keyframes advice-in {
  from { opacity: 0; transform: translateY(14px) scale(0.995); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.advice h3 {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-top: var(--s-5);
  margin-bottom: var(--s-2);
  padding-bottom: var(--s-2);
  border-bottom: 1px solid var(--border);
}
.advice h3:first-child { margin-top: 0; }

/* The primary recommendation heading (channel) reads larger & serif */
.advice > h3:first-child {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-transform: none;
  color: var(--text);
  border-bottom: none;
  padding-bottom: 0;
}

/* ---- Content (pre-formatted advice text) ------------------------------- */
.content {
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  font-size: 1rem;
  line-height: 1.7;
  color: var(--text-soft);
}

/* ---- Lists ------------------------------------------------------------- */
main ul { margin: 0 0 var(--s-3); padding-left: 1.2rem; }
main li { margin-bottom: var(--s-2); }
main li::marker { color: var(--accent); }
main ul a { font-weight: 550; }

/* ---- Utility ----------------------------------------------------------- */
.muted {
  color: var(--text-muted);
  font-size: 0.92rem;
}

.error {
  padding: 0.7rem 0.95rem;
  color: var(--error);
  background: var(--error-tint);
  border: 1px solid color-mix(in srgb, var(--error) 35%, transparent);
  border-radius: var(--r-md);
  font-size: 0.92rem;
  font-weight: 550;
}

.inline { display: inline; }

/* ---- Accessible focus -------------------------------------------------- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}
input:focus-visible,
textarea:focus-visible,
select:focus-visible { outline: none; }

/* ---- Motion preferences ------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

.assign-row { display:flex; gap:.6rem; align-items:center; margin:.5rem 0; }
.assign-row .assign-name { flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.assign-row input { flex:1; }
.assign-row button { flex:0 0 auto; }

/* ---- Import dropzone ---- */
.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--surface-inset);
  padding: var(--s-6) var(--s-4);
  text-align: center;
  cursor: pointer;
  outline: none;
  transition: border-color .15s ease, background .15s ease, transform .15s ease, box-shadow .15s ease;
}
.dropzone:hover { border-color: var(--accent); }
.dropzone:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.dropzone.dragover { border-color: var(--accent); background: var(--accent-tint); transform: translateY(-1px); }
.dropzone.has-files { border-style: solid; }
.dropzone-icon { font-size: 1.9rem; line-height: 1; color: var(--accent); margin-bottom: var(--s-2); }
.dropzone-primary { font-family: var(--font-display); font-size: 1.15rem; margin: var(--s-1) 0; color: var(--text); }
.dropzone-secondary { margin: 0; font-size: .9rem; }
.dropzone-browse { color: var(--accent); text-decoration: underline; }
.file-list { list-style: none; margin: var(--s-4) 0 0; padding: 0; text-align: left; max-height: 240px; overflow: auto; }
.file-list li { padding: var(--s-1) var(--s-2); border-bottom: 1px solid var(--border); font-size: .9rem; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-list li:last-child { border-bottom: 0; }
.file-list .file-count { color: var(--text-muted); font-size: .85rem; padding-top: var(--s-2); }
#import-submit { margin-top: var(--s-4); }

/* ---- Busy button (import in progress) ---- */
button.busy { cursor: progress; opacity: .9; }
button.busy::before {
  content: ""; display: inline-block; width: .9em; height: .9em;
  margin-right: .55em; vertical-align: -.1em;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: oracle-spin .7s linear infinite;
}
@keyframes oracle-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { button.busy::before { animation: none; } }

/* ---- Scenario conversation ---- */
.msg { padding: var(--s-3) 0; border-bottom: 1px solid var(--border); }
.msg:last-child { border-bottom: 0; }
.msg-role { font-family: var(--font-sans); font-size: .78rem; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-muted); margin-bottom: var(--s-1); }
.msg-user .msg-role { color: var(--accent); }

/* ---- Ask: people search ---- */
.person-search { margin-bottom: var(--s-3); }
.checklist { max-height: 300px; overflow: auto; }
.is-hidden { display: none !important; }

/* ---- Larger, more readable type ---- */
body { font-size: 1.12rem; line-height: 1.6; }
.content { line-height: 1.6; }
.content strong { font-weight: 700; }

/* ---- Conversation cards ---- */
.msg { padding: var(--s-4); border-bottom: 0; }
.msg-head { display: flex; align-items: center; gap: var(--s-2); margin-bottom: var(--s-2); }
.msg-role { margin: 0; font-family: var(--font-sans); font-size: .8rem; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); }
.msg-user .msg-role { color: var(--accent); }
.msg-latest { border-left: 3px solid var(--accent); background: var(--accent-tint); }
.pill-latest { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.section-label { margin: var(--s-5) 0 var(--s-2); text-transform: uppercase; letter-spacing: .06em; font-size: .8rem; }

/* ---- "Oracle is thinking" overlay ---- */
.thinking-overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  background: rgba(8, 9, 12, 0.62); backdrop-filter: blur(3px); padding: var(--s-4); }
.thinking-card { text-align: center; max-width: 420px; width: 100%;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg); padding: var(--s-6) var(--s-5); color: var(--text); }
.thinking-orb { width: 56px; height: 56px; margin: 0 auto var(--s-4); border-radius: 50%;
  background: radial-gradient(circle at 50% 38%, var(--accent), transparent 68%);
  animation: oracle-pulse 1.7s ease-in-out infinite; }
.thinking-title { font-family: var(--font-display); font-size: 1.45rem; margin: 0 0 var(--s-2); }
.thinking-step { min-height: 1.5em; margin: 0 0 var(--s-2); transition: opacity .18s ease; }
.thinking-timer { font-variant-numeric: tabular-nums; margin: 0 0 var(--s-1); }
.thinking-note { font-size: .85rem; margin: 0; }
@keyframes oracle-pulse {
  0%   { transform: scale(.9);  box-shadow: 0 0 0 0 var(--accent-tint); }
  60%  { transform: scale(1.06); box-shadow: 0 0 0 16px transparent; }
  100% { transform: scale(.9);  box-shadow: 0 0 0 0 transparent; }
}
@media (prefers-reduced-motion: reduce) { .thinking-orb { animation: none; } }

/* ---- Depth toggle (Deep / Fast) ---- */
.effort-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: var(--r-pill);
  overflow: hidden; margin: var(--s-1) 0 var(--s-3); }
.effort-toggle label { display: flex; align-items: baseline; gap: .4rem; margin: 0;
  padding: .5rem 1rem; cursor: pointer; transition: background .12s ease; }
.effort-toggle label + label { border-left: 1px solid var(--border); }
.effort-toggle label:has(:checked) { background: var(--accent-tint); }
.effort-toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.effort-toggle .eff-name { font-weight: 600; color: var(--text); }
