:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --muted: #6b7280;
  --subtle: #f3f4f6;
  --brand: #f38020;
  --primary: #c2410c;
  --primary-hover: #9a3412;
  --primary-soft: #fff4eb;
  --success: #15803d;
  --success-soft: #ecfdf3;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --warning: #a16207;
  --warning-soft: #fefce8;
  --info: #1d4ed8;
  --info-soft: #eff6ff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(17, 24, 39, 0.04), 0 1px 3px rgba(17, 24, 39, 0.06);
  --shadow-lg: 0 10px 30px rgba(17, 24, 39, 0.12);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
}

* { box-sizing: border-box; }
svg { width: 16px; height: 16px; flex-shrink: 0; }
.badge svg { width: 12px; height: 12px; }
.brand-mark svg { width: 18px; height: 18px; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.6; -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
code, .mono { font-family: var(--mono); font-size: 0.92em; }
h1, h2, h3, h4 { margin: 0; line-height: 1.3; }
p { margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.boot { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--brand); animation: spin 0.8s linear infinite; }
.spinner.sm { width: 14px; height: 14px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Layout ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 232px; flex-shrink: 0; background: var(--card); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 40; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 20px; font-weight: 700; font-size: 16px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--brand); display: grid; place-items: center; color: #fff; flex-shrink: 0; }
.nav { flex: 1; overflow-y: auto; padding: 4px 12px 16px; }
.nav-group { margin-top: 14px; }
.nav-label { font-size: 12px; color: var(--muted); padding: 0 10px 6px; font-weight: 500; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: #374151; font-weight: 500; }
.nav a:hover { background: var(--subtle); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.nav a svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-foot { border-top: 1px solid var(--border); padding: 12px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--subtle); display: grid; place-items: center; font-weight: 600; color: var(--muted); flex-shrink: 0; text-transform: uppercase; }
.user-chip .meta { min-width: 0; flex: 1; }
.user-chip .email { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; align-items: center; justify-content: space-between; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30; }
.content { padding: 28px 32px 48px; max-width: 1160px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; font-weight: 650; }
.page-head p { color: var(--muted); margin-top: 4px; }
.backdrop { display: none; }

@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform 0.2s ease; box-shadow: var(--shadow-lg); }
  .shell.nav-open .sidebar { transform: translateX(0); }
  .shell.nav-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(17, 24, 39, 0.35); z-index: 35; }
  .topbar { display: flex; }
  .content { padding: 18px 14px 40px; }
}

