/* OUR-OS Chunk 2 — dark charcoal + warm amber. Phone-first (390px), desktop-safe. */
:root {
  color-scheme: dark;
  --bg: #0e0f13;
  --bg-elev: #15171d;
  --line: #262932;
  --text: #e8e6e3;
  --text-dim: #9a9da6;
  --accent: #e5a844;
  --accent-ink: #171105;
  --user-bubble: #38301c;
  --assistant-bubble: #1b1e24;
  --danger: #e2694f;
  --radius: 18px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;          /* mobile URL bar safe */
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px;
  background: rgba(14, 15, 19, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
  z-index: 2;
}
.brand { font-weight: 700; letter-spacing: 0.14em; font-size: 0.95rem; color: var(--accent); white-space: nowrap; }
.top-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; min-width: 0; }
#model {
  width: clamp(70px, 22vw, 220px);
  min-width: 0;
  padding: 9px 12px;
  font-size: 0.85rem;
  color: var(--text-dim);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
}
#model:focus { border-color: var(--accent); color: var(--text); }
.btn-ghost {
  min-height: 40px;
  padding: 8px 11px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}
.btn-ghost:active { background: var(--line); }

/* thread */
.chat {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 12px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.thread { display: flex; flex-direction: column; gap: 10px; max-width: 760px; margin: 0 auto; }
.msg { display: flex; }
.msg .bubble {
  max-width: 86%;
  padding: 11px 15px;
  border-radius: var(--radius);
  font-size: 1rem;          /* 16px — iOS refuses to zoom on focus */
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--user-bubble); border-bottom-right-radius: 6px; color: #f4ead6; }
.msg.assistant { justify-content: flex-start; }
.msg.assistant .bubble { background: var(--assistant-bubble); border-bottom-left-radius: 6px; }
.msg .who {
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 3px;
}
.msg.assistant.streaming .content::after {
  content: "▍";
  color: var(--accent);
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.msg.error .bubble { background: #2a1713; color: var(--danger); border: 1px solid #3a1f18; }

/* mid-stream failure: partial text is kept, always labeled */
.msg.partial .bubble { border: 1px dashed #43291f; }
.partial-flag {
  margin-top: 6px;
  font-size: 0.72rem;
  line-height: 1.35;
  color: var(--danger);
}

/* empty state — the chat greets you (spec §2.8) */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 18vh 24px 0;
  text-align: center;
  color: var(--text-dim);
}
.empty-mark { font-size: 1.6rem; color: var(--accent); }
.empty-text { font-size: 0.95rem; line-height: 1.5; }

.status { text-align: center; color: var(--danger); font-size: 0.8rem; padding: 4px 12px 6px; }

/* composer — pinned to bottom, safe-area aware */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--bg);
  border-top: 1px solid var(--line);
}
#input {
  flex: 1;
  resize: none;
  min-height: 48px;         /* thumb-sized touch target */
  max-height: 160px;
  padding: 12px 14px;
  font: inherit;
  font-size: 16px;
  line-height: 1.4;
  color: var(--text);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: none;
}
#input:focus { border-color: var(--accent); }
.btn-send {
  min-width: 48px;
  min-height: 48px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 1.3rem;
  font-weight: 800;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.btn-send:disabled { opacity: 0.4; }
.btn-send:active { transform: scale(0.96); }
/* Send turns into Stop while a reply streams */
.btn-send.stop {
  background: var(--danger);
  color: #1c0d09;
  font-size: 0.95rem;
  line-height: 1;
}

/* desktop */
@media (min-width: 700px) {
  .chat { padding: 24px 20px 12px; }
  .msg .bubble { max-width: 74%; }
  #model { width: 240px; }
}
/* the doorman (Chunk 1.5): PIN screen. While locked, the room stays hidden. */
[hidden] { display: none !important; }
body.locked .topbar,
body.locked .chat,
body.locked .status,
body.locked .composer,
body.locked .chip,
body.locked .drawer { display: none; }
.gate {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + env(safe-area-inset-top, 0px)) 24px calc(24px + env(safe-area-inset-bottom, 0px));
}
.gate-card {
  width: min(100%, 340px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}
.gate-card .brand { font-size: 1.15rem; margin-bottom: 8px; }
.gate-label { color: var(--text-dim); font-size: 0.85rem; }
#gate-pin {
  min-height: 52px;
  padding: 12px 16px;
  font-size: 1.1rem;
  text-align: center;
  letter-spacing: 0.12em;
  color: var(--text);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: none;
}
#gate-pin:focus { border-color: var(--accent); }
.btn-gate {
  min-height: 48px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent-ink);
  background: var(--accent);
  border: 0;
  border-radius: 14px;
  cursor: pointer;
}
.btn-gate:disabled { opacity: 0.5; cursor: default; }
.gate-msg { color: var(--danger); font-size: 0.85rem; min-height: 1.2em; }

/* the file room (Chunk 2): a drawer that slides out of the chat room. Read-only. */
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  width: min(92vw, 400px);
  display: flex;
  flex-direction: column;
  background: var(--bg-elev);
  border-left: 1px solid var(--line);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.45);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  transform: translateX(105%);
  visibility: hidden;        /* a closed drawer is not reachable by Tab */
  transition: transform 0.22s ease, visibility 0s linear 0.22s;
}
.drawer.open { transform: translateX(0); visibility: visible; transition: transform 0.22s ease; }
.drawer-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.drawer-title { flex: 1; min-width: 0; font-size: 0.9rem; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 6px 8px 12px; }
.row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;          /* thumb-sized */
  padding: 8px 10px;
  font: inherit;
  font-size: 0.95rem;
  text-align: left;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  -webkit-touch-callout: none;   /* long-press must not raise the iOS callout */
  -webkit-user-select: none;
  user-select: none;
}
.row:active { background: var(--line); }
.row-icon { flex: none; width: 1.4em; text-align: center; }
.row-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-empty, .row-note { padding: 14px 12px; font-size: 0.85rem; color: var(--text-dim); }
.drawer-preview { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; padding: 10px 12px 14px; }
.preview-name { font-size: 0.85rem; font-weight: 600; color: var(--accent); overflow-wrap: anywhere; }
.preview-text {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 10px 12px;
  overflow: auto;
  font: 0.8rem/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.preview-note { min-height: 1.2em; font-size: 0.8rem; color: var(--text-dim); }
.btn-ask {
  min-height: 48px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent-ink);
  background: var(--accent);
  border: 0;
  border-radius: 14px;
  cursor: pointer;
}
.btn-ask:disabled { opacity: 0.4; cursor: default; }
/* the attached-file chip sits above the composer */
.chip {
  display: flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  max-width: calc(100% - 24px);
  margin: 4px 12px 0;
  padding: 6px 6px 6px 12px;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--user-bubble);
  border-radius: 999px;
}
.chip-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-x { flex: none; width: 32px; height: 32px; color: var(--text-dim); background: transparent; border: 0; border-radius: 50%; cursor: pointer; }
@media (min-width: 700px) { .drawer { width: 400px; } }
