:root {
    --bg: #f6f1e8;
    --panel: #fffdf8;
    --panel-strong: #fff7e8;
    --line: #d9c6a6;
    --ink: #22170d;
    --muted: #68584a;
    --accent: #0f766e;
    --accent-dark: #134e4a;
    --warn: #b45309;
    --danger: #b91c1c;
    --success: #166534;
    --shadow: 0 20px 60px rgba(66, 40, 10, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", "Helvetica Neue", sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at top right, rgba(15, 118, 110, 0.13), transparent 32%),
        radial-gradient(circle at top left, rgba(217, 119, 6, 0.12), transparent 30%),
        var(--bg);
}

a {
    color: var(--accent-dark);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

button,
.primary-button,
.secondary-button {
    border: 0;
    border-radius: 999px;
    background: var(--accent);
    color: white;
    padding: 0.82rem 1.22rem;
    font-weight: 700;
    cursor: pointer;
}

.primary-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: white;
    text-decoration: none;
}

.primary-button:hover,
.primary-button:focus,
.primary-button:visited {
    color: white;
    text-decoration: none;
}

.toggle-button {
    background: #eadcc0;
    color: var(--ink);
}

.toggle-button.is-active {
    background: var(--accent);
    color: white;
}

.secondary-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #eadcc0;
    color: var(--ink);
}

.danger-button {
    background: var(--danger);
    color: white;
}

.link-button {
    background: none;
    color: var(--accent-dark);
    padding: 0;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 0.8rem 0.9rem;
    font: inherit;
    color: var(--ink);
    background: white;
}

textarea {
    resize: vertical;
}

label span {
    display: block;
    margin-bottom: 0.4rem;
    font-weight: 700;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 920px;
}

th,
td {
    padding: 0.82rem;
    border-bottom: 1px solid rgba(217, 198, 166, 0.85);
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 0.92rem;
}

.sticky-head-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--panel);
    box-shadow: inset 0 -1px 0 rgba(217, 198, 166, 0.95);
}

.page-shell {
    max-width: 1440px;
    margin: 0 auto;
    padding: 1.5rem;
}

.topbar {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-start;
    margin-bottom: 1.5rem;
}

.brand {
    display: inline-block;
    font-size: 1.95rem;
    font-weight: 800;
    color: var(--ink);
}

.subtitle {
    color: var(--muted);
    margin: 0.35rem 0 0;
}

.topnav {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

.session-pill {
    padding: 0.45rem 0.9rem;
    border-radius: 999px;
    background: rgba(15, 118, 110, 0.10);
    color: var(--accent-dark);
    font-weight: 700;
}

.card {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(255, 250, 241, 0.98));
    border: 1px solid rgba(217, 198, 166, 0.88);
    border-radius: 24px;
    padding: 1.3rem;
    box-shadow: var(--shadow);
}

.nested-card {
    background: rgba(255, 255, 255, 0.45);
    border-style: dashed;
    box-shadow: none;
}

.stack {
    display: grid;
    gap: 1.1rem;
}

.hero-grid,
.chart-grid,
.form-grid,
.info-grid,
.scope-grid,
.auth-grid {
    display: grid;
    gap: 1rem;
}

.hero-grid {
    grid-template-columns: 1.2fr 1fr;
}

.auth-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: min(1100px, 100%);
}

.scope-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.chart-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.chart-grid.triple {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.form-grid,
.info-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.stats-wide-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 1rem;
}

.stat-grid.single-column {
    grid-template-columns: 1fr;
}

.stat-card,
.chart-panel {
    background: var(--panel-strong);
    border: 1px solid rgba(217, 198, 166, 0.88);
    border-radius: 20px;
    padding: 1rem;
}

.stat-card strong {
    display: block;
    font-size: 1.7rem;
    margin-top: 0.35rem;
}

.highlight-number {
    display: block;
    font-size: 1.7rem;
    font-weight: 800;
    line-height: 1.1;
    margin: 0.2rem 0 0.45rem;
}

