/*
 * CabRoyal admin panel (Section J).
 *
 * A dark sidebar on #0B0B0D with #C9A227 as the accent, per Constitution 7.
 * Loads after cabroyal.css and only adds what the panel needs on top of the
 * shared identity.
 */

.cr-admin { background: #0a0a0c; }

.cr-admin-shell {
    display: flex;
    min-height: 100vh;
}

/* --- sidebar ------------------------------------------------------------- */

.cr-sidebar {
    width: 268px;
    flex-shrink: 0;
    background: var(--cr-black);
    border-right: 1px solid var(--cr-line-soft);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 1040;
}

.cr-sidebar-head {
    padding: 1.25rem 1.15rem;
    border-bottom: 1px solid var(--cr-line-soft);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.cr-sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0.75rem;
    scrollbar-width: thin;
    scrollbar-color: var(--cr-line) transparent;
}

.cr-sidebar-nav::-webkit-scrollbar { width: 6px; }
.cr-sidebar-nav::-webkit-scrollbar-thumb { background: var(--cr-line); border-radius: 3px; }

.cr-sidebar-heading {
    font-size: 0.68rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: rgba(245, 241, 232, 0.35);
    padding: 1rem 0.75rem 0.5rem;
}

.cr-nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.75rem;
    border-radius: var(--cr-radius-sm);
    color: var(--cr-muted);
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 500;
    position: relative;
    transition: background 0.15s ease, color 0.15s ease;
}

.cr-nav-link i:first-child { font-size: 1.05rem; width: 1.25rem; }

.cr-nav-link:hover:not(.disabled) {
    background: rgba(245, 241, 232, 0.04);
    color: var(--cr-ivory);
}

/* The gold bar is how you know where you are. */
.cr-nav-link.active {
    background: var(--cr-gold-soft);
    color: var(--cr-gold);
}

.cr-nav-link.active::before {
    content: '';
    position: absolute;
    left: -0.75rem;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: var(--cr-gold);
    border-radius: 0 3px 3px 0;
}

.cr-nav-link.disabled {
    opacity: 0.38;
    cursor: not-allowed;
}

.cr-sidebar-foot {
    padding: 0.75rem;
    border-top: 1px solid var(--cr-line-soft);
}

/* --- main ---------------------------------------------------------------- */

.cr-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.cr-topbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1.5rem;
    background: rgba(11, 11, 13, 0.9);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--cr-line-soft);
    position: sticky;
    top: 0;
    z-index: 1030;
}

.cr-content {
    padding: 1.75rem 1.5rem 3rem;
    flex: 1;
}

.cr-search {
    position: relative;
    max-width: 22rem;
    flex: 1;
}

.cr-search i {
    position: absolute;
    left: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--cr-muted);
    pointer-events: none;
}

.cr-search .form-control {
    padding-left: 2.4rem;
    background: var(--cr-surface-2);
}

.cr-icon-btn {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: var(--cr-radius-sm);
    background: var(--cr-surface-2);
    border: 1px solid var(--cr-line-soft);
    color: var(--cr-ivory);
}

.cr-icon-btn:hover { color: var(--cr-gold); border-color: var(--cr-line); }

.cr-badge-dot {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--cr-red);
    color: #fff;
    font-size: 0.66rem;
    font-weight: 600;
    display: grid;
    place-items: center;
}

.cr-user-btn {
    background: var(--cr-surface-2);
    border: 1px solid var(--cr-line-soft);
    border-radius: var(--cr-radius-sm);
    color: var(--cr-ivory);
    padding: 0.35rem 0.6rem;
}

.cr-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--cr-gold);
    color: var(--cr-black);
    font-weight: 600;
}

.cr-dropdown {
    background: var(--cr-surface);
    border: 1px solid var(--cr-line-soft);
    border-radius: var(--cr-radius);
    box-shadow: 0 18px 44px rgba(0, 0, 0, 0.5);
}

