:root {
  --bg: #f0f2f5;
  --bg-deep: #151b2c;
  --panel: #ffffff;
  --ink: #1f2329;
  --muted: #68707d;
  --line: #e4e7ed;
  --line-strong: #d3d8de;
  --accent: #2563eb;
  --accent-hover: #1d4fd8;
  --accent-bg: rgba(37, 99, 235, 0.08);
  --danger: #d93a3a;
  --danger-hover: #c02e2e;
  --ok: #16a34a;
  --warn: #d48806;
  --shadow: 0 10px 32px rgba(15, 23, 42, 0.14);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --radius: 10px;
  --font: "Segoe UI", "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  --ctrl-h: 38px;
  --ctrl-pad-y: 0.55rem;
  --ctrl-pad-x: 0.75rem;
  --lh: 1.35;
}

* { box-sizing: border-box; }
html { height: 100%; font-size: 16px; }
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea {
  font: inherit;
  line-height: var(--lh);
}
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
::selection { background: rgba(37, 99, 235, 0.18); }
.is-hidden, [hidden] { display: none !important; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb {
  background: rgba(31, 35, 41, 0.22);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-track { background: transparent; }

/* buttons — same metrics as desktop exe */
.btn {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0.5rem 1rem;
  min-height: var(--ctrl-h);
  font-weight: 500;
  line-height: var(--lh);
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  transition: background .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease;
  white-space: nowrap;
}
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-bg), 0 0 0 1px var(--accent) inset;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary, button.g {
  background: #fff;
  border-color: var(--line-strong);
  color: var(--ink);
}
.btn-secondary:hover, button.g:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-bg);
}
.btn-danger, button.r { background: var(--danger); color: #fff; border-color: transparent; }
.btn-danger:hover, button.r:hover { background: var(--danger-hover); }
.btn-ghost {
  background: #fff;
  border-color: var(--line);
  color: var(--muted);
}
.btn-sm {
  padding: 0.3rem 0.7rem;
  min-height: 32px;
  font-size: 0.85rem;
  border-radius: 6px;
}
.btn-block { width: 100%; }

input, select {
  height: var(--ctrl-h);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: var(--ctrl-pad-y) var(--ctrl-pad-x);
  background: #fff;
  outline: none;
  color: var(--ink);
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}
input[type="number"] { width: 5.5rem; }
.muted { color: var(--muted); font-size: 0.92rem; line-height: 1.45; }

.pill {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  background: rgba(22, 163, 74, 0.1);
  color: var(--ok);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
}
.pill.warn { background: rgba(212, 136, 6, 0.12); color: var(--warn); }
.pill.off, .pill.bad { background: rgba(217, 58, 58, 0.09); color: var(--danger); }
.ok { color: var(--ok); font-weight: 600; }
.bad { color: var(--danger); font-weight: 600; }
.warn { color: var(--warn); font-weight: 600; }

/* login — match exe card */
.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  padding: 2rem;
}
.login-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 70% 55% at 78% 12%, rgba(37, 99, 235, 0.28), transparent 58%),
    radial-gradient(ellipse 60% 45% at 12% 88%, rgba(29, 79, 216, 0.22), transparent 55%),
    linear-gradient(150deg, #10162a 0%, #182039 55%, #131a30 100%);
}
.login-card {
  position: relative;
  width: min(420px, 100%);
  background: #fff;
  border-radius: 14px;
  padding: 2.25rem 2rem 2rem;
  box-shadow: var(--shadow);
}
.login-brand { text-align: center; margin-bottom: 1.75rem; }
.login-brand h1 {
  margin: 0.9rem 0 0.3rem;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.3;
}
.login-brand p { margin: 0; color: var(--muted); font-size: 0.92rem; line-height: 1.45; }
.brand-mark {
  width: 60px; height: 60px; margin: 0 auto;
  border-radius: 14px;
  display: grid; place-items: center;
  font-weight: 700; color: #fff; font-size: 1.25rem; line-height: 1;
  background: linear-gradient(135deg, #2563eb, #1d4fd8);
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.35);
}
.login-form label { display: block; margin-bottom: 1rem; }
.login-form span {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.35;
}
.login-form input { width: 100%; height: var(--ctrl-h); }
.form-error, .err {
  color: var(--danger);
  text-align: center;
  margin-top: 0.6rem;
  font-size: 0.9rem;
  line-height: 1.45;
}

