@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&family=VT323&display=swap');

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    color: #333;
    background: #f5f7fa;
    padding: 12px;
    line-height: 1.5;
}

.loading {
    text-align: center;
    padding: 60px 20px;
    font-size: 16px;
    color: #888;
}

/* =========================
   CALCULATOR — Manager View (Light)
   ========================= */
.calculator {
    max-width: 600px;
    margin: 0 auto;
    background: #fff;
    border-radius: 24px;
    padding: 0;
    border: none;
    overflow: hidden;
    position: relative;
    box-shadow:
        0 30px 80px rgba(0,0,0,.2),
        0 10px 30px rgba(0,0,0,.12),
        6px 6px 14px rgba(0,0,0,.1),
        -6px -6px 14px rgba(255,255,255,.7);
}

.calculator::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 24px;
    box-shadow:
        inset 0 8px 20px rgba(0,0,0,.15),
        inset 0 -8px 20px rgba(0,0,0,.1),
        inset 8px 0 20px rgba(0,0,0,.08),
        inset -8px 0 20px rgba(0,0,0,.08);
    pointer-events: none;
    z-index: 2;
}

/* Display */
.calc-display {
    background: linear-gradient(135deg, #e8f5e9 0%, #f1f8e9 50%, #e8f5e9 100%);
    border: none;
    border-bottom: 1px solid #2e7d32;
    border-radius: 0;
    padding: 30px 24px;
    margin-bottom: 0;
    position: relative;
    overflow: hidden;
}

.calc-display::before {
    content: '';
    position: absolute; inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 3px,
        rgba(0,0,0,.02) 3px,
        rgba(0,0,0,.02) 4px
    );
    pointer-events: none;
}

.calc-display-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

.calc-display-left {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.calc-display-right {
    display: flex;
    align-items: baseline;
}

.calc-display-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    font-weight: 500;
    color: #1b5e20;
    letter-spacing: 3px;
    text-transform: uppercase;
}

.calc-display-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 40px;
    font-weight: 700;
    color: #1b5e20;
    letter-spacing: 2px;
    line-height: 1;
}

.calc-display-currency {
    font-family: 'JetBrains Mono', monospace;
    font-size: 16px;
    font-weight: 500;
    color: #1b5e20;
    margin-left: 6px;
}

/* Body */
.calc-body {
    background: #fff;
    border-radius: 0;
    padding: 20px 28px 24px;
}

.calc-period-row {
    margin-bottom: 14px;
    display: flex;
    gap: 8px;
    align-items: center;
}

.calc-period-row > * {
    flex: 1;
}

.calc-gear {
    background: none;
    border: none;
    padding: 4px;
    margin-top: 10px;
    color: #1b5e20;
    cursor: pointer;
    transition: color .15s;
    line-height: 0;
}

.calc-gear:hover {
    color: #2e7d32;
}

.calc-gear:active {
    color: #1b5e20;
}

