:root {
  --bg: #f4f2fb;
  --surface: #ffffff;
  --surface-2: #efeaff;
  --line: #e4dff3;
  --text: #1c1730;
  --muted: #6e6880;
  --accent: #6d4aff;
  --ok: #1f9d62;
  --warn: #b7791f;
  --off: #8b849c;
  --danger: #d64545;
  --teal: #5b4ad6;
  color-scheme: light;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(900px 420px at 100% -10%, rgba(109, 74, 255, 0.16), transparent 55%),
    var(--bg);
  color: var(--text);
  font: 15px/1.45 "Segoe UI", Helvetica, sans-serif;
}

button, input { font: inherit; color: inherit; }

button {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
}

button.ghost, button.chip {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
}

button.chip { color: var(--muted); border-radius: 99px; padding: 6px 12px; }
button.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

button.play {
  background: var(--surface-2);
  color: var(--accent);
  border-radius: 99px;
  padding: 6px 14px;
}

button.danger { background: var(--danger); }
button:disabled { opacity: 0.45; cursor: default; }

button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input {
  background: #faf9ff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
  margin: 0 0 12px;
}

a { color: var(--accent); }

.shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }

.side {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 22px 16px;
  background: #fff;
  border-right: 1px solid var(--line);
  min-height: 100vh;
}

.brand strong { display: block; margin-top: 8px; font-size: 18px; }
.mark { color: var(--accent); font-weight: 700; letter-spacing: 0.16em; font-size: 13px; }

.side nav { display: flex; flex-direction: column; gap: 4px; margin-top: 18px; }
.nav {
  display: block;
  padding: 8px 10px;
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
}
.nav.on { background: var(--surface-2); color: var(--accent); }

.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.live { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }

.stage { padding: 28px 28px 72px; max-width: 1180px; }
.topbar { display: flex; justify-content: space-between; gap: 16px; align-items: flex-end; margin-bottom: 18px; }
.title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h1 { font-size: 32px; line-height: 1.1; font-weight: 650; margin: 0; letter-spacing: -0.03em; }
h2 { font-size: 18px; margin: 0; }
.muted { color: var(--muted); }
.mono { font-family: Consolas, "Cascadia Mono", ui-monospace, monospace; white-space: pre-wrap; word-break: break-word; }
.error { color: #b42318; min-height: 1.2em; margin: 8px 0 0; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px 18px; box-shadow: 0 8px 24px rgba(60, 40, 120, 0.04); }
.stat b { display: block; font-family: Bahnschrift, "Segoe UI", sans-serif; font-size: 32px; letter-spacing: -0.04em; font-weight: 600; color: var(--accent); }
.stat span { color: var(--muted); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; }

.home-grid { display: grid; grid-template-columns: 1.4fr 0.8fr; gap: 14px; align-items: start; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 18px; margin-bottom: 14px; box-shadow: 0 8px 24px rgba(60, 40, 120, 0.04); }
.home-grid .card { margin-bottom: 0; }
.card-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }

