:root {
  /* Skillfluence brand: teal #30C1D7 and charcoal #373A3C, from the Skillfluence logo. White text
     on the teal fails contrast (2.2:1), so filled controls are charcoal, teal marks the active and
     hovered state, and teal TEXT uses the darker --teal-text. */
  --teal: #30c1d7;
  --teal-text: #0f7584;
  --teal-tint: #e6f7fa;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --border: #e1e5e8;
  --text: #373a3c;
  --muted: #6b7075;
  --accent: #373a3c;
  --accent-hover: #232628;
  --warn-bg: #fdf2e3;
  --warn-text: #8a5a13;
  --escalate-bg: #fdeceb;
  --escalate-text: #9c2f26;
  --radius: 10px;
}

* { box-sizing: border-box; }
/* `hidden` must win over the display rules below (#app is display:flex). */
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

#app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 1.05rem; }
.brand-mark { height: 30px; width: auto; }
.brand-name { font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; }
.brand-product { color: var(--teal-text); font-weight: 600; }
.identity { display: flex; align-items: center; gap: 10px; }
.persona-blurb { font-size: 0.75rem; color: var(--muted); max-width: 320px; }

.tabs { display: flex; gap: 4px; padding: 0 20px; background: var(--panel); border-bottom: 1px solid var(--border); }
.tab {
  border: none; background: none; padding: 12px 16px; cursor: pointer; font-size: 0.95rem;
  color: var(--muted); border-bottom: 2px solid transparent;
}
.tab.active { color: var(--text); border-bottom: 3px solid var(--teal); font-weight: 600; }

main { flex: 1; display: flex; min-height: 0; }
.panel { display: none; flex: 1; min-height: 0; }
.panel.active { display: flex; }

/* --- chat --- */
.sidebar {
  width: 220px; flex-shrink: 0; padding: 16px 12px; border-right: 1px solid var(--border);
  background: var(--panel); display: flex; flex-direction: column; gap: 10px;
}
.thread-list { display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.thread-item {
  text-align: left; border: none; background: none; padding: 8px 10px; border-radius: var(--radius);
  cursor: pointer; font-size: 0.85rem; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.thread-item:hover, .thread-item.active { background: var(--bg); }

.chat-area { flex: 1; display: flex; flex-direction: column; max-width: 780px; margin: 0 auto; width: 100%; }
.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 16px; }

.msg { max-width: 85%; }
.msg-user { align-self: flex-end; background: var(--accent); color: #fff; padding: 10px 14px; border-radius: var(--radius); }
.msg-assistant { align-self: flex-start; }
.msg-assistant .msg-text {
  background: var(--panel); border: 1px solid var(--border); padding: 12px 14px; border-radius: var(--radius);
  white-space: pre-wrap; line-height: 1.5;
}
.msg-text > :first-child { margin-top: 0; }
.msg-text > :last-child { margin-bottom: 0; }
.msg-text p { margin: 0 0 10px; }
.msg-text ul, .msg-text ol { margin: 0 0 10px; padding-left: 22px; }
.msg-text li { margin: 3px 0; }
/* A nested list sits INSIDE its parent <li>, so the 10px meant to separate one list from the next
   paragraph would instead open a gap in the middle of an item — tighten it. */
.msg-text li > ul, .msg-text li > ol { margin: 3px 0 0; }
.msg-text h1, .msg-text h2, .msg-text h3, .msg-text h4 {
  margin: 16px 0 6px; font-size: 1em; font-weight: 600; line-height: 1.35;
}
.msg-text h1:first-child, .msg-text h2:first-child,
.msg-text h3:first-child, .msg-text h4:first-child { margin-top: 0; }
.msg-text code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em;
  background: var(--bg); padding: 2px 5px; border-radius: 5px;
}
.msg-text pre {
  margin: 0 0 10px; padding: 10px 12px; background: var(--bg); border-radius: var(--radius);
  overflow-x: auto;
}
.msg-text pre code { background: none; padding: 0; }
.msg-text blockquote {
  margin: 0 0 10px; padding: 2px 0 2px 12px; border-left: 2px solid var(--border); color: var(--muted);
}
.msg-text hr { margin: 12px 0; border: none; border-top: 1px solid var(--border); }
.msg.pending .msg-text::after { content: "▍"; animation: blink 1s step-start infinite; }
@keyframes blink { 50% { opacity: 0; } }
.msg-error .msg-text { border-color: var(--escalate-text); color: var(--escalate-text); }

.steps { margin-top: 6px; font-size: 0.78rem; color: var(--muted); }
.steps summary { cursor: pointer; }
.step { padding: 3px 0 3px 12px; }
.step-warn { color: var(--warn-text); }
.step-model { color: var(--teal-text); }

.citations { margin-top: 6px; font-size: 0.8rem; color: var(--muted); }
.citation { margin-right: 8px; }

/* Prominent and separate from the small muted citation list — this is the actual answer to "do
   you have a template", not a footnote, so it needs to read as part of the response rather than
   something to notice only after scrolling past the citations. */
.downloads { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.download-card {
  display: inline-flex; align-items: center; gap: 6px; align-self: flex-start;
  padding: 8px 12px; font-size: 0.9rem; font-weight: 600; color: var(--text);
  background: var(--teal-tint); border: 1px solid var(--teal); border-radius: var(--radius);
  text-decoration: none; cursor: pointer;
}
.download-card:hover { background: var(--teal); color: var(--text); }

.general-answer {
  margin-bottom: 8px; padding: 6px 10px; font-size: 0.85rem; border-radius: var(--radius);
  background: var(--warn-bg); color: var(--warn-text);
}

.disclaimer { margin-top: 6px; font-size: 0.75rem; color: var(--muted); font-style: italic; }

.badge { margin-top: 8px; display: inline-block; padding: 6px 10px; border-radius: 999px; font-size: 0.8rem; }
.badge-escalated { background: var(--escalate-bg); color: var(--escalate-text); }

.starters { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 20px 12px; }
.starter {
  border: 1px solid var(--border); background: var(--panel); border-radius: var(--radius);
  padding: 8px 12px; font-size: 0.85rem; cursor: pointer; text-align: left;
}
.starter:hover { border-color: var(--teal); }

.composer { display: flex; flex-direction: column; gap: 8px; padding: 12px 20px 20px; border-top: 1px solid var(--border); background: var(--panel); }
.composer textarea {
  resize: none; font: inherit; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius);
}
.composer textarea:focus { border-color: var(--teal); outline: none; box-shadow: 0 0 0 3px var(--teal-tint); }
.composer-actions { display: flex; justify-content: space-between; align-items: center; }
.composer-send { display: flex; align-items: center; gap: 8px; }
.voice-button { display: inline-flex; align-items: center; gap: 6px; }
.voice-button[hidden] { display: none; }
.voice-button.recording { background: var(--escalate-bg); border-color: var(--escalate-text); color: var(--escalate-text); }
.voice-button:disabled { cursor: wait; opacity: 0.7; }
.voice-status { font-size: 0.8rem; color: var(--muted); }
.voice-status.error { color: var(--escalate-text); }

/* --- worksheet --- */
.worksheet-area { max-width: 780px; margin: 0 auto; width: 100%; padding: 24px 20px; overflow-y: auto; }
.panel-intro { color: var(--muted); margin-bottom: 16px; }
.worksheet-form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--muted); }
.field input, .field textarea { font: inherit; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); }
.worksheet-result { margin-top: 20px; }
.worksheet-result .msg-text {
  background: var(--panel); border: 1px solid var(--border); padding: 14px; border-radius: var(--radius);
  white-space: pre-wrap; line-height: 1.5;
}

