/* ==========================================================================
   Zagu Attendance — theme system (light + dark), sticky header, responsive
   sidebar, digital clock, calendar and check-in/out chips.
   ========================================================================== */

/* ---- Theme tokens ------------------------------------------------------ */
:root {
    --bg: #f2f5f9;
    --surface: #ffffff;
    --surface-2: #f7f9fc;
    --text: #1e2733;
    --text-muted: #8a94a6;
    --border: #e6e9ef;
    --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
    --shadow-md: 0 4px 14px rgba(16, 24, 40, .08);

    --brand: #1e3a5f;
    --brand-dark: #142943;
    --brand-light: #2d5285;
    --accent: #f5a623;

    --success-bg: #dcf6e6;
    --success-text: #0e8a4b;
    --success-border: #b6ebc9;

    --info-bg: #dfeaff;
    --info-text: #1d5fd6;
    --info-border: #bcd6ff;

    --danger-bg: #fde4e4;
    --danger-text: #c22a2a;

    --warning-bg: #fff2d9;
    --warning-text: #966300;

    --topbar-h: 60px;
    --sidebar-w: 240px;
}

[data-theme="dark"] {
    --bg: #10141d;
    --surface: #171d29;
    --surface-2: #1d2431;
    --text: #e7ebf3;
    --text-muted: #8d97ab;
    --border: #2a3242;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-md: 0 8px 20px rgba(0, 0, 0, .45);

    --brand: #1c2b42;
    --brand-dark: #0f1826;
    --brand-light: #2f5486;
    --accent: #f5b93e;

    --success-bg: rgba(34, 197, 94, .14);
    --success-text: #4ade80;
    --success-border: rgba(34, 197, 94, .3);

    --info-bg: rgba(59, 130, 246, .16);
    --info-text: #6fa8ff;
    --info-border: rgba(59, 130, 246, .32);

    --danger-bg: rgba(239, 68, 68, .16);
    --danger-text: #f87171;

    --warning-bg: rgba(245, 169, 35, .16);
    --warning-text: #f5b93e;
}

* { scrollbar-color: var(--border) transparent; }

html, body {
    background: var(--bg);
    color: var(--text);
}

/* Tell the browser which palette to use for native controls (select
   option lists, scrollbars, checkboxes) so dropdown text stays legible
   instead of defaulting to a light-on-light native render in dark mode. */
[data-theme="dark"] { color-scheme: dark; }
[data-theme="light"] { color-scheme: light; }

body {
    transition: background-color .2s ease, color .2s ease;
    min-height: 100vh;
}

a { color: var(--info-text); }

/* ---- Topbar (sticky) ---------------------------------------------------- */
.topbar {
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 1040;
    box-shadow: var(--shadow-md);
    border: none;
    /* Bootstrap's base .navbar sets flex-wrap: wrap, which — once the
       brand text + the icon group no longer fit on one line on a phone —
       pushed the icons (theme toggle / bell / profile) onto a second row.
       The bar's height stays fixed, so that second row spilled out and
       overlapped the page content underneath it instead of being visible
       inside the bar. Force a single row and let the brand text ellipsis
       instead.
       NOTE: overflow used to be hidden here as the safety net for that,
       but the topbar is also the positioning parent for the notification
       and profile dropdown menus — clipping the bar clips them too, which
       is why "Sign Out" was invisible. The ellipsis truncation below on
       the brand group is the real fix, so overflow stays visible here. */
    flex-wrap: nowrap;
}
.topbar .navbar-brand { font-weight: 600; font-size: 1.05rem; }
/* Left group (hamburger + brand) is the only part allowed to shrink/clip;
   the icon group on the right always keeps its full size. */
.topbar .gap-2:has(.navbar-brand) {
    min-width: 0;
    overflow: hidden;
    flex-shrink: 1;
}
.topbar .navbar-brand {
    display: inline-block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
    max-width: 100%;
}
.topbar .gap-3 { flex-shrink: 0; }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,.18);
    background: rgba(255,255,255,.08);
    color: #fff;
    cursor: pointer;
    transition: background .15s ease, transform .15s ease;
}
.icon-btn:hover { background: rgba(255,255,255,.18); }
.icon-btn:active { transform: scale(.94); }
.theme-toggle .bi-moon-stars-fill { display: none; }
[data-theme="dark"] .theme-toggle .bi-sun-fill { display: none; }
[data-theme="dark"] .theme-toggle .bi-moon-stars-fill { display: inline-block; }

