/* Fisan chat — design tokens
   Palette:  ink #14213D · paper #FBFAF7 · stone #EDEAE3 · green #0E7C66 · muted #6B6862
   Signature: ledger-style monospace metadata (names + timestamps) over a calm paper field. */

:root {
  --ink: #14213D;
  --paper: #FBFAF7;
  --stone: #EDEAE3;
  --stone-deep: #E2DED5;
  --green: #0E7C66;
  --green-soft: #E2F0EC;
  --muted: #6B6862;
  --line: #DAD6CC;
  --danger: #9A2A2A;
  --gold: #B07A12;

  --radius: 14px;
  --radius-sm: 9px;
  --maxw: 760px;

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans); color: var(--ink); background: var(--paper);
  -webkit-font-smoothing: antialiased;
}
.screen { height: 100dvh; }
[hidden] { display: none !important; }

/* ---- brand ---- */
.brand { display: inline-flex; align-items: center; gap: .55rem; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px; background: var(--green);
  box-shadow: inset 0 0 0 3px var(--paper), 0 0 0 1.5px var(--green);
}
.brand-name { font-weight: 680; letter-spacing: -.01em; font-size: 1.15rem; }
.brand--lg .brand-mark { width: 30px; height: 30px; border-radius: 8px; }
.brand--lg .brand-name { font-size: 1.7rem; }

/* ---- join screen ---- */
.join { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1.25rem; padding: 1.5rem; }
.join-card {
  width: 100%; max-width: 380px; background: #fff;
  border: 1px solid var(--line); border-radius: var(--radius); padding: 1.6rem 1.4rem;
  box-shadow: 0 1px 0 var(--stone), 0 18px 40px -28px rgba(20,33,61,.4);
}
.join-card .brand--lg { margin-bottom: 1.1rem; }
.join-title { font-size: 1.3rem; line-height: 1.25; margin: 0 0 .35rem; letter-spacing: -.01em; }
.join-sub { margin: 0 0 1.3rem; color: var(--muted); font-size: .92rem; }
.field { display: block; margin-bottom: .95rem; }
.field-label {
  display: block; font-family: var(--mono); font-size: .72rem; text-transform: uppercase;
  letter-spacing: .08em; color: var(--muted); margin-bottom: .35rem;
}
.input {
  width: 100%; padding: .7rem .8rem; font-size: 1rem; font-family: var(--sans);
  color: var(--ink); background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius-sm); transition: border-color .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.btn {
  width: 100%; padding: .8rem 1rem; font-size: 1rem; font-weight: 620;
  border: 1px solid transparent; border-radius: var(--radius-sm); cursor: pointer;
  transition: transform .05s, background .15s, opacity .15s;
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--ink); color: #fff; }
.btn--primary:hover { background: #1d2e54; }
.btn:disabled { opacity: .55; cursor: default; }
.error {
  margin: .9rem 0 0; padding: .55rem .7rem; background: #fff1f0; color: var(--danger);
  border: 1px solid #f0caca; border-radius: var(--radius-sm); font-size: .88rem;
}
.footnote { color: var(--muted); font-size: .78rem; max-width: 380px; text-align: center; }

/* ---- chat layout ---- */
.chat { display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: .6rem;
  padding: .7rem 1rem; padding-top: calc(.7rem + env(safe-area-inset-top));
  background: var(--paper); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 6;
}

/* conversation toggle */
.convo-toggle {
  flex: 1; min-width: 0; display: inline-flex; align-items: center; gap: .35rem;
  background: #fff; border: 1px solid var(--line); border-radius: 999px;
  padding: .34rem .8rem; cursor: pointer; font: inherit; color: var(--ink);
  position: relative;
}
.convo-title {
  font-weight: 600; font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.convo-toggle .caret { color: var(--muted); font-size: .7rem; }
.unread-dot {
  position: absolute; top: -2px; right: -2px; width: 10px; height: 10px;
  background: var(--gold); border: 2px solid var(--paper); border-radius: 50%;
}

.online-pill {
  flex: none; display: inline-flex; align-items: center; gap: .35rem;
  font-family: var(--mono); font-size: .78rem; color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px; padding: .28rem .6rem;
}
.online-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }

/* conversation panel */
.convo-panel {
  position: sticky; top: 0; z-index: 5;
  background: var(--stone); border-bottom: 1px solid var(--line);
  max-height: 55dvh; overflow-y: auto;
}
.convo-list { padding: .5rem; display: flex; flex-direction: column; gap: .25rem; max-width: var(--maxw); margin: 0 auto; }
.convo-section {
  font-family: var(--mono); font-size: .68rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); padding: .6rem .6rem .2rem;
}
.convo-row {
  display: flex; align-items: center; gap: .6rem; width: 100%;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: .6rem .75rem; cursor: pointer; font: inherit; color: var(--ink); text-align: left;
}
.convo-row:hover { background: var(--green-soft); }
.convo-row.active { border-color: var(--green); box-shadow: 0 0 0 2px var(--green-soft); }
.convo-row .row-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--stone-deep); flex: none; }
.convo-row .row-dot.on { background: var(--green); }
.convo-row .row-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 560; }
.convo-row .row-tag { font-family: var(--mono); font-size: .66rem; color: var(--muted); }
.badge {
  flex: none; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--gold); color: #fff; font-family: var(--mono); font-size: .7rem;
  display: grid; place-items: center;
}

