:root {
    --bg: #f4f7f4;
    --surface: #ffffff;
    --surface-2: #eef5f1;
    --text: #18211d;
    --muted: #647067;
    --line: #d8e1db;
    --primary: #176b52;
    --primary-ink: #ffffff;
    --danger: #b42318;
    --accent: #2f5f98;
    --shadow: 0 10px 30px rgba(24, 33, 29, 0.08);
}

* { box-sizing: border-box; }
html { font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { margin: 0; background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    min-height: 70px;
    padding: 14px clamp(18px, 4vw, 36px);
    background: rgba(255,255,255,0.94);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(10px);
}
.brand { color: var(--text); font-weight: 800; font-size: 20px; }
.nav { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.nav-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 44px;
    padding: 8px 10px;
    border-radius: 8px;
    color: var(--muted);
    font-weight: 850;
    font-size: 16px;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link-danger { color: var(--danger); }
.nav-link-danger:hover { background: #fff0ee; color: var(--danger); }
.nav-icon {
    width: 21px;
    height: 21px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.nav-emoji { font-size: 20px; line-height: 1; }
.link-button { border: 0; background: transparent; cursor: pointer; font: inherit; }

.shell { width: min(1180px, 100%); margin: 0 auto; padding: 22px clamp(14px, 4vw, 32px) 48px; }
.cash-shell { width: min(1520px, 100%); }
.compensation-shell { width: min(1360px, 100%); }
.vault-shell { width: min(1420px, 100%); }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.page-head h1, .auth-panel h1 { margin: 0; font-size: 28px; line-height: 1.1; letter-spacing: 0; }
.eyebrow { margin: 0 0 6px; color: var(--muted); font-weight: 700; text-transform: uppercase; font-size: 12px; }

.panel, .auth-panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 18px;
}
.auth-panel { max-width: 420px; margin: 40px auto; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 12px; }
.panel h2 { margin: 0 0 12px; font-size: 18px; }
.panel-head h2 { margin: 0; }
.panel-subtitle { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.metric-grid.compact { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cash-metric-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.metric {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    min-height: 88px;
}
.metric span { display: block; color: var(--muted); font-size: 13px; font-weight: 650; }
.metric strong { display: block; margin-top: 8px; font-size: 26px; letter-spacing: 0; }

.split-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.cash-split-grid { grid-template-columns: minmax(420px, 0.9fr) minmax(0, 1.1fr); }
.list-stack { display: grid; gap: 10px; }
.row-card, .line-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 58px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
}
.row-card small, .line-card small { display: block; margin-top: 3px; color: var(--muted); }
.line-amount { font-weight: 800; font-size: 18px; color: var(--accent); }
.attachment-link { display: inline-block; margin: 4px 0 4px 12px; font-size: 13px; }
.empty { color: var(--muted); margin: 6px 0; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 780px; }
.compact-table { min-width: 520px; }
.cash-tracking-table { min-width: 1420px; }
.cash-tracking-table th:last-child,
.cash-tracking-table td:last-child {
    width: 76px;
    min-width: 76px;
}
.cash-amount-input {
    width: 98px;
    min-height: 36px;
    padding: 7px 8px;
    border-radius: 8px;
    text-align: right;
}
.cash-amount-input:disabled {
    background: #edf1ef;
    color: var(--muted);
    cursor: not-allowed;
}
th, td { padding: 11px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0; }
.actions-col { width: 104px; text-align: right; }
.row-actions { display: flex; align-items: center; justify-content: flex-end; gap: 7px; min-width: 88px; }
.row-actions form { margin: 0; }
.table-icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--primary);
    cursor: pointer;
}
.table-icon-button:hover { background: var(--surface-2); }
.table-icon-button.danger { color: var(--danger); }
.table-icon-button.danger:hover { background: #fff0ee; }
.table-icon {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.pen-icon { transform: rotate(-160deg); transform-origin: 50% 50%; }

.filter-bar {
    display: grid;
    grid-template-columns: repeat(4, minmax(130px, 1fr)) auto auto auto;
    gap: 10px;
    align-items: center;
    margin-bottom: 14px;
}
.cash-filter-bar { grid-template-columns: minmax(180px, 220px) minmax(220px, 1fr) minmax(220px, 1fr) auto auto; }
.compensation-filter-bar { grid-template-columns: minmax(180px, 220px) minmax(220px, 1fr) minmax(220px, 1fr) auto; }
.vault-filter-bar { grid-template-columns: minmax(180px, 220px) auto; justify-content: start; }
.cash-import-form {
    display: grid;
    grid-template-columns: minmax(240px, 360px) auto;
    gap: 10px;
    align-items: center;
    margin: -4px 0 14px;
}
.form-stack { display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-weight: 700; color: var(--text); }
.field, input, select, textarea {
    width: 100%;
    border: 1px solid #c9d5ce;
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    padding: 11px 12px;
    min-height: 44px;
    font: inherit;
}
textarea { resize: vertical; }
.actions, .action-strip { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.button, button.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text);
    font-weight: 800;
    cursor: pointer;
}
.button.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.button.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.button.ghost { background: transparent; }
.icon-button {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--danger);
    font-weight: 900;
}
.status {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 4px 9px;
    border-radius: 999px;
    background: #e6edf8;
    color: #254a78;
    font-weight: 800;
    font-size: 13px;
}
.status.large { min-height: 36px; padding-inline: 12px; }
.status-ok { background: #dff3e9; color: #17603f; }
.status-justified { background: #fff3d5; color: #7a4b00; }
.status-unjustified, .status-missing { background: #fff0ee; color: var(--danger); }
.status-draft { background: #e6edf8; color: #254a78; }
.status-future { background: #edf1ef; color: var(--muted); }
.cash-row { scroll-margin-top: 92px; }
.cash-row-missing { background: #fffafa; }
.cash-row-unjustified { background: #fff8f7; }
.cash-row-justified { background: #fffdf5; }
.cash-row-saved { outline: 2px solid #8fc9ad; outline-offset: -2px; }
.cash-row-error { outline: 2px solid #d74739; outline-offset: -2px; }
.cash-row-target { outline: 2px solid var(--primary); outline-offset: -2px; }
.cash-row-validate-button {
    min-height: 34px;
    padding: 5px 10px;
    font-size: 13px;
}
.cash-reason-cell { min-width: 260px; max-width: 420px; white-space: normal; color: var(--muted); }
.cash-user-cell {
    min-width: 180px;
}
.cash-user-cell small {
    display: block;
    margin-top: 3px;
    color: var(--muted);
}
.cash-justification-cell {
    min-width: 128px;
}
.cash-justification-content {
    display: flex;
    align-items: center;
    gap: 8px;
}
.cash-justification-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 30px;
    padding: 5px 9px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--primary);
    font-weight: 850;
    font-size: 13px;
    white-space: nowrap;
}
.cash-justification-todo {
    border-color: var(--danger);
    background: var(--danger);
    color: #fff;
}
.cash-justification-todo:hover {
    background: #8f1c14;
    color: #fff;
}
.cash-justification-partial { background: #fff8e8; color: #7a4b00; }
.cash-justification-done { background: #e8f4ee; color: #17603f; }
.cash-watch-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.cash-watch-grid h3 { margin: 0 0 10px; font-size: 15px; }
.compensation-metric-grid { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.vault-metric-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.vault-split-grid { grid-template-columns: minmax(360px, 0.85fr) minmax(420px, 1.15fr); }
.vault-form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}
.vault-comment-field {
    margin-top: 12px;
}
.vault-source-table { min-width: 560px; }
.vault-statement-table { min-width: 1120px; }
.vault-income,
.vault-outcome {
    font-weight: 850;
    white-space: nowrap;
}
.vault-income { color: var(--primary); }
.vault-outcome { color: var(--danger); }
.vault-comment {
    min-width: 240px;
    color: var(--muted);
}
.status-vault { background: #eef5f1; color: var(--text); }
.compensation-reallocation-panel { margin-bottom: 16px; }
.compensation-reallocation-status {
    margin: -4px 0 12px;
}
.compensation-reallocation-prepared {
    background: #f1f8f5;
}
.compensation-reallocation-prepared td {
    border-top-color: #b9ddcc;
}
.compensation-table { min-width: 1340px; }
.compensation-table th,
.compensation-table td { padding: 9px 10px; }
.compensation-row-locked {
    background: #f3f8f5;
}
.compensation-table tfoot th {
    background: var(--surface-2);
    color: var(--text);
    font-size: 14px;
    text-transform: none;
}
.employee-name {
    min-width: 210px;
    font-weight: 760;
}
.compensation-number-input { width: 116px; }
.compensation-paid-cell {
    min-width: 230px;
}
.compensation-payment-entry {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}
.compensation-new-payment-input {
    width: 96px;
}
.compensation-payment-history {
    margin-top: 8px;
    color: var(--muted);
    font-size: 12px;
}
.compensation-payment-history summary {
    cursor: pointer;
    color: var(--accent);
    font-weight: 800;
}
.compensation-payment-history ul {
    display: grid;
    gap: 5px;
    margin: 8px 0 0;
    padding: 0;
    list-style: none;
}
.compensation-payment-history li {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 4px 8px;
    padding: 5px 0;
    border-top: 1px solid var(--line);
}
.compensation-payment-history small {
    grid-column: 1 / -1;
}
.compensation-readonly {
    color: var(--accent);
    font-weight: 850;
}
.compensation-received-cell {
    color: var(--primary);
    font-weight: 900;
    white-space: nowrap;
}
.compensation-due-amount {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    color: var(--text);
    font-size: 17px;
}
.compensation-note-input {
    min-width: 220px;
}
.compensation-due-preview {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
}
.compensation-pay-button {
    min-height: 36px;
    white-space: nowrap;
}
.definition-list { display: grid; grid-template-columns: minmax(120px, 0.8fr) 1.2fr; gap: 10px 14px; margin: 0; }
.definition-list dt { color: var(--muted); font-weight: 800; }
.definition-list dd { margin: 0; }
.messages { display: grid; gap: 8px; margin-bottom: 14px; }
.message { border-radius: 8px; padding: 10px 12px; background: #e8f4ee; border: 1px solid #b9ddcc; }
.message.error, .error-text { color: var(--danger); }
.message.error { background: #fff0ee; border-color: #f4b8b1; }

.modal-backdrop {
    position: fixed;
    inset: 70px 0 0;
    z-index: 9;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(24, 33, 29, 0.28);
}
.modal-card {
    width: min(460px, 100%);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
    padding: 22px;
}
.modal-card h1 {
    margin: 0;
    font-size: 25px;
    line-height: 1.15;
    letter-spacing: 0;
}
.modal-copy {
    margin: 12px 0 18px;
    color: var(--muted);
}

@media (max-width: 820px) {
    .topbar { align-items: flex-start; flex-direction: column; }
    .page-head { align-items: stretch; flex-direction: column; }
    .metric-grid, .metric-grid.compact, .cash-metric-grid, .vault-metric-grid, .split-grid, .cash-split-grid, .vault-split-grid, .cash-watch-grid { grid-template-columns: 1fr; }
    .filter-bar { grid-template-columns: 1fr 1fr; }
    .cash-filter-bar, .compensation-filter-bar, .vault-filter-bar { grid-template-columns: 1fr; }
    .cash-import-form { grid-template-columns: 1fr; }
    .vault-form-grid { grid-template-columns: 1fr; }
    .action-strip form, .action-strip .button, .actions .button { flex: 1 1 150px; }
    .button { width: 100%; }
}

@media (max-width: 480px) {
    .shell { padding-top: 16px; }
    .filter-bar { grid-template-columns: 1fr; }
    .cash-import-form { grid-template-columns: 1fr; }
    .definition-list { grid-template-columns: 1fr; }
    .metric strong { font-size: 23px; }
}
