/* Duke's Picks AI — chat UI.
   Palette and type mirror ../../site/styles.css so the assistant feels like part
   of the room, not a bolted-on tool. */

:root {
  --bg:        #0a0908;
  --bg-deep:   #050403;
  --bg-raised: #14110d;
  --bg-input:  #191510;
  --gold:      #d4af6f;
  --gold-soft: #e7cf9f;
  --ink:       #f5f0e6;
  --muted:     rgba(245, 240, 230, 0.6);
  --muted-2:   rgba(245, 240, 230, 0.4);
  --line:      rgba(212, 175, 111, 0.2);
  --line-soft: rgba(212, 175, 111, 0.1);
  --serif: "Playfair Display", Georgia, "Times New Roman", serif;
  --sans:  "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --sidebar-w: 288px;
  --radius:    14px;
  --radius-sm: 10px;
  --measure:   760px;
  /* Real viewport height on mobile: 100vh sits under Safari's chrome and cuts
     off the composer. Overridden with the visual viewport in app.js. */
  --vh: 100dvh;
}

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

html, body {
  height: 100%;
  margin: 0;
  /* The page itself never scrolls; only the message list does. Without this,
     iOS rubber-banding drags the whole app and hides the composer. */
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.eyebrow {
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 0 0 8px;
  font-weight: 500;
}

.fine { font-size: 12px; color: var(--muted-2); }

a { color: var(--gold); text-decoration: none; }
a:hover { color: var(--gold-soft); text-decoration: underline; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.btn {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
  padding: 11px 20px;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}
.btn--gold { background: var(--gold); color: #14110d; }
.btn--gold:hover:not(:disabled) { background: var(--gold-soft); }
.btn--ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn--ghost:hover { border-color: var(--gold); color: var(--gold); }
.btn--sm { padding: 8px 14px; font-size: 12.5px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.linkish {
  background: none; border: none; padding: 0;
  color: var(--muted); font-family: var(--sans); font-size: 12px;
  cursor: pointer; text-decoration: underline;
}
.linkish:hover { color: var(--gold); }

/* Square tap target, comfortably past the 44px minimum on touch. */
.icon-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  display: none;
  place-items: center;
  padding: 0;
  transition: background 0.18s ease, color 0.18s ease;
}
.icon-btn:hover { background: rgba(212, 175, 111, 0.08); color: var(--gold); }
.icon-btn svg { width: 19px; height: 19px; display: block; }

/* ── Sign in ─────────────────────────────────────────────────────────────── */

.login {
  height: 100%;
  overflow-y: auto;
  display: grid;
  place-items: center;
  padding: 32px 20px;
  background:
    radial-gradient(1000px 500px at 50% -10%, rgba(212, 175, 111, 0.07), transparent 70%),
    var(--bg-deep);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-raised);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 40px 36px;
}

.login-card h1 {
  font-family: var(--serif);
  font-size: 34px;
  font-weight: 500;
  margin: 0 0 12px;
  letter-spacing: -0.01em;
}

.lead { color: var(--muted); margin: 0 0 28px; }

.login-card label {
  display: block;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.login-card input {
  width: 100%;
  padding: 13px 16px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-family: var(--sans);
  /* 16px stops iOS zooming the page when the field is focused. */
  font-size: 16px;
  margin-bottom: 16px;
}
.login-card input:focus { outline: none; border-color: var(--gold); }

.login-card .btn { width: 100%; }

.msg { font-size: 13.5px; margin: 16px 0 0; min-height: 20px; }
.msg.ok { color: var(--gold-soft); }
.msg.err { color: #e8836f; }

.login-card .fine { margin: 24px 0 0; text-align: center; }

/* ── App shell ───────────────────────────────────────────────────────────── */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: var(--vh);
  transition: grid-template-columns 0.24s ease;
}
/* Desktop collapse: the panel slides out and the grid track closes behind it. */
.app.collapsed { grid-template-columns: 0 1fr; }

.sidebar {
  background: var(--bg-deep);
  border-right: 1px solid var(--line-soft);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  transition: transform 0.24s ease, opacity 0.18s ease;
}
.app.collapsed .sidebar {
  transform: translateX(-100%);
  opacity: 0;
  pointer-events: none;
}

.sidebar-head {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 24px;
}
.sidebar-brand .eyebrow { margin: 0; white-space: nowrap; }
.sidebar-head .btn { width: 100%; }
/* Collapse control lives in the panel on desktop, next to the brand. */
#panel-close { display: none; }

.threads {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

.thread-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-family: var(--sans);
  font-size: 13.5px;
  padding: 10px 12px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.thread-item:hover { background: rgba(212, 175, 111, 0.06); color: var(--ink); }
.thread-item.active { background: rgba(212, 175, 111, 0.1); color: var(--gold); }

.sidebar-foot {
  padding: 14px 18px;
  border-top: 1px solid var(--line-soft);
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
}
.sidebar-foot .fine {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Dimmer behind the drawer on mobile. */
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.22s ease, visibility 0.22s ease;
  z-index: 15;
  border: 0;
  padding: 0;
}
.scrim.show { opacity: 1; visibility: visible; }

/* ── Chat ────────────────────────────────────────────────────────────────── */

.chat {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  position: relative;
}

.chat-head {
  padding: 12px 18px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 60px;
  flex: 0 0 auto;
}
.chat-head h2 {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 500;
  margin: 0;
  min-width: 0;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Shown on desktop only; the mobile drawer uses #menu-toggle. */
#panel-open { display: none; }

.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 26px 18px;
  display: flex;
  flex-direction: column;
  gap: 26px;
  min-height: 0;
}

.turn { max-width: var(--measure); width: 100%; margin: 0 auto; min-width: 0; }

.turn-role {
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted-2);
  margin-bottom: 8px;
}
.turn--assistant .turn-role { color: var(--gold); }

/* Long horse names and URLs must wrap rather than force a sideways scroll. */
.turn-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.turn-body p { margin: 0 0 12px; }
.turn-body p:last-child { margin-bottom: 0; }
.turn-body strong { color: var(--gold-soft); font-weight: 600; }

/* Tables come back from the model often; they scroll inside themselves so the
   page never does. */
.turn-body table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  margin: 4px 0 14px;
  font-size: 13.5px;
  white-space: nowrap;
}
.turn-body th, .turn-body td {
  border-bottom: 1px solid var(--line-soft);
  padding: 7px 12px 7px 0;
  text-align: left;
}
.turn-body th { color: var(--gold); font-weight: 600; }

.turn--user .turn-body {
  background: var(--bg-raised);
  border-left: 2px solid var(--line);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
}

.tool-note {
  font-size: 12px;
  color: var(--muted-2);
  font-style: italic;
  margin: 6px 0;
}

/* The waiting state is the one place the app can look broken while working, so
   it carries the brand mark with the mane moving plus stepping dots: two
   independent signs of life, in case one is ever mistaken for a static image. */
.thinking {
  display: flex;
  align-items: center;
  gap: 9px;
  font-style: normal;
  letter-spacing: 0.02em;
}
/* Spins like a coin on its axis. The logo PNG is used directly, so this is the
   real artwork rather than a redraw, and the rotation reads as working without
   needing the mane to move. backface-visibility stays visible on purpose: the
   mark mirrors through the back half of the turn, which is what a real coin
   does. */
.thinking-mark {
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  display: block;
  background-image: url(/logo-mark.png);
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  transform-style: preserve-3d;
  animation: dp-coin 2.6s cubic-bezier(0.45, 0, 0.55, 1) infinite;
}
@keyframes dp-coin {
  from { transform: rotateY(0deg); }
  to   { transform: rotateY(360deg); }
}
}
.thinking .dots { display: inline-flex; }
.thinking .dots i {
  font-style: normal;
  animation: dp-dot 1.4s infinite;
}
.thinking .dots i:nth-child(2) { animation-delay: 0.2s; }
.thinking .dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes dp-dot {
  0%, 60%, 100% { opacity: 0.25; }
  30%           { opacity: 1; }
}

.login-mark {
  display: block;
  width: 56px;
  height: 56px;
  margin: 0 0 18px;
  border-radius: 12px;
}

.turn-actions { margin-top: 10px; display: flex; gap: 8px; }
.rate {
  background: none;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  color: var(--muted-2);
  cursor: pointer;
  font-size: 13px;
  padding: 4px 11px;
  line-height: 1.4;
}
.rate:hover { border-color: var(--gold); color: var(--gold); }
.rate.chosen { border-color: var(--gold); color: var(--gold); }

.empty {
  margin: auto;
  text-align: center;
  max-width: 460px;
  color: var(--muted);
  padding: 0 4px;
}
.empty h3 {
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 500;
  color: var(--ink);
  margin: 0 0 12px;
}

.caret::after {
  content: '▍';
  color: var(--gold);
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ── Composer ────────────────────────────────────────────────────────────── */

.composer {
  border-top: 1px solid var(--line-soft);
  padding: 14px 18px calc(12px + env(safe-area-inset-bottom));
  flex: 0 0 auto;
  background: var(--bg);
}

/* The field and the button sit in one rounded shell, so they cannot drift out
   of alignment as the textarea grows. */
.composer form {
  max-width: var(--measure);
  margin: 0 auto;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 6px 6px 8px;
  transition: border-color 0.18s ease;
}
.composer form:focus-within { border-color: var(--gold); }

.composer textarea {
  flex: 1 1 auto;
  min-width: 0;
  resize: none;
  max-height: 168px;
  padding: 9px 6px;
  background: transparent;
  border: none;
  color: var(--ink);
  font-family: var(--sans);
  /* 16px: anything smaller makes iOS zoom on focus. */
  font-size: 16px;
  line-height: 1.5;
}
.composer textarea:focus { outline: none; }
.composer textarea::placeholder { color: var(--muted-2); }

#send {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 10px 20px;
  /* Matches one line of textarea plus its padding, so it sits flush on the
     baseline at rest and stays pinned to the bottom as the field grows. */
  min-height: 40px;
  display: inline-grid;
  place-items: center;
}
.send-icon { display: none; width: 19px; height: 19px; }

.disclaimer {
  max-width: var(--measure);
  margin: 10px auto 0;
  font-size: 11.5px;
  color: var(--muted-2);
  text-align: center;
  text-wrap: balance;
}

/* ── Desktop ─────────────────────────────────────────────────────────────── */

@media (min-width: 861px) {
  .chat-head { padding: 14px 28px; }
  .messages { padding: 30px 28px; }
  .composer { padding: 16px 28px 14px; }
  #panel-close { display: grid; }
  /* Only offer "open" while the panel is actually collapsed. */
  .app.collapsed #panel-open { display: grid; }
}

/* ── Mobile ──────────────────────────────────────────────────────────────── */

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .app.collapsed { grid-template-columns: 1fr; }

  #menu-toggle { display: grid; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(var(--sidebar-w), 86vw);
    z-index: 20;
    transform: translateX(-100%);
    opacity: 1;
    padding-top: env(safe-area-inset-top);
  }
  /* The desktop collapse class must not fight the drawer. */
  .app.collapsed .sidebar { transform: translateX(-100%); opacity: 1; }
  .sidebar.open,
  .app.collapsed .sidebar.open { transform: translateX(0); opacity: 1; pointer-events: auto; }

  .chat-head {
    padding: 10px 14px;
    padding-top: calc(10px + env(safe-area-inset-top));
    min-height: 56px;
  }
  .chat-head h2 { font-size: 16px; }

  .messages { padding: 20px 16px; gap: 22px; }
  .composer { padding: 12px 14px calc(10px + env(safe-area-inset-bottom)); }

  /* An arrow instead of the word, so the field keeps its width and the
     placeholder never wraps onto a clipped second line. */
  .send-label { display: none; }
  .send-icon { display: block; }
  #send { width: 44px; height: 44px; min-height: 44px; padding: 0; }
  .composer textarea { max-height: 132px; }

  .login-card { padding: 32px 24px; border-radius: var(--radius); }
  .login-card h1 { font-size: 28px; }

  .turn-body table { font-size: 13px; }
  .disclaimer { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ── Findings (internal build) ───────────────────────────────────────────────
   Same surface as the chat so it reads as one tool, not a bolted-on admin
   screen. Never reachable on the members' build: the button that opens it stays
   hidden and every route behind it answers 404. */

.panel {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line-soft);
  flex: 0 0 auto;
}
.panel-head h2 {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 500;
  margin: 0;
}
.panel-actions { display: flex; align-items: center; gap: 16px; }
#findings-close { display: grid; }

.panel-body {
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}

.finding {
  width: 100%;
  max-width: var(--measure);
  background: var(--bg-raised);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.finding h3 {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 4px;
}
.finding-meta {
  font-size: 12px;
  color: var(--muted-2);
  margin: 0 0 12px;
}
/* Findings hold tables and query text, so whitespace is load-bearing and a long
   line scrolls inside the card rather than stretching the page. */
.finding-body {
  white-space: pre-wrap;
  overflow-x: auto;
  font-size: 14px;
  color: var(--ink);
  margin: 0;
}
.finding-note {
  margin: 12px 0 0;
  padding-left: 12px;
  border-left: 2px solid var(--line);
  color: var(--muted);
  font-size: 14px;
}
.finding-foot {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 14px;
}

/* Saving a turn: an inline form in place of the actions row, so nothing covers
   the answer being kept. */
.save-form { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.save-form input {
  background: var(--bg-input);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  padding: 9px 12px;
  width: 100%;
}
.save-form input:focus { outline: none; border-color: var(--line); }
.save-form-row { display: flex; align-items: center; gap: 10px; }
