:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --surface-muted: #eef2f6;
  --border: #dfe5ec;
  --border-strong: #cbd4df;
  --text: #182230;
  --text-secondary: #526173;
  --text-muted: #788699;
  --primary: #1769e0;
  --primary-hover: #1259c1;
  --primary-soft: #eaf2ff;
  --success: #12805c;
  --success-soft: #e7f6ef;
  --warning: #a15c00;
  --warning-soft: #fff3db;
  --danger: #c0362c;
  --danger-soft: #fdecea;
  --info: #1769e0;
  --info-soft: #eaf2ff;
  --shadow-drawer: -16px 0 40px rgba(20, 33, 50, .16);
  --radius-sm: 6px;
  --radius: 9px;
  --radius-lg: 12px;
  --content-width: 1280px;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--bg); }

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button { color: inherit; }
a { color: inherit; text-decoration: none; }
svg { display: block; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 3px solid rgba(23, 105, 224, .26);
  outline-offset: 2px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 64px;
  background: rgba(255, 255, 255, .96);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.topbar-inner {
  width: min(calc(100% - 40px), var(--content-width));
  min-height: 64px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand { display: inline-flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--primary);
  border-radius: var(--radius);
}
.brand-mark svg { width: 21px; height: 21px; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 14px; line-height: 1.25; letter-spacing: .01em; }
.brand small { margin-top: 2px; color: var(--text-muted); font-size: 11px; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }
.topbar-actions form { margin: 0; }

.page-shell {
  width: min(calc(100% - 40px), var(--content-width));
  margin: 0 auto;
  padding: 38px 0 32px;
}

.page-heading {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 24px;
  margin-bottom: 20px;
}
.eyebrow { margin: 0 0 5px; color: var(--primary); font-size: 10px; font-weight: 750; letter-spacing: .16em; }
.page-heading h1 { margin: 0; font-size: clamp(24px, 3vw, 30px); line-height: 1.2; letter-spacing: -.025em; }
.page-heading p:not(.eyebrow) { margin: 7px 0 0; color: var(--text-secondary); }
.button.mobile-primary-action { display: none; }

.button {
  min-height: 38px;
  padding: 8px 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  font-weight: 650;
  cursor: pointer;
  transition: background-color .16s ease, border-color .16s ease, color .16s ease, transform .16s ease;
}
.button:hover { transform: translateY(-1px); }
.button:active { transform: translateY(0); }
.button-compact { min-height: 34px; padding: 6px 11px; font-size: 13px; }
.button-primary { color: #fff; background: var(--primary); border-color: var(--primary); }
.button-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.button-secondary { color: var(--text); background: var(--surface); border-color: var(--border-strong); }
.button-secondary:hover { background: var(--surface-subtle); border-color: #adb9c7; }
.button-ghost { color: var(--text-secondary); }
.button-ghost:hover { color: var(--text); background: var(--surface-muted); }
.button-danger { color: #fff; background: var(--danger); border-color: var(--danger); }
.button-danger:hover { background: #a82d25; }
.button-danger-text { margin-right: auto; color: var(--danger); }
.button-danger-text:hover { background: var(--danger-soft); }
.button-icon { width: 16px; height: 16px; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

.status-badge {
  min-height: 28px;
  padding: 4px 9px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border-radius: 999px;
  color: var(--text-secondary);
  background: var(--surface-muted);
  font-size: 12px;
  font-weight: 680;
  white-space: nowrap;
}
.status-small { min-height: 24px; padding: 3px 8px; font-size: 11px; }
.status-dot { width: 7px; height: 7px; flex: none; border-radius: 50%; background: currentColor; }
.status-success { color: var(--success); background: var(--success-soft); }
.status-warning { color: var(--warning); background: var(--warning-soft); }
.status-danger, .status-error { color: var(--danger); background: var(--danger-soft); }
.status-info, .status-generating { color: var(--info); background: var(--info-soft); }
.status-neutral, .status-idle { color: var(--text-secondary); background: var(--surface-muted); }

.flash-stack { display: grid; gap: 8px; margin-bottom: 16px; }
.flash { padding: 11px 13px; display: flex; align-items: flex-start; gap: 9px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.flash svg { width: 18px; height: 18px; flex: none; margin-top: 1px; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.flash-success { color: var(--success); border-color: #bfe5d4; background: var(--success-soft); }
.flash-error { color: var(--danger); border-color: #f0c6c2; background: var(--danger-soft); }

.overview-card,
.login-card,
.content-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.overview-card {
  min-height: 132px;
  padding: 20px 22px;
  display: grid;
  grid-template-columns: minmax(270px, 1.1fr) 2fr;
  align-items: center;
  gap: 24px;
}
.overview-primary { min-width: 0; display: flex; align-items: center; gap: 14px; }
.overview-icon { width: 44px; height: 44px; flex: none; display: grid; place-items: center; border-radius: var(--radius); color: var(--text-secondary); background: var(--surface-muted); }
.overview-icon svg { width: 24px; height: 24px; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.overview-icon-success { color: var(--success); background: var(--success-soft); }
.overview-icon-danger { color: var(--danger); background: var(--danger-soft); }
.overview-icon-info { color: var(--info); background: var(--info-soft); }
.metric-label { display: block; margin-bottom: 3px; color: var(--text-secondary); font-size: 12px; font-weight: 650; }
.metric-main-row { display: flex; align-items: center; gap: 9px; }
.metric-main-row > strong { font-size: 18px; letter-spacing: -.01em; }
.overview-primary small { display: block; margin-top: 4px; color: var(--text-muted); font-size: 11px; }
.overview-metrics { margin: 0; display: grid; grid-template-columns: repeat(4, 1fr); }
.overview-metrics > div { min-width: 0; padding: 3px 20px; border-left: 1px solid var(--border); }
.overview-metrics dt { color: var(--text-secondary); font-size: 12px; }
.overview-metrics dd { margin: 5px 0 0; font-size: 23px; font-weight: 720; letter-spacing: -.025em; }
.overview-metrics dd span { color: var(--text-muted); font-size: 12px; font-weight: 500; }
.text-danger { color: var(--danger) !important; }

.login-card { margin-top: 16px; overflow: hidden; }
.login-summary { min-height: 78px; padding: 16px 20px; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 13px; }
.summary-icon { width: 36px; height: 36px; display: grid; place-items: center; color: var(--primary); background: var(--primary-soft); border-radius: var(--radius); }
.summary-icon svg { width: 20px; height: 20px; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.section-title-row { display: flex; align-items: center; gap: 9px; }
.section-title-row h2 { margin: 0; font-size: 17px; letter-spacing: -.01em; }
.login-copy { min-width: 0; }
.login-copy p { margin: 4px 0 0; color: var(--text-secondary); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.muted-text { color: var(--text-muted); font-size: 12px; }
.qr-workspace { padding: 24px; display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 28px; border-top: 1px solid var(--border); background: var(--surface-subtle); }
.qr-frame { width: 230px; height: 230px; padding: 12px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
.qr-frame img { width: 100%; height: 100%; display: block; object-fit: contain; image-rendering: crisp-edges; }
.qr-placeholder { display: grid; place-items: center; gap: 10px; color: var(--text-muted); text-align: center; font-size: 12px; }
.qr-placeholder svg { width: 52px; height: 52px; stroke: currentColor; stroke-width: 1.2; }
.qr-instructions { align-self: center; max-width: 510px; }
.qr-kicker { color: var(--primary); font-size: 10px; font-weight: 750; letter-spacing: .12em; }
.qr-instructions h3 { margin: 6px 0 12px; font-size: 18px; }
.qr-instructions ol { margin: 0; padding-left: 20px; color: var(--text-secondary); }
.qr-instructions li + li { margin-top: 5px; }
.qr-meta { min-height: 20px; margin: 15px 0 0; display: flex; flex-wrap: wrap; gap: 14px; color: var(--primary); font-size: 12px; font-weight: 650; }
.privacy-note { margin: 7px 0 0; color: var(--text-muted); font-size: 11px; }

.content-card { margin-top: 16px; overflow: hidden; }
.section-header { padding: 20px 22px 17px; display: flex; align-items: end; justify-content: space-between; gap: 24px; border-bottom: 1px solid var(--border); }
.section-header > div:first-child > p:last-child { margin: 5px 0 0; color: var(--text-secondary); font-size: 12px; }
.count-badge { min-width: 24px; height: 24px; padding: 0 7px; display: inline-grid; place-items: center; border-radius: 999px; color: var(--text-secondary); background: var(--surface-muted); font-size: 11px; font-weight: 700; }
.section-actions { display: flex; align-items: center; gap: 8px; }
.search-field { position: relative; width: min(260px, 25vw); }
.search-field svg { position: absolute; top: 50%; left: 11px; width: 16px; height: 16px; transform: translateY(-50%); stroke: var(--text-muted); stroke-width: 1.6; stroke-linecap: round; pointer-events: none; }
.search-field input,
.filter-field select,
.field input,
.field select,
.field textarea {
  width: 100%;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color .16s ease, box-shadow .16s ease;
}
.search-field input { height: 36px; padding: 7px 10px 7px 34px; }
.filter-field select { height: 36px; padding: 6px 30px 6px 10px; }
.search-field input:hover, .filter-field select:hover, .field input:hover, .field select:hover, .field textarea:hover { border-color: #aeb9c6; }
.search-field input:focus, .filter-field select:focus, .field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); outline: 0; box-shadow: 0 0 0 3px rgba(23, 105, 224, .13); }

.table-wrap { width: 100%; overflow-x: auto; }
.subscriber-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.subscriber-table th { padding: 10px 14px; color: var(--text-muted); background: var(--surface-subtle); border-bottom: 1px solid var(--border); font-size: 10px; font-weight: 750; letter-spacing: .06em; text-align: left; text-transform: uppercase; }
.subscriber-table td { padding: 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.subscriber-table tbody tr { transition: background-color .14s ease; }
.subscriber-table tbody tr:hover { background: #fafcff; }
.subscriber-table tbody tr:last-child td { border-bottom: 0; }
.subscriber-table th:nth-child(1) { width: 23%; }
.subscriber-table th:nth-child(2) { width: 13%; }
.subscriber-table th:nth-child(3) { width: 21%; }
.subscriber-table th:nth-child(4) { width: 15%; }
.subscriber-table th:nth-child(5) { width: auto; }
.subscriber-table th:nth-child(6) { width: 54px; }
.identity-cell { min-width: 0; display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; flex: none; display: grid; place-items: center; color: var(--primary); background: var(--primary-soft); border-radius: 50%; font-size: 12px; font-weight: 760; }
.identity-cell > div { min-width: 0; }
.identity-cell strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.identity-cell small, .cell-note { display: block; margin-top: 3px; color: var(--text-muted); font-size: 10px; }
.chip-list { display: flex; flex-wrap: wrap; gap: 4px; }
.code-chip { padding: 3px 6px; color: #43546a; background: var(--surface-muted); border-radius: 4px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 10px; font-weight: 650; }
.table-value { font-size: 12px; font-weight: 650; }
.note-cell { display: block; overflow: hidden; color: var(--text-secondary); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.action-cell { text-align: right; }
.icon-button { width: 34px; height: 34px; padding: 0; display: inline-grid; place-items: center; color: var(--text-secondary); background: transparent; border: 1px solid transparent; border-radius: var(--radius-sm); cursor: pointer; }
.icon-button:hover { color: var(--text); background: var(--surface-muted); }
.icon-button svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.empty-state { min-height: 260px; padding: 40px 20px; display: grid; place-items: center; align-content: center; text-align: center; }
.empty-icon { width: 48px; height: 48px; margin-bottom: 12px; display: grid; place-items: center; color: var(--text-muted); background: var(--surface-muted); border-radius: 50%; }
.empty-icon svg { width: 24px; height: 24px; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.empty-state strong { font-size: 15px; }
.empty-state p { margin: 5px 0 15px; color: var(--text-secondary); font-size: 12px; }

.page-footer { padding: 18px 2px 0; display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 7px 10px; color: var(--text-muted); font-size: 10px; }
.page-footer code { max-width: 50vw; padding: 2px 5px; overflow: hidden; color: var(--text-secondary); background: var(--surface-muted); border-radius: 4px; text-overflow: ellipsis; white-space: nowrap; }

dialog { color: var(--text); }
dialog::backdrop { background: rgba(21, 32, 46, .42); backdrop-filter: blur(2px); }
.drawer {
  width: min(560px, 100vw);
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0 0 0 auto;
  padding: 0;
  overflow: hidden;
  background: var(--surface);
  border: 0;
  box-shadow: var(--shadow-drawer);
}
.drawer[open] { display: block; animation: drawer-in .2s ease-out; }
@keyframes drawer-in { from { transform: translateX(26px); opacity: .7; } to { transform: translateX(0); opacity: 1; } }
.drawer form { height: 100%; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.drawer-header { padding: 22px 24px 18px; display: flex; justify-content: space-between; gap: 24px; border-bottom: 1px solid var(--border); }
.drawer-header h2 { margin: 0; font-size: 21px; letter-spacing: -.02em; }
.drawer-header p:last-child { margin: 5px 0 0; color: var(--text-secondary); font-size: 12px; }
.drawer-body { padding: 0 24px 30px; overflow-y: auto; }
.form-section { padding: 24px 0; border-bottom: 1px solid var(--border); }
.form-section:last-child { border-bottom: 0; }
.form-section-heading { margin-bottom: 17px; display: flex; align-items: center; gap: 10px; }
.form-section-heading > span { width: 26px; height: 26px; display: grid; place-items: center; color: var(--primary); background: var(--primary-soft); border-radius: 50%; font-size: 10px; font-weight: 750; }
.form-section-heading strong, .form-section-heading small { display: block; }
.form-section-heading strong { font-size: 13px; }
.form-section-heading small { margin-top: 1px; color: var(--text-muted); font-size: 10px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.field { display: block; }
.field + .field-full { margin-top: 15px; }
.field > span { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 6px; color: var(--text-secondary); font-size: 11px; font-weight: 650; }
.field > span em { color: var(--text-muted); font-style: normal; font-weight: 400; }
.field input, .field select { min-height: 40px; padding: 8px 10px; }
.field textarea { min-height: 80px; padding: 9px 10px; resize: vertical; }
.field > small { display: block; margin-top: 5px; color: var(--text-muted); font-size: 10px; }
.drawer-footer { min-height: 72px; padding: 14px 24px; display: flex; align-items: center; justify-content: flex-end; gap: 8px; background: var(--surface); border-top: 1px solid var(--border); }
.form-dirty-state { margin-right: auto; color: var(--warning); font-size: 10px; }
.button-danger-text:not([hidden]) + .form-dirty-state { margin-right: 0; }

.confirm-dialog { width: min(420px, calc(100vw - 32px)); padding: 0; border: 0; border-radius: var(--radius-lg); box-shadow: 0 18px 50px rgba(20, 33, 50, .2); }
.confirm-dialog form { padding: 26px; }
.confirm-icon { width: 42px; height: 42px; display: grid; place-items: center; color: var(--danger); background: var(--danger-soft); border-radius: 50%; }
.confirm-icon svg { width: 21px; height: 21px; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.confirm-dialog h2 { margin: 16px 0 6px; font-size: 19px; }
.confirm-dialog p { margin: 0; color: var(--text-secondary); font-size: 12px; }
.confirm-dialog p strong { color: var(--text); }
.confirm-actions { margin-top: 22px; display: flex; justify-content: flex-end; gap: 8px; }

.login-page { min-height: 100dvh; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.login-shell { width: min(400px, 100%); }
.login-brand { margin-bottom: 22px; display: flex; align-items: center; justify-content: center; gap: 11px; }
.login-brand strong, .login-brand small { display: block; }
.login-brand strong { font-size: 15px; }
.login-brand small { margin-top: 2px; color: var(--text-muted); font-size: 11px; }
.login-panel { padding: 28px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.login-panel h1 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.login-panel > p { margin: 7px 0 22px; color: var(--text-secondary); font-size: 12px; }
.login-panel .field { margin-bottom: 16px; }
.login-submit { width: 100%; }
.login-notice { margin-bottom: 16px; padding: 10px 11px; color: var(--danger); background: var(--danger-soft); border-radius: var(--radius-sm); font-size: 11px; }
.login-footer { margin-top: 15px; color: var(--text-muted); font-size: 10px; text-align: center; }

@media (max-width: 980px) {
  .overview-card { grid-template-columns: 1fr; }
  .overview-metrics > div:first-child { border-left: 0; }
  .section-header { align-items: flex-start; flex-direction: column; }
  .section-actions { width: 100%; }
  .search-field { width: auto; flex: 1; }
  .subscriber-table th:nth-child(5), .subscriber-table td:nth-child(5) { display: none; }
}

@media (max-width: 720px) {
  .topbar-inner, .page-shell { width: min(calc(100% - 24px), var(--content-width)); }
  .topbar-actions > .status-badge, .topbar-actions > .button-primary { display: none; }
  .page-shell { padding-top: 26px; }
  .page-heading { align-items: center; }
  .page-heading p:not(.eyebrow) { max-width: 240px; }
  .button.mobile-primary-action { display: inline-flex; flex: none; }
  .overview-card { padding: 18px; }
  .overview-metrics { grid-template-columns: 1fr 1fr; gap: 15px 0; }
  .overview-metrics > div { padding: 0 14px; }
  .overview-metrics > div:nth-child(odd) { padding-left: 0; border-left: 0; }
  .login-summary { grid-template-columns: auto minmax(0, 1fr); }
  .login-summary > .button, .login-summary > .muted-text { grid-column: 1 / -1; width: 100%; }
  .login-copy p { white-space: normal; }
  .qr-workspace { grid-template-columns: 1fr; justify-items: center; }
  .qr-instructions { width: 100%; }
  .section-header { padding: 18px; }
  .section-actions { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
  .search-field { width: 100%; }
  .desktop-add-action { display: none; }
  .table-wrap { overflow: visible; }
  .subscriber-table, .subscriber-table tbody { display: block; }
  .subscriber-table thead { display: none; }
  .subscriber-table tbody { padding: 0 16px; }
  .subscriber-table tbody tr { position: relative; padding: 15px 44px 15px 0; display: grid; grid-template-columns: 1fr 1fr; gap: 13px 18px; border-bottom: 1px solid var(--border); }
  .subscriber-table td { padding: 0; display: block !important; border: 0; }
  .subscriber-table td::before { content: attr(data-label); margin-bottom: 4px; display: block; color: var(--text-muted); font-size: 9px; font-weight: 700; letter-spacing: .06em; }
  .subscriber-table td:first-child { grid-column: 1 / -1; }
  .subscriber-table td:first-child::before, .subscriber-table .action-cell::before { display: none; }
  .subscriber-table .action-cell { position: absolute; top: 12px; right: 0; }
  .note-cell { white-space: normal; }
  .page-footer { align-items: flex-start; flex-direction: column; }
  .page-footer code { max-width: 100%; }
  .drawer { width: 100vw; }
}

@media (max-width: 480px) {
  .brand small { display: none; }
  .page-heading p:not(.eyebrow) { display: none; }
  .page-heading h1 { font-size: 23px; }
  .overview-primary { align-items: flex-start; }
  .metric-main-row { align-items: flex-start; flex-direction: column; gap: 5px; }
  .overview-metrics dd { font-size: 20px; }
  .qr-frame { width: min(230px, 100%); height: auto; aspect-ratio: 1; }
  .filter-field { min-width: 105px; }
  .subscriber-table tbody tr { grid-template-columns: 1fr; }
  .subscriber-table td:first-child { grid-column: auto; }
  .field-grid { grid-template-columns: 1fr; }
  .drawer-header, .drawer-body { padding-left: 18px; padding-right: 18px; }
  .drawer-footer { padding: 12px 18px; flex-wrap: wrap; }
  .drawer-footer .button-danger-text { width: 100%; margin: 0; justify-content: flex-start; }
  .form-dirty-state { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
