:root {
  --bg: #d9edfb;
  --bg2: #eaf5fd;
  --card: #ffffff;
  --ink: #12324a;
  --muted: #5b7a93;
  --line: #cfe2f1;
  --primary: #1f7fd1;
  --primary-ink: #ffffff;
  --up: #22b55f;
  --high: #f2c218;
  --down: #e5484d;
  --none: #c7d3dd;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(30, 90, 140, .10);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%) fixed;
  min-height: 100vh;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}
button, input { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 650; }
h2 { font-size: 1.15rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 10px; padding: .5rem .95rem; cursor: pointer; font-weight: 550;
  box-shadow: 0 1px 2px rgba(0,0,0,.04); white-space: nowrap;
}
.btn:hover { border-color: var(--primary); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.danger { background: var(--down); border-color: var(--down); color: #fff; }
.btn.wide { width: 100%; padding: .7rem; }
.btnrow { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.btnrow.center { justify-content: center; }
.btnrow form { margin: 0; }

/* ---------- top bar ---------- */
.top {
  max-width: 1100px; margin: 0 auto; padding: 22px 0 14px;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap;
}
.clock { font-size: clamp(3.4rem, 11vw, 5.6rem); font-weight: 700; line-height: 1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.date { font-size: clamp(1rem, 3vw, 1.3rem); color: var(--muted); margin-top: 6px; font-weight: 500; }
.topbtns { display: flex; gap: .5rem; align-items: center; }
.topbtns form { margin: 0; }
.iconbox {
  width: 42px; height: 40px; display: grid; place-items: center; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); border-radius: 10px;
}
.iconbox .dot { width: 16px; height: 16px; }

.wrap { max-width: 1100px; margin: 0 auto; padding-bottom: 40px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.cardhead { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }

/* ---------- status dot ---------- */
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: var(--none); flex: none; }
.dot.up { background: var(--up); }
.dot.down { background: var(--down); }

/* ---------- monitor rows ---------- */
.mlist { display: flex; flex-direction: column; }
.mrow {
  display: block; width: 100%; text-align: left; background: none; border: 0; cursor: pointer;
  border-top: 1px solid var(--line); padding: 12px 4px;
}
.mrow:first-child { border-top: 0; }
.mrow:hover { background: #f5faff; }
.mname { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 1.05rem; }
.mhost { color: var(--muted); font-weight: 400; font-size: .85rem; }
.mline { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.strip { flex: 1; display: flex; gap: 2px; height: 26px; min-width: 0; }
.strip i { flex: 1; border-radius: 3px; background: var(--none); min-width: 2px; }
.strip i.g { background: var(--up); }
.strip i.r { background: var(--down); }
.pct { font-weight: 650; font-variant-numeric: tabular-nums; min-width: 4.6em; text-align: right; }
.srow { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.srow .mname { min-width: 0; flex-wrap: wrap; }
.empty { padding: 20px 4px; color: var(--muted); }

/* ---------- full-screen overlays ---------- */
.ov {
  position: fixed; inset: 0; z-index: 50; overflow-y: auto;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%);
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}
.ovbar {
  position: sticky; top: 0; z-index: 2; max-width: 900px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px; padding: 14px 0;
  background: linear-gradient(180deg, var(--bg) 80%, rgba(217,237,251,0));
}
.ovbar h2 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 1.25rem; }
.ovbody { max-width: 900px; margin: 0 auto; padding-bottom: 40px; }
.confirm { z-index: 80; display: grid; place-items: center; background: rgba(217,237,251,.97); }
.confirm[hidden] { display: none; }
.confirmbox { max-width: 440px; width: 100%; text-align: center; padding: 28px 22px; }
.confirmbox p { color: var(--muted); margin: 12px 0 22px; }

/* ---------- forms ---------- */
label { display: block; font-weight: 550; margin-bottom: 12px; }
label .hint { display: block; font-weight: 400; color: var(--muted); font-size: .82rem; }
input[type=text], input[type=password], input[type=number], input:not([type]) {
  display: block; width: 100%; margin-top: 5px; padding: .6rem .7rem;
  border: 1px solid var(--line); border-radius: 9px; background: #fbfdff;
}
input:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0 16px; }
.alert { background: #fdecec; color: #8c1d20; border-radius: 9px; padding: .6rem .8rem; margin-bottom: 12px; }
.ok { background: #e6f7ed; color: #145c32; border-radius: 9px; padding: .6rem .8rem; margin-bottom: 12px; }
.formmsg:empty { display: none; }

/* ---------- key/value boxes ---------- */
.kv { display: grid; grid-template-columns: minmax(120px, 40%) 1fr; }
.kv div { padding: 10px 2px; border-top: 1px solid var(--line); }
.kv div:nth-child(-n+2) { border-top: 0; }
.kv .k { color: var(--muted); }
.kv .v { font-weight: 600; text-align: right; overflow-wrap: anywhere; }
.meter { height: 6px; background: #e7f0f7; border-radius: 3px; margin-top: 5px; overflow: hidden; }
.meter b { display: block; height: 100%; background: var(--primary); }

/* ---------- graph ---------- */
.rangenav { display: flex; align-items: center; justify-content: center; gap: 14px; margin-bottom: 12px; }
.rangenav h3 { font-size: 1.2rem; min-width: 7.5em; text-align: center; }
.btn.arrow { width: 42px; height: 38px; padding: 0; font-size: 1.5rem; line-height: 1; }
.graphbox { touch-action: pan-y; user-select: none; }
.gtop { display: flex; justify-content: space-between; color: var(--muted); font-size: .8rem; margin-bottom: 4px; }
.graph { display: flex; align-items: flex-end; gap: 2px; height: 200px; border-bottom: 1px solid var(--line); }
.graph i { flex: 1; min-width: 1px; border-radius: 2px 2px 0 0; background: var(--none); cursor: pointer; }
.graph i.up { background: var(--up); }
.graph i.high { background: var(--high); }
.graph i.down { background: var(--down); }
.gplot { position: relative; }
.gplot .graph {
  background: repeating-linear-gradient(to top, transparent 0, transparent calc(25% - 1px), #e8f1f8 calc(25% - 1px), #e8f1f8 25%); }
.yaxis { position: absolute; inset: 0; pointer-events: none; z-index: 1; }
.yaxis span { position: absolute; left: 2px; transform: translateY(-50%); padding: 0 4px; border-radius: 4px;
  background: rgba(255,255,255,.85); color: var(--muted); font-size: .72rem; line-height: 1.4; font-variant-numeric: tabular-nums; }
.gaxis { display: flex; justify-content: space-between; color: var(--muted); font-size: .8rem; margin-top: 4px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .85rem; color: var(--muted); margin-top: 10px; }
.legend span::before { content: ""; display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; background: var(--c); }

/* ---------- toggles ---------- */
.toggle { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); margin: 0; }
.toggle:first-of-type { border-top: 0; }
.switch { position: relative; width: 50px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--none); border-radius: 14px; transition: .2s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 22px; height: 22px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--up); }
.switch input:checked + span::after { transform: translateX(22px); }
.switch input:focus-visible + span { outline: 2px solid var(--primary); }

.device { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.device:first-child { border-top: 0; }
.tag { background: #e3f0fa; color: var(--primary); border-radius: 6px; padding: 1px 7px; font-size: .78rem; font-weight: 600; margin-left: 6px; }

/* ---------- login ---------- */
.login-body { display: grid; place-items: center; }
.login { width: 100%; max-width: 360px; padding: 28px 24px; }
.login h1 { font-size: 1.4rem; margin-bottom: 18px; }
.login-logo { display: flex; align-items: center; gap: 8px; color: var(--primary); font-weight: 700; margin-bottom: 16px; }

@media (max-width: 520px) {
  .top { padding-top: 16px; }
  .kv { grid-template-columns: 1fr 1fr; }
  .card { padding: 14px; }
  .graph { height: 160px; gap: 1px; }
}
