/* =============================================================================
   BLACKSMITH TOWING — ADMIN DASHBOARD
   Optimized for dashboard.html
============================================================================= */

/* --- 1. CSS Variables --- */
:root {
    --primary-bg: #f4f7f6;
    --panel-bg: #ffffff;
    --accent-orange: #fd7e14;
    --accent-orange-dark: #df6f12;
    --sidebar-bg: rgba(17, 24, 39, 0.92);
    --sidebar-border: rgba(255, 255, 255, 0.08);
    --text-main: #2b2b2b;
    --text-muted: #6c757d;
    --accent-blue: #0d6efd;
    --success-green: #198754;
    --danger-red: #dc3545;
    --panel-radius: 12px;
    --soft-border: rgba(0, 0, 0, 0.06);
    --soft-shadow: 0 4px 20px rgba(0, 0, 0, 0.035);
    --focus-ring: 0 0 0 0.2rem rgba(253, 126, 20, 0.25);
    --mobile-header-height: 64px;
}

/* --- 2. Resets & Base Styles --- */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    max-width: 100%;
    min-height: 100vh;
    margin: 0;
    overflow-x: hidden;
    background: var(--primary-bg);
}

body {
    color: var(--text-main);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    display: flex;
}

button,
input,
select,
textarea {
    font: inherit;
}

img,
svg {
    max-width: 100%;
}

a {
    cursor: pointer;
}

:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

/* --- 3. Header & Overlays --- */
.mobile-header,
.sidebar-overlay {
    display: none;
}

/* Override Bootstrap d-lg-none to keep mobile header hidden on tablets where sidebar is now visible */
@media (min-width: 768px) {
    .mobile-header {
        display: none !important;
    }
}

/* --- 4. Sidebar --- */
.sidebar {
    width: 260px;
    height: 100vh;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1rem;
    color: #fff;
    background: var(--sidebar-bg);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-right: 1px solid var(--sidebar-border);
    box-shadow: inset -1px 0 0 rgba(255, 255, 255, 0.05), 4px 0 15px rgba(0, 0, 0, 0.05);
    z-index: 1040;
}

.sidebar h5 {
    line-height: 1.2;
}

.sidebar-nav {
    list-style: none;
    padding: 0;
    margin: 2rem 0;
    flex-grow: 1;
}

.sidebar-nav li a {
    display: block;
    padding: 0.75rem 1rem;
    margin-bottom: 0.25rem;
    border-radius: 8px;
    color: #9ca3af;
    text-decoration: none;
    user-select: none;
    transition: background-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.sidebar-nav li a:hover,
.sidebar-nav li a.active {
    color: var(--accent-orange);
    background: rgba(255, 255, 255, 0.1);
    font-weight: 600;
}

.sidebar-nav li a:hover {
    transform: translateX(2px);
}

#btn-lock {
    border-color: rgba(255, 255, 255, 0.35);
}

#btn-lock:hover {
    color: #111827;
}

/* --- 5. Main Content Layout --- */
.main-content {
    flex-grow: 1;
    min-width: 0;
    height: 100vh;
    padding: 2rem 3rem;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--primary-bg);
}

/* --- 6. View Sections & Animations --- */
.view-section {
    display: none;
    width: 100%;
    max-width: 100%;
    animation: fadeIn 0.3s ease-in-out;
}

.view-section.active-view {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- 7. Panels & Cards --- */
.dashboard-panel {
    width: 100%;
    min-width: 0;
    height: 100%;
    padding: 1.5rem;
    background: var(--panel-bg);
    border: 1px solid var(--soft-border);
    border-radius: var(--panel-radius);
    box-shadow: var(--soft-shadow);
}

.dashboard-panel h2,
.dashboard-panel h3,
.dashboard-panel h4,
.dashboard-panel h5,
.dashboard-panel h6 {
    color: var(--text-main);
}

#dashboard-queue-container,
#fullboard-pending-list,
#fullboard-active-list,
#fullboard-cleared-list {
    min-height: 80px;
}

.dispatch-card,
.queue-card {
    padding: 1rem;
    background: #fff;
    border: 1px solid var(--soft-border);
    border-radius: 10px;
    box-shadow: var(--soft-shadow);
}

/* --- 8. KPI Icons --- */
.kpi-icon {
    width: 48px;
    height: 48px;
    min-width: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    font-size: 1.25rem;
}

