/* ====== Humro brand palette ======
   Logo authoritative colors: charcoal #221F1F + yellow #F9BF17.
   Font: Montserrat (vendored). */
@font-face {
  font-family: 'Montserrat';
  src: url('/vendor/fonts/montserrat/Montserrat.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
:root {
  --bg:        #16151a;     /* warm charcoal — sits behind the brand */
  --panel:     #1f1d22;
  --panel-2:   #28252b;
  --ink:       #f1ede5;     /* warm off-white */
  --muted:     #9c948b;
  --line:      #322f36;
  --line-2:    #43404a;
  --accent:    #f9bf17;     /* HUMRO YELLOW */
  --accent-ink:#221f1f;     /* dark text for use on yellow */
  --accent-2:  #f9bf17;
  --danger:    #ff5d6c;
  --warn:      #f59f00;
  --gradient:  linear-gradient(135deg, #25232a 0%, #14131a 100%);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--ink);
             font: 15px/1.5 'Montserrat', system-ui, -apple-system,
                   "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 0.95rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: #9bc1ff; }

/* ====== shared buttons ====== */
button, .btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  background: var(--panel-2); color: var(--ink); border: 1px solid var(--line);
  padding: 0.4rem 0.8rem; border-radius: 6px; cursor: pointer;
  font: inherit; transition: background 0.12s, border-color 0.12s, transform 0.05s;
}
button:hover, .btn:hover { background: #2a2f37; border-color: var(--line-2); }
button:active, .btn:active { transform: translateY(1px); }
button.primary, .btn.primary {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
  font-weight: 600;
}
button.primary:hover { background: #ffd54a; border-color: #ffd54a; }
button.ghost, .btn.ghost { background: transparent; }
button.ghost:hover { background: rgba(249, 191, 23, 0.10); }

/* Toggle-on state: the panel this button controls is currently visible.
   Accent-tinted background + a small glowing dot in the top-right corner. */
button.toggle-on, .btn.toggle-on {
  background: rgba(249, 191, 23, 0.16);
  border-color: rgba(249, 191, 23, 0.50);
  color: var(--accent);
  position: relative;
}
button.toggle-on::after, .btn.toggle-on::after {
  content: "";
  position: absolute;
  top: 5px; right: 5px;
  width: 7px; height: 7px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--accent), 0 0 12px rgba(249, 191, 23, 0.55);
}
button.toggle-on:hover { background: rgba(249, 191, 23, 0.24); }
button.danger, .btn.danger { color: var(--danger); border-color: rgba(255, 93, 108, 0.4); }
button.danger:hover { background: rgba(255, 93, 108, 0.12); border-color: var(--danger); }

input, select, textarea {
  background: var(--bg); color: var(--ink); border: 1px solid var(--line);
  border-radius: 6px; padding: 0.4rem 0.6rem; font: inherit; outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(249, 191, 23, 0.18);
}
.mono { font-family: ui-monospace, "JetBrains Mono", monospace; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.spacer { flex: 1; }
.row { display: flex; align-items: center; gap: 0.5rem; margin: 0.25rem 0; }
.row.gap { gap: 0.5rem; }
.block { display: block; margin: 0.5rem 0; }
.err { color: var(--danger); min-height: 1.2em; font-size: 12px; margin-top: 0.5rem; }

/* ====== top header (shared across all pages) ====== */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
  display: flex; align-items: center; gap: 0.9rem;
  padding: 0.55rem 1rem;
  background: var(--gradient);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(255,255,255,0.03), 0 6px 14px rgba(0,0,0,0.25);
  position: sticky; top: 0; z-index: 20;
}
.brand {
  display: inline-flex; align-items: center; gap: 0.6rem;
  color: var(--ink); text-decoration: none;
  font-size: 1.05rem; font-weight: 700; letter-spacing: 0.4px;
}
.brand img.brand-logo {
  height: 30px; width: auto; display: block;
  /* The SVG ships with its own colors; on a dark background the
     charcoal silhouette would disappear, so invert+brighten it. */
  filter: brightness(0) invert(1);
}
.brand .product {
  font-weight: 600; color: var(--accent); letter-spacing: 0.6px;
  border-left: 1px solid var(--line-2); padding-left: 0.7rem;
}

.nav { display: flex; gap: 0.1rem; margin-left: 0.3rem; align-items: center; }
.nav a, .nav .here {
  padding: 0.45rem 0.9rem; border-radius: 6px; color: var(--muted);
  font-weight: 500; transition: background 0.12s, color 0.12s;
}
.nav a:hover { color: var(--ink); background: rgba(255,255,255,0.05); }
.nav a.active { color: var(--accent-ink); background: var(--accent); font-weight: 600; }
.nav .here { color: var(--ink); font-weight: 500; }

.robot-picker { display: flex; gap: 0.4rem; align-items: center; }
.robot-picker select { min-width: 220px; }
.modes { display: flex; gap: 0.2rem; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.modes label { cursor: pointer; padding: 0.32rem 0.8rem; border-radius: 6px; color: var(--muted); transition: background 0.12s, color 0.12s; font-weight: 500; }
.modes input { display: none; }
.modes label:has(input:checked) { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.modes label:hover { color: var(--ink); }
.status {
  color: var(--muted); font-family: ui-monospace, monospace; font-size: 12px;
  min-width: 16ch; padding: 0 0.4rem;
}
.who { color: var(--muted); font-size: 12px; padding: 0 0.2rem; }
.who::before { content: "@"; opacity: 0.7; }

/* ====== centered auth pages (login / setup) ====== */
body.centered { display: flex; align-items: center; justify-content: center;
                background: radial-gradient(60% 60% at 50% 40%, #2a2620 0%, #0f0d10 100%); }
.auth-card {
  width: min(420px, 92%); padding: 2rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.55);
  text-align: center;
}
.auth-card .auth-logo {
  display: block; margin: 0 auto 0.6rem; height: 56px;
  filter: brightness(0) invert(1);
}
.auth-card .product-tag {
  display: inline-block; margin: 0 0 0.25rem;
  color: var(--accent); font-weight: 600; letter-spacing: 1.5px; font-size: 0.82rem;
  text-transform: uppercase;
}
.auth-card .sub { color: var(--muted); margin: 0 0 1.4rem; }
.auth-card form { text-align: left; }
.auth-card label { display: block; margin: 0.7rem 0 0.3rem; color: var(--muted); font-size: 11px; letter-spacing: 0.6px; text-transform: uppercase; font-weight: 600; }
.auth-card input { width: 100%; padding: 0.6rem 0.7rem; }
.auth-card button.primary { width: 100%; margin-top: 1.2rem; padding: 0.7rem; justify-content: center; font-size: 14px; }

/* ====== cards (used in admin + paths) ====== */
.card {
  background: linear-gradient(180deg, rgba(36,42,52,0.85) 0%, var(--panel) 100%);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.2rem 1.4rem;
  margin-bottom: 1.2rem;
  box-shadow: 0 6px 22px rgba(0,0,0,0.25);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.card:hover { border-color: var(--line-2); }
.card h2 {
  margin: 0 0 1rem; font-size: 1.05rem; letter-spacing: 0.3px;
  color: var(--ink); font-weight: 600;
  display: flex; align-items: center; gap: 0.5rem;
}
.card h2::before {
  content: ""; width: 4px; height: 18px;
  background: linear-gradient(180deg, var(--accent) 0%, transparent 100%);
  border-radius: 2px;
}
.flex-1 { flex: 1; min-height: 0; }

/* ====== admin page ====== */
/* `display: block` overrides the generic `main { display: grid }` below,
   which is meant for the Live viewer's panel+canvas split. */
.page-admin { display: block; padding: 1.6rem 2rem; width: 100%; max-width: none; margin: 0; }
.add-grid { display: grid; grid-template-columns: 1.3fr 1fr 1.8fr; gap: 0.9rem 1.2rem; align-items: end; }
.add-grid label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 12px; color: var(--muted); letter-spacing: 0.4px; text-transform: uppercase; font-weight: 600; }
.add-grid input, .add-grid select { padding: 0.55rem 0.7rem; font-size: 14px; }
.add-actions { grid-column: 1 / -1; display: flex; gap: 0.6rem; justify-content: flex-end; margin-top: 0.4rem; }

.datatable { width: 100%; border-collapse: separate; border-spacing: 0; }
.datatable th, .datatable td { padding: 0.85rem 1rem; text-align: left; border-bottom: 1px solid var(--line); font-size: 14px; }
.datatable thead th {
  color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.7px;
  font-weight: 600; padding-top: 0.4rem; padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--line-2);
}
.datatable tbody tr { transition: background 0.12s; }
.datatable tbody tr:hover { background: rgba(249, 191, 23, 0.05); }
.datatable tbody tr:last-child td { border-bottom: 0; }
.datatable td.nowrap { white-space: nowrap; }
.type-chip {
  display: inline-block; padding: 4px 0.8rem; border-radius: 999px;
  background: rgba(249, 191, 23, 0.14); color: var(--accent);
  border: 1px solid rgba(249, 191, 23, 0.32);
  font-size: 12px; letter-spacing: 0.3px; font-weight: 600;
}
.row-actions { display: flex; gap: 0.5rem; justify-content: flex-end; flex-wrap: wrap; }

/* API key cell — full key shown, hover-highlight as a copy affordance. */
.key-col { display: flex; align-items: center; gap: 0.6rem; }
code.key-cell {
  display: inline-block; padding: 4px 0.6rem;
  background: rgba(249, 191, 23, 0.08);
  border: 1px solid rgba(249, 191, 23, 0.20);
  border-radius: 5px;
  font: 13px ui-monospace, "JetBrains Mono", monospace;
  color: #f1d77e;
  cursor: pointer;
  user-select: all;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  max-width: 36ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
code.key-cell:hover {
  background: rgba(249, 191, 23, 0.18);
  border-color: rgba(249, 191, 23, 0.50);
  color: var(--accent);
}
code.key-cell.muted { color: var(--muted); cursor: default; background: transparent; border-color: var(--line); }
code.key-cell.muted:hover { background: transparent; border-color: var(--line); color: var(--muted); }
.btn.small { padding: 0.25rem 0.55rem; font-size: 12px; }
.small { font-size: 12px; }

/* ====== toast notifications ====== */
#toast-root {
  position: fixed; top: 70px; right: 24px; z-index: 1000;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: 6px; padding: 0.7rem 1rem;
  font-size: 13px; font-weight: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
  min-width: 220px;
  transform: translateX(20px); opacity: 0;
  transition: transform 0.22s ease-out, opacity 0.22s ease-out;
  pointer-events: auto;
}
.toast.in { transform: translateX(0); opacity: 1; }
.toast-ok  { border-left-color: var(--accent-2); }
.toast-err { border-left-color: var(--danger); }

/* ====== paths page ====== */
.page-paths { display: grid; grid-template-columns: 360px 1fr; gap: 0; flex: 1; min-height: 0; }
.paths-left {
  padding: 1rem; overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
}
.paths-right { position: relative; }
.paths-right canvas { width: 100%; height: 100%; display: block; background: #14161a; cursor: grab; }
.paths-right canvas:active { cursor: grabbing; }
.entries { list-style: none; padding: 0; margin: 0; overflow-y: auto; flex: 1; }
.entries .entry {
  padding: 0.5rem 0.7rem; border-radius: 6px; cursor: pointer;
  border: 1px solid transparent; margin: 2px 0;
}
.entries .entry:hover { background: rgba(249, 191, 23, 0.08); }
.entries .entry.active {
  background: rgba(249, 191, 23, 0.18); border-color: rgba(249, 191, 23, 0.40);
}
.entry-title { font-weight: 600; font-size: 13px; }
.entry-time { font-size: 11px; margin-top: 2px; }

/* ====== Live viewport (existing, kept mostly the same) ====== */
main { display: grid; grid-template-columns: 280px 1fr; flex: 1; min-height: 0; }
main.mode-live { grid-template-columns: 1fr; }
#panel { overflow-y: auto; background: var(--panel); border-right: 1px solid var(--line); padding: 0.5rem 0.85rem; }
#panel section { padding: 0.4rem 0 0.6rem; border-bottom: 1px solid var(--line); }
#panel section:last-child { border-bottom: 0; }
#panel h3 { margin: 0.2rem 0 0.4rem; font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; font-weight: 600; }
#panel .row label { flex: 0 0 6.5rem; color: var(--muted); }
#panel .row input[type="number"], #panel .row input[type="range"] { flex: 1; }
#panel .row .val { width: 3.5rem; text-align: right; font-family: ui-monospace, monospace; color: var(--accent); }

#viewport-wrap { position: relative; }
#viewport { width: 100%; height: 100%; display: block; background: #14161a; cursor: grab; }
#viewport:active { cursor: grabbing; }
#info {
  position: absolute; bottom: 8px; left: 8px; margin: 0; padding: 4px 10px;
  background: rgba(0,0,0,0.55); border: 1px solid var(--line); border-radius: 6px;
  font-family: ui-monospace, monospace; font-size: 11px; color: var(--muted);
  max-width: 60ch; white-space: pre-wrap; z-index: 5;
}

#zoom-controls { position: absolute; bottom: 10px; right: 10px;
                  display: flex; flex-direction: column; gap: 4px; z-index: 11; }
#zoom-controls button {
  width: 34px; height: 34px; font-size: 18px; font-weight: 600; line-height: 1; padding: 0;
  background: rgba(44, 49, 56, 0.92);
}

/* ----- Keys panel (movable + closable, like the Legend) ----------------- */
#kbd-panel {
  position: absolute;
  bottom: 50px; left: 50%; transform: translateX(-50%);
  min-width: 280px;
  background: rgba(22, 25, 31, 0.96);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.55);
  color: var(--ink);
  font-size: 12px;
  user-select: none;
  z-index: 10;
}
#kbd-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 10px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
  cursor: move;
  font-weight: 600; letter-spacing: 0.3px;
  color: var(--accent);
}
#kbd-close {
  background: transparent; border: 0; color: var(--muted); cursor: pointer;
  font-size: 16px; line-height: 1; padding: 0 4px;
}
#kbd-close:hover { color: #fff; }
#kbd-body { padding: 8px 12px 10px; }
.kbd-row { padding: 3px 0; line-height: 1.7; }
kbd {
  display: inline-block;
  min-width: 18px; padding: 1px 6px;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  border-bottom-width: 2px;
  border-radius: 4px;
  font: 11px ui-monospace, "JetBrains Mono", monospace;
  color: var(--ink);
  text-align: center;
}

