:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --line: #e6e9f2;
    --line-strong: #d7dce8;
    --brand: #4f46e5;
    --brand-hover: #4338ca;
    --brand-soft: #eef2ff;
    --brand-ink: #3730a3;
    --sidebar: #0b1220;
    --sidebar-text: #94a3b8;
    --sidebar-active: #ffffff;
    --danger: #e11d48;
    --danger-soft: #fff1f2;
    --success: #059669;
    --success-soft: #ecfdf5;
    --warn: #d97706;
    --warn-soft: #fffbeb;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px rgba(15, 23, 42, .04);
    --font: "Plus Jakarta Sans", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

[x-cloak] { display: none !important; }

html, body {
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    letter-spacing: -.01em;
}

h1, h2, h3, h4, h5, .fw-semibold, .fw-bold {
    letter-spacing: -.03em;
}

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-hover); }

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

.app-sidebar {
    width: 268px;
    flex-shrink: 0;
    background: var(--sidebar);
    color: #fff;
    display: flex;
    flex-direction: column;
    padding: 22px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 4px 8px 22px;
}

.brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: linear-gradient(180deg, #6366f1, #4f46e5);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: .02em;
    flex-shrink: 0;
}

.brand-name { font-weight: 700; font-size: 14px; line-height: 1.25; }
.brand-sub { color: var(--sidebar-text); font-size: 12px; margin-top: 2px; }

.nav-label {
    color: #64748b;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    padding: 18px 12px 8px;
}

.app-sidebar .nav-link {
    color: var(--sidebar-text);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 10px;
    font-weight: 550;
    font-size: 14px;
}

.app-sidebar .nav-link i {
    width: 18px;
    text-align: center;
    font-size: 16px;
}

.app-sidebar .nav-link:hover {
    background: rgba(255,255,255,.06);
    color: #fff;
}

.app-sidebar .nav-link.active {
    background: var(--brand);
    color: var(--sidebar-active);
}

.app-main {
    flex: 1;
    min-width: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
}

.app-topbar {
    height: 72px;
    background: rgba(255,255,255,.84);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 20;
}

.page-title {
    font-size: 20px;
    font-weight: 750;
    margin: 0;
}

.app-content {
    padding: 28px;
    width: 100%;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--brand-soft);
    color: var(--brand-ink);
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 13px;
}

.card, .card.shadow-sm {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--line);
    padding: 16px 20px;
    font-weight: 650;
}

.card-body { padding: 20px; }
.card-footer { background: transparent; border-top: 1px solid var(--line); }

.kpi {
    overflow: hidden;
}

.kpi-label {
    color: var(--muted);
    font-size: 12px;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: .06em;
}

.kpi-value {
    font-size: 26px;
    font-weight: 750;
    margin-top: 6px;
    font-variant-numeric: tabular-nums;
}

.kpi-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: var(--brand-soft);
    color: var(--brand);
    font-size: 18px;
}

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

.stat-cell {
    padding: 12px 4px;
}

.kpi-link {
    display: block;
    color: inherit;
}
.kpi-link:hover {
    color: inherit;
    box-shadow: 0 8px 28px rgba(15, 23, 42, .08);
}
.dash-stats { grid-template-columns: repeat(4, 1fr); }
.dash-stats-2 { grid-template-columns: 1fr 1fr; }
.stat-value {
    font-weight: 700;
    font-size: 18px;
    margin-top: 6px;
    font-variant-numeric: tabular-nums;
}

.btn {
    border-radius: 10px;
    font-weight: 650;
    padding: 8px 14px;
    border: 1px solid transparent;
}

.btn-success, .btn-primary {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
}

.btn-success:hover, .btn-primary:hover {
    background: var(--brand-hover);
    border-color: var(--brand-hover);
    color: #fff;
}

.btn-outline-secondary, .btn-outline-primary {
    background: #fff;
    border-color: var(--line-strong);
    color: var(--text);
}

.btn-outline-secondary:hover, .btn-outline-primary:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
    color: var(--text);
}

.btn-outline-success {
    background: var(--success-soft);
    border-color: #a7f3d0;
    color: var(--success);
}

