:root {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-card: rgba(255, 255, 255, 0.7);
    --bg-glass: rgba(255, 255, 255, 0.5);
    --border-glass: rgba(255, 255, 255, 0.8);
    --text-primary: #000000;
    --text-secondary: #222222;
    --text-muted: #444444;
    --accent-primary: #6366f1;
    --accent-secondary: #a855f7;
    --accent-gradient: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    /* E = Piket → Kuning */
    --status-e: #d4a017;
    --status-e-bg: rgba(234, 179, 8, 0.15);
    /* L = Libur → Merah */
    --status-l: #f43f5e;
    --status-l-bg: rgba(244, 63, 94, 0.15);
    /* X = Cuti → Ungu */
    --status-x: #9333ea;
    --status-x-bg: rgba(147, 51, 234, 0.15);
    /* O = WFO → Biru */
    --status-o: #2563eb;
    --status-o-bg: rgba(37, 99, 235, 0.15);
    /* W = WFH → Orange */
    --status-w: #f97316;
    --status-w-bg: rgba(249, 115, 22, 0.15);
    /* WE = WFH + Piket → Gradient orange-kuning */
    --status-we: #c2690e;
    --status-we-bg: rgba(220, 110, 20, 0.18);
    --weekend-bg: rgba(244, 63, 94, 0.05);
    --today-bg: rgba(99, 102, 241, 0.1);
    --today-border: #6366f1;
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 15px rgba(0, 0, 0, 0.04);
    --radius-lg: 20px;
    --radius-md: 12px;
    --radius-sm: 8px;
}

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

html {
    color-scheme: light;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    inset: -50%;
    background:
        radial-gradient(circle at 30% 20%, rgba(99, 102, 241, 0.12) 0%, transparent 50%),
        radial-gradient(circle at 70% 80%, rgba(244, 63, 94, 0.08) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(168, 85, 247, 0.1) 0%, transparent 50%);
    z-index: 0;
    animation: bgFloat 20s ease-in-out infinite;
}

@keyframes bgFloat {
    0%,
    100% {
        transform: translate(0, 0);
    }

    33% {
        transform: translate(-2%, 1%);
    }

    66% {
        transform: translate(1%, -2%);
    }
}

.app-container {
    position: relative;
    z-index: 1;
    max-width: 1400px;
    margin: 0 auto;
    padding: 30px 24px 60px;
}

.app-header {
    text-align: center;
    margin-bottom: 36px;
}

.app-header h1 {
    font-size: 2.2rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    margin-bottom: 8px;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.app-header p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 300;
}

.header-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-bottom: 12px;
}

.btn-sm {
    padding: 7px 14px;
    font-size: 0.78rem;
    border-radius: var(--radius-sm);
}

.login-link {
    gap: 6px;
}

.card {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 24px;
    margin-bottom: 24px;
}

#scheduleCard {
    padding: 16px 12px 12px;
}

#scheduleCard .card-title {
    margin-bottom: 14px;
}

#scheduleCard .legend-row {
    margin-bottom: 12px;
}

.card-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 18px;
}

.icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.06em;
}

.controls-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: end;
}

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

.period-state {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 220px;
}

.period-state-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.period-state-row {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
}

.period-lock-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 88px;
    padding: 8px 12px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    white-space: nowrap;
}

.period-lock-badge.unlocked {
    background: rgba(0, 184, 148, 0.16);
    color: var(--status-e);
}

.period-lock-badge.locked {
    background: rgba(253, 121, 168, 0.16);
    color: var(--status-l);
}

.period-lock-note {
    color: var(--text-secondary);
    font-size: 0.82rem;
    line-height: 1.35;
}

.control-group label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.select-styled,
.input-styled {
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    color: var(--text-primary);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    outline: none;
    transition: all 0.25s ease;
}

.select-styled:hover,
.input-styled:hover,
.select-styled:focus,
.input-styled:focus {
    border-color: var(--accent-primary);
    background: rgba(108, 92, 231, 0.08);
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.16);
}

.select-styled option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.input-styled {
    width: 120px;
}

.btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-left: auto;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:active {
    transform: scale(0.98);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: var(--accent-gradient);
    color: #fff;
    box-shadow: 0 4px 15px rgba(108, 92, 231, 0.35);
}

.btn-secondary {
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    color: var(--text-primary);
}

.btn-danger {
    background: rgba(244, 63, 94, 0.15);
    border: 1px solid rgba(244, 63, 94, 0.3);
    color: #f43f5e;
}