.label,
.muted,
.meta-line {
    color: var(--muted);
}

.label {
    display: block;
    font-size: 0.9rem;
    margin-bottom: 0.3rem;
}

.locked-value {
    display: inline-block;
    min-width: 140px;
    padding: 0.8rem 0;
    font-weight: 700;
}

.locked-link {
    display: inline-flex;
    align-items: center;
    min-width: 140px;
    padding: 0.8rem 0;
    font-weight: 700;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 92px;
    padding: 0.45rem 0.8rem;
    border-radius: 999px;
    font-size: 0.88rem;
    font-weight: 700;
}

.status-badge.enabled {
    color: var(--success);
    background: rgba(22, 101, 52, 0.10);
}

.status-badge.disabled {
    color: var(--warn);
    background: rgba(180, 83, 9, 0.12);
}

.status-badge.indicator-status.stable {
    color: var(--success);
    background: rgba(22, 101, 52, 0.10);
}

.status-badge.indicator-status.watch,
.status-badge.indicator-status.insufficient {
    color: var(--warn);
    background: rgba(180, 83, 9, 0.12);
}

.status-badge.indicator-status.decline {
    color: var(--danger);
    background: rgba(185, 28, 28, 0.12);
}

.meta-list {
    display: grid;
    gap: 0.25rem;
}

.compact-list {
    gap: 0.6rem;
}

.indicator-list {
    margin: 0.2rem 0 0;
    padding-left: 1.2rem;
    display: grid;
    gap: 0.45rem;
}

.section-head {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-start;
}

.table-wrap {
    overflow-x: auto;
}

.inline-form {
    display: flex;
    gap: 0.8rem;
    align-items: end;
    flex-wrap: wrap;
}

.checkbox-field {
    display: grid;
    gap: 0.4rem;
}

.checkbox-inline {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    min-height: 46px;
}

.checkbox-inline input {
    width: auto;
    margin: 0;
}

.time-helper-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-top: 0.55rem;
}

.time-choice,
.time-clear-button {
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.9);
    color: var(--ink);
    padding: 0.42rem 0.8rem;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
}

.time-choice.suggested {
    background: rgba(15, 118, 110, 0.10);
    border-color: rgba(15, 118, 110, 0.32);
    color: var(--accent-dark);
}

.time-clear-button {
    color: var(--muted);
}

.button-row {
    display: flex;
    justify-content: flex-end;
    gap: 0.8rem;
    flex-wrap: wrap;
}

.table-actions {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    flex-wrap: wrap;
}

.table-actions form {
    margin: 0;
}

.salary-calculator-form {
    display: grid;
    gap: 1rem;
}

.salary-calculator-grid {
    display: grid;
    grid-template-columns: minmax(0, 320px) auto;
    gap: 1rem;
    align-items: end;
}

.salary-calculator-actions {
    display: flex;
    gap: 0.8rem;
    align-items: center;
    flex-wrap: wrap;
}

.salary-breakdown-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
}

