:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --bg-dark: #0f172a;
    --bg-card: rgba(30, 41, 59, 0.7);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --glass-border: rgba(255, 255, 255, 0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background-image:
        radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 0%, rgba(168, 85, 247, 0.15) 0px, transparent 50%);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
    width: 100%;
}

/* Glassmorphism Card */
.card {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    padding: 2rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

h1,
h2,
h3 {
    margin-bottom: 1rem;
    font-weight: 700;
    letter-spacing: -0.025em;
}

h1 {
    font-size: 2.5rem;
    background: linear-gradient(to right, #fff, #94a3b8);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

input,
select,
button {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    border: 1px solid var(--glass-border);
    background: rgba(15, 23, 42, 0.5);
    color: white;
    margin-bottom: 1rem;
    font-size: 1rem;
    transition: all 0.2s;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

button {
    background: var(--primary);
    border: none;
    font-weight: 600;
    cursor: pointer;
}

button:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
}

.calendar-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    gap: 1rem;
    flex-wrap: nowrap;
}

.calendar-controls h2 {
    font-size: 1.5rem;
    white-space: nowrap;
}

/* --- Navigation --- */
.nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 2rem;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--glass-border);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.nav-brand {
    font-size: 1.5rem;
    font-weight: 800;
    color: white;
    text-decoration: none;
    background: linear-gradient(135deg, #6366f1, #a855f7);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    transition: opacity 0.2s;
}

.nav-brand:hover {
    opacity: 0.8;
}

.nav-links {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.nav-links a {
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-links a:hover {
    color: white;
    background: rgba(255, 255, 255, 0.08);
}

/* --- Hamburger Icon --- */
.nav-toggle {
    display: none;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    z-index: 1100;
    width: 40px;
    height: 40px;
    position: relative;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 6px;
}

.hamburger-line {
    display: block;
    width: 24px;
    height: 2px;
    background-color: white;
    border-radius: 2px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-toggle.active .hamburger-line:nth-child(1) {
    transform: translateY(8px) rotate(45deg);
}

.nav-toggle.active .hamburger-line:nth-child(2) {
    opacity: 0;
    transform: translateX(-10px);
}

.nav-toggle.active .hamburger-line:nth-child(3) {
    transform: translateY(-8px) rotate(-45deg);
}

/* --- Mobile Overlay --- */
.nav-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 1050;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.nav-overlay.active {
    display: block;
    opacity: 1;
}

/* --- Mobile View --- */
@media (max-width: 768px) {
    .nav {
        padding: 0.75rem 1.25rem;
    }

    .nav-toggle {
        display: flex;
    }

    .nav-links {
        position: fixed;
        top: 0;
        right: -300px;
        width: 300px;
        height: 100vh;
        background: rgba(15, 23, 42, 0.95);
        flex-direction: column;
        padding: 5rem 1.5rem 2rem;
        box-shadow: -10px 0 30px rgba(0, 0, 0, 0.3);
        transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.4s;
        z-index: 1001;
        backdrop-filter: blur(20px);
        align-items: flex-start;
        gap: 1rem;
        visibility: hidden;
    }

    .nav-links.active {
        transform: translateX(-300px);
        visibility: visible;
    }

    .nav-links a {
        font-size: 1.1rem;
        width: 100%;
        padding: 0.75rem 1.25rem;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        border-radius: 0;
    }

    .nav-links a:last-child {
        border-bottom: none;
        margin-top: auto;
        color: #f87171;
    }
}

body.lock-scroll {
    overflow: hidden;
}

/* --- Global Modal Overlay --- */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    overflow-y: auto;
    box-sizing: border-box;
    padding: 1rem;
}

.modal-overlay.active {
    display: flex;
}

/* Constrain all modal cards globally */
.modal-overlay>.card,
.modal-overlay .card {
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-sizing: border-box;
    margin: auto;
    flex-shrink: 0;
}

/* Pop-overs that use inline style fixed positioning */
[style*="position: fixed"]>.card {
    box-sizing: border-box;
    max-width: min(600px, calc(100vw - 2rem));
    width: 95%;
    overflow-x: hidden;
    overflow-y: auto;
    max-height: 90vh;
}

/* Ensure tables inside modals scroll horizontally rather than push content */
.card table {
    min-width: 0;
    width: 100%;
}

/* Wrap any overflowing tables horizontally */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
}

/* Modal close button - styled as small circle, no overlap */
.modal-close-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    width: 2rem;
    height: 2rem;
    min-width: 2rem;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin: 0;
    line-height: 1;
    transition: background 0.2s;
    flex-shrink: 0;
}

.modal-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: none;
}

/* Give all fixed-overlay cards top padding so absolute close btn doesn't overlap */
[style*="position: fixed"]>.card {
    padding-top: 3.5rem;
}

/* --- Base Table Styles (Desktop) --- */
table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
    font-size: 0.95rem;
}

th,
td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--glass-border);
}

th {
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.85rem;
    background: rgba(255, 255, 255, 0.05);
}

tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

/* --- Base Calendar Styles (Desktop) --- */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background: var(--glass-border);
    border-radius: 0.5rem;
    overflow: hidden;
}

.calendar-header {
    background: rgba(255, 255, 255, 0.1);
    padding: 1rem;
    text-align: center;
    font-weight: bold;
    color: #cbd5e1;
}

.calendar-cell {
    background: var(--bg-card);
    min-height: 120px;
    padding: 0.5rem;
    position: relative;
    cursor: pointer;
    transition: background 0.2s;
}

.calendar-cell:hover {
    background: rgba(30, 41, 59, 0.9);
}

.date-number {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    font-weight: 600;
    color: var(--text-muted);
}

.punch-summary {
    position: absolute;
    bottom: 0.5rem;
    left: 0.5rem;
    right: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    font-size: 0.8rem;
}

.status-message {
    font-size: 0.9rem;
    padding: 0.75rem;
}

/* Responsive Grid Helper */
.grid-responsive {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}


@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    .card {
        padding: 1.5rem;
    }

    .grid-responsive {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    h1 {
        font-size: 2rem;
    }

    .calendar-controls {
        flex-direction: row;
        justify-content: space-between;
        gap: 0.5rem;
    }

    .calendar-controls h2 {
        font-size: 1.25rem;
        margin-bottom: 0;
    }

    .calendar-controls button {
        width: auto;
        padding: 0.5rem 1rem;
    }

    /* Card-based Mobile Table (Page-level only, not inside modals) */
    .container table,
    .container thead,
    .container tbody,
    .container th,
    .container td,
    .container tr {
        display: block;
    }

    .container thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    .container tr {
        margin-bottom: 1.5rem;
        background: rgba(30, 41, 59, 0.4);
        border: 1px solid var(--glass-border);
        border-radius: 1rem;
        padding: 1rem;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    }

    .container td {
        border: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        position: relative;
        padding-left: 50% !important;
        text-align: right !important;
        white-space: normal;
        min-height: 3rem;
        display: flex;
        align-items: center;
        justify-content: flex-end;
    }

    .container td:last-child {
        border-bottom: none;
    }

    .container td::before {
        content: attr(data-label);
        position: absolute;
        left: 1rem;
        width: 45%;
        padding-right: 10px;
        white-space: nowrap;
        text-align: left;
        font-weight: 600;
        color: var(--text-muted);
        font-size: 0.85rem;
        text-transform: uppercase;
    }

    /* Tables inside popup cards: horizontal scroll, not card view */
    [style*="position: fixed"] table,
    [style*="position: fixed"] thead,
    [style*="position: fixed"] tbody,
    [style*="position: fixed"] th,
    [style*="position: fixed"] td,
    [style*="position: fixed"] tr {
        display: revert;
    }

    [style*="position: fixed"] table {
        width: 100%;
        display: block;
        overflow-x: auto;
    }

    [style*="position: fixed"] thead tr {
        position: static;
    }

    /* Compact Calendar for Mobile */
    .calendar-grid {
        /* Handled by global styles, just need to adjust padding/sizing */
    }

    .calendar-header {
        padding: 0.5rem;
        font-size: 0.7rem;
    }

    .calendar-cell {
        min-height: 80px;
        padding: 0.25rem;
    }

    .date-number {
        font-size: 0.9rem;
    }

    .punch-summary {
        font-size: 0.65rem;
    }

    /* Professional Modal for Mobile */
    #employee-modal .card,
    #day-modal .card,
    #payslip-modal .card,
    #advance-modal .card {
        width: 100%;
        height: 100%;
        max-width: none;
        margin: 0;
        border-radius: 0;
        overflow-y: auto;
        padding: 4rem 1.5rem 2rem;
        display: flex;
        flex-direction: column;
    }

    #payslip-modal .card {
        padding-top: 2rem;
    }

    #payslip-content {
        font-size: 0.85rem;
    }

    #payslip-content table td {
        padding: 0.5rem 0 !important;
        display: table-cell !important;
        text-align: left !important;
        position: static !important;
        min-height: 0 !important;
        width: auto !important;
    }

    #payslip-content table td:last-child {
        text-align: right !important;
    }

    #payslip-content table td::before {
        display: none !important;
    }

    #employee-modal .card h2,
    #day-modal .card h2,
    #payslip-modal .card h2,
    #advance-modal .card h2 {
        font-size: 1.75rem;
    }

    /* All inline/fixed overlay modals on mobile */
    [style*="position: fixed"] {
        overflow-y: auto;
        overflow-x: hidden;
    }

    [style*="position: fixed"]>.card {
        max-width: calc(100vw - 2rem) !important;
        width: 95% !important;
        margin: auto !important;
        overflow-x: hidden !important;
        box-sizing: border-box !important;
    }

    /* Tables inside modals: allow horizontal scroll within cell, not page */
    .card table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* But restore for the payslip table specifically */
    #payslip-content table {
        display: table;
        width: 100%;
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}