:root {
    --sw-teal: #0f766e;
    --sw-teal-dark: #115e59;
    --sw-ink: #172033;
    --sw-muted: #64748b;
    --sw-line: #d8dee9;
    --sw-bg: #f5f7fb;
    --sw-amber: #f59e0b;
    --sw-red: #dc2626;
}

* {
    letter-spacing: 0;
}

body {
    margin: 0;
    color: var(--sw-ink);
    background: var(--sw-bg);
    font-family: Arial, Helvetica, sans-serif;
    -webkit-text-size-adjust: 100%;
}

.app-topbar {
    background: #ffffff;
    border-bottom: 1px solid var(--sw-line);
    z-index: 1030;
}

.app-topbar .container-fluid {
    min-height: 64px;
    gap: 8px;
}

.navbar-brand {
    color: var(--sw-ink);
    display: inline-flex;
    align-items: center;
    min-width: 0;
    white-space: nowrap;
}

.brand-mark {
    display: inline-flex;
    width: 34px;
    height: 34px;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
    color: #ffffff;
    background: var(--sw-teal);
    border-radius: 8px;
    font-size: 13px;
}

.btn-icon {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--sw-line);
    border-radius: 8px;
    background: #ffffff;
}

.logout-form {
    margin: 0;
}

.user-role-pill {
    color: var(--sw-muted);
    font-size: 13px;
    font-weight: 700;
}

.mobile-nav-bar {
    position: sticky;
    top: 65px;
    z-index: 1020;
    background: #ffffff;
    border-bottom: 1px solid var(--sw-line);
    padding: 8px 12px 10px;
}

.mobile-user-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    color: var(--sw-muted);
    font-size: 12px;
    padding: 0 2px 8px;
}

.mobile-nav-scroll {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
}

.mobile-nav-scroll .nav-link {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 40px;
    padding: 9px 12px;
    border: 1px solid var(--sw-line);
    border-radius: 8px;
    color: #334155;
    background: #ffffff;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
}

.mobile-nav-scroll .nav-link.active {
    color: #ffffff;
    background: var(--sw-teal);
    border-color: var(--sw-teal);
}

.mobile-nav-scroll .nav-link i {
    color: currentColor;
}

.app-shell {
    display: grid;
    grid-template-columns: 264px minmax(0, 1fr);
    min-height: calc(100vh - 57px);
}

.app-sidebar {
    background: #ffffff;
    border-right: 1px solid var(--sw-line);
    padding: 18px 14px;
}

.sidebar-label {
    color: var(--sw-muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    margin: 8px 10px 14px;
}

.app-nav {
    display: grid;
    gap: 6px;
}

.app-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #334155;
    border-radius: 8px;
    padding: 11px 12px;
    font-weight: 600;
}

.app-nav .nav-link i {
    width: 20px;
    color: var(--sw-muted);
}

.app-nav .nav-link.active,
.app-nav .nav-link:hover {
    background: #e7f5f2;
    color: var(--sw-teal-dark);
}

.sidebar-note {
    margin-top: 24px;
    padding: 14px;
    border: 1px solid #bae6dd;
    border-radius: 8px;
    background: #f0fdfa;
    font-size: 13px;
}

.sidebar-note span {
    display: block;
    margin-top: 6px;
    color: var(--sw-muted);
}

.app-main {
    padding: 24px;
    min-width: 0;
}

.page-title {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
}

.page-title h1 {
    margin: 0;
    font-size: 26px;
    font-weight: 800;
}

.page-title p {
    margin: 4px 0 0;
    color: var(--sw-muted);
}

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

.stat-card,
.panel,
.record-card {
    background: #ffffff;
    border: 1px solid var(--sw-line);
    border-radius: 8px;
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.04);
}

.stat-card {
    padding: 16px;
}

.stat-card .label {
    color: var(--sw-muted);
    font-size: 13px;
    font-weight: 700;
}

.stat-card .value {
    font-size: 30px;
    font-weight: 800;
    margin-top: 8px;
}

.panel {
    padding: 18px;
}

.panel-title {
    font-size: 16px;
    font-weight: 800;
    margin-bottom: 14px;
}

.table thead th {
    color: #475569;
    background: #f8fafc;
    font-size: 12px;
    text-transform: uppercase;
}

