:root {
  --bg: #0f172a;
  --card: #111827;
  --card2: #162033;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --line: #273449;
  --accent: #38bdf8;
  --good: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.topbar {
  padding: 16px 28px;
  border-bottom: 1px solid var(--line);
  background: #0b1220;
  display: flex;
  align-items: baseline;
  gap: 16px;
}
.brand { font-size: 22px; font-weight: 800; color: #fff; }
.subtitle { color: var(--muted); }
.container { max-width: 1280px; margin: 0 auto; padding: 24px; }
.card {
  background: linear-gradient(180deg, var(--card), var(--card2));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.16);
}
h1, h2, h3 { margin-top: 0; }
.muted { color: var(--muted); }
.upload-form { display: grid; gap: 14px; max-width: 640px; }
label { display: grid; gap: 8px; color: var(--muted); }
input[type="text"], input[type="file"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0b1220;
  color: var(--text);
}
button, .button {
  display: inline-block;
  border: 0;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--accent);
  color: #06111f;
  font-weight: 700;
  cursor: pointer;
}
button.secondary, .button.secondary { background: #334155; color: var(--text); }
button.danger { background: #7f1d1d; color: #fee2e2; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.inline-form { display: flex; gap: 10px; flex-wrap: wrap; }
.row { display: flex; gap: 16px; }
.between { justify-content: space-between; }
.center { align-items: center; }
.grid.two { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .grid.two { grid-template-columns: 1fr; } .row { flex-direction: column; } }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: #cbd5e1; background: rgba(255,255,255,0.03); }
tr.severity-success { background: rgba(16,185,129,0.08); }
tr.severity-warning { background: rgba(245,158,11,0.08); }
tr.severity-danger { background: rgba(239,68,68,0.10); }
tr.severity-muted { opacity: 0.82; }
.badge { background: #1e293b; border: 1px solid var(--line); border-radius: 999px; padding: 4px 8px; font-size: 12px; }
.flash-stack { display: grid; gap: 8px; margin-bottom: 18px; }
.flash { padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); }
.flash-success { background: rgba(16,185,129,0.12); }
.flash-danger { background: rgba(239,68,68,0.12); }
.flash-warning { background: rgba(245,158,11,0.14); }
.flash-info { background: rgba(56,189,248,0.12); }
.kv { display: grid; grid-template-columns: minmax(160px, 260px) 1fr; gap: 8px 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.ai-box {
  padding: 16px;
  background: rgba(56,189,248,0.10);
  border: 1px solid rgba(56,189,248,0.35);
  border-radius: 12px;
  white-space: pre-wrap;
}
pre {
  overflow: auto;
  padding: 14px;
  border-radius: 12px;
  background: #020617;
  border: 1px solid var(--line);
  color: #d1d5db;
}
ul { padding-left: 22px; }

.quality-card { border-left: 6px solid var(--accent); }
.quality-good { border-left-color: var(--good); }
.quality-acceptable { border-left-color: #84cc16; }
.quality-limited { border-left-color: var(--warn); }
.quality-poor, .quality-bad { border-left-color: var(--danger); }
.quality-score { font-size: 20px; font-weight: 800; margin-bottom: 0; }
.quality-score span { letter-spacing: .02em; }
.quality-permissions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.pill { display: inline-block; padding: 6px 10px; border-radius: 999px; border: 1px solid var(--line); background: #1e293b; font-size: 13px; }
.pill.ok { background: rgba(16,185,129,0.14); border-color: rgba(16,185,129,0.45); }
.pill.warn { background: rgba(245,158,11,0.14); border-color: rgba(245,158,11,0.45); }
.pill.bad { background: rgba(239,68,68,0.16); border-color: rgba(239,68,68,0.45); }
.compact th, .compact td { padding: 7px 8px; font-size: 13px; }
.qc-list li { color: #fde68a; }
.import-details { margin-top: 14px; }
.import-details summary { cursor: pointer; font-weight: 700; color: #cbd5e1; margin-bottom: 10px; }
.warn-box {
  margin: 10px 0 14px 0;
  padding: 12px 14px;
  border: 1px solid rgba(245,158,11,0.45);
  background: rgba(245,158,11,0.12);
  border-radius: 12px;
}
code { color: #bae6fd; }

.topnav {
  margin-left: auto;
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
}
.topnav a { color: #cbd5e1; font-weight: 600; }
.user-chip {
  color: #dbeafe;
  background: #1e293b;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
}
.logout-form { display: inline; margin: 0; }
.link-button {
  background: transparent;
  color: var(--accent);
  padding: 0;
  border-radius: 0;
  font-weight: 600;
}
.auth-card { max-width: 560px; margin: 40px auto; }
.auth-note { margin-top: 16px; }
input[type="email"], input[type="password"], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0b1220;
  color: var(--text);
}
textarea { resize: vertical; min-height: 80px; }
select { cursor: pointer; }
.checkline {
  display: flex;
  grid-template-columns: auto 1fr;
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
.checkline input { width: auto; }
.upload-form.wide { max-width: 900px; }
.compact-grid { gap: 14px; }
@media (max-width: 760px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .topnav { margin-left: 0; }
}

.subcard {
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.65);
  border-radius: 14px;
  padding: 14px;
}
.small { font-size: 12px; color: var(--muted); }
.table-scroll { overflow-x: auto; max-width: 100%; }
.badge.danger { background: rgba(239,68,68,0.18); border-color: rgba(239,68,68,0.45); color: #fecaca; }
.mapping-table select { min-width: 220px; }
.required-row { background: rgba(96,165,250,0.06); }
.checkbox { display: inline-flex; align-items: center; gap: 6px; }
.checkbox input { width: auto; }
.quality-mapping_required { border-left-color: var(--warn); }

.plot-box {
  width: 100%;
  min-height: 520px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #020617;
  overflow: hidden;
}
.tablet-card h2 { margin-bottom: 8px; }
.tablet-toolbar label { color: var(--text); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.checkbox.standalone { display: flex; margin: 8px 0 14px; }
.lag-summary { margin: 16px 0; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: rgba(30, 41, 59, 0.35); }
.inline-form { display: inline-flex; margin: 0; }
.actions form.inline-form button { margin: 0; }

.progress {
  height: 16px;
  background: #e9eef5;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid #d2d9e6;
  min-width: 180px;
}
.progress.small { height: 10px; min-width: 120px; }
.progress > div {
  height: 100%;
  background: linear-gradient(90deg, #2f80ed, #35c2ff);
  transition: width .25s ease;
}
.job-status-panel { margin-top: 16px; }
.hidden { display: none !important; }
.status-ready { background: #e6f7ed; color: #116b35; }
.status-processing { background: #eaf3ff; color: #1157a6; }
.status-queued { background: #fff8e1; color: #8a5a00; }
.status-error { background: #fdeaea; color: #9b1c1c; }
.status-mapping_required { background: #fff0e6; color: #9b4a00; }

.comment-list { display: flex; flex-direction: column; gap: 12px; }
.comment-item { border: 1px solid var(--border, #dde3ea); border-radius: 10px; padding: 12px; background: rgba(255,255,255,0.55); }
.small { font-size: 0.82rem; }
.compact-form { margin-bottom: 18px; }
.metric-card .big-number{font-size:2.2rem;font-weight:700;margin:0.2rem 0;}
.status-listening,.status-online,.status-polling{background:#e6f7ed;color:#11662d;}
.status-error{background:#ffe8e8;color:#9b111e;}
.status-stopped{background:#eee;color:#555;}
.status-queued{background:#fff4d4;color:#7a4d00;}
.alert-row.alert-critical{background:#fff0f0;}
.alert-row.alert-high{background:#fff6e6;}
.severity-critical{background:#ffd7d7;color:#8b0000;}
.severity-high{background:#ffe8bf;color:#8a4b00;}
.severity-medium{background:#fff4cf;color:#665000;}
.details-box{margin:0.8rem 0;padding:0.8rem;border:1px solid #e1e4e8;border-radius:10px;background:#fafafa;}
.small{font-size:0.85rem;}

.mode-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
  border: 1px solid rgba(100,116,139,0.35);
  white-space: nowrap;
}
.mode-offline { background: rgba(148,163,184,0.18); color: #334155; }
.mode-online { background: rgba(16,185,129,0.18); color: #065f46; border-color: rgba(16,185,129,0.35); }
.mode-switch-card { border-left: 5px solid #60a5fa; }
.mode-switch-form { align-items: center; }
.notice {
  border: 1px solid rgba(245, 158, 11, .35);
  background: rgba(245, 158, 11, .10);
  border-radius: 14px;
  padding: 14px 16px;
}
.notice.warning { border-left: 5px solid #f59e0b; }
.status-paused { background: #f1f5f9; color: #475569; }

.expert-analysis-card .analysis-result {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.expert-analysis-card h4 { margin-bottom: 6px; }
.expert-analysis-card details { margin-top: 10px; }

/* Language switcher */
.lang-switch { display: inline-flex; gap: 2px; align-items: center; margin: 0 6px; }
.lang-form { display: inline; margin: 0; }
.lang-button {
  background: transparent;
  border: 1px solid rgba(148, 163, 184, 0.45);
  color: inherit;
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  line-height: 1.6;
}
.lang-button:hover { border-color: rgba(148, 163, 184, 0.9); }
.lang-button.active {
  background: rgba(56, 189, 248, 0.18);
  border-color: rgba(56, 189, 248, 0.7);
  cursor: default;
}