.cr-dropdown .dropdown-item { color: var(--cr-muted); border-radius: var(--cr-radius-sm); }
.cr-dropdown .dropdown-item:hover { background: rgba(245, 241, 232, 0.05); color: var(--cr-ivory); }

.cr-input-icon {
    background: var(--cr-surface-2);
    border: 1px solid var(--cr-line-soft);
    color: var(--cr-muted);
}

/* --- stat cards ---------------------------------------------------------- */

.cr-stat-card {
    padding: 1.35rem;
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    height: 100%;
}

.cr-stat-card .cr-icon { margin-bottom: 0; flex-shrink: 0; }
.cr-stat-card .value { font-family: 'Playfair Display', Georgia, serif; font-size: 1.9rem; line-height: 1.1; }
.cr-stat-card .label { color: var(--cr-muted); font-size: 0.85rem; }

/* --- tables -------------------------------------------------------------- */

.table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--cr-ivory);
    --bs-table-border-color: var(--cr-line-soft);
    --bs-table-hover-bg: rgba(245, 241, 232, 0.03);
    --bs-table-hover-color: var(--cr-ivory);
}

.table > thead th {
    color: var(--cr-muted);
    font-size: 0.78rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    font-weight: 600;
    border-bottom-color: var(--cr-line);
}

div.dt-container .dt-paging .page-link {
    background: var(--cr-surface-2);
    border-color: var(--cr-line-soft);
    color: var(--cr-muted);
}

div.dt-container .dt-paging .active > .page-link {
    background: var(--cr-gold);
    border-color: var(--cr-gold);
    color: var(--cr-black);
}

div.dt-container .dt-search input,
div.dt-container .dt-length select {
    background: var(--cr-surface-2);
    border: 1px solid var(--cr-line-soft);
    color: var(--cr-ivory);
    border-radius: var(--cr-radius-sm);
}

div.dt-container .dt-info { color: var(--cr-muted); font-size: 0.86rem; }

/* --- leaflet, darkened to match ----------------------------------------- */

.cr-map {
    height: 420px;
    border-radius: var(--cr-radius);
    overflow: hidden;
    border: 1px solid var(--cr-line-soft);
}

/* OSM tiles are bright; this settles them into the panel without needing a
   paid dark tile provider (Constitution 1). */
.cr-map .leaflet-tile-pane {
    filter: invert(1) hue-rotate(180deg) brightness(0.86) contrast(0.92) saturate(0.5);
}

.cr-map .leaflet-container { background: #0d0d10; }

/* --- modals -------------------------------------------------------------- */

.modal-content {
    background: var(--cr-surface);
    border: 1px solid var(--cr-line-soft);
    border-radius: var(--cr-radius);
}

.modal-header, .modal-footer { border-color: var(--cr-line-soft); }

/* --- select2, to match the form controls -------------------------------- */

.select2-container--bootstrap-5 .select2-selection {
    background: var(--cr-surface-2);
    border-color: var(--cr-line-soft);
    color: var(--cr-ivory);
    border-radius: var(--cr-radius-sm);
}

.select2-container--bootstrap-5 .select2-dropdown {
    background: var(--cr-surface);
    border-color: var(--cr-line-soft);
}

/* --- login --------------------------------------------------------------- */

.cr-login {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 2rem 1rem;
    background:
        radial-gradient(circle at 50% 0%, rgba(201, 162, 39, 0.10), transparent 55%),
        #0a0a0c;
}

.cr-login-shell { width: 100%; max-width: 26rem; }
.cr-login-card { padding: 2.25rem; }

/* --- responsive ---------------------------------------------------------- */

@media (max-width: 991.98px) {
    .cr-sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        transform: translateX(-100%);
        transition: transform 0.22s ease;
        box-shadow: 0 0 60px rgba(0, 0, 0, 0.6);
    }

    .cr-sidebar.open { transform: translateX(0); }

    .cr-sidebar-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.6);
        z-index: 1035;
    }

    .cr-content { padding: 1.25rem 1rem 2.5rem; }
    .cr-topbar { padding: 0.75rem 1rem; }
}

