/* Musician Payroll - theming system.
   Colors, logo, and terminology are swappable per organization via
   Settings, so this works for other clients without touching this file. */

:root {
    /* Overridden per-org via an inline <style> block in base.html,
       sourced from Settings.primary_color / secondary_color.
       These are just fallback defaults if that's ever missing. */
    --color-primary: #001685;
    --color-secondary: #e60000;

    --color-bg: #f7f6f2;
    --color-surface: #ffffff;
    --color-border: #e2ded4;
    --color-border-strong: #cfc9ba;
    --color-text: #23241f;
    --color-text-muted: #6b6a5f;
    --color-danger: #9a3324;

    --font-display: "Manrope", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    --font-mono: "IBM Plex Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;

    --radius-sm: 6px;
    --radius: 10px;
    --shadow-sm: 0 1px 2px rgba(20, 20, 10, 0.05);
    --shadow-md: 0 8px 24px rgba(20, 20, 10, 0.08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font-body);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 15px;
    line-height: 1.5;
}

/* ---------- Sidebar nav ---------- */

.app-shell {
    display: flex;
    align-items: flex-start;
    min-height: 100vh;
}

.sidenav {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    width: 232px;
    padding: 20px 16px;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    position: sticky;
    top: 0;
}

.sidenav-header {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    margin-bottom: 20px;
}

.sidenav-brand {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 16px;
    color: var(--color-primary);
    text-decoration: none;
    line-height: 1.3;
    min-width: 0;
}

.sidenav-brand span {
    overflow-wrap: break-word;
}

.sidenav-logo {
    width: 100%;
    height: auto;
    max-height: 120px;
    object-fit: contain;
    object-position: left;
    display: block;
    border-radius: var(--radius-sm);
}

.nav-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text);
    cursor: pointer;
}

.nav-toggle:hover { background: var(--color-bg); filter: none; }

.nav-toggle .icon-close { display: none; }
.sidenav.open .nav-toggle .icon-menu { display: none; }
.sidenav.open .nav-toggle .icon-close { display: block; }

.sidenav-links {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.sidenav-links a {
    display: block;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--color-text);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    opacity: 0.85;
}

.sidenav-links a:hover { opacity: 1; background: var(--color-bg); color: var(--color-primary); }

.sidenav-links a.active {
    opacity: 1;
    background: color-mix(in srgb, var(--color-primary) 10%, transparent);
    color: var(--color-primary);
    font-weight: 600;
}

.sidenav-logout {
    margin-top: auto !important;
    padding-top: 14px !important;
    border-top: 1px solid var(--color-border);
}

/* ---------- Layout ---------- */

.page {
    flex: 1;
    min-width: 0;
    max-width: 980px;
    margin: 0 auto;
    padding: 40px 28px 72px;
}

/* Pages built around a dense, wide table (many rows/columns) opt into
   this instead of the standard reading-width cap above. */
.page-wide {
    max-width: none;
}

h1 {
    font-family: var(--font-display);
    font-size: 27px;
    font-weight: 600;
    margin: 0 0 18px;
    color: var(--color-text);
}

h2 {
    font-family: var(--font-display);
    font-size: 17px;
    font-weight: 600;
    margin: 0 0 14px;
}

.subtitle {
    color: var(--color-text-muted);
    margin: 0 0 24px;
    font-size: 14px;
}

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 22px;
    margin-bottom: 22px;
}

/* ---------- Ledger-style tables ---------- */

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

th, td {
    text-align: left;
    padding: 11px 16px;
    border-bottom: 1px solid var(--color-border);
    font-size: 14px;
}

/* Denser variant for pages that can run to many rows (e.g. a weekly
   pay run) - same table, tighter row height. */
.table-compact th, .table-compact td { padding: 7px 14px; }
.table-compact .void-note { padding: 4px 0; }

/* Flat variant - drops the border/rounded corners/shadow that make a
   table read as its own boxed widget, leaving just the header and row
   divider lines. For pages that already widen past the normal reading
   column (see .page-wide) and don't need the extra visual weight. */
