:root {
  --canvas: #f5f7fb;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --line: #e5eaf2;
  --text: #172033;
  --muted: #667085;
  --blue: #215ad5;
  --blue-dark: #1948ad;
  --green: #047857;
  --green-soft: #e8faf3;
  --amber: #b45309;
  --amber-soft: #fff6e7;
  --red: #b42318;
  --red-soft: #fff0ef;
  --radius: 16px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--canvas); color: var(--text); }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .7; }
a { color: inherit; text-decoration: none; }

.topbar {
  min-height: 66px; display: flex; align-items: center; justify-content: space-between;
  gap: 20px; padding: 0 5vw; background: rgba(255,255,255,.9); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5; backdrop-filter: blur(12px);
}
.brand, .topbar-actions, .title-row, .section-heading, .group-head, .window-row, .window-actions { display: flex; align-items: center; }
.brand { gap: 10px; font-weight: 750; letter-spacing: -.02em; }
.brand-mark { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; background: var(--blue); color: white; font-weight: 800; font-size: 24px; box-shadow: 0 8px 24px #215ad544; }
.brand-mark.small { width: 32px; height: 32px; border-radius: 10px; font-size: 16px; box-shadow: none; }
.topbar-actions { gap: 18px; }
.page { width: min(1180px, 100% - 40px); margin: 0 auto; padding: 56px 0 72px; }
.intro { display: flex; align-items: flex-end; justify-content: space-between; gap: 28px; margin-bottom: 32px; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(28px, 4vw, 42px); line-height: 1.1; letter-spacing: -.045em; margin-bottom: 12px; }
h2 { margin-bottom: 4px; font-size: 21px; letter-spacing: -.025em; }
h3 { margin-bottom: 3px; font-size: 17px; }
.eyebrow { margin-bottom: 8px; color: var(--blue); font-size: 11px; font-weight: 800; letter-spacing: .11em; }
.muted, .hint, .group-ref, .empty { color: var(--muted); line-height: 1.55; }
.intro .muted { max-width: 720px; margin-bottom: 0; }
.hint { margin: 14px 0 0; font-size: 13px; }

.primary, .secondary, .text-button, .icon-button {
  border: 0; border-radius: 10px; font-weight: 700; transition: transform .15s, background .15s, border-color .15s;
}
.primary, .secondary { padding: 10px 14px; }
.primary { color: white; background: var(--blue); box-shadow: 0 5px 14px #215ad52c; }
.primary:hover { background: var(--blue-dark); transform: translateY(-1px); }
.secondary { color: var(--blue); background: #eef3ff; border: 1px solid #d9e4ff; }
.secondary:hover { background: #e2ebff; }
.text-button { padding: 7px 9px; color: var(--blue); background: transparent; }
.text-button:hover { background: #eef3ff; }
.wide { width: 100%; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 28px; }
.stats article, .panel, .group-card, .empty-state { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 22px rgba(16, 24, 40, .025); }
.stats article { padding: 18px; }
.stats span, .stats small { display: block; color: var(--muted); font-size: 13px; }
.stats strong { display: block; margin: 7px 0 2px; font-size: 30px; line-height: 1; letter-spacing: -.04em; }
.stats small { font-size: 12px; }
.panel { padding: 26px; margin: 28px 0; }
.section-heading { justify-content: space-between; gap: 16px; }
.balance-result { margin: 18px 0; min-height: 48px; display: flex; align-items: center; border-radius: 12px; padding: 12px 14px; background: var(--surface-muted); color: var(--muted); font-weight: 650; }
.balance-result.success { color: var(--green); background: var(--green-soft); }
.balance-result.error { color: var(--red); background: var(--red-soft); }
.balance-result.pending { color: var(--blue); background: #eff4ff; }

label { display: grid; gap: 7px; color: #344054; font-size: 13px; font-weight: 650; }
input, textarea { width: 100%; padding: 10px 11px; border: 1px solid #d7deea; border-radius: 9px; color: var(--text); background: white; outline: none; }
textarea { resize: vertical; }
input:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px #215ad51a; }
.settings-form { display: grid; grid-template-columns: minmax(0, 2.5fr) minmax(120px, .7fr) auto; align-items: end; gap: 14px; }
code { padding: 2px 5px; border-radius: 5px; background: #edf1f8; color: #344054; }

.section-title { display: flex; justify-content: space-between; align-items: end; margin: 40px 0 16px; }
.groups { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.group-card { padding: 20px; }
.group-card.is-paused { background: #fbfcfe; }
.group-head { justify-content: space-between; gap: 10px; }
.title-row { gap: 8px; }
.group-ref { margin: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.notes { margin: 13px 0 8px; color: #475467; font-size: 13px; line-height: 1.5; white-space: pre-wrap; }
.consent { margin: 13px 0; font-size: 12px; color: var(--amber); font-weight: 700; }
.consent.confirmed { color: var(--green); }
.pill { display: inline-flex; align-items: center; width: max-content; padding: 4px 7px; border-radius: 999px; color: var(--amber); background: var(--amber-soft); font-size: 11px; font-weight: 800; white-space: nowrap; }
.pill.active { color: var(--green); background: var(--green-soft); }
.pill.ready { color: var(--blue); background: #eaf0ff; }
.pill.paused { color: #667085; background: #edf0f4; }
.windows { border-top: 1px solid var(--line); }
.window-row { justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.window-row strong, .window-row span { display: block; }
.window-row strong { font-size: 14px; }
.window-row span { margin-top: 3px; color: var(--muted); font-size: 12px; }
.window-actions { gap: 5px; }
.icon-button { width: 28px; height: 28px; display: grid; place-items: center; color: #475467; background: #f1f4f8; font-size: 18px; }
.icon-button:hover { background: #e7edf4; }
.icon-button.danger:hover { color: var(--red); background: var(--red-soft); }

details { margin-top: 15px; }
summary { color: var(--blue); cursor: pointer; font-weight: 750; font-size: 13px; }
.window-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; padding-top: 14px; border-top: 1px dashed #d9e0eb; }
.window-form fieldset { grid-column: 1 / -1; margin: 0; padding: 0; border: 0; }
.window-form legend { margin-bottom: 8px; color: #475467; font-size: 13px; font-weight: 650; }
.day-picks { display: flex; flex-wrap: wrap; gap: 7px; }
.day-picks label, .check { display: flex; align-items: center; gap: 5px; width: auto; font-size: 12px; font-weight: 600; }
.day-picks input, .check input { width: auto; accent-color: var(--blue); }
.window-form button { grid-column: 1 / -1; width: max-content; }
.empty-state { padding: 38px; grid-column: 1 / -1; text-align: center; }
.empty-state p { margin: 6px 0 0; color: var(--muted); }

.add-panel { margin-top: 28px; }
.add-group-form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 20px; }
.wide-field { grid-column: 1 / -1; }
.add-group-form button { width: max-content; }
.audit-panel { margin-bottom: 0; }
.audit-list { display: grid; margin-top: 17px; border-top: 1px solid var(--line); }
.audit-list > div { display: grid; grid-template-columns: 152px 100px 110px 1fr; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); align-items: start; font-size: 13px; }
.audit-list time, .audit-list span, .audit-list p { color: var(--muted); }
.audit-list p { margin: 0; line-height: 1.45; }

.notice { padding: 12px 14px; margin: 0 0 18px; border-radius: 10px; font-size: 14px; font-weight: 650; }
.notice.success { color: var(--green); background: var(--green-soft); }
.notice.error { color: var(--red); background: var(--red-soft); }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at 10% 0%, #dce7ff 0, transparent 35%), var(--canvas); }
.login-card { width: min(430px, 100%); padding: 36px; background: rgba(255,255,255,.92); border: 1px solid var(--line); border-radius: 20px; box-shadow: 0 24px 70px rgba(28, 56, 104, .12); }
.login-card .brand-mark { margin-bottom: 24px; }
.login-card h1 { font-size: 30px; }
.stack-form { display: grid; gap: 16px; margin-top: 24px; }

@media (max-width: 820px) {
  .page { width: min(100% - 28px, 620px); padding: 32px 0 44px; }
  .topbar { padding: 0 14px; }
  .intro, .section-heading { align-items: flex-start; flex-direction: column; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .groups { grid-template-columns: 1fr; }
  .settings-form { grid-template-columns: 1fr; }
  .settings-form button { width: max-content; }
  .audit-list > div { grid-template-columns: 1fr 1fr; gap: 5px 12px; }
  .audit-list > div p { grid-column: 1 / -1; }
}

@media (max-width: 480px) {
  .desktop-only { display: none; }
  .panel { padding: 19px; }
  .stats article { padding: 14px; }
  .stats strong { font-size: 25px; }
  .group-card { padding: 16px; }
  .add-group-form { grid-template-columns: 1fr; }
  .wide-field { grid-column: auto; }
  .window-form { grid-template-columns: 1fr; }
  .window-form button { grid-column: auto; width: 100%; }
  .add-group-form button { width: 100%; }
  .login-card { padding: 28px 22px; }
}
