/* ============================================
   銀巷食光 — 送餐即時地圖 設計系統
   FoodMap Visual Design System
   ============================================ */

:root {
  /* === 主色系：暖橙 === */
  --primary: #E8722A;
  --primary-dark: #C45A1A;
  --primary-light: #F5A66B;
  --primary-bg: #FEF3EB;

  /* === 輔助色：暖綠 === */
  --success: #5B9A3C;
  --success-light: #E8F5E0;
  --success-dark: #3D7A22;

  /* === 功能色 === */
  --warning: #F0AD4E;
  --warning-bg: #FFF8E7;
  --danger: #D94452;
  --danger-light: #FDECEE;
  --info: #4A8DB7;
  --info-light: #E8F2F8;

  /* === 中性色 === */
  --gray-900: #2D2A26;
  --gray-700: #5C5650;
  --gray-500: #8A837B;
  --gray-300: #C4BDB5;
  --gray-100: #F0EDE9;
  --white: #FFFDFB;

  /* === 地圖標記色（色弱友善：以色溫＋明度區分，避免純紅綠對比） === */
  --marker-delivering: #E8722A;
  --marker-delivered: #0097A7;  /* 青碧：色弱者看到「藍」，與待送餐「黃」最大對比 */
  --marker-pending: #E68A00;    /* 深琥珀：色弱者看到「黃」，與已送達「藍」最大對比 */
  --marker-alert: #D94452;

  /* === 字型 === */
  --font-display: 'Zen Maru Gothic', 'Noto Sans TC', sans-serif;
  --font-body: 'Noto Sans TC', sans-serif;

  /* === 圓角 === */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
}

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

body {
  font-family: var(--font-body);
  background: var(--gray-100) !important;
  color: var(--gray-900);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ============================================
   Dashboard 佈局
   ============================================ */
.dashboard {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* --- 頂部導航列 --- */
.dash-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--white);
  border-bottom: 1px solid var(--gray-100);
  z-index: 100;
  flex-shrink: 0;
}
.dash-nav .logo-area {
  display: flex;
  align-items: center;
  gap: 12px;
}
.dash-nav .logo-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.2rem;
  font-weight: 900;
  font-family: var(--font-display);
  flex-shrink: 0;
}
.dash-nav .logo-text {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--gray-900);
}
.dash-nav .logo-text small {
  display: block;
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--gray-500);
}
.dash-nav .nav-center {
  display: flex;
  align-items: center;
  gap: 12px;
}
.dash-nav .nav-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* 即時狀態徽章 */
.nav-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 20px;
  background: var(--success-light);
  color: var(--success-dark);
  font-size: 0.78rem;
  font-weight: 500;
}
.nav-badge .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* 日期選擇 */
.nav-date {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  background: var(--primary-bg);
  color: var(--primary-dark);
  font-size: 0.85rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  font-family: var(--font-body);
}
.nav-date input[type="date"] {
  border: none;
  background: transparent;
  color: var(--primary-dark);
  font-size: 0.85rem;
  font-weight: 500;
  font-family: var(--font-body);
  cursor: pointer;
  outline: none;
}

/* 漢堡選單按鈕 */
.dash-nav .menu-toggle {
  background: none;
  border: none;
  color: var(--gray-700);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.dash-nav .menu-toggle:hover {
  background: var(--gray-100);
}

/* 導航列統計數字 */
.nav-stat {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 20px;
  background: var(--gray-100);
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--gray-700);
}
.nav-stat-icon {
  font-size: 0.9rem;
}

/* 載入中 */
.nav-loading {
  font-size: 0.8rem;
  color: var(--gray-500);
  animation: pulse 1.5s infinite;
}

/* 補助機構 */
.nav-funding {
  display: flex;
  align-items: center;
  gap: 6px;
}
.nav-funding img {
  height: 24px;
  width: auto;
  opacity: 0.7;
}

/* --- Dashboard 主體 --- */
.dash-body {
  display: grid;
  grid-template-columns: 150px 1fr;
  flex: 1;
  overflow: hidden;
}

/* --- 左側面板 --- */
.dash-sidebar {
  background: var(--white) !important;
  border-right: 1px solid var(--gray-100);
  padding: 12px;
  display: flex !important;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  /* 覆寫 style.css 的 aside 舊規則 */
  position: static !important;
  transform: none !important;
  width: auto !important;
  z-index: auto !important;
  min-height: auto !important;
  height: auto !important;
  color: var(--gray-900) !important;
  transition: none !important;
}