.table-flat {
    border: none;
    border-radius: 0;
    box-shadow: none;
}
.table-flat th { background: transparent; }

/* Expand/collapse for a grouped payment row's services - collapsed
   shows a plain summary line; open reveals one checkbox per service so
   a bookkeeper can hold back individual ones before printing/paying. */
.row-expand > summary {
    cursor: pointer;
    color: var(--color-text);
}
.row-expand > summary:hover { color: var(--color-primary); }
.row-expand-list {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.row-expand-item {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-size: 13.5px;
    color: var(--color-text-muted);
}
.row-expand-item input { width: auto; }
.row-expand[open] > summary { display: none; }

th {
    background: var(--color-bg);
    font-family: var(--font-body);
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.06em;
    border-bottom: 2px solid var(--color-border-strong);
}

tbody tr:nth-child(even) { background: rgba(0, 0, 0, 0.015); }
tr:last-child td { border-bottom: none; }

.sort-link {
    color: inherit;
    text-decoration: none;
}

.sort-link:hover { color: var(--color-primary); }

.sort-arrow {
    margin-left: 3px;
    color: var(--color-primary);
}

.amount {
    font-family: var(--font-mono);
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.badge-eligible { background: #fde8e3; color: var(--color-danger); }
.badge-not-eligible { background: #e8ece5; color: var(--color-primary); }
.badge-irregular { background: rgba(201, 161, 59, 0.18); color: var(--color-secondary); }
.badge-archived { background: var(--color-border); color: var(--color-text-muted); }

/* ---------- Help tooltip ("?" icon) ---------- */

.help-tooltip {
    position: relative;
    display: inline-block;
    margin-left: 6px;
    vertical-align: middle;
}

/* vertical-align alone doesn't reliably center a small icon against
   different heading font sizes/metrics - flexing the containing
   heading/label centers it against the actual text box instead. */
h1:has(.help-tooltip),
h2:has(.help-tooltip),
h3:has(.help-tooltip),
label:has(.help-tooltip) {
    display: flex;
    align-items: center;
}

.help-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: none;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: color 0.15s ease, background-color 0.15s ease;
}

.help-icon svg { display: block; }

.help-icon:hover,
.help-icon:focus-visible {
    color: var(--color-primary);
    background: var(--color-border);
}

.help-tooltip-content {
    display: none;
    position: absolute;
    z-index: 10;
    top: 130%;
    left: 0;
    width: 260px;
    max-width: 70vw;
    padding: 10px 12px;
    background: var(--color-text);
    color: var(--color-surface);
    font-size: 13px;
    font-weight: 400;
    text-transform: none;
    letter-spacing: normal;
    line-height: 1.4;
    border-radius: 4px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}

.help-tooltip.open .help-tooltip-content {
    display: block;
}

/* ---------- Shared confirm/prompt modal (replaces native confirm()) ---------- */

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(20, 20, 10, 0.4);
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}

.modal-overlay.open {
    display: flex;
}

.modal-card {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 24px;
    max-width: 420px;
    width: 100%;
}

.modal-card p {
    margin: 0 0 16px;
    font-size: 14.5px;
    line-height: 1.5;
}

.modal-reason-wrap {
    display: none;
}

.modal-reason-wrap.shown {
    display: block;
}

.modal-card textarea {
    width: 100%;
    min-height: 70px;
    padding: 9px 12px;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    background: var(--color-surface);
    color: var(--color-text);
    margin-bottom: 16px;
    resize: vertical;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.modal-actions button {
    margin-top: 0;
}

/* ---------- Settings: same-line singular/plural label pairs ---------- */

.label-pair-row {
    display: flex;
    gap: 12px;
}

.label-pair-row input {
    flex: 1;
    min-width: 0;
}

/* ---------- Forms ---------- */

form { max-width: 480px; }

/* A .page-wide page opted out of the standard reading-width cap - its
   forms shouldn't silently get re-narrowed back down by the rule
   above (e.g. Pay Runs' whole table lives inside one <form>). */
.page-wide form { max-width: none; }

label {
    display: block;
    font-size: 12.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin: 16px 0 5px;
    color: var(--color-text-muted);
}

input[type="text"], input[type="email"], input[type="password"],
input[type="date"], input[type="number"], input[type="tel"], select, textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    background: var(--color-surface);
    color: var(--color-text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type="color"] {
    width: 60px;
    height: 38px;
    padding: 2px;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 18%, transparent);
}

button, .btn {
    display: inline-block;
    margin-top: 20px;
    padding: 10px 20px;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    box-shadow: var(--shadow-sm);
    transition: filter 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

button:hover, .btn:hover { filter: brightness(0.92); box-shadow: var(--shadow-md); }
button:active, .btn:active { transform: translateY(1px); }

.btn-secondary {
    background: transparent;
    color: var(--color-primary);
    border: 1px solid var(--color-primary);
    box-shadow: none;
}
.btn-secondary:hover { background: color-mix(in srgb, var(--color-primary) 6%, transparent); filter: none; box-shadow: none; }

/* ---------- Flash messages ---------- */

.flash-container { margin-bottom: 20px; }

.flash {
    padding: 11px 16px;
    border-radius: 3px;
    margin-bottom: 8px;
    font-size: 14px;
    border-left: 3px solid transparent;
}

.flash-success { background: #eef2eb; color: var(--color-primary); border-left-color: var(--color-primary); }
.flash-error { background: #fce9e4; color: var(--color-danger); border-left-color: var(--color-danger); }

/* ---------- Login ---------- */

.login-wrap {
    max-width: 380px;
    margin: 90px auto;
    padding: 36px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-top: 4px solid var(--color-primary);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
}

.login-wrap h1 { border-bottom: none; padding-bottom: 0; }

/* ---------- Misc ---------- */

.actions-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.inline-form { display: inline; }

.btn-tiny { margin: 0; padding: 2px 8px; font-size: 12.5px; }

.void-note {
    font-size: 13px;
    color: var(--color-danger);
    padding: 8px 0;
}

.empty-state {
    text-align: center;
    padding: 52px 24px;
    color: var(--color-text-muted);
    font-style: italic;
}

.bulk-actions-group {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.bulk-actions-group select {
    width: auto;
    margin: 0;
    padding: 9px 11px;
}

.bulk-actions-group button {
    margin: 0;
}

/* ---------- Bulk-create season: repeating rehearsal patterns ---------- */

.rehearsal-pattern {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid var(--color-border);
}

.rehearsal-pattern-header {
    justify-content: space-between;
}

.pattern-heading {
    margin: 0;
    font-family: var(--font-display);
    font-size: 15px;
}

.btn-remove-pattern {
    margin-top: 0;
}

.btn-add-pattern {
    margin-top: 14px;
}

.weekday-picker {
    display: flex;
    gap: 6px;
    margin-top: 6px;
}

.weekday-pill {
    width: 34px;
    height: 34px;
    padding: 0;
    margin-top: 0;
    border-radius: 50%;
    border: 1px solid var(--color-border-strong);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
}

.weekday-pill:hover { filter: none; background: var(--color-bg); }

.weekday-pill.selected {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: white;
}

.ends-picker {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
}

.ends-option {
    margin-top: 0;
    padding: 7px 14px;
    background: transparent;
    color: var(--color-text-muted);
    border: 1px solid var(--color-border-strong);
}

.ends-option.selected {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

.ends-picker input {
    width: auto;
    flex: 0 0 110px;
}

.ends-suffix {
    color: var(--color-text-muted);
    font-size: 13px;
}

.ends-inactive {
    opacity: 0.4;
}

/* ---------- Bulk-assign musicians: group/checklist picker ---------- */

.musician-group-block {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid var(--color-border);
}

.musician-group-block:first-child {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
}

.group-select-all {
    display: flex;
    align-items: center;
    gap: 8px;
    text-transform: none;
    font-weight: 400;
    font-size: 14px;
    color: var(--color-text);
    margin: 0 0 10px;
}

.musician-checklist {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 20px;
    padding-left: 24px;
}

.musician-checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    text-transform: none;
    font-weight: 400;
    font-size: 14px;
    color: var(--color-text);
    margin: 0;
    flex: 0 0 auto;
}

.cards-grid-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 22px;
}

.cards-grid-2col .card {
    margin-bottom: 0;
}

@media (max-width: 720px) {
    .cards-grid-2col {
        grid-template-columns: 1fr;
    }
}

.settings-swatch-row { display: flex; gap: 16px; align-items: center; }
.settings-logo-wrap { margin-bottom: 10px; }
.settings-logo-preview {
    max-height: 60px;
    max-width: 200px;
    border: 1px solid var(--color-border);
    border-radius: 3px;
    padding: 8px;
    background: var(--color-surface);
}

/* ---------- Responsive ---------- */

@media (min-width: 721px) {
    .sidenav {
        height: 100vh;
        overflow-y: auto;
    }
}

@media (max-width: 720px) {
    .app-shell {
        flex-direction: column;
    }

    .sidenav {
        position: sticky;
        width: 100%;
        padding: 14px 18px;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
        z-index: 30;
    }

    /* Full-width stacked logo works for a tall sidebar, but not a slim
       mobile top bar - go back to a compact inline lockup there. */
    .sidenav-header {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        margin-bottom: 0;
    }

    .sidenav-brand {
        flex-direction: row;
        align-items: center;
        gap: 10px;
    }

    .sidenav-logo {
        width: auto;
        height: 30px;
        max-height: none;
        flex-shrink: 0;
    }

    .nav-toggle {
        display: inline-flex;
    }

    .sidenav-links {
        display: none;
        flex-direction: column;
        margin-top: 14px;
        padding-top: 14px;
        border-top: 1px solid var(--color-border);
    }

    .sidenav.open .sidenav-links {
        display: flex;
    }

    .sidenav-logout {
        margin-top: 4px !important;
        padding-top: 10px !important;
    }

    .page {
        padding: 24px 16px 56px;
    }

    h1 {
        font-size: 22px;
    }

    .card {
        padding: 16px;
    }

    /* Tables become horizontally scrollable rather than squeezing
       columns unreadably small or breaking the page layout. */
    table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }

    th, td {
        padding: 9px 12px;
    }

    form {
        max-width: 100%;
    }

    .actions-row {
        gap: 8px;
    }

    button, .btn {
        width: 100%;
        text-align: center;
        box-sizing: border-box;
    }

    .actions-row button, .actions-row .btn {
        width: auto;
    }

    .login-wrap {
        margin: 40px auto;
        padding: 28px 22px;
        max-width: 90%;
    }
}

@media (max-width: 420px) {
    h1 {
        font-size: 19px;
    }
}

/* --- Paid payments locked on the service payments page (CODE_REVIEW.md item 3) --- */
.row-paid td {
    background: #f5f6f8;
    color: #5a6270;
}

.badge-paid {
    background: #e6f4ea;
    color: #1e7e34;
}

/* ---------- Dashboard stat tiles ---------- */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 18px 20px;
}

.stat-label {
    margin: 0 0 8px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
}

.stat-value {
    margin: 0;
    font-family: var(--font-display);
    font-size: 24px;
    font-weight: 700;
    color: var(--color-text);
    font-variant-numeric: tabular-nums;
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
}

.stat-value-sub {
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-muted);
}

/* A pay run that's due now gets the same accent treatment as its badge,
   so it reads as "needs attention" even before you read the number. */
.stat-card-due {
    border-left: 3px solid var(--color-secondary);
}

@media (max-width: 900px) {
    .stat-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .stat-grid {
        grid-template-columns: 1fr;
    }
}
