/* =====================================================
   شهر نگار نیکسا - استایل اصلی سامانه
   ===================================================== */

:root {
    --bg-main: #06111B;
    --bg-panel: #0D1B2A;
    --bg-panel-light: #122638;
    --border-color: #1B3349;
    --green: #21A663;
    --yellow: #F4B324;
    --red: #EF3F3A;
    --text-primary: #FFFFFF;
    --text-secondary: #7E92A6;
    --font-main: 'Vazirmatn', 'Tahoma', sans-serif;
}

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

body {
    font-family: var(--font-main);
    background: var(--bg-main);
    color: var(--text-primary);
    direction: rtl;
}

a { text-decoration: none; color: inherit; }
ul { list-style: none; }
button { font-family: var(--font-main); cursor: pointer; border: none; }
input, select { font-family: var(--font-main); }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-main); }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--green); }

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

/* ===================== Sidebar ===================== */
.sidebar {
    width: 270px;
    flex-shrink: 0;
    background: var(--bg-panel);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: sticky;
    top: 0;
}

.sidebar-header {
    padding: 24px 20px;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header .logo-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-header h2 {
    font-size: 17px;
    font-weight: 700;
}

.sidebar-header p {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 14px 12px;
}

.sidebar-nav .nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    margin-bottom: 4px;
    border-radius: 10px;
    color: var(--text-secondary);
    font-size: 14px;
    transition: all .2s ease;
}

.sidebar-nav .nav-item svg { flex-shrink: 0; width: 19px; height: 19px; }

.sidebar-nav .nav-item:hover {
    background: var(--bg-panel-light);
    color: var(--text-primary);
}

.sidebar-nav .nav-item.active {
    background: rgba(33, 166, 99, 0.15);
    color: var(--green);
    border-right: 3px solid var(--green);
}

.sidebar-illustration {
    padding: 10px 16px;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    text-align: center;
    font-size: 10.5px;
    color: var(--text-secondary);
    line-height: 1.8;
}

.sidebar-footer strong { color: var(--text-primary); display:block; font-size: 12px;}

/* ===================== Main Content ===================== */
.main-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* ===================== Top Header ===================== */
.top-header {
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
    padding: 14px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
}

.header-right { display: flex; align-items: center; gap: 20px; }
.header-left { display: flex; align-items: center; gap: 18px; }

.header-datetime { font-size: 13px; color: var(--text-secondary); display:flex; flex-direction:column; gap:2px;}
.header-datetime strong { color: var(--text-primary); font-size: 14px;}

.header-weather {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-panel-light);
    padding: 8px 14px;
    border-radius: 10px;
    font-size: 13px;
}

.header-icon-btn {
    position: relative;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--bg-panel-light);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

.header-icon-btn .badge {
    position: absolute;
    top: -3px;
    left: -3px;
    background: var(--red);
    color: #fff;
    font-size: 10px;
    border-radius: 50%;
    width: 17px;
    height: 17px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 6px 6px 14px;
    background: var(--bg-panel-light);
    border-radius: 30px;
}

.header-user .avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--green), #158a4f);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
}

.header-user .info { font-size: 12.5px; line-height: 1.4; }
.header-user .info strong { display: block; font-size: 13px; }
.header-user .logout-link { color: var(--red); font-size: 11px; }

/* ===================== Page Content ===================== */
.page-content { padding: 24px 28px; }

.page-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.page-title-row h1 { font-size: 20px; font-weight: 700; }
.page-title-row p { color: var(--text-secondary); font-size: 13px; margin-top: 4px; }

/* ===================== KPI Cards ===================== */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 18px;
    position: relative;
    overflow: hidden;
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0; right: 0;
    width: 4px; height: 100%;
    background: var(--accent, var(--green));
}

.kpi-card .kpi-icon {
    width: 38px; height: 38px;
    border-radius: 10px;
    background: rgba(33,166,99,0.15);
    color: var(--accent, var(--green));
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 12px;
}

.kpi-card .kpi-value { font-size: 24px; font-weight: 800; margin-bottom: 4px; }
.kpi-card .kpi-label { font-size: 12.5px; color: var(--text-secondary); }
.kpi-card .kpi-trend { font-size: 11px; margin-top: 8px; display:flex; align-items:center; gap:4px;}

/* ===================== Panels ===================== */
.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 18px;
    margin-bottom: 18px;
}

.panel {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 18px;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.panel-header h3 { font-size: 15px; font-weight: 700; }
.panel-header .panel-sub { font-size: 11.5px; color: var(--text-secondary); }

.status-dot {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11.5px;
    color: var(--green);
}
.status-dot::before {
    content: '';
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 8px var(--green);
    animation: pulse-dot 1.6s infinite;
}
@keyframes pulse-dot {
    0% { opacity: 1; } 50% { opacity: 0.4; } 100% { opacity: 1; }
}

.map-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}
.map-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-panel-light);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    padding: 7px 16px;
    border-radius: 8px;
    font-size: 12.5px;
    font-weight: 600;
    transition: all .15s ease;
}
.map-tab i { font-size: 14px; }
.map-tab:hover { color: var(--text-primary); }
.map-tab.active {
    background: rgba(33,166,99,0.15);
    color: var(--green);
    border-color: var(--green);
}
.map-refresh-note {
    display: flex;
    gap: 18px;
    margin-top: 10px;
    font-size: 11px;
    color: var(--text-secondary);
}
.map-refresh-note strong { color: var(--text-primary); font-weight: 600; }

