:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #182230;
  --muted: #667085;
  --line: #d8dee8;
  --line-dark: #b8c1ce;
  --blue: #175cd3;
  --blue-dark: #144da8;
  --blue-soft: #eff6ff;
  --danger: #b42318;
  --danger-soft: #fff4f2;
  --success: #067647;
  --radius: 6px;
}

* { box-sizing: border-box; }
html { color: var(--text); background: var(--bg); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
body { min-width: 320px; min-height: 100vh; margin: 0; }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
a { color: var(--blue); }

.topbar { position: sticky; top: 0; z-index: 20; display: flex; height: 58px; align-items: center; justify-content: space-between; padding: 0 max(22px, calc((100vw - 1240px) / 2)); color: #fff; background: #182230; border-bottom: 1px solid #101828; }
.wordmark { color: #fff; font-weight: 650; text-decoration: none; letter-spacing: -.01em; }
.topbar-actions, .profile-form { display: flex; align-items: center; gap: 12px; }
.profile-form label { color: #cbd5e1; font-size: 12px; }
.profile-form select { min-width: 180px; color: #fff; background: #27364a; border: 1px solid #475467; border-radius: 4px; padding: 6px 30px 6px 9px; }
.topbar .text-button { color: #e2e8f0; }

.dashboard { width: min(1240px, calc(100% - 44px)); margin: 0 auto; padding: 34px 0 72px; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 22px; }
.page-header h1 { margin: 2px 0 0; font-size: 30px; line-height: 1.2; letter-spacing: -.025em; }
.overline { margin: 0; color: var(--muted); font-size: 12px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase; }
.profile-id { margin: 5px 0 0; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.status { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.status i { width: 8px; height: 8px; background: #12b76a; border-radius: 50%; }

.section { margin-bottom: 18px; padding: 22px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.section-header { margin-bottom: 18px; }
.section-header.split { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; }
.section-header h2 { margin: 0 0 3px; font-size: 17px; letter-spacing: -.01em; }
.section-header p, .help { margin: 0; color: var(--muted); font-size: 13px; }
.poll-note { flex: 0 0 auto; color: var(--muted); font-size: 12px; }

.toggle-list { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: 5px; overflow: hidden; }
.toggle-row { display: flex; min-width: 0; align-items: center; justify-content: space-between; gap: 18px; padding: 14px 16px; border-right: 1px solid var(--line); }
.toggle-row:last-child { border: 0; }
.toggle-row strong, .toggle-row > div > span { display: block; }
.toggle-row strong { font-size: 14px; }
.toggle-row > div > span { margin-top: 2px; color: var(--muted); font-size: 12px; }
.switch { position: relative; width: 38px; height: 22px; flex: 0 0 38px; padding: 0; background: #d0d5dd; border: 0; border-radius: 20px; transition: background .12s ease; }
.switch span { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; background: white; border-radius: 50%; box-shadow: 0 1px 2px rgba(16,24,40,.25); transition: transform .12s ease; }
.switch.active { background: var(--blue); }
.switch.active span { transform: translateX(16px); }

.schedule-list { border-top: 1px solid var(--line); }
.day-schedule { display: grid; grid-template-columns: 105px minmax(0, 1fr) 104px; align-items: start; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.day-name { padding-top: 27px; font-weight: 650; }
.window-list { display: grid; gap: 8px; }
.time-window { display: flex; align-items: end; gap: 9px; }
.time-window label span, .field { display: block; color: var(--muted); font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .035em; }
.time-window input, .field input { display: block; width: 132px; margin-top: 3px; padding: 7px 9px; color: var(--text); background: #fff; border: 1px solid var(--line-dark); border-radius: 4px; }
.time-separator { margin-bottom: 8px; color: var(--muted); font-size: 12px; }
.icon-button, .remove-rule, .text-button { padding: 0; color: var(--muted); background: transparent; border: 0; font-size: 12px; text-decoration: none; }
.icon-button { margin: 0 0 8px 4px; }
.icon-button:hover, .remove-rule:hover { color: var(--danger); }
.add-window { align-self: center; margin-top: 25px; color: var(--blue); text-align: left; }
.form-footer { display: flex; align-items: end; justify-content: space-between; gap: 20px; padding-top: 18px; }
.field input { width: 220px; text-transform: none; letter-spacing: normal; }
.form-actions { display: flex; align-items: center; gap: 12px; }
.save-status { color: var(--muted); font-size: 12px; }
.save-status.success { color: var(--success); }
.save-status.error, .inline-error { color: var(--danger); }

.rules-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.rule-section { min-width: 0; }
.add-rule { display: grid; grid-template-columns: minmax(0, 1fr) minmax(135px, .65fr) auto; align-items: end; gap: 8px; padding: 12px; background: #f8fafc; border: 1px solid var(--line); border-radius: 5px; }
.add-rule label > span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 11px; font-weight: 650; text-transform: uppercase; }
.add-rule select, .rule-row select { width: 100%; min-width: 0; padding: 7px 28px 7px 9px; color: var(--text); background: white; border: 1px solid var(--line-dark); border-radius: 4px; }
.rule-table { margin-top: 14px; border-top: 1px solid var(--line); }
.rule-row { display: grid; grid-template-columns: minmax(105px, 1fr) 168px 48px; align-items: center; gap: 10px; min-height: 51px; border-bottom: 1px solid var(--line); }
.rule-row strong { overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.remove-rule { text-align: right; }
.empty { margin: 14px 0 0; color: var(--muted); font-size: 13px; }

.advanced summary { font-size: 15px; font-weight: 650; cursor: pointer; }
.advanced > .help { margin: 8px 0 18px; }
.native-schedule { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 28px; border-top: 1px solid var(--line); }
.native-day { display: grid; grid-template-columns: 82px 1fr auto 1fr; align-items: center; gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
.native-day input { min-width: 0; width: 100%; padding: 6px; border: 1px solid var(--line-dark); border-radius: 4px; }

.access-section { display: grid; grid-template-columns: .75fr 1.25fr; gap: 42px; }
.audit-list { max-height: 310px; overflow: auto; margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.audit-list li { display: flex; justify-content: space-between; gap: 20px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.audit-list small { display: block; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.audit-list time { flex: 0 0 auto; color: var(--muted); font-size: 12px; }

.button { display: inline-flex; min-height: 36px; align-items: center; justify-content: center; padding: 8px 13px; border: 1px solid transparent; border-radius: 4px; font-weight: 600; text-decoration: none; transition: background .12s ease, border-color .12s ease; }
.button.primary { color: white; background: var(--blue); border-color: var(--blue); }
.button.primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
.button.secondary { color: var(--text); background: white; border-color: var(--line-dark); }
.button.secondary:hover { background: #f8fafc; }
.button.small { min-height: 34px; padding: 6px 11px; font-size: 13px; }
.button:disabled, select:disabled { cursor: not-allowed; opacity: .55; }

.auth-shell { min-height: calc(100vh - 58px); display: grid; place-items: center; padding: 38px 20px; }
.auth-panel { width: min(460px, 100%); padding: 30px; background: white; border: 1px solid var(--line); border-radius: 7px; box-shadow: 0 8px 24px rgba(16,24,40,.06); }
.auth-panel h1 { margin: 6px 0 8px; font-size: 25px; letter-spacing: -.025em; }
.auth-panel h2 { font-size: 17px; }
.lede { margin: 0 0 22px; color: var(--muted); }
.stack { display: grid; gap: 8px; margin-top: 18px; }
.stack label { color: var(--muted); font-size: 12px; font-weight: 650; }
.stack input { padding: 9px 10px; border: 1px solid var(--line-dark); border-radius: 4px; }
.compact { margin-top: 14px; }
.recovery-login, .recovery-created { margin-top: 24px; }
pre { overflow: auto; padding: 13px; background: #f1f5f9; border: 1px solid var(--line); border-radius: 4px; font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; }
.recovery-box { margin-top: 16px; }
.banner { margin-bottom: 18px; padding: 11px 13px; border: 1px solid; border-radius: 4px; }
.banner.error { color: var(--danger); background: var(--danger-soft); border-color: #fda29b; }
.htmx-request { pointer-events: none; opacity: .55; }

@media (max-width: 900px) {
  .toggle-list, .rules-grid, .access-section { grid-template-columns: 1fr; }
  .toggle-row { border-right: 0; border-bottom: 1px solid var(--line); }
  .native-schedule { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
  .topbar { position: static; height: auto; min-height: 58px; padding: 10px 16px; }
  .topbar-actions { gap: 8px; }
  .profile-form label { display: none; }
  .profile-form select { min-width: 130px; max-width: 44vw; }
  .dashboard { width: calc(100% - 24px); padding-top: 22px; }
  .page-header, .section-header.split, .form-footer { align-items: flex-start; flex-direction: column; }
  .section { padding: 16px; }
  .day-schedule { grid-template-columns: 1fr; gap: 8px; }
  .day-name, .add-window { padding-top: 0; margin-top: 0; }
  .time-window { flex-wrap: wrap; }
  .time-window label { flex: 1; min-width: 115px; }
  .time-window input { width: 100%; }
  .icon-button { margin-bottom: 8px; }
  .add-rule { grid-template-columns: 1fr; }
  .rule-row { grid-template-columns: minmax(85px, 1fr) 148px; padding: 8px 0; }
  .remove-rule { grid-column: 2; }
  .form-actions, .field, .field input { width: 100%; }
  .form-actions { justify-content: space-between; }
}