/* Leaflet critical fallback: keeps map tiles aligned if leaflet.css is cached late or not loaded. */
.leaflet-container {
    position: relative;
    overflow: hidden;
    background: #dddddd;
    outline-offset: 1px;
    -webkit-tap-highlight-color: transparent;
}

.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
    position: absolute;
    left: 0;
    top: 0;
}

.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow {
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
}

.leaflet-marker-icon,
.leaflet-marker-shadow {
    display: block;
}

.leaflet-container .leaflet-overlay-pane svg {
    max-width: none !important;
    max-height: none !important;
}

.leaflet-container .leaflet-marker-pane img,
.leaflet-container .leaflet-shadow-pane img,
.leaflet-container .leaflet-tile-pane img,
.leaflet-container img.leaflet-image-layer,
.leaflet-container .leaflet-tile {
    max-width: none !important;
    max-height: none !important;
    width: auto;
    padding: 0;
}

.leaflet-tile {
    filter: inherit;
    visibility: hidden;
}

.leaflet-tile-loaded {
    visibility: inherit;
}

.leaflet-pane {
    z-index: 400;
}

.leaflet-tile-pane {
    z-index: 200;
}

.leaflet-overlay-pane {
    z-index: 400;
}

.leaflet-shadow-pane {
    z-index: 500;
}

.leaflet-marker-pane {
    z-index: 600;
}

.leaflet-tooltip-pane {
    z-index: 650;
}

.leaflet-popup-pane {
    z-index: 700;
}

.leaflet-map-pane canvas {
    z-index: 100;
}

.leaflet-map-pane svg {
    z-index: 200;
}

.leaflet-control {
    position: relative;
    z-index: 800;
    pointer-events: auto;
}

.leaflet-top,
.leaflet-bottom {
    position: absolute;
    z-index: 1000;
    pointer-events: none;
}

.leaflet-top {
    top: 0;
}

.leaflet-right {
    right: 0;
}

.leaflet-bottom {
    bottom: 0;
}

.leaflet-left {
    left: 0;
}

.leaflet-control {
    float: left;
    clear: both;
}

.leaflet-right .leaflet-control {
    float: right;
}

.leaflet-top .leaflet-control {
    margin-top: 10px;
}

.leaflet-bottom .leaflet-control {
    margin-bottom: 10px;
}

.leaflet-left .leaflet-control {
    margin-left: 10px;
}

.leaflet-right .leaflet-control {
    margin-right: 10px;
}

.leaflet-zoom-animated {
    transform-origin: 0 0;
}

.leaflet-interactive {
    cursor: pointer;
}

.leaflet-grab {
    cursor: grab;
}

.leaflet-dragging .leaflet-grab,
.leaflet-dragging .leaflet-marker-draggable {
    cursor: move;
}

.leaflet-touch .leaflet-control {
    box-shadow: none;
}

.leaflet-bar {
    border-radius: 4px;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.65);
}

.leaflet-bar a {
    width: 26px;
    height: 26px;
    line-height: 26px;
    display: block;
    background: #ffffff;
    color: #000000;
    text-align: center;
    text-decoration: none;
    border-bottom: 1px solid #cccccc;
}

.leaflet-bar a:hover,
.leaflet-bar a:focus {
    background: #f4f4f4;
}

.leaflet-bar a:first-child {
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
}

.leaflet-bar a:last-child {
    border-bottom: 0;
    border-bottom-left-radius: 4px;
    border-bottom-right-radius: 4px;
}

.leaflet-control-attribution {
    background: rgba(255, 255, 255, 0.8);
    margin: 0;
    padding: 0 5px;
    color: #333333;
    font-size: 11px;
}

.leaflet-popup {
    position: absolute;
    text-align: center;
    margin-bottom: 20px;
}

.leaflet-popup-content-wrapper {
    padding: 1px;
    text-align: left;
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 3px 14px rgba(0, 0, 0, 0.4);
}

.leaflet-popup-content {
    margin: 13px 19px;
    line-height: 1.3;
    font-size: 13px;
    min-height: 1px;
}

.leaflet-popup-tip-container {
    width: 40px;
    height: 20px;
    position: absolute;
    left: 50%;
    margin-left: -20px;
    overflow: hidden;
    pointer-events: none;
}

