/* ============================================================
   IoT Accident Detection System — Master Stylesheet
   ============================================================ */

/* ---- Variables ---- */
:root {
    --sidebar-width: 260px;
    --sidebar-collapsed: 72px;
    --navbar-height: 60px;
    --sidebar-bg: #0f172a;
    --sidebar-hover: rgba(255,255,255,.07);
    --sidebar-active: #dc3545;
    --sidebar-text: #94a3b8;
    --sidebar-text-active: #ffffff;
    --brand-red: #dc3545;
    --transition: .25s ease;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
    --radius: .75rem;
    --radius-sm: .5rem;
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    font-size: .9rem;
    background: #f1f5f9;
    color: #1e293b;
    overflow-x: hidden;
}

/* ============================================================
   LAYOUT — Wrapper, Sidebar, Main
   ============================================================ */
.wrapper {
    display: flex;
    min-height: calc(100vh - var(--navbar-height));
    margin-top: var(--navbar-height);
}

/* ---- Sidebar ---- */
.sidebar {
    position: fixed;
    top: var(--navbar-height);
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--navbar-height));
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    transition: width var(--transition), transform var(--transition);
    z-index: 900;
    scrollbar-width: thin;
    scrollbar-color: #334155 transparent;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: #334155; border-radius: 2px; }

/* Brand */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .875rem;
    padding: 1.25rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,.06);
    min-height: 70px;
    flex-shrink: 0;
}

.brand-icon {
    width: 40px; height: 40px;
    background: var(--brand-red);
    border-radius: .625rem;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-size: 1.1rem;
    flex-shrink: 0;
    box-shadow: 0 0 0 3px rgba(220,53,69,.25);
}

.brand-name {
    display: block;
    font-weight: 700;
    font-size: .95rem;
    color: #f8fafc;
    white-space: nowrap;
}

.brand-sub {
    display: block;
    font-size: .65rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: .08em;
    white-space: nowrap;
}

/* Status */
.sidebar-status {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem 1rem .75rem;
    font-size: .7rem;
    color: #4ade80;
}

.status-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: #4ade80;
    flex-shrink: 0;
}

.status-dot.pulse {
    animation: statusPulse 2s ease-in-out infinite;
}

/* Nav */
.sidebar-nav { padding: 0 .625rem; }

.nav-section-label {
    font-size: .6rem;
    font-weight: 700;
    letter-spacing: .12em;
    color: #475569;
    text-transform: uppercase;
    padding: .75rem .5rem .25rem;
}

.sidebar-item { margin-bottom: .125rem; }

.sidebar-link {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .625rem .75rem;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    text-decoration: none;
    transition: background var(--transition), color var(--transition);
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-link:hover {
    background: var(--sidebar-hover);
    color: #e2e8f0;
}

.sidebar-item.active .sidebar-link {
    background: rgba(220, 53, 69, .15);
    color: var(--sidebar-text-active);
    font-weight: 600;
}

.sidebar-item.active .sidebar-icon { color: var(--brand-red); }

.sidebar-icon {
    width: 18px;
    text-align: center;
    font-size: .9rem;
    flex-shrink: 0;
    color: #64748b;
    transition: color var(--transition);
}

.sidebar-link:hover .sidebar-icon { color: #94a3b8; }

.sidebar-label { font-size: .85rem; }

.text-danger-light { color: #f87171 !important; }

/* Sidebar Footer */
.sidebar-footer {
    margin-top: auto;
    padding: 1rem;
    border-top: 1px solid rgba(255,255,255,.06);
    flex-shrink: 0;
}

/* Main Content */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-width: 0;
    transition: margin-left var(--transition);
}

/* Collapsed sidebar */
.sidebar-collapsed .sidebar { width: var(--sidebar-collapsed); }
.sidebar-collapsed .brand-text,
.sidebar-collapsed .sidebar-label,
.sidebar-collapsed .sidebar-status,
.sidebar-collapsed .nav-section-label,
.sidebar-collapsed .sidebar-footer,
.sidebar-collapsed .brand-icon + .brand-text { display: none; }
.sidebar-collapsed .sidebar-brand { justify-content: center; padding: 1.25rem .5rem; }
.sidebar-collapsed .sidebar-link { justify-content: center; padding: .75rem; }
.sidebar-collapsed .sidebar-nav { padding: 0 .375rem; }
.sidebar-collapsed .main-content { margin-left: var(--sidebar-collapsed); }

/* Overlay (mobile) */
.sidebar-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 899;
    display: none;
}
.sidebar-overlay.show { display: block; }

/* ============================================================
   TOP NAVBAR
   ============================================================ */
.top-navbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--navbar-height);
    background: #ffffff;
    border-bottom: 1px solid #e2e8f0;
    z-index: 1000;
    box-shadow: var(--shadow-sm);
}

