* { box-sizing: border-box; }

:root {
  --page: #0b0c0f;
  --surface: #15181f;
  --surface-2: #1b1f28;
  --surface-hover: #20242e;
  --border: rgba(255,255,255,0.08);
  --border-strong: rgba(255,255,255,0.14);
  --ink: #f4f5f7;
  --ink-secondary: #b7bec9;
  --ink-muted: #7b8494;

  --accent: #3987e5;
  --accent-dark: #2a78d6;
  --accent-wash: rgba(57,135,229,0.12);

  --good: #1fbf5c;
  --good-wash: rgba(31,191,92,0.12);
  --critical: #e34f4f;
  --critical-wash: rgba(227,79,79,0.12);
  --critical-dark: #cc3d3d;

  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-card: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.28);
}

html { color-scheme: dark; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background:
    radial-gradient(1100px 500px at 15% -10%, rgba(57,135,229,0.10), transparent 60%),
    var(--page);
  color: var(--ink);
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

.center {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

/* ---------- brand mark ---------- */
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  background: linear-gradient(155deg, var(--accent), #6d5ce8);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(57,135,229,0.35);
}
.brand-mark svg { width: 18px; height: 18px; }
.brand-text { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
.brand-sub { font-size: 12px; color: var(--ink-muted); }

/* ---------- auth card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 32px;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 340px;
  box-shadow: var(--shadow-card);
}
.card .brand { margin-bottom: 24px; }
.card h1 { margin: 0; font-size: 18px; }

label { display: block; margin: 14px 0 6px; font-size: 13px; color: var(--ink-secondary); font-weight: 500; }

input[type=text], input[type=password], input[type=number], input[type=date] {
  width: 100%; padding: 11px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--page); color: var(--ink); font-size: 14px; font-family: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-wash);
}
input::placeholder { color: var(--ink-muted); }

button {
  margin-top: 18px; width: 100%; padding: 11px; border-radius: var(--radius-sm); border: none;
  background: var(--accent); color: white; font-weight: 600; cursor: pointer; font-size: 14px;
  font-family: inherit; transition: background .15s ease, transform .05s ease;
}
button:hover { background: var(--accent-dark); }
button:active { transform: translateY(1px); }
button.danger { background: transparent; color: var(--critical); border: 1px solid rgba(227,79,79,0.35); }
button.danger:hover { background: var(--critical-wash); }
button.secondary { background: var(--surface-2); color: var(--ink-secondary); border: 1px solid var(--border); }
button.secondary:hover { background: var(--surface-hover); color: var(--ink); }
button.ghost { background: transparent; border: 1px dashed var(--border-strong); color: var(--ink-secondary); }
button.ghost:hover { background: var(--surface-2); }

.error {
  color: #ffb4b4; font-size: 13px; background: var(--critical-wash);
  border: 1px solid rgba(227,79,79,0.3); padding: 10px 12px; border-radius: var(--radius-sm);
  margin: 0 0 16px;
}

/* ---------- layout ---------- */
.wrap { max-width: 1080px; margin: 0 auto; padding: 32px 20px 60px; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 28px; gap: 16px; flex-wrap: wrap; }
.topbar form, .topbar button { margin: 0; }
.topbar button { width: auto; padding: 9px 16px; }

/* ---------- stat tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 18px 18px 16px; position: relative; overflow: hidden;
}
.stat::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 2px;
  background: linear-gradient(90deg, var(--stat-accent, var(--accent)), transparent);
}
.stat-icon {
  width: 30px; height: 30px; border-radius: 9px; display: flex; align-items: center; justify-content: center;
  background: var(--stat-wash, var(--accent-wash)); color: var(--stat-accent, var(--accent)); margin-bottom: 10px;
}
.stat-icon svg { width: 16px; height: 16px; }
.stat-value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12.5px; color: var(--ink-muted); margin-top: 2px; }

/* ---------- chart ---------- */
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 18px 18px 8px; margin-bottom: 24px; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.chart-title { font-size: 13.5px; color: var(--ink-secondary); font-weight: 600; }
.chart-hint { font-size: 12px; color: var(--ink-muted); }
.chart-wrap { position: relative; }
.chart { width: 100%; height: 150px; display: block; overflow: visible; }
.chart .bar { fill: var(--accent); transition: fill .12s ease; }
.chart .bar:hover, .chart .bar.hovered { fill: #6db0ff; }
.chart .baseline { stroke: var(--border-strong); stroke-width: 1; }
.chart .chart-label { fill: var(--ink-muted); font-size: 9px; font-family: inherit; }
.chart-tooltip {
  position: absolute; pointer-events: none; background: #0d0f14; border: 1px solid var(--border-strong);
  color: var(--ink); font-size: 12px; padding: 6px 9px; border-radius: 8px; white-space: nowrap;
  transform: translate(-50%, -115%); opacity: 0; transition: opacity .1s ease; box-shadow: var(--shadow-card);
  z-index: 5;
}
.chart-tooltip.show { opacity: 1; }
.chart-tooltip b { font-variant-numeric: tabular-nums; }

/* ---------- add user ---------- */
.addform-toggle { display: flex; justify-content: flex-end; margin-bottom: 12px; }
.addform-toggle button { width: auto; padding: 9px 16px; margin: 0; }
details.addform-details { margin-bottom: 20px; }
details.addform-details summary { list-style: none; cursor: pointer; }
details.addform-details summary::-webkit-details-marker { display: none; }
.summary-btn {
  display: inline-block; padding: 9px 16px; border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--ink-secondary); border: 1px solid var(--border);
  font-size: 14px; font-weight: 600; user-select: none; transition: background .15s ease, color .15s ease;
}
.summary-btn:hover { background: var(--surface-hover); color: var(--ink); }
details[open] .summary-btn { background: var(--accent-wash); color: var(--accent); border-color: rgba(57,135,229,0.35); }
.addform {
  background: var(--surface); border: 1px solid var(--border); padding: 20px;
  border-radius: var(--radius-md); margin-top: 12px;
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; align-items: end;
}
.addform > div:nth-child(1) { grid-column: span 1; }
.addform label { margin-top: 0; }
.addform button { grid-column: span 1; margin-top: 0; }

/* ---------- table ---------- */
.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 16px; text-align: left; font-size: 14px; border-bottom: 1px solid var(--border); }
th { color: var(--ink-muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; background: var(--surface-2); }
tr:last-child td { border-bottom: none; }
tbody tr { transition: background .1s ease; }
tbody tr:hover { background: var(--surface-2); }
.name-cell { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: white; background: linear-gradient(155deg, var(--accent), #6d5ce8);
}
.contact-cell { color: var(--ink-muted); font-size: 13px; }
.traffic-cell { font-variant-numeric: tabular-nums; color: var(--ink-secondary); }
.traffic-cell .limit { color: var(--ink-muted); }
.progress { width: 100px; height: 4px; border-radius: 999px; background: var(--surface-2); margin-top: 6px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.progress > span.warn { background: #e0a638; }
.progress > span.full { background: var(--critical); }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.on { background: var(--good-wash); color: var(--good); }
.badge.off { background: var(--critical-wash); color: #ff8f8f; }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; margin: 0; }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #545c69; margin-right: 6px; flex: none; }
.dot.online { background: var(--good); box-shadow: 0 0 0 3px var(--good-wash); }

.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.actions form { display: inline; }
.actions button { width: auto; margin: 0; padding: 7px 11px; font-size: 12.5px; }

.empty-state { padding: 48px 20px; text-align: center; color: var(--ink-muted); }
.empty-state .brand-mark { margin: 0 auto 14px; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.mono {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace; word-break: break-all; font-size: 12.5px;
  background: var(--page); border: 1px solid var(--border); padding: 12px 14px; border-radius: var(--radius-sm);
  display: block; margin: 14px 0; color: var(--ink-secondary); line-height: 1.5;
}

.footnote { margin-top: 24px; color: var(--ink-muted); font-size: 12.5px; display: flex; gap: 6px; align-items: center; }
.footnote .mono-inline {
  font-family: ui-monospace, Consolas, monospace; background: var(--surface); border: 1px solid var(--border);
  padding: 2px 7px; border-radius: 6px; color: var(--ink-secondary); font-size: 12px;
}

/* ---------- link/qr page ---------- */
.qr-card { text-align: center; }
.qr-card img { width: 220px; height: 220px; border-radius: var(--radius-md); background: #fff; padding: 10px; margin: 4px auto 4px; display: block; }
.copy-row { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.copy-row .mono { flex: 1; margin: 0; }
.copy-btn { width: auto; margin: 0; padding: 0 14px; height: 44px; flex: none; }
.copy-btn.copied { background: var(--good); }
.meta-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 14px 0; }
.meta-chip {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 5px 12px; font-size: 12px; color: var(--ink-secondary);
}
.hint { color: var(--ink-muted); font-size: 13px; line-height: 1.5; margin-top: 16px; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .addform { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 700px) {
  .wrap { padding: 20px 14px 40px; }
  .topbar { margin-bottom: 18px; }
  .topbar h1, .brand-text { font-size: 16px; }
  .stats { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat { padding: 14px; }
  .stat-value { font-size: 21px; }
  .chart-card { padding: 14px 14px 4px; }
  .addform { grid-template-columns: 1fr; padding: 16px; }

  .table-card { background: none; border: none; }
  table, thead, tbody, th, td, tr { display: block; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  tbody tr {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
    margin-bottom: 10px; padding: 4px 0;
  }
  tbody tr:hover { background: var(--surface); }
  td { border-bottom: 1px solid var(--border); padding: 10px 14px 10px 42%; position: relative; min-height: 20px; }
  td:last-child, tr:last-child td { border-bottom: none; }
  td:not(.actions)::before {
    content: attr(data-label);
    position: absolute; left: 14px; width: 36%;
    color: var(--ink-muted); font-size: 10.5px; text-transform: uppercase; font-weight: 600; letter-spacing: .03em;
  }
  td.actions { padding: 12px 14px; flex-direction: column; align-items: stretch; }
  td.actions button { width: 100%; }

  .qr-card img { width: 180px; height: 180px; }
  .copy-row { flex-direction: column; align-items: stretch; }
  .copy-btn { width: 100%; padding: 11px; }
}
