/* ═══════════════════════════════════════
   Traffic AI — Web Map Dashboard CSS (2GIS Style)
   ═══════════════════════════════════════ */

:root {
  --primary: #5A52FF;
  --primary-hover: #4039CC;
  --bg: #ffffff;
  --bg-panel: #f8fafc;
  --border: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --shadow: 0 4px 12px rgba(0,0,0,0.08);
  
  --traffic-green: #10B981;
  --traffic-yellow: #F59E0B;
  --traffic-red: #EF4444;
}

body.dark-theme {
  --bg: #0f172a;
  --bg-panel: #1e293b;
  --border: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --shadow: 0 4px 12px rgba(0,0,0,0.5);
}

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

body {
  font-family: 'Inter', sans-serif;
  display: flex;
  height: 100vh;
  overflow: hidden;
  color: var(--text-main);
  background: var(--bg);
}

/* ── RAIL MENU (2GIS Style Left Bar) ── */
.rail-menu {
  width: 72px;
  height: 100vh;
  background: white;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0;
  z-index: 1100;
  box-shadow: 2px 0 10px rgba(0,0,0,0.05);
}

.rail-item {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 12px 0;
  color: var(--text-muted);
  cursor: pointer;
  transition: all .2s;
  text-decoration: none;
}
.rail-item:hover { color: var(--primary); background: var(--bg-panel); }
.rail-item.active { color: var(--primary); font-weight: 600; }
.rail-item .icon { font-size: 22px; }
.rail-item .label { font-size: 10px; text-align: center; line-height: 1.1; }
.rail-spacer { flex: 1; }

/* ── SIDEBAR ── */
.sidebar {
  width: 380px;
  height: 100vh;
  background: var(--bg);
  box-shadow: var(--shadow);
  z-index: 1000; /* Above map */
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--border);
}

.back-btn {
  text-decoration: none;
  color: var(--text-muted);
  font-size: 20px;
  padding: 4px;
}
.back-btn:hover { color: var(--primary); }

.logo { font-size: 18px; font-weight: 500; }
.logo strong { font-weight: 800; color: var(--primary); }

.sidebar-search {
  padding: 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
  font-size: 14px;
}
.clear-btn {
  position: absolute;
  right: 12px;
  background: none; border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 4px;
}
.clear-btn:hover { color: var(--traffic-red); }

.sidebar-search input {
  width: 100%;
  padding: 12px 36px 12px 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  background: white;
  transition: all .2s;
}
.sidebar-search input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(90, 82, 255, 0.1);
}

