/* Walli - SafetyWallet chat assistant.
   The palette is the SafetyWallet one, shared with the version 3 phone app:
   a warm near-black, gold for anything you act on, orange as a second accent,
   and light cards so long answers stay readable. */

@font-face {
  font-family: 'Montserrat';
  src: url('../fonts/montserrat-latin.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215;
}
@font-face {
  font-family: 'Montserrat';
  src: url('../fonts/montserrat-latin-ext.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --dark: #1c1710;
  --dark-2: #262019;
  --dark-3: #322a20;
  --dark-line: #3a3128;
  --gold: #f2a93c;
  --gold-dark: #d9922a;
  --orange: #e8731c;
  --ink: #1c2733;
  --ink-soft: #5a6b76;
  --ink-faint: #8b9aa4;
  --line: #dde5e9;
  --bg: #f2f5f7;
  --card: #ffffff;
  --danger: #c0392b;
  --ok: #2e8b57;
  --radius: 12px;
  --sidebar: 288px;
  --shell: 900px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

button, input, textarea { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- layout */

.shell { display: flex; height: 100dvh; overflow: hidden; }

/* ------------------------------------------------------------- side panel */

.side {
  width: var(--sidebar);
  flex: none;
  background: var(--dark);
  color: #fff;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--dark-line);
  transition: margin-left 0.18s ease;
}

.side-head {
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--dark-line);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.side-head img { height: 30px; width: auto; }

.new-chat {
  margin: 0.9rem 1rem 0.4rem;
  padding: 0.7rem 1rem;
  background: var(--gold);
  color: #26200f;
  border: 0;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: background 0.15s ease;
}
.new-chat:hover { background: var(--gold-dark); }

.history { flex: 1; overflow-y: auto; padding: 0.6rem 0.6rem 1rem; }
.history-day {
  color: var(--gold);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.9rem 0.6rem 0.35rem;
}
.history-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.55rem;
  border-radius: 10px;
  cursor: pointer;
  color: #e8e3db;
  font-size: 0.86rem;
}
.history-item:hover { background: var(--dark-2); }
.history-item.current { background: var(--dark-3); color: #fff; }
.history-item .label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-item .label[contenteditable="true"] {
  white-space: normal;
  background: var(--dark);
  outline: 1px solid var(--gold);
  border-radius: 5px;
  padding: 0 3px;
}
.history-item .tools { display: none; gap: 0.1rem; flex: none; }
.history-item:hover .tools, .history-item.current .tools { display: flex; }
.icon-button {
  background: none;
  border: 0;
  color: var(--ink-faint);
  cursor: pointer;
  padding: 0.2rem;
  border-radius: 6px;
  line-height: 0;
}
.icon-button:hover { color: #fff; background: rgba(255,255,255,0.1); }
.icon-button svg { width: 15px; height: 15px; }

.side-foot {
  border-top: 1px solid var(--dark-line);
  padding: 0.8rem 1rem;
  font-size: 0.8rem;
  color: #b9b1a5;
}
.side-foot .who { color: #fff; font-weight: 600; }
.side-foot a { color: var(--gold); text-decoration: none; }
.side-foot a:hover { text-decoration: underline; }

/* ------------------------------------------------------------ main column */

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.top-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 1rem;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.top-bar h1 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.top-bar .icon-button { color: var(--ink-soft); }
.top-bar .icon-button:hover { color: var(--ink); background: var(--bg); }
.panel-toggle { display: none; }

.stream { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.stream-inner { max-width: var(--shell); margin: 0 auto; padding: 1.4rem 1.1rem 2rem; }

/* --------------------------------------------------------- opening screen */

.opening { text-align: center; padding: 2.2rem 1rem 1rem; }
.opening img { width: 132px; height: auto; }
.opening h2 { margin: 0.8rem 0 0.3rem; font-size: 1.45rem; font-weight: 700; }
.opening p { margin: 0 auto; max-width: 30rem; color: var(--ink-soft); font-size: 0.95rem; }

.starters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 0.7rem;
  max-width: 640px;
  margin: 1.6rem auto 0;
}
.starter {
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.85rem 0.95rem;
  cursor: pointer;
  font-size: 0.87rem;
  color: var(--ink);
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.starter:hover { border-color: var(--gold); transform: translateY(-1px); }

/* -------------------------------------------------------------- messages */

.turn { display: flex; gap: 0.8rem; margin-bottom: 1.5rem; }
.turn .face {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--dark);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.turn .face img { width: 34px; height: 34px; object-fit: cover; }
.turn .face.you {
  background: var(--gold);
  color: #26200f;
  font-weight: 700;
  font-size: 0.8rem;
}
.turn .body { min-width: 0; flex: 1; }
.turn .name { font-weight: 700; font-size: 0.82rem; margin-bottom: 0.15rem; }
.turn.from-you .bubble {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
}
.turn.from-walli .bubble { padding: 0.1rem 0; }

.tools-row { display: flex; gap: 0.15rem; margin-top: 0.45rem; opacity: 0; transition: opacity 0.15s ease; }
.turn:hover .tools-row, .tools-row:focus-within { opacity: 1; }
.tools-row .icon-button { color: var(--ink-faint); }
.tools-row .icon-button:hover { color: var(--ink); background: var(--bg); }
.tools-row .icon-button.on { color: var(--orange); }

.thinking { display: inline-flex; gap: 4px; padding: 0.45rem 0; }
.thinking span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--gold);
  animation: bounce 1.1s infinite ease-in-out;
}
.thinking span:nth-child(2) { animation-delay: 0.15s; }
.thinking span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.45; }
  40% { transform: translateY(-5px); opacity: 1; }
}

.trouble {
  background: #fdf0d0;
  border: 1px solid #ecd9a0;
  color: #7a5a00;
  border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
  font-size: 0.88rem;
}

/* ------------------------------------------------- what Walli writes back */

.said > *:first-child { margin-top: 0; }
.said > *:last-child { margin-bottom: 0; }
.said h2 { font-size: 1.15rem; margin: 1.4rem 0 0.5rem; font-weight: 700; }
.said h3 { font-size: 1rem; margin: 1.2rem 0 0.4rem; font-weight: 700; }
.said h4 { font-size: 0.95rem; margin: 1.1rem 0 0.35rem; font-weight: 700; }
.said p { margin: 0 0 0.85rem; }
.said ul, .said ol { margin: 0 0 0.9rem; padding-left: 1.35rem; }
.said li { margin-bottom: 0.35rem; }
.said li > ul, .said li > ol { margin-top: 0.35rem; }
.said a { color: var(--orange); text-decoration: underline; text-underline-offset: 2px; }
.said strong { font-weight: 700; }
.said hr { border: 0; border-top: 1px solid var(--line); margin: 1.3rem 0; }
.said blockquote {
  margin: 0 0 0.9rem;
  padding: 0.5rem 0.9rem;
  border-left: 3px solid var(--gold);
  background: var(--card);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--ink-soft);
}
.said code {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0.1rem 0.32rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.86em;
}
.said pre {
  background: var(--dark);
  color: #f4efe7;
  padding: 0.9rem 1rem;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 0 0 0.9rem;
}
.said pre code { background: none; border: 0; padding: 0; color: inherit; font-size: 0.85rem; }

/* Tables are the reason people ask for a comparison, so they get real
   treatment: their own scroll on a narrow screen rather than stretching the
   page sideways. */
.table-wrap {
  overflow-x: auto;
  margin: 0 0 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  -webkit-overflow-scrolling: touch;
}
.said table { border-collapse: collapse; width: 100%; font-size: 0.88rem; }
.said thead th {
  background: var(--dark);
  color: #fff;
  text-align: left;
  font-weight: 700;
  padding: 0.6rem 0.8rem;
  white-space: nowrap;
  border-bottom: 2px solid var(--gold);
}
.said tbody td {
  padding: 0.55rem 0.8rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.said tbody tr:last-child td { border-bottom: 0; }
.said tbody tr:nth-child(even) { background: #f8fafb; }

/* ------------------------------------------------------------- the writer */

.writer { border-top: 1px solid var(--line); background: var(--card); padding: 0.8rem 1.1rem 0.5rem; }
.writer-inner { max-width: var(--shell); margin: 0 auto; }
.writer-box {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.45rem 0.45rem 0.45rem 0.85rem;
  background: var(--bg);
  transition: border-color 0.15s ease;
}
.writer-box:focus-within { border-color: var(--gold); }
.writer-box textarea {
  flex: 1;
  border: 0;
  background: none;
  resize: none;
  outline: none;
  max-height: 220px;
  min-height: 26px;
  padding: 0.28rem 0;
  line-height: 1.5;
}
.attach {
  flex: none;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 9px;
  background: none;
  color: var(--ink-soft);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: -0.45rem;
}
.attach:hover { background: #e7ecef; color: var(--ink); }
.attach svg { width: 19px; height: 19px; }

/* What is waiting to be sent with the next question. */
.attached { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.55rem; }
.chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.35rem 0.5rem;
  font-size: 0.8rem;
  max-width: 260px;
}
.chip img { width: 34px; height: 34px; object-fit: cover; border-radius: 6px; flex: none; }
.chip .paper {
  width: 34px; height: 34px; border-radius: 6px; flex: none;
  background: var(--dark); color: var(--gold);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.62rem; font-weight: 800; letter-spacing: 0.02em;
}
.chip .about { min-width: 0; }
.chip .about b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.chip .about span { color: var(--ink-faint); font-size: 0.74rem; }
.chip .about span.bad { color: var(--danger); }
.chip .drop {
  background: none; border: 0; color: var(--ink-faint); cursor: pointer;
  font-size: 1.1rem; line-height: 1; padding: 0 0.15rem;
}
.chip .drop:hover { color: var(--danger); }
.chip.working { opacity: 0.6; }

/* Dragging a file anywhere over the page. */
body.dropping .writer-box { border-color: var(--gold); background: #fff8ec; }
body.dropping::after {
  content: 'Drop it here to attach';
  position: fixed; inset: 0; z-index: 40;
  background: rgba(28, 23, 16, 0.55);
  color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}

/* Attachments shown on a message already sent. */
.said-attachments { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.55rem; }
.said-attachments a { text-decoration: none; color: inherit; }
.said-attachments img {
  max-width: 210px; max-height: 210px;
  border-radius: 10px; border: 1px solid var(--line); display: block;
}

.send {
  flex: none;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: var(--gold);
  color: #26200f;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.send:hover:not(:disabled) { background: var(--gold-dark); }
.send:disabled { background: var(--line); color: var(--ink-faint); cursor: not-allowed; }
.send svg { width: 19px; height: 19px; }

.small-print {
  text-align: center;
  font-size: 0.72rem;
  color: var(--ink-faint);
  padding: 0.5rem 0 0.35rem;
}
.small-print a { color: var(--ink-soft); }

/* ------------------------------------------------------------- on a phone */

.scrim { display: none; }

@media (max-width: 860px) {
  .side {
    position: fixed;
    z-index: 30;
    top: 0; bottom: 0; left: 0;
    margin-left: calc(-1 * var(--sidebar));
    box-shadow: 0 0 30px rgba(0,0,0,0.35);
  }
  body.panel-open .side { margin-left: 0; }
  body.panel-open .scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 20;
    background: rgba(0,0,0,0.45);
  }
  .panel-toggle { display: inline-flex; }
  .stream-inner { padding: 1rem 0.85rem 1.5rem; }
  .starters { grid-template-columns: 1fr; }
  .opening img { width: 104px; }
  .tools-row { opacity: 1; }
}
