:root {
  color-scheme: dark;
  --bg: #03111e;
  --panel: #0a1d30;
  --panel-2: #10263d;
  --line: #27435e;
  --text: #f4f7fb;
  --muted: #a9b8ca;
  --cyan: #19d4dc;
  --blue: #0aa9ff;
  --green: #27df88;
  --gold: #ffbd3f;
  --red: #ff4e62;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); }
button, input { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-panel {
  width: min(460px, 100%);
  padding: 34px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 20px 70px rgba(0,0,0,.35);
}
.login-panel img { width: 230px; max-height: 72px; object-fit: contain; object-position: left center; }
.eyebrow { margin: 24px 0 8px; color: var(--cyan); font-size: .76rem; font-weight: 700; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 10px; font-size: 2rem; }
.muted { color: var(--muted); line-height: 1.55; }
label { display: grid; gap: 8px; color: var(--muted); font-size: .84rem; font-weight: 650; }
input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 13px;
  color: var(--text);
  background: #061522;
  outline: none;
}
input:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(25,212,220,.12); }
#loginForm { display: grid; gap: 16px; margin-top: 24px; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 16px;
  color: var(--text);
  background: var(--panel-2);
  font-weight: 700;
}
.button:hover { border-color: var(--cyan); }
.button.primary { color: #00131d; border-color: var(--cyan); background: var(--cyan); }
.button.danger, .button.danger-outline { border-color: rgba(255,78,98,.55); color: #ffd9de; }
.button.danger { background: rgba(255,78,98,.2); }
.button.danger-outline { background: transparent; }
.button.small { min-height: 34px; padding: 0 10px; font-size: .78rem; }
.back-link { display: inline-block; margin-top: 20px; color: var(--muted); }
.notice { min-height: 20px; margin: 14px 0 0; color: var(--muted); }
.notice.error { color: #ffb6c0; }
.notice.success { color: var(--green); }

.app { min-height: 100vh; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 18px;
  align-items: center;
  min-height: 86px;
  padding: 12px max(20px, calc((100vw - 1500px) / 2));
  border-bottom: 1px solid var(--line);
  background: rgba(3,17,30,.96);
}
.brand img { width: 180px; height: 58px; object-fit: contain; object-position: left center; }
.topbar strong { display: block; font-size: 1.12rem; }
.topbar span { display: block; margin-top: 4px; color: var(--muted); font-size: .8rem; }
.top-actions { display: flex; gap: 10px; }

.metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  max-width: 1500px;
  margin: 24px auto 16px;
  padding: 0 20px;
}
.metrics div { min-height: 104px; padding: 18px; border: 1px solid var(--line); background: var(--panel); }
.metrics span { display: block; color: var(--muted); font-size: .76rem; text-transform: uppercase; }
.metrics strong { display: block; margin-top: 10px; color: var(--cyan); font-size: 1.75rem; }

.tabs {
  display: flex;
  gap: 4px;
  max-width: 1460px;
  margin: 0 auto;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
}
.tabs button {
  min-width: 140px;
  min-height: 48px;
  border: 0;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--cyan); }

.workspace { max-width: 1500px; margin: 0 auto; padding: 24px 20px 60px; }
.workspace-head { display: flex; justify-content: space-between; gap: 20px; align-items: end; }
.workspace h2 { margin-bottom: 4px; font-size: 1.5rem; }
.workspace-head p { margin-bottom: 0; color: var(--muted); }
.search { width: min(360px, 100%); }
.search input { min-height: 40px; }
.table-wrap { margin-top: 18px; overflow: auto; border: 1px solid var(--line); }
.admin-tool-panel {
  margin-top: 18px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #061522;
}
.admin-tool-panel iframe {
  display: block;
  width: 100%;
  height: max(680px, calc(100svh - 250px));
  border: 0;
  background: #061220;
}
.analysis-tool-panel iframe {
  height: max(760px, calc(100svh - 220px));
}
table { width: 100%; min-width: 1280px; border-collapse: collapse; background: var(--panel); }
th, td { padding: 13px 14px; border-bottom: 1px solid rgba(39,67,94,.72); text-align: left; vertical-align: top; }
th { position: sticky; top: 0; z-index: 1; color: var(--muted); background: #0c2135; font-size: .72rem; text-transform: uppercase; }
td { font-size: .86rem; }
tr:hover td { background: rgba(25,212,220,.035); }
.cell-main { display: block; color: var(--text); font-weight: 700; }
.cell-sub { display: block; margin-top: 4px; color: var(--muted); font-size: .76rem; overflow-wrap: anywhere; }
.status { display: inline-flex; align-items: center; min-height: 26px; padding: 0 9px; border-radius: 4px; color: var(--green); background: rgba(39,223,136,.1); font-weight: 700; }
.status.bad { color: #ffb2bc; background: rgba(255,78,98,.11); }
.method { color: var(--gold); font-weight: 700; }
.row-actions { display: flex; gap: 7px; justify-content: flex-end; }
.empty { padding: 48px; border: 1px solid var(--line); color: var(--muted); text-align: center; }

dialog {
  width: min(680px, calc(100% - 30px));
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0;
  color: var(--text);
  background: var(--panel);
  box-shadow: 0 30px 100px rgba(0,0,0,.58);
}
dialog::backdrop { background: rgba(0,8,15,.82); }
#editForm { padding: 24px; }
.dialog-head { display: flex; justify-content: space-between; gap: 20px; }
.dialog-head .eyebrow { margin: 0 0 5px; }
.dialog-head h2 { margin-bottom: 0; }
.icon-button { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 50%; color: var(--text); background: transparent; font-size: 1.4rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 24px; }
.form-grid label.wide { grid-column: 1 / -1; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }

.telemetry-dialog { width: min(1180px, calc(100% - 30px)); }
.telemetry-dialog-body { padding: 24px; }
.telemetry-subtitle { margin: 7px 0 0; }
.telemetry-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin: 18px 0;
}
.telemetry-metrics div { min-height: 72px; padding: 12px; border: 1px solid var(--line); background: #061522; }
.telemetry-metrics span { display: block; color: var(--muted); font-size: .68rem; text-transform: uppercase; }
.telemetry-metrics b { display: block; margin-top: 7px; color: var(--text); font-size: .95rem; overflow-wrap: anywhere; }
.telemetry-files { margin-bottom: 14px; border: 1px solid var(--line); background: #061522; }
.telemetry-file-list { display: grid; gap: 8px; padding: 10px; }
.telemetry-file-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-width: 0; padding: 10px 12px; border: 1px solid rgba(39,67,94,.72); background: #041321; }
.telemetry-file-row > div { min-width: 0; }
.telemetry-file-row .cell-main,
.telemetry-file-row .cell-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.telemetry-file-empty { padding: 8px 2px; color: var(--muted); font-size: .82rem; }
.telemetry-visuals { display: grid; grid-template-columns: minmax(0, .9fr) minmax(0, 1.35fr); gap: 14px; }
.telemetry-visuals section { min-width: 0; border: 1px solid var(--line); background: #041321; }
.telemetry-heading { display: flex; justify-content: space-between; gap: 12px; padding: 11px 13px; border-bottom: 1px solid var(--line); }
.telemetry-heading span { color: var(--muted); font-size: .76rem; }
.telemetry-visuals canvas { display: block; width: 100%; height: 390px; }
.telemetry-map { position: relative; height: 390px; overflow: hidden; background: #041321; }
.telemetry-map-tiles { position: absolute; inset: 0; overflow: hidden; background: #07131c; }
.telemetry-map-tiles img { position: absolute; width: 256px; height: 256px; max-width: none; user-select: none; }
.telemetry-map canvas { position: absolute; inset: 0; height: 100%; }
.telemetry-map-credit { position: absolute; right: 6px; bottom: 5px; padding: 2px 5px; color: rgba(255,255,255,.82); background: rgba(0,0,0,.62); font-size: .62rem; }
.telemetry-json { margin-top: 14px; border: 1px solid var(--line); background: #061522; }
.telemetry-json summary { padding: 13px; color: var(--muted); cursor: pointer; font-weight: 700; }
.telemetry-json pre { max-height: 260px; margin: 0; overflow: auto; padding: 14px; border-top: 1px solid var(--line); color: #cce2f2; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; }

@media (max-width: 900px) {
  .topbar { grid-template-columns: auto 1fr; }
  .top-actions { grid-column: 1 / -1; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .workspace-head { align-items: stretch; flex-direction: column; }
  .search { width: 100%; }
}

@media (max-width: 560px) {
  .login-panel { padding: 24px; }
  .topbar { padding: 10px 14px; }
  .brand img { width: 135px; }
  .metrics { grid-template-columns: 1fr 1fr; padding: 0 14px; }
  .metrics div { min-height: 88px; padding: 14px; }
  .tabs { margin: 0 14px; }
  .workspace { padding-inline: 14px; }
  .admin-tool-panel iframe,
  .analysis-tool-panel iframe { height: 78svh; min-height: 620px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid label.wide { grid-column: auto; }
  .telemetry-metrics { grid-template-columns: 1fr 1fr; }
  .telemetry-visuals { grid-template-columns: 1fr; }
  .telemetry-visuals canvas,
  .telemetry-map { height: 310px; }
  .telemetry-file-row { align-items: stretch; flex-direction: column; }
}
