/* Theme lifted from koryofront.org's own shipped CSS (dark mode — the site
   itself defaults to <html class="dark">). Colors are HSL triplets matching
   their --primary/--background/etc custom properties 1:1; the mono face is
   this codebase's existing terminal aesthetic (JetBrains Mono), since
   koryofront.org doesn't define one of its own. */
:root {
  color-scheme: dark;
  --scrollbar-thumb: hsl(0 0% 28%);
  --scrollbar-hover: hsl(0 0% 40%);
  --background: hsl(0 0% 6%);
  --foreground: hsl(0 0% 95%);
  --card: hsl(0 0% 8%);
  --card-foreground: hsl(0 0% 95%);
  --card-border: hsl(0 0% 12%);
  --border: hsl(0 0% 16%);
  --muted: hsl(0 2% 16%);
  --muted-foreground: hsl(0 2% 75%);
  --primary: hsl(355 85% 42%);
  --primary-hover: hsl(355 85% 48%);
  --primary-foreground: hsl(355 85% 98%);
  --destructive: hsl(0 84% 38%);
  --destructive-hover: hsl(0 84% 45%);
  --destructive-foreground: hsl(0 84% 98%);
  --ring: hsl(355 85% 45%);
  --green: #2ecc71;
  --yellow: #e6b800;
  --font-sans: 'Open Sans', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --radius: 10px;
}

* { box-sizing: border-box; scrollbar-width:thin; scrollbar-color:var(--scrollbar-thumb) var(--background); }
::-webkit-scrollbar { width:8px; height:8px; }
::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background:var(--background); }
::-webkit-scrollbar-thumb { background:var(--scrollbar-thumb); border:2px solid var(--background); border-radius:8px; }
::-webkit-scrollbar-thumb:hover { background:var(--scrollbar-hover); }

html, body {
  margin: 0;
  padding: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

button, input { font-family: inherit; }

/* ── Login screen ── */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-screen[hidden] { display: none; }

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: stretch;
}

.login-mark { width: 40px; height: 40px; margin: 0 auto 4px; display: block; }

.login-title {
  text-align: center;
  font-weight: 700;
  font-size: 17px;
  margin-bottom: 8px;
  letter-spacing: 0.01em;
}

.login-card input {
  background: var(--background);
  border: 1px solid var(--border);
  color: var(--foreground);
  font-size: 14px;
  padding: 11px 13px;
  border-radius: 8px;
  outline: none;
  width: 100%;
  transition: border-color 0.15s;
}
.login-card input:focus { border-color: var(--primary); }

.btn-primary {
  background: var(--primary);
  color: var(--primary-foreground);
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  color: var(--muted-foreground);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-ghost:hover { color: var(--foreground); border-color: var(--muted-foreground); }

.btn-danger {
  background: var(--destructive);
  color: var(--destructive-foreground);
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-danger:hover { background: var(--destructive-hover); }
.btn-start { background:#17683c; color:#fff; border:1px solid #278452; border-radius:8px; padding:9px 16px; font-size:12px; font-weight:700; cursor:pointer; }
.btn-start:hover { background:#20834d; }

.login-err { color: var(--destructive-hover); font-size: 12px; text-align: center; min-height: 16px; }

/* ── App shell ── */

.app { min-height: 100vh; display: flex; flex-direction: column; }
/* [hidden] alone loses to the .app rule above (equal specificity, author
   CSS beats the UA stylesheet's default) — the app content was rendering
   even while "hidden" was set, which is what made sign-in look broken. */
.app[hidden] { display: none; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; }
.brand-mark { width: 22px; height: 22px; }

.topbar-right { display: flex; align-items: center; gap: 14px; }
.whoami { font-size: 12px; color: var(--muted-foreground); font-family: var(--font-mono); }

.tabbar {
  display: flex;
  gap: 4px;
  padding: 10px 18px 0;
  border-bottom: 1px solid var(--border);
  background: var(--background);
  overflow-x: auto;
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--muted-foreground);
  font-size: 13px;
  font-weight: 600;
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--foreground); }
.tab-btn.active { color: var(--foreground); border-bottom-color: var(--primary); }

.tab-content { flex: 1; padding: 24px; max-width: 1200px; width: 100%; margin: 0 auto; }

.tab-pane { display: none; }
.tab-pane.active { display: block; }

.pane-placeholder {
  color: var(--muted-foreground);
  font-size: 13px;
  padding: 40px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ── Shared building blocks (cards, grids, tables) for later phases ── */

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
}

.stat-label {
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--muted-foreground);
  text-transform: uppercase;
  margin-bottom: 6px;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 19px;
  font-weight: 700;
}
.stat-value.ok { color: var(--green); }
.stat-value.warn { color: var(--yellow); }
.stat-value.bad { color: var(--destructive-hover); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--muted-foreground); font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted-foreground); display: inline-block; }
.dot.live { background: var(--green); box-shadow: 0 0 8px var(--green); }
.dot.down { background: var(--destructive-hover); }

