:root {
  --bg: #0f1117;
  --surface: #171b24;
  --surface-2: #1f2532;
  --border: #2a3242;
  --text: #e6ebf5;
  --muted: #8b96ad;
  --primary: #4f7cff;
  --primary-hover: #3d69eb;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.sm { font-size: 12px; }
.xs { font-size: 11px; }
.mt { margin-top: 16px; }
.full { width: 100%; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; }
.login-card h1 { margin: 12px 0 6px; font-size: 20px; }
.login-card form { margin-top: 18px; display: flex; flex-direction: column; gap: 10px; }
.error-text { color: var(--danger); font-size: 12px; margin-top: 10px; min-height: 16px; }

.brand-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, #4f7cff, #7c3aed);
  font-weight: 700; font-size: 13px; color: #fff;
}
.brand-badge.sm { width: 32px; height: 32px; font-size: 11px; }

/* Layout */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 216px; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px; flex-shrink: 0;
}
.sidebar-header { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; border-bottom: 1px solid var(--border); }
.brand-title { font-weight: 600; font-size: 15px; }
.nav { display: flex; flex-direction: column; gap: 4px; margin-top: 14px; flex: 1; }
.nav-item {
  text-align: left; background: transparent; border: none; color: var(--muted);
  padding: 10px 12px; border-radius: 8px; cursor: pointer; font-size: 13.5px;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: rgba(79,124,255,.16); color: #8ab0ff; font-weight: 600; }
.sidebar-footer { padding-top: 12px; border-top: 1px solid var(--border); }

.content { flex: 1; padding: 24px 28px; overflow-x: auto; max-width: 1320px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.page-head h2 { margin: 0 0 4px; font-size: 20px; }
.page-head p { margin: 0; }

/* Cards & Grids */
.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.card h3 { margin: 0 0 4px; font-size: 15px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }

.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 19px; font-weight: 600; margin-top: 6px; display: flex; align-items: center; gap: 8px; }

/* Subscriptions */
.sub-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px; margin-top: 10px; }
.sub-box {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 6px;
}
.sub-box-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.sub-title { font-weight: 600; font-size: 13px; }
.sub-url {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Controls */
label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 4px; }
input, select, textarea {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 7px; padding: 7px 10px; font-size: 13px; outline: none; width: 100%;
}
input[type="checkbox"] { width: auto; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); }

.btn {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 7px 13px; border-radius: 7px; cursor: pointer; font-size: 13px; white-space: nowrap;
}
.btn:hover { background: #2a3345; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { background: rgba(239,68,68,.15); border-color: rgba(239,68,68,.4); color: #fca5a5; }
.btn.danger:hover { background: rgba(239,68,68,.28); }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--muted); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form input, .inline-form select { width: auto; }
.stack { display: flex; flex-direction: column; gap: 12px; }

.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; margin-top: 6px; }
.table th, .table td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
.table th { color: var(--muted); font-weight: 500; font-size: 12px; }
.table input[type="text"] { width: 100%; min-width: 90px; }

/* Badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge.ok { background: rgba(34,197,94,.16); color: #4ade80; }
.badge.warn { background: rgba(245,158,11,.16); color: #fbbf24; }
.badge.bad { background: rgba(239,68,68,.16); color: #f87171; }
.badge.info { background: rgba(79,124,255,.16); color: #93b4ff; }

.code-box {
  background: #0a0c10; border: 1px solid var(--border); border-radius: 8px; padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; line-height: 1.5;
  overflow: auto; max-height: 300px; white-space: pre-wrap; word-break: break-all;
}
.code-box.tall { max-height: 380px; }
.editor { width: 100%; min-height: 340px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; line-height: 1.5; resize: vertical; }
.kv-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.kv-row { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid rgba(42,50,66,.5); font-size: 13px; }
.kv-key { color: var(--muted); }
.summary-title { cursor: pointer; font-weight: 600; font-size: 14px; color: var(--muted); }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.65); z-index: 900;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  width: 100%; max-width: 580px; max-height: 92vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px 22px;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* Toast */
.toast {
  position: fixed; top: 18px; right: 20px; z-index: 999; padding: 10px 16px;
  border-radius: 8px; font-size: 13px; background: var(--surface-2); border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0,0,0,.45); max-width: 440px; white-space: pre-wrap;
}
.toast.ok { border-color: var(--ok); color: #86efac; }
.toast.err { border-color: var(--danger); color: #fca5a5; }
