/* ============================================================
   Bihar Pathology Tool - Modern Clinical UI
   ============================================================ */

:root {
  --bg-color: #f4f7f9;
  --panel-bg: #ffffff;
  --text-main: #1e293b;
  --text-sub: #64748b;
  --border-color: #e2e8f0;
  --accent-blue: #0284c7;
  --accent-purple: #7c3aed;
  --accent-red: #dc2626;
  --accent-green: #16a34a;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.05);
  --input-bg: #ffffff;
  --table-header-bg: #f8fafc;
  --table-row-hover: #f1f5f9;
  --table-row-selected: #e0f2fe;
}

[data-theme="dark"] {
  --bg-color: #0f172a; 
  --panel-bg: #1e293b; 
  --text-main: #f8fafc; 
  --text-sub: #94a3b8; 
  --border-color: #334155; 
  --accent-blue: #38bdf8;
  --accent-purple: #a78bfa;
  --accent-red: #f87171;
  --accent-green: #4ade80;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.5);
  --input-bg: #0f172a;
  --table-header-bg: #1e293b;
  --table-row-hover: #334155;
  --table-row-selected: #0c4a6e;
}

* { box-sizing: border-box; margin: 0; padding: 0; transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease; }
body { font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif; background: var(--bg-color); color: var(--text-main); padding: 24px; line-height: 1.5; }

.container { max-width: 1400px; margin: 0 auto; background: var(--panel-bg); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 32px; border: 1px solid var(--border-color); }

/* Header */
.app-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 32px; padding-bottom: 20px; border-bottom: 1px solid var(--border-color); }
.brand { display: flex; align-items: center; gap: 16px; }
.logo { font-size: 32px; background: var(--table-row-selected); padding: 8px; border-radius: 12px; }
h1 { font-size: 24px; font-weight: 700; color: var(--text-main); letter-spacing: -0.5px; }
.subtitle { font-size: 14px; color: var(--text-sub); margin-top: 2px; }
.theme-toggle { background: var(--table-header-bg); border: 1px solid var(--border-color); color: var(--text-main); padding: 8px 16px; border-radius: 20px; cursor: pointer; font-weight: 600; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.theme-toggle:hover { background: var(--border-color); }

/* Global Search */
.global-search-wrap { position: relative; margin-bottom: 24px; }
.global-search-wrap label { display: block; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--accent-blue); margin-bottom: 8px; }
#globalSearch { width: 100%; padding: 16px 16px 16px 46px; font-size: 16px; border: 2px solid var(--border-color); border-radius: 12px; background: var(--input-bg) url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="%230284c7" stroke-width="2"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg>') no-repeat 16px center; background-size: 20px; outline: none; color: var(--text-main); transition: all 0.2s; }
#globalSearch:focus { border-color: var(--accent-blue); box-shadow: 0 0 0 4px rgba(2, 132, 199, 0.1); }
#globalResults { position: absolute; top: 100%; left: 0; right: 0; background: var(--panel-bg); border: 1px solid var(--border-color); border-radius: 0 0 12px 12px; max-height: 400px; overflow-y: auto; z-index: 1000; display: none; box-shadow: var(--shadow-lg); margin-top: -2px; }
#globalResults.show { display: block; }
.result-item { padding: 12px 16px; cursor: pointer; border-bottom: 1px solid var(--border-color); }
.result-item:last-child { border-bottom: none; }
.result-item:hover, .result-item.active { background: var(--table-row-hover); }
.ri-name { font-weight: 600; color: var(--text-main); font-size: 14px; }
.ri-meta { font-size: 12px; color: var(--text-sub); margin-top: 4px; }
.ri-type { display: inline-block; background: var(--table-row-selected); color: var(--accent-blue); font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 4px; margin-right: 8px; text-transform: uppercase; }
.no-results { padding: 20px; color: var(--text-sub); text-align: center; font-size: 14px; }