.sidebar-toggle-btn { display: none; }

/* ---- Layout shell -------------------------------------------------------- */
.app-shell { align-items: flex-start; }

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: var(--topbar-h) 0 0 0;
    background: rgba(0,0,0,.45);
    z-index: 1020;
}
.sidebar-backdrop.show { display: block; }

/* ---- Sidebar -------------------------------------------------------------- */
.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    min-height: calc(100vh - var(--topbar-h));
    background: var(--surface);
    border-right: 1px solid var(--border);
    position: sticky;
    top: var(--topbar-h);
    max-height: calc(100vh - var(--topbar-h));
    overflow-y: auto;
    transition: background-color .2s ease, border-color .2s ease;
    z-index: 1030;
}
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 10px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    margin-bottom: 2px;
    transition: background .15s ease, color .15s ease;
}
.sidebar-link i { font-size: 15px; width: 18px; text-align: center; }
.sidebar-link:hover {
    background: var(--surface-2);
    color: var(--text);
}
.sidebar-link.active {
    background: var(--brand);
    color: #fff;
    box-shadow: var(--shadow);
}
.sidebar hr { border-color: var(--border); }
.sidebar .text-muted { color: var(--text-muted) !important; }

/* ---- Content -------------------------------------------------------------- */
.content-area {
    max-width: 1200px;
    width: 100%;
}

/* ---- Cards ----------------------------------------------------------------- */
.stat-card, .table-card {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    transition: background-color .2s ease, border-color .2s ease, transform .15s ease, box-shadow .15s ease;
}
.stat-card {
    border-radius: 14px;
    box-shadow: var(--shadow);
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}
.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
}
.stat-card .stat-label {
    font-size: 11.5px;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: .05em;
    margin-top: 2px;
}
.stat-card .text-warning { color: var(--warning-text) !important; }
.stat-card .text-danger { color: var(--danger-text) !important; }

.table-card {
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 20px;
}

/* Profile card fields */
.table-card .text-muted { color: var(--text-muted) !important; }

/* Bootstrap's .text-muted ships its own !important gray that doesn't
   adapt to dark mode on its own — applying the theme token globally
   (not just inside .table-card/.sidebar) keeps every muted label legible
   in dark mode, e.g. "My Attendance (August 2026)". */
.text-muted { color: var(--text-muted) !important; }

/* .text-bg-light is a Bootstrap utility that bakes in its own light
   background AND dark text together. In dark mode our .text-dark
   override (below) turns the text light-colored, but the background
   stays Bootstrap's literal near-white — near-invisible low-contrast
   text (e.g. the "Member"/"Head" role badge, DTR "In"/"Out" chips).
   Give it real dark-mode surface + text colors instead. */
[data-theme="dark"] .text-bg-light {
    background-color: var(--surface-2) !important;
    color: var(--text) !important;
}

.notif-menu { min-width: 300px; max-width: 340px; max-height: 380px; overflow-y: auto; }
.notif-menu .dropdown-item { white-space: normal; }

/* Keep the notification / user-menu dropdowns fully on-screen on narrow
   viewports — they used to right-align against the icon button with a
   fixed min-width, which pushed them off the left edge of the screen on
   phones (rendering as an unreadable, clipped box). */
@media (max-width: 480px) {
    .notif-menu {
        min-width: 0;
        width: calc(100vw - 24px);
        max-width: calc(100vw - 24px);
        position: fixed !important;
        left: 12px !important;
        right: 12px !important;
        top: var(--topbar-h) !important;
        transform: none !important;
        z-index: 1050;
    }
    .user-menu-btn + .dropdown-menu {
        min-width: 0;
        width: calc(100vw - 24px);
        max-width: calc(100vw - 24px);
        position: fixed !important;
        left: 12px !important;
        right: 12px !important;
        top: var(--topbar-h) !important;
        transform: none !important;
        z-index: 1050;
    }
}