h1 { font-size: 24px; margin: 0; letter-spacing: -.025em; }
h2 { font-size: 15px; margin: 0 0 16px; font-weight: 700; }
p { line-height: 1.6; }
.section { margin-bottom: 22px; }
.section-heading { display:flex; justify-content:space-between; align-items:center; gap:16px; margin-bottom:16px; flex-wrap:wrap; }
.section-heading h2 { margin:0; }
.section-heading p { margin:6px 0 0; color:var(--muted-foreground); font-size:13px; }
.muted { font-size:12px; color:var(--muted-foreground); line-height:1.6; }
.error { color:#ff858e; font-size:13px; overflow-wrap:anywhere; }
.error:empty { display:none; }
.notice { font-size:12px; color:var(--muted-foreground); border-left:2px solid var(--primary); padding:8px 12px; }
.metrics-grid { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:24px; }
.channel-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(300px,1fr)); gap:14px; }
.instance-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(290px,1fr)); gap:16px; }
.two-col { display:grid; grid-template-columns:1fr 1fr; gap:20px; }
.card { min-width:0; }
.card-title { display:flex; align-items:center; justify-content:space-between; gap:10px; margin-bottom:18px; }
.card-title h2 { margin:0; }
.badge { display:inline-flex; align-items:center; gap:6px; border:1px solid var(--border); border-radius:5px; padding:4px 7px; color:var(--muted-foreground); font-size:10px; white-space:nowrap; }
.badge.good { color:var(--green); background:#2ecc710b; border-color:#2ecc712e; }
.badge.warn { color:var(--yellow); border-color:#e6b80033; }
.metrics-row { display:flex; gap:28px; margin:18px 0; }
.meter { height:4px; background:var(--muted); border-radius:3px; margin-top:12px; overflow:hidden; }
.meter span { display:block; height:100%; width:0; background:var(--primary); transition:width .4s; }
.actions { display:flex; flex-wrap:wrap; align-items:center; gap:8px; }
.stream-link { display:block; color:var(--muted-foreground); font:11px/1.7 var(--font-mono); overflow-wrap:anywhere; margin:8px 0 10px; }
a { color:var(--foreground); text-underline-offset:3px; }
.domain-link { display:block; overflow-wrap:anywhere; margin-bottom:12px; font-size:13px; }
.tv-icon { display:inline-grid; place-items:center; width:36px; height:36px; border:1px solid var(--border); background:var(--background); border-radius:9px; color:var(--primary); margin-right:10px; }
.tv-icon img { width:26px; height:26px; object-fit:contain; }
.instance-name { display:flex; align-items:center; }
.port-row { display:flex; gap:24px; margin:20px 0; }
.port-row strong { font:15px var(--font-mono); }
.inline-form { display:flex; gap:14px; align-items:flex-end; flex-wrap:wrap; }
label { display:flex; flex-direction:column; gap:7px; font-size:12px; color:var(--muted-foreground); }
input { width:100%; min-width:0; background:var(--background); border:1px solid var(--border); color:var(--foreground); padding:10px 12px; border-radius:7px; font-size:14px; }
input:focus { outline:2px solid var(--ring); outline-offset:2px; }
button:focus-visible, a:focus-visible { outline:2px solid var(--ring); outline-offset:3px; }
button:disabled { opacity:.5; cursor:wait; }
.table-wrap { overflow-x:auto; }
dialog { background:var(--card); color:var(--foreground); border:1px solid var(--border); border-radius:12px; width:min(440px,calc(100% - 32px)); padding:24px; }
dialog::backdrop { background:#000a; }
dialog input { margin:10px 0 14px; }
#deleteInstanceDialog { width:min(560px,calc(100% - 32px)); overflow-wrap:anywhere; }
#deleteInstanceDialog ul { padding-left:20px; font-size:12px; line-height:1.7; }
#deleteInstanceDialog p { font-size:13px; }
.sr-only { position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0,0,0,0); }
#trafficMap { height:500px; border:1px solid var(--border); border-radius:8px; background:#0b0e12; }
.map-legend { display:flex; flex-wrap:wrap; gap:18px; margin-top:14px; color:var(--muted-foreground); font-size:11px; }
.map-legend .dot { margin-right:5px; width:6px; height:6px; }
.map-point { outline:none; cursor:pointer; }
.map-selection { opacity:0; pointer-events:none; }
.map-point.selected .map-selection, .map-point:focus-visible .map-selection { opacity:1; }
.analytics-table td:first-child { overflow-wrap:anywhere; }
.analytics-table td:not(:first-child) { white-space:nowrap; }
.analytics-breakdowns { margin-top:20px; }
.analytics-breakdowns .table-wrap { max-height:360px; overflow:auto; }
#trafficMap { position:relative; overflow:hidden; }
#trafficMap svg { display:block; width:100%; height:100%; touch-action:none; cursor:grab; }
#trafficMap svg:active { cursor:grabbing; }
#trafficMap > svg:focus { outline:none; }
#trafficMap > svg:focus-visible:not([data-pointer-focus]) { outline:2px solid var(--ring); outline-offset:-3px; }
.map-controls { position:absolute; top:12px; left:12px; display:flex; flex-direction:column; gap:5px; }
.map-controls button { background:var(--card); font-size:18px; }
.map-tooltip { position:absolute; bottom:10px; left:10px; right:10px; width:fit-content; max-width:calc(100% - 20px); padding:10px; background:#101216ed; border:1px solid var(--border); border-radius:6px; font-size:12px; pointer-events:none; }
.map-legend .dot.live { background:#9169cd; box-shadow:none; }
@media(max-width:800px) { .metrics-grid { grid-template-columns:repeat(2,minmax(0,1fr)); } .two-col { grid-template-columns:1fr; } }
@media(max-width:520px) {
  .topbar { padding:14px 16px; gap:8px; } .brand { font-size:12px; } .whoami { display:none; }
  .tab-content { padding:20px 16px; } .tabbar { padding-left:4px; } .tab-btn { padding:12px 10px; font-size:12px; }
  .channel-grid,.instance-grid { grid-template-columns:minmax(0,1fr); } .card { padding:16px; }
  .stat-value { font-size:16px; } .metrics-grid { gap:20px 12px; } .inline-form label { width:100%; }
  #trafficMap { height:360px; } th,td { padding:10px 8px; }
}
