/* The Creed — chat UI. Mirrors scriptmaster palette + type. */

:root {
  --bg:         #0d1117;
  --surface:    #161b22;
  --surface-2:  #1e293b;
  --surface-3:  #21262d;
  --border:     #30363d;
  --border-2:   #233148;
  --amber:      #f59e0b;
  --amber-dk:   #d97706;
  --amber-soft: rgba(245, 158, 11, .12);
  --text:       #e6edf3;
  --muted:      #8b949e;
  --green:      #22c55e;
  --red:        #f85149;

  --sidebar-w:  260px;
  --radius:     10px;
  --radius-sm:  6px;
  --t-fast:     .15s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', system-ui, sans-serif;
  min-height: 100vh;
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.5;
}

button { font-family: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
textarea, select, input { font-family: inherit; color: inherit; }

/* ── Boot / auth gate ──────────────────────────────────────────────────── */
.boot {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: var(--bg);
  z-index: 100;
}
.boot-brand {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 2.5rem;
  letter-spacing: .35em;
  color: var(--amber);
}
.boot-text { color: var(--muted); font-size: .9rem; }

/* ── App shell ─────────────────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
}

/* ── Sidebar ───────────────────────────────────────────────────────────── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-head {
  padding: 1.1rem 1.1rem .8rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6rem;
}
.sidebar .brand {
  font-family: 'Bebas Neue', sans-serif;
  letter-spacing: .3em;
  color: var(--amber);
  font-size: 1rem;
}
.btn-new {
  background: var(--amber-soft);
  color: var(--amber);
  border: 1px solid var(--amber);
  border-radius: var(--radius-sm);
  padding: .35rem .7rem;
  font-size: .75rem;
  font-weight: 600;
  transition: background var(--t-fast);
}
.btn-new:hover { background: rgba(245, 158, 11, .22); }

.history {
  flex: 1;
  overflow-y: auto;
  padding: .9rem .7rem;
  min-height: 0;
}
.history-label {
  font-size: .65rem;
  letter-spacing: .2em;
  color: var(--muted);
  text-transform: uppercase;
  padding: 0 .4rem .5rem;
}
.history-list { list-style: none; display: grid; gap: .15rem; }
.history-list li {
  padding: .55rem .6rem;
  border-radius: var(--radius-sm);
  font-size: .82rem;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background var(--t-fast);
}
.history-list li:hover { background: var(--surface-2); }
.history-list li.active { background: var(--amber-soft); color: var(--amber); }
.history-empty {
  color: var(--muted);
  font-size: .75rem;
  font-style: italic;
  cursor: default !important;
  padding: .55rem .6rem;
}
.history-empty:hover { background: transparent !important; }

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding: .8rem .9rem 1rem;
  display: grid;
  gap: .65rem;
}
.engine-pill {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .45rem .65rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .75rem;
  color: var(--muted);
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 8px rgba(245, 158, 11, .55);
  flex-shrink: 0;
}
.dot.ok { background: var(--green); box-shadow: 0 0 8px rgba(34, 197, 94, .55); }
.dot.bad { background: var(--red); box-shadow: 0 0 8px rgba(248, 81, 73, .55); }

.user-row {
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: 0 .15rem;
}
.user-email {
  flex: 1;
  font-size: .78rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  font-size: .95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color var(--t-fast), border-color var(--t-fast), background var(--t-fast);
}
.icon-btn:hover:not(:disabled) { color: var(--amber); border-color: var(--amber); }

/* ── Main ──────────────────────────────────────────────────────────────── */
.main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
}
.main-head {
  padding: 1rem 1.5rem .85rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  gap: 1rem;
}
.wordmark {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.75rem;
  letter-spacing: .12em;
  color: var(--amber);
  font-weight: 400;
}
.tagline {
  color: var(--muted);
  font-size: .82rem;
}

/* ── Thread ────────────────────────────────────────────────────────────── */
.thread {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  min-height: 0;
  scroll-behavior: smooth;
}

.empty-state {
  margin: auto;
  max-width: 620px;
  padding: 2rem 1rem;
  text-align: center;
}
.empty-brand {
  font-family: 'Bebas Neue', sans-serif;
  letter-spacing: .4em;
  color: var(--amber);
  font-size: 1.1rem;
  margin-bottom: 1.3rem;
}
.empty-prompt {
  color: var(--muted);
  font-size: .95rem;
  line-height: 1.6;
  margin-bottom: 2rem;
}
.suggest-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: .65rem;
}
.suggest {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: .85rem 1rem;
  font-size: .85rem;
  text-align: left;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.suggest:hover {
  border-color: var(--amber);
  background: var(--surface-2);
}

.msg {
  display: flex;
  gap: .75rem;
  max-width: 760px;
  width: 100%;
}
.msg.user  { align-self: flex-end;   flex-direction: row-reverse; }
.msg.ai    { align-self: flex-start; }

.bubble {
  border-radius: var(--radius);
  padding: .8rem 1rem;
  font-size: .92rem;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.55;
}
.msg.user .bubble {
  background: var(--amber);
  color: #0d1117;
  border-bottom-right-radius: 3px;
  max-width: 80%;
}
.msg.ai .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 3px;
  max-width: 80%;
}
.bubble.thinking {
  color: var(--muted);
  font-style: italic;
}
.bubble.error {
  border-color: var(--red);
  background: rgba(248, 81, 73, .08);
  color: var(--red);
  font-style: normal;
}

