/* SuperRouter Console — Alibaba Cloud / Model Studio-inspired theme */
:root {
  --blue: #326BFF;
  --blue-dark: #2456d6;
  --blue-light: #eaf0ff;
  --bg: #F5F7FA;
  --card-bg: #ffffff;
  --border: #e6e9f0;
  --border-strong: #d4d9e3;
  --text: #1f2a3d;
  --text-2: #5b6478;
  --text-3: #8a93a8;
  --green: #1a9e54;
  --green-bg: #e7f7ee;
  --red: #e5484d;
  --red-bg: #fdeeee;
  --orange: #e8890c;
  --orange-bg: #fdf3e3;
  --gray-bg: #f0f2f6;
  --radius: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
          "Microsoft YaHei", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
}
.hidden { display: none !important; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Views ---------- */
.view { min-height: 100vh; }

/* ---------- Login / tenant picker ---------- */
#login-view, #tenant-picker-view {
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: var(--shadow);
  width: 400px; max-width: 100%; padding: 36px 32px;
}
.login-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.logo-mark {
  width: 34px; height: 34px; border-radius: 8px;
  background: linear-gradient(135deg, var(--blue), #5b8cff);
  color: #fff; font-weight: 700; font-size: 18px;
  display: inline-flex; align-items: center; justify-content: center;
}
.logo-text { font-size: 17px; font-weight: 600; }
.login-sub { color: var(--text-2); margin: 0 0 22px; font-size: 13px; }
.field-label { display: block; font-weight: 500; margin: 0 0 6px; }
.input, .select, .textarea {
  width: 100%; padding: 8px 10px; font-size: 13px; font-family: var(--font);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: #fff; color: var(--text);
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue-light);
}
.textarea { resize: vertical; }
.form-error { color: var(--red); font-size: 12px; margin: 8px 0 0; }
.dev-note { color: var(--text-2); font-size: 12px; margin: 0 0 10px; }
.dev-token-box {
  border: 1px dashed var(--blue); background: var(--blue-light);
  border-radius: var(--radius); padding: 12px; margin-bottom: 14px;
}
.dev-token-label { display: block; font-size: 11px; color: var(--text-2); margin-bottom: 4px; }
.dev-token-link { font-family: var(--mono); font-size: 12px; word-break: break-all; }
.tenant-list { display: flex; flex-direction: column; gap: 8px; }
.tenant-btn {
  text-align: left; padding: 12px 14px; border: 1px solid var(--border);
  border-radius: var(--radius); background: #fff; cursor: pointer; font-family: var(--font);
}
.tenant-btn:hover { border-color: var(--blue); background: var(--blue-light); }
.tenant-btn .t-name { display: block; font-weight: 600; font-size: 14px; }
.tenant-btn .t-meta { display: block; color: var(--text-2); font-size: 12px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; font-size: 13px; font-family: var(--font); font-weight: 500;
  border-radius: var(--radius); border: 1px solid transparent; cursor: pointer;
  white-space: nowrap;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-default { background: #fff; border-color: var(--border-strong); color: var(--text); }
.btn-default:hover { border-color: var(--blue); color: var(--blue); }
.btn-danger { background: #fff; border-color: var(--border-strong); color: var(--red); }
.btn-danger:hover { border-color: var(--red); background: var(--red-bg); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { color: var(--blue); }
.btn-block { width: 100%; margin-top: 14px; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.link-btn { background: none; border: none; color: var(--blue); cursor: pointer; font-size: 12px; padding: 0; font-family: var(--font); }
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--red); }

/* ---------- Console shell ---------- */
#console-shell { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
#topbar {
  height: 52px; background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; flex-shrink: 0; z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-left .logo-mark { width: 28px; height: 28px; font-size: 15px; }
.topbar-left .logo-text { font-size: 15px; }
.topbar-divider { width: 1px; height: 22px; background: var(--border); }
.ws-switcher { position: relative; }
.ws-btn {
  display: flex; align-items: center; gap: 6px;
  background: none; border: none; cursor: pointer; font-family: var(--font);
  font-size: 13px; font-weight: 500; color: var(--text); padding: 6px 8px; border-radius: var(--radius);
}
.ws-btn:hover { background: var(--gray-bg); }
.chevron { font-size: 10px; color: var(--text-3); }
.dropdown {
  position: absolute; top: calc(100% + 6px); left: 0; min-width: 220px;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(16, 24, 40, .12); z-index: 100; padding: 4px;
}
.dropdown-right { left: auto; right: 0; }
.dropdown-item {
  display: block; width: 100%; text-align: left; padding: 8px 10px;
  border: none; background: none; cursor: pointer; border-radius: 4px;
  font-family: var(--font); font-size: 13px; color: var(--text);
}
.dropdown-item:hover { background: var(--blue-light); }
.dropdown-item.active { color: var(--blue); font-weight: 600; }
.dropdown-item .sub { display: block; font-size: 11px; color: var(--text-3); font-weight: 400; }
.dropdown-sep { height: 1px; background: var(--border); margin: 4px 0; }
.dropdown-header { padding: 6px 10px; font-size: 11px; color: var(--text-3); }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.tenant-name { font-size: 13px; color: var(--text-2); }
.user-menu-wrap { position: relative; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--blue); color: #fff; font-weight: 600; font-size: 13px;
  font-family: var(--font);
}

.shell-body { display: flex; flex: 1; min-height: 0; }
#sidebar {
  width: 200px; background: #fff; border-right: 1px solid var(--border);
  flex-shrink: 0; padding: 12px 8px; overflow-y: auto;
}
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 12px; margin-bottom: 2px; border: none; background: none;
  border-radius: var(--radius); cursor: pointer; font-family: var(--font);
  font-size: 13px; color: var(--text-2); text-align: left;
  border-left: 3px solid transparent;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-item:hover { background: var(--gray-bg); color: var(--text); }
.nav-item.active { background: var(--blue-light); color: var(--blue); font-weight: 600; border-left-color: var(--blue); border-radius: 0 var(--radius) var(--radius) 0; }

#main { flex: 1; overflow-y: auto; padding: 16px 20px 40px; min-width: 0; }
.breadcrumb { font-size: 12px; color: var(--text-3); margin-bottom: 12px; }
.breadcrumb .crumb-sep { margin: 0 6px; }
.breadcrumb .crumb-current { color: var(--text-2); }
.page-title-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.page-title { font-size: 17px; font-weight: 600; margin: 0; }
.page-sub { color: var(--text-2); font-size: 12px; margin: 2px 0 0; }

/* ---------- Cards ---------- */
.card {
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 16px;
}
.card-title { font-size: 14px; font-weight: 600; margin: 0 0 12px; }
.card-title-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-title-row .card-title { margin: 0; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
.stat-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.stat-label { font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.stat-value { font-size: 24px; font-weight: 600; letter-spacing: -.5px; }
.stat-value.blue { color: var(--blue); }
.stat-value.green { color: var(--green); }
.stat-hint { font-size: 11px; color: var(--text-3); margin-top: 4px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.data th {
  text-align: left; font-weight: 600; color: var(--text-2); font-size: 12px;
  padding: 8px 10px; border-bottom: 1px solid var(--border); background: #fafbfd;
  white-space: nowrap;
}
table.data td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: #fafbfd; }
.mono { font-family: var(--mono); font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
th.num { text-align: right; }
.pill {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 500; white-space: nowrap;
}
.pill.green { background: var(--green-bg); color: var(--green); }
.pill.gray { background: var(--gray-bg); color: var(--text-2); }
.pill.orange { background: var(--orange-bg); color: var(--orange); }
.pill.red { background: var(--red-bg); color: var(--red); }
.pill.blue { background: var(--blue-light); color: var(--blue); }
.role-select { padding: 4px 6px; font-size: 12px; width: auto; }
.budget-bar { height: 5px; background: var(--gray-bg); border-radius: 3px; margin-top: 5px; min-width: 90px; }
.budget-bar > span { display: block; height: 100%; border-radius: 3px; background: var(--blue); }
.budget-bar.over > span { background: var(--red); }

/* ---------- Empty state ---------- */
.empty-state {
  border: 1px dashed var(--border-strong); border-radius: var(--radius);
  padding: 36px 20px; text-align: center; color: var(--text-2);
}
.empty-state .empty-icon { font-size: 28px; margin-bottom: 8px; }
.empty-state p { margin: 0 0 12px; }

/* ---------- Filters ---------- */
.filter-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-group label { font-size: 11px; color: var(--text-2); font-weight: 500; }
.filter-group .input, .filter-group .select { width: 170px; }
.chart-wrap { position: relative; width: 100%; }
canvas.chart { width: 100%; height: 220px; display: block; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 10px; font-size: 12px; color: var(--text-2); }

/* ---------- Modal ---------- */
#modal-root .modal-overlay {
  position: fixed; inset: 0; background: rgba(16, 24, 40, .45);
  display: flex; align-items: center; justify-content: center; z-index: 200; padding: 20px;
}
.modal {
  background: #fff; border-radius: 8px; width: 520px; max-width: 100%;
  max-height: 90vh; overflow-y: auto; box-shadow: 0 12px 40px rgba(16, 24, 40, .25);
}
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 15px; font-weight: 600; margin: 0; }
.modal-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text-3); line-height: 1; }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.form-row { margin-bottom: 14px; }
.form-row .hint { font-size: 11px; color: var(--text-3); margin-top: 4px; }
.form-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* raw key reveal */
.rawkey-box {
  background: #0f172a; color: #e2e8f0; border-radius: var(--radius);
  padding: 14px 16px; font-family: var(--mono); font-size: 13px;
  word-break: break-all; margin: 12px 0; position: relative;
}
.rawkey-warning {
  background: var(--orange-bg); border: 1px solid #f0c979; color: #8a5a00;
  border-radius: var(--radius); padding: 10px 12px; font-size: 12px; margin-bottom: 6px;
}

/* ---------- Toast ---------- */
#toast-root { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: #1f2a3d; color: #fff; padding: 10px 18px; border-radius: var(--radius);
  font-size: 13px; box-shadow: 0 4px 16px rgba(0,0,0,.25); animation: toast-in .18s ease-out;
}
.toast.error { background: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Billing ---------- */
.balance-hero { font-size: 32px; font-weight: 700; letter-spacing: -.5px; margin: 4px 0 2px; }
.soon-note {
  background: var(--gray-bg); border-radius: var(--radius);
  padding: 14px 16px; color: var(--text-2); font-size: 12.5px; margin-top: 14px;
}
.inline-row { display: flex; align-items: center; gap: 10px; }
.mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mb-0 { margin-bottom: 0; }
.muted { color: var(--text-2); } .small { font-size: 12px; }

@media (max-width: 900px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  #sidebar { width: 64px; }
  .nav-item span.nav-label { display: none; }
  .nav-item { justify-content: center; border-left: none; }
}

/* ---------- login tabs ---------- */
.login-tabs { display: flex; gap: 4px; margin: 0 0 16px; background: var(--bg); border-radius: 8px; padding: 4px; }
.login-tab { flex: 1; border: none; background: none; padding: 8px; font-size: 13px; font-weight: 600; color: var(--text-3); border-radius: 6px; cursor: pointer; }
.login-tab.active { background: #fff; color: var(--text-1); box-shadow: 0 1px 2px rgba(16,24,40,.08); }
.form-hint { font-size: 12px; color: var(--text-3); margin: 8px 0 0; }

/* ---------- onboarding wizard ---------- */
.ob-steps { display: flex; gap: 6px; margin-bottom: 18px; }
.ob-dot { flex: 1; height: 4px; border-radius: 2px; background: var(--border); }
.ob-dot.done { background: var(--accent); }
.ob-hero { font-size: 16px; font-weight: 700; margin: 0 0 8px; }
.ob-sub { font-size: 13px; color: var(--text-2); margin: 0 0 16px; line-height: 1.55; }
.ob-curl { background: #0b1220; color: #d7e3f4; border-radius: 8px; padding: 14px; font-family: ui-monospace, monospace; font-size: 12px; line-height: 1.6; overflow-x: auto; white-space: pre; margin: 0 0 12px; }
.ob-actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 18px; }
.ob-check { display: flex; gap: 10px; align-items: flex-start; background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 8px; padding: 12px; font-size: 13px; margin-top: 12px; }

/* ---------- growth page ---------- */
.gw-refcard { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.gw-refcard .card-title { margin-bottom: 4px; }
.gw-refrow { display: flex; align-items: center; gap: 10px; }
.gw-refcode { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 16px; font-weight: 700; letter-spacing: 1px; background: var(--blue-light); color: var(--blue); padding: 8px 14px; border-radius: 8px; }
.gw-head-right { display: flex; align-items: center; gap: 12px; }
.gw-fields { margin-top: 12px; display: grid; gap: 12px; }
.gw-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.gw-field .field-label { margin-bottom: 4px; }
.gw-money { display: flex; align-items: center; gap: 6px; }
.gw-money > span { color: var(--text-2); font-size: 13px; font-weight: 600; }
.gw-money .input { width: 130px; }
.gw-tiers { display: grid; gap: 8px; }
.gw-tier { display: flex; align-items: flex-end; gap: 10px; }
.gw-tier .gw-money .input { width: 110px; }
.gw-tier-rm { flex-shrink: 0; }
.gw-actions { display: flex; gap: 8px; margin-top: 14px; }
.gw-card .card-title-row { align-items: flex-start; }

/* toggle switch */
.gw-switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; cursor: pointer; }
.gw-switch input { opacity: 0; width: 0; height: 0; }
.gw-slider { position: absolute; inset: 0; background: var(--border-strong); border-radius: 22px; transition: background .2s; }
.gw-slider:before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .2s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.gw-switch input:checked + .gw-slider { background: var(--blue); }
.gw-switch input:checked + .gw-slider:before { transform: translateX(18px); }
.gw-switch input:disabled + .gw-slider { opacity: .5; cursor: not-allowed; }

/* billing top-up row */
.gw-topup-row { display: flex; align-items: center; gap: 10px; }

/* ---------- Impersonation banner (read-only customer view) ---------- */
.imp-banner {
  position: fixed; top: 0; left: 0; right: 0; height: 44px; z-index: 2000;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 16px; background: #f59e0b; color: #1f2937;
  font-size: 13px; font-weight: 500;
}
.imp-banner .btn {
  background: #1f2937; color: #fff; border: 0; padding: 6px 10px;
  border-radius: 6px; cursor: pointer; font-size: 12px;
}
body.has-imp-banner #console-shell {
  margin-top: 44px; height: calc(100vh - 44px);
}
body.has-imp-banner #login-view,
body.has-imp-banner #tenant-picker-view { padding-top: 68px; }

/* ---------- Usage Analytics additions ---------- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }
tr.drill { cursor: pointer; }
tr.drill:hover { background: rgba(50, 107, 255, 0.06); }
