/* ════════════════════════════════════════════════════════════════════════════
   OSI SURVEILLANCE DESIGN STUDIO — design system
   Aesthetic: tactical command-center. Deep blue-black field, instrument cyan,
   amber warning accent, chamfered corner-cut panels (OSI signature geometry),
   Rajdhani display type + IBM Plex Sans/Mono instrumentation type.
   ════════════════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Rajdhani:wght@500;600;700&family=IBM+Plex+Sans:wght@300;400;500;600&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --ink-0: #06090e;        /* deepest field */
  --ink-1: #0a0f17;        /* app background */
  --ink-2: #0f1722;        /* panel */
  --ink-3: #15202e;        /* raised panel / input */
  --ink-4: #1c2a3b;        /* hover */
  --line-0: rgba(56, 182, 230, 0.10);
  --line-1: rgba(56, 182, 230, 0.22);
  --line-2: rgba(56, 182, 230, 0.45);
  --cyan: #38b6e6;
  --cyan-bright: #5fd0f7;
  --amber: #f0a830;
  --red: #e05c5c;
  --green: #4dd890;
  --violet: #b08cff;
  --text-0: #e8f1f8;       /* primary */
  --text-1: #9fb4c6;       /* secondary */
  --text-2: #5e7689;       /* muted */
  --display: 'Rajdhani', sans-serif;
  --body: 'IBM Plex Sans', sans-serif;
  --mono: 'IBM Plex Mono', monospace;
  --chamfer-lg: polygon(0 0, calc(100% - 16px) 0, 100% 16px, 100% 100%, 16px 100%, 0 calc(100% - 16px));
  --chamfer: polygon(0 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 10px 100%, 0 calc(100% - 10px));
  --chamfer-sm: polygon(0 0, calc(100% - 6px) 0, 100% 6px, 100% 100%, 6px 100%, 0 calc(100% - 6px));
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--ink-1);
  color: var(--text-0);
  font-family: var(--body);
  font-weight: 300;
  font-size: 15px;
  overflow: hidden;
}
/* scan-grid atmosphere */
body::before {
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image:
    linear-gradient(rgba(56,182,230,0.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(56,182,230,0.022) 1px, transparent 1px);
  background-size: 44px 44px;
}
#root { position: relative; z-index: 1; height: 100vh; display: flex; flex-direction: column; }

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--ink-1); }
::-webkit-scrollbar-thumb { background: var(--line-1); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--cyan); }
::selection { background: rgba(56,182,230,0.3); }

/* ── type utilities ─────────────────────────────────────────────────────────── */
.eyebrow {
  font-family: var(--display); font-size: 0.68rem; font-weight: 600;
  letter-spacing: 0.22em; text-transform: uppercase; color: var(--cyan);
}
.h-display {
  font-family: var(--display); font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.04em; line-height: 1.08; color: var(--text-0);
}
.mono { font-family: var(--mono); }
.muted { color: var(--text-2); }
.sec { color: var(--text-1); }

/* ── buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  font-family: var(--display); font-weight: 600; font-size: 0.82rem;
  letter-spacing: 0.1em; text-transform: uppercase;
  background: var(--ink-3); color: var(--text-1);
  border: 1px solid var(--line-1); cursor: pointer;
  padding: 0.5rem 1.1rem; clip-path: var(--chamfer-sm);
  transition: border-color .18s, color .18s, background .18s;
  white-space: nowrap; text-decoration: none; user-select: none;
}
.btn:hover { border-color: var(--cyan); color: var(--cyan-bright); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: var(--cyan); color: var(--ink-0); border-color: var(--cyan); font-weight: 700; }
.btn.primary:hover { background: var(--cyan-bright); color: var(--ink-0); }
.btn.danger:hover { border-color: var(--red); color: var(--red); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { border-color: var(--line-1); }
.btn.sm { padding: 0.3rem 0.7rem; font-size: 0.72rem; }
.btn.active { border-color: var(--cyan); color: var(--cyan-bright); background: rgba(56,182,230,0.10); }

/* ── inputs ─────────────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field label {
  font-family: var(--display); font-size: 0.7rem; font-weight: 600;
  letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-2);
}
.input, select.input, textarea.input {
  background: var(--ink-3); border: 1px solid var(--line-1); color: var(--text-0);
  font-family: var(--body); font-size: 0.9rem; padding: 0.55rem 0.8rem;
  outline: none; transition: border-color .18s; width: 100%;
}
.input:focus { border-color: var(--cyan); }
.input::placeholder { color: var(--text-2); }
textarea.input { resize: vertical; min-height: 80px; }
input[type="range"] { width: 100%; accent-color: var(--cyan); }
.input.compact { width: 70px; padding: 0.3rem 0.5rem; font-size: 0.8rem; font-family: var(--mono); }

/* ── panels & cards ─────────────────────────────────────────────────────────── */
.panel {
  background: var(--ink-2); border: 1px solid var(--line-0);
  clip-path: var(--chamfer);
}
.card {
  background: var(--ink-2); border: 1px solid var(--line-0);
  clip-path: var(--chamfer); padding: 1.1rem;
  transition: border-color .18s, background .18s;
}
.card.clickable { cursor: pointer; }
.card.clickable:hover { border-color: var(--line-2); background: var(--ink-3); }
.card.selected { border-color: var(--cyan); background: rgba(56,182,230,0.06); }

