/* CustomerDB Web UI (light by default; body.dark enables dark mode) */

:root{
  /* core */
  --bg:#f5f7fb;
  --panel:#ffffff;
  --panel2:rgba(255,255,255,.78);
  --panelHd:rgba(248,250,252,.92);
  --line:#dde1ea;
  --text:#0f172a;
  --muted:#64748b;

  /* accents */
  --accent:#38bdf8;
  --accent2:#a78bfa;
  --good:#16a34a;
  --bad:#ef4444;
  --warn:#f59e0b;

  /* misc */
  --radius:16px;
  --shadow: 0 18px 50px rgba(15,23,42,.14);
  --shadowSoft: 0 10px 30px rgba(15,23,42,.12);
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

  /* page glow */
  --bgGlow1: rgba(56,189,248,.12);
  --bgGlow2: rgba(167,139,250,.10);
  --bgGlow3: rgba(34,197,94,.08);

  /* component surfaces */
  --inputBg: rgba(255,255,255,.90);
  --btnBg: rgba(255,255,255,.78);
  --btnBgHover: rgba(255,255,255,.96);
  --chipBg: rgba(255,255,255,.66);
  --tableBg: rgba(255,255,255,.70);
  --rowHover: rgba(56,189,248,.10);
  --tableLine: rgba(15,23,42,.10);

  --modalBg: rgba(255,255,255,.99);
  --modalHdBg: rgba(248,250,252,.92);
  --toastBg: rgba(255,255,255,.96);
}

/* Dark theme overrides (your JS toggles body.dark) */
body.dark{
  --bg:#0b1220;
  --panel:rgba(15,27,51,.70);
  --panel2:rgba(15,27,51,.75);
  --panelHd:rgba(12,22,43,.75);
  --line:#233252;
  --text:#e8eefc;
  --muted:#9bb0d0;

  --shadow: 0 18px 50px rgba(0,0,0,.35);
  --shadowSoft: 0 10px 30px rgba(0,0,0,.25);

  --bgGlow1: rgba(56,189,248,.13);
  --bgGlow2: rgba(167,139,250,.10);
  --bgGlow3: rgba(34,197,94,.08);

  --inputBg: rgba(11,18,32,.75);
  --btnBg: rgba(11,18,32,.75);
  --btnBgHover: rgba(11,18,32,.92);
  --chipBg: rgba(12,22,43,.55);
  --tableBg: rgba(11,18,32,.55);
  --rowHover: rgba(56,189,248,.055);
  --tableLine: rgba(35,50,82,.65);

  --modalBg: rgba(15,27,51,.95);
  --modalHdBg: rgba(12,22,43,.65);
  --toastBg: rgba(12,22,43,.95);
}

*{ box-sizing:border-box; }
html,body{ height:100%; }

body{
  margin:0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: radial-gradient(1200px 800px at 20% 10%, var(--bgGlow1), transparent 55%),
              radial-gradient(900px 600px at 80% 20%, var(--bgGlow2), transparent 55%),
              radial-gradient(1200px 900px at 60% 90%, var(--bgGlow3), transparent 55%),
              var(--bg);
  color:var(--text);
}

.wrap{
  max-width: 1250px;
  margin: 0 auto;
  padding: 24px 16px 60px;
}

.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin-bottom:18px;
}

.brand{
  display:flex; align-items:center; gap:12px;
}
.logo{
  width:38px;height:38px;border-radius:12px;
  background: linear-gradient(135deg, rgba(56,189,248,.9), rgba(167,139,250,.9));
  box-shadow: var(--shadow);
}
.hgroup h1{ margin:0; font-size:18px; letter-spacing:.2px; }
.hgroup p{ margin:0; color:var(--muted); font-size:12px; }

.pill{
  display:inline-flex; align-items:center; gap:8px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  background: var(--panel2);
  border-radius:999px;
  box-shadow: var(--shadowSoft);
  color: var(--muted);
  font-size:12px;
}

.grid{
  display:grid;
  grid-template-columns: 380px 1fr;
  gap: 16px;
  align-items:start;
}
@media (max-width: 980px){
  .grid{ grid-template-columns: 1fr; }
}

.card{
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow:hidden;
}

.card .hd{
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panelHd);
  display:flex; align-items:center; justify-content:space-between; gap:10px;
}
.card .hd h2{ margin:0; font-size:14px; color: var(--text); }
.card .bd{ padding: 16px; }

.row{ display:flex; gap:10px; align-items:center; }
.row + .row{ margin-top: 12px; }
.lab{ width: 92px; color: var(--muted); font-size: 12px; }

input, select, textarea{
  width:100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--inputBg);
  color: var(--text);
  outline:none;
}
textarea{ min-height: 94px; resize: vertical; }

.btns{ display:flex; gap:10px; flex-wrap:wrap; }
button{
  border: 1px solid var(--line);
  background: var(--btnBg);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 12px;
  cursor:pointer;
  transition: transform .05s ease, background .18s ease, border-color .18s ease;
}
button:hover{
  border-color: rgba(56,189,248,.55);
  background: var(--btnBgHover);
}
button:active{ transform: translateY(1px); }

button.primary{
  border-color: rgba(56,189,248,.55);
  background: linear-gradient(135deg, rgba(56,189,248,.22), rgba(167,139,250,.18));
}
button.danger{
  border-color: rgba(239,68,68,.55);
  background: rgba(239,68,68,.10);
}
button.ghost{
  background: transparent;
}

