/* ============================================================
   Signal Routing — Stylesheet
   ============================================================ */

:root {
  --primary: #1e40af;
  --primary-hover: #1d3a9f;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --secondary: #475569;
  --secondary-hover: #334155;

  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;

  --green: #16a34a;
  --green-bg: #dcfce7;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --amber: #d97706;
  --amber-bg: #fef3c7;
  --gray: #64748b;
  --gray-bg: #f1f5f9;

  --header-h: 56px;
  --radius: 6px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#app { display: flex; flex-direction: column; height: 100vh; }

/* ---- Header ---- */
.app-header {
  height: var(--header-h);
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}

.header-brand { display: flex; align-items: center; gap: 10px; }

.logo {
  width: 32px; height: 32px;
  background: rgba(255,255,255,.2);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; letter-spacing: .5px;
}

.brand-name { font-weight: 600; font-size: 16px; }

.tab-nav { display: flex; gap: 4px; }

.tab-btn {
  background: rgba(255,255,255,.15);
  color: rgba(255,255,255,.85);
  border: none;
  padding: 7px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background .15s;
}
.tab-btn:hover { background: rgba(255,255,255,.25); }
.tab-btn.active { background: white; color: var(--primary); }

.settings-btn {
  background: rgba(255,255,255,.15);
  color: white; border: none;
  width: 34px; height: 34px;
  border-radius: var(--radius);
  font-size: 18px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
  margin-left: 8px;
}
.settings-btn:hover { background: rgba(255,255,255,.3); }

/* ---- Main ---- */
.app-main { flex: 1; overflow: hidden; display: flex; flex-direction: column; }

.tab-content { display: none; flex: 1; flex-direction: column; overflow: hidden; }
.tab-content.active { display: flex; }

/* ---- Shared Buttons ---- */
.btn {
  padding: 7px 14px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--secondary); color: white; }
.btn-secondary:hover:not(:disabled) { background: var(--secondary-hover); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ---- Shared Inputs ---- */
.search-input, .filter-select {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  background: white;
  color: var(--text);
}
.search-input:focus, .filter-select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.search-input { width: 220px; }

/* ---- Status / Zone Badges ---- */
.status-badge, .zone-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.status-functional { background: var(--green-bg); color: var(--green); }
.status-non_functional { background: var(--red-bg); color: var(--red); }
.status-requires_attention { background: var(--amber-bg); color: var(--amber); }
.status-unknown { background: var(--gray-bg); color: var(--gray); }

.zone-patrol-zone { background: #dbeafe; color: #1d4ed8; }
.zone-dedicated-zone { background: #ede9fe; color: #7c3aed; }
.zone-admin { background: var(--gray-bg); color: var(--gray); }

/* ---- Dot indicators ---- */
.dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  vertical-align: middle;
}
.dot-green { background: var(--green); }
.dot-red { background: var(--red); }
.dot-amber { background: var(--amber); }

/* ============================================================
   CLIENTS TAB
   ============================================================ */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 8px;
}
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 8px; }
.client-count { font-size: 12px; color: var(--text-muted); }

.table-container { flex: 1; overflow: auto; }

.clients-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
}
.clients-table thead { position: sticky; top: 0; z-index: 1; }
.clients-table th {
  background: #f8fafc;
  border-bottom: 2px solid var(--border);
  padding: 10px 12px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}
.clients-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.clients-table tr:hover td { background: #f8fafc; }

.empty-row td {
  text-align: center;
  color: var(--text-muted);
  padding: 40px;
}

.client-name { font-weight: 600; }
.address-cell { color: var(--text-muted); font-size: 12px; max-width: 240px; }
.contact-info { display: flex; flex-direction: column; gap: 1px; }
.contact-info small { color: var(--text-muted); font-size: 11px; }

.geocoded-yes { color: var(--green); font-weight: 700; }
.geocoded-no { color: var(--text-muted); }

.link-btn {
  background: none; border: none; padding: 0;
  color: var(--primary); cursor: pointer; font-size: inherit;
  text-decoration: underline; font-weight: 500;
}
.link-btn:hover { color: var(--primary-hover); }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
}
.modal-box {
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
  width: 520px; max-width: 95vw; max-height: 80vh;
  display: flex; flex-direction: column;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 15px; font-weight: 600; }
.modal-close {
  background: none; border: none; cursor: pointer;
  font-size: 18px; color: var(--text-muted); line-height: 1; padding: 2px 6px;
  border-radius: 4px;
}
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-hint { padding: 10px 20px; font-size: 12px; color: var(--text-muted); }
.settings-body { padding: 16px 20px; display: flex; flex-direction: column; gap: 8px; }
.settings-label { font-size: 13px; font-weight: 600; }
.settings-input { padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 13px; font-family: monospace; }
.settings-input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.settings-hint { font-size: 12px; color: var(--text-muted); line-height: 1.5; }
.settings-key-status { font-size: 12px; color: var(--green); font-weight: 500; }
.ungeocoded-list { overflow-y: auto; padding: 0 12px 12px; }
.ungeocoded-item {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 3px;
}
.ungeocoded-item:last-child { border-bottom: none; }
.ungeocoded-name { font-weight: 600; font-size: 13px; }
.ungeocoded-address { font-size: 12px; color: var(--text-muted); }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; }