.sources {
  margin-top: .55rem;
  max-width: 80%;
}
.sources[open] { display: block; }
.sources > .source { margin-top: .3rem; }
.sources-label {
  font-size: .65rem;
  letter-spacing: .2em;
  color: var(--muted);
  text-transform: uppercase;
  cursor: pointer;
  list-style: none;
  padding: .35rem 0;
  user-select: none;
}
.sources-label::-webkit-details-marker { display: none; }
.sources-label::before {
  content: '▸ ';
  display: inline-block;
  margin-right: .3rem;
  transition: transform .15s ease;
  color: var(--amber);
}
.sources[open] > .sources-label::before {
  content: '▾ ';
}
.source {
  font-size: .76rem;
  padding: .45rem .65rem;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-left: 2px solid var(--amber);
  border-radius: var(--radius-sm);
  color: var(--text);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .5rem;
  align-items: center;
}
.source .src-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.source .src-cat { color: var(--muted); font-size: .7rem; }
.source .src-dist {
  font-variant-numeric: tabular-nums;
  color: var(--amber);
  font-size: .72rem;
  font-weight: 600;
}

/* ── Composer ──────────────────────────────────────────────────────────── */
.composer {
  border-top: 1px solid var(--border);
  padding: 1rem 1.5rem 1.25rem;
  background: var(--bg);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .75rem;
  align-items: end;
}
.prompt {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .8rem 1rem;
  font-size: .95rem;
  resize: none;
  max-height: 200px;
  outline: none;
  transition: border-color var(--t-fast);
}
.prompt:focus { border-color: var(--amber); }
.prompt::placeholder { color: var(--muted); }

.composer-actions { display: flex; gap: .5rem; align-items: stretch; }
.btn-send {
  background: var(--amber);
  color: #0d1117;
  border: none;
  border-radius: var(--radius);
  padding: 0 1.4rem;
  font-weight: 600;
  font-size: .9rem;
  transition: background var(--t-fast);
}
.btn-send:hover:not(:disabled) { background: var(--amber-dk); }
.composer-actions .icon-btn {
  width: auto;
  padding: 0 .75rem;
  height: auto;
}

/* ── Drawer ────────────────────────────────────────────────────────────── */
.drawer {
  position: fixed;
  top: 0; right: 0;
  height: 100vh;
  width: 320px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 50;
  padding: 1.25rem 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  box-shadow: -8px 0 40px rgba(0, 0, 0, .4);
}
.drawer[hidden] { display: none; }
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: .9rem;
  border-bottom: 1px solid var(--border);
}
.drawer-head h2 {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.3rem;
  color: var(--amber);
  letter-spacing: .15em;
  font-weight: 400;
}
.drawer-section { display: grid; gap: .45rem; }
.setting-label {
  font-size: .68rem;
  letter-spacing: .2em;
  color: var(--muted);
  text-transform: uppercase;
}
.setting-input, .setting-readout {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .55rem .7rem;
  font-size: .85rem;
}
.setting-readout { color: var(--text); }
.setting-hint { font-size: .72rem; color: var(--muted); }
.slider { width: 100%; accent-color: var(--amber); }

/* ── Mobile ────────────────────────────────────────────────────────────── */
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .drawer { width: 100%; }
  .composer { padding: .85rem 1rem 1rem; }
  .main-head { padding: .85rem 1rem; }
  .thread { padding: 1rem; }
}

/* ── Sign-in ───────────────────────────────────────────────────────────── */
.signin {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: var(--bg);
  z-index: 110;
  overflow-y: auto;
  font-size: 1.4rem; /* 21px at the 15px root; text on this screen is never smaller */
}
.signin[hidden], .signin-form[hidden] { display: none; }
.signin-card {
  width: 100%;
  max-width: 26rem;
  display: grid;
  gap: 1.5rem;
  justify-items: center;
}
.signin-form {
  width: 100%;
  display: grid;
  gap: .6rem;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.signin-form label { color: var(--text); font-size: 1.4rem; margin-top: .4rem; }
.signin-form input {
  width: 100%;
  min-height: 3.25rem;
  padding: .6rem .9rem;
  font-size: 1.4rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.signin-form input:focus { outline: 2px solid var(--amber); outline-offset: 1px; }
.signin-note { font-size: 1.4rem; }
.signin-btn { min-height: 3.25rem; margin-top: .8rem; font-size: 1.4rem; }
.signin-err { min-height: 1.5rem; color: var(--red); font-size: 1.4rem; }
.signin-link {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.4rem;
  text-decoration: underline;
  padding: .5rem 0;
}

.boot[hidden], .app[hidden] { display: none; }