/* --- admin --- */
.admin-area { max-width: 900px; margin: 0 auto; width: 100%; padding: 24px 20px; overflow-y: auto; }
.admin-heading { margin: 0 0 6px; font-size: 1.15rem; }
.account-form {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px;
}
.account-form .field select, .account-form .field input {
  font: inherit; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff;
}
.account-form input[readonly] { background: var(--bg); color: var(--muted); }
.account-actions { grid-column: 1 / -1; display: flex; gap: 8px; }
.account-message {
  margin-top: 14px; padding: 10px 14px; border-radius: var(--radius);
  background: var(--teal-tint); color: var(--accent-hover); font-size: 0.9rem;
}
.account-message.error { background: var(--escalate-bg); color: var(--escalate-text); }
.account-message code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.95em; }
.account-table { width: 100%; margin-top: 20px; border-collapse: collapse; font-size: 0.88rem; background: var(--panel); }
.account-table th, .account-table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
.account-table th { color: var(--muted); font-weight: 600; font-size: 0.8rem; }
.account-table td:last-child { text-align: right; white-space: nowrap; }
.account-table .btn { padding: 5px 10px; font-size: 0.8rem; margin-left: 4px; }
.status { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.78rem; }
.status-active { background: var(--teal-tint); color: var(--accent-hover); }
.status-off { background: var(--warn-bg); color: var(--warn-text); }
.status-ended { background: var(--bg); color: var(--muted); }

.login-error { font-size: 0.85rem; color: var(--escalate-text); }
.access-ended {
  margin: auto; max-width: 460px; padding: 28px; text-align: center; background: var(--panel);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.access-ended p { margin: 0 0 16px; }

/* --- sign-in screen (shown instead of #app when signed out) --- */
.signin {
  height: 100vh; overflow-y: auto; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 20px; padding: 32px 16px;
  background: linear-gradient(180deg, var(--teal-tint) 0%, var(--bg) 60%);
}
.signin-card {
  width: 100%; max-width: 400px; padding: 36px 32px 32px; text-align: center; background: var(--panel);
  border: 1px solid var(--border); border-top: 4px solid var(--teal); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(55, 58, 60, 0.08);
}
.signin-logo { width: 200px; max-width: 70%; height: auto; display: block; margin: 0 auto 20px; }
.signin-card h1 { margin: 0 0 8px; font-size: 1.35rem; font-weight: 600; color: var(--text); }
.signin-sub { margin: 0 0 24px; color: var(--muted); line-height: 1.45; }
.signin-card .login-error { margin: 0 0 16px; }
.signin-button { display: block; width: 100%; padding: 12px 16px; font-size: 1rem; font-weight: 600; text-decoration: none; }
.signin-foot { margin: 0; max-width: 400px; text-align: center; font-size: 0.75rem; color: var(--muted); }

/* --- buttons --- */
.btn { border: none; border-radius: var(--radius); padding: 9px 14px; font-size: 0.88rem; cursor: pointer; }
.btn-primary { background: var(--accent); color: #fff; text-decoration: none; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg); border: 1px solid var(--border); }
.btn-ghost { background: none; border: 1px solid var(--border); color: var(--muted); }

select#personaSelect { font: inherit; padding: 6px 10px; border-radius: var(--radius); border: 1px solid var(--border); }

.footnote { text-align: center; padding: 10px; font-size: 0.75rem; color: var(--muted); background: var(--panel); border-top: 1px solid var(--border); }

@media (max-width: 720px) {
  .sidebar { display: none; }
  .brand-name { display: none; }
  .account-form { grid-template-columns: 1fr; }
  .account-table th:nth-child(2), .account-table td:nth-child(2) { display: none; }
}