/* app shell — match exe */
.app-view {
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
  align-items: start;
}
.sidebar {
  background: var(--bg-deep);
  color: #dbe1ec;
  display: flex;
  flex-direction: column;
  padding: 1rem 0.75rem 0.85rem;
  position: sticky;
  top: 0;
  height: 100vh;
  max-height: 100vh;
  overflow-y: auto;
  z-index: 10;
}
.sidebar-brand {
  display: flex; gap: 0.7rem; align-items: center;
  padding: 0.35rem 0.5rem 1.1rem;
}
.sidebar-avatar {
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #2b64d9, #1d4fd8);
  color: #fff; font-weight: 700; font-size: 1.05rem; line-height: 1;
  border: 2px solid rgba(255, 255, 255, 0.16);
  flex-shrink: 0;
}
.sidebar-brand strong {
  display: block; font-size: 1rem; font-weight: 600; color: #fff; line-height: 1.3;
}
.sidebar-brand small {
  color: #8b94ab; font-size: 0.8rem; display: block; margin-top: 0.1rem; line-height: 1.35;
}
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  text-align: left;
  background: transparent;
  border: none;
  color: #aab2c4;
  padding: 0.6rem 0.75rem;
  min-height: 42px;
  border-radius: 7px;
  font-weight: 500;
  font-size: 0.95rem;
  line-height: 1.3;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  position: relative;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.nav-item.active {
  background: rgba(37, 99, 235, 0.22);
  color: #fff;
  font-weight: 600;
}
.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 60%;
  border-radius: 0 2px 2px 0;
  background: var(--accent);
}
.sidebar-foot {
  padding: 0.7rem 0.5rem 0.15rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.user-chip {
  display: flex; justify-content: space-between; align-items: center;
  padding-top: 0.6rem; font-size: 0.92rem; color: #cbd2df; line-height: 1.35;
}
.sidebar .btn-ghost {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.16);
  color: #cbd2df;
}
.sidebar .btn-ghost:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.28);
}
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.85rem 1.5rem;
  min-height: 56px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.topbar h2 { margin: 0; font-size: 1.05rem; font-weight: 600; line-height: 1.35; }
.topbar-actions { display: flex; gap: 0.6rem; align-items: center; }
.content { padding: 1.4rem 1.5rem 2rem; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
}
.panel > h4, .panel-head h4 {
  position: relative;
  padding-left: 0.72rem;
  font-size: 1rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  line-height: 1.35;
  margin: 0 0 0.85rem;
}
.panel > h4::before, .panel-head h4::before {
  content: "";
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 3.5px; height: 0.95rem;
  border-radius: 2px;
  background: var(--accent);
}
.panel-head {
  display: flex; justify-content: space-between; align-items: center; gap: 0.6rem;
  margin-bottom: 0.85rem; flex-wrap: wrap;
}
.panel-head h4 { margin: 0; }
.row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.row > input, .row > select { width: auto; min-width: 140px; flex: 1; }
.row > input.short, .row > input[name="count"], .row > input[name="amount"], .row > input[name="max_devices"] {
  min-width: 4.6rem; width: 4.6rem; flex: 0 0 4.6rem;
}
.hint { margin: 0.75rem 0 0; color: var(--muted); font-size: 0.88rem; line-height: 1.45; }

.table-wrap {
  overflow: auto;
  max-height: max(280px, calc(100vh - 280px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
table {
  width: 100%;
  min-width: 960px;
  border-collapse: collapse;
  font-size: 0.9rem;
  line-height: 1.4;
}
th, td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}
th {
  background: #f5f7fa;
  position: sticky; top: 0; z-index: 1;
  font-weight: 600;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.35;
}
tr:hover td { background: #f7fafd; }
.mono {
  font-family: ui-monospace, Consolas, "Courier New", monospace;
  font-size: 0.85rem;
  word-break: break-all;
}
td.mono[data-full] { color: var(--accent); cursor: pointer; }
.dev-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem 0.5rem;
  padding: 0.28rem 0;
  line-height: 1.35;
}
.dev-line form { display: inline; margin: 0; }
.ops form { display: inline; margin: 0; }
.pager {
  display: flex; gap: 0.75rem; align-items: center;
  padding: 0.7rem 0.15rem 0;
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.35;
}

@media (max-width: 980px) {
  .app-view { grid-template-columns: 1fr; }
  .sidebar { position: sticky; height: auto; max-height: none; }
  .nav { flex-direction: row; overflow-x: auto; }
  .nav-item { white-space: nowrap; min-height: 38px; }
  .nav-item.active::before { display: none; }
  .content, .topbar { padding-left: 0.9rem; padding-right: 0.9rem; }
}