.editable-cell { white-space: nowrap; }
.field-prefix { color: var(--text-muted); font-size: 12px; margin-right: 2px; }

.client-field-input {
  width: 64px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  text-align: right;
  background: #fafafa;
  transition: border-color .15s, background .15s;
}
.client-field-input:hover { border-color: #94a3b8; background: white; }
.client-field-input:focus { outline: 2px solid var(--primary); outline-offset: -1px; background: white; }

/* ============================================================
   MAP TAB
   ============================================================ */
.map-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 12px;
}
.map-filters { display: flex; align-items: center; gap: 16px; }
.map-filter-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 13px;
  user-select: none;
}
.geocode-bar { display: flex; align-items: center; gap: 10px; }
.geocode-status { font-size: 12px; color: var(--text-muted); }

#map { flex: 1; }

/* ============================================================
   ROUTES TAB
   ============================================================ */
#tab-routes {
  flex-direction: column;
  overflow: auto;
}

.route-builder {
  display: flex;
  flex: 1;
  min-height: 0;
  border-bottom: 1px solid var(--border);
}

/* Left sidebar */
.route-sidebar {
  width: 260px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 8px;
}
.sidebar-header h3 { font-size: 13px; font-weight: 600; }
.sidebar-filters { display: flex; flex-direction: column; gap: 6px; padding: 0 10px 8px; }
.sidebar-filters .search-input { width: 100%; }
.sidebar-filters .filter-select { width: 100%; }
.available-clients-list { flex: 1; overflow-y: auto; }

.available-client-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.available-client-item:hover { background: #f8fafc; }
.available-client-item .dot { flex-shrink: 0; }
.client-item-name { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.add-stop-btn {
  width: 24px; height: 24px;
  border: none;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background .15s;
}
.add-stop-btn:hover { background: var(--primary-hover); }

/* Route main panel */
.route-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.route-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.route-name-input {
  flex: 1;
  min-width: 180px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
}
.route-name-input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.route-status { font-size: 12px; color: var(--text-muted); font-style: italic; white-space: nowrap; }
.time-label { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.time-label input[type="time"] {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
}

/* Route stops */
.route-stops-list { flex: 1; overflow-y: auto; padding: 8px; }

.route-empty-msg {
  text-align: center;
  color: var(--text-muted);
  padding: 32px 16px;
  font-size: 13px;
}

.route-stop {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 6px;
  transition: box-shadow .15s;
}
.route-stop:hover { box-shadow: 0 2px 6px rgba(0,0,0,.08); }

.stop-handle {
  cursor: grab;
  color: var(--text-muted);
  font-size: 16px;
  flex-shrink: 0;
  user-select: none;
}
.stop-handle:active { cursor: grabbing; }

.stop-number {
  width: 24px; height: 24px;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

.stop-info { flex: 1; min-width: 0; }
.stop-name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stop-address { font-size: 11px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stop-arrival { font-size: 11px; color: var(--primary); font-weight: 500; margin-top: 2px; }

.stop-inputs {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.stop-inputs label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}
.stop-input {
  width: 54px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
  text-align: right;
}
.stop-input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.remove-stop-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  flex-shrink: 0;
  transition: color .15s, background .15s;
}
.remove-stop-btn:hover { color: var(--red); background: var(--red-bg); }

/* Office bookend stops */
.route-office-stop {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 6px;
}

.office-badge {
  width: 32px; height: 32px;
  background: var(--primary);
  color: white;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .05em;
  flex-shrink: 0;
}

/* SortableJS ghost/drag styles */
.sortable-ghost { opacity: .4; }
.sortable-chosen { box-shadow: 0 4px 12px rgba(0,0,0,.15); }

/* Route summary bar */
.route-summary {
  display: flex;
  gap: 0;
  border-top: 2px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.summary-item {
  flex: 1;
  padding: 10px 14px;
  border-right: 1px solid var(--border);
  text-align: center;
}
.summary-item:last-child { border-right: none; }
.summary-item.highlight { background: #eff6ff; }
.summary-label { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin-bottom: 2px; }
.summary-value { font-size: 16px; font-weight: 700; color: var(--text); }
.summary-item.highlight .summary-value { color: var(--primary); }

/* Saved routes section */
.saved-routes-section {
  padding: 16px;
  background: var(--bg);
  flex-shrink: 0;
}
.saved-routes-section h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 10px;
}

.saved-route {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
}
.saved-route-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.saved-route-header strong { font-size: 14px; }
.saved-route-header > span { color: var(--text-muted); font-size: 12px; flex: 1; }
.saved-route-header > div { display: flex; gap: 6px; }
.saved-route-stats { display: flex; gap: 16px; font-size: 12px; color: var(--text-muted); }
.saved-route-stats span strong { color: var(--text); }