/* Form Grid */
.grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.full { display: block; margin-bottom: 16px; }
label { display: block; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-sub); margin-bottom: 6px; }
select { width: 100%; padding: 12px 16px; font-size: 14px; border: 1px solid var(--border-color); border-radius: 10px; background: var(--input-bg); color: var(--text-main); outline: none; transition: border-color 0.2s; }
select:focus { 
  border-color: var(--accent-blue); 
  outline: 2px solid var(--accent-blue); 
  outline-offset: 2px; 
  box-shadow: none; 
}
select:disabled { background: var(--bg-color); color: var(--text-sub); cursor: not-allowed; }
.hint { font-size: 12px; color: var(--text-sub); margin-top: 6px; }

/* Summary */
#districtSummary { display: none; background: var(--table-row-selected); border-left: 4px solid var(--accent-blue); border-radius: 12px; padding: 20px; margin-bottom: 24px; }
#districtSummary.show { display: block; }
.ds-title { font-size: 16px; font-weight: 700; color: var(--text-main); margin-bottom: 12px; }
.ds-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.ds-stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-sub); font-weight: 600; }
.ds-stat-value { font-size: 20px; font-weight: 700; color: var(--accent-blue); margin-top: 4px; }
.ds-extra { font-size: 13px; color: var(--text-sub); margin-top: 12px; }

/* Layout */
.layout { display: grid; grid-template-columns: 480px 1fr; gap: 32px; margin-top: 32px; }
@media (max-width: 1100px) { .layout { grid-template-columns: 1fr; } }
.panel { background: var(--bg-color); border-radius: 16px; padding: 24px; min-height: 500px; border: 1px solid var(--border-color); }

/* Modern Tabs */
.tabs { display: flex; overflow-x: auto; gap: 4px; margin-bottom: 24px; border-bottom: 2px solid var(--border-color); padding-bottom: 4px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { padding: 10px 18px; font-size: 13px; font-weight: 600; color: var(--text-sub); cursor: pointer; border: none; background: none; border-bottom: 3px solid transparent; margin-bottom: -4px; transition: all 0.2s ease; white-space: nowrap; border-radius: 6px 6px 0 0; }
.tab:hover { color: var(--accent-blue); background: var(--table-row-hover); }
.tab.active { color: var(--accent-blue); border-bottom-color: var(--accent-blue); background: var(--table-row-selected); }

/* --- NEW MODERN DETAILS SECTION --- */

/* Selected Spoke */
.result-headline { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-sub); margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
#spokeTitle { font-size: 18px; font-weight: 700; color: var(--text-main); line-height: 1.3; }

/* Distance Card */
.distance-card {
  background: linear-gradient(135deg, var(--panel-bg) 0%, var(--table-row-hover) 100%);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 24px;
  margin: 20px 0;
  box-shadow: var(--shadow-sm);
  text-align: center;
  position: relative;
  overflow: hidden;
}
.distance-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; height: 4px;
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-purple));
}
.distance-card .label { font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--text-sub); letter-spacing: 1px; margin-bottom: 8px; }
.distance-card .value { font-size: 48px; font-weight: 800; color: var(--text-main); line-height: 1; letter-spacing: -2px; }
.distance-card .unit { font-size: 18px; font-weight: 600; color: var(--text-sub); margin-left: 4px; }
.disclaimer { font-size: 11px; color: var(--text-sub); margin-top: 12px; font-style: italic; opacity: 0.8; }

