/* =========================================================================
   GenAI Chat — Modern SaaS light theme
   ========================================================================= */
:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #f1f4f9;
  --border: #e3e8ef;
  --border-strong: #d3dae5;
  --text: #1a2233;
  --text-muted: #667085;
  --text-faint: #98a2b3;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --danger: #d92d20;
  --danger-soft: #fef3f2;
  --success: #067647;
  --shadow-sm: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.05);
  --shadow-md: 0 4px 12px rgba(16,24,40,.08);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-w: 280px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font-family: inherit; }

/* ---------------- Buttons ---------------- */
.btn {
  appearance: none; border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 9px 16px; font-size: 14px; font-weight: 600; cursor: pointer;
  color: var(--text); background: var(--surface-2);
  transition: background .15s ease, border-color .15s ease, box-shadow .15s ease, transform .05s ease;
}
.btn:hover { background: #e9edf4; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { background: #c7cbe8; cursor: not-allowed; box-shadow: none; }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-block { width: 100%; justify-content: center; display: inline-flex; align-items: center; gap: 8px; }

/* ---------------- Inputs ---------------- */
.input {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 9px 12px; font-size: 14px; font-family: inherit; width: 100%;
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input:disabled { opacity: .6; cursor: not-allowed; }

/* ---------------- Alerts ---------------- */
.alert { border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13px; }
.alert-error { background: var(--danger-soft); border: 1px solid #fda29b; color: var(--danger); }

/* =========================================================================
   Signed-out: centered sign-in card
   ========================================================================= */
body.signed-out { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.app-header, .app-footer { display: none; } /* replaced by shell layout below */

#signin-view { width: 100%; }
.signin-card {
  max-width: 400px; margin: 0 auto; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px; padding: 40px 36px;
  text-align: center; box-shadow: var(--shadow-md);
}
.signin-card .brand-mark {
  width: 48px; height: 48px; border-radius: 12px; margin: 0 auto 20px;
  background: linear-gradient(135deg, var(--primary), #7c6cf0);
  display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 22px;
}
.signin-card h1 { margin: 0 0 8px; font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.signin-card p { color: var(--text-muted); margin: 0 0 28px; font-size: 14px; }
#auth-error { max-width: 400px; margin: 0 auto 16px; }

/* =========================================================================
   Signed-in: full-height app shell (sidebar + chat)
   ========================================================================= */
body.signed-in { height: 100vh; overflow: hidden; }
body.signed-in main { height: 100vh; }
main { display: block; }

.app-shell { 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; padding: 20px 16px; gap: 20px; overflow-y: auto;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; letter-spacing: -.01em; padding: 4px 4px 0; }
.sidebar-brand .brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), #7c6cf0);
  display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 15px;
}
.sidebar-section { display: flex; flex-direction: column; gap: 8px; }
.sidebar-section > .section-title {
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-faint); margin: 0 4px;
}
.sidebar-spacer { flex: 1; }
.sidebar-user {
  border-top: 1px solid var(--border); padding-top: 14px; display: flex; flex-direction: column; gap: 8px;
}
.sidebar-user #user-label { font-size: 13px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ----- Main chat column ----- */
.chat-main { display: flex; flex-direction: column; height: 100vh; min-width: 0; }
.chat-header {
  height: 60px; border-bottom: 1px solid var(--border); background: var(--surface);
  display: flex; align-items: center; padding: 0 24px; gap: 12px; flex-shrink: 0;
}
.chat-header h2 { font-size: 15px; font-weight: 600; margin: 0; color: var(--text); }
.chat-header .subtle { color: var(--text-faint); font-size: 13px; }

/* Transcript scroll area, centered column */
.chat-transcript {
  flex: 1; overflow-y: auto; padding: 28px 24px; scroll-behavior: smooth;
}
.transcript-inner { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }

.chat-empty {
  text-align: center; color: var(--text-muted); margin: 12vh auto; max-width: 420px;
}
.chat-empty .big { font-size: 20px; font-weight: 700; color: var(--text); letter-spacing: -.01em; margin-bottom: 6px; }

/* Messages */
.msg { display: flex; gap: 12px; align-items: flex-start; }
.msg-user { flex-direction: row-reverse; }
.avatar {
  width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0; display: flex;
  align-items: center; justify-content: center; font-size: 13px; font-weight: 700; color: #fff;
}
.msg-user .avatar { background: #0e1726; }
.msg-assistant .avatar { background: linear-gradient(135deg, var(--primary), #7c6cf0); }
.bubble {
  max-width: 100%; padding: 12px 16px; border-radius: 14px; font-size: 14.5px; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word;
}
.msg-user .bubble { background: var(--primary); color: #fff; border-top-right-radius: 4px; }
.msg-assistant .bubble { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-top-left-radius: 4px; box-shadow: var(--shadow-sm); }
.msg-errored .bubble { background: var(--danger-soft); border-color: #fda29b; color: var(--danger); }
.bubble.streaming::after { content: "▍"; margin-left: 2px; opacity: .5; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* Composer pinned at bottom, centered */
.composer-wrap { border-top: 1px solid var(--border); background: var(--surface); padding: 16px 24px 12px; flex-shrink: 0; }
.composer-inner { max-width: 760px; margin: 0 auto; }
.composer {
  display: flex; gap: 10px; align-items: flex-end;
  border: 1px solid var(--border-strong); border-radius: 14px; background: var(--surface);
  padding: 8px 8px 8px 14px; box-shadow: var(--shadow-sm);
}
.composer:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.composer-input {
  flex: 1; resize: none; border: 0; background: transparent; color: var(--text);
  font: inherit; font-size: 14.5px; line-height: 1.5; max-height: 200px; overflow-y: auto; padding: 6px 0;
}
.composer-input:focus { outline: none; }
.composer-send { border-radius: 10px; padding: 9px 18px; }

/* Metrics bar under composer */
#metrics-bar {
  max-width: 760px; margin: 10px auto 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  min-height: 22px;
}
.metrics-empty { font-size: 12px; color: var(--text-faint); }
.metric {
  display: inline-flex; align-items: baseline; gap: 6px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 999px; padding: 4px 11px; font-size: 12px;
}
.metric-label { color: var(--text-faint); text-transform: uppercase; letter-spacing: .04em; font-size: 10px; font-weight: 700; }
.metric-value { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ----- Upload control (in sidebar) ----- */
.upload-card { display: flex; flex-direction: column; gap: 10px; }
.file-drop {
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius-sm);
  padding: 14px; text-align: center; background: var(--surface-2); transition: border-color .15s, background .15s;
}
.file-drop:hover { border-color: var(--primary); background: var(--primary-soft); }
.file-input { width: 100%; font-size: 13px; cursor: pointer; }
.file-input::file-selector-button {
  margin-right: 10px; border: 1px solid var(--border-strong); border-radius: 6px; padding: 6px 12px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
}
.file-input::file-selector-button:hover { border-color: var(--primary); color: var(--primary); }
.field-label { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.upload-status { font-size: 12.5px; color: var(--success); min-height: 1em; word-break: break-word; }
#upload-error { font-size: 12.5px; }

/* Model select in sidebar */
.model-field { display: flex; flex-direction: column; gap: 6px; }

/* Responsive: collapse sidebar on narrow screens */
@media (max-width: 820px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 20; width: var(--sidebar-w); height: 100vh; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-md); }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .chat-header .menu-toggle { display: inline-flex; }
}
.chat-header .menu-toggle { display: none; background: none; border: 0; font-size: 20px; cursor: pointer; color: var(--text-muted); padding: 4px 8px; }
