@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&family=IBM+Plex+Sans:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #F4F4F5; --surface: #FFFFFF; --primary: #E63946; --primary-hover: #D32F3F;
    --text: #1E293B; --text-muted: #64748B; --border: #E2E8F0; --input-bg: #F4F4F5;
    --success: #10B981; --warning: #F59E0B; --danger: #EF4444; --info: #3B82F6;
    --sidebar-w: 260px; --header-h: 60px; --radius: 8px;
}
.dark {
    --bg: #09090B; --surface: #18181B; --text: #F8FAFC; --text-muted: #A1A1AA;
    --border: #27272A; --input-bg: #27272A;
}

html { font-size: 14px; }
body { font-family: 'IBM Plex Sans', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }
h1,h2,h3,h4,h5 { font-family: 'Manrope', sans-serif; }
a { color: inherit; text-decoration: none; }

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

/* Sidebar */
.sidebar {
    width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; position: fixed; top: 0; left: 0; height: 100vh; z-index: 40;
    transition: transform 0.2s ease;
}
.sidebar.closed { transform: translateX(-100%); }
@media (min-width: 1024px) { .sidebar, .sidebar.closed { transform: translateX(0); } }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 35; }
.sidebar-overlay.active { display: block; }
@media (min-width: 1024px) { .sidebar-overlay { display: none !important; } }

.sidebar-logo {
    height: var(--header-h); display: flex; align-items: center; gap: 12px;
    padding: 0 20px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.sidebar-logo .logo-icon {
    width: 36px; height: 36px; border-radius: 8px; background: var(--primary);
    display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 16px;
}
.sidebar-logo span { font-weight: 700; font-size: 16px; font-family: 'Manrope'; }

.sidebar-nav { flex: 1; padding: 16px 12px; overflow-y: auto; }
.nav-item {
    display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 8px;
    font-size: 14px; font-weight: 500; cursor: pointer; margin-bottom: 2px;
    color: var(--text-muted); transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--input-bg); color: var(--text); }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item i { width: 20px; text-align: center; font-size: 16px; }

.sidebar-user {
    padding: 16px 20px; border-top: 1px solid var(--border);
    display: flex; align-items: center; gap: 12px; flex-shrink: 0;
}
.sidebar-user .avatar {
    width: 34px; height: 34px; border-radius: 50%; background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px;
}
.sidebar-user .user-info { flex: 1; min-width: 0; }
.sidebar-user .user-info p { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .user-info small { font-size: 11px; color: var(--text-muted); }

/* Main */
.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; }
@media (max-width: 1023px) { .main { margin-left: 0; } }

/* Header */
.header {
    height: var(--header-h); background: var(--surface); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between; padding: 0 24px;
    position: sticky; top: 0; z-index: 20;
}
.header-left { display: flex; align-items: center; gap: 12px; }
.header-right { display: flex; align-items: center; gap: 8px; }
.header-btn {
    background: none; border: none; color: var(--text-muted); cursor: pointer;
    width: 36px; height: 36px; border-radius: 8px; display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, color 0.15s; font-size: 16px;
}
.header-btn:hover { background: var(--input-bg); color: var(--text); }

.lang-select {
    background: var(--input-bg); border: 1px solid var(--border); color: var(--text);
    padding: 4px 8px; border-radius: 6px; font-size: 12px; cursor: pointer; text-transform: uppercase;
}

/* Content */
.content { padding: 24px; }
@media (max-width: 640px) { .content { padding: 16px; } }

.page-title { font-size: 28px; font-weight: 700; margin-bottom: 24px; letter-spacing: -0.5px; }

/* Cards */
.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    transition: transform 0.15s ease;
}
.card:hover { transform: translateY(-2px); }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-header h3 { font-size: 16px; font-weight: 600; }
.card-body { padding: 20px; }

/* Stats Grid */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
@media (max-width: 1200px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px) { .stats-grid { grid-template-columns: 1fr; } }

.stat-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px 20px; display: flex; align-items: center; gap: 14px;
}
.stat-icon {
    width: 44px; height: 44px; border-radius: 8px; display: flex; align-items: center;
    justify-content: center; font-size: 18px; flex-shrink: 0;
}
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
.stat-value { font-size: 26px; font-weight: 600; font-family: 'JetBrains Mono'; letter-spacing: -1px; margin-top: 2px; }