.btn-outline-danger {
    background: #fff;
    border-color: #fecdd3;
    color: var(--danger);
}

.btn-outline-danger:hover {
    background: var(--danger-soft);
    color: var(--danger);
    border-color: #fda4af;
}

.btn-link { color: var(--muted); font-weight: 600; }
.btn-sm { border-radius: 8px; padding: 4px 10px; font-size: 13px; }

.form-control, .form-select {
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    padding: 10px 12px;
    min-height: 44px;
    background: #fff;
    box-shadow: none;
}

.form-control:focus, .form-select:focus {
    border-color: #a5b4fc;
    box-shadow: 0 0 0 4px rgba(79, 70, 229, .12);
}

.form-control:disabled, .form-control[readonly] {
    background: #f8fafc;
    color: var(--muted);
}

.form-label {
    font-size: 13px;
    font-weight: 650;
    color: #334155;
    margin-bottom: 6px;
}

.form-text { color: var(--muted); font-size: 12px; }

.table {
    margin: 0;
    --bs-table-bg: transparent;
}

.table > :not(caption) > * > * {
    padding: 12px 14px;
    border-bottom-color: var(--line);
    vertical-align: middle;
}

.table thead th {
    background: #f8fafc;
    color: #64748b;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .07em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

.table-bordered, .table-bordered > :not(caption) > * > * {
    border-color: var(--line);
}

.table-hover tbody tr:hover { background: #f8fafc; }

.table-stock thead th.col-green,
.table-stock thead th.col-red {
    background: #f8fafc;
    color: #64748b;
}

.table-stock thead th.col-red { color: #be123c; }
.table-stock td.col-out, .table-stock tbody td:nth-child(4) { color: #be123c; }
.table-stock tfoot th {
    background: #f8fafc;
    font-weight: 700;
    border-top: 1px solid var(--line);
}

.table-daily {
    font-size: 12px;
}

.table-daily thead th {
    white-space: normal;
    min-width: 76px;
    max-width: 92px;
    line-height: 1.25;
    text-transform: none;
    letter-spacing: 0;
    font-size: 10px;
    padding: 8px 6px;
    vertical-align: bottom;
}

.table-daily tbody td,
.table-daily tfoot th {
    padding: 8px 6px;
}

.table-daily .sticky {
    position: sticky;
    left: 0;
    z-index: 2;
    background: #fff;
    min-width: 92px;
    box-shadow: 1px 0 0 var(--line);
}

.table-daily thead .sticky {
    background: #f8fafc;
    z-index: 3;
}

.table-daily tfoot .sticky,
.table-daily tfoot th {
    background: #ffedd5;
}

.table-daily .tone-input { background: #ecfdf5; }
.table-daily .tone-calc { background: #fff7ed; }
.table-daily .tone-cash { background: #ecfeff; }
.table-daily .tone-netcash { background: #fce7f3; }
.table-daily thead .tone-input { background: #d1fae5; }
.table-daily thead .tone-calc { background: #ffedd5; }
.table-daily thead .tone-cash { background: #cffafe; }
.table-daily thead .tone-netcash { background: #fbcfe8; }

.table-payroll thead th.tone-salary,
.table-payroll td.tone-salary { background: #bbf7d0; }
.table-payroll thead th.tone-incentive,
.table-payroll td.tone-incentive { background: #86efac; }
.table-payroll thead th.tone-subtotal,
.table-payroll td.tone-subtotal { background: #fde047; }
.table-payroll thead th.tone-due,
.table-payroll td.tone-due { background: #fdba74; }
.table-payroll thead th.tone-payable,
.table-payroll td.tone-payable { background: #7dd3fc; }
.table-payroll tfoot th { background: #ffedd5; }
.table-payroll .signature-cell { min-width: 90px; }

.calc-field.calc-salary { background: #bbf7d0 !important; }
.calc-field.calc-incentive { background: #86efac !important; }
.calc-field.calc-subtotal { background: #fde047 !important; }
.calc-field.calc-due { background: #fdba74 !important; }
.calc-field.calc-payable { background: #7dd3fc !important; }
.calc-field.calc-calc { background: #fff7ed !important; }

.tone-input-incentive { background: #ecfdf5; }
.tone-input-due { background: #fff7ed; }

.payroll-month-top { max-width: 340px; }

.table-ofs thead th {
    background: #ede9fe;
    color: #1e1b4b;
}

.table-ofs .tone-payable { background: #bbf7d0; }
.table-ofs thead th.tone-payable { background: #86efac; }
.table-ofs .tone-payment { background: #fde047; }
.table-ofs thead th.tone-payment { background: #facc15; }
.table-ofs .tone-rtgs { background: #ef4444; color: #fff; }
.table-ofs thead th.tone-rtgs { background: #dc2626; color: #fff; }
.table-ofs .ofs-low { color: #be123c; }
.table-ofs .ofs-ok { color: #047857; }
.table-ofs tfoot th { background: #ffedd5; }

.calc-field.calc-ofs { background: #fee2e2 !important; }
.calc-field.calc-rtgs { background: #fecaca !important; color: #991b1b; font-weight: 800; }
.tone-input-payable { background: #ecfdf5; }
.tone-input-payment { background: #fefce8; }

.form-section-title {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: #64748b;
    margin: 8px 0 4px;
}

.field-serial {
    display: inline-block;
    min-width: 22px;
    margin-right: 4px;
    color: #94a3b8;
    font-weight: 800;
    font-size: 11px;
}

.calc-field {
    background: #fff7ed !important;
    font-weight: 700;
}

.calc-field.calc-netcash { background: #fce7f3 !important; }
.calc-field.calc-cash { background: #ecfeff !important; }

.daily-calc-bar {
    grid-template-columns: 1fr 1fr 1fr 1fr;
}

.amount {
    font-variant-numeric: tabular-nums;
    text-align: right;
    white-space: nowrap;
    font-feature-settings: "tnum";
}

.alert {
    border: 0;
    border-radius: 12px;
    padding: 12px 16px;
}

.alert-success { background: var(--success-soft); color: #047857; }
.alert-danger { background: var(--danger-soft); color: #be123c; }

.badge {
    border-radius: 999px;
    font-weight: 650;
    padding: 5px 10px;
    font-size: 12px;
}

.badge-draft { background: #f1f5f9; color: #475569; }
.badge-submitted { background: var(--warn-soft); color: #b45309; }
.badge-paid { background: var(--success-soft); color: #047857; }
.badge-rejected { background: var(--danger-soft); color: #be123c; }

.toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 18px;
}

.hint { color: var(--muted); font-size: 13px; margin-top: 12px; }

.formula-guide {
    background: #f8fafc;
    border: 1px dashed var(--line-strong);
    border-radius: 14px;
    padding: 16px 18px;
    margin: 22px 0 0;
}

.formula-guide-title {
    font-weight: 800;
    font-size: 15px;
    margin-bottom: 4px;
}

.formula-block + .formula-block {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}

.formula-label {
    font-weight: 800;
    font-size: 13px;
    margin-bottom: 2px;
}

.formula-eq {
    font-size: 13px;
    color: var(--text);
}

.formula-note {
    font-size: 12px;
    color: var(--muted);
    margin-top: 4px;
}

.formula-live {
    margin-top: 6px;
    font-variant-numeric: tabular-nums;
    font-size: 13px;
    color: #0f766e;
}

.formula-live strong {
    font-size: 15px;
    color: #0f172a;
}

.daily-date-top {
    max-width: 280px;
    margin: 0 auto 22px;
    text-align: center;
}

.daily-date-top .form-label {
    display: block;
    text-align: center;
}

.daily-date-top .form-control {
    text-align: center;
}

.calc-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    background: #f8fafc;
    border: 1px dashed var(--line-strong);
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 18px;
}

.calc-bar .kpi-value { font-size: 22px; }

.login-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1.05fr .95fr;
}

.login-brand {
    background: #0b1220;
    color: #fff;
    padding: 56px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.login-brand h1 {
    font-size: 40px;
    font-weight: 750;
    max-width: 420px;
    line-height: 1.15;
}

.login-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    background: #fff;
}

.login-card-inner { width: 100%; max-width: 400px; }

.menu-btn {
    display: none;
    border: 1px solid var(--line-strong);
    background: #fff;
    border-radius: 10px;
    width: 40px;
    height: 40px;
}

@media (max-width: 991.98px) {
    .app-shell { display: block; }
    .app-sidebar {
        display: none;
        width: 100%;
        height: auto;
        position: static;
    }
    .app-sidebar.is-open { display: flex; }
    .menu-btn { display: grid; place-items: center; }
    .login-shell { grid-template-columns: 1fr; }
    .login-brand { min-height: 220px; padding: 32px; }
    .stat-grid, .dash-stats { grid-template-columns: 1fr 1fr; }
    .app-content { padding: 18px; }
    .daily-calc-bar { grid-template-columns: 1fr 1fr; }
}

.page-link {
    border-radius: 8px !important;
    margin: 0 2px;
    border-color: var(--line-strong);
    color: var(--text);
}
.page-item.active .page-link {
    background: var(--brand);
    border-color: var(--brand);
}

.field-plus {
    padding: 0 6px;
    line-height: 1.2;
    border-radius: 8px;
}

.credit-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1050;
    background: rgba(15, 23, 42, .45);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 48px 16px 24px;
    overflow: auto;
}

.credit-modal {
    width: min(720px, 100%);
    max-height: calc(100vh - 72px);
    display: flex;
    flex-direction: column;
}

.credit-modal .card-body {
    overflow: auto;
}

.credit-search-results {
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    max-height: 180px;
    overflow: auto;
}

.credit-search-item {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    text-align: left;
    background: #fff;
    border: 0;
    border-bottom: 1px solid var(--line);
    padding: 8px 12px;
}

.credit-search-item:last-child { border-bottom: 0; }
.credit-search-item:hover { background: var(--brand-soft); }

.credit-search-row {
    display: flex;
    align-items: stretch;
    border-bottom: 1px solid var(--line);
}

.credit-search-row:last-child { border-bottom: 0; }
.credit-search-row .credit-search-item { border-bottom: 0; flex: 1; min-width: 0; }

.credit-search-delete {
    flex: 0 0 40px;
    border: 0;
    border-left: 1px solid var(--line);
    background: #fff;
    color: #be123c;
    font-size: 18px;
    line-height: 1;
}

.credit-search-delete:hover { background: #fff1f2; }

.credit-search-edit {
    flex: 0 0 40px;
    border: 0;
    border-left: 1px solid var(--line);
    background: #fff;
    color: var(--muted);
    font-size: 14px;
}

.credit-search-edit:hover { background: var(--brand-soft); color: var(--brand-ink); }

.period-toggle .btn { min-width: 72px; }

@media print {
    .app-sidebar, .app-topbar, .no-print, .menu-btn { display: none !important; }
    .app-content { max-width: none; padding: 0; }
    body, .app-main { background: #fff; }
    .card { box-shadow: none; border: 0; }
    .payroll-sheet .table-responsive { overflow: visible !important; }
    .payroll-sheet .table-daily { width: 100% !important; font-size: 8px; }
    .payroll-sheet .table-daily thead th {
        font-size: 7px;
        min-width: 0;
        max-width: none;
        white-space: normal;
        overflow-wrap: anywhere;
        padding: 3px 2px;
    }
    .payroll-sheet .table-daily tbody td,
    .payroll-sheet .table-daily tfoot th { padding: 3px 2px; }
    .payroll-sheet .table-daily .sticky { position: static; box-shadow: none; min-width: 0; }
    .payroll-sheet .signature-cell { height: 32px; min-width: 64px; }
}

.payroll-signoff {
    display: flex;
    justify-content: flex-end;
    gap: 48px;
    margin-top: 28px;
    font-size: 13px;
}

.payroll-sign-line {
    width: 180px;
    border-bottom: 1px solid #0f172a;
    height: 36px;
    margin-bottom: 6px;
}
