:root {
  --navy: #0b2545;
  --navy-2: #13315c;
  --accent: #c8a04a;     /* MPD gold */
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #18222e;
  --muted: #5b6b7d;
  --line: #e2e8f0;
  --error: #b00020;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.screen { min-height: 100dvh; display: flex; flex-direction: column; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }

/* --- Gate / sign-in --- */
#gate { align-items: center; justify-content: center; padding: 24px; }
.card {
  background: var(--card);
  width: 100%; max-width: 380px;
  padding: 28px 24px 22px;
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(11, 37, 69, 0.12);
  text-align: center;
}
.logo { width: 64px; height: 64px; margin-bottom: 8px; }
.card h1 { font-size: 1.3rem; margin: 6px 0 2px; color: var(--navy); }
.card p { font-size: 0.95rem; line-height: 1.4; }
.card input {
  width: 100%; padding: 14px; font-size: 1.05rem; text-align: center;
  border: 1px solid var(--line); border-radius: 10px; margin: 10px 0;
}
.card button, .composer button, #redeemBtn {
  background: var(--navy); color: #fff; border: 0; cursor: pointer;
  padding: 13px 18px; font-size: 1rem; border-radius: 10px; width: 100%;
}
.card button:active { transform: translateY(1px); }
.fineprint { font-size: 0.72rem; color: var(--muted); margin-top: 16px; }
.error { color: var(--error); font-size: 0.9rem; }

/* --- Top bar --- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  background: var(--navy); color: #fff;
  padding: 12px 14px; padding-top: max(12px, env(safe-area-inset-top));
}
.logo-sm { width: 28px; height: 28px; }
.topbar .titlewrap { flex: 1; min-width: 0; }
.topbar .title { font-weight: 600; line-height: 1.15; }
.topbar .acct { font-size: 0.72rem; color: #cfe0ff; opacity: 0.9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.link { background: none; border: 0; color: #cfe0ff; cursor: pointer; font-size: 0.9rem; }

/* --- Mode toggle (Ask / Generate) --- */
.modebar { display: flex; gap: 8px; padding: 8px 12px; background: #fff; border-bottom: 1px solid var(--line); position: relative; z-index: 1; }
.modebtn { flex: 1; padding: 9px; border: 1px solid var(--line); background: #e7ecf3; color: var(--muted); border-radius: 9px; font-size: 0.92rem; cursor: pointer; transition: background 0.12s, color 0.12s; }
.modebtn:hover { background: #dde4ee; }
.modebtn.active { background: var(--navy); color: #fff; border-color: var(--navy); font-weight: 700; box-shadow: inset 0 -3px 0 var(--accent); }

/* --- Generate: format selector row --- */
.gencontrols { padding: 8px 12px 0; background: #fff; position: relative; z-index: 1; }
.gencontrols .fb-select { width: 100%; padding: 9px; }

/* --- Generated-document card --- */
.docready { border: 1px solid #cfe0ff; background: #f0f6ff; border-radius: 10px; padding: 12px; }
.docready-t { font-weight: 600; color: var(--navy); margin-bottom: 2px; }
.dl-btn { margin-top: 10px; background: var(--navy); color: #fff; border: 0; padding: 9px 16px; border-radius: 9px; cursor: pointer; font-size: 0.9rem; }
.dl-btn:disabled { opacity: 0.6; }

/* --- Thread --- */
.thread { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.welcome { text-align: center; margin: auto 0; }
.welcome h2 { color: var(--navy); margin-bottom: 4px; }
.examples { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.chip {
  background: #fff; border: 1px solid var(--line); border-radius: 999px;
  padding: 10px 14px; font-size: 0.9rem; cursor: pointer; color: var(--navy-2);
}

.msg { max-width: 90%; padding: 12px 14px; border-radius: var(--radius); line-height: 1.5; }
.msg.user { align-self: flex-end; background: var(--navy); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.bot h1, .msg.bot h2, .msg.bot h3 { font-size: 1.02rem; margin: 8px 0 4px; }
.msg.bot ol, .msg.bot ul { margin: 6px 0; padding-left: 20px; }
.msg.bot p { margin: 6px 0; }
.msg.bot code { background: #eef2f7; padding: 1px 5px; border-radius: 5px; font-size: 0.9em; }

.sources { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 8px; }
.sources h4 { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 0 0 6px; }
.sources a { display: block; font-size: 0.82rem; color: var(--navy-2); text-decoration: none; padding: 3px 0; }
.sources a:hover { text-decoration: underline; }
.src-folder { color: var(--muted); font-size: 0.72rem; }
.sources .src-item { font-size: 0.82rem; color: var(--navy-2); padding: 3px 0; }

.typing { font-style: italic; color: var(--muted); }

/* --- Per-answer feedback dropdown --- */
.fb { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.fb-select { font-size: 0.8rem; padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--navy-2); }
.fb-comment { font-size: 0.85rem; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; flex: 1; min-width: 140px; }
.fb-send { font-size: 0.8rem; padding: 6px 12px; border: 0; border-radius: 8px; background: var(--navy); color: #fff; cursor: pointer; }
.fb-status { font-size: 0.78rem; color: var(--muted); }

/* --- Composer --- */
.composer {
  display: flex; gap: 8px; padding: 10px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: #fff; border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; font-size: 1rem; font-family: inherit; max-height: 140px;
}
.composer button[type="submit"] { width: auto; padding: 0 20px; border-radius: 12px; }
.composer button:disabled { opacity: 0.5; }

/* --- Icon buttons (back + mic) --- */
.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: 0; cursor: pointer; padding: 8px; border-radius: 10px;
}
.topbar .iconbtn { color: #cfe0ff; margin-left: -4px; }
.topbar .iconbtn:active { background: rgba(255, 255, 255, 0.12); }
.composer .mic { color: #fff; background: var(--navy); border: 0; border-radius: 12px; width: 48px; flex: 0 0 auto; }
.composer .mic.listening {
  color: #fff; background: var(--error); border-color: var(--error);
  animation: micpulse 1.2s infinite;
}
@keyframes micpulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(176, 0, 32, 0.5); }
  50%      { box-shadow: 0 0 0 7px rgba(176, 0, 32, 0); }
}

/* --- RTOC logo watermark behind the main view --- */
.watermark {
  position: fixed; inset: 0;
  background-image: url('/rtoc-logo.png');
  background-repeat: no-repeat;
  background-position: center center;
  background-size: cover;
  opacity: 0.08;
  pointer-events: none;
  z-index: 0;
}
.topbar, .thread, .composer { position: relative; z-index: 1; }