/* Search Results UI */
.search-results-container {
  flex: 1;
  overflow-y: auto;
  background: white;
}
.search-result-item {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  gap: 12px;
  transition: background .2s;
}
.search-result-item:hover { background: var(--bg-panel); }
.sr-icon {
  width: 32px; height: 32px;
  background: rgba(90,82,255,0.1); color: var(--primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 14px;
}
.sr-text h4 { font-size: 14px; margin-bottom: 2px; color: var(--text-main); }
.sr-text p { font-size: 12px; color: var(--text-muted); line-height: 1.4; }

.btn {
  padding: 12px;
  border-radius: 8px;
  border: none;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

/* ── FRIENDS MODAL (2GIS Style) ── */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: flex; align-items: center; justify-content: center;
}

.modal-content {
  background: radial-gradient(circle at top right, #1a202c, #0f172a);
  border-radius: 20px;
  width: 900px;
  max-width: 95%;
  color: white;
  position: relative;
  box-shadow: 0 20px 40px rgba(0,0,0,0.4);
  overflow: hidden;
}

.modal-close {
  position: absolute;
  top: 16px; right: 16px;
  background: rgba(255,255,255,0.1);
  border: none; color: white;
  width: 32px; height: 32px; border-radius: 50%;
  cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  z-index: 10;
  transition: background 0.2s;
}
.modal-close:hover { background: rgba(255,255,255,0.2); }

.modal-inner {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 400px;
}

.modal-text {
  padding: 40px;
}

.modal-title {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 30px;
}

.modal-steps {
  list-style: none;
  display: flex; flex-direction: column; gap: 24px;
}

.modal-steps li {
  display: flex; gap: 16px;
}

.step-num {
  width: 24px; height: 24px; min-width: 24px;
  background: white; color: black;
  border-radius: 50%; font-weight: 800; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
}

.step-info strong {
  display: block; font-size: 15px; margin-bottom: 4px;
}
.step-info p {
  font-size: 13px; color: #94a3b8; line-height: 1.5; margin-bottom: 12px;
}
.qr-code {
  width: 120px; height: 120px;
  background: white; padding: 8px; border-radius: 12px;
}

.modal-graphics {
  position: relative;
  background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%"><line x1="0" y1="50" x2="100" y2="150" stroke="rgba(255,255,255,0.2)" stroke-width="2"/><line x1="100" y1="150" x2="300" y2="150" stroke="rgba(255,255,255,0.2)" stroke-width="2"/></svg>');
  display: flex; align-items: center; justify-content: center;
}

.big-plus {
  font-size: 180px; font-weight: 900;
  color: white; line-height: 1;
  text-shadow: 0 10px 30px rgba(0,0,0,0.5), -2px -2px 0 #7e22ce, 2px 2px 0 #10b981;
  position: relative; z-index: 2;
}

.avatar-circle {
  width: 60px; height: 60px; border-radius: 50%;
  border: 3px solid white; position: absolute; z-index: 3;
  overflow: hidden; box-shadow: 0 10px 20px rgba(0,0,0,0.3);
}
.avatar-circle img { width: 100%; height: 100%; object-fit: cover; }
.a1 { bottom: 60px; left: 40px; }
.a2 { bottom: 40px; right: 60px; border-color: var(--primary); }

.btn-search {
  background: var(--text-main);
  color: white;
}
.btn-search:hover { background: #000; }

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-hover); }

.w-100 { width: 100%; }
.mt-3 { margin-top: 16px; }

/* ── TABS ── */
.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.tab {
  flex: 1;
  text-align: center;
  padding: 14px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ── PANEL CONTENT ── */
.panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.status-card, .action-card, .ai-controls {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}

.status-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px;
}
.status-header h3 { font-size: 15px; }

.status-badge {
  font-size: 10px; font-weight: 800;
  padding: 4px 8px; border-radius: 4px;
}
.status-badge.live { background: rgba(239, 68, 68, 0.1); color: var(--traffic-red); }

.traffic-index { display: flex; gap: 16px; align-items: center; }
.index-score {
  width: 50px; height: 50px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 800;
  background: #f1f5f9; color: #94a3b8; /* Default */
}
.index-text { display: flex; flex-direction: column; gap: 4px; }
.index-text strong { font-size: 14px; }
.index-text span { font-size: 13px; color: var(--text-muted); }

.mode-toggles { display: flex; gap: 8px; margin-top: 12px; }
.mode-btn {
  flex: 1; padding: 10px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.mode-btn.active {
  background: rgba(90, 82, 255, 0.1);
  border-color: var(--primary);
  color: var(--primary);
}

/* AI Panel */
.ai-controls h3 { font-size: 15px; margin-bottom: 8px; }
.ai-controls p { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; line-height: 1.5; }

.time-slider-container {
  padding: 10px 0;
}
.time-labels {
  display: flex; justify-content: space-between;
  font-size: 12px; color: var(--text-muted); font-weight: 600;
  margin-bottom: 8px;
}
input[type=range] { width: 100%; cursor: pointer; }
.horizon-value {
  text-align: center; font-size: 14px; font-weight: 700; color: var(--primary);
  margin-top: 8px;
}

.ar-points-list { display: flex; flex-direction: column; gap: 12px; }
.ar-point-card {
  padding: 12px; border-radius: 8px; border: 1px solid var(--border);
  font-size: 13px; cursor: pointer; transition: all .2s;
}
.ar-point-card:hover { border-color: var(--primary); background: var(--bg-panel); }
.ar-point-card strong { display: block; margin-bottom: 4px; font-size: 14px;}
.ar-point-card .desc { color: var(--text-muted); margin-bottom: 8px; }
.ar-point-card.critical { border-left: 4px solid var(--traffic-red); }
.ar-point-card.warning { border-left: 4px solid var(--traffic-yellow); }

/* ── MAP AREA ── */
.map-container {
  flex: 1;
  position: relative;
}
#map {
  width: 100%;
  height: 100%;
  background: #e5e7eb;
}

/* Map UI */
.map-controls-right {
  position: absolute;
  top: 20px; right: 20px;
  z-index: 1000;
  display: flex; flex-direction: column; gap: 12px;
}
.zoom-controls {
  display: flex; flex-direction: column;
  background: white; border-radius: 8px; box-shadow: var(--shadow);
  overflow: hidden;
}
.map-btn {
  width: 40px; height: 40px;
  background: white; border: none;
  font-size: 18px; color: var(--text-main);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.map-btn:hover { background: #f1f5f9; }
#btn-location { border-radius: 8px; box-shadow: var(--shadow); }
.zoom-controls .map-btn:first-child { border-bottom: 1px solid var(--border); }

.map-legend {
  position: absolute;
  bottom: 24px; right: 24px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 1000;
  display: flex; flex-direction: column; gap: 8px;
}
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 500;}
.color-box { width: 12px; height: 12px; border-radius: 3px; }

/* Custom Map Tooltip */
.custom-tooltip {
  background: rgba(15, 23, 42, 0.9);
  color: white;
  border: none;
  border-radius: 4px;
  padding: 4px 8px;
  font-weight: 600;
  font-size: 12px;
}
.custom-tooltip::before { border-top-color: rgba(15, 23, 42, 0.9); }

/* ── MOBILE RESPONSIVENESS (Смарфондарға бейімделу) ── */
@media (max-width: 768px) {
  body {
    flex-direction: column;
  }

  /* Rail menu becomes a top horizontal navigation bar */
  .rail-menu {
    width: 100%;
    height: 65px;
    flex-direction: row;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 0 10px;
    overflow-x: auto;
    z-index: 1200;
    order: 1;
  }
  
  .rail-item {
    width: auto;
    padding: 0 16px;
    height: 100%;
  }
  
  .rail-spacer { display: none; } /* Hide spacer on mobile */

  /* Map container gets the middle flexible space */
  .map-container {
    width: 100%;
    flex: 1;
    order: 2;
  }

  /* Sidebar becomes a bottom sheet (45% of height) */
  .sidebar {
    width: 100%;
    height: 45vh;
    border-right: none;
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 12px rgba(0,0,0,0.1);
    order: 3;
    z-index: 1200;
  }

  /* Hide legend on mobile to save map space */
  .map-legend {
    display: none;
  }
  
  .map-controls-right {
    top: 10px; right: 10px;
  }
}
