/* ===================================================
   TARIQI - West Bank Road Intelligence
   Design System
   =================================================== */

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

:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-card: #1a2234;
  --bg-hover: #1e293b;
  --border: rgba(255,255,255,0.06);
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-red: #ef4444;
  --accent-green: #22c55e;
  --accent-amber: #f59e0b;
  --accent-purple: #8b5cf6;
  --accent-blue: #3b82f6;
  --radius: 12px;
  --radius-sm: 8px;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

html { scroll-behavior: smooth; }
body {
  font-family: 'Tajawal', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
}

/* --- LAYOUT --- */
.app {
  display: grid;
  grid-template-columns: 380px 1fr;
  grid-template-rows: auto 1fr;
  height: 100vh;
  height: 100dvh;
}

/* --- HEADER --- */
.header {
  grid-column: 1 / -1;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 50;
}
.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.header-logo {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--accent-red), var(--accent-amber));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 1.1rem; color: white;
}
.header-title {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}
.header-subtitle {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 1px;
}
.header-actions {
  display: flex; align-items: center; gap: 8px;
}
.header-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}
.header-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.live-indicator {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.78rem; color: var(--accent-green);
  font-weight: 600;
}
.live-dot {
  width: 8px; height: 8px;
  background: var(--accent-green);
  border-radius: 50%;
  animation: pulse-live 2s ease-in-out infinite;
}
@keyframes pulse-live {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(34,197,94,0.4); }
  50% { opacity: 0.7; box-shadow: 0 0 0 6px rgba(34,197,94,0); }
}

/* --- SIDEBAR --- */
.sidebar {
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Stats Row */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  text-align: center;
}
.stat-card .num {
  font-size: 1.4rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.stat-card .lbl {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 2px;
  font-weight: 500;
}

/* Filter Pills */
.filter-row {
  display: flex;
  gap: 6px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.filter-row::-webkit-scrollbar { display: none; }
.filter-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 5px 14px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s var(--ease), color 0.2s var(--ease), border-color 0.2s var(--ease);
}
.filter-btn:hover { border-color: var(--text-muted); color: var(--text-primary); }
.filter-btn.active {
  background: var(--accent-red);
  border-color: var(--accent-red);
  color: white;
}

/* Feed Section */
.feed-section {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.feed-header {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.feed-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
}
.feed-count {
  font-size: 0.72rem;
  color: var(--text-muted);
  background: var(--bg-card);
  padding: 2px 8px;
  border-radius: 4px;
}
.feed-list {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-card) transparent;
}
.feed-list::-webkit-scrollbar { width: 4px; }
.feed-list::-webkit-scrollbar-track { background: transparent; }
.feed-list::-webkit-scrollbar-thumb { background: var(--bg-card); border-radius: 2px; }

/* Feed Items */
.feed-item {
  display: flex;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s var(--ease);
}
.feed-item:hover { background: var(--bg-hover); }
.feed-flash { animation: flash-bg 1.5s ease; }
@keyframes flash-bg {
  0% { background: rgba(245,158,11,0.15); }
  100% { background: transparent; }
}
.feed-indicator {
  width: 3px;
  border-radius: 2px;
  flex-shrink: 0;
  align-self: stretch;
}
.feed-content { flex: 1; min-width: 0; }
.feed-item .feed-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  border: none;
  margin-bottom: 4px;
}
.feed-platform {
  background: var(--bg-card);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}
.feed-channel {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
}
.feed-time {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-right: auto;
  font-variant-numeric: tabular-nums;
}
[dir="ltr"] .feed-time { margin-right: 0; margin-left: auto; }
.feed-text {
  font-size: 0.82rem;
  color: var(--text-primary);
  line-height: 1.6;
  margin-bottom: 6px;
}
.feed-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.72rem;
}
.feed-confidence { font-weight: 700; }
.feed-location { color: var(--text-muted); }

/* --- MAP AREA --- */
.map-area {
  position: relative;
  overflow: hidden;
}
#map {
  width: 100%;
  height: 100%;
}

/* Leaflet overrides */
.leaflet-container { background: var(--bg-primary); }
.leaflet-control-zoom a {
  background: var(--bg-card) !important;
  color: var(--text-primary) !important;
  border-color: var(--border) !important;
}
.leaflet-control-zoom a:hover { background: var(--bg-hover) !important; }
.leaflet-control-attribution {
  background: rgba(10,14,23,0.8) !important;
  color: var(--text-muted) !important;
  font-size: 0.6rem !important;
}
.leaflet-control-attribution a { color: var(--text-secondary) !important; }

