:root {
    --ink: #172624;
    --muted: #687673;
    --paper: #fffdf8;
    --canvas: #f2f0e9;
    --line: #d9d5c9;
    --line-dark: #aaa79e;
    --green: #164c43;
    --green-2: #23695d;
    --green-soft: #e8f0ed;
    --gold: #c5953f;
    --gold-soft: #f7ecd7;
    --red: #a9473e;
    --red-soft: #fae8e5;
    --blue-soft: #e8eff4;
    --shadow: 0 12px 38px rgba(27, 42, 39, .08);
    --radius: 14px;
}

* { box-sizing: border-box; }
html { color-scheme: light; -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background:
        radial-gradient(circle at 15% 10%, rgba(197,149,63,.07), transparent 26rem),
        linear-gradient(180deg, #eeece5 0, var(--canvas) 18rem);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

a { color: var(--green-2); }
button, input, select { font: inherit; }
h1, h2, h3, p { margin-top: 0; }

.site-header {
    position: sticky;
    z-index: 20;
    top: 0;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 28px;
    min-height: 74px;
    padding: 10px max(24px, calc((100vw - 1540px) / 2));
    color: #fff;
    background: rgba(18, 57, 51, .97);
    box-shadow: 0 6px 24px rgba(17, 42, 38, .16);
    backdrop-filter: blur(14px);
}

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    min-width: max-content;
    color: #fff;
    text-decoration: none;
}
.brand span:last-child { display: flex; flex-direction: column; line-height: 1.15; }
.brand small { margin-top: 4px; color: #bcd0ca; font-size: 11px; letter-spacing: .05em; text-transform: uppercase; }
.brand-mark {
    display: grid;
    width: 42px;
    height: 42px;
    place-items: center;
    border: 1px solid rgba(255,255,255,.32);
    border-radius: 50%;
    color: #1b4b42;
    background: var(--gold-soft);
    font-family: Georgia, serif;
    font-weight: 800;
}

.main-nav { display: flex; align-items: center; justify-content: center; gap: 4px; }
.main-nav a {
    padding: 9px 10px;
    border-radius: 7px;
    color: #e5efec;
    font-size: 13px;
    text-decoration: none;
    white-space: nowrap;
}
.main-nav a:hover, .main-nav a.active { color: #fff; background: rgba(255,255,255,.11); }
.nav-toggle { display: none; }
.user-menu { display: grid; grid-template-columns: auto auto; align-items: center; column-gap: 12px; min-width: max-content; }
.user-menu > span { font-weight: 700; }
.user-menu small { grid-column: 1; color: #bcd0ca; }
.user-menu a { grid-column: 2; grid-row: 1 / 3; padding-left: 12px; border-left: 1px solid rgba(255,255,255,.18); color: #f4d9a9; font-size: 12px; }

.page-shell { width: min(1540px, calc(100% - 40px)); margin: 0 auto; padding: 38px 0 70px; }
.auth-shell { display: grid; min-height: 100vh; padding: 30px 0; place-items: center; }
.paper-card {
    border: 1px solid rgba(113, 111, 101, .22);
    border-radius: var(--radius);
    background: var(--paper);
    box-shadow: var(--shadow);
}

.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 22px; }
.page-heading h1 { margin-bottom: 3px; font-family: Georgia, "Times New Roman", serif; font-size: clamp(28px, 3vw, 43px); line-height: 1.05; font-weight: 600; letter-spacing: -.025em; }
.page-heading p:last-child { margin-bottom: 0; color: var(--muted); }
.eyebrow { margin-bottom: 7px; color: var(--green-2); font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.heading-total { min-width: 220px; padding: 14px 17px; border-left: 3px solid var(--gold); text-align: right; background: rgba(255,253,248,.55); }
.heading-total small, .heading-total strong { display: block; }
.heading-total small { margin-bottom: 4px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; }
.heading-total strong { color: var(--green); font-family: Georgia, serif; font-size: 23px; }

.context-bar { display: flex; align-items: end; gap: 12px; margin-bottom: 18px; padding: 14px 16px; }
.context-bar label, .grid-form label, .stack-form label { display: grid; gap: 6px; color: #4c5a57; font-size: 11px; font-weight: 750; letter-spacing: .035em; }
input, select {
    width: 100%;
    min-height: 44px;
    padding: 8px 10px;
    border: 1px solid #c8c8c1;
    border-radius: 7px;
    outline: none;
    color: var(--ink);
    background: #fff;
}
input:focus, select:focus { border-color: var(--green-2); box-shadow: 0 0 0 3px rgba(35,105,93,.12); }
.context-bar input, .context-bar select { min-width: 175px; }
.context-name { display: grid; margin-left: auto; padding: 0 4px 3px; font-weight: 750; text-align: right; }
.context-name small { color: var(--muted); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }
.button {
    min-height: 44px;
    padding: 9px 16px;
    border: 1px solid #c4c2b9;
    border-radius: 7px;
    color: var(--ink);
    background: #f8f6f0;
    cursor: pointer;
    font-weight: 750;
}
.button:hover { border-color: #96978f; background: #fff; }
.button-primary { border-color: var(--green); color: #fff; background: var(--green); }
.button-primary:hover { border-color: var(--green-2); background: var(--green-2); }
.text-link { font-size: 13px; font-weight: 700; }

.flash { margin: 0 0 15px; padding: 12px 15px; border: 1px solid; border-radius: 9px; }
.flash-success { border-color: #9bc0b7; color: #185046; background: #e9f3f0; }
.flash-error { border-color: #d9a49f; color: #81362f; background: var(--red-soft); }
.flash-warning { border-color: #d6b16f; color: #684713; background: var(--gold-soft); }

.entry-panel { margin-bottom: 18px; padding: 18px; }
.correction-panel { border-color: #ddb277; background: #fffbf3; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.section-title h2 { margin: 0; font-family: Georgia, serif; font-size: 21px; }
.section-title .eyebrow { margin-bottom: 2px; }
.grid-form { display: grid; gap: 12px; }
.four-columns { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stock-form { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.loan-form { grid-template-columns: 1.4fr repeat(3, 1fr); }
.source-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.worker-create-form { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-all { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; padding-top: 2px; }

.register-card, .master-card { overflow: hidden; }
.register-header, .sheet-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 18px 20px;
    border-bottom: 2px solid var(--ink);
    background: linear-gradient(90deg, #f7f3e9, #fffdf8 55%);
}
.register-header > div, .sheet-heading > div { display: grid; }
.register-header strong, .sheet-heading strong { font-family: Georgia, serif; font-size: 22px; letter-spacing: .03em; }
.register-header span, .sheet-heading span { color: var(--muted); }
.register-header dl, .sheet-heading dl { display: grid; grid-template-columns: auto auto; gap: 3px 12px; margin: 0; font-size: 12px; }
.register-header dt, .sheet-heading dt { color: var(--muted); }
.register-header dd, .sheet-heading dd { margin: 0; font-weight: 750; }
.table-scroll { width: 100%; overflow-x: auto; }
.register-table, .master-table, .compact-table { width: 100%; border-collapse: collapse; }
.register-table { min-width: 920px; }
.register-table th, .register-table td, .master-table th, .master-table td, .compact-table th, .compact-table td { border: 1px solid var(--line); padding: 10px 11px; vertical-align: top; }
.register-table thead th, .master-table thead th, .compact-table thead th { color: #fff; background: var(--green); font-size: 11px; letter-spacing: .04em; text-align: left; text-transform: uppercase; }
.register-table tbody tr:nth-child(even):not(.subtotal-row) td { background: rgba(241,239,232,.42); }
.register-table tfoot th, .compact-table tfoot th { border-top: 2px solid var(--ink); background: #f0eee7; }
.register-table .number { text-align: right; white-space: nowrap; }
.empty-cell { padding: 30px !important; color: var(--muted); text-align: center !important; }
.subtotal-row td { padding-top: 7px; padding-bottom: 7px; color: var(--green); background: var(--green-soft); font-size: 12px; font-weight: 750; }
.flagged-row td { background: #fff7ec !important; }
.flagged-row td:first-child { box-shadow: inset 3px 0 var(--gold); }
.badge { display: inline-block; margin: 0 4px 4px 0; padding: 3px 7px; border-radius: 99px; font-size: 10px; font-weight: 800; white-space: nowrap; }
.badge-warning { color: #793a21; background: #f8dfbf; }
.badge-info { color: #28516c; background: var(--blue-soft); }
.row-action { display: inline-block; margin-top: 3px; font-size: 11px; font-weight: 800; }
.meta-stack { display: grid; min-width: 120px; }
.meta-stack small { color: var(--muted); }
.audit-note, .calculation-note { margin: 0; padding: 11px 16px; border-top: 1px solid var(--line); color: var(--muted); background: #f8f6f0; font-size: 11px; }

.expense-board { display: grid; grid-template-columns: repeat(3, minmax(300px, 1fr)); gap: 0; }
.expense-column { display: grid; grid-template-rows: auto 1fr auto; min-height: 250px; border-right: 1px solid var(--line-dark); border-bottom: 1px solid var(--line-dark); }
.expense-column:nth-child(3n) { border-right: 0; }
.expense-column header, .inventory-section header { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; color: #fff; background: var(--green); }
.expense-column h3, .inventory-section h2 { margin: 0; font-family: Georgia, serif; font-size: 14px; letter-spacing: .02em; }
.expense-column header strong { color: #f6d9a5; font-size: 12px; }
.expense-lines { padding: 0 7px; }
.expense-line { display: grid; grid-template-columns: 65px 95px minmax(120px, 1fr); border-bottom: 1px solid var(--line); }
.expense-line > * { padding: 7px 5px; }
.expense-line strong { text-align: right; }
.expense-line a { margin-left: 4px; font-size: 10px; }
.expense-labels { color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }
.expense-column footer { display: flex; justify-content: space-between; padding: 9px 12px; border-top: 2px solid var(--ink); background: #f0eee7; font-weight: 800; }
.empty-mini { padding: 28px 8px; color: var(--muted); text-align: center; }
.flagged-line { background: #fff3e3; box-shadow: inset 3px 0 var(--gold); }
.flag-dot { display: inline-grid; width: 16px; height: 16px; place-items: center; border-radius: 50%; color: #fff; background: var(--red); }
.corrected-mark { display: block; margin-top: 3px; color: #99631d; font-size: 9px; font-weight: 800; text-transform: uppercase; }
.daily-total-strip { display: flex; align-items: stretch; gap: 1px; overflow-x: auto; border-top: 2px solid var(--ink); background: var(--line); }
.daily-total-strip h3 { min-width: 130px; margin: 0; padding: 14px; background: #f0eee7; font-family: Georgia, serif; }
.daily-total-strip > span { display: grid; min-width: 110px; padding: 10px 13px; background: var(--paper); }
.daily-total-strip small { color: var(--muted); }
.daily-total-strip .grand-total { min-width: 190px; margin-left: auto; color: #fff; background: var(--green); }
.daily-total-strip .grand-total small { color: #c9dbd6; }

.source-panel { margin-bottom: 18px; overflow: hidden; }
.source-panel summary { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 16px 18px; cursor: pointer; list-style: none; }
.source-panel summary::-webkit-details-marker { display: none; }
.source-panel summary > span:first-child { display: grid; }
.source-panel summary small { color: var(--muted); font-weight: 400; }
.source-panel summary > span:last-child { color: var(--green-2); font-size: 12px; font-weight: 800; }
.source-panel form { padding: 4px 18px 18px; }

.monthly-sheet { overflow: hidden; }
.summary-columns { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--line-dark); }
.summary-stack:first-child { border-right: 2px solid var(--ink); }
.summary-box { border-bottom: 2px solid var(--ink); }
.summary-box h2 { margin: 0; padding: 6px 12px; color: #fff; background: var(--green); font-family: Georgia, serif; font-size: 15px; letter-spacing: .08em; }
.summary-box dl { margin: 0; }
.summary-row { display: grid; grid-template-columns: 1fr minmax(130px, .7fr); min-height: 35px; border-bottom: 1px solid var(--line); }
.summary-row:last-child { border-bottom: 0; }
.summary-row dt, .summary-row dd { margin: 0; padding: 8px 12px; }
.summary-row dd { border-left: 1px solid var(--line); color: #44514e; background: #efeee9; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-weight: 750; text-align: right; }
.summary-row.total-line { font-weight: 850; }
.summary-row.total-line dt, .summary-row.total-line dd { background: #e1e7e3; }
.summary-row.cash-flow-line dt, .summary-row.cash-flow-line dd { color: #fff; background: var(--green); }
.signature-box { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; padding: 28px 18px; }
.signature-box > div { display: grid; grid-template-columns: max-content 1fr; gap: 8px; color: var(--muted); font-size: 11px; }
.signature-box span { border-bottom: 1px solid var(--line-dark); }
.signature-box small { grid-column: 1 / -1; }
.master-signatures { border-top: 2px solid var(--ink); }

.master-table { min-width: 900px; }
.master-table thead th { min-width: 165px; text-align: right; }
.master-table thead th:first-child { position: sticky; z-index: 2; left: 0; min-width: 210px; text-align: left; }
.master-table thead span, .master-table thead small { display: block; }
.master-table thead small { color: #bfd3cd; font-size: 9px; }
.master-table tbody th { position: sticky; z-index: 1; left: 0; background: #faf8f2; text-align: left; }
.master-table td { font-family: ui-monospace, Consolas, monospace; text-align: right; white-space: nowrap; }
.master-table .group-row th { position: static; padding: 6px 11px; color: #fff; background: #56756f; font-family: Georgia, serif; letter-spacing: .08em; }
.master-table .combined-column { color: #173e37; background: var(--gold-soft); font-weight: 850; }
.mobile-scroll-hint { display: none; }

.inventory-board { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.inventory-section { min-width: 0; border-right: 1px solid var(--line-dark); border-bottom: 2px solid var(--ink); }
.inventory-section:nth-child(even) { border-right: 0; }
.inventory-section:first-child { grid-column: 1 / -1; }
.inventory-section header strong { color: #f6d9a5; }
.compact-table { min-width: 620px; }
.compact-table th, .compact-table td { padding: 8px; }
.compact-table thead th { color: var(--ink); background: #eceae4; }

.audit-table { min-width: 1280px; }
.audit-table td:first-child { white-space: nowrap; }
.audit-table td:first-child small { display: block; color: var(--muted); }
.audit-table .audit-value { max-width: 340px; color: #53615e; font-size: 11px; }
.audit-correction td { background: #fff8eb !important; }
.reason-text { display: block; max-width: 220px; margin-top: 5px; color: #71431d; }

.workers-table { min-width: 58rem; }
.workers-table th:last-child { min-width: 20rem; }
.worker-created { display: block; margin-top: .2rem; color: var(--muted); font-size: .7rem; }
.username-value { padding: .2rem .4rem; border-radius: .3rem; color: #194e45; background: var(--green-soft); font-size: .85rem; }
.status-badge { display: inline-flex; min-height: 1.75rem; align-items: center; padding: .25rem .65rem; border-radius: 99rem; font-size: .72rem; font-weight: 850; }
.status-active { color: #155345; background: #dceee8; }
.status-inactive { color: #763b34; background: var(--red-soft); }
.worker-actions { display: grid; gap: .55rem; }
.reset-form { display: grid; grid-template-columns: minmax(10rem, 1fr) auto; align-items: end; gap: .55rem; }
.reset-form label { display: grid; gap: .3rem; color: var(--muted); font-size: .7rem; font-weight: 750; }
.reset-form input { min-height: 2.75rem; }
.reset-password-field { display: grid; min-width: 0; gap: .3rem; }
.form-field-label { color: var(--muted); font-size: .7rem; font-weight: 750; }
.password-recovery-tools { display: flex; flex-wrap: wrap; gap: .35rem; }
.password-tool-button { display: inline-flex; min-height: 2.25rem; align-items: center; justify-content: center; padding: .35rem .65rem; border: 1px solid #c7c6bf; border-radius: .4rem; color: var(--green); background: #fff; cursor: pointer; font-size: .7rem; font-weight: 800; }
.password-tool-button:hover { border-color: #91b6ac; background: var(--green-soft); }
.password-tool-button:focus-visible { outline: 3px solid rgba(35,105,93,.22); outline-offset: 2px; }
.password-security-note { color: var(--muted); font-size: .65rem; font-weight: 500; line-height: 1.35; }
.saved-password-panel { display: grid; gap: .45rem; padding: .7rem; border: 1px solid #78aa9e; border-radius: .55rem; color: #164c43; background: #e4f2ee; }
.saved-password-panel strong { font-size: .8rem; }
.saved-password-panel small { font-size: .68rem; }
.saved-password-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .4rem; }
.saved-password-row input { min-height: 2.75rem; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-weight: 800; }
.status-form { display: flex; justify-content: flex-end; }
.button-quiet { color: var(--muted); background: transparent; }

.login-card { width: min(470px, 100%); padding: 34px; }
.account-panel { width: min(560px, 100%); }
.login-heading { display: flex; align-items: center; gap: 17px; margin-bottom: 28px; }
.login-heading h1 { margin-bottom: 5px; font-family: Georgia, serif; font-size: 29px; }
.login-heading p:last-child { margin: 0; color: var(--muted); }
.brand-mark-large { flex: 0 0 auto; width: 68px; height: 68px; border-color: #d8c394; font-size: 21px; }
.stack-form { display: grid; gap: 15px; }
.stack-form .button { margin-top: 6px; }
.field-hint { color: var(--muted); font-size: 10px; font-weight: 500; letter-spacing: 0; }
.password-control { position: relative; display: block; width: 100%; }
.password-control input { padding-right: 5rem; }
.password-toggle { position: absolute; z-index: 1; top: 0; right: 0; bottom: 0; display: inline-flex; min-width: 4.5rem; min-height: 44px; align-items: center; justify-content: center; padding: 0 .75rem; border: 0; border-left: 1px solid #c8c8c1; border-radius: 0 7px 7px 0; color: var(--green); background: #f4f2ec; cursor: pointer; font-size: .75rem; font-weight: 850; }
.password-toggle:hover { background: var(--green-soft); }
.password-toggle:focus-visible { outline: 3px solid rgba(35,105,93,.25); outline-offset: -3px; }

@media (max-width: 1180px) {
    .site-header { grid-template-columns: auto auto 1fr auto; gap: 12px; padding: 10px 20px; }
    .nav-toggle { display: inline-flex; min-width: 44px; min-height: 44px; align-items: center; justify-content: center; gap: 7px; padding: 8px 10px; border: 1px solid rgba(255,255,255,.25); border-radius: 6px; color: #fff; background: transparent; }
    .main-nav { position: absolute; top: 69px; left: 20px; display: none; width: 240px; align-items: stretch; padding: 8px; border: 1px solid rgba(255,255,255,.15); border-radius: 9px; background: #173f38; box-shadow: var(--shadow); flex-direction: column; }
    .main-nav.open { display: flex; }
    .main-nav a { display: flex; min-height: 44px; align-items: center; padding: 11px; }
    .user-menu { grid-column: 4; }
    .expense-board { grid-template-columns: repeat(2, minmax(300px, 1fr)); }
    .expense-column:nth-child(3n) { border-right: 1px solid var(--line-dark); }
    .expense-column:nth-child(2n) { border-right: 0; }
    .source-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .stock-form { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .inventory-board { grid-template-columns: 1fr; }
    .inventory-section, .inventory-section:nth-child(even), .inventory-section:first-child { grid-column: auto; border-right: 0; }
}

@media (max-width: 768px) {
    body { overflow-x: clip; font-size: 16px; line-height: 1.55; }
    .site-header { position: relative; grid-template-columns: minmax(0, 1fr) auto; min-height: 4.25rem; padding: .55rem .75rem; background: #123933; backdrop-filter: none; -webkit-backdrop-filter: none; }
    .brand { min-width: 0; }
    .brand > span:last-child { min-width: 0; }
    .brand strong { overflow: hidden; font-size: .95rem; text-overflow: ellipsis; white-space: nowrap; }
    .brand-mark { width: 2.65rem; height: 2.65rem; }
    .brand small { display: none; }
    .nav-toggle { grid-column: 2; grid-row: 1; }
    .main-nav { top: 3.75rem; right: .75rem; left: auto; width: min(20rem, calc(100vw - 1.5rem)); padding: .5rem; }
    .main-nav a { min-height: 3rem; padding: .7rem .85rem; font-size: .95rem; }
    .user-menu { grid-column: 1 / -1; grid-row: 2; display: flex; min-width: 0; align-items: center; gap: .45rem; padding-top: .45rem; border-top: 1px solid rgba(255,255,255,.13); }
    .user-menu > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .user-menu small { margin-right: auto; }
    .user-menu a { display: inline-flex; min-height: 2.75rem; align-items: center; padding: 0 .4rem; border: 0; white-space: nowrap; }
    .page-shell { width: calc(100% - 1rem); padding: 1.25rem 0 3rem; }
    .auth-shell { width: 100%; min-height: 100svh; padding: 1rem; }
    .paper-card { max-width: 100%; border-radius: .75rem; }
    .page-heading { align-items: stretch; flex-direction: column; }
    .page-heading h1 { font-size: clamp(1.85rem, 9vw, 2.5rem); }
    .heading-total { min-width: 0; text-align: left; }
    .context-bar { align-items: stretch; gap: .85rem; padding: 1rem; flex-direction: column; }
    .context-bar label, .grid-form label, .stack-form label { gap: .45rem; font-size: .78rem; }
    .context-bar input, .context-bar select { min-width: 0; }
    .context-name { margin-left: 0; text-align: left; }
    .four-columns, .loan-form, .source-grid, .stock-form, .worker-create-form { grid-template-columns: 1fr; }
    input, select { min-height: 3rem; padding: .7rem .8rem; font-size: 16px; }
    .button { min-height: 3rem; padding: .7rem 1rem; font-size: 1rem; }
    .form-actions { justify-content: stretch; }
    .form-actions .button { width: 100%; }
    .entry-panel { padding: 1rem; }
    .section-title { align-items: flex-start; }
    .section-title .text-link { display: inline-flex; min-height: 2.75rem; align-items: center; padding: 0 .35rem; }
    .register-header, .sheet-heading { align-items: start; padding: 1rem; flex-direction: column; }
    .register-header strong, .sheet-heading strong { font-size: 1.15rem; }
    .register-header dl, .sheet-heading dl { width: 100%; grid-template-columns: minmax(6rem, auto) minmax(0, 1fr); font-size: .8rem; }

    /* Record tables become labeled cards. The Master Sheet remains the one
       intentional horizontal comparison table. */
    .table-scroll:not(.master-scroll) { overflow: visible; }
    .mobile-card-table { display: block; width: 100%; min-width: 0; border-collapse: separate; }
    .mobile-card-table thead { display: none; }
    .mobile-card-table tbody { display: grid; gap: .85rem; padding: .85rem; }
    .mobile-card-table tbody tr { display: block; overflow: hidden; border: 1px solid var(--line); border-radius: .7rem; background: #fff; box-shadow: 0 .25rem .8rem rgba(27,42,39,.06); }
    .mobile-card-table tbody tr td,
    .mobile-card-table tbody tr:nth-child(even):not(.subtotal-row) td { display: block; width: 100%; padding: .7rem .8rem; border: 0; border-bottom: 1px solid #e6e2d8; background: #fff; text-align: left; white-space: normal; }
    .mobile-card-table tbody tr td:last-child { border-bottom: 0; }
    .mobile-card-table tbody td[data-label]::before { display: block; margin-bottom: .18rem; color: var(--muted); content: attr(data-label); font-size: .68rem; font-weight: 850; letter-spacing: .065em; text-transform: uppercase; }
    .mobile-card-table tbody .empty-cell { padding: 2rem 1rem !important; text-align: center !important; }
    .mobile-card-table tbody .empty-cell::before { display: none; }
    .mobile-card-table tbody .subtotal-row { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .75rem .85rem; border-color: #b9d0c9; background: var(--green-soft); box-shadow: none; }
    .mobile-card-table tbody .subtotal-row td { display: none; width: auto; padding: 0; border: 0; color: var(--green); background: transparent; }
    .mobile-card-table tbody .subtotal-row td:first-child,
    .mobile-card-table tbody .subtotal-row td:nth-child(2) { display: block; }
    .mobile-card-table tfoot { display: block; border-top: 2px solid var(--ink); }
    .mobile-card-table tfoot tr { display: flex; flex-wrap: wrap; padding: .75rem; background: #efede6; }
    .mobile-card-table tfoot th { display: block; min-width: 50%; padding: .35rem .45rem; border: 0; background: transparent; text-align: left; }
    .mobile-card-table tfoot th:empty { display: none; }
    .mobile-card-table tfoot th[data-label]::before { display: block; margin-bottom: .12rem; color: var(--muted); content: attr(data-label); font-size: .65rem; font-weight: 850; letter-spacing: .06em; text-transform: uppercase; }
    .mobile-card-table .number { text-align: left; }
    .meta-stack { min-width: 0; }
    .row-action { display: inline-flex; min-height: 2.75rem; align-items: center; justify-content: center; margin-top: .4rem; padding: .45rem .8rem; border: 1px solid #a9c5be; border-radius: .5rem; font-size: .8rem; text-decoration: none; }

    .expense-board { grid-template-columns: 1fr; }
    .expense-column, .expense-column:nth-child(3n) { border-right: 0; }
    .expense-column { min-height: 0; }
    .expense-column header { min-height: 3rem; padding: .7rem .85rem; }
    .expense-lines { padding: .25rem .6rem .7rem; }
    .expense-labels { display: none; }
    .expense-line:not(.expense-labels) { display: grid; gap: 0; margin-top: .65rem; padding: .25rem .75rem; border: 1px solid var(--line); border-radius: .65rem; background: #fff; }
    .expense-line:not(.expense-labels) > * { display: block; padding: .55rem 0; border-bottom: 1px solid #ebe8e0; text-align: left; }
    .expense-line:not(.expense-labels) > *:last-child { border-bottom: 0; }
    .expense-line:not(.expense-labels) > *::before { display: block; margin-bottom: .15rem; color: var(--muted); content: attr(data-label); font-size: .68rem; font-weight: 850; letter-spacing: .065em; text-transform: uppercase; }
    .expense-line a { margin-left: 0; }
    .daily-total-strip { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); overflow: visible; gap: 1px; }
    .daily-total-strip h3, .daily-total-strip > span { min-width: 0; }
    .daily-total-strip h3, .daily-total-strip .grand-total { grid-column: 1 / -1; }
    .daily-total-strip .grand-total { min-width: 0; margin-left: 0; }

    .summary-columns { grid-template-columns: 1fr; }
    .summary-stack:first-child { border-right: 0; }
    .summary-box h2 { display: flex; min-height: 3rem; align-items: center; justify-content: space-between; padding: .65rem .85rem; cursor: pointer; touch-action: manipulation; }
    .summary-box h2::after { display: grid; width: 1.75rem; height: 1.75rem; flex: 0 0 auto; margin-left: .75rem; place-items: center; border: 1px solid rgba(255,255,255,.4); border-radius: 50%; content: '−'; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 1.1rem; }
    .summary-box.mobile-collapsed h2::after { content: '+'; }
    .summary-box.mobile-collapsed dl { display: none; }
    .summary-row { grid-template-columns: minmax(0, 1fr) minmax(7.25rem, auto); }
    .summary-row dt, .summary-row dd { padding: .7rem .8rem; }
    .signature-box { grid-template-columns: 1fr; }
    .source-panel summary { align-items: start; flex-direction: column; }

    .mobile-scroll-hint { display: flex; align-items: center; gap: .5rem; margin: 0; padding: .65rem .85rem; border-bottom: 1px solid #d7cfbd; color: #664b1c; background: var(--gold-soft); font-size: .78rem; font-weight: 750; }
    .mobile-scroll-hint span { font-size: 1.15rem; }
    .master-scroll { overflow-x: auto; overscroll-behavior-inline: contain; scrollbar-width: thin; -webkit-overflow-scrolling: touch; box-shadow: inset -1.25rem 0 1.2rem -1.5rem rgba(23,38,36,.65); }
    .master-scroll:focus { outline: 3px solid rgba(35,105,93,.25); outline-offset: -3px; }
    .master-table { min-width: 55rem; }
    .master-table thead th { min-width: 9rem; }
    .master-table thead th:first-child { min-width: 9.5rem; }

    .inventory-board { grid-template-columns: 1fr; }
    .inventory-section, .inventory-section:nth-child(even) { grid-column: auto; border-right: 0; }
    .compact-table { min-width: 0; }

    .audit-table .audit-value { max-width: none; font-size: .82rem; }
    .audit-table td:first-child { white-space: normal; }
    .audit-note, .calculation-note { padding: .8rem 1rem; font-size: .75rem; }

    .workers-table { min-width: 0; }
    .workers-table th:last-child { min-width: 0; }
    .worker-actions { min-width: 0; gap: .8rem; }
    .reset-form { grid-template-columns: 1fr; }
    .reset-form input { min-height: 3rem; font-size: 16px; }
    .password-recovery-tools { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .5rem; }
    .password-tool-button { min-height: 2.75rem; padding: .55rem .75rem; font-size: .78rem; }
    .password-security-note { font-size: .72rem; }
    .saved-password-panel { padding: .8rem; }
    .saved-password-row input { min-height: 3rem; font-size: 16px; }
    .reset-form .button, .status-form .button { width: 100%; }
    .status-form { justify-content: stretch; }

    .login-card { width: 100%; max-width: 28rem; padding: 1.25rem; }
    .login-heading { align-items: center; gap: .85rem; margin-bottom: 1.5rem; }
    .login-heading h1 { font-size: clamp(1.55rem, 8vw, 2rem); }
    .brand-mark-large { width: 3.4rem; height: 3.4rem; }
    .stack-form { gap: 1rem; }
    .stack-form .button { width: 100%; min-height: 3.25rem; }
    .field-hint { font-size: .72rem; }
    .password-control input { padding-right: 5.25rem; }
    .password-toggle { min-width: 4.75rem; min-height: 3rem; font-size: .8rem; }
}

@media (max-width: 360px) {
    .page-shell { width: calc(100% - .75rem); }
    .site-header { padding-inline: .55rem; }
    .nav-toggle span:last-child { display: none; }
    .page-heading h1 { font-size: 1.8rem; }
    .summary-row { grid-template-columns: 1fr; }
    .summary-row dd { border-top: 1px solid var(--line); border-left: 0; text-align: left; }
    .daily-total-strip { grid-template-columns: 1fr; }
    .daily-total-strip h3, .daily-total-strip .grand-total { grid-column: auto; }
    .login-heading { align-items: flex-start; }
    .login-heading p:last-child { font-size: .85rem; }
}

@page monthly-report { size: A4 portrait; margin: 9mm; }
@page master-report { size: A4 landscape; margin: 8mm; }

@media print {
    html, body { width: 100%; margin: 0; color: #000; background: #fff !important; font-size: 9pt; }
    body { overflow: visible; }
    .site-header, .context-bar, .entry-panel, .source-panel, .page-heading, .flash, .audit-note, .calculation-note, .mobile-scroll-hint, .print-button { display: none !important; }
    .page-shell { width: 100%; max-width: none; margin: 0; padding: 0; }
    .paper-card { border: 1px solid #000; border-radius: 0; box-shadow: none; }
    .monthly-sheet { page: monthly-report; overflow: visible; }
    .master-card { page: master-report; overflow: visible; }
    .register-header, .sheet-heading { padding: 7pt 9pt; border-color: #000; color: #000; background: #fff !important; }
    .register-header strong, .sheet-heading strong { font-size: 15pt; }
    .sheet-heading dl { font-size: 8pt; }
    .summary-columns { display: grid !important; grid-template-columns: 1fr 1fr !important; border-color: #000; }
    .summary-stack:first-child { border-right: 1px solid #000 !important; }
    .summary-box { break-inside: avoid; page-break-inside: avoid; border-color: #000; }
    .summary-box h2 { display: block; min-height: 0; padding: 3pt 6pt; border-bottom: 1px solid #000; color: #000 !important; background: #fff !important; font-size: 10pt; }
    .summary-box h2::after { display: none !important; }
    .summary-box dl, .summary-box.mobile-collapsed dl { display: block !important; }
    .summary-row { min-height: 0; grid-template-columns: 1fr minmax(85pt, .65fr); border-color: #777; }
    .summary-row dt, .summary-row dd { padding: 3pt 6pt; border-color: #777; color: #000 !important; background: #fff !important; font-size: 8pt; }
    .summary-row.total-line dt, .summary-row.total-line dd,
    .summary-row.cash-flow-line dt, .summary-row.cash-flow-line dd { color: #000 !important; background: #eee !important; }
    .signature-box { break-inside: avoid; page-break-inside: avoid; gap: 20pt; padding: 18pt 10pt; color: #000; background: #fff; }
    .signature-box span { border-color: #000; }
    .master-scroll, .table-scroll { overflow: visible !important; box-shadow: none; }
    .master-table { width: 100% !important; min-width: 0 !important; table-layout: fixed; font-size: 6.5pt; }
    .master-table thead { display: table-header-group; }
    .master-table thead th, .master-table tbody th, .master-table td,
    .master-table .group-row th, .master-table .combined-column { position: static; min-width: 0; padding: 2.5pt 3pt; border-color: #000; color: #000 !important; background: #fff !important; white-space: normal; word-break: break-word; }
    .master-table thead th:first-child { width: 20%; }
    .master-table .group-row th { border-top: 1.5pt solid #000; border-bottom: 1pt solid #000; font-weight: 900; }
    .master-table tr { break-inside: avoid; page-break-inside: avoid; }
    a { color: #000 !important; text-decoration: none; }
}
