:root {
  --primary: #0f172a;
  --secondary: #1e3a8a;
  --accent: #a16207;
  --accent-dark: #854d0e;
  --background: #f8fafc;
  --card: #ffffff;
  --foreground: #020617;
  --muted: #e8ecf1;
  --muted-foreground: #475569;
  --border: #e2e8f0;
  --success: #15803d;
  --warning: #a16207;
  --danger: #dc2626;
  --ring: #0f172a;
  --sidebar: 248px;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }
html { background: var(--background); }
body {
  margin: 0;
  color: var(--foreground);
  background:
    radial-gradient(circle at 85% 0%, rgba(30, 58, 138, .06), transparent 28rem),
    var(--background);
  font: 16px/1.5 "Microsoft YaHei", "PingFang SC", "Source Sans 3", sans-serif;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; }
button, select, input, textarea, a { outline-color: var(--ring); }
button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 3px solid rgba(15, 23, 42, .24);
  outline-offset: 2px;
}
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar); z-index: 20;
  display: flex; flex-direction: column; gap: 24px; padding: 24px 16px;
  background: var(--primary); color: #cbd5e1;
}
.brand { display: flex; align-items: center; gap: 12px; color: white; text-decoration: none; padding: 4px 8px 20px; border-bottom: 1px solid rgba(255,255,255,.12); }
.brand strong { display: block; font-size: 17px; letter-spacing: .02em; }
.brand small { display: block; margin-top: 2px; color: #94a3b8; font-size: 12px; }
.brand-mark {
  display: grid; place-items: center; width: 38px; height: 38px; flex: 0 0 auto;
  color: #fbbf24; border: 1px solid rgba(251,191,36,.45); border-radius: 10px;
  background: rgba(251,191,36,.08);
}
.brand-mark.large { width: 56px; height: 56px; }
.brand-mark.large svg { width: 30px; height: 30px; }
.sidebar nav { display: grid; gap: 5px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 11px; min-height: 44px; padding: 10px 12px;
  border-radius: 9px; text-decoration: none; color: #cbd5e1; font-weight: 500;
  transition: background 180ms ease, color 180ms ease;
}
.sidebar nav a:hover, .sidebar nav a.active { color: white; background: rgba(255,255,255,.1); }
.sidebar nav a.active { box-shadow: inset 3px 0 #fbbf24; }
.sidebar-foot {
  margin-top: auto; display: flex; align-items: center; gap: 8px; padding: 12px;
  color: #94a3b8; font-size: 13px; border-top: 1px solid rgba(255,255,255,.1);
}
.status-dot { width: 8px; height: 8px; border-radius: 999px; background: #64748b; }
.status-dot.ok { background: #4ade80; box-shadow: 0 0 0 4px rgba(74,222,128,.12); }
.workspace { grid-column: 2; min-width: 0; }
.topbar {
  min-height: 96px; display: flex; align-items: center; justify-content: space-between; gap: 20px;
  padding: 20px clamp(22px, 3vw, 44px); border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,.8); backdrop-filter: blur(14px);
}
.topbar h1 { margin: 2px 0 0; font-size: clamp(24px, 2.2vw, 32px); letter-spacing: -.03em; }
.eyebrow { margin: 0; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .15em; text-transform: uppercase; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.user-chip span:not(.avatar) { display: grid; }
.user-chip strong { font-size: 14px; }
.user-chip small { color: var(--muted-foreground); font-size: 11px; }
.user-chip a { margin-left: 8px; color: var(--muted-foreground); font-size: 13px; text-decoration: none; }
.user-chip a:hover { color: var(--foreground); }
.avatar { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: var(--muted); color: var(--secondary); font-weight: 800; }
.content { max-width: 1500px; margin: 0 auto; padding: clamp(20px, 3vw, 40px); }
.mobile-menu { display: none; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.metric-card, .panel {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow);
}
.metric-card { padding: 18px 20px; position: relative; overflow: hidden; }
.metric-card::after { content: ""; position: absolute; width: 60px; height: 60px; border-radius: 50%; right: -24px; top: -24px; background: rgba(30,58,138,.06); }
.metric-card span { color: var(--muted-foreground); font-size: 13px; }
.metric-card strong { display: block; margin: 8px 0 4px; font-size: 30px; line-height: 1; letter-spacing: -.04em; }
.metric-card small { color: #64748b; }
.metric-card.attention strong { color: var(--danger); }
.dashboard-grid, .settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-bottom: 18px; }
.panel { padding: 20px; margin-bottom: 18px; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.panel h2 { margin: 4px 0 0; font-size: 20px; letter-spacing: -.02em; }
.amount { color: var(--accent-dark); font-size: 18px; font-weight: 700; }
.integration-list { display: grid; margin-bottom: 18px; }
.integration-list div, .detail-list div { display: flex; justify-content: space-between; gap: 18px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.integration-list div:last-child, .detail-list div:last-child { border-bottom: 0; }
.integration-list span, .detail-list dt { color: var(--muted-foreground); }
.ok { color: var(--success) !important; }
.warn { color: var(--warning) !important; }
.text-link { color: var(--secondary); font-weight: 700; text-decoration: none; }
.text-link:hover { text-decoration: underline; }
.step-list { list-style: none; display: grid; gap: 12px; padding: 0; margin: 0; }
.step-list li { display: flex; gap: 12px; }
.step-list li > span { display: grid; place-items: center; width: 28px; height: 28px; flex: 0 0 auto; border-radius: 8px; background: var(--muted); color: var(--secondary); font-weight: 800; }
.step-list div { display: grid; }
.step-list small { color: var(--muted-foreground); }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th { padding: 10px 12px; text-align: left; color: var(--muted-foreground); background: #f8fafc; font-size: 12px; letter-spacing: .03em; border-bottom: 1px solid var(--border); }
td { padding: 13px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
td small { display: block; margin-top: 3px; color: var(--muted-foreground); font-size: 11px; }
tbody tr:hover { background: #fbfdff; }
.row-disabled { color: #94a3b8; background: #f8fafc; }
.badge { display: inline-flex; align-items: center; min-height: 25px; padding: 2px 9px; border-radius: 999px; background: #eef2ff; color: var(--secondary); font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge.muted { background: var(--muted); color: var(--muted-foreground); }
.badge.ok { background: #dcfce7; color: var(--success); }
.mono { font-family: "Cascadia Mono", Consolas, monospace; font-size: 13px; }
.empty-state { display: grid; justify-items: start; gap: 8px; padding: 34px 20px; color: var(--muted-foreground); }
.empty-state strong { color: var(--foreground); }
.empty-state p { margin: 0 0 8px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 10px 18px;
  border: 1px solid transparent; border-radius: 9px; text-decoration: none; font-weight: 700; cursor: pointer;
  transition: background 180ms ease, color 180ms ease, border-color 180ms ease, transform 180ms ease;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn-primary { color: white; background: var(--accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); }
.btn-secondary { color: var(--primary); background: white; border-color: var(--primary); }
.btn-secondary:hover:not(:disabled) { background: #f1f5f9; }
.btn:disabled, button:disabled, select:disabled, input:disabled, textarea:disabled {
  cursor: not-allowed; opacity: .48; transform: none;
}
.flash-stack { display: grid; gap: 8px; margin-bottom: 16px; }
.flash { padding: 12px 14px; border-radius: 9px; border: 1px solid var(--border); background: white; }
.flash.error { border-color: #fecaca; color: #991b1b; background: #fef2f2; }
.flash.success { border-color: #bbf7d0; color: #166534; background: #f0fdf4; }
.form-layout { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(280px, .7fr); gap: 18px; align-items: start; }
.form-main, .form-side { margin: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
label { display: grid; gap: 7px; color: #334155; font-size: 13px; font-weight: 700; }
label.span-2, fieldset.span-2 { grid-column: span 2; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid #cbd5e1; border-radius: 8px;
  background: white; color: var(--foreground); transition: border-color 180ms ease, box-shadow 180ms ease;
}
textarea { min-height: 108px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--secondary); box-shadow: 0 0 0 3px rgba(30,58,138,.12); outline: none; }
fieldset { min-width: 0; margin: 0; padding: 14px; border: 1px solid var(--border); border-radius: 10px; }
legend { padding: 0 6px; color: #334155; font-size: 13px; font-weight: 700; }
.check-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.check-card { display: flex; align-items: center; gap: 10px; min-height: 58px; padding: 10px; border: 1px solid var(--border); border-radius: 9px; cursor: pointer; }
.check-card:has(input:checked) { border-color: var(--secondary); background: #eef2ff; }
.check-card input { width: 18px; min-height: 18px; }
.check-card span { display: grid; }
.check-card small { color: var(--muted-foreground); font-weight: 400; }
.field-note { font-size: 12px; font-weight: 500; }
.danger { color: var(--danger); }
.inline-disabled { padding: 14px; border-radius: 8px; background: #f1f5f9; color: #64748b; }
.gate-list { list-style: none; display: grid; gap: 10px; padding: 0; margin: 18px 0; }
.gate-list li { display: flex; align-items: center; gap: 9px; color: var(--muted-foreground); }
.gate-list li span { width: 9px; height: 9px; border-radius: 50%; background: #cbd5e1; }
.gate-list li.ok span { background: var(--success); }
.gate-list li.blocked span { background: var(--danger); }
.notice { padding: 13px; border-radius: 9px; }
.notice.warning { border: 1px solid #fde68a; background: #fffbeb; color: #854d0e; }
.notice p { margin: 4px 0 0; color: #92400e; font-size: 13px; }
.form-actions { display: grid; gap: 9px; margin-top: 16px; }
.detail-list { margin: 0; }
.detail-list dd { margin: 0; text-align: right; font-weight: 700; }

.login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    linear-gradient(135deg, rgba(15,23,42,.96), rgba(30,58,138,.9)),
    repeating-linear-gradient(45deg, transparent 0 28px, rgba(255,255,255,.03) 28px 29px);
}
.login-card { width: min(460px, 100%); padding: 34px; border-radius: 18px; background: white; box-shadow: 0 24px 80px rgba(2,6,23,.35); }
.login-brand { display: grid; gap: 8px; margin-bottom: 26px; }
.login-brand h1 { margin: 0; font-size: 28px; letter-spacing: -.04em; }
.login-brand > p:last-child { margin: 0; color: var(--muted-foreground); }
.login-form { display: grid; gap: 16px; }
.login-form .btn { width: 100%; margin-top: 4px; }
.form-error { margin: 0; color: var(--danger); font-size: 13px; }
.login-note { margin: 22px 0 0; color: #64748b; font-size: 12px; }

@media (max-width: 1024px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-layout { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { transform: translateX(-100%); transition: transform 200ms ease; box-shadow: 20px 0 40px rgba(2,6,23,.25); }
  .sidebar.open { transform: translateX(0); }
  .workspace { display: block; }
  .mobile-menu {
    display: grid; place-items: center; position: fixed; z-index: 30; top: 16px; left: 16px;
    width: 44px; height: 44px; border: 1px solid var(--border); border-radius: 10px;
    background: white; box-shadow: var(--shadow); cursor: pointer;
  }
  .topbar { padding-left: 74px; min-height: 82px; }
  .user-chip span:not(.avatar), .user-chip a { display: none; }
  .content { padding: 16px; }
  .dashboard-grid, .settings-grid { grid-template-columns: 1fr; }
  .form-grid, .check-grid { grid-template-columns: 1fr; }
  label.span-2, fieldset.span-2 { grid-column: span 1; }
}
@media (max-width: 480px) {
  .metric-grid { grid-template-columns: 1fr; }
  .panel { padding: 16px; }
  .topbar h1 { font-size: 22px; }
  .login-card { padding: 24px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
