/* Theme controls keep the existing toolbar height and never submit a form. */
.theme-toggle { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 36px; width: 36px; height: 36px; min-height: 36px; padding: 8px; }
.theme-toggle[hidden], .theme-icon-dark { display: none; }
.theme-toggle span { align-items: center; justify-content: center; line-height: 0; }
.theme-icon-light { display: inline-flex; }
:root[data-theme="light"] .theme-icon-light { display: none; }
:root[data-theme="light"] .theme-icon-dark { display: inline-flex; }
.login-card { position: relative; }
.login-card > .theme-toggle { position: absolute; top: 12px; right: 12px; }
.client-header > div { flex-shrink: 0; }
.client-brand strong { white-space: normal; overflow-wrap: anywhere; }

@media (max-width: 760px) {
    .workspace-bar { gap: 8px; }
    .workspace-bar .branch-switch { flex: 1; max-width: 260px; }
    .workspace-bar .branch-switch select { flex: 1; width: 0; min-width: 72px; }
    .workspace-bar #navigation-toggle, .workspace-logo { flex-shrink: 0; }
}
@media (max-width: 380px) {
    .client-header, .client-header > div { gap: 8px; }
    .client-brand strong { font-size: 13px; }
}

/* Screen-only palette leaves receipts and printed reports unchanged. */
@media screen {
    :root[data-theme="light"], :root[data-theme="light"] body {
        color-scheme: light;
        --bg: #f4f6f8;
        --surface: #ffffff;
        --surface-raised: #edf0f3;
        --ink: #20242a;
        --muted: #59616b;
        --line: #d5dbe1;
        --ok: #176243;
        --warn: #805400;
        --danger: #b32635;
        --link-ink: #894300;
        --selected-bg: #fff0d8;
        --selected-line: #e3b67c;
    }
    :root[data-theme="light"] * { scrollbar-color: #b0b7bf #edf0f3; }
    :root[data-theme="light"] body,
    :root[data-theme="light"] .shell,
    :root[data-theme="light"] .client-shell,
    :root[data-theme="light"] .login-shell { background: var(--bg); }
    :root[data-theme="light"] .sidebar,
    :root[data-theme="light"] .sidebar .brand,
    :root[data-theme="light"] .workspace-bar,
    :root[data-theme="light"] .client-header { background: var(--surface); border-color: var(--line); box-shadow: none; }
    :root[data-theme="light"] .brand div > span,
    :root[data-theme="light"] .nav-section,
    :root[data-theme="light"] .sidebar nav a .lucide { color: var(--muted); }
    :root[data-theme="light"] .sidebar nav a { color: #424a54; }
    :root[data-theme="light"] .sidebar nav a:hover,
    :root[data-theme="light"] .userbox a:hover { background: var(--surface-raised); color: var(--ink); }
    :root[data-theme="light"] .sidebar nav a.active { color: var(--link-ink); background: var(--selected-bg); border-color: var(--selected-line); }
    :root[data-theme="light"] .sidebar nav a.active .lucide { color: var(--link-ink); }
    :root[data-theme="light"] .user-avatar { background: var(--surface-raised); color: var(--muted); border-color: var(--line); }
    :root[data-theme="light"] .userbox { border-color: var(--line); }
    :root[data-theme="light"] :is(.brand-mark, .workspace-logo, .login-logo, .client-brand img) { filter: drop-shadow(0 0 1px #46505c); }
    :root[data-theme="light"] label,
    :root[data-theme="light"] .filter-bar label,
    :root[data-theme="light"] .portal-form label { color: #424a54; }
    :root[data-theme="light"] input:not([type="checkbox"]):not([type="radio"]),
    :root[data-theme="light"] select,
    :root[data-theme="light"] textarea { color: var(--ink); background-color: var(--surface); border-color: #aeb7c2; }
    :root[data-theme="light"] input::placeholder,
    :root[data-theme="light"] textarea::placeholder { color: #69717b; }
    :root[data-theme="light"] input[readonly],
    :root[data-theme="light"] input:disabled,
    :root[data-theme="light"] select:disabled { background: var(--surface-raised); color: var(--muted); }
    :root[data-theme="light"] input[type="file"]::file-selector-button { background: var(--surface-raised); color: var(--ink); }
    :root[data-theme="light"] button,
    :root[data-theme="light"] .button,
    :root[data-theme="light"] .record-actions .icon-button,
    :root[data-theme="light"] .module-actions .success { color: #303842; background: var(--surface); border-color: #b8c0c9; }
    :root[data-theme="light"] button:hover,
    :root[data-theme="light"] .button:hover,
    :root[data-theme="light"] .record-actions .icon-button:hover { color: var(--ink); background: var(--surface-raised); border-color: #818d9a; }
    :root[data-theme="light"] .primary { color: #15110b; background: var(--primary); border-color: var(--primary); }
    :root[data-theme="light"] .primary:hover { color: #15110b; background: var(--primary-dark); border-color: var(--primary-dark); }
    :root[data-theme="light"] .danger,
    :root[data-theme="light"] .operation-cancel button { color: var(--danger); background: #fff0f1; border-color: #e2a8ae; }
    :root[data-theme="light"] .nav-backdrop { background: #0006; }
    :root[data-theme="light"] .module-notice { color: #745000; background: #fff5d6; border-color: #b78325; }
    :root[data-theme="light"] .module-error,
    :root[data-theme="light"] .checkin-warning { color: var(--danger); background: #ffecef; border-color: #e2a8ae; }
    :root[data-theme="light"] .flash { color: var(--ok); background: #e5f5ed; border-color: #99c8b1; }
    :root[data-theme="light"] .module-table { background: var(--surface); border-color: var(--line); }
    :root[data-theme="light"] th,
    :root[data-theme="light"] .module-table th,
    :root[data-theme="light"] .record-table th.record-controls { color: #4a535f; background: #e9edf1; border-color: var(--line); }
    :root[data-theme="light"] td,
    :root[data-theme="light"] .module-table td { color: #303842; border-color: var(--line); }
    :root[data-theme="light"] .module-table tr:nth-child(even) td { background: #f6f8fa; }
    :root[data-theme="light"] .module-table tr:hover td,
    :root[data-theme="light"] tbody tr:hover td,
    :root[data-theme="light"] .dashboard-table tr[data-member-row]:focus-within td { background: #eaf0f4; }
    :root[data-theme="light"] .record-table .table-link,
    :root[data-theme="light"] .report-totals dd { color: var(--ink); }
    :root[data-theme="light"] .table-link,
    :root[data-theme="light"] .module-tabs a[aria-current="page"],
    :root[data-theme="light"] .record-actions a[href*="socio_membresias"] { color: var(--link-ink); }
    :root[data-theme="light"] .record-actions a[href*="socio_membresias"] { background: var(--selected-bg); border-color: var(--selected-line); }
    :root[data-theme="light"] .status-label.ok, :root[data-theme="light"] .badge.ok { color: var(--ok); background: #e0f2e9; }
    :root[data-theme="light"] .status-label.warn, :root[data-theme="light"] .badge.warn { color: var(--warn); background: #fff0c6; }
    :root[data-theme="light"] .status-label.danger, :root[data-theme="light"] .badge.danger { color: var(--danger); background: #ffe7eb; }
    :root[data-theme="light"] .status-label.muted, :root[data-theme="light"] .badge.muted { color: #505963; background: #e8ecf0; }
    :root[data-theme="light"] .metrics:not(.member-kpis) article { background: var(--surface); border-color: var(--line); }
    :root[data-theme="light"] .metrics article:last-child { border-top-color: var(--primary); }
    :root[data-theme="light"] .metrics span,
    :root[data-theme="light"] .metrics .lucide { color: var(--muted); }
    :root[data-theme="light"] .quick-actions a:hover { background: var(--surface-raised); }
    :root[data-theme="light"] .quick-actions span,
    :root[data-theme="light"] .dashboard-empty strong { color: var(--ink); }
    :root[data-theme="light"] .quick-actions .lucide,
    :root[data-theme="light"] .metrics article:last-child .lucide { color: var(--link-ink); }
    :root[data-theme="light"] .member-detail-card .member-photo.compact,
    :root[data-theme="light"] .membership-facts,
    :root[data-theme="light"] .member-fields span,
    :root[data-theme="light"] .routine-tabs { background: var(--surface-raised); border-color: var(--line); }
    :root[data-theme="light"] .row-actions { background: var(--surface-raised); }
    :root[data-theme="light"] .row-actions a { background: var(--surface); }
    :root[data-theme="light"] .row-actions a.primary { background: var(--selected-bg); color: var(--link-ink); border-color: var(--selected-line); }
    :root[data-theme="light"] .row-actions a.danger { background: #ffe7eb; color: var(--danger); border-color: #e2a8ae; }
    :root[data-theme="light"] .checkin-board,
    :root[data-theme="light"] .checkin-footer,
    :root[data-theme="light"] .access-card { background: var(--surface); border-color: var(--line); }
    :root[data-theme="light"] .checkin-footer,
    :root[data-theme="light"] .checkin-footer div a,
    :root[data-theme="light"] .gym-logo { color: var(--ink); }
    :root[data-theme="light"] .gym-logo img { filter: drop-shadow(0 0 1px #46505c); }
    :root[data-theme="light"] .checkin-header { background: var(--surface-raised); border-color: var(--line); }
    :root[data-theme="light"] .checkin-header h2,
    :root[data-theme="light"] .routine-tabs span,
    :root[data-theme="light"] .routine-tabs a,
    :root[data-theme="light"] .routine-grid span { color: var(--ink); }
    :root[data-theme="light"] .checkin-header p,
    :root[data-theme="light"] .birthday-message p { color: var(--muted); }
    :root[data-theme="light"] .routine-tabs a:hover,
    :root[data-theme="light"] .routine-tabs a:focus-visible { background: #dde4eb; color: var(--link-ink); }
    :root[data-theme="light"] .birthday-message h2 span,
    :root[data-theme="light"] .birthday-message .birthday-eyebrow { color: var(--link-ink); }
    :root[data-theme="light"] .checkin-footer div a { background: var(--surface-raised); border-color: #b8c0c9; }
    :root[data-theme="light"] .login-card { background: var(--surface); border-color: var(--line); border-top-color: var(--primary); box-shadow: none; }
    :root[data-theme="light"] .login-card .eyebrow { color: var(--link-ink); }
    :root[data-theme="light"] .login-audience { border-color: var(--line); }
    :root[data-theme="light"] .login-audience a { color: var(--muted); }
    :root[data-theme="light"] .login-audience a[aria-current] { background: var(--selected-bg); color: var(--link-ink); }
    :root[data-theme="light"] .client-header a,
    :root[data-theme="light"] .client-links > a,
    :root[data-theme="light"] .client-help summary,
    :root[data-theme="light"] .client-overview strong { color: var(--ink); }
    :root[data-theme="light"] .client-header > div > span,
    :root[data-theme="light"] .client-heading p,
    :root[data-theme="light"] .client-overview span,
    :root[data-theme="light"] .client-overview p,
    :root[data-theme="light"] .client-offer p,
    :root[data-theme="light"] .client-offer-top,
    :root[data-theme="light"] .client-login-note,
    :root[data-theme="light"] .client-help,
    :root[data-theme="light"] .client-empty,
    :root[data-theme="light"] .client-pagination,
    :root[data-theme="light"] .client-key { color: var(--muted); }
    :root[data-theme="light"] .client-nav { background: transparent; }
    :root[data-theme="light"] .client-nav a,
    :root[data-theme="light"] .client-days a { color: #424a54; }
    :root[data-theme="light"] .client-nav a[aria-current] { color: var(--link-ink); background: var(--selected-bg); }
    :root[data-theme="light"] .client-overview a,
    :root[data-theme="light"] .client-links > a .lucide:first-child,
    :root[data-theme="light"] .client-offer-price,
    :root[data-theme="light"] .client-offer-top .lucide,
    :root[data-theme="light"] .client-required { color: var(--link-ink); }
    :root[data-theme="light"] .client-offer { background: var(--surface); border-color: var(--line); border-top-color: var(--primary); }
    :root[data-theme="light"] :is(.client-nav, .client-overview, .client-overview > div + div, .client-links, .client-days, .client-required, .client-empty, .client-shell .table-wrap, .client-access) { border-color: var(--line); }
    :root[data-theme="light"] .halloween-season .topbar,
    :root[data-theme="light"] .halloween-season .quick-actions,
    :root[data-theme="light"] .halloween-season .module-tabs { border-color: var(--line); }
    :root[data-theme="light"] .halloween-season .topbar h1,
    :root[data-theme="light"] .halloween-season .panel-head h2 { color: var(--ink); }
    :root[data-theme="light"] .halloween-season .topbar .eyebrow,
    :root[data-theme="light"] .halloween-badge span,
    :root[data-theme="light"] .halloween-login strong,
    :root[data-theme="light"] .halloween-login span { color: var(--link-ink); }
    :root[data-theme="light"] .halloween-season .checkin-header { background: var(--surface-raised) url('halloween-gym-2026.webp') right 112px center / 100px auto no-repeat; }
    :root[data-theme="light"] .halloween-season .checkin-header h2,
    :root[data-theme="light"] .halloween-season .checkin-header p { max-width: calc(100% - 110px); }
}
@media screen and (max-width: 680px) {
    :root[data-theme="light"] .halloween-season .checkin-header { background-image: none; }
    :root[data-theme="light"] .halloween-season .checkin-header h2,
    :root[data-theme="light"] .halloween-season .checkin-header p { max-width: none; }
}
@media print {
    .theme-toggle { display: none !important; }
}