[data-bs-theme="dark"] .top-navbar {
    background: #1e293b;
    border-color: #334155;
}

/* ============================================================
   AVATAR
   ============================================================ */
.avatar-circle {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, #dc3545, #b02a37);
    color: #fff;
    font-weight: 700;
    font-size: .85rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.avatar-sm { width: 28px; height: 28px; font-size: .7rem; }

/* ============================================================
   STAT CARDS
   ============================================================ */
.stat-card {
    border: none;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    transition: transform .2s, box-shadow .2s;
    cursor: default;
}

.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.stat-card .card-body { padding: 1.25rem 1.5rem; }

.stat-icon {
    width: 52px; height: 52px;
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.4rem;
    background: rgba(255,255,255,.2);
    color: #fff;
    flex-shrink: 0;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
    color: #fff;
}

.stat-label {
    font-size: .78rem;
    color: rgba(255,255,255,.8);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .06em;
}

.stat-sub {
    font-size: .7rem;
    color: rgba(255,255,255,.65);
    margin-top: .25rem;
}

.bg-gradient-danger  { background: linear-gradient(135deg, #dc3545 0%, #9d0b1e 100%); }
.bg-gradient-warning { background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%); }
.bg-gradient-success { background: linear-gradient(135deg, #198754 0%, #0d5c39 100%); }
.bg-gradient-primary { background: linear-gradient(135deg, #0d6efd 0%, #084298 100%); }
.bg-gradient-purple  { background: linear-gradient(135deg, #6f42c1 0%, #4a0e9e 100%); }
.bg-gradient-teal    { background: linear-gradient(135deg, #0dcaf0 0%, #0891b2 100%); }

/* ============================================================
   PAGE HEADER
   ============================================================ */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
}

.page-header .breadcrumb {
    font-size: .78rem;
    margin: 0;
}

/* ============================================================
   TABLES
   ============================================================ */
.table-card {
    border: none;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.table-card .card-header {
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    padding: 1rem 1.25rem;
    font-weight: 600;
}

.table thead th {
    font-size: .75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #64748b;
    background: #f8fafc;
    border-color: #e2e8f0;
    white-space: nowrap;
    padding: .75rem 1rem;
}

.table tbody tr { transition: background .15s; }
.table tbody tr:hover { background: rgba(13,110,253,.03); }
.table tbody td { padding: .75rem 1rem; vertical-align: middle; border-color: #f1f5f9; }

[data-bs-theme="dark"] .table thead th { background: #1e293b; border-color: #334155; }
[data-bs-theme="dark"] .table tbody td { border-color: #334155; }

/* ============================================================
   CARDS
   ============================================================ */
.card {
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.card-header { font-weight: 600; }

/* ============================================================
   EMERGENCY ALERT PANEL
   ============================================================ */
.emergency-alert-panel {
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 0 0 3px rgba(220,53,69,.3), var(--shadow-lg);
    animation: emergencyGlow 1.5s ease-in-out infinite;
}

@keyframes emergencyGlow {
    0%, 100% { box-shadow: 0 0 0 3px rgba(220,53,69,.3), var(--shadow-lg); }
    50%       { box-shadow: 0 0 0 6px rgba(220,53,69,.5), 0 20px 40px rgba(220,53,69,.2); }
}

.emergency-header {
    background: linear-gradient(135deg, #dc3545, #9d0b1e);
    color: #fff;
    padding: 2rem;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.emergency-header::before {
    content: '';
    position: absolute; inset: 0;
    background: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 10px,
        rgba(255,255,255,.03) 10px,
        rgba(255,255,255,.03) 20px
    );
}

.siren-icon-wrap {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 70px; height: 70px;
    border-radius: 50%;
    background: rgba(255,255,255,.15);
    margin-bottom: 1rem;
    animation: sirenSpin 1s linear infinite;
    position: relative;
    z-index: 1;
}

.siren-icon-wrap i { font-size: 2rem; }

@keyframes sirenSpin {
    0%   { box-shadow: 0 0 0 0 rgba(255,255,255,.5); }
    70%  { box-shadow: 0 0 0 20px rgba(255,255,255,0); }
    100% { box-shadow: 0 0 0 0 rgba(255,255,255,0); }
}

.emergency-title {
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: .05em;
    text-shadow: 0 2px 4px rgba(0,0,0,.3);
    position: relative; z-index: 1;
}

.emergency-subtitle {
    font-size: .85rem;
    opacity: .85;
    position: relative; z-index: 1;
}

.emergency-body { padding: 1.5rem; background: #fff; }

.alert-detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.alert-detail-item {
    padding: 1rem;
    border-radius: var(--radius-sm);
    background: #f8fafc;
    border-left: 3px solid #dc3545;
}

.alert-detail-label {
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #64748b;
    margin-bottom: .25rem;
}

.alert-detail-value {
    font-size: .95rem;
    font-weight: 600;
    color: #1e293b;
}

.emergency-footer {
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
    padding: 1.25rem 1.5rem;
}

.notification-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .5rem 0;
    border-bottom: 1px solid #e2e8f0;
    font-size: .85rem;
}

.notification-item:last-child { border: 0; }

.notif-icon {
    width: 30px; height: 30px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: .75rem;
    flex-shrink: 0;
}

/* ============================================================
   SEVERITY BADGE OVERRIDE
   ============================================================ */
.badge.severity-High   { background: #dc3545 !important; }
.badge.severity-Medium { background: #f59e0b !important; }
.badge.severity-Low    { background: #198754 !important; }

/* ============================================================
   FLASH BADGE (navbar/sidebar)
   ============================================================ */
@keyframes flashBadge {
    0%, 100% { opacity: 1; }
    50%       { opacity: .3; }
}
.badge[style*="font-size:.6rem"] { animation: flashBadge 1s ease-in-out infinite; }

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-page {
    min-height: 100vh;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.login-bg {
    position: fixed; inset: 0;
    pointer-events: none;
    overflow: hidden;
}

.particle {
    position: absolute;
    border-radius: 50%;
    background: rgba(220,53,69,.15);
    animation: float 8s ease-in-out infinite;
}
.particle:nth-child(1) { width:300px;height:300px; top:-100px; left:-100px; animation-delay:0s; }
.particle:nth-child(2) { width:200px;height:200px; bottom:-50px; right:-50px; animation-delay:2s; }
.particle:nth-child(3) { width:150px;height:150px; top:50%; left:60%; animation-delay:4s; }
.particle:nth-child(4) { width:80px; height:80px;  top:20%; right:20%; animation-delay:1s; background:rgba(13,110,253,.1); }
.particle:nth-child(5) { width:60px; height:60px;  bottom:30%;left:10%; animation-delay:3s; background:rgba(13,110,253,.1); }
.particle:nth-child(6) { width:120px;height:120px; top:70%; left:40%; animation-delay:5s; }

@keyframes float {
    0%,100% { transform: translateY(0) scale(1); }
    50%      { transform: translateY(-30px) scale(1.05); }
}

.login-container { position: relative; z-index: 1; width: 100%; max-width: 430px; padding: 1rem; }

.login-card {
    background: #fff;
    border-radius: 1rem;
    padding: 2.25rem 2rem;
    box-shadow: 0 25px 50px rgba(0,0,0,.4);
}

.login-logo {
    width: 70px; height: 70px;
    background: linear-gradient(135deg, #dc3545, #9d0b1e);
    border-radius: 1rem;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.75rem;
    color: #fff;
    box-shadow: 0 8px 20px rgba(220,53,69,.4);
}

.login-card .input-group-text { border-color: #dee2e6; }
.login-card .form-control { border-color: #dee2e6; }
.login-card .form-control:focus { border-color: #dc3545; box-shadow: 0 0 0 .2rem rgba(220,53,69,.15); }

/* ============================================================
   FORM SIMULATOR
   ============================================================ */
.simulator-card {
    border: 2px solid #e2e8f0;
    border-radius: var(--radius);
    transition: border-color .3s;
}

.simulator-card:focus-within { border-color: #dc3545; }

.severity-selector .severity-opt {
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    padding: .75rem;
    transition: all .2s;
    flex: 1;
    text-align: center;
}

.severity-selector .severity-opt:hover { opacity: .85; }
.severity-selector .severity-opt.selected { border-color: currentColor; box-shadow: 0 0 0 3px currentColor inset, 0 0 0 5px rgba(255,255,255,.6) inset; }

.sev-low    { background: rgba(25,135,84,.1); color:#198754; }
.sev-medium { background: rgba(245,158,11,.1); color:#d97706; }
.sev-high   { background: rgba(220,53,69,.1);  color:#dc3545; }

/* ============================================================
   CHARTS
   ============================================================ */
.chart-container { position: relative; }

/* ============================================================
   CONTACT CARDS
   ============================================================ */
.contact-card {
    border-radius: var(--radius);
    overflow: hidden;
    transition: transform .2s, box-shadow .2s;
    border: none;
    box-shadow: var(--shadow-sm);
}

.contact-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.contact-avatar {
    width: 48px; height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, #dc3545, #9d0b1e);
    color: #fff;
    font-weight: 700;
    font-size: 1.1rem;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

/* ============================================================
   LOCATION CARD
   ============================================================ */
.location-map-placeholder {
    height: 400px;
    background: linear-gradient(135deg, #e2e8f0 0%, #cbd5e1 100%);
    border-radius: var(--radius-sm);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    color: #94a3b8;
    border: 2px dashed #cbd5e1;
}

#leafletMap { height: 450px; border-radius: var(--radius-sm); z-index: 1; }

/* ============================================================
   REPORTS
   ============================================================ */
.report-stat {
    text-align: center;
    padding: 1.5rem;
    border-radius: var(--radius-sm);
    background: #f8fafc;
    border: 1px solid #e2e8f0;
}

.report-stat .rs-value {
    font-size: 2.25rem;
    font-weight: 800;
    line-height: 1;
}

.report-stat .rs-label { font-size: .78rem; color: #64748b; margin-top: .25rem; }

/* ============================================================
   TOASTS
   ============================================================ */
.toast { border: none; box-shadow: var(--shadow-lg); border-radius: var(--radius-sm); }
.toast-header { border-bottom: none; padding: .6rem 1rem; }
.toast-body   { padding: .6rem 1rem 1rem; font-size: .85rem; }

/* ============================================================
   DARK MODE
   ============================================================ */
[data-bs-theme="dark"] {
    --bs-body-bg: #0f172a;
    --bs-body-color: #e2e8f0;
}

[data-bs-theme="dark"] body          { background: #0f172a; }
[data-bs-theme="dark"] .card         { background: #1e293b; border-color: #334155; }
[data-bs-theme="dark"] .card-header  { background: #1e293b; border-color: #334155; }
[data-bs-theme="dark"] .table-card   { background: #1e293b; }
[data-bs-theme="dark"] .table thead th { background: #0f172a; color: #94a3b8; }
[data-bs-theme="dark"] .table tbody td { color: #e2e8f0; }
[data-bs-theme="dark"] .table tbody tr:hover { background: rgba(255,255,255,.03); }
[data-bs-theme="dark"] .form-control  { background: #0f172a; border-color: #334155; color: #e2e8f0; }
[data-bs-theme="dark"] .form-select   { background: #0f172a; border-color: #334155; color: #e2e8f0; }
[data-bs-theme="dark"] .input-group-text { background: #1e293b; border-color: #334155; color: #94a3b8; }
[data-bs-theme="dark"] .alert-detail-item { background: #0f172a; }
[data-bs-theme="dark"] .alert-detail-value { color: #e2e8f0; }
[data-bs-theme="dark"] .emergency-body { background: #1e293b; }
[data-bs-theme="dark"] .emergency-footer { background: #0f172a; border-color: #334155; }
[data-bs-theme="dark"] .notification-item { border-color: #334155; }
[data-bs-theme="dark"] .report-stat  { background: #0f172a; border-color: #334155; }
[data-bs-theme="dark"] .location-map-placeholder { background: linear-gradient(135deg,#1e293b,#0f172a); border-color:#334155; }
[data-bs-theme="dark"] .sev-low    { background:rgba(25,135,84,.2); }
[data-bs-theme="dark"] .sev-medium { background:rgba(245,158,11,.2); }
[data-bs-theme="dark"] .sev-high   { background:rgba(220,53,69,.2); }
[data-bs-theme="dark"] .simulator-card { border-color:#334155; }
[data-bs-theme="dark"] .contact-card   { background:#1e293b; }
[data-bs-theme="dark"] .modal-content  { background:#1e293b; }
[data-bs-theme="dark"] .modal-header   { border-color:#334155; }
[data-bs-theme="dark"] .modal-footer   { border-color:#334155; }

/* ============================================================
   KEYFRAMES
   ============================================================ */
@keyframes statusPulse {
    0%,100% { opacity: 1; transform: scale(1); }
    50%      { opacity: .6; transform: scale(.85); }
}

@keyframes slideInDown {
    from { opacity: 0; transform: translateY(-20px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.slide-in-down { animation: slideInDown .4s ease forwards; }
.fade-in       { animation: fadeIn .4s ease forwards; }

/* ============================================================
   UTILITIES
   ============================================================ */
.ls-1 { letter-spacing: .05em; }
.cursor-pointer { cursor: pointer; }
.min-w-0 { min-width: 0; }

/* Truncate text */
.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Scrollable table wrapper */
.table-responsive-card { overflow-x: auto; }

/* Print styles */
@media print {
    .sidebar, .top-navbar, .btn, .page-header .btn, #darkModeToggle { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .wrapper { margin-top: 0; }
    .card { box-shadow: none; border: 1px solid #dee2e6; }
}

/* ============================================================
   RESPONSIVE — Tablet & Mobile
   ============================================================ */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width) !important;
    }
    .sidebar.show {
        transform: translateX(0);
    }
    .main-content { margin-left: 0 !important; }

    /* Show brand-text even on mobile when sidebar open */
    .sidebar.show .brand-text,
    .sidebar.show .sidebar-label,
    .sidebar.show .nav-section-label,
    .sidebar.show .sidebar-status,
    .sidebar.show .sidebar-footer { display: unset; }
}

@media (max-width: 575.98px) {
    .emergency-title { font-size: 1.2rem; }
    .stat-value { font-size: 1.5rem; }
    .stat-icon  { width: 42px; height: 42px; font-size: 1.1rem; }
    .alert-detail-grid { grid-template-columns: 1fr 1fr; }
    .login-card { padding: 1.5rem 1.25rem; }
}