/* Action Buttons */
.btn-row { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.btn { flex: 1; min-width: 140px; padding: 12px 20px; font-size: 14px; font-weight: 600; border-radius: 10px; cursor: pointer; text-align: center; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; transition: all 0.2s; }
.btn-google { background: var(--panel-bg); color: var(--text-main); border-color: var(--border-color); box-shadow: var(--shadow-sm); }
.btn-google:hover { background: var(--table-row-hover); border-color: var(--accent-blue); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-primary { background: var(--accent-purple); color: #fff; border-color: var(--accent-purple); box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: #6d28d9; border-color: #6d28d9; transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* Modern Hub List */
.nearby-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-sub); margin-bottom: 12px; display: flex; align-items: center; gap: 6px; }
.hub-item-modern {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  background: var(--panel-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
}
.hub-item-modern:hover {
  border-color: var(--accent-blue);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.hub-item-modern.assigned {
  border-color: var(--accent-green);
  background: rgba(22, 163, 74, 0.05);
}
[data-theme="dark"] .hub-item-modern.assigned {
  background: rgba(74, 222, 128, 0.1);
}
.hub-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.hub-name-modern {
  font-weight: 600;
  font-size: 15px;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}
.assigned-badge {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  background: var(--accent-green);
  color: white;
  padding: 2px 8px;
  border-radius: 20px;
  letter-spacing: 0.5px;
}
.hub-distance-badge {
  font-weight: 700;
  font-size: 14px;
  color: var(--accent-blue);
  background: var(--table-row-selected);
  padding: 4px 12px;
  border-radius: 20px;
  white-space: nowrap;
}
.hub-bar-bg {
  height: 6px;
  background: var(--border-color);
  border-radius: 3px;
  width: 100%;
  overflow: hidden;
}
.hub-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-purple));
  border-radius: 3px;
  transition: width 0.5s ease-out;
}

/* --- END MODERN DETAILS SECTION --- */

