:root {
  color-scheme: light;
  --brand: #315f9f;
  --brand-strong: #244a80;
  --brand-soft: #edf3fa;
  --ink: #182335;
  --muted: #68768a;
  --line: #e1e7ee;
  --surface: #ffffff;
  --canvas: #f3f5f8;
  --danger: #c94955;
  --success: #287f69;
  --warning: #b8782e;
  --sidebar: #101a28;
  --radius: 12px;
  --shadow: 0 8px 28px rgba(19, 32, 50, .055);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font: 14px/1.55 Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; }
.danger-text { color: var(--danger); }
.success-text { color: var(--success); }

/* Login */
.login-page {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    radial-gradient(circle at 15% 10%, color-mix(in srgb, var(--brand) 17%, transparent), transparent 32%),
    radial-gradient(circle at 90% 80%, rgba(14, 165, 233, .14), transparent 30%),
    #f6f9fe;
}
.login-card {
  width: min(430px, 100%);
  padding: 38px;
  border: 1px solid rgba(226, 232, 240, .9);
  border-radius: 18px;
  background: rgba(255, 255, 255, .94);
  box-shadow: 0 24px 70px rgba(30, 64, 175, .13);
}
.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  color: #fff;
  border-radius: 13px;
  font-weight: 800;
  font-size: 20px;
  background: linear-gradient(135deg, var(--brand), color-mix(in srgb, var(--brand) 48%, #06b6d4));
  box-shadow: 0 10px 25px color-mix(in srgb, var(--brand) 30%, transparent);
}
.brand-mark.brand-logo { padding: 5px; overflow: hidden; background: #fff; border: 1px solid rgba(255,255,255,.28); }
.brand-mark.brand-logo img { width: 100%; height: 100%; object-fit: contain; border-radius: 7px; }
.login-card h1 { margin: 20px 0 5px; font-size: 25px; }
.login-product { margin-top: 6px; color: var(--brand); font-weight: 650; }
.login-card > p { margin: 5px 0 25px; color: var(--muted); }
.login-card footer { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); color: var(--muted); text-align: center; font-size: 12px; }

/* App shell */
.app-shell { min-height: 100%; display: grid; grid-template-columns: 250px minmax(0, 1fr); }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 250px;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 20px 14px 15px;
  color: #cbd5e1;
  background: var(--sidebar);
  z-index: 30;
  transition: transform .2s ease;
}
.sidebar nav { flex: 1 1 auto; min-height: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #344155 transparent; }
.sidebar-footer { position: static; flex: 0 0 auto; margin: 12px 8px 0; padding: 13px 1px 2px; color: #748399; border-top: 1px solid rgba(255,255,255,.07); font-size: 11px; }
.sidebar-footer small { display: block; margin-top: 3px; color: #8c9ab0; }
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 21px; color: #fff; }
.sidebar-brand .brand-mark { width: 38px; height: 38px; border-radius: 10px; font-size: 16px; }
.sidebar-brand strong { display: block; font-size: 16px; }
.sidebar-brand > div:last-child { min-width: 0; }
.sidebar-brand strong, .sidebar-brand small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-brand small { display: block; max-width: 160px; color: #8290a6; }
.nav-title { margin: 19px 10px 7px; color: #65738a; font-size: 11px; letter-spacing: .08em; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 9px 11px;
  border-radius: 8px;
  color: #aebbd0;
  transition: .15s ease;
}
.nav-item:hover { color: #fff; background: rgba(255,255,255,.06); }
.nav-item.active { color: #fff; background: var(--brand); box-shadow: 0 6px 18px color-mix(in srgb, var(--brand) 28%, transparent); }
.nav-icon { width: 20px; text-align: center; font-size: 15px; }
.app-main { grid-column: 2; min-width: 0; }
.topbar {
  height: 64px;
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 26px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(12px);
}
.topbar-left, .topbar-user, .row-actions, .inline, .pagination { display: flex; align-items: center; gap: 10px; }
.row-actions { flex-wrap: wrap; min-width: 185px; }
.global-announcement { display: flex; align-items: center; gap: 10px; min-height: 38px; padding: 7px 26px; color: #76510b; border-bottom: 1px solid #fde6a8; background: linear-gradient(90deg, #fff9e9, #fffdf8); }
.global-announcement span { flex: 0 0 auto; padding: 2px 7px; color: #fff; border-radius: 99px; background: #d79717; font-size: 11px; font-weight: 700; }
.global-announcement p { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-button { display: none; }
.user-avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; background: #334155; }
.page { padding: 25px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.page-head h1 { margin: 0 0 3px; font-size: 23px; letter-spacing: -.02em; }
.page-head p { margin: 0; color: var(--muted); }

/* Common cards and dashboard */
.card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.card { transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease; }
.card:hover { border-color: color-mix(in srgb, var(--brand) 20%, var(--line)); box-shadow: 0 14px 38px rgba(15, 23, 42, .09); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 17px 19px; border-bottom: 1px solid var(--line); }
.card-head h2 { margin: 0; font-size: 16px; }
.card-body { padding: 19px; }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 15px; margin-bottom: 18px; }
.stat-card { padding: 19px; position: relative; overflow: hidden; }
.stat-card::after { content: ''; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--brand); }
.stat-card.tone-cyan::after { background: #0891b2; }
.stat-card.tone-green::after { background: #059669; }
.stat-card.tone-orange::after { background: #d97706; }
.stat-label { color: var(--muted); margin-bottom: 9px; }
.stat-value { font-size: 25px; line-height: 1.2; font-weight: 750; letter-spacing: -.025em; }
.stat-hint { margin-top: 8px; color: var(--muted); font-size: 12px; }
.dashboard-grid { display: grid; grid-template-columns: 1.45fr 1fr; gap: 18px; }
.metric-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; background: var(--line); }
.metric-item { padding: 17px 19px; background: #fff; }
.metric-item strong { display: block; margin-top: 3px; font-size: 18px; }
.progress { height: 8px; overflow: hidden; background: #eaf0f8; border-radius: 999px; }
.progress > i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--brand), color-mix(in srgb, var(--brand) 40%, #06b6d4)); }
.dashboard-meta { display: flex; flex-wrap: wrap; gap: 16px; margin: -8px 0 14px; color: var(--muted); font-size: 12px; }
.live-dot::before { content: ''; display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: #10b981; box-shadow: 0 0 0 4px rgba(16,185,129,.12); }
.ops-health { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 10px; margin-bottom: 18px; }
.health-item { display: flex; align-items: center; justify-content: space-between; padding: 11px 14px; border: 1px solid var(--line); border-radius: 9px; background: #fff; }
.health-item span { color: var(--muted); }
.health-item strong { font-size: 16px; }
.health-item.success strong { color: var(--success); }
.health-item.danger { border-color: #fecaca; background: #fff7f7; }
.health-item.danger strong { color: var(--danger); }
.success-rate-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 24px; padding: 22px; }
.success-rate-grid span { color: var(--muted); }
.success-rate-grid strong { display: block; margin: 5px 0 10px; font-size: 28px; }
.card-head p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.text-link { padding: 0; border: 0; color: var(--brand); background: none; font-weight: 650; }

/* Forms */
.field { display: grid; gap: 6px; }
.field label, .field-label { font-size: 13px; color: #475569; font-weight: 600; }
.field input, .field select, .field textarea, .control {
  width: 100%;
  min-height: 39px;
  padding: 8px 11px;
  color: var(--ink);
  border: 1px solid #d7deea;
  border-radius: 8px;
  outline: none;
  background: #fff;
  transition: .15s ease;
}
.field textarea { min-height: 90px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .control:focus { border-color: #6b9df6; box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.field small { color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.form-grid .full { grid-column: 1 / -1; }
.filters { display: grid; grid-template-columns: repeat(5, minmax(120px, 1fr)) auto; gap: 10px; padding: 15px; border-bottom: 1px solid var(--line); }
.filters .field label { display: none; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.input-group { display: flex; }
.input-group .control { border-radius: 8px 0 0 8px; }
.input-group .btn { border-radius: 0 8px 8px 0; }

/* Buttons */
.btn {
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: #fff;
  background: var(--brand);
  font-weight: 600;
  white-space: nowrap;
  transition: .15s ease;
}
.btn:hover { background: var(--brand-strong); transform: translateY(-1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn.secondary { color: #334155; background: #fff; border-color: #d8e0eb; }
.btn.secondary:hover { color: var(--brand); border-color: #93b4ee; background: #f8fbff; }
.btn.danger { background: var(--danger); }
.btn.warning { background: var(--warning); }
.btn.success { background: var(--success); }
.btn.small { min-height: 30px; padding: 5px 9px; font-size: 12px; }
.btn.ghost { color: var(--muted); background: transparent; border-color: transparent; }
.icon-btn { width: 36px; min-width: 36px; padding: 0; }

/* Tables */
.table-wrap { width: 100%; overflow: auto; }
table { width: 100%; min-width: 820px; border-collapse: collapse; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: #526174; background: #f8fafc; font-size: 12px; font-weight: 700; white-space: nowrap; }
tbody tr:hover { background: #fafcff; }
td { color: #263449; }
.cell-main { display: block; font-weight: 600; }
.cell-sub { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }
.money { font-variant-numeric: tabular-nums; font-weight: 650; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; padding: 3px 8px; border-radius: 999px; color: #475569; background: #eef2f7; font-size: 12px; white-space: nowrap; }
.badge.success { color: #047857; background: #dff7ed; }
.badge.danger { color: #b91c1c; background: #fee8e8; }
.badge.warning { color: #b45309; background: #fff2d8; }
.badge.info { color: #1d4ed8; background: #e7efff; }
.table-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 15px; }
.pagination .btn { min-width: 34px; padding: 4px 8px; }
.copy-inline { margin-top: 3px; padding: 0; border: 0; color: var(--brand); background: transparent; font-size: 11px; }

/* Empty/loading */
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty-icon { width: 48px; height: 48px; display: grid; place-items: center; margin: 0 auto 10px; border-radius: 50%; background: #f1f5f9; font-size: 20px; }
.skeleton { border-radius: 6px; color: transparent !important; background: linear-gradient(90deg, #eef2f7 25%, #f7f9fc 50%, #eef2f7 75%); background-size: 200% 100%; animation: shimmer 1.25s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.spinner { width: 20px; height: 20px; display: inline-block; border: 2px solid #dbe5f4; border-top-color: var(--brand); border-radius: 50%; animation: spin .65s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Modal, toast, drawer */
.modal-backdrop { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: rgba(15,23,42,.52); backdrop-filter: blur(4px); }
.modal { width: min(650px, 100%); max-height: calc(100vh - 40px); max-height: calc(100dvh - 40px); overflow: auto; overscroll-behavior: contain; border: 1px solid rgba(255,255,255,.28); border-radius: 16px; background: #fff; box-shadow: 0 32px 100px rgba(15,23,42,.28); }
.modal-attention { animation: modal-attention .24s ease-out; }
.modal-backdrop[data-submitting="true"] .modal { cursor: wait; }
@keyframes modal-attention { 35% { transform: scale(.994); } 70% { transform: scale(1.002); } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 17px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 9px; padding: 15px 20px; border-top: 1px solid var(--line); background: #fafcff; }
.toast-stack { position: fixed; top: 18px; right: 18px; z-index: 200; display: grid; gap: 10px; }
.toast { width: min(360px, calc(100vw - 36px)); padding: 12px 15px; color: #fff; border-radius: 9px; background: #1e293b; box-shadow: 0 12px 35px rgba(15,23,42,.24); animation: toast-in .18s ease-out; }
.toast.success { background: #047857; }
.toast.error { background: #b91c1c; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }
.mobile-overlay { display: none; }

/* Details and API docs */
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; overflow: hidden; border: 1px solid var(--line); border-radius: 9px; background: var(--line); }
.detail-item { min-height: 62px; padding: 11px 13px; background: #fff; }
.detail-item .label { display: block; color: var(--muted); font-size: 12px; }
.detail-item .value { display: block; margin-top: 3px; font-weight: 600; word-break: break-all; }
.code-block { overflow: auto; padding: 15px; color: #dbeafe; border-radius: 9px; background: #111827; font: 12px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre; }
.notice { padding: 12px 14px; border: 1px solid #bfdbfe; border-radius: 9px; color: #1e40af; background: #eff6ff; }
.notice.warning { color: #92400e; border-color: #fed7aa; background: #fff7ed; }
.integration-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.integration-info { max-height: 58vh; overflow: auto; margin: 0; padding: 18px; color: #dbeafe; border-radius: 9px; background: #0b1220; font: 13px/1.8 ui-monospace,SFMono-Regular,Menlo,monospace; white-space: pre-wrap; word-break: break-all; }
.permission-matrix { display: grid; gap: 12px; margin-top: 18px; }
.permission-matrix section { overflow: hidden; border: 1px solid var(--line); border-radius: 9px; }
.permission-group-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 13px; background: #f7f9fc; }
.permission-options { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 1px; background: var(--line); }
.permission-options label { display: grid; grid-template-columns: auto 1fr; align-items: start; gap: 3px 9px; padding: 12px; background: #fff; cursor: pointer; }
.permission-options label:hover { background: #f8fbff; }
.permission-options input { grid-row: 1 / span 2; margin-top: 3px; accent-color: var(--brand); }
.permission-options span { font-weight: 650; }
.permission-options small { color: var(--muted); font: 10px/1.35 ui-monospace,SFMono-Regular,Menlo,monospace; word-break: break-all; }
.report-filter { margin-bottom: 14px; }
.report-filter .filters { border: 0; }
.report-summary { display: grid; grid-template-columns: repeat(6,minmax(0,1fr)); gap: 10px; margin-bottom: 14px; }
.report-summary > div { padding: 14px; border: 1px solid var(--line); border-radius: 9px; background: #fff; }
.report-summary span { display: block; color: var(--muted); font-size: 12px; }
.report-summary strong { display: block; margin-top: 5px; font-size: 18px; }
.report-summary .primary { color: #fff; border-color: var(--brand); background: linear-gradient(135deg,var(--brand),#0f4db8); }
.report-summary .primary span { color: #dbeafe; }
.settings-layout { display: grid; gap: 18px; }
.settings-section .card-head { align-items: flex-start; }
.settings-section .card-head p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.settings-section .card-body { padding: 22px; }
.branding-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 15px; }
.upload-panel { display: grid; grid-template-columns: 110px minmax(0,1fr); align-items: center; gap: 18px; padding: 15px; border: 1px dashed #bdc8d6; border-radius: 12px; background: color-mix(in srgb, var(--canvas) 72%, var(--surface)); }
.image-preview { width: 110px; height: 74px; display: grid; place-items: center; overflow: hidden; color: var(--muted); border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.image-preview.favicon { width: 74px; }
.image-preview img { width: 100%; height: 100%; object-fit: contain; }
.upload-copy strong { display: block; margin-bottom: 4px; }
.upload-copy p { margin: 0 0 10px; color: var(--muted); font-size: 12px; }
.upload-copy input { width: 100%; max-width: 100%; }
.upload-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.code-tags { display: flex; flex-wrap: wrap; gap: 4px; max-width: 220px; }
.code-tag { padding: 2px 6px; color: #355a86; border: 1px solid #cfdae8; border-radius: 5px; background: #f1f5fa; font: 10px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace; }
.security-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.setting-color { display: flex; align-items: center; gap: 9px; }
.setting-color input[type="color"] { width: 48px; min-height: 39px; padding: 3px; }
.tabs { display: flex; gap: 4px; padding: 5px; border-radius: 9px; background: #edf2f8; }
.tab { padding: 7px 12px; border: 0; border-radius: 7px; color: var(--muted); background: transparent; }
.tab.active { color: var(--brand); background: #fff; box-shadow: 0 2px 6px rgba(15,23,42,.08); }

@media (max-width: 1180px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .filters { grid-template-columns: repeat(3, minmax(120px,1fr)); }
  .report-summary { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .permission-options { grid-template-columns: repeat(2,minmax(0,1fr)); }
}
@media (max-width: 820px) {
  .app-shell { grid-template-columns: 1fr; }
  .app-main { grid-column: 1; }
  .sidebar { width: min(86vw, 284px); transform: translateX(-102%); box-shadow: 18px 0 50px rgba(15,23,42,.2); }
  .sidebar.open { transform: translateX(0); }
  .mobile-overlay { display: block; position: fixed; inset: 0; z-index: 25; background: rgba(15,23,42,.4); }
  .menu-button { display: inline-grid; place-items: center; }
  .topbar { padding: 0 15px; }
  .page { padding: 17px 14px; }
  .page-head { align-items: stretch; flex-direction: column; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .ops-health { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .filters { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
}
@media (max-width: 520px) {
  .login-card { padding: 28px 22px; }
  .stats-grid { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .topbar-user .user-copy { display: none; }
  .table-footer { align-items: flex-start; flex-direction: column; }
  .ops-health,.success-rate-grid,.report-summary,.permission-options { grid-template-columns: 1fr; }
  .branding-grid { grid-template-columns: 1fr; }
  .upload-panel { grid-template-columns: 82px minmax(0,1fr); gap: 13px; }
  .image-preview { width: 82px; height: 64px; }
}