small.help{ display:block; margin-top:10px; color: var(--muted); line-height:1.35; }

hr.sep{ border:0; height:1px; background: var(--line); margin: 14px 0; }

.tableWrap{
  overflow:auto;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--tableBg);
}

table{
  width:100%;
  border-collapse: collapse;
  font-size: 12px;
  min-width: 950px;
}

th, td{
  border-bottom: 1px solid var(--tableLine);
  padding: 10px 10px;
  vertical-align: top;
}
th{
  position: sticky;
  top: 0;
  background: var(--panelHd); /* index.html overrides #tbl thead th, this stays as a sane fallback */
  color: var(--muted);
  text-align:left;
  letter-spacing:.3px;
  font-weight:600;
}

td.mono{ font-family: var(--mono); }
td.actions{ white-space:nowrap; }

tr:hover td{
  background: var(--rowHover);
}

.badge{
  display:inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  border:1px solid var(--line);
  color: var(--muted);
  background: var(--chipBg);
}

.toast{
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--toastBg);
  box-shadow: var(--shadow);
  font-size: 12px;
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.toast.show{
  opacity: 1;
  transform: translateX(-50%) translateY(-4px);
}

.modalBack{
  position:fixed; inset:0;
  background: rgba(0,0,0,.55);
  display:none;
  align-items:center;
  justify-content:center;
  padding: 18px;
}
.modalBack.show{ display:flex; }

.modal{
  width:min(920px, 100%);
  max-height: 86vh;
  overflow:auto;
  border:1px solid var(--line);
  border-radius: 18px;
  background: var(--modalBg);
  box-shadow: var(--shadow);
}
.modal .hd{
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display:flex; align-items:center; justify-content:space-between; gap:10px;
  background: var(--modalHdBg);
}
.modal .hd h3{ margin:0; font-size:14px; }
.modal .bd{ padding: 16px; }

.formGrid{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 840px){
  .formGrid{ grid-template-columns: 1fr; }
}

.kv label{
  display:block;
  font-size: 11px;
  color: var(--muted);
  margin: 0 0 6px;
}
.kv input, .kv textarea{ width: 100%; }

.footerRow{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin-top: 12px;
  flex-wrap:wrap;
}

/* =========================
   Context menu (row right-click)
   ========================= */
.ctxMenu{
  position: fixed;
  z-index: 20000;
  min-width: 220px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 30px 90px rgba(0,0,0,.35);
  border-radius: 14px;
  padding: 6px;
  display: none;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.ctxMenu.show{ display:block; }

.ctxMenu button{
  width: 100%;
  text-align: left;
  padding: 10px 10px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
}
.ctxMenu button:hover{
  border-color: rgba(56,189,248,.45);
  background: rgba(56,189,248,.10);
}

/* =========================
   Row state (selected / in route)
   ========================= */
#tbody tr.isSelected > td{
  box-shadow: inset 0 0 0 1px rgba(56,189,248,.55);
  background: rgba(56,189,248,.08);
}
#tbody tr.inRoute > td:first-child{
  box-shadow: inset 5px 0 0 rgba(167,139,250,.75);
}
#tbody tr.inRoute.isSelected > td:first-child{
  box-shadow: inset 5px 0 0 rgba(167,139,250,.85), inset 0 0 0 1px rgba(56,189,248,.60);
}

/* =========================
   Route planner modal
   ========================= */
.routeModal{
  width: min(1180px, 100%);
  max-height: 88vh;
  overflow: hidden;
  border:1px solid var(--line);
  border-radius: 18px;
  background: var(--modalBg);
  box-shadow: var(--shadow);
  display:flex;
  flex-direction: column;
}
.routeBody{
  display:grid;
  grid-template-columns: 360px 1fr;
  gap: 12px;
  height: calc(88vh - 64px);
}
@media (max-width: 980px){
  .routeBody{
    grid-template-columns: 1fr;
    height: auto;
  }
}

.routeLeft{
  border: 1px solid var(--line);
  background: var(--panel2);
  border-radius: 16px;
  padding: 12px;
  overflow: auto;
}
.routeSummary{
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--muted);
}
.routeList{
  display:flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}
.routeItem{
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,.78), rgba(255,255,255,.58));
  border-radius: 14px;
  padding: 10px;
  box-shadow: var(--shadowSoft);
}
body.dark .routeItem{
  background: linear-gradient(180deg, rgba(11,18,32,.72), rgba(11,18,32,.52));
}
.routeItemTop{
  display:flex;
  align-items:flex-start;
  justify-content: space-between;
  gap: 10px;
}
.routeItemTitle{
  font-weight: 700;
  font-size: 12px;
  color: var(--text);
  line-height: 1.2;
}
.routeItemSub{
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
  overflow:hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.routeItemBtns{
  display:flex;
  gap: 6px;
  flex: 0 0 auto;
}
.routeItemBtns button{
  padding: 6px 10px;
  border-radius: 12px;
}

.routeMapWrap{
  border: 1px solid var(--line);
  background: var(--panel2);
  border-radius: 16px;
  overflow: hidden;
}
.routeMap{
  width: 100%;
  height: 100%;
  min-height: 420px;
}

/* Leaflet tweaks to match theme */
.leaflet-control-attribution{
  font-size: 10px !important;
  opacity: .85;
}
.leaflet-popup-content-wrapper{
  border-radius: 14px !important;
}