.calc-employee-select {
    background: linear-gradient(180deg, #fff 0%, #f0f0f0 100%);
    border: none;
    color: #263238;
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    font-weight: 500;
    padding: 8px 12px;
    border-radius: 8px;
    outline: none;
    cursor: pointer;
    box-shadow:
        3px 3px 6px rgba(0,0,0,.1),
        -3px -3px 6px rgba(255,255,255,.8),
        inset 0 1px 0 rgba(255,255,255,.9);
    transition: all .15s;
}

.calc-employee-select:focus {
    box-shadow:
        inset 2px 2px 5px rgba(0,0,0,.1),
        inset -2px -2px 5px rgba(255,255,255,.7);
}

.calc-period-row .calc-period input[type="month"] {
    background: linear-gradient(180deg, #fff 0%, #f0f0f0 100%);
    border: none;
    color: #263238;
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    font-weight: 500;
    padding: 8px 12px;
    border-radius: 8px;
    outline: none;
    width: 100%;
    cursor: pointer;
    box-shadow:
        3px 3px 6px rgba(0,0,0,.1),
        -3px -3px 6px rgba(255,255,255,.8),
        inset 0 1px 0 rgba(255,255,255,.9);
    transition: all .15s;
}

.calc-period-row .calc-period input[type="month"]:focus {
    box-shadow:
        inset 2px 2px 5px rgba(0,0,0,.1),
        inset -2px -2px 5px rgba(255,255,255,.7);
    background: linear-gradient(180deg, #f0f0f0 0%, #fff 100%);
}

.calc-period-row .calc-period input[type="month"]:hover {
    box-shadow:
        4px 4px 8px rgba(0,0,0,.12),
        -4px -4px 8px rgba(255,255,255,.9),
        inset 0 1px 0 rgba(255,255,255,.9);
}

.calc-period-row .calc-period input[type="month"]::-webkit-datetime-edit {
    color: #1565c0;
    font-weight: 600;
}

.calc-section {
    margin-bottom: 14px;
}

.calc-section:last-of-type { margin-bottom: 16px; }

.calc-section-header {
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 3px;
    color: #78909c;
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid #e0e0e0;
}

.calc-fields {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 8px;
}

.calc-field-wide { grid-column: 1 / -1; }

.calc-field {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.calc-field-label {
    font-size: 12px;
    font-weight: 500;
    color: #78909c;
    text-transform: uppercase;
    letter-spacing: .5px;
}

.calc-input {
    background: #fafafa;
    border: 1px solid #cfd8dc;
    border-radius: 8px;
    color: #263238;
    font-family: 'JetBrains Mono', monospace;
    font-size: 20px;
    font-weight: 500;
    padding: 10px 12px;
    text-align: center;
    outline: none;
    transition: all .15s;
    width: 100%;
    -moz-appearance: textfield;
    appearance: textfield;
}

.calc-input::-webkit-outer-spin-button,
.calc-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.calc-input:focus {
    border-color: #42a5f5;
    box-shadow: 0 0 0 2px rgba(66,165,245,.2);
    background: #fff;
}

.calc-input.readonly {
    background: #f5f5f5;
    color: #90a4ae;
    border-color: #eceff1;
}

.calc-result {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #e3f2fd;
    border: none;
    border-radius: 8px;
    padding: 10px 16px;
    margin-top: 8px;
}

.calc-result span:first-child {
    font-size: 14px;
    font-weight: 500;
    color: #546e7a;
    text-transform: uppercase;
    letter-spacing: .5px;
}

.calc-result-val {
    font-family: 'JetBrains Mono', monospace;
    font-size: 20px;
    color: #1565c0;
    font-weight: 700;
}

/* KPI header row */
.kpi-header {
    display: grid;
    grid-template-columns: 1fr 50px 100px 100px 80px;
    gap: 8px;
    padding: 0 0 4px;
    margin-bottom: 4px;
    border-bottom: 1px solid #e0e0e0;
}

.kpi-header span {
    font-size: 11px;
    font-weight: 600;
    color: #90a4ae;
    text-transform: uppercase;
    letter-spacing: .5px;
    text-align: center;
}

.kpi-header span:first-child { text-align: left; }

/* KPI rows in calculator */
.kpi-row {
    display: grid;
    grid-template-columns: 1fr 50px 100px 100px 80px;
    gap: 8px;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid #eeeeee;
}

.kpi-row:last-child { border-bottom: none; }

.kpi-row .kpi-name {
    font-size: 14px;
    font-weight: 500;
    color: #37474f;
}

.kpi-row .kpi-weight-display {
    font-family: 'JetBrains Mono', monospace;
    font-size: 16px;
    font-weight: 500;
    color: #90a4ae;
    text-align: center;
}

.kpi-row .kpi-plan,
.kpi-row .kpi-fact {
    background: #fafafa;
    border: 1px solid #cfd8dc;
    border-radius: 6px;
    color: #263238;
    font-family: 'JetBrains Mono', monospace;
    font-size: 16px;
    font-weight: 500;
    padding: 7px 8px;
    text-align: center;
    outline: none;
    width: 100%;
    -moz-appearance: textfield;
    appearance: textfield;
}

.kpi-row .kpi-plan::-webkit-outer-spin-button,
.kpi-row .kpi-plan::-webkit-inner-spin-button,
.kpi-row .kpi-fact::-webkit-outer-spin-button,
.kpi-row .kpi-fact::-webkit-inner-spin-button {
    -webkit-appearance: none;
}

.kpi-row .kpi-plan:focus,
.kpi-row .kpi-fact:focus {
    border-color: #42a5f5;
    box-shadow: 0 0 0 2px rgba(66,165,245,.2);
    background: #fff;
}

.kpi-row .kpi-plan.readonly,
.kpi-row .kpi-fact.readonly {
    background: #f5f5f5;
    color: #90a4ae;
    border-color: #eceff1;
}

.kpi-result {
    font-family: 'JetBrains Mono', monospace;
    font-size: 16px;
    font-weight: 600;
    text-align: right;
    align-self: center;
    color: #90a4ae;
}

.kpi-result.ok { color: #2e7d32; }
.kpi-result.zero { color: #d32f2f; }

/* Calculator buttons */
.calc-actions {
    display: flex;
    gap: 8px;
}

.calc-btn {
    flex: 1;
    padding: 18px 20px;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
    text-transform: uppercase;
    letter-spacing: .5px;
}

.calc-btn-primary {
    background: linear-gradient(135deg, #42a5f5, #1e88e5);
    color: #fff;
    box-shadow: 0 4px 12px rgba(30,136,229,.25);
}

.calc-btn-primary:hover {
    background: linear-gradient(135deg, #64b5f6, #42a5f5);
    box-shadow: 0 6px 16px rgba(30,136,229,.35);
    transform: translateY(-1px);
}

.calc-btn-secondary {
    background: #eceff1;
    color: #546e7a;
}

.calc-btn-secondary:hover {
    background: #cfd8dc;
    color: #37474f;
}

/* =========================
   RECEIPT — Summary
   ========================= */
.receipt-wrap {
    max-width: 400px;
    margin: 30px auto 60px;
    position: relative;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,.15));
}

.receipt {
    background: #fff;
    padding: 32px 32px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 16px;
    color: #222;
    line-height: 1.6;
    clip-path: polygon(
        0% 8px, 1.5% 3px, 3% 6px, 5% 0, 7% 5px, 8.5% 2px, 10% 7px, 12% 1px, 14% 8px,
        15.5% 3px, 17% 0, 19% 6px, 21% 2px, 23% 7px, 24.5% 4px, 26% 0, 28% 5px,
        30% 8px, 31.5% 1px, 33% 6px, 35% 3px, 37% 0, 39% 7px, 40.5% 2px, 42% 5px,
        44% 8px, 46% 1px, 47.5% 4px, 49% 0, 51% 6px, 53% 3px, 55% 8px, 56.5% 1px,
        58% 5px, 60% 0, 62% 7px, 63.5% 2px, 65% 6px, 67% 8px, 69% 1px, 71% 4px,
        72.5% 0, 74% 7px, 76% 3px, 78% 8px, 79.5% 2px, 81% 5px, 83% 0, 85% 6px,
        87% 8px, 88.5% 1px, 90% 4px, 92% 7px, 93.5% 0, 95% 5px, 97% 3px, 99% 7px, 100% 2px,
        100% calc(100% - 3px), 99% calc(100% - 7px), 97% 100%, 95.5% calc(100% - 5px),
        94% calc(100% - 1px), 92% calc(100% - 8px), 90% calc(100% - 2px), 88.5% 100%,
        87% calc(100% - 6px), 85% calc(100% - 1px), 83% calc(100% - 7px), 81.5% 100%,
        80% calc(100% - 4px), 78% calc(100% - 8px), 76% 100%, 74.5% calc(100% - 3px),
        73% calc(100% - 7px), 71% calc(100% - 1px), 69% 100%, 67.5% calc(100% - 5px),
        66% calc(100% - 8px), 64% calc(100% - 2px), 62% 100%, 60.5% calc(100% - 6px),
        59% calc(100% - 1px), 57% calc(100% - 7px), 55% 100%, 53.5% calc(100% - 4px),
        52% calc(100% - 8px), 50% calc(100% - 2px), 48% 100%, 46.5% calc(100% - 5px),
        45% calc(100% - 1px), 43% calc(100% - 7px), 41% 100%, 39.5% calc(100% - 3px),
        38% calc(100% - 8px), 36% calc(100% - 1px), 34% 100%, 32.5% calc(100% - 6px),
        31% calc(100% - 2px), 29% calc(100% - 8px), 27% 100%, 25.5% calc(100% - 4px),
        24% calc(100% - 7px), 22% 100%, 20.5% calc(100% - 3px), 19% calc(100% - 8px),
        17% calc(100% - 1px), 15% 100%, 13.5% calc(100% - 5px), 12% calc(100% - 7px),
        10% 100%, 8.5% calc(100% - 2px), 7% calc(100% - 6px), 5% 100%,
        3.5% calc(100% - 4px), 2% calc(100% - 8px), 0.5% 100%, 0% calc(100% - 3px)
    );
}

.receipt-header {
    text-align: center;
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 6px;
    text-transform: uppercase;
}

.receipt-subheader {
    text-align: center;
    font-size: 14px;
    color: #555;
    margin-bottom: 4px;
}

.receipt-subheader span + span::before {
    content: '\a';
    white-space: pre;
}

.receipt-divider {
    border: none;
    border-top: 1px dashed #999;
    margin: 10px 0;
}

.receipt-line {
    display: flex;
    justify-content: space-between;
    margin: 4px 0;
}

.receipt-label {
    text-transform: uppercase;
}

.receipt-amount {
    white-space: nowrap;
    text-align: right;
}

.receipt-total-line {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin: 6px 0 4px;
}

.receipt-total-label {
    font-size: 24px;
    font-weight: 700;
}

.receipt-total-amount {
    font-size: 28px;
    font-weight: 700;
}

.receipt-footer {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: #777;
    margin-top: 10px;
}

.receipt-disclaimer {
    margin-top: 10px;
    font-size: 11px;
    color: #999;
    text-align: center;
    line-height: 1.4;
}

/* =========================
   ADMIN — Card style (unchanged)
   ========================= */
.card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,.1);
    padding: 20px;
    margin-bottom: 16px;
}

h2 { font-size: 18px; margin-bottom: 16px; color: #1a1a1a; }
h3 { font-size: 15px; margin-bottom: 12px; color: #333; }

.hint { font-weight: normal; font-size: 12px; color: #888; }

.period-selector {
    display: flex; align-items: center; gap: 16px;
    margin-bottom: 16px; flex-wrap: wrap;
}

.employee-name { font-weight: 600; color: #2067b0; }

.section {
    border-top: 1px solid #eee;
    padding-top: 16px;
    margin-top: 16px;
}

.section:first-child { border-top: none; padding-top: 0; margin-top: 0; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 12px;
}

.form-group { display: flex; flex-direction: column; gap: 4px; }

.form-group label { font-size: 12px; color: #666; font-weight: 500; }

.card input[type="number"],
.card input[type="month"],
.card input[type="text"],
.card select {
    padding: 10px 12px;
    border: 1px solid #d0d5dd;
    border-radius: 6px;
    font-size: 16px;
    outline: none;
    transition: border-color .15s;
    width: 100%;
}

.card input[type="number"]::-webkit-inner-spin-button,
.card input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.card input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

.num-input-wrap {
    display: flex;
    align-items: stretch;
    gap: 0;
    border: 1px solid #d0d5dd;
    border-radius: 6px;
    overflow: hidden;
}

.num-input-wrap input[type="number"] {
    border: none;
    border-left: 1px solid #d0d5dd;
    border-right: 1px solid #d0d5dd;
    border-radius: 0;
    text-align: center;
    flex: 1;
    min-width: 0;
}

.num-input-wrap input[type="number"]:focus {
    box-shadow: none;
    border-color: #2067b0;
}

.num-btn {
    background: #f5f7fa;
    border: none;
    cursor: pointer;
    font-size: 20px;
    font-weight: 700;
    color: #555;
    padding: 0 16px;
    line-height: 1;
    transition: background .15s;
    -webkit-user-select: none;
    user-select: none;
}

.num-btn:hover {
    background: #e2e8f0;
    color: #222;
}

.num-btn:active {
    background: #d0d5dd;
}

.card input:focus, .card select:focus {
    border-color: #2067b0;
    box-shadow: 0 0 0 2px rgba(32,103,176,.15);
}

.card input.readonly { background: #f9fafb; color: #888; }

.result-line {
    background: #f0f4f8;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
}

.total-section { background: #f8fafc; border-radius: 6px; padding: 16px; }

.summary-table { width: 100%; max-width: 320px; border-collapse: collapse; }
.summary-table td { padding: 4px 8px; }
.summary-table .sum-val { text-align: right; font-weight: 600; }
.summary-table .total-row td { border-top: 2px solid #333; font-size: 16px; padding-top: 8px; }

.btn {
    padding: 8px 18px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: background .15s;
}

.btn-primary { background: #2067b0; color: #fff; }
.btn-primary:hover { background: #185a9e; }
.btn-secondary { background: #e8ecf1; color: #333; }
.btn-secondary:hover { background: #d5dbe3; }
.btn-danger { background: #e53e3e; color: #fff; font-size: 12px; padding: 4px 10px; }
.btn-danger:hover { background: #c53030; }

.actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* Tabs */
.tabs { display: flex; gap: 4px; margin-bottom: 16px; flex-wrap: wrap; }

.tab {
    padding: 8px 16px;
    border: 1px solid #d0d5dd;
    border-radius: 6px 6px 0 0;
    background: #f5f7fa;
    cursor: pointer;
    font-size: 13px;
    transition: background .15s;
}

.tab.active {
    background: #fff;
    border-bottom-color: #fff;
    font-weight: 600;
    color: #2067b0;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Tables */
.table-wrap { overflow-x: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th, .data-table td {
    padding: 8px 10px;
    text-align: left;
    border-bottom: 1px solid #eee;
}

.data-table th { background: #f5f7fa; font-weight: 600; color: #555; font-size: 12px; }

.data-table .total-row td {
    font-weight: 700;
    border-top: 2px solid #333;
    background: #f0f4f8;
}

.data-table input[type="number"], .data-table input[type="text"], .data-table select {
    padding: 4px 6px;
    font-size: 13px;
    min-width: 80px;
}

.data-table .btn-danger { padding: 2px 8px; }

.weight-check {
    margin-top: 8px;
    font-size: 13px;
}

.weight-ok { color: #38a169; }
.weight-err { color: #e53e3e; font-weight: 600; }

.employee-select-wrap { margin-bottom: 16px; }

/* KPI sort buttons */
.kpi-sort-cell { display: flex; flex-direction: column; gap: 2px; }
.btn-sort {
    background: #f5f7fa; border: 1px solid #ccc; border-radius: 3px;
    cursor: pointer; font-size: 11px; line-height: 1; padding: 3px 6px; color: #666;
}
.btn-sort:hover { background: #e2e8f0; color: #333; }

/* KPI auto toggle */
.kpi-auto-cell { white-space: nowrap; }
.auto-toggle { display: flex; align-items: center; gap: 4px; font-size: 13px; margin-bottom: 4px; cursor: pointer; }
.kpi-auto-cell select { width: 100%; }

/* Toast */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: 6px;
    color: #fff;
    font-size: 14px;
    z-index: 9999;
    animation: fadeIn .3s;
}

.toast-success { background: #38a169; }
.toast-error { background: #e53e3e; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 600px) {
    .form-grid { grid-template-columns: 1fr; }
    .calc-fields { grid-template-columns: 1fr 1fr 1fr; }
    .kpi-row { grid-template-columns: 1fr 40px 80px 80px 65px; font-size: 12px; }
    .calc-display-value { font-size: 32px; }
    .calculator { border-radius: 14px; }
    .receipt { padding: 20px 16px; }
}

/* Access user list */
.access-user-list {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    margin-bottom: 12px;
}
.access-user-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-bottom: 1px solid #f0f0f0;
    font-size: 14px;
    cursor: pointer;
    transition: background .1s;
}
.access-user-item:last-child { border-bottom: none; }
.access-user-item:hover { background: #f5f7fa; }
.access-user-item input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; }
.access-user-item.hidden { display: none; }
