/* CynchTrack RTLS — control-room design system
   Ink navy chrome, paper workspace, signal cyan, mono telemetry. */
:root {
  --ink: #0e1b2c;
  --ink-2: #16283f;
  --ink-3: #1f3552;
  --paper: #f4f6f8;
  --panel: #ffffff;
  --line: #dde4ea;
  --text: #1e293b;
  --muted: #64748b;
  --faint: #94a3b8;
  --signal: #0891b2;
  --signal-strong: #0e7490;
  --signal-soft: #e0f2f7;
  --live: #10b981;
  --amber: #d97706;
  --alarm: #dc2626;
  --radius: 10px;
  --font: 'Barlow', -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --shadow: 0 1px 2px rgba(14, 27, 44, 0.06), 0 4px 16px rgba(14, 27, 44, 0.07);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }
a { color: var(--signal-strong); text-decoration: none; }
.mono { font-family: var(--mono); font-size: 12.5px; }

/* ---------- boot splash ---------- */
.boot {
  height: 100vh; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 22px; background: var(--ink);
}
.boot-word { color: #7dd3e8; letter-spacing: 0.42em; font-weight: 700; font-size: 13px; }
.boot-ping { width: 14px; height: 14px; border-radius: 50%; background: var(--signal); position: relative; }
.boot-ping::after {
  content: ''; position: absolute; inset: -12px; border-radius: 50%;
  border: 2px solid var(--signal); animation: ping 1.4s ease-out infinite;
}
@keyframes ping { 0% { transform: scale(0.4); opacity: 1; } 100% { transform: scale(1.8); opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------- auth screens ---------- */
.auth-wrap {
  min-height: 100vh; display: grid; place-items: center; background: var(--ink);
  background-image:
    linear-gradient(rgba(125, 211, 232, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(125, 211, 232, 0.05) 1px, transparent 1px);
  background-size: 44px 44px;
  padding: 24px;
}
.auth-card {
  width: 100%; max-width: 400px; background: var(--panel); border-radius: 14px;
  padding: 36px 34px; box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
}
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.auth-brand .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--signal); box-shadow: 0 0 0 5px var(--signal-soft); }
.auth-brand h1 { font-size: 17px; font-weight: 800; letter-spacing: 0.18em; }
.auth-brand span { color: var(--signal-strong); }
.auth-sub { color: var(--muted); font-size: 13px; margin: -16px 0 22px; }
.field { margin-bottom: 15px; }
.field label { display: block; font-size: 11px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: #fbfcfd; color: var(--text); outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
.field textarea { resize: vertical; min-height: 70px; }
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--signal); box-shadow: 0 0 0 3px rgba(8, 145, 178, 0.15);
}
.form-error { color: var(--alarm); font-size: 13px; margin-bottom: 12px; min-height: 17px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid transparent;
  font-weight: 600; font-size: 13.5px; transition: background 0.12s, border-color 0.12s;
}
.btn-primary { background: var(--signal); color: #fff; }
.btn-primary:hover { background: var(--signal-strong); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn-ghost:hover { background: #eef2f5; }
.btn-danger { background: #fef2f2; color: var(--alarm); border-color: #fecaca; }
.btn-danger:hover { background: #fee2e2; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.55; cursor: default; }

/* ---------- app shell ---------- */
.shell { display: flex; min-height: 100vh; }
.nav {
  width: 216px; flex-shrink: 0; background: var(--ink); color: #b9c7d6;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.nav-brand { display: flex; align-items: center; gap: 10px; padding: 20px 18px 16px; }
.nav-brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--signal); position: relative; }
.nav-brand .dot::after { content: ''; position: absolute; inset: -6px; border-radius: 50%; border: 1.5px solid var(--signal); animation: ping 2.2s ease-out infinite; }
.nav-brand b { color: #f0f6fa; font-size: 14px; letter-spacing: 0.16em; font-weight: 800; }
.nav-section { font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: #5c7189; padding: 16px 18px 6px; }
.nav a.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 9px 18px; color: #b9c7d6;
  font-weight: 500; font-size: 13.5px; border-left: 3px solid transparent;
}
.nav a.nav-item:hover { background: var(--ink-2); color: #e8eff5; }
.nav a.nav-item.active { background: var(--ink-2); color: #fff; border-left-color: var(--signal); }
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.85; }
.nav-foot { margin-top: auto; padding: 14px 18px; border-top: 1px solid var(--ink-3); font-size: 12.5px; }
.nav-foot .who { color: #e8eff5; font-weight: 600; }
.nav-foot .role { color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
.nav-foot button { background: none; border: none; color: #7d94ab; font-size: 12px; margin-top: 6px; padding: 0; }
.nav-foot button:hover { color: #cfe0ee; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 56px; background: var(--panel); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 16px; padding: 0 22px; position: sticky; top: 0; z-index: 20;
}
.topbar h2 { font-size: 16px; font-weight: 700; }
.topbar .spacer { flex: 1; }
.bswitch { display: flex; align-items: center; gap: 8px; }
.bswitch label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); font-weight: 700; }
.bswitch select {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
  font-weight: 600; min-width: 160px;
}
.content { padding: 22px; flex: 1; }

/* ---------- cards / stats ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.stat .k { font-size: 26px; font-weight: 800; font-family: var(--mono); }
.stat .k.warn { color: var(--amber); }
.stat .k.bad { color: var(--alarm); }
.stat .k.live { color: var(--signal-strong); }
.stat .l { color: var(--muted); font-size: 12px; margin-top: 2px; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 20px;
}
.panel-head { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--line); }
.panel-head h3 { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text); }
.panel-head .spacer { flex: 1; }
.panel-body { padding: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.tbl td { padding: 10px 14px; border-bottom: 1px solid #edf1f5; vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr.rowlink { cursor: pointer; }
.tbl tr.rowlink:hover { background: #f6fafc; }
.tbl .empty { color: var(--faint); text-align: center; padding: 28px; }

/* ---------- badges ---------- */
.badge {
  display: inline-block; padding: 2.5px 9px; border-radius: 99px; font-size: 11px;
  font-weight: 700; letter-spacing: 0.03em;
}
.badge.green { background: #d1fae5; color: #065f46; }
.badge.cyan { background: var(--signal-soft); color: var(--signal-strong); }
.badge.gray { background: #eef2f5; color: var(--muted); }
.badge.amber { background: #fef3c7; color: #92400e; }
.badge.red { background: #fee2e2; color: #991b1b; }
.badge.navy { background: #e2e8f0; color: #334155; }

/* ---------- toolbar rows ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input[type="search"], .toolbar input[type="text"] {
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; min-width: 220px; background: #fff;
}
.toolbar select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.toolbar .spacer { flex: 1; }

/* ---------- modal ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(14, 27, 44, 0.55); z-index: 100;
  display: grid; place-items: center; padding: 20px;
}
.modal {
  background: var(--panel); border-radius: 14px; width: 100%; max-width: 560px;
  max-height: 90vh; overflow-y: auto; box-shadow: 0 24px 64px rgba(0, 0, 0, 0.4);
}
.modal.wide { max-width: 820px; }
.modal-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-size: 15px; font-weight: 700; flex: 1; }
.modal-head button { background: none; border: none; font-size: 20px; color: var(--muted); line-height: 1; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); }
.frow { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 560px) { .frow { grid-template-columns: 1fr; } }

/* ---------- toast ---------- */
#toast-root { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--ink); color: #e8eff5; padding: 11px 18px; border-radius: 10px;
  font-size: 13.5px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35); animation: rise 0.2s ease-out;
}
.toast.error { background: #7f1d1d; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- map / builder ---------- */
.map-shell { display: flex; gap: 16px; align-items: stretch; }
.map-side { width: 250px; flex-shrink: 0; display: flex; flex-direction: column; gap: 14px; }
.map-canvas-wrap {
  flex: 1; min-width: 0; background: var(--ink); border-radius: var(--radius);
  position: relative; overflow: hidden; min-height: 68vh; box-shadow: var(--shadow);
  background-image:
    linear-gradient(rgba(125, 211, 232, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(125, 211, 232, 0.06) 1px, transparent 1px);
  background-size: 40px 40px;
}
.map-canvas-wrap svg { display: block; width: 100%; height: 100%; cursor: grab; }
.map-canvas-wrap svg.tool-active { cursor: crosshair; }
.map-canvas-wrap svg:active { cursor: grabbing; }
.map-hud {
  position: absolute; top: 12px; left: 12px; display: flex; gap: 8px; z-index: 5; flex-wrap: wrap;
  flex-direction: column; align-items: flex-start; max-width: calc(100% - 24px);
}
.hud-row { display: flex; gap: 8px; flex-wrap: wrap; }
.hud-row .fx-btn { font-size: 11.5px; padding: 5px 10px; }
.map-hud .hud-btn {
  background: rgba(22, 40, 63, 0.92); color: #cfe0ee; border: 1px solid var(--ink-3);
  border-radius: 8px; padding: 7px 12px; font-size: 12.5px; font-weight: 600;
}
.map-hud .hud-btn:hover { background: var(--ink-3); }
.map-hud .hud-btn.on { background: var(--signal); color: #fff; border-color: var(--signal); }
.map-note {
  position: absolute; bottom: 12px; left: 12px; right: 12px; color: #9fb6ca; font-size: 12px;
  font-family: var(--mono); pointer-events: none; text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}
.floor-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.floor-tab {
  padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff;
  font-weight: 600; font-size: 13px; color: var(--muted);
}
.floor-tab.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.legend { display: flex; flex-direction: column; gap: 8px; font-size: 12.5px; }
.legend .li { display: flex; align-items: center; gap: 9px; color: var(--muted); }
.legend .sw { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }
.room-poly { fill-opacity: 0.16; stroke-width: 1.6; cursor: pointer; }
.room-poly:hover { fill-opacity: 0.3; }
.room-poly.sel { fill-opacity: 0.36; stroke-width: 2.5; }
.zone-poly { fill-opacity: 0.08; stroke-width: 1.8; stroke-dasharray: 7 5; cursor: pointer; }
.zone-poly.sel { fill-opacity: 0.2; }
.room-label { fill: #dbe9f4; font-size: 13px; font-weight: 600; pointer-events: none; font-family: var(--font); }
.room-sub { fill: #7d94ab; font-size: 10px; pointer-events: none; font-family: var(--mono); }
.ant-ring { fill: none; stroke: var(--live); stroke-width: 1.5; opacity: 0.7; animation: antping 2.6s ease-out infinite; transform-origin: center; pointer-events: none; }
@keyframes antping { 0% { opacity: 0.8; } 70% { opacity: 0; } 100% { opacity: 0; } }
.asset-dot { cursor: pointer; }
.map-tip {
  position: absolute; background: rgba(14, 27, 44, 0.95); color: #e8eff5; padding: 8px 12px;
  border-radius: 8px; font-size: 12px; pointer-events: none; z-index: 10; max-width: 260px;
  border: 1px solid var(--ink-3); font-family: var(--mono);
}

/* ---------- catalog ---------- */
.prod-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.prod-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column;
}
.prod-img { height: 150px; background: #fff; display: grid; place-items: center; border-bottom: 1px solid var(--line); }
.prod-img img { max-width: 88%; max-height: 130px; object-fit: contain; }
.prod-img .noimg { color: var(--faint); font-size: 12px; font-family: var(--mono); }
.prod-body { padding: 13px 14px; flex: 1; display: flex; flex-direction: column; gap: 5px; }
.prod-body .mfr { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-weight: 700; }
.prod-body .mdl { font-weight: 700; font-size: 14.5px; }
.prod-body .nm { font-size: 12.5px; color: var(--muted); }
.prod-foot { display: flex; gap: 8px; padding: 0 14px 13px; }

/* ---------- AI assistant sidebar (mirrors cure-data AssistantSidebar) ---------- */
.ai-launch {
  position: fixed; bottom: 20px; right: 20px; z-index: 40; width: 46px; height: 46px;
  border-radius: 50%; background: var(--signal); color: #fff; border: none;
  display: grid; place-items: center; box-shadow: 0 6px 24px rgba(8, 145, 178, 0.5);
}
.ai-launch:hover { background: var(--signal-strong); }
.ai-launch svg { width: 21px; height: 21px; }
.ai-panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 50; width: 100%; max-width: 400px;
  background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column;
  box-shadow: -12px 0 40px rgba(14, 27, 44, 0.18);
  transform: translateX(100%); transition: transform 0.2s ease; pointer-events: none;
}
.ai-panel.open { transform: translateX(0); pointer-events: auto; }
.ai-head { height: 56px; display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid var(--line); }
.ai-head .ttl { font-weight: 700; font-size: 14px; flex: 1; display: flex; align-items: center; gap: 8px; }
.ai-head .ttl svg { width: 16px; height: 16px; color: var(--signal); }
.ai-head button { background: none; border: none; color: var(--muted); padding: 6px; border-radius: 6px; }
.ai-head button:hover { background: #eef2f5; color: var(--text); }
.ai-msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.ai-empty { color: var(--faint); font-size: 12.5px; text-align: center; margin-top: 30px; line-height: 1.7; }
.ai-bubble {
  max-width: 85%; border-radius: 10px; padding: 9px 12px; font-size: 13px;
  white-space: pre-wrap; line-height: 1.55;
}
.ai-bubble.user { margin-left: auto; background: var(--signal); color: #fff; }
.ai-bubble.assistant { background: #eef2f5; color: var(--text); }
.ai-bubble.err { background: #fee2e2; color: #991b1b; }
.ai-foot { border-top: 1px solid var(--line); padding: 12px; display: flex; gap: 9px; align-items: flex-end; }
.ai-foot textarea {
  flex: 1; border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px;
  resize: none; height: 58px; outline: none; font-size: 13px;
}
.ai-foot textarea:focus { border-color: var(--signal); }
.ai-send {
  width: 38px; height: 38px; border-radius: 9px; background: var(--signal); color: #fff;
  border: none; display: grid; place-items: center; flex-shrink: 0;
}
.ai-send[disabled] { opacity: 0.5; }
.ai-hint { font-size: 10px; color: var(--faint); padding: 0 14px 10px; }
.spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- misc ---------- */
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 7px 14px; font-size: 13px; }
.kv .k { color: var(--muted); }
.spec-tbl td { padding: 5px 10px; font-size: 12.5px; }
.spec-tbl td:first-child { color: var(--muted); white-space: nowrap; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.mb0 { margin-bottom: 0; }
.apikey-box {
  background: var(--ink); color: #7dd3e8; font-family: var(--mono); font-size: 12px;
  padding: 10px 12px; border-radius: 8px; word-break: break-all; cursor: pointer;
}
.doc-icon { width: 34px; height: 40px; border-radius: 5px; background: var(--signal-soft); color: var(--signal-strong); display: grid; place-items: center; font-size: 9.5px; font-weight: 800; font-family: var(--mono); }

@media (max-width: 900px) {
  .nav { width: 62px; }
  .nav-brand b, .nav-section, .nav-item span, .nav-foot { display: none; }
  .nav a.nav-item { justify-content: center; padding: 12px 0; }
  .map-shell { flex-direction: column; }
  .map-side { width: 100%; }
}