.leaflet-popup-tip {
    width: 17px;
    height: 17px;
    padding: 1px;
    margin: -10px auto 0;
    transform: rotate(45deg);
    background: #ffffff;
    box-shadow: 0 3px 14px rgba(0, 0, 0, 0.4);
}

.leaflet-container a.leaflet-popup-close-button {
    position: absolute;
    top: 0;
    right: 0;
    border: 0;
    text-align: center;
    width: 24px;
    height: 24px;
    font: 16px/24px Tahoma, Verdana, sans-serif;
    color: #757575;
    text-decoration: none;
    background: transparent;
}

.map-box {
    min-height: 360px;
    width: 100%;
    border: 1px solid var(--sw-line);
    border-radius: 8px;
    overflow: hidden;
    background: #f8fafc;
}

.map-sm {
    height: 260px;
}

.map-box.is-map-error {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
}

.map-empty {
    max-width: 360px;
    color: var(--sw-muted);
    text-align: center;
    font-size: 14px;
    line-height: 1.45;
}

.selfie-preview,
.attendance-photo {
    width: 76px;
    height: 76px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--sw-line);
}

.camera-frame {
    background: #111827;
    border-radius: 8px;
    overflow: hidden;
    min-height: 260px;
}

.camera-frame video,
.camera-frame canvas {
    width: 100%;
    max-height: 420px;
    object-fit: cover;
    display: block;
}

.filter-chip {
    border: 1px solid var(--sw-line);
    border-radius: 8px;
    padding: 10px 12px;
    cursor: pointer;
}

.filter-chip input {
    margin-right: 8px;
}

.checkout-note-form .btn {
    margin-top: 8px;
}

.login-page {
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 24px;
    overflow-y: auto;
    background: linear-gradient(135deg, #0f766e 0%, #172033 50%, #f59e0b 100%);
}

.login-card {
    width: min(980px, 100%);
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: #ffffff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 28px 70px rgba(0, 0, 0, 0.25);
}

.login-info {
    padding: 38px;
    background: #f8fafc;
}

.login-info h1 {
    font-size: 34px;
    font-weight: 800;
    margin-bottom: 12px;
}

.login-info p {
    color: var(--sw-muted);
}

.login-form {
    padding: 38px;
}

.login-form input,
.login-form button,
.login-form select,
.login-form textarea {
    scroll-margin-top: 96px;
    scroll-margin-bottom: 45vh;
}

.login-info .panel {
    box-shadow: none;
}

.photo-success-modal {
    border: 1px solid var(--sw-line);
    border-radius: 8px;
}

.photo-success-icon {
    width: 54px;
    height: 54px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    background: #16a34a;
    border-radius: 50%;
    font-size: 22px;
}

.safework-toast-container {
    z-index: 2000;
}

form.is-submitting button[type="submit"] {
    pointer-events: none;
}

.badge-dot {
    width: 10px;
    height: 10px;
    display: inline-block;
    border-radius: 50%;
    margin-right: 6px;
}

.dot-valid {
    background: #16a34a;
}

.dot-late {
    background: var(--sw-amber);
}

.dot-invalid {
    background: var(--sw-red);
}

@media (max-width: 991.98px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .app-main {
        padding: 16px;
    }

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

@media (max-width: 640px) {
    .login-page {
        display: block;
        padding: 14px 10px calc(18px + env(safe-area-inset-bottom));
    }

    .login-page.keyboard-open {
        padding-bottom: 48vh;
    }

    .stat-grid,
    .login-card {
        grid-template-columns: 1fr;
    }

    .login-info,
    .login-form {
        padding: 20px;
    }

    .login-info h1 {
        font-size: 28px;
    }

    .page-title h1 {
        font-size: 22px;
    }

    .app-topbar .container-fluid {
        min-height: 62px;
    }

    .navbar-brand {
        font-size: 20px;
        max-width: calc(100vw - 150px);
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .brand-mark {
        width: 38px;
        height: 38px;
        flex: 0 0 38px;
    }

    .app-main {
        padding: 14px 12px;
    }

    .page-title {
        align-items: flex-start;
    }

    .page-title .btn,
    .page-title a.btn {
        width: 100%;
    }
}