#warnings { position: absolute; top: 10px; left: 10px; z-index: 9;
            display: flex; flex-direction: column; gap: 6px; pointer-events: none;
            max-width: calc(100% - 280px); }
.warn { background: rgba(245, 159, 0, 0.95); color: #1c1f24;
        padding: 5px 10px; border-radius: 5px; font-size: 12px; font-weight: 600;
        box-shadow: 0 2px 6px rgba(0,0,0,0.45); }
.warn::before { content: "⚠  "; }
.warn.severe { background: rgba(255, 93, 108, 0.95); color: #fff; }

#legend, #data-panel {
  position: absolute; min-width: 260px;
  background: rgba(22, 25, 31, 0.96);
  border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.55); color: var(--ink);
  font-size: 12px; user-select: none; z-index: 10;
}
#legend { top: 10px; right: 10px; }
#data-panel { top: 320px; right: 10px; width: 320px; max-width: 90%; max-height: 50vh;
              display: flex; flex-direction: column; }
#legend-header, #data-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 10px; background: var(--panel-2); border-bottom: 1px solid var(--line);
  border-radius: 8px 8px 0 0; cursor: move;
  font-weight: 600; letter-spacing: 0.3px; color: var(--accent);
}
#legend-close, #data-close {
  background: transparent; border: 0; color: var(--muted); cursor: pointer;
  font-size: 16px; line-height: 1; padding: 0 4px;
}
#legend-close:hover, #data-close:hover { color: #fff; }
#legend-body { padding: 6px 10px 10px; }
#data-body { margin: 0; padding: 6px 10px 10px; overflow: auto;
              font-family: ui-monospace, monospace; font-size: 11px; line-height: 1.35;
              white-space: pre; color: var(--ink); user-select: text; }
