/* Universal RAG — single-page UI. Light theme with gradient accents echoing the voice orb. */
:root {
  --bg: #f5f6fb;
  --bg-2: #ffffff;
  --panel: #ffffff;
  --panel-2: #f0f2f9;
  --line: #e3e7f0;
  --text: #1b1e2b;
  --muted: #5c6375;
  --faint: #9aa1b4;
  --purple: #7c3aed;
  --blue: #2563eb;
  --red: #e11d48;
  --green: #059669;
  --amber: #d97706;
  --accent: linear-gradient(135deg, #7c3aed 0%, #2563eb 55%, #ec4899 120%);
  --radius: 14px;
  --shadow: 0 10px 40px rgba(40, 50, 90, .12);
  --shadow-sm: 0 2px 8px rgba(40, 50, 90, .08);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(1200px 600px at 80% -10%, rgba(124, 58, 237, .08), transparent 60%),
              radial-gradient(900px 500px at -10% 110%, rgba(37, 99, 235, .07), transparent 55%),
              var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }

/* ---------- Brand / orb ---------- */
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 28px; margin: 0; letter-spacing: -.02em; }
.brand.small { font-weight: 600; font-size: 15px; color: var(--text); }
.brand-orb {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 14px rgba(124, 58, 237, .45), 0 0 28px rgba(37, 99, 235, .25);
  animation: breathe 4.2s ease-in-out infinite;
}
@keyframes breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(1.12); } }

/* ---------- Auth ---------- */
.auth-screen { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 20px; padding: 32px;
  box-shadow: var(--shadow);
}
.tagline { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 14px 0 22px; }
.tabs { display: flex; gap: 6px; background: var(--panel-2); padding: 4px; border-radius: 10px; margin-bottom: 18px; }
.tab {
  flex: 1; border: 0; background: transparent; color: var(--muted);
  padding: 9px; border-radius: 8px; font-size: 14px; font-weight: 500;
}
.tab.active { background: var(--panel); color: var(--text); box-shadow: var(--shadow-sm); }
#auth-form { display: flex; flex-direction: column; gap: 12px; }
input, textarea {
  background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  padding: 12px 14px; border-radius: 10px; font-size: 14px; outline: none; width: 100%;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, textarea:focus { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(124,58,237,.12); }
.primary {
  background: var(--accent); color: #fff; border: 0; padding: 12px; border-radius: 10px;
  font-size: 15px; font-weight: 600; box-shadow: 0 6px 20px rgba(124, 58, 237, .25);
  transition: transform .12s ease, filter .12s ease;
}
.primary:hover { filter: brightness(1.05); }
.primary:active { transform: translateY(1px); }
.error { color: var(--red); font-size: 13px; min-height: 16px; margin: 4px 0 0; }

/* ---------- App layout ---------- */
.app { display: grid; grid-template-columns: 300px 1fr; height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--bg-2); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 18px; gap: 16px; min-height: 0;
}
.upload-zone {
  border: 1.5px dashed var(--line); border-radius: var(--radius); padding: 18px;
  text-align: center; color: var(--muted); transition: all .15s ease; cursor: pointer;
}
.upload-zone:hover, .upload-zone.drag { border-color: var(--purple); background: rgba(124,58,237,.05); color: var(--text); }
.upload-icon { font-size: 24px; color: var(--purple); }
.upload-text { font-size: 13px; margin-top: 6px; line-height: 1.4; }
.upload-text span { color: var(--faint); font-size: 12px; }

.docs { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.docs-head { display: flex; justify-content: space-between; align-items: center;
  font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); margin-bottom: 8px; }
.docs-head button { background: none; border: 0; color: var(--muted); font-size: 15px; }
.doc-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.doc {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-size: 13px; display: flex; flex-direction: column; gap: 5px;
  box-shadow: var(--shadow-sm);
}
.doc-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.doc-title { font-weight: 500; word-break: break-word; }
.doc-del {
  background: none; border: 0; color: var(--faint); font-size: 13px; line-height: 1;
  padding: 2px 4px; border-radius: 6px; flex-shrink: 0; opacity: 0; transition: all .12s ease;
}
.doc:hover .doc-del { opacity: 1; }
.doc-del:hover { color: var(--red); background: rgba(225,29,72,.1); }
.doc-meta { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--faint); }
.badge { padding: 2px 7px; border-radius: 999px; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.badge.ready { background: rgba(5, 150, 105, .12); color: var(--green); }
.badge.pending, .badge.parsing, .badge.embedding, .badge.running { background: rgba(217, 119, 6, .12); color: var(--amber); }
.badge.failed { background: rgba(225, 29, 72, .12); color: var(--red); }
.progress { height: 4px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .3s ease; }

.sidebar-foot { border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.usage { font-size: 12px; color: var(--muted); }
.usage .bar { height: 5px; background: var(--panel-2); border-radius: 999px; margin-top: 5px; overflow: hidden; }
.usage .bar > i { display: block; height: 100%; background: var(--accent); width: 0; }
.who { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); }
.who button { background: none; border: 0; color: var(--faint); text-decoration: underline; }
.foot-actions { display: flex; gap: 8px; }
.ghost-btn {
  flex: 1; background: var(--panel); border: 1px solid var(--line); color: var(--muted);
  padding: 8px 10px; border-radius: 9px; font-size: 12.5px; font-weight: 500;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: all .12s ease;
}
.ghost-btn:hover { border-color: var(--purple); color: var(--text); }

/* ---------- Chat ---------- */
.chat { display: flex; flex-direction: column; min-height: 0; }
.chat-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 24px; border-bottom: 1px solid var(--line); background: var(--bg-2);
}
.chat-head h2 { margin: 0; font-size: 16px; }
.conn { font-size: 11px; color: var(--faint); }
.conn.busy { color: var(--amber); }
.conn.err { color: var(--red); }
.speak-toggle { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); cursor: pointer; }

