:root {
  --bg: #F5F7FA;
  --sidebar: #0F2744;
  --sidebar-2: #163556;
  --accent: #12B886;
  --accent-dark: #0CA678;
  --ink: #1F2937;
  --muted: #6B7280;
  --line: #E5E7EB;
  --card: #FFFFFF;
  --danger: #E03131;
  --ok: #0CA678;
  --info: #228BE6;
  --warn: #F08C00;
  --shadow: 0 8px 24px rgba(15, 39, 68, 0.06);
  --radius: 12px;
  --sidebar-w: 240px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

/* ===== Shell ===== */
.app-shell {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--sidebar) 0%, #0B1C31 100%);
  color: #fff;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.sidebar-brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding: 1.25rem 1.1rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.logo-mark {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 10px;
  background: var(--accent);
  display: grid;
  place-items: center;
  font-weight: 800;
}
.brand-title { font-weight: 700; font-size: 0.98rem; }
.brand-sub { font-size: 0.75rem; color: #9FB3C8; margin-top: 0.15rem; }
.sidebar-nav { padding: 0.75rem 0.7rem 1.5rem; }
.nav-group {
  margin: 1rem 0.55rem 0.35rem;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #7B93A9;
}
.nav-link {
  display: block;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  color: #D9E2EC;
  text-decoration: none;
  font-size: 0.94rem;
  margin-bottom: 0.15rem;
}
.nav-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-link.is-active {
  background: rgba(18, 184, 134, 0.18);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--accent);
}

.main-area {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.top-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(245, 247, 250, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1.5rem;
}
.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}
.breadcrumb { font-size: 0.78rem; color: var(--muted); }
.page-title { margin: 0.1rem 0 0; font-size: 1.25rem; }
.admin-chip {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  font-size: 0.88rem;
  color: var(--muted);
}
.sidebar-toggle {
  display: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  width: 2.2rem;
  height: 2.2rem;
  cursor: pointer;
}
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 39, 68, 0.35);
  z-index: 30;
}
.content {
  padding: 1.25rem 1.5rem 2.5rem;
  width: 100%;
  max-width: 1280px;
}

/* ===== Cards / typography ===== */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.2rem 1.35rem;
  box-shadow: var(--shadow);
}
.stack { display: grid; gap: 1rem; }
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.page-head h1 { margin: 0 0 0.3rem; font-size: 1.35rem; }
.muted { color: var(--muted); font-size: 0.92rem; }
h2 { margin: 0 0 0.75rem; font-size: 1.05rem; }
h3 { margin: 0; }

/* ===== Stats ===== */
.grid, .stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.15rem;
}
.stat, .stat-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.05rem 1.1rem;
  box-shadow: var(--shadow);
}
.stat .n, .stat-card .n { font-size: 1.7rem; font-weight: 750; letter-spacing: -0.02em; }
.stat .l, .stat-card .l { color: var(--muted); font-size: 0.85rem; margin-top: 0.3rem; }

.mini-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
  gap: 0.55rem;
  margin: 0.5rem 0 0.75rem;
}
.mini-stats > div {
  background: #F8FAFC;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.45rem;
  text-align: center;
}
.mini-stats .n { display: block; font-size: 1.2rem; font-weight: 700; }
.mini-stats .l { display: block; color: var(--muted); font-size: 0.76rem; margin-top: 0.15rem; }

/* ===== Tables / badges / forms ===== */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 0.75rem 0.5rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.93rem;
  vertical-align: middle;
}
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
.badge {
  display: inline-block;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-size: 0.76rem;
  background: #EEF2F6;
  color: #475569;
}
.badge.on, .badge.ok { background: #D3F9D8; color: var(--ok); }
.badge.off, .badge.muted { background: #E9ECEF; color: #868E96; }
.badge.info, .badge.active { background: #D0EBFF; color: var(--info); }
.badge.warn { background: #FFF3BF; color: var(--warn); }
.badge.danger { background: #FFE3E3; color: var(--danger); }

label { display: block; margin: 0.6rem 0 0.25rem; font-size: 0.9rem; color: var(--muted); }
input[type=text], input[type=password], input[type=number], input[type=url], select, textarea {
  width: 100%;
  padding: 0.58rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  background: #fff;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 0.85rem;
  padding: 0.55rem 1rem;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--accent-dark); }
.btn.secondary { background: #334E68; }
.btn.secondary:hover { background: #243B53; }
.btn.ghost {
  margin-top: 0;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn.ghost:hover { background: #F8FAFC; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.actions .btn { margin-top: 0; }
.flash { padding: 0.8rem 1rem; border-radius: 10px; margin-bottom: 1rem; }
.flash-ok { background: #D3F9D8; color: var(--ok); }
.flash-err { background: #FFE3E3; color: var(--danger); }
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: flex-end;
}
.filter-row label { margin: 0; min-width: 8rem; }
.filter-row .btn { margin-top: 0; }
.once-keys textarea {
  font-family: ui-monospace, Consolas, monospace;
  background: #0B1F33;
  color: #E6F0FF;
  border-color: #243B53;
}
.warn-text { color: var(--danger); font-size: 0.92rem; }
.count-presets { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.35rem 0 0.5rem; }
.count-presets .btn { margin-top: 0; }
table.kv th { width: 9rem; color: var(--muted); font-weight: 600; vertical-align: top; }
table.kv td, table.kv th { border-bottom: 1px solid var(--line); padding: 0.7rem 0.4rem; }
.hidden-form { display: none; }
code.mono { font-size: 0.8rem; word-break: break-all; }

/* ===== Software cards ===== */
.software-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1rem;
}
.software-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}
.software-card-head h2 { margin: 0; font-size: 1.12rem; }
.soft-h { margin: 1rem 0 0.5rem; font-size: 0.92rem; color: var(--muted); font-weight: 600; }
.soft-meta { margin: 0.4rem 0; font-size: 0.94rem; }
.plan-pills { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0.35rem 0 0.75rem; }
.plan-pill {
  background: #EBFBEE;
  color: var(--ok);
  border-radius: 999px;
  padding: 0.18rem 0.55rem;
  font-size: 0.78rem;
}

/* ===== Tabs ===== */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.55rem;
}
.tab-btn {
  border: 0;
  background: transparent;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  cursor: pointer;
  color: var(--muted);
  font: inherit;
}
.tab-btn.is-active {
  background: rgba(18, 184, 134, 0.12);
  color: var(--accent-dark);
  font-weight: 600;
}
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

/* ===== Auth ===== */
.auth-shell { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, #E7F5FF, var(--bg) 45%); }
.login-wrap { width: min(420px, 92vw); }
.login-wrap h1 { margin-top: 0; }
.auth-content { width: 100%; padding: 1rem; }

/* ===== Responsive ===== */
@media (max-width: 960px) {
  .sidebar {
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-backdrop { display: block; }
  .main-area { margin-left: 0; }
  .sidebar-toggle { display: inline-grid; place-items: center; }
  .content { padding: 1rem; }
  .admin-chip { display: none; }
}