/* Grid layouts */
.grid-2 { display: grid; grid-template-columns: 1fr 2fr; gap: 16px; margin-bottom: 24px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 24px; }
.grid-eq { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
@media (max-width: 768px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* Badges */
.badge {
    display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 20px;
    font-size: 11px; font-weight: 600; gap: 4px; white-space: nowrap;
}
.badge-success { background: var(--success); color: #fff; }
.badge-warning { background: var(--warning); color: #fff; }
.badge-danger { background: var(--danger); color: #fff; }
.badge-info { background: var(--info); color: #fff; }
.badge-muted { background: var(--text-muted); color: #fff; }
.badge-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border: none;
    border-radius: 6px; font-size: 13px; font-weight: 600; cursor: pointer;
    transition: background 0.15s, transform 0.1s; font-family: inherit;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--input-bg); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--input-bg); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-danger-text { background: transparent; color: var(--danger); }
.btn-danger-text:hover { background: rgba(239,68,68,0.1); }

/* Forms */
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.form-control {
    width: 100%; padding: 9px 12px; background: var(--input-bg); border: 1px solid var(--border);
    border-radius: 6px; font-size: 14px; color: var(--text); font-family: inherit;
    transition: border-color 0.15s;
}
.form-control:focus { outline: none; border-color: var(--primary); }
select.form-control { appearance: auto; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .form-row { grid-template-columns: 1fr; } }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 16px; text-align: left; font-size: 13px; border-bottom: 1px solid var(--border); }
th { font-weight: 600; background: var(--input-bg); color: var(--text); font-size: 12px; text-transform: uppercase; letter-spacing: 0.3px; }
tr:hover td { background: var(--input-bg); }

/* Alert items */
.alert-item {
    display: flex; align-items: flex-start; gap: 12px; padding: 14px; border-radius: 8px;
    background: var(--input-bg); margin-bottom: 8px; transition: background 0.15s;
}
.alert-item:hover { background: var(--border); }
.alert-icon { color: var(--primary); font-size: 16px; margin-top: 2px; flex-shrink: 0; }
.alert-content { flex: 1; min-width: 0; }
.alert-content p { font-size: 13px; font-weight: 500; }
.alert-content small { font-size: 11px; color: var(--text-muted); }

/* Equipment card */
.eq-card { padding: 16px; }
.eq-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; }
.eq-header h4 { font-size: 15px; font-weight: 600; }
.eq-meta { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.eq-telemetry {
    display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding-top: 10px;
    border-top: 1px solid var(--border); margin-top: 10px;
}
.eq-telemetry-item {
    display: flex; align-items: center; gap: 6px; font-size: 12px; font-family: 'JetBrains Mono';
}
.eq-telemetry-item i { color: var(--primary); font-size: 12px; }
.eq-actions { display: flex; gap: 6px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }

/* Map */
#map-container { height: 65vh; border-radius: var(--radius); overflow: hidden; }
.map-legend { display: flex; gap: 20px; margin-top: 12px; flex-wrap: wrap; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; }

/* Tabs */
.tabs { display: flex; gap: 4px; background: var(--input-bg); padding: 4px; border-radius: 8px; margin-bottom: 20px; width: fit-content; }
.tab {
    padding: 8px 16px; border-radius: 6px; font-size: 13px; font-weight: 600; cursor: pointer;
    border: none; background: transparent; color: var(--text-muted); transition: all 0.15s;
    display: flex; align-items: center; gap: 6px;
}
.tab.active { background: var(--primary); color: #fff; }

/* Modal */
.modal-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5);
    z-index: 50; align-items: center; justify-content: center; padding: 16px;
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
    width: 100%; max-width: 500px; max-height: 90vh; overflow-y: auto;
}
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 18px; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 20px; }
.modal-body { padding: 20px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 20px; border-top: 1px solid var(--border); }

/* Login */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 16px; }
.login-card { width: 100%; max-width: 400px; }
.login-logo { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 32px; }
.login-logo .logo-icon { width: 48px; height: 48px; border-radius: 10px; background: var(--primary); display: flex; align-items: center; justify-content: center; color: #fff; font-size: 22px; font-weight: 800; }
.login-logo h1 { font-size: 22px; font-weight: 800; }
.login-error { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.2); border-radius: 8px; margin-bottom: 12px; font-size: 13px; color: var(--danger); }

/* Incident/Intervention card */
.list-card {
    display: flex; align-items: flex-start; gap: 14px; padding: 16px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    margin-bottom: 10px;
}
.list-card-icon { color: var(--primary); font-size: 18px; margin-top: 2px; flex-shrink: 0; }
.list-card-body { flex: 1; min-width: 0; }
.list-card-body h4 { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.list-card-body p { font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.list-card-meta { display: flex; gap: 12px; font-size: 11px; color: var(--text-muted); flex-wrap: wrap; }

/* Chart container */
.chart-container { width: 100%; height: 220px; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(100,116,139,0.3); border-radius: 3px; }

/* Leaflet dark mode */
.dark .leaflet-tile-pane { filter: brightness(0.85) contrast(1.1) saturate(0.8); }
.leaflet-popup-content-wrapper { border-radius: 8px !important; }

/* Utilities */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-1 { gap: 4px; }
.flex-wrap { flex-wrap: wrap; }
.text-center { text-align: center; }
.mt-2 { margin-top: 8px; }
.mb-4 { margin-bottom: 16px; }
.py-12 { padding-top: 48px; padding-bottom: 48px; }
.hidden { display: none !important; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Page header with action */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.page-header .page-title { margin-bottom: 0; }

/* RTL support */
[dir="rtl"] .sidebar { left: auto; right: 0; border-right: none; border-left: 1px solid var(--border); }
[dir="rtl"] .main { margin-left: 0; margin-right: var(--sidebar-w); }
@media (max-width: 1023px) { [dir="rtl"] .main { margin-right: 0; } }
[dir="rtl"] .sidebar.closed { transform: translateX(100%); }

/* Dropzone */
.dropzone {
    border: 2px dashed var(--border); border-radius: 12px; padding: 40px; text-align: center;
    cursor: pointer; transition: border-color 0.2s, background 0.2s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 5%, transparent); }

/* Split layout for equipment */
.eq-split-layout { display: flex; gap: 16px; transition: all 0.3s ease; }
@media (max-width: 768px) { .eq-split-layout { flex-direction: column; }
    .eq-split-layout > div { width: 100% !important; min-width: 0 !important; } }

/* Active view toggle */
.active-view { background: var(--primary) !important; color: #fff !important; }

/* Nav settings */
.nav-item[data-page="settings"] i { color: var(--text-muted); }
.nav-item.active[data-page="settings"] i { color: #fff; }
