:root {
  /* Stratefix brand palette */
  --bg-0: #0a1119;      /* page background */
  --bg-1: #121c27;      /* app card */
  --bg-2: #0f1822;      /* header / inputs */
  --bg-bot: #1b2735;    /* bot bubble */
  --accent: #f2dc09;    /* signature yellow */
  --accent-dark: #d6c200;
  --text: #f3f5f7;
  --muted: #848b94;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --radius: 18px;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
  --font: 'Public Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 50% -10%, #16263a 0%, transparent 60%),
    linear-gradient(160deg, #0a1119 0%, #060a0f 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.app {
  width: 100%;
  max-width: 460px;
  height: min(760px, 94vh);
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Toggled screens — min-height:0 lets the inner list scroll instead of growing */
.view { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.hidden { display: none !important; }

/* ── Header ───────────────────────────────────────────── */
.header {
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(242, 220, 9, 0.18);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.header .avatar {
  width: 42px; height: 42px;
  border-radius: 13px;
  background: var(--accent);
  color: #0a1119;
  display: grid; place-items: center;
  font-weight: 800; font-size: 20px;
  box-shadow: 0 4px 14px rgba(242, 220, 9, 0.35);
}
.header-text { line-height: 1.25; }
.header h1 { font-size: 16px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.header p { font-size: 12px; margin: 3px 0 0; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.header .dot { width: 7px; height: 7px; border-radius: 50%; background: #2ecc71; box-shadow: 0 0 0 3px rgba(46, 204, 113, 0.18); }
.header-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.header .logout {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 7px 12px; border-radius: 9px;
  font-size: 12px; font-weight: 600; cursor: pointer;
  font-family: inherit; transition: all 0.15s ease;
  text-decoration: none; display: inline-flex; align-items: center;
}
.header .logout:hover { border-color: var(--accent); color: var(--accent); }

/* ── Login ────────────────────────────────────────────── */
.login {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 40px 30px;
  text-align: center;
}
.login .lock {
  width: 66px; height: 66px; margin: 0 auto 18px;
  border-radius: 20px;
  background: var(--accent);
  color: #0a1119;
  display: grid; place-items: center;
  font-size: 30px;
  box-shadow: 0 10px 30px rgba(242, 220, 9, 0.3);
}
.login h2 { margin: 0 0 8px; font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }
.login p { margin: 0 0 24px; color: var(--muted); font-size: 14px; }

input[type=text], input[type=password] {
  width: 100%;
  padding: 13px 15px;
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input::placeholder { color: #5d666f; }
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(242, 220, 9, 0.15); }

.btn {
  width: 100%;
  margin-top: 14px;
  padding: 13px;
  background: var(--accent);
  color: #0a1119;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease;
}
.btn:hover { background: var(--accent-dark); }
.btn:active { transform: scale(0.99); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.error { color: #ff6b6b; font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ── Chat ─────────────────────────────────────────────── */
.messages {
  flex: 1;
  min-height: 0;            /* critical: enables scrolling */
  overflow-y: auto;
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background:
    radial-gradient(700px 300px at 50% 0%, rgba(242, 220, 9, 0.03), transparent 70%),
    var(--bg-1);
}
.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.12); border-radius: 8px; }
.messages::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.22); }
.messages { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.18) transparent; }

.msg {
  max-width: 84%;
  padding: 11px 15px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: rise 0.22s ease;
  scroll-margin-top: 14px; /* breathing room when a message is scrolled to top */
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.msg.bot {
  background: var(--bg-bot);
  border: 1px solid var(--border);
  color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 5px;
}
.msg.user {
  background: var(--accent);
  color: #0a1119;
  font-weight: 500;
  align-self: flex-end;
  border-bottom-right-radius: 5px;
}
.msg.bot p { margin: 0 0 8px; }
.msg.bot p:last-child { margin-bottom: 0; }
.msg.bot ul { margin: 4px 0 8px; padding-left: 20px; }
.msg.bot ul:last-child { margin-bottom: 0; }
.msg.bot li { margin: 3px 0; }
.msg.bot li::marker { color: var(--accent); }
.msg.bot strong { color: #fff; font-weight: 700; }

.sources { font-size: 11px; color: var(--muted); align-self: flex-start; margin-top: -6px; padding-left: 6px; }

.typing { display: inline-flex; gap: 5px; padding: 2px 0; }
.typing span { width: 7px; height: 7px; background: var(--muted); border-radius: 50%; animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.3; } 30% { opacity: 1; } }

.chat-input {
  display: flex;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-2);
  flex-shrink: 0;
}
.chat-input input { flex: 1; }
.chat-input button {
  background: var(--accent);
  border: none; color: #0a1119;
  width: 48px; border-radius: 12px;
  display: grid; place-items: center;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}
.chat-input button:hover { background: var(--accent-dark); }
.chat-input button:active { transform: scale(0.95); }

.footer {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  padding: 8px;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.footer strong { color: var(--accent); font-weight: 700; }

/* ── Admin ────────────────────────────────────────────── */
.admin { padding: 22px; overflow-y: auto; min-height: 0; }
.admin::-webkit-scrollbar { width: 8px; }
.admin::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 8px; }
.admin label { display: block; font-size: 13px; font-weight: 700; margin: 16px 0 7px; }
.admin textarea, .admin input[type=file], .admin input[type=password] {
  width: 100%; padding: 11px 13px;
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  color: var(--text);
  font-size: 14px; font-family: inherit;
  outline: none;
}
.admin textarea { min-height: 120px; resize: vertical; }
.admin textarea:focus, .admin input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(242, 220, 9, 0.15); }
.admin input[type=file] { padding: 10px; color: var(--muted); }
.status-box {
  background: var(--bg-2);
  border: 1px solid var(--border);
  padding: 13px 15px; border-radius: 12px;
  font-size: 13px; color: var(--text); margin-bottom: 6px;
}
.crawl-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-top: 12px; flex-wrap: wrap;
}
.crawl-row .switch { display: flex; align-items: center; gap: 9px; margin: 0; font-weight: 600; font-size: 13px; cursor: pointer; }
.crawl-row .switch input { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }
.crawl-row .maxpages { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.crawl-row .maxpages input { width: 72px; padding: 7px 9px; }

/* ── OneDrive sync card ─────────────────────────────────── */
.sync-card {
  border: 1px solid var(--accent);
  background: rgba(242, 220, 9, 0.05);
  border-radius: 14px;
  padding: 16px;
  margin: 4px 0 8px;
}
.sync-card h3 { margin: 0 0 6px; font-size: 15px; }
.sync-card label { margin-top: 10px; }
.sync-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.btn-sm {
  padding: 9px 16px; border: 1px solid var(--border-strong); background: var(--bg-2);
  color: var(--text); border-radius: 10px; font-size: 13px; font-weight: 600;
  font-family: inherit; cursor: pointer;
}
.btn-sm:hover { border-color: var(--accent); }
.btn-sm.primary { background: var(--accent); color: #0a1119; border-color: var(--accent); }
.btn-sm.primary:hover { background: var(--accent-dark); }
.sync-status { margin-top: 12px; font-size: 13px; min-height: 18px; }
.section-h { font-size: 14px; margin: 20px 0 4px; color: var(--muted); font-weight: 700; }

/* ── Users panel ─────────────────────────────────────────── */
.users-list { margin: 10px 0; display: flex; flex-direction: column; gap: 6px; }
.user-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 9px 12px; background: var(--bg-2);
  border: 1px solid var(--border); border-radius: 10px; font-size: 13px; flex-wrap: wrap;
}
.user-row .tag {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  background: rgba(242, 220, 9, 0.18); color: var(--accent);
  padding: 2px 7px; border-radius: 6px; margin-left: 4px;
}
.user-row .tag.off { background: rgba(255, 107, 107, 0.18); color: #ff6b6b; }
.user-actions { display: flex; gap: 6px; }
.create-user { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.create-user input, .create-user select {
  flex: 1; min-width: 120px; padding: 9px 11px; background: var(--bg-2);
  border: 1px solid var(--border-strong); border-radius: 10px; color: var(--text);
  font-size: 13px; font-family: inherit;
}
.create-user select { flex: 0 0 auto; }
.result { font-size: 13px; margin-top: 14px; white-space: pre-wrap; color: var(--text); line-height: 1.55; }
.muted { color: var(--muted); font-size: 12px; }
a.link { color: var(--accent); font-size: 13px; text-decoration: none; font-weight: 600; }
a.link:hover { text-decoration: underline; }

/* Login lock emoji uses the same chip style on admin/chat login */
.login .lock { font-style: normal; }
