/* Fences & Routes — shared design system (carried over from routes_creator) */

:root {
  --bg:         #0a0a0c;
  --surface:    #111114;
  --surface-hi: #1a1a1f;
  --border:     #1f1f23;
  --text:       #e6e6e9;
  --muted:      #8a8a93;
  --muted-2:    #5a5a63;
  --accent:     #6ee7ff;
  --success:    #4ade80;
  --danger:     #f87171;
  --warn:       #f59e0b;
}

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

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

/* ── Top bar ─────────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 18px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.topbar .brand {
  font-size: 1.02rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.topbar .brand .dim { color: var(--muted-2); font-weight: 400; }

.nav-tabs { display: flex; gap: 6px; }
.nav-tab {
  padding: 6px 14px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.82rem;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.nav-tab:hover { background: var(--surface-hi); border-color: var(--muted-2); color: var(--text); }
.nav-tab.active { background: var(--surface-hi); border-color: var(--accent); color: var(--accent); }

.topbar .spacer { flex: 1; }
.topbar .who {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--muted-2);
  white-space: nowrap;
}
.topbar .who a { color: var(--muted); text-decoration: none; }
.topbar .who a:hover { color: var(--accent); }
.logout-form { display: inline; }

/* ── Layout ──────────────────────────────────────────────────────────────── */

.layout { display: flex; flex: 1; overflow: hidden; }

.left-col {
  width: 300px;
  min-width: 300px;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.sidebar {
  flex: 1;
  background: var(--bg);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  border-right: 1px solid var(--border);
}

#map { flex: 1; }

.section-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 7px;
}
.section-label .hint {
  font-size: 0.62rem;
  font-weight: 400;
  letter-spacing: 0.04em;
  color: var(--muted-2);
  text-transform: none;
}

/* ── Controls ────────────────────────────────────────────────────────────── */

.btn {
  padding: 7px 13px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 0.82rem;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-primary:hover:not(:disabled) { background: var(--surface-hi); border-color: var(--muted-2); }
.btn-primary.active { background: var(--surface-hi); border-color: var(--accent); color: var(--accent); }
.btn-success { background: var(--surface); color: var(--success); border-color: var(--border); width: 100%; margin-top: 8px; }
.btn-success:hover:not(:disabled) { background: var(--surface-hi); border-color: var(--success); }
.btn-warn { background: var(--surface); color: var(--warn); border-color: var(--border); }
.btn-warn:hover:not(:disabled) { background: var(--surface-hi); border-color: var(--warn); }
.btn-danger  { background: transparent; color: var(--danger); border-color: var(--border); padding: 3px 8px; font-size: 0.75rem; }
.btn-danger:hover:not(:disabled) { background: var(--surface-hi); border-color: var(--danger); }
.btn-sm { padding: 3px 8px; font-size: 0.75rem; }
.btn-block { width: 100%; }

.mode-row { display: flex; gap: 8px; }
.mode-row .btn { flex: 1; text-align: center; }

.btn-col { display: flex; flex-direction: column; gap: 6px; }

label { display: block; font-size: 0.76rem; color: var(--muted); margin-bottom: 4px; }

input[type="text"], input[type="number"], input[type="password"] {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 9px;
  border-radius: 4px;
  font-size: 0.83rem;
  transition: border-color 0.15s;
}
input[type="text"]:focus,
input[type="number"]:focus,
input[type="password"]:focus { outline: none; border-color: var(--accent); }
input[type="range"] { width: 100%; accent-color: var(--accent); cursor: pointer; }

input[type="checkbox"] {
  accent-color: var(--accent);
  width: 14px; height: 14px;
  cursor: pointer;
  flex-shrink: 0;
}

.check-list { display: flex; flex-direction: column; gap: 7px; margin-top: 4px; }
.check-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  cursor: pointer;
  margin-bottom: 0;
  font-size: 0.78rem;
}

.range-row { display: flex; align-items: center; gap: 8px; }
.range-row input[type="range"] { flex: 1; }
.range-val { font-size: 0.78rem; color: var(--accent); min-width: 55px; text-align: right; font-variant-numeric: tabular-nums; }

.input-unit { position: relative; }
.input-unit input { padding-right: 28px; }
.input-unit .unit {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted-2);
  font-size: 0.72rem;
  pointer-events: none;
}

.field-stack > * + label { margin-top: 8px; }

hr { border: none; border-top: 1px solid var(--border); }

.collapse-head {
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* ── Status / cards ──────────────────────────────────────────────────────── */

.status-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.5;
  min-height: 38px;
}
.status-box .hi { color: var(--accent); font-weight: 600; }
.status-box.error { border-left: 2px solid var(--danger); color: var(--danger); }