.leg { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.sw { flex: 0 0 22px; display: inline-block; text-align: center; }
.sw-wall          { height: 0; border-top: 3px solid #4dd0e1; }
.sw-pallet        { height: 0; border-top: 4px solid #f59f00; }
.sw-robot         { width: 14px; height: 8px; background: rgba(110,168,254,0.20);
                    border: 1px solid #6ea8fe; flex: 0 0 14px; margin: 0 4px; }
.sw-curve         { height: 0; border-top: 2.5px solid #ff5d6c; }
.sw-ctrlpoly      { height: 0; border-top: 1px dashed #b07cff; }
.sw-ctrlpt        { width: 8px; height: 8px; border-radius: 50%; background: #b07cff;
                    margin: 0 7px; flex: 0 0 8px; }
.sw-target        { color: #fff; font-weight: bold; }
.sw-cloud-mid360  { width: 6px; height: 6px; border-radius: 50%; background: #ffd866;
                    margin: 0 8px; flex: 0 0 6px; }
.sw-cloud-pnf     { width: 6px; height: 6px; border-radius: 50%; background: #4dd0e1;
                    margin: 0 8px; flex: 0 0 6px; }
.sw-cloud-allcam  { width: 6px; height: 6px; border-radius: 50%; background: #80e27e;
                    margin: 0 8px; flex: 0 0 6px; }
.sw-entrance      { height: 0; border-top: 2.5px dashed #80e27e; }
.sw-mark-junction { width: 8px; height: 8px; background: #ce93d8; transform: rotate(45deg);
                    margin: 0 7px; flex: 0 0 8px; }
.sw-mark-starting { width: 8px; height: 8px; background: #ffb74d; transform: rotate(45deg);
                    margin: 0 7px; flex: 0 0 8px; }
