:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  --accent: #d97706;
  --success: #15803d;
  --success-soft: #ecfdf3;
  --danger: #dc2626;
  --danger-soft: #fff1f2;
  --warning: #b45309;
  --warning-soft: #fffbeb;
  --sidebar: #0f172a;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --background: #f3f6fb;
  --text: #172033;
  --text-muted: #64748b;
  --border: #dfe6f0;
  --border-strong: #cbd5e1;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04), 0 5px 16px rgba(15, 23, 42, .035);
  --shadow-md: 0 18px 45px rgba(15, 23, 42, .1);
  font-family: "Segoe UI Variable", "Segoe UI", "Microsoft YaHei UI", "PingFang SC", sans-serif;
  color: var(--text);
  background: var(--background);
}

html { background: var(--background); }
body { color: var(--text); background: var(--background); }
button, input, select { font: inherit; }
button { transition: color .18s ease, background-color .18s ease, border-color .18s ease, box-shadow .18s ease, opacity .18s ease; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(37, 99, 235, .22); outline-offset: 2px; }
button:disabled { cursor: not-allowed; opacity: .58; }

.login-shell { grid-template-columns: minmax(390px, 44%) minmax(0, 1fr); background: #fff; }
.login-brand {
  position: relative;
  overflow: hidden;
  padding: 58px clamp(42px, 5vw, 82px);
  background:
    radial-gradient(circle at 18% 14%, rgba(96, 165, 250, .35), transparent 30%),
    radial-gradient(circle at 85% 86%, rgba(37, 99, 235, .34), transparent 34%),
    linear-gradient(145deg, #0f2f75 0%, #174fb4 56%, #2563eb 100%);
}
.login-brand::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: .16;
  background-image: linear-gradient(rgba(255,255,255,.2) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.2) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(to bottom, #000, transparent 78%);
}
.login-brand > * { position: relative; z-index: 1; }
.brand-mark { border-radius: 15px; background: rgba(255,255,255,.15); box-shadow: inset 0 0 0 1px rgba(255,255,255,.16), 0 16px 40px rgba(3, 18, 55, .22); }
.login-copy h2 { max-width: 560px; font-size: 38px; line-height: 1.3; }
.login-copy li { color: rgba(255,255,255,.9); }
.login-form-wrap { background: #fff; }
.login-card { width: min(430px, 100%); padding: 38px; border-radius: 20px; box-shadow: var(--shadow-md); }
.login-card h2 { letter-spacing: 0; }
.login-card input { min-height: 46px; }
.login-card .primary { min-height: 46px; margin-top: 4px; }

.app-shell { grid-template-columns: 248px minmax(0, 1fr); }
.sidebar {
  width: 248px;
  padding: 24px 16px 18px;
  background: linear-gradient(180deg, #101a31 0%, #0f172a 54%, #0b1221 100%);
  box-shadow: 12px 0 36px rgba(15, 23, 42, .08);
}
.sidebar-brand { padding: 0 10px 26px; }
.sidebar-brand strong { font-size: 15px; letter-spacing: .01em; }
.sidebar-brand span { color: #7f8da8; font-size: 10px; letter-spacing: .06em; }
.sidebar nav { gap: 6px; }
.sidebar nav button {
  min-height: 46px;
  padding: 0 13px;
  gap: 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  color: #aab6ca;
  font-size: 13px;
  font-weight: 650;
}
.sidebar nav button:hover { color: #f8fafc; background: rgba(255,255,255,.06); border-color: rgba(255,255,255,.04); }
.sidebar nav button.active { color: #fff; background: linear-gradient(135deg, #2563eb, #1d4ed8); border-color: rgba(147,197,253,.25); box-shadow: 0 10px 24px rgba(0, 67, 191, .3); }
.sidebar nav button > .nav-icon {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: currentColor;
  background: rgba(255,255,255,.05);
}
.sidebar nav button.active > .nav-icon { color: #1d4ed8; background: #fff; }
.nav-icon svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sidebar nav button:first-child .nav-icon svg { fill: currentColor; stroke: none; }
.sidebar-foot { margin: auto 5px 0; padding: 16px 10px 2px; }
.sidebar-foot strong { color: #dbeafe; }

.workspace { min-width: 0; background: var(--background); }
.topbar {
  min-height: 88px;
  padding: 18px clamp(24px, 3vw, 42px);
  position: sticky;
  top: 0;
  z-index: 15;
  border-color: rgba(203, 213, 225, .75);
  background: rgba(255, 255, 255, .92);
  box-shadow: 0 1px 0 rgba(15, 23, 42, .02);
}
.topbar h1 { font-size: 23px; letter-spacing: 0; }
.topbar > div > span { color: var(--text-muted); }
.top-actions { gap: 10px; }
.top-actions .ghost, .top-actions .text-button { min-height: 40px; }
.admin-chip { border-radius: 11px; box-shadow: var(--shadow-sm); }
.admin-chip > span { border-radius: 9px; background: linear-gradient(135deg, #2563eb, #1e40af); }

.page { padding: 28px clamp(24px, 3vw, 42px) 64px; }
.page.active { animation: page-in .2s ease-out; }
.metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.metric {
  position: relative;
  overflow: hidden;
  min-height: 132px;
  padding: 20px;
  border-color: var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.metric::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: #94a3b8; }
.metric[data-tone="primary"]::before { background: var(--primary); }
.metric[data-tone="success"]::before { background: var(--success); }
.metric[data-tone="danger"]::before { background: var(--danger); }
.metric[data-tone="warning"]::before { background: var(--warning); }
.metric span { color: var(--text-muted); font-size: 12px; font-weight: 650; }
.metric strong { margin-top: 14px; color: var(--text); font-size: 30px; line-height: 1; letter-spacing: -.035em; font-variant-numeric: tabular-nums; }
.metric small { margin-top: 10px; color: #8b98aa; font-size: 11px; }
.metric[data-tone="primary"] strong { color: var(--primary-dark); }
.metric[data-tone="success"] strong { color: var(--success); }
.metric[data-tone="danger"] strong { color: var(--danger); }

.panel {
  padding: 22px;
  border-color: var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.panel h2 { color: var(--text); font-size: 18px; letter-spacing: 0; }
.panel-head { margin-bottom: 18px; }
.panel-head p, .issue-panel p { max-width: 760px; color: var(--text-muted); line-height: 1.65; }
.section-tag { color: var(--primary); letter-spacing: .12em; }
.data-meta { min-height: 34px; margin: 7px 2px 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.data-meta span:last-child { text-align: right; }
.data-note { margin: 13px 0 0; color: var(--text-muted); font-size: 11px; line-height: 1.6; }
.overview-grid { grid-template-columns: minmax(0, 1.25fr) minmax(320px, .75fr); gap: 14px; margin-top: 14px; }
.section-gap { margin-top: 14px; }
.alert-item { min-height: 48px; padding: 12px 14px; border-color: #e8edf4; border-radius: 10px; background: #fbfcfe; }
.alert-item strong { min-width: 32px; text-align: center; color: var(--primary-dark); font-variant-numeric: tabular-nums; }
.health-line { min-height: 44px; }
.health-line strong { color: var(--text); }

input, select {
  min-height: 44px;
  border-color: var(--border-strong);
  border-radius: 9px;
  color: var(--text);
  background: #fff;
}
input:hover, select:hover { border-color: #94a3b8; }
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .13); }
.primary, .ghost, .text-button { min-height: 42px; border-radius: 9px; }
.primary { border-color: var(--primary); background: linear-gradient(135deg, var(--primary), var(--primary-dark)); box-shadow: 0 8px 18px rgba(37, 99, 235, .19); }
.primary:hover { box-shadow: 0 10px 24px rgba(37, 99, 235, .27); }
.ghost { border-color: var(--border-strong); color: #40506a; background: #fff; }
.ghost:hover { border-color: #93b4f6; color: var(--primary-dark); background: var(--primary-soft); }

.table-wrap { border: 1px solid var(--border); border-radius: 12px; background: #fff; }
table { min-width: 920px; }
th, td { padding: 13px 12px; }
th { position: sticky; top: 0; z-index: 2; color: #6f7c90; background: #f8fafc; letter-spacing: .05em; }
tbody tr { transition: background-color .15s ease; }
tbody tr:hover { background: #f8fbff; }
td { color: #43506a; }
td strong { color: var(--text); }
.subtext { color: #8793a6; font-size: 10px; line-height: 1.45; }
.data-number { font-size: 16px; font-variant-numeric: tabular-nums; }
.primary-number { color: var(--primary-dark); }
.change-pair { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 750; font-variant-numeric: tabular-nums; }
.change-pair span { min-width: 34px; padding: 4px 7px; border-radius: 7px; text-align: center; }
.change-add { color: var(--success); background: var(--success-soft); }
.change-delete { color: var(--danger); background: var(--danger-soft); }
.badge { min-height: 25px; font-weight: 750; }
.badge.success { color: #166534; background: #dcfce7; }
.badge.warning { color: #92400e; background: #fef3c7; }
.badge.danger { color: #991b1b; background: #fee2e2; }
.badge.neutral { color: #475569; background: #eef2f7; }
.mini { min-height: 32px; border-radius: 7px; }
.mini:hover { border-color: #9ab5e9; color: var(--primary-dark); background: var(--primary-soft); }
.mini.danger:hover { color: #991b1b; border-color: #f2aaaa; background: var(--danger-soft); }

.usage-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(360px, .65fr); gap: 14px; margin-top: 14px; }
.privacy-pill { padding: 8px 11px; border: 1px solid #bfdbfe; border-radius: 999px; color: #1d4ed8; background: #eff6ff; font-size: 11px; font-weight: 750; white-space: nowrap; }
.trend-chart { height: 310px; padding: 20px 10px 4px; display: grid; grid-template-columns: repeat(7, minmax(54px, 1fr)); gap: 10px; align-items: end; border-top: 1px solid #edf1f6; }
.trend-chart.compact { height: 220px; padding-top: 12px; }
.trend-column { min-width: 0; height: 100%; display: grid; grid-template-rows: minmax(0, 1fr) auto auto auto; gap: 5px; align-items: end; text-align: center; }
.trend-chart.compact .trend-column { grid-template-rows: minmax(0, 1fr) auto auto; }
.trend-bars { height: 100%; min-height: 80px; display: flex; justify-content: center; align-items: end; gap: 4px; border-bottom: 1px solid #dbe3ee; background: repeating-linear-gradient(to top, transparent 0, transparent 24%, rgba(226,232,240,.65) 25%); }
.trend-bars i { width: min(18px, 28%); min-height: 2px; display: block; border-radius: 5px 5px 2px 2px; transition: opacity .18s ease; }
.trend-bars i.orders { background: linear-gradient(180deg, #60a5fa, #2563eb); }
.trend-bars i.adds { background: linear-gradient(180deg, #4ade80, #15803d); }
.trend-bars i.deletes { background: linear-gradient(180deg, #fb7185, #dc2626); }
.trend-column:hover .trend-bars i { opacity: .78; }
.trend-column strong { color: var(--text); font-size: 13px; font-variant-numeric: tabular-nums; }
.trend-column span { color: var(--text-muted); font-size: 10px; }
.trend-breakdown { color: var(--text-muted); font-size: 9px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 14px; margin: -2px 0 14px; color: #526078; font-size: 11px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 7px; }
.chart-legend i { width: 9px; height: 9px; display: inline-block; border-radius: 3px; }
.chart-legend i.orders { background: #2563eb; }
.chart-legend i.adds { background: #15803d; }
.chart-legend i.deletes { background: #dc2626; }
.usage-events { max-height: 410px; display: grid; gap: 8px; overflow: auto; padding-right: 3px; }
.usage-event { min-height: 68px; padding: 12px; display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; gap: 11px; align-items: center; border: 1px solid #e8edf4; border-radius: 10px; background: #fbfcfe; }
.usage-event-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 9px; color: var(--success); background: var(--success-soft); font-size: 20px; font-weight: 800; }
.usage-event[data-kind="delete"] .usage-event-icon { color: var(--danger); background: var(--danger-soft); }
.usage-event strong { display: block; font-size: 12px; }
.usage-event p { margin: 5px 0 0; color: var(--text-muted); font-size: 11px; }
.usage-event time { color: #8a96a8; font-size: 10px; white-space: nowrap; }

.two-column { grid-template-columns: minmax(320px, 380px) minmax(0, 1fr); align-items: start; }
.two-column > *, .form-grid > *, .issue-form > * { min-width: 0; }
.form-grid { grid-template-columns: minmax(0, 1fr); }
.form-grid input, .form-grid select, .form-grid button, .issue-form input, .issue-form select { width: 100%; min-width: 0; }
.plan-card { border-radius: 12px; background: #fbfcfe; transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease; }
.plan-card:hover { border-color: #bfd1f1; box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.issue-panel { grid-template-columns: minmax(0, 1fr) minmax(430px, auto); }
.issue-form { display: grid; grid-template-columns: minmax(220px, 1fr) 110px auto; align-items: end; gap: 8px; }
.issued strong { display: block; margin-bottom: 10px; font-family: inherit; }
.issued pre { max-height: 300px; margin: 0; overflow: auto; white-space: pre-wrap; line-height: 1.75; }
.code-cell { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.audit-item { border-radius: 10px; }

.action-dialog {
  inset: 0;
  width: min(480px, calc(100% - 32px));
  max-height: calc(100dvh - 32px);
  margin: auto;
  overflow: visible;
  border: 1px solid rgba(220, 226, 238, .9);
  border-radius: 18px;
  box-shadow: 0 30px 90px rgba(15, 23, 42, .28);
}
.action-dialog::backdrop { background: rgba(15, 23, 42, .54); backdrop-filter: blur(4px); }
.action-dialog-card { position: relative; gap: 0; padding: 30px; text-align: center; }
.action-dialog-symbol { width: 52px; height: 52px; margin: 0 auto 18px; display: grid; place-items: center; border-radius: 16px; color: var(--primary); background: #edf4ff; box-shadow: inset 0 0 0 1px #dbe8ff; }
.action-dialog-symbol span { width: 22px; height: 22px; position: relative; display: block; border: 2px solid currentColor; border-radius: 50%; }
.action-dialog-symbol span::before { content: ""; position: absolute; left: 9px; top: 4px; width: 2px; height: 7px; border-radius: 2px; background: currentColor; }
.action-dialog-symbol span::after { content: ""; position: absolute; left: 9px; bottom: 4px; width: 2px; height: 2px; border-radius: 50%; background: currentColor; }
.action-dialog-copy h2 { margin: 7px 0 8px; color: var(--text); font-size: 21px; }
.action-dialog-copy p { max-width: 390px; margin: 0 auto; color: var(--text-muted); font-size: 13px; line-height: 1.7; }
.action-dialog-field { margin-top: 22px; text-align: left; }
.action-dialog-input-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.action-dialog-input-row input { width: 100%; min-width: 0; color: #17305f; border-color: #bed1f5; background: #f7faff; font-family: Consolas, "SFMono-Regular", monospace; font-size: 14px; font-weight: 700; letter-spacing: .35px; }
.action-dialog-actions { justify-content: center; margin-top: 24px; }
.action-dialog-actions button { min-width: 104px; }
.action-dialog.danger-mode .action-dialog-symbol { color: var(--danger); background: var(--danger-soft); box-shadow: inset 0 0 0 1px #f6d6d6; }
.action-dialog.danger-mode #actionDialogEyebrow { color: var(--danger); }
.action-dialog.danger-mode #actionDialogConfirm { border-color: var(--danger); background: linear-gradient(135deg, #e44f5f, #c9243f); box-shadow: 0 7px 16px rgba(217, 75, 75, .24); }

@keyframes page-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
@keyframes action-dialog-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes action-backdrop-in { from { opacity: 0; } to { opacity: 1; } }

@media (prefers-reduced-motion: no-preference) {
  .action-dialog[open] { animation: action-dialog-in .18s ease-out; }
  .action-dialog[open]::backdrop { animation: action-backdrop-in .18s ease-out; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

@media (max-width: 1320px) {
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .usage-grid { grid-template-columns: 1fr; }
}
@media (max-width: 1200px) {
  .issue-panel { grid-template-columns: 1fr; }
  .overview-grid { grid-template-columns: 1fr; }
}
@media (max-width: 1100px) {
  .two-column { grid-template-columns: 1fr; }
  .sticky-card { position: static; }
}
@media (max-width: 860px) {
  .app-shell { grid-template-columns: 212px minmax(0, 1fr); }
  .sidebar { width: 212px; padding-inline: 12px; }
  .sidebar nav button { gap: 9px; padding-inline: 9px; font-size: 12px; }
  .sidebar nav button > .nav-icon { width: 27px; height: 27px; flex: 0 0 27px; }
  .sidebar-brand { padding-inline: 2px; }
  .sidebar-foot { margin-inline: 0; padding-inline: 4px; }
  .topbar { padding-inline: 22px; }
  .page { padding-inline: 22px; }
}
@media (max-width: 700px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-brand { display: none; }
  .app-shell { display: block; }
  .sidebar { position: static; width: auto; height: auto; padding: 10px; }
  .sidebar-brand, .sidebar-foot { display: none; }
  .sidebar nav { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .sidebar nav button { min-width: 0; min-height: 56px; padding: 5px 2px; display: flex; flex-direction: column; justify-content: center; gap: 3px; font-size: 10px; line-height: 1.2; text-align: center; }
  .sidebar nav button > .nav-icon { width: 22px; height: 22px; flex: 0 0 22px; }
  .sidebar nav button > .nav-icon svg { width: 15px; height: 15px; }
  .topbar { position: static; padding: 16px; }
  .topbar > div:first-child span { display: none; }
  .top-actions .admin-chip, .top-actions #globalRefresh { display: none; }
  .page { padding: 16px 16px 44px; }
  .data-meta { align-items: flex-start; flex-direction: column; gap: 3px; }
  .data-meta span:last-child { text-align: left; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .metric { min-height: 118px; padding: 17px; }
  .panel-head.split { align-items: stretch; flex-direction: column; }
  .filters, .issue-form { grid-template-columns: 1fr; flex-direction: column; }
  .filters input { width: 100%; }
  .trend-chart { grid-template-columns: repeat(7, minmax(42px, 1fr)); gap: 5px; overflow-x: auto; }
  .usage-event { grid-template-columns: 36px minmax(0, 1fr); }
  .usage-event time { grid-column: 2; }
  .form-grid, .issue-form { grid-template-columns: 1fr; }
  .action-dialog-card { padding: 24px 20px 20px; }
  .action-dialog-input-row { grid-template-columns: 1fr; }
  .action-dialog-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .action-dialog-actions button { width: 100%; min-width: 0; }
}
@media (max-width: 460px) {
  .metrics { grid-template-columns: 1fr; }
  .sidebar nav { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
