/*  Reset & Base  */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary:       #1A56DB;
    --primary-dark:  #1E429F;
    --danger:        #C62828;
    --danger-light:  #FFEBEE;
    --danger-dark:   #B71C1C;
    --warning:       #F57C00;
    --warning-light: #FFF3E0;
    --warning-dark:  #E65100;
    --success:       #2E7D32;
    --success-light: #E8F5E9;
    --success-dark:  #1B5E20;
    --info:          #1565C0;
    --info-light:    #E3F2FD;
    --info-dark:     #0D47A1;

    --bg:            #FAFAFA;
    --card:          #FFFFFF;
    --surface:       #FFFFFF;
    --surface-alt:   #F9FAFB;
    --border:        #E5E5E5;
    --sidebar-bg:    #121212;
    --sidebar-width: 220px;
    --topbar-height: 52px;

    --text:          #1A1A1A;
    --text-muted:    #5A5A5A;
    --text-light:    #8A8A8A;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

/*  App Shell Layout  */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/*  Sidebar  */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: #D1D5DB;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-logo {
    padding: 18px 16px;
    font-size: 18px;
    font-weight: 700;
    color: #FFFFFF;
    border-bottom: 1px solid #1F2937;
    letter-spacing: -0.3px;
}

.nav-section {
    padding: 14px 16px 4px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #4B5563;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    font-size: 13.5px;
    color: #9CA3AF;
    border-radius: 0;
    transition: background 0.1s, color 0.1s;
    cursor: pointer;
}

.nav-item:hover { background: #2D2D2D; color: #F9FAFB; }
.nav-item.active { background: var(--primary-dark); color: #FFFFFF; font-weight: 500; }

/*  Main content area  */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.topbar {
    height: var(--topbar-height);
    min-height: var(--topbar-height);
    background: var(--card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
}

.page-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.page-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--text);
}


/*  Cards & Components  */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 16px;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px;
}

.stat-value { font-size: 32px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/*  Badges  */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 600;
}
.badge-green  { background: var(--success-light); color: var(--success-dark); }
.badge-amber  { background: var(--warning-light); color: var(--warning-dark); }
.badge-red    { background: var(--danger-light);  color: var(--danger-dark);  }
.badge-blue   { background: var(--info-light);    color: var(--info-dark);    }
.badge-gray   { background: #F5F5F5; color: #404040; }

/*  Table  */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
    text-align: left;
    padding: 10px 14px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    border-bottom: 2px solid var(--border);
    background: #F9FAFB;
}
.data-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}
.data-table tr:hover td { background: #F9FAFB; }

/*  Buttons  */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: background 0.15s;
}
.btn-primary            { background: var(--primary); color: #fff; }
.btn-primary:hover      { background: var(--primary-dark); }
.btn-secondary          { background: #F3F4F6; color: var(--text); }
.btn-secondary:hover    { background: #E5E7EB; }
.btn-danger             { background: var(--danger); color: #fff; }
.btn-sm                 { padding: 5px 12px; font-size: 13px; }

/*  Form  */
.form-group  { margin-bottom: 16px; }
.form-label  { display: block; margin-bottom: 6px; font-weight: 500; font-size: 13px; }
.form-input  {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s;
    background: #fff;
    color: var(--text);
}
.form-input:focus { border-color: var(--primary); }

/*  Alerts  */
.alert         { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.alert-error   { background: var(--danger-light);  color: var(--danger-dark);  }
.alert-success { background: var(--success-light); color: var(--success-dark); }
.alert-warn    { background: var(--warning-light); color: var(--warning-dark); }

/*  Offline / sync banner  */
.offline-banner {
    background: var(--warning-light);
    color: var(--warning-dark);
    padding: 8px 24px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/*  Blazor error UI  */
#blazor-error-ui {
    background: var(--danger-light);
    color: var(--danger-dark);
    padding: 12px 16px;
    position: fixed;
    bottom: 0;
    width: 100%;
    display: none;
    font-size: 14px;
    z-index: 1000;
}
#blazor-error-ui .reload { color: var(--primary); text-decoration: underline; margin-left: 8px; }
#blazor-error-ui .dismiss { float: right; cursor: pointer; }

/*  Dropdown action menu  */
.dropdown-item {
    display: block;
    width: 100%;
    padding: 8px 16px;
    background: none;
    border: none;
    text-align: left;
    font-size: 14px;
    cursor: pointer;
    color: var(--text-primary, #111827);
    transition: background 0.15s;
}
.dropdown-item:hover                { background: var(--surface, #f9fafb); }
.dropdown-item-success              { color: var(--success); }
.dropdown-item-success:hover        { background: var(--success-light); }
.dropdown-item-warning              { color: var(--warning); }
.dropdown-item-warning:hover        { background: var(--warning-light); }
.dropdown-item-danger               { color: var(--danger); }
.dropdown-item-danger:hover         { background: var(--danger-light); }

/* Bootstrap Icons — nav + table sizing */
.nav-item .bi {
    font-size: 1rem;
    width: 1.25rem;
    text-align: center;
    margin-right: 0.5rem;
    flex-shrink: 0;
}

td .bi, th .bi {
    font-size: 0.9rem;
    vertical-align: middle;
}

/* ── Mobile hamburger (hidden on desktop) ── */
.nav-toggle { display: none; }

/* ── Notification dropdown base width ── */
.notif-dropdown { width: 360px; }

/* ── Photo gallery grid (desktop: 4 cols) ── */
.photo-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

/* ── Mobile / tablet responsive ── */
@media (max-width: 768px) {
    .nav-toggle {
        display: inline-flex;
        margin-right: 8px;
    }

    /* Sidebar slides off-screen by default on mobile */
    .sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        z-index: 200;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }

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

    /* Dim overlay behind open sidebar */
    .nav-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 199;
    }

    .main-content { width: 100%; }

    .topbar       { padding: 0 12px; }
    .page-content { padding: 16px; }
    .card         { padding: 16px; }

    /* Any element directly containing a table scrolls horizontally —
       covers .data-table and non-classed tables (Operations/Workforce/Safety/Settings). */
    *:has(> table) {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    /* Modal/panel cards + non-.card panels constrained to viewport.
       Second selector catches Incidents sidebar and SitePhotos lightbox (plain divs). */
    [style*="inset:0"] > .card,
    [style*="inset:0"] > [style*="max-width"] {
        max-width: calc(100vw - 24px) !important;
        box-sizing: border-box;
    }

    /* Page header rows (title + action buttons) wrap on mobile.
       Targets any flex div that directly contains a .page-title h1. */
    div:has(> .page-title) {
        flex-wrap: wrap !important;
        gap: 8px;
    }

    /* Photo gallery: 2 columns on mobile */
    .photo-grid { grid-template-columns: repeat(2, 1fr); }

    /* Notification dropdown caps to viewport width */
    .notif-dropdown {
        width: calc(100vw - 24px);
        right: -8px;
    }

    /* Stat cards fit tighter on mobile */
    .stat-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }

    /* Flex summary card rows (e.g. invoice totals) wrap on mobile */
    .cards-row {
        flex-wrap: wrap;
    }

    /* Page header rows (title + action buttons) wrap on mobile */
    .page-header-row {
        flex-wrap: wrap;
        gap: 8px;
    }
}