.icon-orange {
    color: var(--accent-orange);
    background: rgba(253, 126, 20, 0.1);
}

.icon-green {
    color: var(--success-green);
    background: rgba(25, 135, 84, 0.1);
}

.icon-blue {
    color: var(--accent-blue);
    background: rgba(13, 110, 253, 0.1);
}

/* --- 9. D3 Chart --- */
#d3ChartContainer {
    width: 100%;
    max-width: 100%;
    min-height: 350px;
    overflow: hidden;
}

#d3ChartContainer svg {
    display: block;
    width: 100%;
    max-width: 100%;
}

.line {
    fill: none;
    stroke: var(--accent-orange);
    stroke-width: 3px;
}

.area {
    fill: url(#area-gradient);
    opacity: 0.5;
}

.axis text {
    font-size: 12px;
    fill: var(--text-muted);
}

.axis path,
.axis line {
    stroke: rgba(0, 0, 0, 0.1);
}

/* --- 10. Tables --- */
.table > :not(caption) > * > * {
    padding: 1rem 0.5rem;
    border-bottom-color: rgba(0, 0, 0, 0.05);
}

.table-responsive {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    border-radius: 10px;
    -webkit-overflow-scrolling: touch;
}

/* --- 11. Forms & Inputs --- */
.form-control,
.form-select,
.input-group-text {
    border-color: #dee2e6;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--accent-orange);
    box-shadow: var(--focus-ring);
}

.form-label {
    margin-bottom: 0.35rem;
}

.input-group .form-floating {
    min-width: 0;
    flex: 1 1 auto;
}

.input-group .form-floating > .form-control {
    width: 100%;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

.input-group .form-floating > label {
    z-index: 5;
}

/* --- 12. UI Components (Glass, Buttons, Pricing, System Tabs) --- */
.glass-panel {
    position: relative;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.68);
    border: 1px solid rgba(255, 255, 255, 0.75);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.045);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

.glass-panel::before {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    height: 4px;
    background: linear-gradient(90deg, var(--accent-orange), #ff9e43);
}

/* --- Custom System Overview Controls (Rounded Segmented Tabs) --- */
#timeControls {
    background: var(--primary-bg); /* Creates a soft track for the tabs */
    border: 1px solid var(--soft-border);
    border-radius: 50rem !important; /* Fully rounded pill container */
    padding: 4px; /* Inner spacing to separate tabs from the edge */
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.04) !important; /* Inner depth */
    display: inline-flex;
}

#timeControls .btn-outline-secondary {
    border: none !important;
    background: transparent !important;
    color: var(--text-muted) !important;
    font-weight: 700;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-radius: 50rem !important; /* Fully rounded individual tabs */
    padding: 0.5rem 1.5rem !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Hover state for inactive tabs */
#timeControls .btn-outline-secondary:hover {
    color: var(--text-main) !important;
    background: rgba(0, 0, 0, 0.03) !important; 
}

/* Active/Selected Tab State */
#timeControls .btn-check:checked + .btn-outline-secondary {
    color: #ffffff !important;
    background: var(--accent-orange) !important;
    box-shadow: 0 4px 12px rgba(253, 126, 20, 0.35) !important;
}

/* Accessibility Focus Ring */
#timeControls .btn-check:focus-visible + .btn-outline-secondary {
    box-shadow: var(--focus-ring) !important;
    outline: none;
}


/* Matching Dashboard Elements Dynamic State Reference */
.kpi-trend-indicator {
    font-size: 0.8rem;
    font-weight: 700;
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
    transition: all 0.25s ease;
}

.glow-btn {
    border: none;
    box-shadow: 0 0 12px rgba(253, 126, 20, 0.5);
    transition: box-shadow 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
}

@media (hover: hover) {
    .glow-btn:hover:not(:disabled) {
        transform: translateY(-2px);
        box-shadow: 0 0 20px rgba(253, 126, 20, 0.8);
    }
}

.glow-btn:disabled {
    opacity: 0.75;
    cursor: not-allowed;
    transform: none;
}

.pricing-input-group {
    max-width: 150px;
}

.pricing-input-group .input-group-text {
    color: var(--text-muted);
    background: transparent;
    border-right: none;
}

.pricing-input-group .form-control {
    padding-left: 0;
    border-left: none;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    font-size: 1.1rem;
    font-weight: 600;
}