.chip {
  display: inline-flex; align-items: center; gap: 0.3rem;
  font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.05em;
  padding: 0.12rem 0.5rem; border: 1px solid var(--line-1); color: var(--text-1);
  text-transform: uppercase; white-space: nowrap;
}
.chip.warn { border-color: rgba(240,168,48,0.5); color: var(--amber); }
.chip.ok { border-color: rgba(77,216,144,0.4); color: var(--green); }
.chip.err { border-color: rgba(224,92,92,0.5); color: var(--red); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* ── topbar ─────────────────────────────────────────────────────────────────── */
.topbar {
  flex-shrink: 0; height: 56px; display: flex; align-items: center; gap: 1rem;
  padding: 0 1rem; background: rgba(6,9,14,0.92);
  border-bottom: 1px solid var(--line-0); backdrop-filter: blur(10px);
}
.topbar .brand { display: flex; align-items: center; gap: 0.6rem; text-decoration: none; cursor: pointer; }
.topbar .brand img { height: 32px; }
.topbar .brand-name {
  font-family: var(--display); font-weight: 700; font-size: 0.92rem;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-0); line-height: 1.05;
}
.topbar .brand-name small { display: block; font-size: 0.6rem; color: var(--cyan); letter-spacing: 0.18em; font-weight: 600; }
.topbar .sep { width: 1px; height: 26px; background: var(--line-1); }
.topbar .spacer { flex: 1; }
.topbar .nav-link {
  font-family: var(--display); font-size: 0.78rem; font-weight: 600; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--text-2); text-decoration: none; cursor: pointer;
  padding: 0.3rem 0.6rem; transition: color .18s; background: none; border: none;
}
.topbar .nav-link:hover, .topbar .nav-link.active { color: var(--cyan-bright); }

/* ── views ──────────────────────────────────────────────────────────────────── */
.view { flex: 1; overflow-y: auto; padding: 2rem clamp(1rem, 4vw, 3rem); }
.view-narrow { max-width: 1100px; margin: 0 auto; width: 100%; }

/* ── auth screens ───────────────────────────────────────────────────────────── */
.auth-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.auth-card {
  width: 100%; max-width: 440px; background: var(--ink-2);
  border: 1px solid var(--line-1); clip-path: var(--chamfer-lg);
  padding: 2.2rem 2.2rem 1.8rem; position: relative;
}
.auth-card::before {
  content: ''; position: absolute; top: 0; left: 0; width: 60px; height: 2px;
  background: var(--cyan);
}
.auth-title { font-size: 1.65rem; margin: 0.3rem 0 0.4rem; }
.auth-sub { color: var(--text-1); font-size: 0.86rem; line-height: 1.6; margin-bottom: 1.5rem; }
.auth-form { display: flex; flex-direction: column; gap: 0.95rem; }
.auth-alt { margin-top: 1.2rem; font-size: 0.8rem; color: var(--text-2); text-align: center; }
.auth-alt a, a.link { color: var(--cyan); text-decoration: none; cursor: pointer; }
.auth-alt a:hover, a.link:hover { color: var(--cyan-bright); }
.form-error { color: var(--red); font-size: 0.8rem; line-height: 1.45; display: none; }
.form-error.show { display: block; }

