:root {
  --bg: #0f1420;
  --panel: #171e2e;
  --panel2: #1e2740;
  --border: #2a3550;
  --text: #e6ebf5;
  --muted: #8b96ad;
  --accent: #4f8cff;
  --accent2: #ffb347;
  --green: #16A34A;
  --red: #ef4444;
  --radius: 10px;
  --shadow: 0 8px 28px rgba(0,0,0,.45);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }

.btn {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-accent { background: var(--accent2); border-color: var(--accent2); color: #000; font-weight: 600; }
.btn-accent:hover { filter: brightness(1.07); }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.link { color: var(--accent); cursor: pointer; text-decoration: underline; }

/* ---- LOGIN ---- */
.login-screen {
  height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 20% -10%, #1b2740 0%, var(--bg) 60%);
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px 40px;
  width: 340px;
  text-align: center;
  box-shadow: var(--shadow);
}
.login-logo { font-size: 42px; }
.login-card h1 { margin: 8px 0 2px; font-size: 22px; }
.login-sub { color: var(--muted); margin: 0 0 22px; font-size: 13px; }
.login-card input {
  width: 100%; padding: 11px 13px; margin-bottom: 12px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 7px;
  color: var(--text); font-size: 14px;
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-err { color: var(--red); font-size: 12px; margin-top: 10px; min-height: 16px; }

/* ---- TOPBAR ---- */
.topbar {
  display: flex; align-items: center; gap: 22px;
  padding: 0 18px; height: 54px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 1000;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.brand-icon { font-size: 20px; }
.tabs { display: flex; gap: 4px; }
.tab {
  background: transparent; color: var(--muted); border: none;
  padding: 8px 16px; font-size: 14px; cursor: pointer; border-radius: 7px;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--panel2); color: var(--text); font-weight: 600; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

/* ---- VIEWS / MAP ---- */
.view { height: calc(100vh - 54px); position: relative; }
.map-toolbar {
  position: absolute; top: 12px; left: 12px; z-index: 900;
  display: flex; align-items: center; gap: 12px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 12px; box-shadow: var(--shadow);
}
.toolbar-right { margin-left: auto; }
.badge {
  background: var(--panel2); border: 1px solid var(--border);
  padding: 4px 10px; border-radius: 20px; font-size: 12px;
}
.ov-toggle { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; user-select: none; }
#map { height: 100%; width: 100%; background: #0d1117; }
.legend {
  position: absolute; bottom: 14px; left: 12px; z-index: 900;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 12px; font-size: 12px; box-shadow: var(--shadow);
}
.legend-item { display: flex; align-items: center; gap: 8px; margin: 3px 0; }
.legend-dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }

/* Leaflet popup overrides */
.leaflet-popup-content-wrapper { background: var(--panel); color: var(--text); border: 1px solid var(--border); }
.leaflet-popup-tip { background: var(--panel); }
.leaflet-popup-content { font-size: 13px; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }
.pmap-name { font-weight: 700; }
.pmap-meta { color: var(--muted); font-size: 12px; }

/* ---- SCHEDULE ---- */
.sched-toolbar {
  display: flex; align-items: center; gap: 8px; padding: 12px 16px;
  background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 54px; z-index: 500;
}
.sched-range { font-weight: 700; font-size: 15px; min-width: 180px; text-align: center; }
.sched-hint { margin-left: auto; color: var(--muted); font-size: 12px; }
.schedule { padding: 16px; overflow: auto; height: calc(100vh - 54px - 52px); }
.sched-day { margin-bottom: 20px; }
.sched-day-head {
  font-weight: 700; font-size: 15px; padding: 6px 4px;
  border-bottom: 1px solid var(--border); margin-bottom: 8px;
  display: flex; align-items: center; gap: 10px;
}
.day-load { font-size: 11px; color: var(--muted); font-weight: 400; }
.sched-row { display: flex; gap: 14px; }
.sched-lane {
  flex: 1; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); min-height: 90px; padding: 8px;
  transition: background .15s, border-color .15s;
}
.sched-lane.dragover { background: var(--panel2); border-color: var(--accent); }
.lane-head { display: flex; align-items: center; gap: 8px; padding: 4px 6px 8px; font-weight: 600; font-size: 13px; }
.lane-dot { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.lane-total { margin-left: auto; font-size: 11px; color: var(--muted); font-weight: 400; }
.site-card {
  background: var(--panel2); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: 7px; padding: 8px 10px; margin-bottom: 7px; cursor: grab;
  font-size: 12px; position: relative; transition: transform .1s, box-shadow .1s;
}
.site-card:hover { box-shadow: 0 4px 14px rgba(0,0,0,.4); }
.site-card:active { cursor: grabbing; }
.site-card.dragging { opacity: .4; }
.site-card.new { border-left-color: var(--red); }
.site-card.priority { border-left-color: var(--accent2); }
.card-top { display: flex; align-items: center; gap: 6px; }
.card-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-time { margin: 4px 0; color: var(--muted); font-size: 11px; }
.card-addr { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-tag { font-size: 10px; background: var(--bg); padding: 1px 6px; border-radius: 10px; color: var(--muted); margin-left: auto; }
.unsched-lane { border-style: dashed; }

/* ---- IMPORT MODAL ---- */
.modal {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(5,8,14,.7); display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow: auto;
}
.modal-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; width: 720px; max-width: 100%; box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-close { background: transparent; border: none; color: var(--muted); font-size: 18px; cursor: pointer; }
.modal-body { padding: 20px; }
.modal-sub { color: var(--muted); margin: 0 0 14px; }
.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 34px; text-align: center; color: var(--muted);
  cursor: pointer; transition: all .15s; background: var(--panel2);
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); color: var(--text); }
.dropzone input { display: none; }
.mapping-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.mapping-row { display: flex; flex-direction: column; gap: 4px; }
.mapping-row label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.mapping-row select, .mapping-row input {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 9px; font-size: 13px;
}
.mapping-row select:focus, .mapping-row input:focus { outline: none; border-color: var(--accent); }
.import-actions { display: flex; gap: 10px; margin-top: 10px; }
.geo-progress { margin-top: 10px; font-size: 12px; color: var(--muted); }
.import-preview { margin-top: 14px; }
.table-wrap { max-height: 280px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.preview-table { border-collapse: collapse; width: 100%; font-size: 12px; }
.preview-table th, .preview-table td { border-bottom: 1px solid var(--border); padding: 6px 9px; text-align: left; white-space: nowrap; }
.preview-table th { position: sticky; top: 0; background: var(--panel2); }
.import-done { background: var(--panel2); border: 1px solid var(--green); color: #c6f5d6; border-radius: 8px; padding: 14px; }
.geo-ok { color: var(--green); }
.geo-fail { color: var(--red); }
.geo-missing { color: var(--accent2); }