.month-summary-grid,
.month-raw-summary-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.month-detail-legend {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.employee-mobile-page .table-wrap {
    width: 100%;
}

.legend-chip {
    display: inline-flex;
    align-items: center;
    padding: 0.45rem 0.8rem;
    border-radius: 999px;
    font-size: 0.88rem;
    font-weight: 700;
}

.legend-chip.corrected {
    color: #92400e;
    background: rgba(251, 191, 36, 0.22);
    border: 1px solid rgba(217, 119, 6, 0.28);
}

.legend-chip.heatmap-legend {
    border: 1px solid rgba(34, 23, 13, 0.10);
}

.legend-chip.heatmap-legend.full_stable {
    background: rgba(22, 101, 52, 0.18);
    color: #166534;
}

.legend-chip.heatmap-legend.full_issue {
    background: rgba(217, 119, 6, 0.18);
    color: #b45309;
}

.legend-chip.heatmap-legend.half_day {
    background: rgba(37, 99, 235, 0.16);
    color: #1d4ed8;
}

.legend-chip.heatmap-legend.short_presence {
    background: rgba(147, 51, 234, 0.14);
    color: #7e22ce;
}

.legend-chip.heatmap-legend.absent {
    background: rgba(185, 28, 28, 0.15);
    color: #b91c1c;
}

.legend-chip.heatmap-legend.off_day {
    background: rgba(107, 114, 128, 0.14);
    color: #4b5563;
}

.legend-chip.heatmap-legend.no_raw {
    background: rgba(148, 163, 184, 0.16);
    color: #475569;
}

.corrected-cell {
    background: rgba(251, 191, 36, 0.18);
    box-shadow: inset 0 0 0 1px rgba(217, 119, 6, 0.28);
}

.align-end {
    align-items: end;
}

.grow {
    flex: 1;
}

.chip-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
}

.chip {
    display: inline-flex;
    align-items: center;
    padding: 0.65rem 1rem;
    border-radius: 999px;
    background: var(--panel-strong);
    border: 1px solid var(--line);
}

.activity-heatmap-shell {
    display: grid;
    gap: 0.5rem;
    overflow-x: hidden;
    padding-bottom: 0.35rem;
    width: 100%;
}

.activity-heatmap-month-row {
    display: grid;
    grid-template-columns: 26px minmax(max-content, 1fr);
    gap: 0.35rem;
    align-items: end;
}

.activity-heatmap-corner {
    display: block;
}

.activity-heatmap-month-labels {
    display: grid;
    gap: 0.24rem;
    grid-template-columns: repeat(var(--week-count, 1), minmax(0, 1fr));
    width: 100%;
}

.activity-heatmap-month-label {
    min-width: 12px;
    font-size: 0.7rem;
    color: var(--muted);
    font-weight: 700;
}

.activity-heatmap-main {
    display: grid;
    grid-template-columns: 26px minmax(max-content, 1fr);
    gap: 0.35rem;
}

.activity-heatmap-weekday-column {
    display: grid;
    grid-template-rows: repeat(7, 14px);
    gap: 0.24rem;
    align-items: center;
}

.activity-heatmap-weekday-column span {
    font-size: 0.68rem;
    color: var(--muted);
    font-weight: 700;
    line-height: 1;
}

.activity-heatmap-week-columns {
    display: grid;
    grid-template-columns: repeat(var(--week-count, 1), minmax(0, 1fr));
    gap: 0.24rem;
    width: 100%;
}

.activity-heatmap-week {
    display: grid;
    grid-template-rows: repeat(7, 14px);
    gap: 0.24rem;
}

.activity-heatmap-cell {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    border-radius: 3px;
    border: 1px solid transparent;
    font-size: 0;
    line-height: 0;
    color: transparent;
}

.activity-heatmap-cell.empty {
    background: transparent;
    border-color: transparent;
}

.activity-heatmap-cell.full_stable {
    background: rgba(22, 101, 52, 0.18);
}

.activity-heatmap-cell.full_issue {
    background: rgba(217, 119, 6, 0.18);
}

.activity-heatmap-cell.half_day {
    background: rgba(37, 99, 235, 0.18);
}

.activity-heatmap-cell.short_presence {
    background: rgba(147, 51, 234, 0.16);
}

.activity-heatmap-cell.absent {
    background: rgba(185, 28, 28, 0.15);
}

.activity-heatmap-cell.off_day {
    background: rgba(107, 114, 128, 0.14);
    color: #4b5563;
}

.activity-heatmap-cell.no_raw {
    background: rgba(148, 163, 184, 0.16);
    color: #475569;
}

.activity-heatmap-cell.corrected {
    box-shadow: inset 0 0 0 2px rgba(217, 119, 6, 0.42);
}

