:root {
    --ink: #172033;
    --muted: #667085;
    --line: #E5E7EB;
    --soft: #F5F7FA;
    --surface: #FFFFFF;
    --navy: #12233F;
    --blue: #2563EB;
    --blue-soft: #EAF1FF;
    --amber: #B45309;
    --amber-soft: #FFF7E6;
    --red: #B42318;
    --red-soft: #FEF3F2;
    --green: #067647;
    --shadow: 0 12px 34px rgba(15, 23, 42, .07);
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--soft); color: var(--ink); font-size: 15px; }
button, input, select { font: inherit; }
a { color: inherit; }

.topbar { min-height: 76px; background: var(--navy); color: white; display: flex; align-items: center; justify-content: space-between; padding: 0 max(24px, calc((100vw - 1180px) / 2)); gap: 28px; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; min-width: 205px; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; background: var(--blue); font-weight: 800; font-size: 19px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.18); }
.brand strong, .brand small { display: block; }
.brand strong { letter-spacing: -.01em; }
.brand small { color: #AFC0DB; font-size: 12px; margin-top: 2px; }
.main-nav { display: flex; align-self: stretch; gap: 4px; }
.main-nav a { display: flex; align-items: center; padding: 0 18px; color: #C7D2E4; text-decoration: none; font-weight: 650; border-bottom: 3px solid transparent; }
.main-nav a:hover, .main-nav a.active { color: white; background: rgba(255,255,255,.045); border-bottom-color: #6EA0FF; }

.shell { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 38px 0 64px; }
.page-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 28px; margin-bottom: 26px; }
.page-heading h1 { margin: 3px 0 6px; font-size: clamp(28px, 4vw, 40px); letter-spacing: -.035em; line-height: 1.05; }
.page-heading p:last-child { margin: 0; color: var(--muted); }
.eyebrow { margin: 0; color: var(--blue); font-size: 12px; line-height: 1.2; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.view-capo .eyebrow { color: var(--green); }
.month-navigation { display: flex; align-items: center; gap: 8px; }
.month-arrow { display: grid; place-items: center; width: 42px; height: 42px; border: 1px solid #D0D5DD; border-radius: 11px; color: var(--navy); background: white; box-shadow: 0 4px 12px rgba(15,23,42,.035); text-decoration: none; font-size: 28px; line-height: 1; }
.month-arrow:hover { color: white; background: var(--blue); border-color: var(--blue); }
.month-switcher { display: flex; align-items: center; gap: 10px; background: white; border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px 8px 14px; box-shadow: 0 4px 12px rgba(15,23,42,.035); }
.month-switcher label { color: var(--muted); font-size: 13px; font-weight: 700; }
.month-switcher input { border: 0; background: var(--soft); border-radius: 8px; padding: 8px 10px; color: var(--ink); }

.flash { margin: -14px 0 24px; padding: 13px 16px; border-radius: 10px; font-weight: 650; }
.flash.ok { color: var(--green); background: #ECFDF3; border: 1px solid #ABEFC6; }
.flash.error { color: var(--red); background: var(--red-soft); border: 1px solid #FECDCA; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 18px; }
.stats.dashboard { grid-template-columns: repeat(4, 1fr); }
.stat { background: white; border: 1px solid var(--line); border-radius: 15px; padding: 19px 21px; box-shadow: 0 5px 18px rgba(15,23,42,.035); }
.stat span, .stat small { display: block; color: var(--muted); }
.stat span { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; }
.stat strong { display: block; font-size: 28px; line-height: 1.2; letter-spacing: -.03em; margin: 6px 0 2px; }
.stat small { font-size: 12px; }
.stat.accent { color: white; background: var(--navy); border-color: var(--navy); }
.stat.accent span, .stat.accent small { color: #BCC9DC; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.quick-entry { padding: 22px; margin-bottom: 18px; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 17px; }
.panel-heading h2 { margin: 3px 0 0; font-size: 20px; letter-spacing: -.02em; }
.quick-row { display: grid; grid-template-columns: 1fr 1.2fr 2fr auto; align-items: end; gap: 14px; }
label { display: grid; gap: 6px; color: #475467; font-size: 12px; font-weight: 750; }
input, select { width: 100%; min-height: 42px; padding: 9px 11px; border: 1px solid #D0D5DD; border-radius: 9px; color: var(--ink); background: white; outline: none; }
input:focus, select:focus { border-color: #84ADFF; box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.shift-kind { border: 0; padding: 0; margin: 0; }
.shift-kind legend { color: #475467; font-size: 12px; font-weight: 750; margin-bottom: 6px; }
.shift-kind { display: grid; grid-template-columns: repeat(3, 1fr); }
.shift-kind label { display: block; }
.shift-kind input { position: absolute; opacity: 0; pointer-events: none; width: 1px; height: 1px; min-height: 0; overflow: hidden; }
.shift-kind span { display: grid; place-items: center; min-height: 42px; padding: 7px 10px; border: 1px solid #D0D5DD; margin-left: -1px; background: white; cursor: pointer; font-size: 13px; }
.shift-kind label:first-of-type span { border-radius: 9px 0 0 9px; margin-left: 0; }
.shift-kind label:last-of-type span { border-radius: 0 9px 9px 0; }
.shift-kind input:checked + span { position: relative; z-index: 1; border-color: var(--blue); background: var(--blue-soft); color: #1849A9; }
.button { display: inline-flex; justify-content: center; align-items: center; min-height: 42px; padding: 9px 15px; border: 1px solid transparent; border-radius: 9px; text-decoration: none; font-weight: 750; cursor: pointer; white-space: nowrap; }
.button.primary, .button:not(.secondary) { color: white; background: var(--blue); border-color: var(--blue); }
.button.primary:hover, .button:not(.secondary):hover { background: #1D4ED8; }
.button.secondary { background: white; color: #344054; border-color: #D0D5DD; }
.button.secondary:hover { background: var(--soft); }
.text-button { border: 0; background: transparent; color: var(--blue); font-weight: 750; cursor: pointer; }
.hidden { display: none !important; }
details { margin-top: 15px; border-top: 1px solid var(--line); padding-top: 12px; }
summary { color: #475467; cursor: pointer; font-size: 13px; font-weight: 700; }
details > .form-grid { margin: 14px 0 12px; }
.form-grid { display: grid; gap: 12px; }
.form-grid.three { grid-template-columns: repeat(3, 1fr); }
.form-grid.four { grid-template-columns: repeat(4, 1fr); }
.form-grid.five { grid-template-columns: repeat(5, 1fr); }
.check-field { align-content: end; grid-template-columns: auto 1fr; align-items: center; min-height: 42px; padding: 8px 10px; border: 1px solid #D0D5DD; border-radius: 9px; }
.check-field input { width: 18px; min-height: 18px; }
.check-field span { font-size: 13px; }

.shifts-panel { overflow: hidden; }
.shifts-panel > .panel-heading { padding: 21px 22px 3px; align-items: center; }
.toolbar { display: flex; gap: 8px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 11px 16px; text-align: left; background: #F8FAFC; color: #667085; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); font-size: 11px; text-transform: uppercase; letter-spacing: .055em; }
td { padding: 13px 16px; border-bottom: 1px solid #EEF1F4; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #FBFCFE; }
td strong, td small { display: block; }
td small { color: var(--muted); font-size: 11px; margin-top: 2px; }
th.money, td.money { text-align: right; white-space: nowrap; }
td.money { font-weight: 800; }
td.money.missing { color: var(--amber); font-size: 12px; }
.company { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; white-space: nowrap; }
.company i, .company-dot { display: inline-block; flex: 0 0 auto; width: 9px; height: 9px; border-radius: 50%; background: var(--dot); }
.badge { display: inline-flex; padding: 4px 8px; border-radius: 99px; font-size: 11px; font-weight: 800; }
.badge.full { background: var(--blue-soft); color: #1849A9; }
.badge.part { background: #F4EBFF; color: #6941C6; }
.badge.extra { background: #ECFDF3; color: var(--green); }
.critical-row { background: #FFFBF4; }
.critical-flag { display: inline-flex; margin-right: 7px; padding: 3px 6px; border-radius: 5px; background: #FEE4E2; color: var(--red); font-size: 10px; font-weight: 850; text-transform: uppercase; letter-spacing: .04em; }
.actions { width: 150px; text-align: right; white-space: nowrap; }
.inline { display: inline; }
.icon-button { border: 0; background: transparent; color: var(--blue); font-size: 12px; font-weight: 750; padding: 5px; cursor: pointer; }
.icon-button.danger { color: #98A2B3; }
.icon-button.danger:hover { color: var(--red); }
.empty { padding: 44px; text-align: center; color: var(--muted); }
.empty strong, .empty span { display: block; }
.empty strong { color: var(--ink); margin-bottom: 5px; }

.bottom-grid { display: grid; grid-template-columns: .85fr 1.15fr; gap: 18px; margin-top: 18px; }
.summary-panel, .payments-panel { padding: 21px 22px; }
.big-total { font-size: 22px; letter-spacing: -.03em; }
.summary-line { display: flex; justify-content: space-between; gap: 16px; padding: 11px 0; border-top: 1px solid #EEF1F4; }
.summary-line span { color: var(--muted); }
.summary-line span b { color: var(--ink); }
.summary-line small { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.summary-line.total-line { color: var(--navy); font-weight: 800; border-top-color: #CBD5E1; }
.summary-line.total-line span { color: var(--navy); }
.warning-line { display: flex; justify-content: space-between; gap: 16px; margin-top: 8px; padding: 11px 12px; border-radius: 9px; color: var(--amber); background: var(--amber-soft); text-decoration: none; font-size: 13px; }
.arrears-card { display: grid; grid-template-columns: 1fr auto; gap: 3px 14px; padding: 15px 16px; border-radius: 12px; color: white; background: var(--navy); }
.arrears-card span { align-self: end; color: #C8D5E7; font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.arrears-card strong { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-size: 25px; letter-spacing: -.03em; }
.arrears-card small { color: #AFC0DB; }
.balance-explanation { margin: 10px 2px 14px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.balance-breakdown { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; margin-bottom: 17px; }
.balance-breakdown div { padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #F8FAFC; }
.balance-breakdown span, .balance-breakdown strong { display: block; }
.balance-breakdown span { color: var(--muted); font-size: 11px; }
.balance-breakdown strong { margin-top: 3px; color: var(--ink); font-size: 17px; }
.recent-payments { margin-top: 17px; }
.section-label { margin: 0 0 7px; color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; }
.payment-form { display: grid; grid-template-columns: repeat(2, 1fr); gap: 11px; padding-top: 16px; margin-top: 5px; border-top: 1px solid var(--line); }
.payment-form input, .payment-form select { min-width: 0; }
.old-balance-choice { grid-column: 1 / -1; align-content: center; }
.payment-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 9px; }
.form-hint { grid-column: 1 / -1; color: var(--muted); text-align: right; }

.settings-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
.company-form { padding: 22px; }
.company-title { display: flex; align-items: center; gap: 10px; margin-bottom: 17px; }
.company-title .company-dot { width: 12px; height: 12px; }
.company-title input { border: 0; padding: 0; min-height: 34px; font-size: 20px; font-weight: 800; letter-spacing: -.02em; }
.company-title input:focus { box-shadow: none; border-bottom: 1px solid var(--blue); border-radius: 0; }
.form-grid.compact { margin-top: 12px; }
.form-actions { display: flex; justify-content: space-between; align-items: end; margin-top: 16px; }
.color-field { display: flex; grid-template-columns: auto auto; align-items: center; }
.color-field input { width: 42px; height: 32px; min-height: 32px; padding: 2px; }
.new-company { border-style: dashed; box-shadow: none; }
.report-footer { color: var(--muted); text-align: center; margin-top: 24px; font-size: 12px; }

@media (max-width: 900px) {
    .stats.dashboard { grid-template-columns: repeat(2, 1fr); }
    .quick-row { grid-template-columns: 1fr 1fr; }
    .shift-kind { grid-column: 1 / 2; }
    .add-button { grid-column: 2 / 3; }
    .form-grid.five { grid-template-columns: repeat(3, 1fr); }
    .payment-form { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 680px) {
    .topbar { align-items: stretch; flex-direction: column; padding: 16px 18px 0; gap: 8px; }
    .brand { min-width: 0; }
    .main-nav { overflow-x: auto; margin: 0 -18px; padding: 0 10px; }
    .main-nav a { min-height: 48px; padding: 0 12px; white-space: nowrap; font-size: 13px; }
    .shell { width: min(100% - 24px, 1180px); padding-top: 26px; }
    .page-heading { align-items: stretch; flex-direction: column; gap: 18px; }
    .month-navigation { align-self: flex-start; width: 100%; }
    .month-switcher { flex: 1; }
    .stats, .stats.dashboard { grid-template-columns: 1fr; gap: 10px; }
    .stat { padding: 15px 17px; }
    .stat strong { font-size: 24px; }
    .quick-entry { padding: 18px 15px; }
    .quick-row { grid-template-columns: 1fr; }
    .shift-kind, .add-button { grid-column: auto; }
    .add-button { width: 100%; }
    .form-grid.three, .form-grid.four, .form-grid.five { grid-template-columns: repeat(2, 1fr); }
    .settings-grid, .bottom-grid { grid-template-columns: 1fr; }
    .shifts-panel > .panel-heading { align-items: flex-start; flex-direction: column; padding: 18px 15px 6px; }
    .toolbar { width: 100%; }
    .toolbar .button { flex: 1; }
    table, thead, tbody, tr, th, td { display: block; }
    thead { display: none; }
    tbody tr { padding: 13px 15px; border-bottom: 1px solid var(--line); }
    tbody tr:last-child { border-bottom: 0; }
    td { display: grid; grid-template-columns: 95px 1fr; gap: 12px; padding: 6px 0; border: 0; text-align: left !important; }
    td::before { content: attr(data-label); color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
    td.actions { display: flex; justify-content: flex-end; width: auto; border-top: 1px solid #EEF1F4; margin-top: 5px; padding-top: 10px; }
    td.actions::before { display: none; }
    .payment-form { grid-template-columns: 1fr; }
    .payment-actions, .form-hint, .old-balance-choice { grid-column: auto; }
    .payment-actions { display: grid; grid-template-columns: 1fr; }
    .form-hint { text-align: left; }
    .arrears-card { grid-template-columns: 1fr; }
    .arrears-card strong { grid-row: auto; grid-column: auto; }
    .balance-breakdown { grid-template-columns: 1fr; }
}

@media print {
    @page { margin: 16mm 12mm; }
    body { background: white; font-size: 11px; }
    .no-print { display: none !important; }
    .shell { width: 100%; padding: 0; }
    .page-heading { margin-bottom: 15px; }
    .page-heading h1 { font-size: 26px; }
    .stats { grid-template-columns: repeat(3, 1fr); margin-bottom: 14px; }
    .stat, .panel { box-shadow: none; break-inside: avoid; }
    .stat { padding: 11px 13px; }
    .stat strong { font-size: 20px; }
    .shifts-panel > .panel-heading { padding: 14px 14px 2px; }
    th, td { padding: 8px 9px; }
    .report-footer { margin-top: 15px; }
}