/* Custom Markers */
.custom-marker { background: none !important; border: none !important; }
.marker-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.marker-dot {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 12px rgba(0,0,0,0.4), 0 0 20px var(--marker-color, #fff) 20;
  border: 2px solid rgba(255,255,255,0.2);
}
.marker-dot svg {
  width: 50%;
  height: 50%;
}
.marker-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--bg-primary);
  color: white;
  font-size: 0.6rem;
  font-weight: 800;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--marker-color);
}
[dir="ltr"] .marker-badge { right: auto; left: -4px; }

.marker-pulse .marker-dot {
  animation: marker-pulse-anim 2s ease-in-out infinite;
}
@keyframes marker-pulse-anim {
  0%, 100% { box-shadow: 0 2px 12px rgba(0,0,0,0.4); }
  50% { box-shadow: 0 2px 12px rgba(0,0,0,0.4), 0 0 24px var(--marker-color); }
}

/* --- DETAIL PANEL --- */
.detail-panel {
  position: absolute;
  bottom: 20px;
  left: 20px;
  right: 20px;
  max-width: 420px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  z-index: 40;
  transform: translateY(calc(100% + 40px));
  transition: transform 0.3s var(--ease);
  backdrop-filter: blur(12px);
}
[dir="ltr"] .detail-panel { left: 20px; right: auto; }
.detail-panel.show { transform: translateY(0); }

.detail-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.detail-status {
  padding: 3px 10px;
  border-radius: 5px;
  font-size: 0.75rem;
  font-weight: 700;
}
.detail-type {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
}
.detail-close {
  margin-right: auto;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: color 0.2s, background 0.2s;
}
[dir="ltr"] .detail-close { margin-right: 0; margin-left: auto; }
.detail-close:hover { color: var(--text-primary); background: var(--bg-card); }
.detail-title {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 2px;
}
.detail-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 10px;
  direction: ltr;
  text-align: right;
}
[dir="ltr"] .detail-subtitle { text-align: left; }
.detail-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 10px;
}
.detail-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.meta-label { color: var(--text-secondary); font-weight: 600; }
.detail-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.detail-stat {
  background: var(--bg-card);
  padding: 10px;
  border-radius: var(--radius-sm);
  text-align: center;
}
.detail-stat .stat-value {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.detail-stat .stat-key {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 2px;
}
.confidence-bar {
  height: 3px;
  background: var(--bg-card);
  border-radius: 2px;
  overflow: hidden;
}
.confidence-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.5s var(--ease);
}

/* --- MAP LEGEND --- */
.map-legend {
  position: absolute;
  top: 16px;
  left: 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  z-index: 30;
  backdrop-filter: blur(8px);
}
[dir="ltr"] .map-legend { left: auto; right: 16px; }
.legend-title {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 6px;
}
.legend-items { display: flex; flex-direction: column; gap: 4px; }
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.72rem;
  color: var(--text-secondary);
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* --- MOBILE TOGGLE --- */
.mobile-sidebar-toggle {
  display: none;
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 60;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  width: 42px; height: 42px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  align-items: center; justify-content: center;
}
[dir="ltr"] .mobile-sidebar-toggle { right: auto; left: 12px; }

/* --- RESPONSIVE --- */
@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }
  .sidebar {
    grid-row: 3;
    max-height: 45vh;
    border-left: none;
    border-top: 1px solid var(--border);
    transition: max-height 0.3s var(--ease);
  }
  .sidebar.collapsed { max-height: 110px; }
  .mobile-sidebar-toggle { display: flex; }
  .map-area { grid-row: 2; }
  .detail-panel { max-width: none; bottom: 46vh; left: 10px; right: 10px; }
  .sidebar.collapsed ~ .map-area .detail-panel { bottom: 130px; }
  .stats-row { grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 10px 12px; }
  .stat-card .num { font-size: 1.1rem; }
  .header-subtitle { display: none; }
  .map-legend { top: 8px; left: 8px; padding: 8px 10px; }
  [dir="ltr"] .map-legend { left: auto; right: 8px; }
}

@media (max-width: 480px) {
  .header { padding: 8px 12px; }
  .header-title { font-size: 1rem; }
  .filter-row { padding: 8px 12px; gap: 4px; }
  .filter-btn { padding: 4px 10px; font-size: 0.7rem; }
}

/* --- FOCUS --- */
:focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: 2px;
  border-radius: 4px;
}
button:focus:not(:focus-visible) { outline: none; }