/* ---- Bootstrap component theming (tables, buttons, dropdowns, forms) ------ */
.table { color: var(--text); }
.table > :not(caption) > * > * {
    background-color: transparent;
    color: var(--text);
    border-bottom-color: var(--border);
}
.table-hover > tbody > tr:hover > * {
    background-color: var(--surface-2);
    color: var(--text);
}
.table thead th {
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .04em;
    border-bottom-color: var(--border);
    font-weight: 700;
}

.dropdown-menu {
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
}
.dropdown-item { color: var(--text); }
.dropdown-item:hover, .dropdown-item:focus { background: var(--surface-2); color: var(--text); }
.dropdown-divider { border-color: var(--border); }

.form-control, .form-select {
    background-color: var(--surface);
    border-color: var(--border);
    color: var(--text);
}
.form-control:focus, .form-select:focus {
    background-color: var(--surface);
    color: var(--text);
    border-color: var(--brand-light);
    box-shadow: 0 0 0 .2rem rgba(45, 82, 133, .18);
}
.form-control::placeholder { color: var(--text-muted); }
.form-label { color: var(--text); }

.card {
    background-color: var(--surface);
    color: var(--text);
    border-color: var(--border);
}

.modal-content {
    background-color: var(--surface);
    color: var(--text);
    border-color: var(--border);
}
.modal-header, .modal-footer { border-color: var(--border); }
.btn-close[data-theme] { filter: none; }
[data-theme="dark"] .btn-close { filter: invert(1) grayscale(100%) brightness(200%); }

.alert-light { background-color: var(--surface-2); color: var(--text); border-color: var(--border); }

