:root {
  --blue: #1769e0;
  --blue-dark: #1054b8;
  --blue-pale: #eaf2ff;
  --green: #16845b;
  --green-pale: #e8f7f0;
  --amber: #b9650b;
  --amber-pale: #fff2dc;
  --red: #c73d48;
  --red-pale: #ffebed;
  --ink: #172033;
  --muted: #647087;
  --line: #dfe4ec;
  --surface: #ffffff;
  --canvas: #f3f5f8;
  --sidebar: #202c3d;
  --sidebar-muted: #aeb9c9;
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-width: 320px; min-height: 100%; font-size: 14px; letter-spacing: 0; }
body { background: var(--canvas); }
button, input, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
.hidden { display: none !important; }
.is-staff .manager-only, body:not(.is-owner) .owner-only { display: none !important; }
.lucide { width: 18px; height: 18px; stroke-width: 1.9; flex: none; }

.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #eef2f6; }
.login-panel { width: min(400px, 100%); padding: 34px 36px 36px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 16px 42px rgba(25, 39, 61, .12); }
.brand-mark { width: 58px; height: 58px; display: grid; place-items: center; margin: 0 auto 18px; border-radius: 8px; background: #ff8a19; color: #fff; font-weight: 800; font-size: 17px; }
.brand-mark.small { width: 42px; height: 42px; margin: 0; font-size: 12px; }
.login-panel h1 { margin: 0; text-align: center; font-size: 24px; line-height: 1.35; }
.login-subtitle { margin: 6px 0 28px; color: var(--muted); text-align: center; }
.field-label { display: block; margin: 16px 0 7px; color: #46516a; font-weight: 600; }
.input-wrap { height: 42px; display: flex; align-items: center; gap: 10px; padding: 0 12px; border: 1px solid #cdd4df; border-radius: 5px; background: #fff; }
.input-wrap:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(23, 105, 224, .12); }
.input-wrap .lucide { color: #8490a5; }
.input-wrap input { min-width: 0; flex: 1; border: 0; outline: 0; background: transparent; }
.login-button { width: 100%; margin-top: 24px; justify-content: center; }
.form-error { min-height: 20px; margin: 12px 0 0; color: var(--red); text-align: center; }

.app-shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; background: var(--sidebar); color: #fff; z-index: 20; }
.sidebar-brand { min-height: 76px; display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid rgba(255,255,255,.1); }
.sidebar-brand strong { display: block; font-size: 16px; }
.sidebar-brand span { display: block; max-width: 130px; margin-top: 4px; color: var(--sidebar-muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.main-nav { display: grid; gap: 4px; padding: 14px 10px; }
.nav-item { height: 44px; display: flex; align-items: center; gap: 12px; padding: 0 13px; border: 0; border-radius: 5px; background: transparent; color: var(--sidebar-muted); text-align: left; }
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: var(--blue); color: #fff; }
.sidebar-footer { margin-top: auto; min-height: 68px; display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.1); color: #e2e8f0; }
.sidebar-footer div { min-width: 0; }
.sidebar-footer span:not(.status-dot), .sidebar-footer small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer small { margin-top: 3px; color: var(--sidebar-muted); font-size: 11px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #95a0b3; flex: none; }
.status-dot.healthy { background: #3cc789; box-shadow: 0 0 0 4px rgba(60,199,137,.12); }
.status-dot.failed, .status-dot.stale { background: #ff6673; }

.workspace { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 15; height: 64px; display: flex; align-items: center; padding: 0 24px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.96); }
.breadcrumb { display: flex; flex-direction: column; gap: 2px; }
.breadcrumb span { color: var(--muted); font-size: 11px; }
.breadcrumb strong { font-size: 17px; }
.topbar-actions { position: relative; margin-left: auto; display: flex; align-items: center; gap: 12px; }
.role-badge { padding: 4px 8px; border-radius: 4px; background: var(--blue-pale); color: var(--blue-dark); font-size: 12px; }
.profile-button { height: 42px; display: flex; align-items: center; gap: 8px; padding: 0 8px 0 4px; border: 0; border-radius: 5px; background: transparent; color: var(--ink); }
.profile-button:hover { background: #f1f4f8; }
.avatar { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; background: #148dc6; color: #fff; font-weight: 700; }
.profile-menu { position: absolute; top: 50px; right: 0; width: 165px; padding: 6px; border: 1px solid var(--line); border-radius: 6px; background: #fff; box-shadow: 0 10px 28px rgba(29,44,70,.14); }
.profile-menu button { width: 100%; height: 38px; display: flex; align-items: center; gap: 9px; padding: 0 10px; border: 0; border-radius: 4px; background: transparent; color: var(--ink); text-align: left; }
.profile-menu button:hover { background: #f2f5f8; }
.mobile-menu { display: none !important; margin-right: 8px; }

.content { width: 100%; padding: 24px; }
.view { max-width: 1680px; margin: 0 auto; }
.page-heading { min-height: 58px; display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.page-heading h2 { margin: 0; font-size: 22px; line-height: 1.3; }
.page-heading p, .section-heading p { margin: 5px 0 0; color: var(--muted); }
.heading-actions { display: flex; align-items: center; gap: 8px; }
.button { min-height: 36px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 0 14px; border: 1px solid transparent; border-radius: 5px; font-weight: 600; white-space: nowrap; }
.button.primary { background: var(--blue); color: #fff; }
.button.primary:hover { background: var(--blue-dark); }
.button.secondary { border-color: #cdd5e0; background: #fff; color: #33405a; }
.button.secondary:hover { background: #f3f6f9; }
.button.danger { background: var(--red); color: #fff; }
.button:disabled { opacity: .48; cursor: not-allowed; }
.icon-button { width: 36px; height: 36px; display: inline-grid; place-items: center; padding: 0; border: 1px solid #d3dae4; border-radius: 5px; background: #fff; color: #40506b; }
.icon-button:hover { background: #f3f6f9; }

.sync-banner { min-height: 58px; display: flex; align-items: center; gap: 12px; margin: 2px 0 14px; padding: 10px 14px; border: 1px solid #d9e0e9; border-left: 4px solid #8a96aa; border-radius: 5px; background: #fff; }
.sync-banner strong, .sync-banner span { display: block; }
.sync-banner span { margin-top: 3px; color: var(--muted); font-size: 12px; }
.sync-banner.healthy { border-left-color: var(--green); background: var(--green-pale); }
.sync-banner.failed, .sync-banner.stale { border-left-color: var(--red); background: var(--red-pale); }
.sync-banner.running { border-left-color: var(--blue); background: var(--blue-pale); }
.filter-band { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.filter-band label { display: grid; gap: 6px; color: #56627a; font-size: 12px; }
.filter-band label.grow { flex: 1; min-width: 220px; }
input, select { height: 36px; min-width: 142px; padding: 0 10px; border: 1px solid #ccd4df; border-radius: 4px; outline: 0; background: #fff; color: var(--ink); }
input:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(23,105,224,.1); }

.metric-band { display: grid; grid-template-columns: repeat(7, minmax(126px, 1fr)); margin-bottom: 22px; border: 1px solid var(--line); border-radius: 6px; background: #fff; overflow: hidden; }
.metric { min-width: 0; min-height: 92px; padding: 15px 14px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric span { display: block; color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin-top: 10px; font-size: 21px; line-height: 1.15; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric.blue strong { color: var(--blue-dark); }
.metric.green strong { color: var(--green); }
.metric.amber strong { color: var(--amber); }
.metric.red strong { color: var(--red); }
.creator-summary { display: grid; grid-template-columns: repeat(6, minmax(120px, 1fr)); margin-bottom: 22px; border: 1px solid var(--line); border-radius: 6px; background: #fff; overflow: hidden; }
.creator-summary-item { min-width: 0; min-height: 70px; padding: 13px 14px; border-right: 1px solid var(--line); }
.creator-summary-item:last-child { border-right: 0; }
.creator-summary-item span { display: block; color: var(--muted); font-size: 12px; }
.creator-summary-item strong { display: block; margin-top: 7px; font-size: 19px; font-variant-numeric: tabular-nums; }
.creator-summary-item.blue strong { color: var(--blue-dark); }
.creator-summary-item.green strong { color: var(--green); }
.creator-summary-item.amber strong { color: var(--amber); }
.creator-summary-item.red strong { color: var(--red); }
.section-heading { min-height: 48px; display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.section-heading h3 { margin: 0; font-size: 16px; }

.table-wrap { position: relative; width: 100%; border: 1px solid var(--line); border-radius: 6px; background: #fff; overflow: auto; }
table { width: 100%; border-collapse: collapse; table-layout: auto; }
th { height: 42px; padding: 0 12px; border-bottom: 1px solid #cfd6e0; background: #edf0f4; color: #46516a; font-size: 12px; text-align: left; white-space: nowrap; }
td { min-height: 48px; padding: 10px 12px; border-bottom: 1px solid #e7eaf0; color: #263149; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #f8fafc; }
th.number, td.number { text-align: right; font-variant-numeric: tabular-nums; }
th.checkbox, td.checkbox { width: 46px; padding-right: 4px; text-align: center; }
td.checkbox input, th.checkbox input { min-width: 0; width: 16px; height: 16px; }
.link-button { padding: 0; border: 0; background: transparent; color: var(--blue); font-weight: 600; }
.subtext { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.status-label { display: inline-block; padding: 3px 7px; border-radius: 4px; background: #edf1f6; color: #58647b; font-size: 12px; }
.status-label.good { background: var(--green-pale); color: var(--green); }
.status-label.warn { background: var(--amber-pale); color: var(--amber); }
.status-label.bad { background: var(--red-pale); color: var(--red); }
.green { color: var(--green); }
.amber { color: var(--amber); }
.empty { min-height: 180px; display: grid; place-content: center; justify-items: center; gap: 9px; color: #8590a3; }
.empty .lucide { width: 28px; height: 28px; }
.pagination { min-height: 50px; display: flex; align-items: center; justify-content: space-between; color: var(--muted); }
.pagination div { display: flex; gap: 6px; }
.order-summary { display: grid; grid-template-columns: repeat(3, 1fr); margin-bottom: 14px; border: 1px solid var(--line); border-radius: 6px; background: #fff; overflow: hidden; }
.order-summary .summary-cell { min-height: 76px; padding: 13px 16px; border-right: 1px solid var(--line); }
.order-summary .summary-cell:last-child { border-right: 0; }
.order-summary span { display: block; color: var(--muted); font-size: 12px; }
.order-summary strong { display: block; margin-top: 7px; font-size: 20px; }
.order-table td:nth-child(4) { min-width: 260px; max-width: 420px; }
.order-table td:nth-child(2) { min-width: 150px; }
.order-table td:nth-child(3) { min-width: 165px; }

.account-layout { display: grid; gap: 22px; }
.plain-section { min-width: 0; }
.plain-section .section-heading { align-items: center; }
.account-profile { display: grid; grid-template-columns: repeat(5, minmax(130px, 1fr)); border: 1px solid var(--line); border-radius: 6px; background: #fff; overflow: hidden; }
.account-profile > div { min-width: 0; min-height: 72px; padding: 13px 15px; border-right: 1px solid var(--line); }
.account-profile > div:last-child { border-right: 0; }
.account-profile span { display: block; color: var(--muted); font-size: 12px; }
.account-profile strong { display: block; margin-top: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inline-setting { min-height: 72px; display: flex; align-items: center; gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.inline-setting label { display: flex; align-items: center; gap: 8px; color: #46516a; }
.inline-setting input { min-width: 0; width: 110px; text-align: right; }
.action-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
.mini-button { min-height: 30px; padding: 0 9px; border: 1px solid #ccd4df; border-radius: 4px; background: #fff; color: #36435e; }
.mini-button:hover { background: #f1f4f8; }

.modal { width: min(560px, calc(100vw - 30px)); max-height: calc(100vh - 40px); padding: 0; border: 0; border-radius: 8px; box-shadow: 0 24px 70px rgba(18,31,52,.28); }
.modal::backdrop { background: rgba(24,34,50,.44); }
.modal-frame { display: flex; flex-direction: column; max-height: calc(100vh - 40px); }
.modal-header { min-height: 58px; display: flex; align-items: center; padding: 0 18px; border-bottom: 1px solid var(--line); }
.modal-header h3 { margin: 0; font-size: 17px; }
.modal-header .icon-button { margin-left: auto; border: 0; }
.modal-body { display: grid; gap: 14px; padding: 18px; overflow: auto; }
.modal-body label { display: grid; gap: 7px; color: #4e5b72; font-weight: 600; }
.modal-body input, .modal-body select, .modal-body textarea { width: 100%; min-width: 0; }
.modal-body textarea { min-height: 210px; resize: vertical; padding: 10px; border: 1px solid #ccd4df; border-radius: 4px; font: 13px Consolas, monospace; }
.modal-actions { min-height: 64px; display: flex; justify-content: flex-end; align-items: center; gap: 8px; padding: 0 18px; border-top: 1px solid var(--line); background: #f8f9fb; }
.toast-region { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: grid; gap: 8px; }
.toast { width: min(360px, calc(100vw - 40px)); padding: 12px 14px; border: 1px solid #cad3df; border-left: 4px solid var(--green); border-radius: 5px; background: #fff; box-shadow: 0 10px 28px rgba(25,40,65,.18); }
.toast.error { border-left-color: var(--red); }

@media (max-width: 1250px) {
  .metric-band { grid-template-columns: repeat(4, minmax(130px, 1fr)); }
  .metric:nth-child(4) { border-right: 0; }
  .metric:nth-child(-n+4) { border-bottom: 1px solid var(--line); }
  .order-filters label { flex: 1 1 170px; }
  .order-filters input, .order-filters select { width: 100%; }
  .creator-summary { grid-template-columns: repeat(3, minmax(130px, 1fr)); }
  .creator-summary-item:nth-child(3n) { border-right: 0; }
  .creator-summary-item:nth-child(-n+3) { border-bottom: 1px solid var(--line); }
  .account-profile { grid-template-columns: repeat(3, minmax(130px, 1fr)); }
  .account-profile > div:nth-child(3) { border-right: 0; }
  .account-profile > div:nth-child(-n+3) { border-bottom: 1px solid var(--line); }
}

@media (max-width: 820px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -230px; width: 220px; transition: left .18s ease; box-shadow: 10px 0 30px rgba(14,28,48,.18); }
  .sidebar.open { left: 0; }
  .mobile-menu { display: inline-grid !important; }
  .topbar { padding: 0 12px; }
  .content { padding: 16px 12px; }
  .profile-button > span:not(.avatar), .role-badge { display: none; }
  .page-heading { align-items: flex-start; }
  .heading-actions { flex-wrap: wrap; justify-content: flex-end; }
  .metric-band { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric, .metric:nth-child(4) { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
  .metric:nth-child(2n) { border-right: 0; }
  .metric:last-child { border-bottom: 0; }
  .order-summary { grid-template-columns: 1fr; }
  .order-summary .summary-cell { border-right: 0; border-bottom: 1px solid var(--line); }
  .order-summary .summary-cell:last-child { border-bottom: 0; }
  .account-profile { grid-template-columns: 1fr; }
  .account-profile > div { border-right: 0; border-bottom: 1px solid var(--line); }
  .account-profile > div:last-child { border-bottom: 0; }
}

@media (max-width: 520px) {
  .login-panel { padding: 28px 22px 30px; }
  .page-heading { display: grid; }
  .heading-actions { justify-content: flex-start; }
  .filter-band > label, .filter-band label.grow { min-width: 100%; flex: 1 1 100%; }
  .filter-band input, .filter-band select { width: 100%; }
  .metric-band { grid-template-columns: 1fr; }
  .metric { border-right: 0 !important; }
  .creator-summary { grid-template-columns: 1fr; }
  .creator-summary-item { border-right: 0 !important; border-bottom: 1px solid var(--line); }
  .creator-summary-item:last-child { border-bottom: 0; }
}