/* ── dashboard ──────────────────────────────────────────────────────────────── */
.dash-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.6rem; flex-wrap: wrap; }
.dash-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 1rem; }
.prj-thumb {
  height: 120px; background: var(--ink-0); margin: -1.1rem -1.1rem 0.8rem;
  background-size: cover; background-position: center;
  border-bottom: 1px solid var(--line-0); position: relative;
}
.prj-thumb .scene-tag { position: absolute; bottom: 6px; left: 8px; }
.prj-name { font-family: var(--display); font-weight: 600; font-size: 1.02rem; letter-spacing: 0.02em; }
.prj-meta { font-size: 0.72rem; color: var(--text-2); margin-top: 0.25rem; font-family: var(--mono); }

/* ── modal ──────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 900; background: rgba(6,9,14,0.86);
  display: flex; align-items: center; justify-content: center; backdrop-filter: blur(6px);
  padding: 1.5rem;
}
.modal {
  background: var(--ink-2); border: 1px solid var(--line-1); clip-path: var(--chamfer-lg);
  padding: 1.8rem; width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
}
.modal.wide { max-width: 860px; }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 1.2rem; }
.modal-title { font-size: 1.3rem; }
.modal-close { background: none; border: none; color: var(--text-2); font-size: 1.3rem; cursor: pointer; line-height: 1; }
.modal-close:hover { color: var(--text-0); }

/* ── studio layout ──────────────────────────────────────────────────────────── */
.studio { flex: 1; display: flex; overflow: hidden; }
.studio-side {
  width: 248px; flex-shrink: 0; background: var(--ink-2);
  border-right: 1px solid var(--line-0); display: flex; flex-direction: column; overflow: hidden;
}
.side-tabs { display: flex; border-bottom: 1px solid var(--line-0); flex-shrink: 0; }
.side-tab {
  flex: 1; background: none; border: none; cursor: pointer; padding: 0.6rem 0.2rem;
  font-family: var(--display); font-size: 0.7rem; font-weight: 600; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--text-2); border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
}
.side-tab:hover { color: var(--text-1); }
.side-tab.active { color: var(--cyan-bright); border-bottom-color: var(--cyan); }
.side-body { flex: 1; overflow-y: auto; padding: 0.6rem; display: flex; flex-direction: column; gap: 0.45rem; }

.lib-card {
  background: var(--ink-3); border: 1px solid var(--line-0); padding: 0.65rem 0.7rem;
  cursor: pointer; clip-path: var(--chamfer-sm); user-select: none;
  transition: border-color .15s, background .15s;
}
.lib-card:hover { border-color: var(--line-2); }
.lib-card.active { border-color: var(--cyan); background: rgba(56,182,230,0.07); }
.lib-card .top { display: flex; align-items: center; gap: 0.5rem; }
.lib-card .name { font-family: var(--display); font-weight: 700; font-size: 0.86rem; line-height: 1.15; }
.lib-card .cat { font-size: 0.64rem; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.06em; display: flex; align-items: center; gap: 0.3rem; margin-top: 0.1rem; }
.lib-card .spec { font-size: 0.68rem; color: var(--text-2); margin-top: 0.4rem; font-family: var(--mono); line-height: 1.5; }
.lib-cat-head { margin: 0.5rem 0.2rem 0.1rem; }

/* studio main */
.studio-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.studio-toolbar {
  flex-shrink: 0; display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  padding: 0.4rem 0.7rem; background: var(--ink-2); border-bottom: 1px solid var(--line-0);
}
.tb-label { font-family: var(--display); font-size: 0.68rem; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-2); white-space: nowrap; }
.tb-sep { width: 1px; height: 20px; background: var(--line-1); flex-shrink: 0; }
.tb-group { display: flex; align-items: center; gap: 0.4rem; }
.unit-toggle { display: inline-flex; border: 1px solid var(--line-1); }
.unit-toggle button {
  background: var(--ink-3); border: none; color: var(--text-1); cursor: pointer;
  font-family: var(--display); font-weight: 600; font-size: 0.74rem; letter-spacing: 0.06em;
  text-transform: uppercase; padding: 0.26rem 0.6rem; transition: background .15s, color .15s;
}
.unit-toggle button + button { border-left: 1px solid var(--line-1); }
.unit-toggle button.active { background: var(--cyan); color: var(--ink-0); }

.canvas-wrap { flex: 1; position: relative; overflow: hidden; background: var(--ink-0); }
#studio-canvas { display: block; position: absolute; inset: 0; cursor: crosshair; }
.canvas-hint {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 0.8rem;
  align-items: center; justify-content: center; pointer-events: none; text-align: center;
  transition: opacity .3s;
}
.canvas-hint.hidden { opacity: 0; }