.item-list { display: flex; flex-direction: column; gap: 6px; }
.item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 10px;
  transition: border-color 0.15s;
}
.item-card:hover { border-color: var(--muted-2); }
.item-card.active { border-color: var(--accent); }
.item-card-name { font-size: 0.84rem; font-weight: 600; cursor: pointer; margin-bottom: 3px; color: var(--text); }
.item-card-meta { font-size: 0.72rem; color: var(--muted-2); margin-bottom: 7px; }
.item-card-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.item-card-actions a { text-decoration: none; }

.empty-note { font-size: 0.78rem; color: var(--muted-2); }

/* Sidebar hints. `text-wrap: pretty` keeps a lone word off the last line in
   a 300px column; browsers without it just wrap normally. */
.hint-text {
  margin-top: 8px;
  font-size: 0.72rem;
  line-height: 1.5;
  color: var(--muted-2);
  text-wrap: pretty;
}

.hint-list {
  list-style: none;
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--muted-2);
}
/* Bullet in its own column so wrapped lines hang past it instead of
   sliding back under the marker. */
.hint-list li { display: flex; gap: 7px; text-wrap: pretty; }
.hint-list li::before { content: "\2022"; flex-shrink: 0; color: var(--muted-2); }

.api-banner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 2px solid var(--warn);
  border-radius: 4px;
  padding: 11px;
  font-size: 0.8rem;
}
.api-banner p { margin-bottom: 7px; color: var(--warn); }

/* ── Stops (routes) ──────────────────────────────────────────────────────── */

.stop-list { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.stop-row {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 7px;
  font-size: 0.75rem;
}
.stop-num {
  background: var(--warn);
  color: var(--bg);
  font-weight: 700;
  font-size: 0.7rem;
  min-width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stop-coords { color: var(--muted); font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.68rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stop-row input[type="number"] { width: 60px; padding: 3px 5px; font-size: 0.72rem; flex-shrink: 0; }

/* ── Vertex list (fences) ────────────────────────────────────────────────── */

.point-list { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; max-height: 220px; overflow-y: auto; }
.point-row {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 7px;
  font-size: 0.75rem;
}
.point-num {
  background: var(--accent);
  color: var(--bg);
  font-weight: 700;
  font-size: 0.7rem;
  min-width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.point-coords {
  color: var(--muted);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.68rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Second line of the fence status box, holding the live polygon area. */
.status-box .status-area {
  margin-top: 5px;
  padding-top: 5px;
  border-top: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

/* Read-only hex payload fields */
.hex-field {
  margin-top: 2px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  cursor: pointer;
}
.hex-field.encrypted { color: var(--warn); }

/* ── Toast ───────────────────────────────────────────────────────────────── */

#toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  max-width: 360px;
  padding: 11px 14px;
  border-radius: 6px;
  font-size: 0.82rem;
  box-shadow: 0 4px 14px rgba(0,0,0,0.6);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.18s, transform 0.18s;
  pointer-events: none;
  z-index: 1000;
  line-height: 1.45;
  word-break: break-all;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
#toast.show { opacity: 1; transform: translateY(0); }
#toast.success { border-left: 2px solid var(--success); }
#toast.error   { border-left: 2px solid var(--danger); }
#toast.info    { border-left: 2px solid var(--accent); }

/* ── Scrollbars ──────────────────────────────────────────────────────────── */

.sidebar::-webkit-scrollbar,
.point-list::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-track,
.point-list::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb,
.point-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.sidebar::-webkit-scrollbar-thumb:hover,
.point-list::-webkit-scrollbar-thumb:hover { background: var(--muted-2); }

/* ── Centred pages (login / account) ─────────────────────────────────────── */

.center-page {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}

.card {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 26px 24px;
}
.card h1 {
  font-size: 1.1rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  margin-bottom: 4px;
}
.card .subtitle {
  font-size: 0.78rem;
  color: var(--muted-2);
  margin-bottom: 20px;
}
.card label { margin-top: 12px; }
.card label:first-of-type { margin-top: 0; }
.card .btn { margin-top: 18px; }

.form-error {
  border-left: 2px solid var(--danger);
  background: var(--bg);
  color: var(--danger);
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 0.78rem;
  margin-bottom: 14px;
}
.form-warn {
  border-left: 2px solid var(--warn);
  background: var(--bg);
  color: var(--warn);
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 0.78rem;
  line-height: 1.45;
  margin-bottom: 14px;
}
.form-ok {
  border-left: 2px solid var(--success);
  background: var(--bg);
  color: var(--success);
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 0.78rem;
  margin-bottom: 14px;
}

.card .foot-note {
  margin-top: 16px;
  font-size: 0.72rem;
  color: var(--muted-2);
  line-height: 1.5;
}
.card .foot-note code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--muted);
}
.card .foot-note a { color: var(--accent); text-decoration: none; }