/* privacy banner */
.privacy-banner {
  display: flex; align-items: center; gap: .5rem;
  background: var(--green-soft); border-bottom: 1px solid #cfe6df;
  color: #0c5c4c; font-size: .82rem; padding: .5rem 1rem;
  max-width: var(--maxw); margin: 0 auto; width: 100%;
}
.privacy-banner .lock { font-size: .9rem; }

/* ---- messages ---- */
.messages {
  flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .55rem;
  width: 100%; max-width: var(--maxw); margin: 0 auto; scroll-behavior: smooth;
}
.msg { max-width: 78%; }
.msg.me { align-self: flex-end; }
.msg-meta { font-family: var(--mono); font-size: .68rem; color: var(--muted); margin: 0 .35rem .15rem; display: flex; gap: .5rem; }
.msg.me .msg-meta { justify-content: flex-end; }
.msg-name { color: var(--green); font-weight: 600; }
.msg.me .msg-name { color: var(--muted); }
.bubble {
  background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius); border-top-left-radius: 4px;
  padding: .6rem .8rem; font-size: .98rem; line-height: 1.4;
  white-space: pre-wrap; word-break: break-word;
}
.msg.me .bubble { background: var(--green-soft); border-color: #cfe6df; border-radius: var(--radius); border-top-right-radius: 4px; }

/* file message */
.file-bubble { display: flex; align-items: center; gap: .65rem; text-decoration: none; color: inherit; }
.file-icon {
  flex: none; width: 38px; height: 38px; border-radius: 8px; background: var(--stone-deep);
  color: var(--ink); display: grid; place-items: center; font-family: var(--mono);
  font-size: .62rem; font-weight: 700; letter-spacing: .03em;
}
.file-info { min-width: 0; }
.file-name { font-weight: 600; font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-sub { font-family: var(--mono); font-size: .7rem; color: var(--muted); }
.file-sub .private-tag { color: var(--green); }

.typing { font-family: var(--mono); font-size: .74rem; color: var(--muted); padding: 0 1rem .35rem; max-width: var(--maxw); margin: 0 auto; width: 100%; }

/* ---- composer ---- */
.composer {
  display: flex; align-items: center; gap: .5rem; padding: .6rem 1rem;
  padding-bottom: calc(.6rem + env(safe-area-inset-bottom));
  background: var(--paper); border-top: 1px solid var(--line);
  width: 100%; max-width: var(--maxw); margin: 0 auto;
}
.composer-input {
  flex: 1; padding: .7rem .9rem; font-size: 1rem; font-family: var(--sans); color: var(--ink);
  background: #fff; border: 1px solid var(--line); border-radius: 999px;
}
.composer-input:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.icon-btn {
  flex: none; width: 42px; height: 42px; border-radius: 50%; font-size: 1.25rem; line-height: 1;
  cursor: pointer; border: 1px solid var(--line); background: #fff; color: var(--ink);
  display: grid; place-items: center; transition: background .15s, transform .05s;
}
.icon-btn:hover { background: var(--stone); }
.icon-btn:active { transform: scale(.96); }
.icon-btn--send { background: var(--ink); color: #fff; border-color: var(--ink); }
.icon-btn--send:hover { background: #1d2e54; }
.upload-status { font-family: var(--mono); font-size: .74rem; color: var(--muted); padding: 0 1rem .4rem; text-align: center; }

/* ---- accessibility & motion ---- */
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