.draw-toast {
  position: absolute; bottom: 44px; left: 50%; transform: translateX(-50%);
  background: rgba(10,15,23,0.95); border: 1px solid var(--line-2); color: var(--text-1);
  font-size: 0.78rem; padding: 0.5rem 1rem; clip-path: var(--chamfer-sm);
  pointer-events: none; display: none; max-width: 92%; text-align: center; z-index: 40;
}
.draw-toast.show { display: block; }
.draw-toast b { color: var(--cyan); font-weight: 600; }

/* properties panel */
.studio-props {
  width: 252px; flex-shrink: 0; background: var(--ink-2);
  border-left: 1px solid var(--line-0); display: flex; flex-direction: column; overflow: hidden;
}
.props-head { padding: 0.8rem 0.95rem 0.65rem; border-bottom: 1px solid var(--line-0); flex-shrink: 0; }
.props-body { flex: 1; overflow-y: auto; padding: 0.85rem 0.95rem; }
.spec-row { display: flex; justify-content: space-between; gap: 0.6rem; font-size: 0.76rem; padding: 0.28rem 0; border-bottom: 1px solid rgba(56,182,230,0.05); }
.spec-row .k { color: var(--text-2); flex-shrink: 0; }
.spec-row .v { color: var(--text-1); text-align: right; font-family: var(--mono); font-size: 0.72rem; }
.props-disclaimer { padding: 0.6rem 0.95rem; border-top: 1px solid var(--line-0); font-size: 0.64rem; color: var(--text-2); line-height: 1.5; flex-shrink: 0; }
.prop-divider { border: none; border-top: 1px solid var(--line-0); margin: 0.8rem 0; }

/* status bar */
.statusbar {
  flex-shrink: 0; display: flex; align-items: center; gap: 1.1rem; flex-wrap: wrap;
  padding: 0.32rem 0.9rem; background: var(--ink-2); border-top: 1px solid var(--line-0);
  font-family: var(--mono); font-size: 0.68rem; color: var(--text-2);
}
.statusbar b { color: var(--cyan); font-weight: 500; }
.statusbar .warn { color: var(--amber); }
.statusbar .spacer { flex: 1; }

/* ── consultant dock ────────────────────────────────────────────────────────── */
.consultant-dock {
  position: absolute; right: 14px; bottom: 14px; width: 380px; max-width: calc(100% - 28px);
  height: 480px; max-height: 70%;
  background: var(--ink-2); border: 1px solid var(--line-1); clip-path: var(--chamfer-lg);
  display: none; flex-direction: column; z-index: 50; overflow: hidden;
}
.consultant-dock.open { display: flex; }
.chat-head { display: flex; align-items: center; gap: 0.55rem; padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--line-0); flex-shrink: 0; }
.chat-body { flex: 1; overflow-y: auto; padding: 0.9rem; display: flex; flex-direction: column; gap: 0.7rem; }
.chat-msg { max-width: 88%; padding: 0.55rem 0.8rem; font-size: 0.82rem; line-height: 1.55; white-space: pre-wrap; clip-path: var(--chamfer-sm); }
.chat-msg.user { align-self: flex-end; background: rgba(56,182,230,0.13); border: 1px solid var(--line-1); }
.chat-msg.assistant { align-self: flex-start; background: var(--ink-3); border: 1px solid var(--line-0); color: var(--text-1); }
.chat-input-row { display: flex; gap: 0.5rem; padding: 0.7rem; border-top: 1px solid var(--line-0); flex-shrink: 0; }
.fab {
  position: absolute; right: 14px; bottom: 14px; z-index: 49;
  display: flex; align-items: center; gap: 0.5rem;
  background: var(--cyan); color: var(--ink-0); border: none; cursor: pointer;
  font-family: var(--display); font-weight: 700; font-size: 0.8rem; letter-spacing: 0.1em;
  text-transform: uppercase; padding: 0.62rem 1.1rem; clip-path: var(--chamfer);
  box-shadow: 0 6px 26px rgba(56,182,230,0.25);
}
.fab:hover { background: var(--cyan-bright); }