.activity-heatmap-cell.pending-review {
    box-shadow: inset 0 0 0 2px rgba(180, 83, 9, 0.42);
}

.activity-heatmap-cell.confirmed {
    box-shadow: inset 0 0 0 2px rgba(15, 118, 110, 0.28);
}

.auth-wrap {
    min-height: 72vh;
    display: grid;
    place-items: center;
}

.auth-card {
    width: 100%;
}

.alert {
    border-radius: 16px;
    padding: 0.95rem 1rem;
    border: 1px solid;
}

.alert.error {
    color: var(--danger);
    border-color: rgba(185, 28, 28, 0.25);
    background: rgba(254, 242, 242, 0.95);
}

.alert.warning {
    color: var(--warn);
    border-color: rgba(180, 83, 9, 0.24);
    background: rgba(255, 247, 237, 0.96);
}

.alert.success {
    color: var(--success);
    border-color: rgba(22, 101, 52, 0.24);
    background: rgba(240, 253, 244, 0.96);
}

.form-table input,
.form-table select {
    min-width: 120px;
}

.employee-group {
    display: grid;
    gap: 0.8rem;
    padding: 1rem;
    border: 1px solid rgba(217, 198, 166, 0.88);
    border-radius: 20px;
    background: rgba(255, 247, 232, 0.55);
}

.employee-group h3 {
    margin: 0;
}

.employee-group-collapsible summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    cursor: pointer;
    font-weight: 700;
    list-style: none;
}

.employee-group-collapsible summary::-webkit-details-marker {
    display: none;
}

.employee-group-collapsible[open] summary {
    margin-bottom: 1rem;
}

.chart-stack {
    display: grid;
    gap: 1rem;
}

.collapsible-scope summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    cursor: pointer;
    font-weight: 700;
    list-style: none;
}

.collapsible-scope summary::-webkit-details-marker {
    display: none;
}

.summary-main {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.summary-inline {
    font-weight: 500;
}

.summary-action {
    white-space: nowrap;
}

.comparison-picker {
    border: 0;
    margin: 0;
    padding: 0;
    min-width: min(480px, 100%);
}

.comparison-picker legend {
    font-size: 0.9rem;
    font-weight: 700;
    margin-bottom: 0.4rem;
}

.comparison-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
}

.comparison-option {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.55rem 0.85rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--panel-strong);
    cursor: pointer;
}

.comparison-option input {
    margin: 0;
}

.collapsible-scope:not([open]) .chart-stack {
    display: none;
}

.collapsible-scope[open] summary {
    margin-bottom: 1rem;
}

.chart-box {
    width: 100%;
    height: 360px;
    background: rgba(255, 255, 255, 0.72);
    border-radius: 20px;
}

.chart-box.large {
    height: 460px;
}