.btn-outline-secondary { color: var(--text-muted); border-color: var(--border); }
.btn-outline-secondary:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-outline-primary { color: var(--brand-light); border-color: var(--brand-light); }
[data-theme="dark"] .btn-outline-primary:hover { color: #fff; }

[data-theme="dark"] .text-dark { color: var(--text) !important; }
[data-theme="dark"] .bg-light { background-color: var(--surface-2) !important; }

/* ---- Pagination / disabled links ------------------------------------------ */
.disabled { pointer-events: none; opacity: .5; }

/* ==========================================================================
   Big digital clock
   ========================================================================== */
.digital-clock-card {
    position: relative;
    overflow: hidden;
    background: radial-gradient(120% 160% at 15% 100%, #ff8a3d 0%, rgba(255,138,61,0) 42%),
                radial-gradient(110% 140% at 100% 0%, #2fb8ff 0%, rgba(47,184,255,0) 45%),
                linear-gradient(135deg, #1a2036 0%, #12162a 100%);
    border-radius: 20px;
    box-shadow: var(--shadow-md);
    padding: 22px 26px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 14px;
    isolation: isolate;
}
.digital-clock-card::before {
    /* frosted panel so the color blobs stay soft/behind the digits */
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(15, 19, 36, .38);
    backdrop-filter: blur(2px);
    z-index: 0;
}
.digital-clock-card > * { position: relative; z-index: 1; }

.clock-segments {
    display: flex;
    align-items: center;
    gap: 6px;
}
.clock-box {
    background: rgba(255,255,255,.06);
    border: 1px solid rgba(255,255,255,.09);
    border-radius: 12px;
    min-width: 64px;
    padding: 12px 10px;
    text-align: center;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.06), 0 6px 14px rgba(0,0,0,.25);
}
.clock-box .clock-digit {
    font-family: 'Courier New', Consolas, monospace;
    font-size: 42px;
    font-weight: 800;
    line-height: 1;
    color: #fff;
    letter-spacing: 1px;
    font-variant-numeric: tabular-nums;
}
.clock-box.clock-seconds .clock-digit { color: var(--accent); }
.clock-colon {
    font-size: 34px;
    font-weight: 800;
    color: rgba(255,255,255,.55);
    padding-bottom: 6px;
}
.clock-ampm {
    margin-left: 6px;
    background: rgba(47,140,255,.22);
    border: 1px solid rgba(96,168,255,.4);
    color: #a9cbff;
    font-weight: 700;
    font-size: 15px;
    letter-spacing: .04em;
    border-radius: 10px;
    padding: 10px 14px;
}

.clock-meta {
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: #cfd7e6;
}
.clock-meta .clock-greeting {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #9fb0cc;
}
.clock-meta .clock-name {
    font-size: 16px;
    font-weight: 700;
    color: #fff;
}
.clock-date-mobile { display: none; }
.clock-greeting-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    font-size: 13px;
}
.clock-greeting-row {
    display: flex;
    align-items: center;
    gap: 6px;
}
.clock-icon-morning {
    color: #ffb26b;
    background: rgba(255, 178, 107, .16);
    animation: clockIconRise 2.4s ease-in-out infinite;
}
.clock-icon-noon,
.clock-icon-afternoon {
    color: #ffd25c;
    background: rgba(255, 210, 92, .16);
    animation: clockIconPulse 1.8s ease-in-out infinite;
}
.clock-icon-evening {
    color: #a9c2ff;
    background: rgba(169, 194, 255, .16);
    animation: clockIconTwinkle 2.6s ease-in-out infinite;
}
@keyframes clockIconRise {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}
@keyframes clockIconPulse {
    0%, 100% { transform: scale(1); filter: brightness(1); }
    50% { transform: scale(1.12); filter: brightness(1.25); }
}
@keyframes clockIconTwinkle {
    0%, 100% { opacity: 1; }
    50% { opacity: .55; }
}
@media (prefers-reduced-motion: reduce) {
    .clock-greeting-icon { animation: none !important; }
}

/* ==========================================================================
   Month calendar
   ========================================================================== */
.mini-calendar-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 6px;
    table-layout: fixed;
}
.mini-calendar-table th {
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: .05em;
    padding: 6px 4px;
    text-align: center;
    font-weight: 700;
}
.mini-calendar-table td {
    vertical-align: top;
    border: 1px solid var(--border);
    border-radius: 10px;
    height: 92px;
    padding: 8px;
    width: 14.28%;
    background: var(--surface-2);
    transition: background-color .2s ease, border-color .2s ease;
    overflow: hidden;
}
.mini-calendar-table td.cal-empty {
    background: transparent;
    border-color: transparent;
}
.mini-calendar-table td.cal-today {
    background: var(--surface);
    border: 2px solid var(--accent);
}
.cal-day-num {
    font-size: 12.5px;
    font-weight: 700;
    color: var(--text);
}
.cal-today .cal-day-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    color: #16202f;
}
.cal-punch {
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.cal-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10.5px;
    font-weight: 600;
    border-radius: 6px;
    padding: 2px 6px;
    line-height: 1.5;
    width: fit-content;
    max-width: 100%;
    box-sizing: border-box;
}
.cal-in {
    background: var(--success-bg);
    color: var(--success-text);
    border: 1px solid var(--success-border);
}
.cal-out {
    background: var(--info-bg);
    color: var(--info-text);
    border: 1px solid var(--info-border);
}
.cal-ot {
    background: var(--warning-bg);
    color: var(--warning-text);
    border: 1px solid var(--warning-bg);
}
.cal-leave {
    background: var(--danger-bg);
    color: var(--danger-text);
    border: 1px solid var(--danger-bg);
}

/* ==========================================================================
   Check-in / Check-out chips (tables)
   ========================================================================== */
.badge-checkin, .badge-checkout {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-weight: 600;
    font-size: 12px;
    padding: 5px 10px;
    border-radius: 999px;
    border: 1px solid transparent;
    white-space: nowrap;
    line-height: 1.3;
}
.table td.col-status { white-space: nowrap; }
.badge-checkin {
    background: var(--success-bg);
    color: var(--success-text);
    border-color: var(--success-border);
}
.badge-checkout {
    background: var(--info-bg);
    color: var(--info-text);
    border-color: var(--info-border);
}

