:root {
  color-scheme: dark;
  --bg: #071018;
  --panel: #0d1923;
  --panel-2: #122330;
  --line: #213746;
  --text: #f5f8fa;
  --muted: #8fa6b5;
  --accent: #2dd4bf;
  --accent-2: #22d3ee;
  --danger: #fb7185;
  --warning: #fbbf24;
  --shadow: 0 24px 70px rgba(0, 0, 0, .32);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: radial-gradient(circle at 80% -10%, #123341 0, transparent 35%), var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(1.65rem, 3vw, 2.35rem); letter-spacing: -.045em; margin-bottom: .3rem; }
h2 { font-size: 1.15rem; letter-spacing: -.02em; margin-bottom: .35rem; }
h3 { margin-bottom: .25rem; }
.muted { color: var(--muted); }
.tiny { color: var(--muted); font-size: .75rem; }
.eyebrow { margin: 0 0 .45rem; color: var(--accent); font-size: .68rem; font-weight: 800; letter-spacing: .18em; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 245px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 1.5rem 1.15rem; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: rgba(7, 16, 24, .84); backdrop-filter: blur(18px); }
.brand { display: flex; align-items: center; gap: .8rem; text-decoration: none; line-height: 1.05; margin-bottom: 2.4rem; }
.brand-mark { width: 52px; aspect-ratio: 1; border-radius: 15px; display: grid; place-items: center; color: #03211e; background: linear-gradient(135deg, var(--accent), var(--accent-2)); font-weight: 900; box-shadow: 0 10px 35px rgba(45, 212, 191, .25); }
.brand-mark.small { width: 40px; border-radius: 12px; }
.sidebar nav { display: grid; gap: .35rem; }
.nav-link { padding: .85rem .95rem; text-align: left; color: var(--muted); border: 0; border-radius: 10px; background: transparent; cursor: pointer; }
.nav-link:hover, .nav-link.active { color: var(--text); background: var(--panel-2); }
.sidebar-footer { margin-top: auto; display: grid; grid-template-columns: auto 1fr; align-items: center; gap: .55rem; color: var(--muted); font-size: .78rem; }
.sidebar-footer form { grid-column: 1 / -1; }
.health-dot, .status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 16px var(--accent); display: inline-block; }
.status-dot.offline { background: #64748b; box-shadow: none; }

.workspace { min-width: 0; padding: 2rem clamp(1.25rem, 3vw, 3.2rem) 4rem; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 2rem; margin-bottom: 2rem; }
.top-actions { display: flex; align-items: center; gap: .65rem; }
.revision { color: var(--muted); font-size: .78rem; margin-right: .5rem; }
.button { border: 1px solid var(--line); border-radius: 10px; padding: .72rem 1rem; color: var(--text); background: var(--panel); cursor: pointer; font-weight: 700; }
.button:hover { transform: translateY(-1px); border-color: #315369; }
.button.primary { border-color: transparent; color: #03211e; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.button.secondary { background: var(--panel-2); }
.button.danger { color: #fecdd3; border-color: rgba(251,113,133,.35); }
.button.small { padding: .5rem .7rem; font-size: .8rem; }
.text-button { border: 0; background: none; color: var(--accent); padding: 0; cursor: pointer; }
.icon-button { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); cursor: pointer; }

.view { display: none; }
.view.active { display: block; animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .9rem; margin-bottom: .9rem; }
.stat-card { padding: 1.25rem; border: 1px solid var(--line); border-radius: 16px; background: linear-gradient(145deg, rgba(18,35,48,.92), rgba(10,24,33,.92)); box-shadow: var(--shadow); }
.stat-value { font-size: 2rem; font-weight: 850; letter-spacing: -.05em; margin: .55rem 0 .2rem; }
.stat-note { color: var(--muted); font-size: .78rem; }
.two-column { display: grid; grid-template-columns: 1.25fr .75fr; gap: .9rem; }
.panel { border: 1px solid var(--line); border-radius: 16px; background: rgba(13, 25, 35, .92); box-shadow: var(--shadow); overflow: hidden; }
.panel-heading { padding: 1.15rem 1.25rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; border-bottom: 1px solid var(--line); }
.panel-heading h2, .panel-heading p { margin-bottom: 0; }
.health-row, .coverage-row { display: grid; align-items: center; gap: .75rem; padding: .9rem 1.25rem; border-bottom: 1px solid rgba(33,55,70,.65); }
.health-row { grid-template-columns: auto minmax(0, 1fr) auto; }
.coverage-row { grid-template-columns: minmax(0, 1fr) auto; }
.health-row:last-child, .coverage-row:last-child { border-bottom: 0; }
.row-title { font-weight: 750; }
.row-meta { color: var(--muted); font-size: .76rem; margin-top: .18rem; }
.pill { display: inline-flex; align-items: center; gap: .35rem; padding: .28rem .5rem; border: 1px solid rgba(45,212,191,.25); border-radius: 999px; color: #99f6e4; background: rgba(45,212,191,.08); font-size: .7rem; font-weight: 800; }
.pill.offline { color: #cbd5e1; border-color: var(--line); background: rgba(100,116,139,.08); }

.section-intro { display: flex; justify-content: space-between; align-items: end; margin-bottom: 1rem; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: .9rem; }
.screen-card { padding: 1.15rem; border: 1px solid var(--line); border-radius: 15px; background: var(--panel); }
.screen-card-head { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.screen-card label { margin-top: .75rem; }
.device-url { display: flex; gap: .4rem; margin-top: .8rem; }
.device-url input { min-width: 0; flex: 1; font-size: .72rem; }
.screen-actions { display: flex; gap: .45rem; margin-top: .8rem; }

.playlist-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: .9rem; align-items: start; }
.playlist-list { position: sticky; top: 1rem; }
.playlist-button { display: block; width: 100%; padding: .9rem 1.1rem; border: 0; border-bottom: 1px solid var(--line); color: var(--muted); background: none; text-align: left; cursor: pointer; }
.playlist-button.active, .playlist-button:hover { color: var(--text); background: var(--panel-2); }
.editor { min-height: 400px; }
.editor-toolbar { padding: 1rem 1.25rem; display: flex; gap: .5rem; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.scene-list { padding: 1rem; display: grid; gap: .75rem; }
.scene-card { border: 1px solid var(--line); border-radius: 12px; padding: 1rem; background: #0a151e; }
.scene-head { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: .85rem; }
.scene-badge { color: var(--accent-2); font-size: .65rem; font-weight: 900; letter-spacing: .14em; }
.scene-fields { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: .7rem; }
.scene-fields .wide { grid-column: 1 / -1; }
.editor-footer { display: flex; justify-content: space-between; padding: 1rem 1.25rem; border-top: 1px solid var(--line); }
.empty-state { padding: 3.5rem 1.5rem; text-align: center; color: var(--muted); }

label { display: grid; gap: .38rem; color: #c5d4dd; font-size: .76rem; font-weight: 750; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: .68rem .75rem; color: var(--text); background: #07131c; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(45,212,191,.1); }
textarea { resize: vertical; min-height: 76px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.stack { display: grid; gap: .9rem; }

dialog { width: min(520px, calc(100vw - 2rem)); padding: 0; border: 1px solid var(--line); border-radius: 17px; color: var(--text); background: var(--panel); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(1, 7, 12, .76); backdrop-filter: blur(5px); }
.dialog-card { display: grid; gap: 1rem; padding: 1.25rem; }
.dialog-card .panel-heading { padding: 0 0 1rem; }
.upload-panel { padding: 1.4rem; }
.upload-box { margin-top: 1rem; padding: 2rem; display: flex; align-items: center; gap: 1rem; border: 1px dashed #315369; border-radius: 13px; background: #08151f; }
.upload-box input { background: transparent; border: 0; padding: 0; }
.upload-result-card { margin-top: 1rem; padding: 1rem; border: 1px solid var(--line); border-radius: 12px; }
.toast { position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 10; max-width: 360px; padding: .8rem 1rem; border: 1px solid var(--line); border-radius: 10px; background: #102431; box-shadow: var(--shadow); transform: translateY(140%); transition: transform .2s ease; }
.toast.show { transform: translateY(0); }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: min(410px, 100%); padding: 2rem; border: 1px solid var(--line); border-radius: 20px; background: rgba(13,25,35,.95); box-shadow: var(--shadow); }
.login-card .brand-mark { margin-bottom: 1.5rem; }
.login-card .button { margin-top: .35rem; }
.login-error { margin: 1rem 0; padding: .75rem; border: 1px solid rgba(251,113,133,.35); border-radius: 9px; color: #fecdd3; background: rgba(251,113,133,.08); font-size: .8rem; }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; width: 100%; height: auto; flex-direction: row; align-items: center; gap: 1rem; padding: .8rem 1rem; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { margin: 0 auto 0 0; }
  .brand span:last-child, .sidebar-footer { display: none; }
  .sidebar nav { display: flex; overflow-x: auto; }
  .nav-link { white-space: nowrap; padding: .65rem .75rem; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .two-column, .playlist-layout { grid-template-columns: 1fr; }
  .playlist-list { position: static; }
}

@media (max-width: 640px) {
  .workspace { padding: 1.2rem .85rem 3rem; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .top-actions { width: 100%; flex-wrap: wrap; }
  .revision { width: 100%; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .scene-fields { grid-template-columns: 1fr; }
  .scene-fields .wide { grid-column: auto; }
  .upload-box { align-items: stretch; flex-direction: column; }
}
