:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --text: #e7ecf3;
  --muted: #8b9bb4;
  --accent: #3d9cfd;
  --ok: #3ecf8e;
  --warn: #f0b429;
  --err: #f07178;
  --border: #2a3548;
  font-family: "Segoe UI", "IBM Plex Sans", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: radial-gradient(1200px 600px at 10% -10%, #1c2a40, var(--bg)); color: var(--text); min-height: 100vh; }
.hidden { display: none !important; }
#login { max-width: 420px; margin: 12vh auto; padding: 2rem; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; }
#login input { width: 100%; padding: .7rem; margin: .5rem 0 1rem; background: #0d121a; border: 1px solid var(--border); color: var(--text); border-radius: 8px; }
button { background: var(--accent); color: #041018; border: 0; padding: .55rem 1rem; border-radius: 8px; font-weight: 600; cursor: pointer; }
button.secondary { background: transparent; color: var(--muted); border: 1px solid var(--border); }
button:disabled { opacity: .5; cursor: wait; }
.err { color: var(--err); }
.muted { color: var(--muted); }
#app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
aside { background: #121a26; border-right: 1px solid var(--border); padding: 1rem; display: flex; flex-direction: column; gap: .5rem; }
.brand { font-weight: 700; letter-spacing: .02em; margin-bottom: 1rem; color: var(--accent); }
.brand-block {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: .55rem;
}
.brand-block--login {
  align-items: center;
  text-align: center;
  margin-bottom: .75rem;
}
.brand-block--login h1 {
  margin: 0;
  font-size: 1.35rem;
  color: var(--text);
}
.brand-logo {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 48px;
  object-fit: contain;
}
.brand-block--login .brand-logo { max-height: 56px; }
.brand-title {
  font-size: .95rem;
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--accent);
  line-height: 1.2;
}
nav { display: flex; flex-direction: column; gap: .35rem; flex: 1; }
nav button { text-align: left; background: transparent; color: var(--text); border: 0; padding: .55rem .7rem; border-radius: 8px; }
nav button:hover, nav button.active { background: #243044; }
main { padding: 1.25rem 1.5rem; }
header { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.badge { background: #243044; color: var(--muted); padding: .2rem .55rem; border-radius: 999px; font-size: .75rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 1rem; }
.card .n { font-size: 1.6rem; font-weight: 700; }
.card .l { color: var(--muted); font-size: .85rem; }
table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: 10px; overflow: hidden; }
th, td { text-align: left; padding: .55rem .7rem; border-bottom: 1px solid var(--border); font-size: .9rem; }
th { color: var(--muted); font-weight: 600; }
.toolbar { display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; align-items: center; }
.warn-banner { background: #3a2e14; border: 1px solid var(--warn); color: #ffd98a; padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.ok { color: var(--ok); }
.bad { color: var(--err); }
input, select, textarea { background: #0d121a; border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: .45rem .6rem; }
pre { background: #0d121a; padding: 1rem; border-radius: 8px; overflow: auto; max-height: 360px; font-size: .8rem; }

.analytics-bars {
  display: flex; align-items: flex-end; gap: .45rem; min-height: 150px;
  padding: 1rem .5rem; background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  overflow-x: auto;
}
.abar { display: flex; flex-direction: column; align-items: center; min-width: 42px; }
.abar-fill { width: 28px; background: linear-gradient(180deg, var(--accent), #1a5f9e); border-radius: 4px 4px 0 0; }
.abar-label { font-size: .65rem; color: var(--muted); text-align: center; margin-top: .35rem; line-height: 1.2; }

/* Modal */
.modal-root {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(4, 8, 16, 0.72);
  padding: 1rem;
}
.modal-root.hidden { display: none !important; }
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: min(960px, 96vw);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 48px rgba(0,0,0,.45);
}
.modal header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--border);
  margin: 0;
}
.modal header h3 { margin: 0; font-size: 1.05rem; }
.modal .modal-body {
  padding: 1rem 1.1rem;
  overflow: auto;
  flex: 1;
}
.modal footer {
  padding: 0.75rem 1.1rem;
  border-top: 1px solid var(--border);
  display: flex; gap: 0.5rem; justify-content: flex-end;
}
a.link-btn {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-weight: 600;
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem 1.25rem;
}
@media (max-width: 800px) {
  .form-grid { grid-template-columns: 1fr; }
}
.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field.full { grid-column: 1 / -1; }
.field label { color: var(--muted); font-size: 0.85rem; font-weight: 600; }
.field input[readonly], .field input:disabled, .url-box {
  opacity: 0.95;
  border-style: dashed;
  color: #b8d4ff;
}
.url-box {
  font-family: ui-monospace, Consolas, monospace;
  word-break: break-all;
  background: #0d121a;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
}
.header-parse-table { font-size: 0.85rem; }
.header-parse-table th, .header-parse-table td { vertical-align: middle; }
.chip {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: #243044;
  color: var(--muted);
  font-size: 0.75rem;
  margin-right: 0.25rem;
}
.chip.sec { background: #2a3a28; color: #9de3a8; }
.chip.route { background: #2a3448; color: #9ec5ff; }

.status-chip {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}
.status-chip.st-pending { background: #2a3448; color: #9ec5ff; }
.status-chip.st-inflight { background: #3a3420; color: #f0d078; }
.status-chip.st-ok { background: #1e3a2f; color: #5ee0a0; }
.status-chip.st-dead { background: #3a2228; color: #f09098; }
.status-chip.st-dup { background: #2a2a38; color: #b0b8c8; }
.status-chip.st-unknown { background: #243044; color: var(--muted); }
.status-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.55rem;
  margin: 0 0 0.85rem;
  font-size: 0.85rem;
  line-height: 1.5;
}
.status-legend .status-chip { margin: 0; }

/* Tabs */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0 0 1rem;
  padding: 0.35rem;
  background: #121a26;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.tab {
  background: transparent;
  color: var(--muted);
  border: 0;
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}
.tab:hover { background: #1c2838; color: var(--text); }
.tab.active {
  background: #243044;
  color: var(--accent);
}
.tab-panel {
  min-height: 120px;
}

/* SQL Explorer */
.sql-layout {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(360px, 1.4fr);
  gap: 1rem;
  align-items: start;
}
@media (max-width: 1000px) {
  .sql-layout { grid-template-columns: 1fr; }
}
.sql-side, .sql-main {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem 1rem;
}
.sql-main textarea {
  width: 100%;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.85rem;
  min-height: 180px;
  resize: vertical;
}
.sql-table-wrap { overflow: auto; max-height: 420px; }
.sql-result-grid { max-height: 480px; margin-top: 0.5rem; }
.sql-table-row { cursor: pointer; }
.sql-table-row:hover { background: #243044; }
.sql-result-grid td {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.8rem;
}
