:root {
    --sidebar-width: 250px;
}

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 0.9375rem;
}

.app-shell {
    min-height: calc(100vh - 57px);
}

.sidebar-col {
    width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem 0.75rem;
    margin-bottom: 0.15rem;
    border-radius: 0.5rem;
    color: var(--bs-body-color);
    text-decoration: none;
    font-size: 0.9rem;
    transition: background-color 0.15s ease;
}

.sidebar-link:hover {
    background-color: var(--bs-tertiary-bg);
    color: var(--bs-body-color);
}

.sidebar-link.active {
    background-color: var(--bs-primary-bg-subtle);
    color: var(--bs-primary-text-emphasis);
    font-weight: 600;
}

.sidebar-link i {
    width: 1.15rem;
    text-align: center;
    font-size: 1rem;
}

.sidebar-title {
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--bs-secondary-color);
    padding: 0 0.75rem;
    margin: 1rem 0 0.4rem;
}

.stat-card {
    border: 1px solid var(--bs-border-color);
    border-radius: 0.85rem;
    background: var(--bs-body-bg);
    padding: 1rem 1.1rem;
    height: 100%;
}

.stat-card .stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1.1;
}

.stat-icon {
    width: 2.6rem;
    height: 2.6rem;
    border-radius: 0.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
}

.card {
    border-radius: 0.85rem;
}

.table > :not(caption) > * > * {
    padding: 0.65rem 0.75rem;
}

.camera-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 3 / 4;
    background: #000;
    border-radius: 0.9rem;
    overflow: hidden;
}

@media (min-width: 768px) {
    .camera-wrap {
        aspect-ratio: 4 / 3;
    }
}

.camera-wrap video,
.camera-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.camera-overlay {
    position: absolute;
    inset: 0;
    border: 2px dashed rgba(255, 255, 255, 0.35);
    border-radius: 0.9rem;
    pointer-events: none;
}

.map {
    height: 320px;
    border-radius: 0.6rem;
    overflow: hidden;
    z-index: 1;
    /* Jangan biarkan gestur peta "bocor" ke scroll halaman. */
    overscroll-behavior: contain;
}

.map-sm {
    height: 220px;
}

.map-lg {
    height: 400px;
}

/* ---------------------------------------------------------------------
   Peta responsif: layar kecil butuh area lebih tinggi agar pin, radius,
   dan tombol "Posisi saya" tidak berdesakan.
   --------------------------------------------------------------------- */
@media (max-width: 575.98px) {
    .map {
        height: 260px;
    }

    .map-sm {
        height: 260px;
    }

    .map-lg {
        height: 300px;
    }
}

@media (min-width: 576px) and (max-width: 991.98px) {
    .map {
        height: 340px;
    }

    .map-sm {
        height: 300px;
    }

    .map-lg {
        height: 380px;
    }
}

/* Target sentuh minimal 44px pada perangkat pointer kasar (HP/tablet).
   Selector dibuat lebih spesifik daripada aturan bawaan leaflet.css. */
.leaflet-container.map-touch .leaflet-control-zoom-in,
.leaflet-container.map-touch .leaflet-control-zoom-out {
    width: 44px;
    height: 44px;
    line-height: 44px;
    font-size: 1.5rem;
}

.leaflet-container.map-touch.leaflet-touch .leaflet-bar a {
    width: 44px;
    height: 44px;
    line-height: 44px;
    font-size: 1.35rem;
}

.leaflet-container.map-touch .leaflet-control-attribution {
    font-size: 0.62rem;
    padding: 0 4px;
}

.leaflet-container.map-touch .absensi-pin svg {
    /* Perbesar pin tanpa menggeser ujungnya (transform-origin di bawah). */
    transform: scale(1.2);
    transform-origin: 50% 100%;
}

/* Marker SVG (pengganti marker-icon.png bawaan Leaflet) */
.absensi-pin {
    background: none;
    border: 0;
}

.absensi-pin svg {
    display: block;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35));
}

.absensi-dot-icon {
    background: none;
    border: 0;
}

.absensi-dot {
    display: block;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #0d6efd;
    border: 3px solid #fff;
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.35), 0 0 0 10px rgba(13, 110, 253, 0.12);
}

/* Mode gelap: gelapkan tile saja, marker & lingkaran tetap normal */
.map-dark.leaflet-container {
    background: #1b1f24;
}

.map-dark .leaflet-tile-pane {
    filter: grayscale(1) invert(1) brightness(0.9) contrast(1.05);
}

/* Notice saat tile peta gagal dimuat (offline / jaringan lambat) */
.map-notice {
    position: absolute;
    left: 50%;
    top: 8px;
    transform: translateX(-50%);
    z-index: 800;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    max-width: calc(100% - 16px);
    padding: 0.25rem 0.35rem 0.25rem 0.6rem;
    border-radius: 0.4rem;
    background: rgba(33, 37, 41, 0.92);
    color: #fff;
    font-size: 0.72rem;
    line-height: 1.35;
    white-space: nowrap;
    pointer-events: none;
}

.map-notice > span {
    overflow: hidden;
    text-overflow: ellipsis;
}

.map-notice-retry {
    pointer-events: auto;
    --bs-btn-padding-y: 0.1rem;
    --bs-btn-padding-x: 0.5rem;
    --bs-btn-font-size: 0.75rem;
}

[data-bs-theme="dark"] .leaflet-bar a {
    background: var(--bs-body-bg);
    color: var(--bs-body-color);
    border-bottom-color: var(--bs-border-color);
}