/* Table */
.bulk-table-wrap { overflow-x: auto; margin: 0 -8px; border-radius: 12px; border: 1px solid var(--border-color); }
.bulk-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.bulk-table th { background: var(--table-header-bg); color: var(--text-sub); padding: 12px 16px; text-align: left; font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; cursor: pointer; user-select: none; white-space: nowrap; border-bottom: 1px solid var(--border-color); }
.bulk-table th:hover { background: var(--border-color); color: var(--text-main); }
.bulk-table th .sort-arrow { font-size: 10px; color: var(--text-sub); margin-left: 4px; }
.bulk-table th.sorted .sort-arrow { color: var(--accent-blue); }
.bulk-table td { padding: 12px 16px; border-bottom: 1px solid var(--border-color); color: var(--text-main); }
.bulk-table tr:last-child td { border-bottom: none; }
.bulk-table tr:hover { background: var(--table-row-hover); cursor: pointer; }
.bulk-table tr.selected { background: var(--table-row-selected); }
.badge { display: inline-block; font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: 6px; text-transform: uppercase; letter-spacing: 0.3px; }
.badge-SDH { background: #fed7aa; color: #7c2d12; }
.badge-RH  { background: #fde68a; color: #78350f; }
.badge-CHC { background: #bbf7d0; color: #14532d; }
.badge-PHC { background: #bfdbfe; color: #1e3a8a; }
.badge-UPHC{ background: #e9d5ff; color: #581c87; }
.badge-DH  { background: #fecaca; color: #7f1d1d; }
.dist-cell { font-weight: 700; color: var(--accent-blue); white-space: nowrap; }

/* Map */
#map { height: 700px; border-radius: 16px; border: 1px solid var(--border-color); box-shadow: var(--shadow-md); z-index: 1; }

/* Cards & Route Planner */
.route-card { background: var(--panel-bg); padding: 16px; border-radius: 12px; border: 1px solid var(--border-color); margin-bottom: 16px; box-shadow: var(--shadow-sm); }
.route-card-label { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--text-sub); margin-bottom: 8px; letter-spacing: 0.5px; }
.route-stop-row { display: flex; justify-content: space-between; align-items: center; padding: 12px; border-radius: 10px; margin-bottom: 8px; background: var(--panel-bg); border: 1px solid var(--border-color); font-size: 14px; box-shadow: var(--shadow-sm); }
.route-stop-row:hover { border-color: var(--accent-blue); }
.route-num-badge { color: #fff; width: 28px; height: 28px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; margin-right: 12px; flex-shrink: 0; box-shadow: var(--shadow-sm); }
.route-btns { display: flex; gap: 4px; }
.route-btns button { border: 1px solid var(--border-color); background: var(--panel-bg); border-radius: 6px; padding: 4px 8px; cursor: pointer; font-size: 12px; color: var(--text-sub); transition: all 0.1s; }
.route-btns button:hover { background: var(--table-row-hover); color: var(--text-main); }
.route-btns button.remove { border-color: #fecaca; background: #fef2f2; color: #dc2626; }
.route-btns button.remove:hover { background: #fee2e2; }
.route-totals { background: var(--table-row-selected); padding: 20px; border-radius: 12px; border-left: 4px solid var(--accent-purple); box-shadow: var(--shadow-sm); }
.route-totals-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.route-totals-label { font-size: 11px; text-transform: uppercase; color: var(--text-sub); font-weight: 700; letter-spacing: 0.5px; }
.route-totals-value { font-size: 28px; font-weight: 800; color: var(--text-main); line-height: 1.1; letter-spacing: -1px; }
.leg-breakdown { margin-top: 16px; font-size: 13px; color: var(--text-sub); line-height: 1.8; display: flex; flex-direction: column; gap: 6px; }

/* Presets & Saved */
.saved-chip { display: block; width: 100%; text-align: left; padding: 10px 14px; margin-bottom: 6px; background: var(--panel-bg); border: 1px solid var(--border-color); border-radius: 8px; cursor: pointer; font-size: 13px; color: var(--text-main); transition: all 0.15s; box-shadow: var(--shadow-sm); }
.saved-chip:hover { background: var(--table-row-hover); border-color: var(--accent-purple); transform: translateX(4px); }
.preset-chip { display: inline-block; padding: 8px 16px; margin: 4px 4px 4px 0; background: var(--table-row-selected); border: 1px solid var(--accent-purple); border-radius: 20px; cursor: pointer; font-size: 12px; color: var(--accent-purple); font-weight: 700; transition: all 0.15s; }
.preset-chip:hover { background: var(--accent-purple); color: #fff; }

/* Hub Distance View */
.hd-rank { display: inline-block; width: 32px; height: 32px; border-radius: 50%; background: var(--table-header-bg); color: var(--text-sub); font-weight: 800; font-size: 13px; line-height: 32px; text-align: center; box-shadow: var(--shadow-sm); }
.hd-rank.top1 { background: var(--accent-green); color: #fff; }
.hd-rank.top3 { background: var(--accent-blue); color: #fff; }
.hd-rank.top5 { background: var(--accent-purple); color: #fff; }
.hd-bar { height: 6px; background: var(--border-color); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.hd-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent-green), var(--accent-blue), var(--accent-purple)); border-radius: 3px; }
.hd-row { transition: all 0.15s; padding: 16px; border-bottom: 1px solid var(--border-color); background: var(--panel-bg); border-radius: 12px; margin-bottom: 10px; border: 1px solid var(--border-color); box-shadow: var(--shadow-sm); }
.hd-row:hover { background: var(--table-row-hover); border-color: var(--accent-blue); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.hd-row:last-child { margin-bottom: 0; }
.hd-verify-btn { display: inline-block; padding: 6px 12px; font-size: 11px; font-weight: 700; color: var(--accent-blue); background: var(--table-row-selected); border: 1px solid var(--accent-blue); border-radius: 6px; cursor: pointer; transition: all 0.15s; margin-top: 8px; }
.hd-verify-btn:hover { background: var(--accent-blue); color: #fff; }

.empty { text-align: center; padding: 80px 20px; color: var(--text-sub); font-size: 15px; }
.error { background: #fef2f2; border-left: 4px solid #ef4444; padding: 16px; border-radius: 8px; color: #991b1b; font-size: 14px; margin-top: 16px; }
.map-legend { background: var(--panel-bg); padding: 12px; border-radius: 12px; box-shadow: var(--shadow-md); font-size: 12px; line-height: 1.6; color: var(--text-main); border: 1px solid var(--border-color); }
.legend-item { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.legend-dot { width: 12px; height: 12px; border-radius: 50%; box-shadow: inset 0 0 0 2px rgba(0,0,0,0.1); }