.pricing-input-group .form-control:focus {
    border-color: #dee2e6;
    box-shadow: none;
}

/* --- 13. Auth Overlay (Lock Console) --- */
#lock-console {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

#lock-console.unlocked {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.auth-panel {
    width: min(100% - 2rem, 420px);
    padding: 2.5rem 2rem;
    text-align: center;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.25);
}

/* --- 14. Bootstrap Helpers & Utilities --- */
@media (min-width: 768px) {
    .w-md-auto {
        width: auto !important;
    }
    .border-start-md {
        border-left: var(--bs-border-width) var(--bs-border-style) var(--bs-border-color) !important;
    }
}

/* --- 15. Responsive Design (Mobile) --- */
/* Breakpoint lowered to 767.98px to keep the sidebar fully visible on split-screens and tablets */
@media (max-width: 767.98px) {
    html,
    body {
        min-width: 0;
        overflow-x: hidden !important;
    }

    body {
        display: block !important;
        overflow-y: auto !important;
    }

    .mobile-header {
        position: sticky;
        top: 0;
        z-index: 1030;
        display: flex !important;
        width: 100%;
        min-height: var(--mobile-header-height);
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
        padding: 0.9rem 1rem;
        background: rgba(17, 24, 39, 0.95);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
    }

    .mobile-header h5 {
        min-width: 0;
        max-width: calc(100vw - 78px);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .sidebar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        z-index: 1050 !important;
        width: min(280px, 86vw) !important;
        max-width: 86vw !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        padding: 1rem !important;
        overflow-y: auto !important;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.45);
        transform: translate3d(-105%, 0, 0) !important;
        transition: transform 0.28s ease-in-out !important;
        will-change: transform;
    }

    .sidebar.mobile-open {
        transform: translate3d(0, 0, 0) !important;
    }

    .sidebar-overlay {
        position: fixed !important;
        inset: 0 !important;
        z-index: 1040 !important;
        display: block !important;
        opacity: 0;
        pointer-events: none;
        background: rgba(17, 24, 39, 0.62);
        backdrop-filter: blur(3px);
        -webkit-backdrop-filter: blur(3px);
        transition: opacity 0.28s ease !important;
    }

    .sidebar-overlay.mobile-open {
        opacity: 1;
        pointer-events: auto;
    }

    .main-content {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        min-height: calc(100dvh - var(--mobile-header-height));
        height: auto !important;
        margin-left: 0 !important;
        padding: 1rem !important;
        overflow: visible !important;
    }

    .row {
        --bs-gutter-x: 1rem;
    }

    .dashboard-panel {
        height: auto !important;
        padding: 1.1rem;
        border-radius: 10px;
    }

    #kpiContainer .dashboard-panel {
        align-items: flex-start !important;
    }

    #kpiContainer h3 {
        font-size: 1.35rem;
        overflow-wrap: anywhere;
    }

    #timeControls {
        display: flex;
        width: 100%;
        padding: 4px;
    }

    #timeControls .btn {
        flex: 1 1 0;
        min-width: 0;
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
        white-space: nowrap;
    }

    #d3ChartContainer {
        height: 300px !important;
        min-height: 300px !important;
        max-height: 300px;
    }

    .table {
        min-width: 640px;
    }

    .table-responsive {
        margin-left: 0;
        margin-right: 0;
    }

    #pricing-engine-table-body .pricing-input-group {
        max-width: 130px;
    }

    .input-group .form-floating > .form-control,
    .input-group .form-floating > label {
        padding-left: 0.75rem !important;
    }
}

/* --- 16. Responsive Design (Small Phones) --- */
@media (max-width: 575.98px) {
    .mobile-header {
        padding: 0.8rem 0.9rem;
    }

    .main-content {
        padding: 0.85rem !important;
    }

    .dashboard-panel {
        padding: 1rem;
    }

    h2.fw-bold {
        font-size: 1.45rem;
    }

    h5.fw-bold {
        font-size: 1rem;
    }

    .kpi-icon {
        width: 42px;
        height: 42px;
        min-width: 42px;
        font-size: 1.05rem;
    }

    .btn,
    .form-control,
    .form-select,
    .input-group-text {
        font-size: 0.95rem;
    }

    #d3ChartContainer {
        height: 280px !important;
        min-height: 280px !important;
        max-height: 280px;
    }

    .pricing-input-group {
        max-width: 120px;
    }
}

/* --- 17. Accessibility: Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}
