:root {
  --bg: #0b1020;
  --bg-soft: #101933;
  --card: #121a2a;
  --line: #273349;
  --text: #e5ebf5;
  --muted: #94a3b8;
  --primary: #4f7cff;
  --danger: #ef4444;
  --ok: #22c55e;
  --warn: #eab308;
  --chip: #1a2338;
  --chip-line: #334155;
}
* { box-sizing: border-box; }
body {
  font-family: Inter, Segoe UI, Arial, sans-serif;
  margin: 0;
  padding: 24px;
  background: radial-gradient(1200px 500px at 15% -10%, #1b2b57 0%, transparent 60%), var(--bg);
  color: var(--text);
}
a { color: #9ec5ff; text-decoration: none; }
a:hover { text-decoration: underline; }
.container { max-width: 1200px; margin: 0 auto; }
.hidden { display: none !important; }

.auth-gate {
  max-width: 520px;
  margin: 72px auto;
  background: linear-gradient(180deg, #131e34, var(--card));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 14px 32px rgba(3, 10, 24, 0.35);
}
.auth-gate h2 { margin: 0 0 10px; }
.auth-gate p { margin: 0 0 16px; color: var(--muted); line-height: 1.45; }
.auth-msg { margin-top: 12px; font-size: 13px; color: var(--muted); }
.auth-msg.err { color: #fecaca; }
.auth-msg.ok { color: #bbf7d0; }

.auth-checking-title {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 600;
}

.app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.app-topbar .brand {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.app-topbar .brand strong { font-size: 18px; }
.app-topbar .brand span { font-size: 13px; color: var(--muted); }

.app-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.app-nav a, .app-nav a:visited {
  padding: 8px 14px;
  border-radius: 10px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
}
.app-nav a:hover { border-color: var(--primary); }
.app-nav a.active {
  background: rgba(79, 124, 255, 0.22);
  border-color: var(--primary);
  color: #fff;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-left: auto;
}

/* Traffic-light style API status (RAG indicator) */
.api-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #0f182d;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.api-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(15, 24, 45, 0.9);
}
.api-status[data-state="ok"] .api-status-dot {
  background: var(--ok);
  box-shadow: 0 0 10px rgba(34, 197, 94, 0.65);
}
.api-status[data-state="err"] .api-status-dot {
  background: var(--danger);
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.55);
}
.api-status[data-state="checking"] .api-status-dot {
  background: var(--warn);
  animation: pulse-dot 1.1s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(0.92); }
}
.api-status[data-state="ok"] { border-color: rgba(34, 197, 94, 0.35); color: #bbf7d0; }
.api-status[data-state="err"] { border-color: rgba(239, 68, 68, 0.4); color: #fecaca; }

.mode-badge {
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-soft);
  color: #c7d2fe;
  font-size: 11px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(15, 24, 45, 0.65);
  border: 1px solid var(--line);
}
.toolbar .muted { margin: 0; font-size: 13px; }

.card {
  background: linear-gradient(180deg, #131e34, var(--card));
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 14px 32px rgba(3, 10, 24, 0.35);
  margin-bottom: 14px;
}
.card h2 { margin: 0 0 12px; font-size: 18px; }
.muted { color: var(--muted); font-size: 13px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.row-end { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }

input, button {
  border-radius: 10px;
  border: 1px solid var(--line);
  padding: 9px 12px;
  background: #0f182d;
  color: var(--text);
}
input { min-width: 200px; }
button {
  background: linear-gradient(180deg, #4f7cff, #3f66d8);
  border-color: #4f7cff;
  cursor: pointer;
  font-weight: 600;
}
button.secondary {
  background: #1a2946;
  border-color: #334155;
}
button.danger {
  background: #3b1316;
  border-color: #7f1d1d;
  color: #fecaca;
}
button.small { padding: 6px 10px; font-size: 12px; border-radius: 8px; }

.id-block {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
  background: #0f182b;
}
.id-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: var(--chip);
  border: 1px solid var(--chip-line);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  color: #cbd5e1;
}
.file-row {
  border-top: 1px dashed #2b3956;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 8px 0;
  align-items: center;
}
.file-key {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: #cbd5e1;
  word-break: break-all;
}
.file-actions { display: flex; gap: 6px; align-items: center; }
.file-actions input[type=file] { min-width: 180px; }

.hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  margin-top: 8px;
}
.hub-card {
  display: block;
  padding: 20px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #131e34, var(--card));
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.hub-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
}
.hub-card h3 { margin: 0 0 8px; font-size: 17px; }
.hub-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; }

.toast-stack {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(420px, calc(100vw - 24px));
}
.toast {
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #0f182d;
  color: var(--text);
  padding: 10px 12px;
  box-shadow: 0 16px 28px rgba(2, 8, 23, 0.45);
}
.toast.ok { border-color: #1f6d43; background: #0f261a; }
.toast.err { border-color: #7f1d1d; background: #2a1113; }
.toast .head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}
.toast .title { font-size: 14px; font-weight: 700; margin: 0; }
.toast .msg { font-size: 13px; white-space: pre-wrap; word-break: break-word; }
.toast details { margin-top: 6px; }
.toast summary { cursor: pointer; color: #c7d2fe; font-size: 12px; }
.toast .details {
  margin-top: 6px;
  padding: 8px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.45);
  border: 1px solid #334155;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 160px;
  overflow: auto;
}
.toast .close-btn {
  padding: 2px 7px;
  border-radius: 8px;
  border: 1px solid #334155;
  background: transparent;
  color: #cbd5e1;
  cursor: pointer;
  font-size: 12px;
}

label.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0;
  cursor: pointer;
  font-size: 14px;
}
label.checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  min-width: 18px;
  accent-color: var(--primary);
}