#cityMap {
    width: 100%;
    height: 420px;
    border-radius: 10px;
    background: var(--bg-panel-light);
}

.map-legend {
    display: flex;
    gap: 16px;
    margin-top: 12px;
    flex-wrap: wrap;
    font-size: 11.5px;
    color: var(--text-secondary);
}
.map-legend span { display: flex; align-items: center; gap: 6px; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; display:inline-block; }

/* ===================== Alerts ===================== */
.alert-list { display: flex; flex-direction: column; gap: 10px; max-height: 420px; overflow-y: auto; }

.alert-item {
    display: flex;
    gap: 12px;
    padding: 12px;
    background: var(--bg-panel-light);
    border-radius: 10px;
    border-right: 3px solid var(--text-secondary);
}
.alert-item.critical { border-color: var(--red); }
.alert-item.warning { border-color: var(--yellow); }
.alert-item.info { border-color: #4FA3E3; }

.alert-icon {
    width: 32px; height: 32px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.alert-item.critical .alert-icon { background: rgba(239,63,58,0.15); color: var(--red); }
.alert-item.warning .alert-icon { background: rgba(244,179,36,0.15); color: var(--yellow); }
.alert-item.info .alert-icon { background: rgba(79,163,227,0.15); color: #4FA3E3; }

.alert-body { flex: 1; min-width: 0; }
.alert-body .alert-title { font-size: 13px; font-weight: 600; }
.alert-body .alert-location { font-size: 11.5px; color: var(--text-secondary); margin-top: 2px; }
.alert-time { font-size: 11px; color: var(--text-secondary); white-space: nowrap; }

/* ===================== Charts Row ===================== */
.charts-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 18px;
    margin-bottom: 18px;
}

.chart-wrap { position: relative; height: 240px; }

.env-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-top: 8px;
}
.env-item {
    background: var(--bg-panel-light);
    border-radius: 10px;
    padding: 14px;
    text-align: center;
}
.env-item .env-value { font-size: 19px; font-weight: 800; margin-bottom: 4px; }
.env-item .env-label { font-size: 11px; color: var(--text-secondary); }

.fleet-stats { display: grid; grid-template-columns: repeat(2,1fr); gap: 10px; margin-top: 14px; }
.fleet-stat-box { background: var(--bg-panel-light); border-radius: 10px; padding: 12px; text-align:center; }
.fleet-stat-box .num { font-size: 18px; font-weight: 800; }
.fleet-stat-box .lbl { font-size: 11px; color: var(--text-secondary); margin-top: 2px;}

/* ===================== Table ===================== */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
    text-align: right;
    padding: 12px;
    color: var(--text-secondary);
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    font-size: 12px;
}
.data-table td {
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
}
.data-table tr:hover td { background: var(--bg-panel-light); }

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}
.status-badge.green { background: rgba(33,166,99,.15); color: var(--green); }
.status-badge.yellow { background: rgba(244,179,36,.15); color: var(--yellow); }
.status-badge.red { background: rgba(239,63,58,.15); color: var(--red); }
.status-badge.gray { background: rgba(156,163,175,.15); color: #9CA3AF; }

.progress-bar-track {
    width: 100%;
    height: 6px;
    background: var(--bg-main);
    border-radius: 10px;
    overflow: hidden;
}
.progress-bar-fill { height: 100%; border-radius: 10px; }

/* ===================== Filters/Toolbar ===================== */
.toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}
.toolbar select, .toolbar input {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 9px 14px;
    border-radius: 9px;
    font-size: 13px;
}

.btn {
    padding: 9px 18px;
    border-radius: 9px;
    font-size: 13px;
    font-weight: 600;
    background: var(--green);
    color: #fff;
}
.btn.outline { background: transparent; border: 1px solid var(--border-color); color: var(--text-primary); }

/* ===================== Leaflet popup theme ===================== */
.leaflet-popup-content-wrapper {
    background: var(--bg-panel);
    color: var(--text-primary);
    border-radius: 10px;
    font-family: var(--font-main);
}
.leaflet-popup-tip { background: var(--bg-panel); }
.niksa-bin-marker { background: transparent !important; border: none !important; }
.niksa-truck-marker { background: transparent !important; border: none !important; }
.bin-popup h4 { font-size: 13px; margin-bottom: 8px; }
.bin-popup table { font-size: 12px; width: 100%; }
.bin-popup table td { padding: 3px 0; color: var(--text-secondary); }
.bin-popup table td:last-child { color: var(--text-primary); text-align: left; font-weight: 600; }

/* ===================== Responsive ===================== */
@media (max-width: 1400px) {
    .kpi-grid { grid-template-columns: repeat(3, 1fr); }
    .charts-row { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 1100px) {
    .dashboard-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
    .sidebar { position: fixed; right: -270px; z-index: 100; transition: right .25s; }
    .sidebar.open { right: 0; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .charts-row { grid-template-columns: 1fr; }
}
.mobile-toggle { display: none; }
@media (max-width: 900px) {
    .mobile-toggle { display: flex; }
}