/* ---------- Components ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head h2, .card-head h3 { font-size: 15px; font-weight: 600; }
.card-body { padding: 20px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.between { justify-content: space-between; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1000px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-3 { grid-template-columns: 1fr; } }
@media (max-width: 640px) { .grid-2, .grid-4 { grid-template-columns: 1fr; } }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.grow { flex: 1; min-width: 0; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }

.btn { display: inline-flex; vertical-align: middle; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--card); font-weight: 500; cursor: pointer; white-space: nowrap; transition: background 0.15s, border-color 0.15s; color: var(--text); }
.btn:hover { background: var(--subtle); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-solid:hover { background: #991b1b; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 7px; }
.btn-icon { width: 34px; padding: 0; }
.btn-block { width: 100%; height: 40px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .label { font-weight: 500; font-size: 13px; }
.hint { font-size: 12.5px; color: var(--muted); }
.input, .select, .textarea { width: 100%; height: 38px; border: 1px solid var(--border-strong); border-radius: 8px; padding: 0 12px; background: #fff; transition: border-color 0.15s, box-shadow 0.15s; }
.textarea { height: auto; min-height: 88px; padding: 10px 12px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(243, 128, 32, 0.18); }
.input-group { display: flex; align-items: stretch; }
.input-group .input { border-radius: 8px 0 0 8px; }
.input-group .addon { display: flex; align-items: center; padding: 0 12px; border: 1px solid var(--border-strong); border-left: 0; background: var(--subtle); border-radius: 0 8px 8px 0; color: var(--muted); white-space: nowrap; font-family: var(--mono); font-size: 13px; }
.input-group .btn { border-radius: 0 8px 8px 0; border-left: 0; height: 38px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }
.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.switch input { appearance: none; width: 36px; height: 20px; background: var(--border-strong); border-radius: 999px; position: relative; cursor: pointer; transition: background 0.15s; margin: 0; flex-shrink: 0; }
.switch input::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform 0.15s; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2); }
.switch input:checked { background: var(--success); }
.switch input:checked::after { transform: translateX(16px); }
fieldset { border: 0; padding: 0; margin: 0; }
details summary { cursor: pointer; font-weight: 500; color: var(--muted); }

.badge { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--subtle); color: #374151; white-space: nowrap; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-brand { background: var(--primary-soft); color: var(--primary); }
.tier-0 { background: var(--subtle); color: #374151; }
.tier-1 { background: var(--info-soft); color: var(--info); }
.tier-2 { background: #fdf4ff; color: #a21caf; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12.5px; font-weight: 500; color: var(--muted); background: #fafafa; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fcfcfd; }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn + .btn { margin-left: 4px; }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty svg { width: 40px; height: 40px; color: var(--border-strong); margin-bottom: 8px; }
.empty h3 { color: var(--text); font-size: 15px; margin-bottom: 4px; }

.stat { padding: 18px 20px; }
.stat .label { color: var(--muted); font-weight: 400; }
.stat .value { font-size: 26px; font-weight: 650; margin-top: 4px; letter-spacing: -0.02em; }
.stat .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

.progress { height: 6px; background: var(--subtle); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.progress.full > span { background: var(--danger); }

.alert { display: flex; gap: 10px; padding: 12px 14px; border-radius: 8px; border: 1px solid; font-size: 13.5px; }
.alert svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.alert-info { background: var(--info-soft); border-color: #bfdbfe; color: #1e3a8a; }
.alert-warning { background: var(--warning-soft); border-color: #fde68a; color: #713f12; }
.alert-success { background: var(--success-soft); border-color: #bbf7d0; color: #14532d; }
.alert-danger { background: var(--danger-soft); border-color: #fecaca; color: #7f1d1d; }

.tabs { display: flex; gap: 4px; box-shadow: inset 0 -1px 0 var(--border); margin-bottom: 16px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; min-width: 0; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex-shrink: 0; background: none; border: 0; padding: 10px 12px; cursor: pointer; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }
.card-head-tabs { padding-top: 0; padding-bottom: 0; align-items: stretch; }
.card-head-tabs .tabs { margin: 0; box-shadow: none; }
.card-head-tabs .tabs button { padding: 16px 12px 14px; }
.card-head-tabs > form { padding: 10px 0; }

.pager { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-top: 1px solid var(--border); gap: 10px; flex-wrap: wrap; }

.kv { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }

.choice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.choice { position: relative; display: flex; flex-direction: column; gap: 4px; padding: 14px; border: 1px solid var(--border-strong); border-radius: 10px; cursor: pointer; background: #fff; transition: border-color 0.15s, box-shadow 0.15s; }
.choice:hover { border-color: var(--brand); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice:has(input:checked) { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(243, 128, 32, 0.16); background: var(--primary-soft); }
.choice:has(input:focus-visible) { outline: 2px solid var(--brand); outline-offset: 2px; }
.choice.locked { cursor: not-allowed; background: var(--subtle); opacity: 0.75; }
.choice .name { font-weight: 600; font-family: var(--mono); word-break: break-all; }

.plan-card { display: flex; flex-direction: column; padding: 22px; gap: 14px; position: relative; }
.plan-card.current { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(243, 128, 32, 0.12); }
.plan-card .price { font-size: 22px; font-weight: 700; }
.plan-card ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.plan-card li { display: flex; gap: 8px; align-items: flex-start; }
.plan-card li svg { width: 16px; height: 16px; color: var(--success); flex-shrink: 0; margin-top: 3px; }

.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; background: radial-gradient(1200px 500px at 50% -10%, #ffedd5 0%, rgba(255, 237, 213, 0) 60%), var(--bg); }
.auth-card { width: 100%; max-width: 400px; padding: 32px 28px; }
.auth-card .brand { padding: 0 0 20px; justify-content: center; font-size: 18px; }
.auth-card h1 { font-size: 20px; text-align: center; }
.auth-card .lead { text-align: center; color: var(--muted); margin-top: 6px; margin-bottom: 22px; }
.auth-foot { text-align: center; margin-top: 18px; color: var(--muted); font-size: 13.5px; }

.toasts { position: fixed; top: 16px; right: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 32px); }
.toast { display: flex; gap: 10px; align-items: flex-start; background: #111827; color: #fff; padding: 11px 14px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 13.5px; max-width: 380px; animation: toast-in 0.18s ease; }
.toast svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.toast.success svg { color: #4ade80; }
.toast.error svg { color: #f87171; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } }

.modal-overlay { position: fixed; inset: 0; background: rgba(17, 24, 39, 0.45); z-index: 80; display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px 16px; overflow-y: auto; animation: fade 0.15s ease; }
@keyframes fade { from { opacity: 0; } }
.modal { width: 100%; max-width: 480px; background: #fff; border-radius: 12px; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; max-height: 84vh; }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 16px; font-weight: 600; }
.modal-body { padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: #fafafa; border-radius: 0 0 12px 12px; }

.dropdown { position: relative; display: inline-block; }
.menu { position: fixed; min-width: 160px; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 4px; z-index: 50; display: none; text-align: left; }
.dropdown.open .menu { display: block; }
.menu button { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; background: none; border: 0; border-radius: 6px; cursor: pointer; text-align: left; }
.menu button:hover { background: var(--subtle); }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }

.code-box { font-family: var(--mono); background: var(--subtle); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; word-break: break-all; font-size: 13px; }
.mail-item { display: flex; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer; background: #fff; width: 100%; border-left: 0; border-right: 0; border-top: 0; text-align: left; }
.mail-item:hover { background: #fcfcfd; }
.mail-item.unread .subj { font-weight: 650; }
.mail-item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); margin-top: 7px; flex-shrink: 0; }
.mail-item:not(.unread) .dot { background: transparent; }
.mail-frame { width: 100%; min-height: 50vh; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.checklist li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px dashed var(--border); }
.checklist li:last-child { border-bottom: 0; }
.checklist { list-style: none; padding: 0; margin: 0; }
.check-ok { color: var(--success); }
.check-no { color: var(--muted); }
.checklist svg { width: 18px; height: 18px; }
.announce { white-space: pre-wrap; }
.hero { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 22px; flex-wrap: wrap; background: linear-gradient(120deg, #fff7ed, #ffffff 60%); }
.hero h2 { font-size: 18px; }