.btn-wfh {
    background: rgba(249, 115, 22, 0.15);
    border: 1px solid rgba(249, 115, 22, 0.3);
    color: var(--status-w);
}

.legend-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.legend-badge,
.stat-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    padding: 0 8px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
}

.legend-badge.e,
.stat-badge.e {
    background: var(--status-e-bg);
    color: var(--status-e);
}

.legend-badge.l,
.stat-badge.l {
    background: var(--status-l-bg);
    color: var(--status-l);
}

.legend-badge.x,
.stat-badge.x {
    background: var(--status-x-bg);
    color: var(--status-x);
}

.legend-badge.o {
    background: var(--status-o-bg);
    color: var(--status-o);
}

.legend-badge.w,
.stat-badge.w {
    background: var(--status-w-bg);
    color: var(--status-w);
}

.legend-badge.we,
.stat-badge.we {
    background: linear-gradient(90deg, rgba(249, 115, 22, 0.3) 50%, rgba(212, 160, 23, 0.3) 50%);
    color: #92400e;
    font-size: 0.62rem;
}

.legend-badge.oe,
.stat-badge.oe {
    background: linear-gradient(90deg, rgba(37, 99, 235, 0.3) 50%, rgba(212, 160, 23, 0.3) 50%);
    color: #1e3a5f;
    font-size: 0.62rem;
}

.settings-panel {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 18px;
}

.settings-section h3 {
    font-size: 0.95rem;
    margin-bottom: 12px;
}

.days-checkbox-group {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 10px;
}

.day-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    background: var(--bg-glass);
}

.day-checkbox.checked {
    border-color: rgba(253, 121, 168, 0.35);
    background: rgba(253, 121, 168, 0.09);
}

.day-checkbox input {
    accent-color: var(--accent-primary);
}

.holiday-input-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
}

.holiday-input-row .input-styled {
    flex: 1 1 180px;
    width: auto;
}

.holiday-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    min-height: 42px;
}

.holiday-tag {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(253, 121, 168, 0.12);
    border: 1px solid rgba(253, 121, 168, 0.2);
    color: var(--text-primary);
    font-size: 0.82rem;
}

.empty-holidays {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.remove-btn {
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.72rem;
}

.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-glass);
    scrollbar-width: thin;
}

#tableWrapper {
    display: block;
    width: 100%;
    max-width: 100%;
}

.schedule-table,
.summary-table {
    border-collapse: collapse;
}

.schedule-table {
    width: 100%;
    min-width: max-content;
    font-size: 0.68rem;
    table-layout: fixed;
}

.summary-table {
    width: 100%;
    min-width: 620px;
    font-size: 0.86rem;
}

.schedule-table th,
.schedule-table td,
.summary-table th,
.summary-table td {
    border: 1px solid var(--border-glass);
    padding: 8px 6px;
    text-align: center;
}

.schedule-table thead th,
.summary-table thead th {
    background: rgba(108, 92, 231, 0.12);
    color: var(--text-secondary);
    font-weight: 600;
}

.schedule-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    font-size: 0.58rem;
    line-height: 1.1;
    text-transform: uppercase;
}

.schedule-table th,
.schedule-table td {
    padding: 3px 2px;
}

.schedule-table thead th:not(.name-col),
.schedule-table td:not(.name-cell) {
    min-width: 30px;
}

.name-col,
.name-cell {
    text-align: left;
    min-width: 118px;
    width: 118px;
    max-width: 118px;
    padding-left: 8px;
}

.name-col {
    font-size: 0.6rem;
}

.name-cell {
    font-size: 0.68rem;
    line-height: 1.1;
    white-space: normal;
    overflow-wrap: anywhere;
}

.summary-table td:first-child,
.summary-table th:first-child {
    text-align: left;
    min-width: 180px;
    padding-left: 12px;
}

.weekend-head,
.weekend {
    background: var(--weekend-bg);
}

.holiday-head,
.holiday {
    background: rgba(253, 121, 168, 0.15);
}

.today-head {
    background: var(--today-bg);
    color: var(--text-primary);
}

.today-col {
    box-shadow: none;
}

.cell-select {
    width: 30px;
    min-width: 30px;
    padding: 2px;
    border-radius: 5px;
    border: 1px solid transparent;
    background-color: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
    font-size: 0.64rem;
    font-weight: 700;
    line-height: 1;
    text-align: center;
    text-align-last: center;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: none;
}

.cell-select:disabled {
    opacity: 0.8;
    cursor: not-allowed;
    padding-right: 2px;
}

.status-e {
    background: var(--status-e-bg);
    color: var(--status-e);
}

.status-l {
    background: var(--status-l-bg);
    color: var(--status-l);
}

