:root {
  --bg: #f5f5f7;
  --surface: #fff;
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --faint: #86868b;
  --line: rgba(0,0,0,.08);
  --blue: #0071e3;
  --blue-hover: #0077ed;
  --blue-soft: rgba(0,113,227,.1);
  --green: #34c759;
  --red: #ff3b30;
  --orange: #ff9500;
  --radius: 16px;
  --radius-sm: 12px;
  --pill: 980px;
  --shadow: 0 2px 8px rgba(0,0,0,.04), 0 12px 28px rgba(0,0,0,.06);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --sidebar: 260px;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; max-width: 100%; overflow-x: hidden; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Auth */
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(180deg, #eef2f7 0%, var(--bg) 40%);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: 20px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.auth-brand {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 20px;
}
.auth-brand span { color: var(--blue); font-weight: 600; }
.auth-card h1 {
  margin: 0 0 6px;
  font-size: 26px;
  letter-spacing: -0.03em;
}
.lead { color: var(--muted); margin: 0 0 20px; }
.auth-foot { margin-top: 18px; font-size: 14px; color: var(--muted); text-align: center; }

/* App shell */
.app { display: flex; min-height: 100vh; max-width: 100%; }
.sidebar {
  width: var(--sidebar);
  background: #1d1d1f;
  color: #f5f5f7;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  padding: 20px 14px;
  overflow-y: auto;
}
.brand {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  padding: 8px 12px 20px;
}
.brand span { color: #5ac8fa; font-weight: 600; }
.nav-group { margin-bottom: 14px; }
.nav-group > span {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: rgba(255,255,255,.4);
  padding: 0 12px 6px;
}
.nav-link {
  display: block;
  color: rgba(255,255,255,.75);
  text-decoration: none;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 2px;
}
.nav-link:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.nav-link.active { background: rgba(0,113,227,.35); color: #fff; }
.side-foot { margin-top: auto; padding-top: 16px; border-top: 1px solid rgba(255,255,255,.08); }
.side-user { display: flex; gap: 10px; align-items: center; padding: 8px 10px; }
.side-user strong { display: block; font-size: 13px; }
.side-user small { color: rgba(255,255,255,.45); font-size: 11px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(145deg, #5ac8fa, #0071e3);
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
  flex-shrink: 0;
}
.logout { color: rgba(255,255,255,.55) !important; }

.main-wrap {
  margin-left: var(--sidebar);
  width: calc(100% - min(var(--sidebar), 100%));
  max-width: 100%;
  min-height: 100vh;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px clamp(16px, 3vw, 28px);
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(245,245,247,.85);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}
.menu-btn {
  display: none;
  border: none;
  background: transparent;
  font-size: 20px;
  cursor: pointer;
}
.crumb strong { font-size: 15px; letter-spacing: -0.02em; }
.top-right { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.status-chip, .plan-chip {
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: var(--pill);
  text-decoration: none;
}
.status-chip.on { background: rgba(52,199,89,.14); color: #1b7f3a; }
.status-chip.off { background: rgba(0,0,0,.06); color: var(--muted); }
.plan-chip { background: var(--blue-soft); color: var(--blue); }

.content { padding: 24px clamp(16px, 3vw, 28px) 48px; max-width: 1120px; }

.hero {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  flex-wrap: wrap;
  margin-bottom: 22px;
}
.hero.compact { margin-bottom: 16px; }
.hero h1 {
  margin: 0 0 6px;
  font-size: 28px;
  letter-spacing: -0.03em;
  font-weight: 700;
}
.hero p { margin: 0; color: var(--muted); }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}
.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,.03);
  min-width: 0;
}
.metric span { display: block; font-size: 13px; color: var(--muted); font-weight: 500; }
.metric strong {
  display: block;
  font-size: 26px;
  letter-spacing: -0.03em;
  margin: 6px 0 4px;
}
.metric small { color: var(--faint); font-size: 12px; }

.panel, .empty-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,.03);
  max-width: 100%;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  gap: 10px;
}
.panel-head h2 { margin: 0; font-size: 17px; letter-spacing: -0.02em; }
.two-col {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 14px;
  margin-bottom: 16px;
}
.two-col > * { min-width: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: var(--pill);
  padding: 10px 18px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  text-decoration: none !important;
}
.btn.primary { background: var(--blue); color: #fff !important; }
.btn.primary:hover { background: var(--blue-hover); }
.btn.ghost {
  background: transparent;
  color: var(--blue) !important;
  border: 1px solid var(--line);
}
.btn.ghost:hover { background: var(--blue-soft); }
.btn.block { width: 100%; }
.btn.danger.text {
  background: transparent;
  color: var(--red);
  border: none;
  padding: 4px 8px;
  font-size: 13px;
}
.btn.danger.text:hover { background: rgba(255,59,48,.08); }

.field { display: block; margin-bottom: 12px; font-size: 13px; font-weight: 500; color: var(--muted); }
.field input, .field select, .form-grid input, .form-grid select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid rgba(0,0,0,.12);
  border-radius: 10px;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: #fff;
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 4px var(--blue-soft);
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-grid .full { grid-column: 1 / -1; }
.form-actions { grid-column: 1 / -1; }

.alert {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  font-size: 14px;
}
.alert.err { background: rgba(255,59,48,.08); color: #c41e16; border: 1px solid rgba(255,59,48,.2); }
.alert.ok { background: rgba(52,199,89,.12); color: #1b7f3a; border: 1px solid rgba(52,199,89,.25); }
.alert.warn { background: rgba(255,149,0,.12); color: #9a5b00; border: 1px solid rgba(255,149,0,.25); }

.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--faint);
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
.data-table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.truncate {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.muted { color: var(--muted); font-size: 13px; }
.badge {
  display: inline-flex;
  padding: 3px 8px;
  border-radius: var(--pill);
  font-size: 11px;
  font-weight: 650;
  background: var(--blue-soft);
  color: var(--blue);
}
.badge.on { background: rgba(52,199,89,.14); color: #1b7f3a; }
.badge.off { background: rgba(0,0,0,.06); color: var(--muted); }
.actions { display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
.inline { display: inline; margin: 0; }
.link { font-weight: 600; font-size: 13px; }

.filter-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip {
  padding: 7px 12px;
  border-radius: var(--pill);
  background: rgba(0,0,0,.04);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}
.chip.on, .chip:hover { background: var(--blue-soft); color: var(--blue); text-decoration: none; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}
.content-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.content-card h3 { margin: 10px 0 6px; font-size: 15px; }

.ext-status { font-weight: 650; margin: 0 0 8px; }
.ext-status.on { color: #1b7f3a; }
.ext-status.off { color: var(--muted); }
.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.feature {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 13.5px;
  font-weight: 500;
}
.steps { color: var(--muted); padding-left: 1.2rem; }
.steps li { margin-bottom: 8px; }
.plain-list { color: var(--muted); padding-left: 1.2rem; }
.activity-feed { list-style: none; margin: 0; padding: 0; }
.activity-feed li {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13.5px;
}
.activity-feed li:last-child { border-bottom: none; }

.kv { margin: 0; }
.kv > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
.plan-badge {
  display: inline-block;
  font-size: 13px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--pill);
  background: var(--blue-soft);
  color: var(--blue);
  margin-bottom: 8px;
}
.plan-days { font-size: 22px; letter-spacing: -0.02em; }

.empty-card { text-align: center; padding: 40px 24px; }
.empty-card h2 { margin: 0 0 8px; }
.empty-inline { text-align: center; padding: 24px; }

@media (max-width: 1100px) {
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .sidebar {
    transform: translateX(-105%);
    transition: transform .2s ease;
  }
  .app.nav-open .sidebar { transform: translateX(0); }
  .main-wrap { margin-left: 0; width: 100%; }
  .menu-btn { display: inline-block; }
  .metric-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .hero h1 { font-size: 24px; }
}


/* —— fixes: missing components —— */
.side-nav { flex: 1; }
.plan-card { max-width: 480px; }
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.search-bar input[type="search"] {
  flex: 1;
  min-width: 180px;
  padding: 10px 12px;
  border: 1px solid rgba(0,0,0,.12);
  border-radius: 10px;
  font: inherit;
  font-size: 14px;
}
.search-bar input[type="search"]:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 4px var(--blue-soft);
}
.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 20px;
  flex-wrap: wrap;
}
.nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 35;
}
.app.nav-open .nav-backdrop {
  display: block;
}
@media (max-width: 860px) {
  .nav-backdrop:not([hidden]) { display: block; }
  .sidebar { z-index: 45; }
}
.status-chip::before {
  content: "";
}
button.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.nav-link { display: flex; align-items: center; gap: 10px; }
.nav-ico { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.9; }
.onboard {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.onboard h2 { margin: 0 0 6px; letter-spacing: -0.02em; }
.onboard-steps { margin: 18px 0 0; padding: 0; list-style: none; counter-reset: step; }
.onboard-steps li {
  counter-increment: step;
  position: relative;
  padding: 16px 16px 16px 52px;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fafafa;
}
.onboard-steps li::before {
  content: counter(step);
  position: absolute;
  left: 14px; top: 16px;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--blue-soft);
  color: var(--blue);
  font-weight: 700;
  font-size: 13px;
  display: grid; place-items: center;
}
.onboard-steps strong { display: block; margin-bottom: 4px; }
.onboard-steps p { margin: 0 0 10px; color: var(--muted); font-size: 14px; }
.type-cards legend { font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 8px; }
.type-choice { display: flex; flex-wrap: wrap; gap: 8px; }
.type-option {
  cursor: pointer;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  background: #fff;
  font-weight: 600;
  font-size: 13px;
}
.type-option input { margin-right: 6px; }
.type-option:has(input:checked) {
  border-color: var(--blue);
  background: var(--blue-soft);
  color: var(--blue);
}
.hint { display: block; margin-top: 6px; font-size: 12px; color: var(--faint); font-weight: 500; }
.hint.ok { color: #1b7f3a; }
.hint.err { color: #c41e16; }
.content-search { margin-bottom: 12px; }