.badge-pending { background: var(--warning-bg); color: var(--warning-text); }
.badge-approved { background: var(--success-bg); color: var(--success-text); }
.badge-rejected { background: var(--danger-bg); color: var(--danger-text); }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 991.98px) {
    .sidebar-toggle-btn { display: inline-flex; }
    .sidebar {
        position: fixed;
        top: var(--topbar-h);
        left: 0;
        height: calc(100vh - var(--topbar-h));
        max-height: none;
        transform: translateX(-100%);
        box-shadow: var(--shadow-md);
        transition: transform .22s ease;
    }
    .sidebar.show { transform: translateX(0); }
    .content-area { padding: 0 !important; }
    main.flex-grow-1 { padding: 16px !important; }
}

@media (max-width: 575.98px) {
    .topbar .d-flex.align-items-center.gap-3 { gap: .5rem !important; margin-left: auto; }
    .icon-btn { width: 32px; height: 32px; }
    .stat-card .stat-value { font-size: 22px; }
    .mini-calendar-table { border-spacing: 2px; }
    .mini-calendar-table td { height: 68px; padding: 3px 2px; }
    .cal-day-num { font-size: 10px; }
    .cal-chip {
        font-size: 8px;
        padding: 1px 2px;
        gap: 0;
        width: 100%;
        justify-content: center;
        text-align: center;
        line-height: 1.2;
        border-radius: 4px;
        white-space: normal;
        word-break: break-word;
    }
    .cal-chip i { display: none; }
    .cal-punch { gap: 2px; margin-top: 3px; }
    .table-card { padding: 12px; }

    /* Bigger, tighter-fit digital clock on phones — was legible but small;
       sized so 3 digit boxes + AM/PM badge still fit one row on a ~360px
       screen without wrapping. */
    .digital-clock-card { padding: 16px; justify-content: center; gap: 10px; }
    .clock-segments { gap: 5px; }
    .clock-box { min-width: 60px; padding: 10px 6px; }
    .clock-box .clock-digit { font-size: 32px; }
    .clock-colon { font-size: 24px; padding-bottom: 4px; }
    .clock-ampm { padding: 8px 10px; font-size: 13px; margin-left: 2px; }
    .clock-meta { width: 100%; align-items: center; text-align: center; }
    .clock-meta .clock-name { font-size: 18px; }
    .clock-date-mobile {
        display: block;
        font-size: 12px;
        color: #9fb0cc;
        margin-top: 2px;
    }

    /* Check-in/out chips: shrink so the pill fits its column instead of
       wrapping onto a second line on narrow phones. */
    .badge-checkin, .badge-checkout {
        font-size: 10.5px;
        padding: 4px 7px;
        gap: 3px;
    }
    .badge-checkin i, .badge-checkout i { font-size: 10px; }

    /* Topbar on mobile: two rows instead of one cramped/truncated row —
       (1) hamburger + full brand text, (2) short date + icons. Redefining
       --topbar-h here also updates every other rule that reads it (sidebar
       offset, dropdown "top" offset, backdrop inset) since it's a CSS
       custom property, so nothing else needs to change to stay lined up
       with the taller mobile header. */
    :root { --topbar-h: 92px; }
    .topbar {
        flex-wrap: wrap;
        align-content: center;
        row-gap: 6px;
        padding: 8px 10px !important;
    }
    .topbar .navbar-brand {
        white-space: normal;
        overflow: visible;
        max-width: none;
        font-size: .88rem;
    }
    /* On mobile the brand is allowed to wrap onto its own row instead of
       ellipsis-truncating, so the left group doesn't need the clipped
       min-width:0 treatment here. */
    .topbar .gap-2:has(.navbar-brand) {
        overflow: visible;
    }
    .topbar-date-short { display: none; }
    /* Profile button collapses to just the person icon on mobile — full
       name/ID/role are already shown inside the dropdown once tapped, and
       in the "Good Morning" card right below it. */
    .topbar .user-menu-btn {
        padding: 0;
        width: 32px;
        height: 32px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: 10px;
    }
    .topbar .user-menu-btn .user-menu-label,
    .topbar .user-menu-btn .badge,
    .topbar .user-menu-btn.dropdown-toggle::after { display: none; }
}