:root {
  --bg: #05040b; --panel: #0c0a18; --panel2: #130f26; --line: #2a2150; --line2: #3a2d6e;
  --text: #ece9ff; --muted: #8c88b4; --blue: #00d9ff; --purple: #b44cff; --red: #ff2e63; --green: #19f5a0; --yellow: #ffd23f;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, Segoe UI, Roboto, sans-serif; }
body {
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(0, 217, 255, .10), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(180, 76, 255, .12), transparent 60%),
    radial-gradient(800px 400px at 50% 110%, rgba(255, 46, 99, .08), transparent 60%), var(--bg);
  min-height: 100vh;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-shadow: 0 0 8px var(--blue); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.pad { padding: 20px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.errtext { color: var(--red); min-height: 18px; }

.logo { font-weight: 900; letter-spacing: 2px; font-size: 20px; color: var(--blue); text-shadow: 0 0 12px rgba(0, 217, 255, .7); white-space: nowrap; }
.logo span { background: linear-gradient(90deg, var(--purple), var(--red)); -webkit-background-clip: text; background-clip: text; color: transparent; text-shadow: none; filter: drop-shadow(0 0 8px rgba(180, 76, 255, .6)); }
.logo.big { font-size: 34px; }

header { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 18px; padding: 12px 20px;
  background: rgba(5, 4, 11, .85); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
nav a { padding: 7px 12px; border-radius: 8px; color: var(--muted); border: 1px solid transparent; }
nav a:hover { color: var(--text); text-shadow: none; border-color: var(--line); }
nav a.active { color: var(--text); border-color: var(--purple); box-shadow: 0 0 12px rgba(180, 76, 255, .35) inset, 0 0 10px rgba(180, 76, 255, .25); }
.hdr-right { display: flex; align-items: center; gap: 10px; }
.badge { padding: 4px 10px; border-radius: 999px; font-weight: 700; font-size: 12px; border: 1px solid var(--line2); }
.badge.live { color: var(--red); border-color: var(--red); box-shadow: 0 0 12px rgba(255, 46, 99, .5); }
.badge.paper { color: var(--purple); border-color: var(--purple); box-shadow: 0 0 10px rgba(180, 76, 255, .4); }
.badge.alert { color: var(--blue); border-color: var(--blue); }

main { padding: 18px 20px 60px; max-width: 1500px; margin: 0 auto; }
.card { background: linear-gradient(180deg, var(--panel2), var(--panel)); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 16px;
  box-shadow: 0 0 0 1px rgba(0, 217, 255, .03), 0 10px 30px rgba(0, 0, 0, .35); }
.card h3 { margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--blue); }
.card.err { border-color: var(--red); color: var(--red); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }
.grid2 .card { margin-bottom: 0; }
.grid2 + .grid2, .grid2 + .card, .card + .grid2 { margin-top: 16px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: linear-gradient(160deg, var(--panel2), var(--panel)); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.kpi .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .8px; }
.kpi .v { font-size: 22px; font-weight: 800; margin: 2px 0; font-variant-numeric: tabular-nums; }
.kpi .s { color: var(--muted); font-size: 12px; }
.kpi .v.pos { text-shadow: 0 0 10px rgba(25, 245, 160, .45); }
.kpi .v.neg { text-shadow: 0 0 10px rgba(255, 46, 99, .45); }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { background: transparent; color: var(--muted); border: 0; padding: 7px 12px; cursor: pointer; font: inherit; }
.seg button.on { color: var(--text); background: linear-gradient(90deg, rgba(0, 217, 255, .18), rgba(180, 76, 255, .22)); }

.btn { background: var(--panel2); color: var(--text); border: 1px solid var(--line2); border-radius: 9px; padding: 8px 14px; cursor: pointer; font: inherit; font-weight: 600; }
.btn:hover { border-color: var(--blue); box-shadow: 0 0 10px rgba(0, 217, 255, .3); }
.btn.primary { border-color: var(--purple); background: linear-gradient(90deg, rgba(0, 217, 255, .25), rgba(180, 76, 255, .35)); }
.btn.danger { border-color: var(--red); color: var(--red); }
.btn.danger:hover { box-shadow: 0 0 10px rgba(255, 46, 99, .4); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 9px; font-size: 12px; }

input, select { background: #08061a; color: var(--text); border: 1px solid var(--line2); border-radius: 9px; padding: 8px 10px; font: inherit; min-width: 0; }
input:focus, select:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 2px rgba(0, 217, 255, .2); }
.form-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.grow { flex: 1 1 240px; }

.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 10px; border-bottom: 1px solid rgba(42, 33, 80, .7); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; position: sticky; top: 0; background: var(--panel2); }
tbody tr:hover { background: rgba(0, 217, 255, .05); }
tr.clickable { cursor: pointer; }
td.wrap { white-space: normal; max-width: 260px; }

.chart { width: 100%; height: 170px; display: block; }
.chart .zero { stroke: var(--line2); stroke-width: 1; }
.axis-note { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-top: 4px; }

.setting { display: flex; gap: 12px; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid rgba(42, 33, 80, .6); }
.setting:last-child { border-bottom: 0; }
.s-name { font-weight: 600; }
.s-info { color: var(--muted); font-size: 12px; }
.s-input { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.s-input input[type=number] { width: 120px; text-align: right; }
.unit { color: var(--muted); font-size: 12px; min-width: 28px; }
.switch { position: relative; width: 46px; height: 24px; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #1a1535; border: 1px solid var(--line2); border-radius: 999px; transition: .2s; cursor: pointer; }
.switch span::before { content: ''; position: absolute; width: 18px; height: 18px; left: 2px; top: 2px; background: var(--muted); border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: rgba(25, 245, 160, .2); border-color: var(--green); box-shadow: 0 0 10px rgba(25, 245, 160, .35); }
.switch input:checked + span::before { transform: translateX(22px); background: var(--green); }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; border: 1px solid var(--line2); }
.pill.live { color: var(--red); border-color: var(--red); }
.pill.paper { color: var(--purple); border-color: var(--purple); }
.pill.auto { color: var(--yellow); border-color: var(--yellow); }
.pill.manual { color: var(--blue); border-color: var(--blue); }
.pill.ok { color: var(--green); border-color: var(--green); }
.pill.no { color: var(--red); border-color: var(--red); }

.statusgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.dot.ok { background: var(--green); box-shadow: 0 0 8px var(--green); }
.dot.bad { background: var(--red); box-shadow: 0 0 8px var(--red); }

.login { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: rgba(5, 4, 11, .96); }
.login-box { width: min(360px, 90vw); display: flex; flex-direction: column; gap: 12px; text-align: center; padding: 30px; border: 1px solid var(--line2);
  border-radius: 18px; background: linear-gradient(180deg, var(--panel2), var(--panel)); box-shadow: 0 0 40px rgba(180, 76, 255, .25); }

.toast { position: fixed; right: 20px; bottom: 20px; padding: 10px 16px; border-radius: 10px; background: var(--panel2); border: 1px solid var(--green);
  color: var(--text); opacity: 0; transform: translateY(10px); transition: .25s; pointer-events: none; z-index: 60; max-width: 80vw; }
.toast.show { opacity: 1; transform: none; }
.toast.bad { border-color: var(--red); }

@media (max-width: 700px) {
  header { flex-wrap: wrap; gap: 10px; }
  nav { order: 3; width: 100%; }
  .grid2 { grid-template-columns: 1fr; }
  main { padding: 12px; }
  .kpi .v { font-size: 18px; }
}