/* ==========================================================================
   Dashboard live map and charts (Prompt 6, Section J-1)
   ========================================================================== */

/* Leaflet's divIcon has its own wrapper; strip it back so only the dot shows. */
.cr-driver-marker { background: none; border: 0; }

.cr-driver-dot {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    font-size: 0.85rem;
    border: 2px solid;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
    transition: background 0.3s ease, border-color 0.3s ease;
}

/* Free is gold — the colour the whole panel uses for "good to go". */
.cr-driver-dot.free {
    background: var(--cr-gold);
    border-color: #f0d264;
    color: var(--cr-black);
}

/* Carrying someone: racing green, the secondary from Constitution 7. */
.cr-driver-dot.busy {
    background: var(--cr-green);
    border-color: rgba(201, 162, 39, 0.6);
    color: var(--cr-gold);
}

.cr-legend-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 0.4rem;
    vertical-align: middle;
}

.cr-legend-dot.free { background: var(--cr-gold); }
.cr-legend-dot.busy { background: var(--cr-green); border: 1px solid var(--cr-gold); }

/* Leaflet's popup is white by default and jarring on a dark panel. */
.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
    background: var(--cr-surface);
    color: var(--cr-ivory);
    border: 1px solid var(--cr-line);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
}

.leaflet-popup-content-wrapper { border-radius: var(--cr-radius-sm); }
.leaflet-popup-content { margin: 0.85rem 1rem; }
.leaflet-container a.leaflet-popup-close-button { color: var(--cr-muted); }

.cr-map-popup { min-width: 11rem; }

.leaflet-control-zoom a {
    background: var(--cr-surface);
    border-color: var(--cr-line-soft);
    color: var(--cr-ivory);
}

.leaflet-control-zoom a:hover { background: var(--cr-surface-2); color: var(--cr-gold); }

.leaflet-control-attribution {
    background: rgba(11, 11, 13, 0.75) !important;
    color: var(--cr-muted);
}

.leaflet-control-attribution a { color: var(--cr-gold); }

/* --- the refresh tick ---------------------------------------------------- */

#cr-refresh-spinner.spin {
    animation: cr-spin 0.8s linear infinite;
    color: var(--cr-gold);
}

@keyframes cr-spin { to { transform: rotate(360deg); } }

/* A counter that changed flashes gold, so an operator watching the screen
   sees what moved rather than having to compare numbers. */
.cr-stat-card.cr-flash {
    border-color: var(--cr-gold);
    box-shadow: 0 0 0 3px var(--cr-gold-soft);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

/* --- ride detail timeline (Section J-2) ---------------------------------- */

.cr-timeline { position: relative; padding-left: 0.25rem; }

.cr-timeline-step {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.45rem 0;
    position: relative;
}

/* The line joining the steps, drawn behind the icons. */
.cr-timeline-step:not(:last-child)::before {
    content: '';
    position: absolute;
    left: 0.52rem;
    top: 1.9rem;
    bottom: -0.35rem;
    width: 1px;
    background: var(--cr-line-soft);
}

.cr-timeline-step > i:first-child {
    width: 1.1rem;
    text-align: center;
    color: rgba(245, 241, 232, 0.28);
    background: var(--cr-surface);
    z-index: 1;
}

/* A step that actually happened. The ones that did not stay dim, so a ride
   that skipped "driver arrived" reads at a glance. */
.cr-timeline-step.done > i:first-child { color: var(--cr-gold); }

/* --- approval queue ------------------------------------------------------ */

.cr-card.border-danger { border-color: rgba(179, 38, 30, 0.5) !important; }

/* --- DataTables' "processing" overlay ------------------------------------
   Three blue dots on a light plate, straight from the library's stylesheet.
   It is the only part of a Section J list that is not ours, and it shows up
   on every filter change. */

div.dt-processing {
    background: var(--cr-surface-2);
    border: 1px solid var(--cr-line);
    border-radius: var(--cr-radius-sm);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
    color: var(--cr-muted);
}

div.dt-processing > div:last-child > div {
    background: var(--cr-gold);
}
