:root {
  color-scheme: light;
  --ink: oklch(25% 0.018 45);
  --ink-soft: oklch(39% 0.015 48);
  --muted: oklch(52% 0.015 55);
  --faint: oklch(68% 0.011 62);
  --canvas: oklch(97.5% 0.006 80);
  --surface: oklch(99% 0.004 80);
  --surface-warm: oklch(95.5% 0.011 70);
  --line: oklch(89% 0.008 70);
  --line-strong: oklch(82% 0.012 65);
  --accent: oklch(60% 0.19 32);
  --accent-dark: oklch(50% 0.17 30);
  --accent-soft: oklch(94% 0.035 35);
  --success: oklch(57% 0.13 150);
  --success-soft: oklch(94% 0.035 150);
  --warning: oklch(68% 0.14 75);
  --warning-soft: oklch(95% 0.04 80);
  --danger: oklch(54% 0.19 25);
  --danger-soft: oklch(94% 0.04 25);
  --info: oklch(57% 0.12 245);
  --info-soft: oklch(94% 0.03 245);
  --shadow: 0 16px 40px rgba(43, 35, 31, 0.12);
  --font-ui: "Microsoft YaHei UI", "Segoe UI", system-ui, sans-serif;
  --font-number: "Bahnschrift", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  letter-spacing: 0;
}
button, input, select, textarea { color: inherit; font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
.hidden { display: none !important; }
.svg-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
svg { fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }

.login-screen { display: grid; min-height: 100vh; grid-template-columns: minmax(420px, 44%) 1fr; }
.login-brand {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  padding: 48px clamp(40px, 6vw, 88px) 36px;
  background: var(--surface-warm);
  border-right: 1px solid var(--line);
}
.login-brand > img { width: 260px; height: auto; }
.brand-statement { position: relative; max-width: 520px; padding: 56px 0; }
.brand-statement h1 { max-width: 9em; margin: 16px 0 44px; font-size: 48px; line-height: 1.18; }
.matrix-preview { display: grid; width: 310px; grid-template-columns: repeat(4, 1fr); gap: 9px; transform: skewY(-4deg); }
.matrix-preview span { aspect-ratio: 1.9; border: 1px solid var(--line-strong); background: var(--surface); }
.matrix-preview span.active { background: var(--accent); border-color: var(--accent); }
.login-footnote { margin: 0; color: var(--muted); font-family: var(--font-number); font-size: 12px; text-transform: uppercase; }
.login-form-wrap { display: grid; min-height: 100vh; place-items: center; padding: 40px; background: var(--surface); }
.login-form { width: min(380px, 100%); }
.mobile-login-logo { display: none; width: 210px; height: auto; margin-bottom: 56px; }
.eyebrow { margin: 0; color: var(--accent); font-family: var(--font-number); font-size: 11px; font-weight: 700; text-transform: uppercase; }
.login-form h2 { margin: 10px 0 36px; font-size: 28px; line-height: 1.25; }
.field { display: grid; gap: 8px; margin-bottom: 18px; color: var(--ink-soft); font-size: 13px; font-weight: 600; }
.field input, .field select, .field textarea, .search-box input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  outline: none;
  background: var(--surface);
  padding: 8px 11px;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}