/* ── onboarding / tour ──────────────────────────────────────────────────────── */
.tour-ring {
  position: fixed; border: 2px solid var(--cyan); border-radius: 4px; z-index: 950;
  pointer-events: none; transition: all .3s ease;
  animation: tourPulse 1.5s ease-out infinite;
}
@keyframes tourPulse {
  0% { box-shadow: 0 0 0 0 rgba(56,182,230,0.5); }
  70% { box-shadow: 0 0 0 12px rgba(56,182,230,0); }
  100% { box-shadow: 0 0 0 0 rgba(56,182,230,0); }
}
.tour-tip {
  position: fixed; z-index: 951; width: 290px; background: var(--ink-2);
  border: 1px solid var(--line-2); clip-path: var(--chamfer); padding: 1rem 1.1rem;
  transition: top .3s, left .3s;
}
.tour-tip .step { margin-bottom: 0.3rem; }
.tour-tip .txt { font-size: 0.82rem; color: var(--text-1); line-height: 1.55; margin-bottom: 0.85rem; }
.tour-actions { display: flex; justify-content: space-between; align-items: center; }

/* ── help drawer ────────────────────────────────────────────────────────────── */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 460px; max-width: 94vw; z-index: 920;
  background: var(--ink-2); border-left: 1px solid var(--line-1);
  transform: translateX(102%); transition: transform .25s ease;
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 0.9rem 1.2rem; border-bottom: 1px solid var(--line-0); flex-shrink: 0; }
.drawer-body { flex: 1; overflow-y: auto; padding: 1.1rem 1.2rem; }
.help-article h3 { font-family: var(--display); font-size: 1rem; text-transform: uppercase; letter-spacing: 0.05em; margin: 1.1rem 0 0.4rem; color: var(--text-0); }
.help-article p, .help-article li { font-size: 0.84rem; color: var(--text-1); line-height: 1.65; }
.help-article ul, .help-article ol { padding-left: 1.2rem; margin: 0.4rem 0; }
.help-article code { font-family: var(--mono); font-size: 0.76rem; color: var(--cyan-bright); }

/* ── tables ─────────────────────────────────────────────────────────────────── */
.tbl { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.tbl th {
  font-family: var(--display); font-size: 0.66rem; font-weight: 600; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--text-2); text-align: left;
  padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--line-1);
}
.tbl td { padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--line-0); color: var(--text-1); }
.tbl td.mono, .tbl .num { font-family: var(--mono); font-size: 0.74rem; }
.tbl .num { text-align: right; }

/* ── toast notifications ────────────────────────────────────────────────────── */
.toasts { position: fixed; top: 66px; right: 16px; z-index: 990; display: flex; flex-direction: column; gap: 0.5rem; }
.toast {
  background: var(--ink-2); border: 1px solid var(--line-2); color: var(--text-0);
  padding: 0.65rem 1rem; font-size: 0.82rem; clip-path: var(--chamfer-sm);
  animation: toastIn .25s ease; max-width: 360px;
}
.toast.err { border-color: var(--red); }
.toast.ok { border-color: var(--green); }
@keyframes toastIn { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── misc ───────────────────────────────────────────────────────────────────── */
.row { display: flex; align-items: center; gap: 0.6rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; }
.mt1 { margin-top: 0.5rem; } .mt2 { margin-top: 1rem; } .mt3 { margin-top: 1.6rem; }
.mb1 { margin-bottom: 0.5rem; } .mb2 { margin-bottom: 1rem; }
.small { font-size: 0.78rem; }
.tiny { font-size: 0.68rem; }
.hidden { display: none !important; }

/* gauges in summary */
.gauge { height: 6px; background: var(--ink-0); border: 1px solid var(--line-0); position: relative; overflow: hidden; }
.gauge > i { position: absolute; inset: 0 auto 0 0; background: var(--cyan); display: block; }
.gauge.warn > i { background: var(--amber); }
.gauge.err > i { background: var(--red); }

@media (max-width: 1100px) { .studio-props { display: none; } }
@media (max-width: 860px) {
  .studio-side { width: 200px; }
  .topbar .brand-name small { display: none; }
}
@media (max-width: 640px) { .studio-side { display: none; } .grid2 { grid-template-columns: 1fr; } }

@media print {
  body { overflow: visible; background: #fff; color: #111; }
  body::before { display: none; }
  .topbar, .studio-side, .studio-props, .studio-toolbar, .statusbar, .fab, .consultant-dock, .toasts, .drawer { display: none !important; }
}
