:root {
    --primary-color: #0ea5e9;
    /* Sky 500 */
    --primary-dark: #0284c7;
    /* Sky 600 */
    --secondary-color: #22c55e;
    /* Green 500 */
    --bg-color: #f8fafc;
    /* Lighter blue-grey for modern feel */
    --sidebar-bg: #1e293b;
    /* Slate 800 */
    --sidebar-width: 280px;
    --header-height: 70px;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    color: #1f2937;
    -webkit-tap-highlight-color: transparent;
}

/* Layout Structure */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* --- Industry Standard Sidebar (Desktop) --- */
#main-sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 50;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-right: 1px solid #334155;
}

.sidebar-header {
    height: var(--header-height);
    padding: 0 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(0, 0, 0, 0.1);
}

.sidebar-menu {
    padding: 24px 16px;
    flex-grow: 1;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    margin-bottom: 4px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
    font-size: 0.95rem;
    color: #94a3b8;
}

.nav-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: #f1f5f9;
}

.nav-item.active {
    background-color: var(--primary-color);
    color: white;
    box-shadow: 0 4px 6px -1px rgba(249, 115, 22, 0.2);
}

.nav-item i {
    font-size: 1.25rem;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(0, 0, 0, 0.1);
}

/* --- Main Content Area --- */
.content-wrapper {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    width: calc(100% - var(--sidebar-width));
    transition: margin-left 0.3s, width 0.3s;
}

/* Modern Header */
.top-header {
    height: var(--header-height);
    background-color: #ffffff;
    border-bottom: 1px solid #e2e8f0;
    padding: 0 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 40;
}

.main-content {
    padding: 32px;
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
}

/* --- Cards & Visuals --- */
.view-section {
    animation: fadeIn 0.4s ease-out;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.card {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
    border: 1px solid #e2e8f0;
    padding: 24px;
    transition: transform 0.2s;
}

.metric-card {
    background: #ffffff;
    padding: 24px;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

.metric-card:hover,
.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

/* Mobile Adjustments */
#mobile-nav-toggle {
    display: none;
}

#nav-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 45;
    display: none;
    opacity: 0;
    transition: opacity 0.3s;
}

@media (max-width: 1024px) {
    #main-sidebar {
        transform: translateX(-100%);
    }

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

    .content-wrapper {
        margin-left: 0;
        width: 100%;
    }

    #mobile-nav-toggle {
        display: block;
    }

    .top-header {
        padding: 0 16px;
        justify-content: space-between;
    }

    .main-content {
        padding: 16px;
    }
}

/* ─── Mobile Table → Card Transformation ─── */
@media (max-width: 768px) {

    /* Force table to block to allow full width cards */
    .mobile-cards {
        display: block;
        width: 100%;
    }

    /* Hide table headers on mobile */
    .mobile-cards thead {
        display: none;
    }

    .mobile-cards tbody {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    /* Card container styling */
    .mobile-cards tbody tr {
        display: flex;
        flex-direction: column;
        background: #ffffff;
        border: 1px solid #e2e8f0;
        border-radius: 12px;
        padding: 0;
        margin-bottom: 20px;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
        overflow: hidden;
    }

    .mobile-cards tbody tr:hover {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
        transform: translateY(-1px);
        transition: all 0.2s ease;
    }

    /* Content rows */
    .mobile-cards tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 12px 16px !important;
        border: none !important;
        border-bottom: 1px solid #f1f5f9 !important;
        font-size: 0.875rem;
        color: #334155;
    }

    .mobile-cards tbody td:last-child {
        border-bottom: none !important;
        background-color: #f8fafc;
        justify-content: flex-end;
        gap: 8px;
    }

    /* Label styling */
    .mobile-cards tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 0.75rem;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: #94a3b8;
        flex-shrink: 0;
        margin-right: 12px;
    }

    /* Header row styling (using data-label="ID" as header indicator if present, or just first child) */
    /* Header row styling (first child is header) */
    .mobile-cards tbody td:first-child {
        background-color: #f8fafc;
        border-bottom: 1px solid #e2e8f0 !important;
        font-weight: 700;
        color: #1e293b;
        font-size: 0.95rem;
        display: flex;
        justify-content: flex-start;
        /* Ensure left align even if flex-between is set on td */
        gap: 8px;
    }

    /* Ensure label stays visible and nicely spaced in header */
    .mobile-cards tbody td:first-child::before {
        margin-right: auto;
        /* Push content to right if needed, or keep standard spacing */
        margin-right: 12px;
    }

    /* Add icon to header row based on context */
    /* We can't easily add icons via CSS content unless using a font like Phosphor code points. 
       Better to let JS inject the icon. But we can style the icon if JS adds it. */

    .mobile-cards tbody td[data-label="Status"] {
        justify-content: space-between;
    }

    /* Quick Action Buttons on mobile cards */
    .mobile-cards tbody td button {
        padding: 6px 12px;
        border-radius: 6px;
        font-size: 0.75rem;
        background-color: white;
        border: 1px solid #e2e8f0;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    }

    /* ─── Table wrapper adjustments ─── */
    .overflow-x-auto {
        overflow-x: visible;
    }

    /* ─── Report preview mobile adjustments ─── */
    /* ─── Report preview: Force Desktop Scale on Mobile ─── */
    #report-content {
        /* Force desktop width (A4) */
        min-width: 210mm !important;
        width: 210mm !important;

        /* JS handles the scaling via 'transform' to fit screen exactly */
        transform-origin: top left;

        /* Restore desktop appearance */
        padding: 40px !important;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    }

    #report-content table {
        font-size: 14px !important;
    }

    /* ─── Dashboard / Analysis Charts ─── */
    .h-56,
    .h-64 {
        height: 200px !important;
    }

    /* ─── Better padding for smaller screens ─── */
    .p-6 {
        padding: 16px !important;
    }
}

/* ─── Mobile Issue/Service Card List Items ─── */
@media (max-width: 768px) {

    /* Stacked cards for open issues list on dashboard */
    #dash-open-issues>div {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 8px;
        padding: 12px 16px !important;
    }

    #dash-open-issues>div>.flex {
        align-self: flex-end;
    }
}

/* ─── Mobile: Transparent Card Container to fix spacing issues ─── */
@media (max-width: 768px) {
    .view-section .card {
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        overflow: visible !important;
    }

    /* Style the header row of the card (Equipment Inventory + Button) as a standalone card */
    .view-section .card>div:first-child {
        background: white;
        border-radius: 12px;
        border: 1px solid #e2e8f0;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
        margin-bottom: 20px;
    }

    /* Adjust the table container */
    .view-section .card .overflow-x-auto {
        overflow: visible;
        padding: 4px;
        /* Space for shadows */
        margin: -4px;
        /* Counteract padding layout shift */
    }

    /* Fix header alignment in rows */
    .mobile-cards tbody td:first-child {
        justify-content: space-between !important;
    }
}