[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; }

:root {
  color-scheme: light;
  --canvas: #f3f5f8;
  --card: #ffffff;
  --ink: #1b2430;
  --muted: #5c6b7c;
  --line: #e6e8ec;
  --brand: #1f4fd8;
  --brand-ink: #ffffff;
  --soft: #eef3ff;
  --danger: #b42318;
  --ok: #067647;
  --shadow: 0 10px 30px rgba(22, 32, 51, 0.08);
}

html, body { margin: 0; padding: 0; }
body {
  min-height: 100vh;
  background: var(--canvas);
  color: var(--ink);
  font: 14px/1.5 "Segoe UI", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
pre, input, select, textarea { max-width: 100%; }
img, svg, canvas { max-width: 100%; }

.gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}
.login-card, .card, .confirm-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.login-card { width: min(440px, 100%); padding: 28px 28px 24px; }
.brand-kicker {
  margin: 0;
  color: var(--brand);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.brand-title { margin: 4px 0 0; font-size: 28px; line-height: 1.2; }
.brand-sub, .hint, .step-line { color: var(--muted); }
.brand-sub { margin: 6px 0 18px; }
.tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.tab, .ghost, .secondary, .primary, .danger, .icon-button, .nav-item, .bar-btn {
  border-radius: 10px;
  border: 1px solid transparent;
}
.tab {
  flex: 1;
  background: transparent;
  border-color: var(--line);
  padding: 8px 10px;
}
.tab.is-active { background: var(--soft); border-color: #d5e1ff; color: var(--brand); }
.field { display: flex; flex-direction: column; gap: 6px; margin: 0 0 14px; font-size: 13px; }
.field input, .field select, .toolbar input, .toolbar select, .bar-label select {
  width: 100%;
  border: 1px solid #d8dee8;
  background: #fff;
  border-radius: 10px;
  padding: 10px 12px;
}
.field input:focus, .field select:focus, .toolbar input:focus, .toolbar select:focus {
  border-color: var(--brand);
  outline: none;
  box-shadow: 0 0 0 3px rgba(31, 79, 216, 0.15);
}
.is-invalid { border-color: #f04438 !important; box-shadow: 0 0 0 3px rgba(240, 68, 56, 0.15); }
.password-row { position: relative; display: block; }
.password-row input { padding-right: 44px; }
.icon-button {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--muted);
}
.password-row .icon-button { position: absolute; right: 4px; top: 4px; }
.icon-button svg, .nav-item svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.primary, .secondary, .danger, .ghost {
  padding: 10px 14px;
}
.primary { background: var(--brand); color: var(--brand-ink); width: 100%; }
.secondary { background: #fff; border-color: var(--line); }
.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.danger { background: #fff; color: var(--danger); border-color: #f3c3bf; }
.primary:disabled, .secondary:disabled, .ghost:disabled, .danger:disabled, .bar-btn:disabled {
  opacity: 0.6;
  cursor: progress;
}
.field-error { color: var(--danger); margin: 0 0 12px; }
.check { display: flex; gap: 8px; align-items: flex-start; margin: 0 0 14px; color: var(--muted); }
.check span { min-width: 0; flex: 1 1 auto; overflow-wrap: anywhere; }
.check input { margin-top: 3px; }
.step-title { margin: 0 0 8px; font-size: 22px; text-align: center; }
.otp-input {
  font-size: 28px;
  letter-spacing: 0.35em;
  text-align: center;
  height: 64px;
}
.compat-field {
  position: absolute;
  left: 0;
  top: 0;
  width: 8px;
  height: 8px;
  padding: 0;
  margin: 0;
  border: 0;
  opacity: 0;
  overflow: hidden;
}
#login-form { position: relative; }
.secret, .mono-wrap {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  word-break: break-all;
}
.secret { margin: 8px 0; }
canvas { display: block; margin: 12px auto; background: #fff; }

.app-shell { display: flex; min-height: 100vh; align-items: stretch; }
.sidebar {
  width: 220px;
  flex: 0 0 220px;
  align-self: stretch;
  min-height: 100vh;
  background: var(--card);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 18px 12px 12px;
}
.side-brand { padding: 0 8px 12px; }
.side-name { margin: 2px 0 0; font-weight: 650; }
.side-nav { display: flex; flex-direction: column; gap: 4px; overflow: auto; flex: 1; min-height: 0; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: transparent;
  padding: 9px 10px;
  color: var(--ink);
}
.nav-item span { min-width: 0; }
.nav-item.is-active { background: var(--soft); color: var(--brand); }
.nav-badge {
  margin-left: auto;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: #e11d48;
  color: #fff;
  font-size: 12px;
  line-height: 20px;
  text-align: center;
}
.user-card {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfcfe;
}
.user-name { margin: 0 0 6px; font-weight: 650; word-break: break-all; }
.role-pill {
  display: inline-flex;
  margin: 0 0 10px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--brand);
  font-size: 12px;
}
.user-card .ghost { width: 100%; }
.workspace { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.workspace, .content, .panel, .table-wrap, .toolbar, .form-grid, .login-card, .card, .check { min-width: 0; }
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.topbar h2 { margin: 0; font-size: 20px; }
.nav-toggle { display: none; background: #fff; border: 1px solid var(--line); border-radius: 10px; width: 40px; height: 40px; align-items: center; justify-content: center; }
.burger, .burger::before, .burger::after {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--ink);
  position: relative;
}
.burger::before, .burger::after { content: ""; position: absolute; left: 0; }
.burger::before { top: -6px; }
.burger::after { top: 6px; }
.content { padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.panel { display: flex; flex-direction: column; gap: 16px; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr)); gap: 16px; }
.kpi, .card { padding: 16px 18px; }
.kpi p { margin: 0; }
.kpi-label { color: var(--muted); font-size: 13px; }
.kpi-value { margin-top: 6px; font-size: 26px; font-weight: 680; letter-spacing: -0.02em; }
.sync-card h3, .section-title, .form-grid h3 { margin: 0 0 8px; }
.section-title { margin-top: 8px; }
.form-grid { padding: 18px; display: flex; flex-direction: column; }
.toolbar, .pager, .row-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.toolbar label, .bar-label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); min-width: 0; }
.toolbar .grow { flex: 1 1 180px; }
.table-wrap { display: block; overflow-x: auto; max-width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 14px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; }
tr.is-clickable { cursor: pointer; }
tr.is-selected { background: #f5f8ff; }
.id-chip {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  max-width: 168px;
  display: inline-block;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
}
.copy-btn { margin-left: 6px; }
.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.pill-gold { background: #fff6d8; color: #8a5a00; }
.pill-usable, .pill-paid, .pill-active { background: #e7f6ee; color: var(--ok); }
.pill-hold { background: #eef2ff; color: #3340a0; }
.pill-reject, .pill-disabled { background: #fdecec; color: var(--danger); }
.pill-unreviewed, .pill-reversed { background: #f2f4f7; color: #475467; }
.pill-unpaid, .pill-unconfigured { background: #fff6e8; color: #b54708; }
.pill-holdout { background: #f4ecff; color: #6941c6; }
.pill-eligible { background: #e7f6ee; color: var(--ok); }
.pill-settled { background: #eef2ff; color: #3340a0; }
.pill-ineligible { background: #f2f4f7; color: #475467; }
.guide {
  margin: 0;
  background: #fff7ed;
  border: 1px solid #f9dbaf;
  color: #93370d;
  border-radius: 12px;
  padding: 12px 16px;
}
.quota { margin: 0; color: var(--muted); }
.pager { align-items: center; }
.toast {
  position: fixed;
  z-index: 80;
  top: 12px;
  right: 24px;
  bottom: auto;
  left: auto;
  width: fit-content;
  max-width: min(280px, calc(100% - 520px));
  margin: 0;
  overflow-wrap: anywhere;
  background: #102017;
  color: #fff;
  border-radius: 999px;
  padding: 10px 16px;
  box-shadow: var(--shadow);
}
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.35);
  border: 0;
  z-index: 40;
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: min(440px, 100%);
  background: var(--card);
  border-left: 1px solid var(--line);
  z-index: 45;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}
.drawer-head, .drawer-body { padding: 16px 18px; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); gap: 12px; }
.drawer-head h3 { margin: 0; min-width: 0; word-break: break-all; }
.drawer-body { overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.drawer-body .primary, .drawer-body .danger, .drawer-body .secondary { width: auto; }
.member-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-width: 0; }
.member-row span { min-width: 0; overflow-wrap: anywhere; }
.batch-bar {
  position: fixed;
  z-index: 55;
  left: 244px;
  right: 24px;
  bottom: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  background: #172033;
  color: #fff;
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}
.bar-btn { background: #2a3854; color: #fff; border-color: transparent; padding: 8px 10px; }
.ghost-bar { background: transparent; border-color: #3d4d6e; }
.bar-label { color: #d5dbe7; }
.bar-label select { background: #fff; color: var(--ink); width: auto; min-width: 120px; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(17, 24, 39, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.confirm-card { width: min(440px, 100%); padding: 22px; }
.confirm-card .primary { width: auto; }
.invite-message { white-space: pre-wrap; word-break: break-word; }
.rate-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; color: var(--muted); }
.empty { color: var(--muted); margin: 0; padding: 8px 0; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.row-actions { justify-content: flex-end; }

@media (max-width: 900px) {
  .nav-toggle { display: inline-flex; }
  .sidebar {
    position: fixed;
    z-index: 50;
    left: 0;
    top: 0;
    height: 100%;
    min-height: 0;
    width: min(280px, 86vw);
    flex: none;
    transform: translateX(-105%);
  }
  .sidebar.is-open { transform: none; }
  .content, .topbar { padding-left: 16px; padding-right: 16px; }
  .toast {
    top: 76px;
    right: 12px;
    bottom: auto;
    left: auto;
    max-width: min(220px, calc(100% - 24px));
    margin: 0;
  }
  .batch-bar { left: 12px; right: 12px; }
  .login-card { padding: 22px 16px; }
  th, td { padding: 10px 12px; }
}