[data-bs-theme="dark"] .leaflet-bar a:hover {
    background: var(--bs-secondary-bg);
}

[data-bs-theme="dark"] .leaflet-container .leaflet-control-attribution {
    background: rgba(33, 37, 41, 0.85);
    color: var(--bs-body-color);
}

[data-bs-theme="dark"] .leaflet-container .leaflet-control-attribution a {
    color: var(--bs-link-color);
}

[data-bs-theme="dark"] .leaflet-popup-content-wrapper,
[data-bs-theme="dark"] .leaflet-popup-tip {
    background: var(--bs-body-bg);
    color: var(--bs-body-color);
    box-shadow: 0 3px 14px rgba(0, 0, 0, 0.5);
}

.bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    height: 150px;
}

.bar-chart .bar-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    height: 100%;
    text-align: center;
}

.bar-chart .bar-stack {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    height: 110px;
}

.bar-chart .bar {
    width: 100%;
    border-radius: 3px 3px 0 0;
}

.avatar-circle {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--bs-primary-bg-subtle);
    color: var(--bs-primary-text-emphasis);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.8rem;
}

.auth-page {
    background: linear-gradient(135deg, #eef2ff 0%, #f8fafc 55%, #e0f2fe 100%);
}

/* ---------------------------------------------------------------------
   Tema terang/gelap
   --------------------------------------------------------------------- */

/* Header tabel & alert yang tetap nyaman di kedua tema. */
.table-light {
    --bs-table-bg: var(--bs-tertiary-bg);
    --bs-table-color: var(--bs-body-color);
    --bs-table-border-color: var(--bs-border-color);
    --bs-table-striped-bg: var(--bs-secondary-bg);
    --bs-table-hover-bg: var(--bs-secondary-bg);
}

.alert-light {
    --bs-alert-color: var(--bs-body-color);
    --bs-alert-bg: var(--bs-tertiary-bg);
    --bs-alert-border-color: var(--bs-border-color);
}

[data-bs-theme="dark"] .btn-light {
    --bs-btn-color: var(--bs-body-color);
    --bs-btn-bg: var(--bs-secondary-bg);
    --bs-btn-border-color: var(--bs-border-color);
    --bs-btn-hover-color: var(--bs-emphasis-color);
    --bs-btn-hover-bg: var(--bs-tertiary-bg);
    --bs-btn-hover-border-color: var(--bs-border-color);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--bs-primary);
    --bs-btn-active-border-color: var(--bs-primary);
    --bs-btn-disabled-color: var(--bs-secondary-color);
    --bs-btn-disabled-bg: var(--bs-secondary-bg);
    --bs-btn-disabled-border-color: var(--bs-border-color);
}

[data-bs-theme="dark"] .auth-page {
    background: linear-gradient(135deg, #0b1220 0%, #111827 55%, #0f172a 100%);
}

/* Matriks jadwal kerja (admin). */
.matrix-table {
    font-size: 0.8rem;
}

.matrix-table > :not(caption) > * > * {
    padding: 0.4rem 0.3rem;
}

.matrix-sticky {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--bs-body-bg);
}

thead .matrix-sticky {
    z-index: 3;
    background: var(--bs-tertiary-bg);
}

.matrix-off {
    background: var(--bs-tertiary-bg);
}

.matrix-cell {
    min-height: 1.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.35rem;
    color: inherit;
}

.matrix-cell:hover {
    outline: 2px solid var(--bs-primary-border-subtle);
}

.matrix-empty {
    color: var(--bs-secondary-color);
    opacity: 0.45;
}

.matrix-cell:hover .matrix-empty {
    opacity: 1;
}

/* Drag & drop shift pada matriks roster. */
.roster-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
}

.shift-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.65rem;
    border-radius: 999px;
    border: 1px solid var(--bs-border-color);
    background: var(--bs-body-bg);
    color: var(--bs-body-color);
    font-size: 0.78rem;
    font-weight: 500;
    cursor: grab;
    user-select: none;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.shift-chip:hover {
    box-shadow: 0 0 0 3px var(--bs-primary-border-subtle);
}

.shift-chip:active {
    cursor: grabbing;
    transform: scale(0.97);
}

.shift-chip .dot {
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 50%;
    background: currentColor;
}

.shift-chip.chip-libur {
    color: var(--bs-secondary-color);
    border-style: dashed;
}

.shift-chip.chip-kosong {
    color: var(--bs-danger);
}

.matrix-cell.drag-target {
    outline: 2px dashed var(--bs-primary);
    background: var(--bs-primary-bg-subtle);
}

.matrix-cell.drop-ok {
    outline: 2px solid var(--bs-success);
}

.matrix-cell.menyimpan {
    opacity: 0.5;
    pointer-events: none;
}

.matrix-cell[data-drop="1"] {
    cursor: pointer;
}

/* Kalender jadwal pegawai. */
.calendar-table > :not(caption) > * > * {
    padding: 0.45rem;
}

.calendar-cell {
    height: 92px;
}

.calendar-out {
    background: var(--bs-tertiary-bg);
    opacity: 0.55;
}

.calendar-today {
    box-shadow: inset 0 0 0 2px var(--bs-primary);
}

@media (max-width: 575.98px) {
    .stat-card .stat-value {
        font-size: 1.35rem;
    }

    .calendar-cell {
        height: 74px;
    }
}