@media (max-width: 1200px) {
    .stats-wide-grid,
    .chart-grid.triple,
    .scope-grid,
    .salary-breakdown-grid,
    .month-summary-grid,
    .month-raw-summary-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 980px) {
    .hero-grid,
    .chart-grid,
    .form-grid,
    .info-grid,
    .stat-grid,
    .auth-grid {
        grid-template-columns: 1fr;
    }

    .topbar,
    .section-head {
        flex-direction: column;
    }

    .salary-calculator-grid {
        grid-template-columns: 1fr;
    }

    .salary-calculator-actions {
        width: 100%;
    }

    .salary-calculator-actions > * {
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 760px) {
    .page-shell {
        padding: 1rem;
    }

    .brand {
        font-size: 1.65rem;
    }

    .employee-mobile-page .card,
    .employee-mobile-page .stat-card,
    .employee-mobile-page .chart-panel {
        padding: 1rem;
        border-radius: 20px;
    }

    .employee-mobile-page .button-row,
    .employee-mobile-page .inline-form,
    .employee-mobile-page .salary-calculator-actions {
        width: 100%;
    }

    .employee-mobile-page .button-row > *,
    .employee-mobile-page .salary-calculator-actions > * {
        width: 100%;
        justify-content: center;
    }

    .employee-mobile-page .inline-form label {
        width: 100%;
    }

    .employee-mobile-page .chart-box {
        height: 280px;
    }

    .employee-mobile-page .chart-box.large {
        height: 320px;
    }

    .employee-mobile-page table.mobile-stack-table {
        min-width: 0;
    }

    .employee-mobile-page .table-wrap {
        overflow: visible;
    }

    .employee-mobile-page .mobile-stack-table thead {
        display: none;
    }

    .employee-mobile-page .mobile-stack-table,
    .employee-mobile-page .mobile-stack-table tbody,
    .employee-mobile-page .mobile-stack-table tr,
    .employee-mobile-page .mobile-stack-table td {
        display: block;
        width: 100%;
    }

    .employee-mobile-page .mobile-stack-table tr {
        padding: 0.85rem 0;
        border-bottom: 1px solid rgba(217, 198, 166, 0.85);
    }

    .employee-mobile-page .mobile-stack-table td {
        border-bottom: 0;
        padding: 0.35rem 0;
    }

    .employee-mobile-page .mobile-stack-table td::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 0.18rem;
        color: var(--muted);
        font-size: 0.82rem;
        font-weight: 700;
    }

    .employee-mobile-page .mobile-stack-table td.corrected-cell {
        padding: 0.55rem 0.6rem;
        border-radius: 14px;
        margin: 0.1rem 0;
    }

    .employee-mobile-page .mobile-stack-table td[data-label="Tháng"] a {
        font-size: 1rem;
        font-weight: 700;
    }

    .employee-mobile-page .month-detail-legend {
        width: 100%;
    }
}

.print-only {
    display: none !important;
}

@page {
    size: A4 portrait;
    margin: 12mm;
}

@media print {
    body {
        background: white;
    }

    .page-shell {
        max-width: none;
        padding: 0;
    }

    .topbar,
    .print-hidden,
    .alert.warning {
        display: none !important;
    }

    .print-only {
        display: block !important;
    }

    .employee-print-layout {
        gap: 0.75rem;
    }

    .card,
    .stat-card,
    .employee-group,
    .chart-panel {
        background: white;
        border: 1px solid #d1d5db;
        box-shadow: none;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .hero-grid,
    .stats-wide-grid,
    .stat-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .chart-box {
        height: 210px;
        background: white;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .chart-box.large {
        height: 250px;
    }

    .print-history-section {
        break-before: page;
        page-break-before: always;
        break-inside: auto;
        page-break-inside: auto;
    }

    .print-history-section .table-wrap {
        overflow: visible;
    }

    .print-history-table {
        width: 100%;
        min-width: 0;
        font-size: 0.78rem;
    }

    .print-history-table thead {
        display: table-header-group;
    }

    .print-history-table tr {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .print-history-table th,
    .print-history-table td {
        padding: 0.35rem 0.4rem;
        word-break: break-word;
    }

    .print-history-table-compact {
        table-layout: fixed;
    }

    .print-history-table-compact th:nth-child(1),
    .print-history-table-compact td:nth-child(1) {
        width: 12%;
    }

    .print-history-table-compact th:nth-child(2),
    .print-history-table-compact td:nth-child(2) {
        width: 18%;
    }

    .print-history-table-compact th:nth-child(3),
    .print-history-table-compact td:nth-child(3) {
        width: 22%;
    }

    .print-history-table-compact th:nth-child(4),
    .print-history-table-compact td:nth-child(4) {
        width: 12%;
    }

    .print-history-table-compact th:nth-child(5),
    .print-history-table-compact td:nth-child(5) {
        width: 18%;
    }

    .print-history-table-compact th:nth-child(6),
    .print-history-table-compact td:nth-child(6) {
        width: 18%;
    }

    table {
        min-width: 0;
        font-size: 0.9rem;
    }

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