.thread { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 18px; }
.empty-state { margin: auto; text-align: center; color: var(--muted); max-width: 420px; }
.empty-state h3 { color: var(--text); margin: 18px 0 8px; }
.empty-state p { font-size: 14px; line-height: 1.6; }
.empty-orb {
  width: 72px; height: 72px; border-radius: 50%; margin: 0 auto;
  background: var(--accent); filter: blur(.5px);
  box-shadow: 0 0 30px rgba(124,58,237,.4), 0 0 60px rgba(37,99,235,.22);
  animation: breathe 4.2s ease-in-out infinite;
}

.msg { display: flex; gap: 12px; max-width: 760px; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.avatar { width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center; font-size: 13px; }
.msg.user .avatar { background: var(--panel-2); color: var(--muted); }
.msg.bot .avatar { background: var(--accent); }
.bubble {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 15px; font-size: 14.5px; line-height: 1.6; white-space: pre-wrap; word-wrap: break-word;
  box-shadow: var(--shadow-sm);
}
.msg.user .bubble { background: var(--accent); color: #fff; border-color: transparent; }
.bubble.refusal { color: var(--muted); font-style: italic; }
.bubble .cursor { display: inline-block; width: 7px; height: 16px; background: var(--purple); margin-left: 2px; vertical-align: text-bottom; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.cites { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.cite {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 4px 9px; font-size: 11.5px; color: var(--muted); display: inline-flex; gap: 6px; align-items: center;
}
.cite b { color: var(--purple); }
.typing { display: inline-flex; gap: 4px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); animation: bounce 1.2s infinite; }
.typing i:nth-child(2){ animation-delay: .15s; } .typing i:nth-child(3){ animation-delay: .3s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-5px); opacity: 1; } }

/* ---------- Composer ---------- */
.composer {
  display: flex; align-items: flex-end; gap: 10px; padding: 16px 24px;
  border-top: 1px solid var(--line); background: var(--bg-2);
}
.composer textarea { resize: none; max-height: 140px; line-height: 1.5; }
.send { width: 46px; height: 46px; padding: 0; border-radius: 12px; font-size: 16px; flex-shrink: 0; }
.send:disabled { opacity: .4; cursor: not-allowed; }

.mic-btn {
  position: relative; width: 46px; height: 46px; flex-shrink: 0; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  display: grid; place-items: center; transition: all .15s ease;
}
.mic-btn:hover { color: var(--text); border-color: var(--purple); }
.mic-btn.listening { color: #fff; border-color: transparent; background: var(--accent); box-shadow: 0 0 0 0 rgba(124,58,237,.5); }
.mic-btn.listening .mic-ring { position: absolute; inset: -3px; border-radius: 14px; animation: ring 1.4s ease-out infinite; }
@keyframes ring { 0% { box-shadow: 0 0 0 0 rgba(124,58,237,.5); } 100% { box-shadow: 0 0 0 14px rgba(124,58,237,0); } }
.mic-btn:disabled { opacity: .35; cursor: not-allowed; }

/* ---------- Voice pill ---------- */
.voice-pill {
  position: fixed; bottom: 96px; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 9px 16px; display: flex; align-items: center; gap: 9px; font-size: 13px;
  box-shadow: var(--shadow); z-index: 50;
}
.voice-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

/* ---------- Modal (settings / integrations) ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20, 24, 40, .45); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 20px; z-index: 100;
}
.modal {
  width: 100%; max-width: 540px; max-height: 88vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: var(--shadow); padding: 26px;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.modal-head h2 { margin: 0; font-size: 19px; display: flex; align-items: center; gap: 9px; }
.modal-close { background: none; border: 0; font-size: 22px; color: var(--faint); line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal .sub { color: var(--muted); font-size: 13px; line-height: 1.55; margin: 0 0 18px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text); }
.field .hint { font-size: 11.5px; color: var(--faint); }
.status-line { font-size: 13px; margin: 6px 0 14px; padding: 9px 12px; border-radius: 9px; }
.status-line.ok { background: rgba(5,150,105,.1); color: var(--green); }
.status-line.off { background: var(--panel-2); color: var(--muted); }
.status-line.err { background: rgba(225,29,72,.1); color: var(--red); }
.webhook-box { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin: 6px 0 16px; }
.webhook-box h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); }
.webhook-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; margin: 6px 0; }
.webhook-row code { flex: 1; background: var(--bg-2); border: 1px solid var(--line); border-radius: 7px; padding: 6px 9px; font-size: 12px; overflow-x: auto; white-space: nowrap; }
.webhook-row .tag { font-weight: 600; color: var(--muted); min-width: 48px; }
.copy-btn { background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 5px 9px; font-size: 11.5px; color: var(--muted); }
.copy-btn:hover { border-color: var(--purple); color: var(--text); }
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.modal-actions .primary { flex: 1; }
.btn-secondary { background: var(--panel); border: 1px solid var(--line); color: var(--muted); padding: 12px 16px; border-radius: 10px; font-size: 14px; font-weight: 500; }
.btn-secondary:hover { border-color: var(--red); color: var(--red); }
.divider { height: 1px; background: var(--line); margin: 20px 0; }
.section-title { font-size: 13px; font-weight: 600; color: var(--text); margin: 0 0 12px; }
.row-2 { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; }

@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}