.status-x {
    background: var(--status-x-bg);
    color: var(--status-x);
}

.status-o {
    background: var(--status-o-bg);
    color: var(--status-o);
}

.status-w {
    background: var(--status-w-bg);
    color: var(--status-w);
}

.status-we {
    background: linear-gradient(90deg, rgba(249, 115, 22, 0.3) 50%, rgba(212, 160, 23, 0.3) 50%);
    color: #92400e;
    font-size: 0.58rem;
}

.status-oe {
    background: linear-gradient(90deg, rgba(37, 99, 235, 0.3) 50%, rgba(212, 160, 23, 0.3) 50%);
    color: #1e3a5f;
    font-size: 0.58rem;
}

.chart-caption {
    margin: -6px 0 14px;
    color: var(--text-secondary);
    font-size: 0.82rem;
    line-height: 1.4;
}

.chart-container {
    position: relative;
    height: 320px;
}

.footer-note {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
    padding: 10px 0 4px;
}

.footer-note span {
    color: var(--status-l);
}

.toast {
    position: fixed;
    right: 24px;
    bottom: 24px;
    min-width: 260px;
    max-width: 420px;
    padding: 14px 16px;
    border-radius: 14px;
    border-left: 4px solid var(--accent-primary);
    background: rgba(255, 255, 255, 0.96);
    color: var(--text-primary);
    box-shadow: var(--shadow-md);
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 20;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

/* ── Modal ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-card {
    width: 100%;
    max-width: 440px;
    margin: 16px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: var(--radius-lg);
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.1);
    padding: 28px;
    transform: translateY(20px) scale(0.96);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-overlay.active .modal-card {
    transform: translateY(0) scale(1);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.modal-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.15rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.modal-title svg {
    color: var(--accent-secondary);
    -webkit-text-fill-color: initial;
}

.modal-close {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: rgba(253, 121, 168, 0.15);
    border-color: rgba(253, 121, 168, 0.3);
    color: #fd79a8;
}

.modal-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

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

.modal-form .form-group label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.modal-form .input-styled {
    width: 100%;
    padding: 12px 14px;
    font-size: 0.9rem;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 4px;
}

.modal-error {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    background: rgba(253, 121, 168, 0.1);
    border: 1px solid rgba(253, 121, 168, 0.25);
    color: #fd79a8;
    font-size: 0.84rem;
    font-weight: 500;
    margin-bottom: 4px;
    animation: shakeModal 0.35s ease-in-out;
}

.modal-success {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    background: rgba(0, 184, 148, 0.1);
    border: 1px solid rgba(0, 184, 148, 0.25);
    color: var(--status-e);
    font-size: 0.84rem;
    font-weight: 500;
    margin-bottom: 4px;
}

@keyframes shakeModal {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    50% { transform: translateX(5px); }
    75% { transform: translateX(-3px); }
}

.toast.success {
    border-left-color: var(--status-e);
}

.toast.info {
    border-left-color: var(--accent-primary);
}

@media (max-width: 768px) {
    .app-container {
        padding: 16px 12px 40px;
    }

    .app-header h1 {
        font-size: 1.6rem;
    }

    .controls-row {
        flex-direction: column;
        align-items: stretch;
    }

    .period-state {
        min-width: auto;
    }

    .period-state-row {
        align-items: flex-start;
        flex-direction: column;
        min-height: auto;
    }

    .btn-row {
        margin-left: 0;
        width: 100%;
    }

    .btn-row .btn {
        flex: 1 1 calc(50% - 10px);
    }

    .card {
        padding: 16px;
    }

    .schedule-table {
        width: max-content;
        min-width: max-content;
    }

    .name-col,
    .name-cell {
        min-width: 112px;
        width: 112px;
    }

    .chart-container {
        height: 260px;
    }

    .toast {
        left: 12px;
        right: 12px;
        bottom: 12px;
        min-width: auto;
    }
}

@media print {
    body {
        background: #fff;
        color: #000;
    }

    body::before {
        display: none;
    }

    .card {
        background: #fff;
        border: 1px solid #ddd;
        box-shadow: none;
    }

    .no-print,
    .btn-row,
    .btn,
    .toast {
        display: none !important;
    }

    .schedule-table th,
    .schedule-table td,
    .summary-table th,
    .summary-table td {
        border-color: #ccc;
    }

    .schedule-table thead th,
    .summary-table thead th {
        background: #f0f0f0;
        color: #333;
    }

    .app-header h1 {
        color: #333;
        background: none;
        -webkit-text-fill-color: #333;
    }
}