.field textarea { min-height: 96px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .search-box input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.field.full { grid-column: 1 / -1; }
.check-field { display: flex; min-height: 40px; align-items: center; gap: 9px; }
.check-field input { width: 17px; height: 17px; accent-color: var(--accent); }
.form-error { min-height: 20px; margin: 6px 0 10px; color: var(--danger); font-size: 13px; }

.button {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 7px 13px;
  font-weight: 700;
  transition: background-color 160ms ease, border-color 160ms ease, transform 100ms ease;
}
.button svg { width: 17px; height: 17px; }
.button:active { transform: translateY(1px); }
.button:focus-visible, .icon-button:focus-visible, .nav-item:focus-visible, .table-action:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 2px; }
.button:disabled { cursor: wait; opacity: .6; }
.button.primary { background: var(--accent); color: oklch(98% 0.01 35); }
.button.primary:hover { background: var(--accent-dark); }
.button.secondary { border-color: var(--line-strong); background: var(--surface); }
.button.secondary:hover { background: var(--surface-warm); }
.button.danger { background: var(--danger); color: oklch(98% 0.01 25); }
.button.danger:hover { background: oklch(47% 0.18 25); }
.button.wide { width: 100%; min-height: 44px; }
.icon-button, .table-action {
  display: inline-grid;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
}
.icon-button:hover, .table-action:hover { border-color: var(--line-strong); background: var(--surface-warm); }
.icon-button svg, .table-action svg { width: 17px; height: 17px; }
.icon-button.spinning svg { animation: spin 650ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.app-shell { display: grid; min-height: 100vh; grid-template-columns: 228px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; z-index: 20; display: flex; height: 100vh; flex-direction: column; background: var(--ink); color: oklch(92% 0.009 60); }
.sidebar-brand { display: flex; height: 76px; align-items: center; gap: 12px; padding: 0 20px; border-bottom: 1px solid oklch(34% 0.018 45); }
.sidebar-brand img { border-radius: 8px; }
.sidebar-brand div { display: grid; gap: 2px; }
.sidebar-brand strong { color: oklch(97% 0.007 60); font-family: var(--font-number); font-size: 16px; }
.sidebar-brand span { color: oklch(70% 0.012 60); font-size: 11px; }
.main-nav { display: grid; gap: 4px; padding: 18px 12px; }
.nav-item { display: flex; min-height: 42px; align-items: center; gap: 12px; border: 0; border-radius: 5px; background: transparent; color: oklch(75% 0.01 60); padding: 0 12px; text-align: left; }
.nav-item svg { width: 18px; height: 18px; }
.nav-item:hover { background: oklch(31% 0.018 45); color: oklch(95% 0.008 60); }
.nav-item.active { background: var(--accent); color: oklch(98% 0.01 35); }
.sidebar-footer { display: flex; align-items: center; gap: 10px; margin-top: auto; padding: 20px; border-top: 1px solid oklch(34% 0.018 45); }
.sidebar-footer div { display: grid; gap: 2px; }
.sidebar-footer strong { font-size: 12px; }
.sidebar-footer span:not(.service-dot) { color: oklch(66% 0.012 60); font-size: 11px; }
.service-dot { width: 9px; height: 9px; border-radius: 50%; background: oklch(70% 0.17 150); box-shadow: 0 0 0 4px oklch(40% 0.07 150); }

.workspace { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 15; display: flex; min-height: 76px; align-items: center; gap: 16px; border-bottom: 1px solid var(--line); background: color-mix(in oklch, var(--surface) 94%, transparent); padding: 10px clamp(20px, 3vw, 38px); }
.breadcrumb { margin: 0 0 3px; color: var(--faint); font-family: var(--font-number); font-size: 10px; text-transform: uppercase; }
.breadcrumb span { color: var(--muted); }
.topbar h1 { margin: 0; font-size: 20px; line-height: 1.25; }
.topbar-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.admin-identity { display: grid; min-width: 94px; gap: 2px; padding-left: 8px; }
.admin-identity strong { font-size: 12px; }
.admin-identity span { color: var(--muted); font-family: var(--font-number); font-size: 9px; }
.menu-button { display: none; }
.content { padding: 28px clamp(20px, 3vw, 38px) 48px; outline: none; }

.page-toolbar { display: flex; min-height: 44px; align-items: center; gap: 10px; margin-bottom: 18px; }
.page-toolbar .button:first-of-type { margin-left: auto; }
.search-box { position: relative; width: min(320px, 42vw); }
.search-box svg { position: absolute; top: 11px; left: 11px; width: 16px; height: 16px; color: var(--faint); }
.search-box input { min-height: 38px; padding-left: 36px; }
.toolbar-caption { color: var(--muted); font-size: 12px; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.metric { min-height: 124px; padding: 24px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric-head { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 12px; }
.metric-head svg { width: 17px; height: 17px; }
.metric strong { display: block; margin-top: 16px; font-family: var(--font-number); font-size: 32px; font-weight: 650; line-height: 1; }
.metric small { display: block; margin-top: 9px; color: var(--faint); font-size: 11px; }
.metric.good strong { color: var(--success); }
.metric.signal strong { color: var(--accent); }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(320px, .65fr); gap: 18px; margin-top: 18px; }
.panel { border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.panel-head { display: flex; min-height: 58px; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); padding: 12px 18px; }
.panel-head h2 { margin: 0; font-size: 15px; }
.panel-head p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.panel-head .button, .panel-head .icon-button { margin-left: auto; }
.announcement-body { min-height: 118px; padding: 18px; color: var(--ink-soft); line-height: 1.75; white-space: pre-wrap; }
.status-list { display: grid; }
.status-row { display: grid; min-height: 56px; grid-template-columns: 10px minmax(0, 1fr) auto; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); padding: 9px 18px; }
.status-row:last-child { border-bottom: 0; }
.status-row .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.status-row .dot.online { background: var(--success); }
.status-row strong { display: block; font-size: 12px; }
.status-row small { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.data-table { width: 100%; min-width: 840px; border-collapse: collapse; }
.data-table th { height: 42px; background: var(--surface-warm); color: var(--muted); padding: 0 14px; font-size: 11px; font-weight: 700; text-align: left; white-space: nowrap; }
.data-table td { height: 54px; border-top: 1px solid var(--line); padding: 8px 14px; color: var(--ink-soft); font-size: 12px; vertical-align: middle; }
.data-table tbody tr:hover { background: oklch(98% 0.008 70); }
.data-table strong { color: var(--ink); font-size: 12px; }
.subtext { display: block; max-width: 240px; overflow: hidden; margin-top: 3px; color: var(--faint); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.numeric { font-family: var(--font-number); font-variant-numeric: tabular-nums; }
.table-actions { display: flex; justify-content: flex-end; gap: 6px; }
.table-action.danger { color: var(--danger); }
.badge { display: inline-flex; min-height: 24px; align-items: center; gap: 6px; border-radius: 999px; padding: 3px 9px; font-size: 10px; font-weight: 700; white-space: nowrap; }
.badge::before { width: 6px; height: 6px; border-radius: 50%; background: currentColor; content: ""; }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.warning { background: var(--warning-soft); color: oklch(54% 0.13 65); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.neutral { background: var(--surface-warm); color: var(--muted); }
.role-chip { color: var(--ink-soft); font-family: var(--font-number); font-size: 10px; font-weight: 700; text-transform: uppercase; }

.empty-state { display: grid; min-height: 240px; place-items: center; padding: 40px; color: var(--muted); text-align: center; }
.empty-state svg { width: 28px; height: 28px; margin-bottom: 12px; }
.empty-state strong { display: block; color: var(--ink); }
.empty-state p { margin: 6px 0 0; font-size: 12px; }
.skeleton { overflow: hidden; border-radius: 4px; background: var(--surface-warm); }
.skeleton-line { height: 12px; margin: 20px; }

.entity-dialog, .confirm-dialog { width: min(620px, calc(100vw - 32px)); max-height: calc(100vh - 40px); overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); padding: 0; box-shadow: var(--shadow); }
.entity-dialog::backdrop, .confirm-dialog::backdrop { background: rgba(35, 29, 26, .42); }
.dialog-head { display: flex; min-height: 72px; align-items: center; border-bottom: 1px solid var(--line); padding: 14px 20px; }
.dialog-head h2 { margin: 5px 0 0; font-size: 18px; }
.dialog-head .icon-button { margin-left: auto; }
.dialog-body { padding: 20px 20px 4px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--line); padding: 14px 20px; }
.entity-dialog .form-error { padding: 0 20px; }
.confirm-dialog { width: min(410px, calc(100vw - 32px)); padding-top: 24px; text-align: center; }
.confirm-dialog h2 { margin: 12px 20px 6px; font-size: 18px; }
.confirm-dialog p { margin: 0 24px 22px; color: var(--muted); line-height: 1.7; }
.confirm-icon { display: grid; width: 42px; height: 42px; margin: 0 auto; place-items: center; border-radius: 50%; background: var(--danger-soft); color: var(--danger); }
.confirm-icon svg { width: 21px; height: 21px; }
.channel-picker { display: grid; max-height: 390px; overflow: auto; border: 1px solid var(--line); border-radius: 5px; }
.channel-choice { display: grid; min-height: 50px; grid-template-columns: 22px minmax(0, 1fr) auto; align-items: center; gap: 9px; border-bottom: 1px solid var(--line); padding: 8px 12px; }
.channel-choice:last-child { border-bottom: 0; }
.channel-choice input { width: 16px; height: 16px; accent-color: var(--accent); }
.channel-choice strong { display: block; font-size: 12px; }
.channel-choice small { color: var(--muted); font-size: 10px; }

.toast-region { position: fixed; right: 22px; bottom: 22px; z-index: 100; display: grid; gap: 8px; }
.toast { width: min(340px, calc(100vw - 44px)); border: 1px solid var(--line-strong); border-radius: 6px; background: var(--ink); color: oklch(96% 0.008 60); padding: 12px 14px; box-shadow: var(--shadow); animation: toast-in 180ms ease-out; }
.toast.error { background: var(--danger); border-color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 1050px) {
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .login-screen { grid-template-columns: 1fr; }
  .login-brand { display: none; }
  .login-form-wrap { padding: 28px; }
  .mobile-login-logo { display: block; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -244px; width: 228px; transition: transform 180ms ease-out; }
  .sidebar.open { transform: translateX(244px); box-shadow: var(--shadow); }
  .menu-button { display: inline-grid; }
  .topbar { min-height: 68px; padding: 8px 14px; }
  .topbar h1 { font-size: 17px; }
  .admin-identity { display: none; }
  .content { padding: 18px 14px 36px; }
  .page-toolbar { flex-wrap: wrap; }
  .search-box { width: 100%; }
  .page-toolbar .button:first-of-type { margin-left: 0; }
  .metric-grid { grid-template-columns: 1fr; }
  .metric { min-height: 104px; border-right: 0; border-bottom: 1px solid var(--line); }
  .metric:last-child { border-bottom: 0; }
  .form-grid { grid-template-columns: 1fr; }
}