/* 統計卡片 */
.stat-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.stat-card {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  position: relative;
}
.stat-card.orange { background: var(--primary-bg); }
.stat-card.green { background: var(--success-light); }
.stat-card.blue { background: var(--info-light); }
.stat-card.yellow { background: var(--warning-bg); }
.stat-card .stat-label {
  font-size: 0.72rem;
  color: var(--gray-500);
  font-weight: 500;
  margin-bottom: 4px;
}
.stat-card .stat-value {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
}
.stat-card.orange .stat-value { color: var(--primary-dark); }
.stat-card.green .stat-value { color: var(--success-dark); }
.stat-card.blue .stat-value { color: var(--info); }
.stat-card.yellow .stat-value { color: #B8860B; }
.stat-card .stat-unit {
  font-size: 0.7rem;
  color: var(--gray-500);
  font-weight: 400;
}

/* 送餐員列表 */
.driver-count {
  font-size: 0.72rem;
  color: var(--gray-500);
  font-weight: 400;
}
.driver-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  flex: 1;
}
.driver-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--gray-100);
  cursor: pointer;
  transition: all 0.15s;
}
.driver-item:hover {
  background: var(--primary-bg);
  box-shadow: 0 2px 8px rgba(232, 114, 42, 0.12);
}
.driver-item.active {
  background: var(--primary-bg);
  border-left: 3px solid var(--primary);
}
.driver-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
  background: var(--primary);
}
.driver-info {
  flex: 1;
  min-width: 0;
}
.driver-info .driver-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--gray-900);
}
.driver-info .driver-meta {
  font-size: 0.68rem;
  color: var(--gray-500);
  display: flex;
  gap: 8px;
  margin-top: 2px;
}
.driver-status {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.65rem;
  font-weight: 600;
  white-space: nowrap;
}
.driver-status.delivering {
  background: var(--primary-bg);
  color: var(--primary-dark);
}
.driver-status.done {
  background: var(--success-light);
  color: var(--success-dark);
}
.driver-status.idle {
  background: var(--gray-100);
  color: var(--gray-500);
}

/* --- 地圖區域 --- */
.dash-map {
  position: relative;
  overflow: hidden;
}
.dash-map #mapid {
  width: 100% !important;
  height: 100% !important;
  z-index: 1;
  border: none !important;
}

/* 地圖圖例 */
.map-legend {
  position: absolute;
  bottom: 16px;
  left: 16px;
  background: white;
  border-radius: var(--radius-md);
  padding: 12px 16px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 20;
}
.map-legend .legend-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--gray-700);
  margin-bottom: 2px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.72rem;
  color: var(--gray-700);
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* 地圖覆蓋統計 — 避開右上角 Leaflet 圖層控制 */
.map-overlay-stats {
  position: absolute;
  top: 70px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 20;
}
.overlay-stat {
  background: white;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.1);
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 140px;
}
.overlay-stat-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
}
.overlay-stat-icon.km { background: var(--info-light); }
.overlay-stat-icon.co2 { background: var(--success-light); }
.overlay-stat-text .ov-value {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--gray-900);
}
.overlay-stat-text .ov-label {
  font-size: 0.65rem;
  color: var(--gray-500);
}

/* 國科會標誌 */
.funding-badge {
  position: absolute;
  bottom: 16px;
  right: 16px;
  background: white;
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 20;
  font-size: 0.65rem;
  color: var(--gray-500);
}
.funding-badge img {
  height: 22px;
  width: auto;
}

/* ============================================
   自訂地圖標記
   ============================================ */
.marker-pin {
  width: 18px;
  height: 23px;
  position: relative;
}
.marker-pin .pin-head {
  width: 18px;
  height: 18px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid white;
  outline: 1px solid rgba(0,0,0,0.25);
}
.marker-pin .pin-head span {
  transform: rotate(45deg);
  font-size: 0.43rem;
  font-weight: 700;
  color: white;
}
.marker-pin.delivering .pin-head { background: var(--marker-delivering); box-shadow: 0 2px 8px rgba(232,114,42,0.4); }
.marker-pin.delivered .pin-head { background: var(--marker-delivered); box-shadow: 0 2px 8px rgba(0,151,167,0.4); }
.marker-pin.pending .pin-head { background: var(--marker-pending); box-shadow: 0 2px 8px rgba(230,138,0,0.4); }
.marker-pin.alert .pin-head { background: var(--marker-alert); box-shadow: 0 2px 8px rgba(217,68,82,0.4); }
.marker-pin.home .pin-head { background: var(--info); box-shadow: 0 2px 8px rgba(74,141,183,0.3); }

/* 多人同住 — 圓角方塊 */
.marker-pin.multi {
  width: 23px;
  height: 23px;
}
.marker-pin.multi .pin-head {
  width: 23px;
  height: 23px;
  border-radius: 4px;
  transform: none;
}
.marker-pin.multi .pin-head span {
  transform: none;
  font-size: 0.58rem;
}