.phones { display: flex; flex-direction: column; gap: 8px; }
.device {
  display: grid;
  grid-template-columns: 4px minmax(0, 1.5fr) auto auto auto auto;
  gap: 12px;
  align-items: center;
  text-decoration: none;
  color: var(--text);
  background: #faf9ff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
}
.device:hover { border-color: #c9bef7; }
.device-main { min-width: 0; display: flex; flex-direction: column; }
.device-main strong { font-size: 16px; }
.sub { color: var(--muted); font-size: 13px; }
.rail { width: 4px; height: 36px; border-radius: 99px; background: var(--off); }
.rail.on { background: var(--ok); }
.rail.off { background: var(--danger); }
.status {
  display: inline-flex;
  align-items: center;
  border-radius: 99px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: #f3e8e8;
  color: #9b2c2c;
}
.status.on { background: #e5f6ee; color: #157a49; }
.status.off { background: #fde8e8; color: #b42318; }
.status.gone { background: #efeaff; color: #5b3fd6; }
.rail.gone { background: #6d4aff; }
.mini.gone { background: #6d4aff; }
.download { display: flex; gap: 16px; align-items: center; margin: 8px 0 16px; }
.download img { width: 168px; height: 168px; background: #fff; border: 1px solid var(--line); border-radius: 12px; }
.removed { border-color: #d9d0ff; background: #f7f4ff; }
.pill { border-radius: 99px; background: #fff; border: 1px solid var(--line); padding: 4px 10px; font-size: 13px; }
.pill.low { color: #b42318; }

.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--off); display: inline-block; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 0 rgba(31, 157, 98, 0.45); animation: pulse 1.8s infinite; }
.dot.bad { background: var(--danger); }

.alert {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
}
.tag { font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--teal); }
.tag.offline, .tag.battery { color: #b42318; }
.tag.left_area { color: var(--warn); }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 14px; }
.tabs button { background: #fff; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; }
.tabs button.on { background: var(--surface-2); color: var(--accent); border-color: transparent; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.line { display: flex; justify-content: space-between; gap: 12px; margin: 7px 0; }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.bar span { display: block; height: 100%; background: var(--accent); }

iframe { width: 100%; height: 240px; border: 0; border-radius: 12px; margin: 8px 0; background: #f4f2fb; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; }
td audio { display: block; margin-top: 8px; }
audio { width: min(100%, 260px); height: 32px; }

.pager { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.pager-btns { display: flex; gap: 8px; align-items: center; }

.setup summary { cursor: pointer; font-weight: 650; }
.setup[open] summary { margin-bottom: 12px; }
.steps { margin: 8px 0 12px; padding-left: 18px; color: var(--muted); }
.facts { display: grid; grid-template-columns: 1.1fr 1fr 1.3fr; gap: 12px; }
.fact .label { color: var(--muted); font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; }
.fact .value { margin-top: 6px; }

.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.15fr 0.85fr; }
.login-brand {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 48px;
  background:
    linear-gradient(165deg, rgba(109, 74, 255, 0.18), transparent 46%),
    #f7f5ff;
  border-right: 1px solid var(--line);
}
.login-brand h1 { font-size: 48px; max-width: 10ch; margin: 12px 0; }
.login-panel { display: grid; place-items: center; padding: 24px; }
.login-card { width: min(420px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 22px; }

.empty { margin: 4px 0 0; }

.device.fresh { animation: flash 1.4s ease; }

@keyframes pulse {
  70% { box-shadow: 0 0 0 8px rgba(31, 157, 98, 0); }
  100% { box-shadow: 0 0 0 0 rgba(31, 157, 98, 0); }
}

@keyframes flash {
  from { background: rgba(109, 74, 255, 0.18); }
  to { background: #faf9ff; }
}

@media (prefers-reduced-motion: reduce) {
  .dot.on, .device.fresh { animation: none; }
}

.stats.five { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.chart-row { display: grid; grid-template-columns: 1fr 1fr 1.15fr; gap: 14px; margin-bottom: 14px; }
.split { display: grid; grid-template-columns: 1.35fr 0.85fr; gap: 14px; align-items: start; margin-bottom: 14px; }
.chart-card { min-height: 240px; }
.chart-sub { margin: 4px 0 12px; }
.donut-block { display: flex; gap: 18px; align-items: center; }
.donut-block svg { width: 132px; height: 132px; flex: none; }
.chart svg.bars, .chart svg.area { width: 100%; height: 170px; display: block; }
.legend-row { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto auto; gap: 8px; align-items: center; margin: 6px 0; font-size: 13px; }
.legend-row i { width: 10px; height: 10px; border-radius: 50%; display: block; }
.feed { display: grid; grid-template-columns: 92px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); color: var(--text); text-decoration: none; }
.when { font-weight: 650; font-size: 13px; white-space: nowrap; }
.when-col { text-align: right; }
.db-note { margin: -6px 0 14px; }
.db-note.warn { color: #9a5b00; background: #fff6e8; border: 1px solid #f3e0bf; border-radius: 12px; padding: 10px 12px; }
.side-phones { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.phone-link { display: flex; align-items: center; gap: 8px; }
.mini { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); flex: none; }
.mini.on { background: var(--ok); }

@media (max-width: 1100px) {
  .stats.five, .chart-row { grid-template-columns: 1fr 1fr; }
  .split { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { min-height: 0; flex-direction: row; flex-wrap: wrap; align-items: center; border-right: 0; border-bottom: 1px solid var(--line); }
  .side nav, .side-foot, .side-phones { margin-top: 0; flex-direction: row; align-items: center; flex-wrap: wrap; }
  .stats, .stats.five, .grid, .facts, .login-wrap, .home-grid, .chart-row, .split { grid-template-columns: 1fr; }
  .login-brand { padding: 28px 24px 8px; }
  .login-brand h1 { font-size: 36px; }
  .stage { padding: 20px 16px 56px; }
  .device, .alert { grid-template-columns: 4px minmax(0, 1fr) auto; }
  .hide-sm { display: none; }
}