/* 車輛標記 */
.car-marker-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================
   按鈕元件
   ============================================ */
.btn-primary {
  background: var(--primary) !important;
  border-color: var(--primary) !important;
  color: white !important;
}
.btn-primary:hover {
  background: var(--primary-dark) !important;
  border-color: var(--primary-dark) !important;
}
.btn-success {
  background: var(--success) !important;
  border-color: var(--success) !important;
}
.btn-warning {
  background: var(--warning) !important;
  border-color: var(--warning) !important;
}
.btn-info {
  background: var(--info) !important;
  border-color: var(--info) !important;
  color: white !important;
}

/* ============================================
   Leaflet Popup 美化
   ============================================ */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius-md) !important;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12) !important;
  font-family: var(--font-body) !important;
}
.leaflet-popup-content {
  font-size: 0.85rem !important;
  line-height: 1.6 !important;
  color: var(--gray-900) !important;
}
.leaflet-popup-content h6 {
  font-family: var(--font-display) !important;
  font-weight: 600 !important;
  margin-bottom: 4px !important;
}

/* --- 送餐員 Popup --- */
.driver-popup { min-width: 200px; }
.dp-header {
  font-size: 1rem;
  font-weight: 700;
  padding-bottom: 6px;
  margin-bottom: 6px;
  border-bottom: 1px solid #eee;
}
.dp-route {
  font-size: 0.8rem;
  font-weight: 400;
  color: #888;
  margin-left: 6px;
}
.dp-body { margin-bottom: 8px; }
.dp-row {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
  font-size: 0.85rem;
}
.dp-label { color: #888; }
.dp-val { font-weight: 600; }
.dp-coord .dp-val { font-size: 0.75rem; font-weight: 400; color: #aaa; }
.dp-actions {
  display: flex;
  gap: 6px;
}
.dp-btn {
  flex: 1;
  border: none;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
}
.dp-btn i { margin-right: 3px; }
.dp-btn-info { background: #FFA726; color: #fff; }
.dp-btn-info:hover { background: #FB8C00; }
.dp-btn-trace { background: #29B6F6; color: #fff; }
.dp-btn-trace:hover { background: #039BE5; }
.dp-btn-stop { background: #EF5350; color: #fff; }
.dp-btn-stop:hover { background: #E53935; }

/* ============================================
   側邊欄覆寫（亮色主題）
   ============================================ */
aside {
  background-color: var(--white) !important;
  box-shadow: 4px 0 16px rgba(0,0,0,0.08);
}
#sidebar ul li a {
  color: var(--gray-700) !important;
}
#sidebar ul li a:hover {
  color: var(--primary-dark) !important;
  background: var(--primary-bg) !important;
}
#sidebarCollapse {
  background-color: transparent !important;
  color: var(--gray-700) !important;
}

/* ============================================
   頁尾
   ============================================ */
.dash-footer {
  text-align: center;
  padding: 8px 24px;
  color: var(--gray-500);
  font-size: 0.7rem;
  background: var(--white);
  border-top: 1px solid var(--gray-100);
  flex-shrink: 0;
}

/* ============================================
   RWD 響應式
   ============================================ */
@media (max-width: 768px) {
  .dash-body {
    grid-template-columns: 1fr;
  }
  .dash-sidebar {
    max-height: 280px;
    border-right: none;
    border-bottom: 1px solid var(--gray-100);
  }
  .dash-map {
    min-height: 400px;
  }
  .dash-nav {
    padding: 8px 12px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .dash-nav .logo-text {
    font-size: 0.95rem;
  }
  .dash-nav .logo-text small {
    display: none;
  }
  .nav-funding {
    display: none;
  }
  .map-overlay-stats {
    top: 8px;
    right: 8px;
  }
  .overlay-stat {
    min-width: 120px;
    padding: 8px 10px;
  }
}

/* ============================================
   其他頁面共用（info, introduce 等）
   ============================================ */
.page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: var(--white);
  border-bottom: 1px solid var(--gray-100);
}
.page-header h5 {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--gray-900);
  margin: 0;
}
.page-content {
  padding: 20px;
}

/* Tabulator 覆寫 */
.tabulator {
  border: 1px solid var(--gray-300) !important;
  border-radius: var(--radius-sm) !important;
  font-family: var(--font-body) !important;
}
.tabulator .tabulator-header {
  background: var(--gray-100) !important;
  border-bottom: 2px solid var(--gray-300) !important;
}
.tabulator .tabulator-header .tabulator-col {
  background: var(--gray-100) !important;
}
