/* ==========================================================================
   Visual Inventory Pro — MVP GUI styles
   Dark theme. Primary #89b4fa on #1e1e2e. Font: Segoe UI.
   ========================================================================== */

:root {
  --bg: #1e1e2e;
  --bg-deep: #171724;
  --panel: #232336;
  --card: #2a2a3d;
  --card-2: #31314a;
  --line: #3c3c55;
  --line-soft: #34344b;
  --text: #e8eaf4;
  --muted: #9ba0b8;
  --faint: #6f7390;
  --primary: #89b4fa;
  --primary-strong: #6f9df0;
  --primary-soft: rgba(137, 180, 250, 0.14);
  --green: #a6e3a1;
  --green-soft: rgba(166, 227, 161, 0.13);
  --amber: #f9e2af;
  --amber-soft: rgba(249, 226, 175, 0.13);
  --red: #f38ba8;
  --red-soft: rgba(243, 139, 168, 0.13);
  --blue: #89b4fa;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
  --font: "Segoe UI", -apple-system, BlinkMacSystemFont, "Inter", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: Consolas, "Cascadia Mono", "SF Mono", Menlo, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
}

input,
select,
textarea {
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--bg-deep);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  outline: none;
  width: 100%;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-soft);
}

textarea {
  resize: vertical;
  min-height: 72px;
}

::placeholder {
  color: var(--faint);
}

/* Layout ------------------------------------------------------------------ */

.app-shell {
  display: grid;
  grid-template-columns: 224px 1fr;
  grid-template-rows: 58px 1fr;
  grid-template-areas: "topbar topbar" "sidebar main";
  height: 100vh;
  background: var(--bg);
}

/* Topbar ------------------------------------------------------------------ */

.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px;
  background: var(--bg-deep);
  border-bottom: 1px solid var(--line-soft);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  color: var(--bg-deep);
  background: linear-gradient(135deg, #89b4fa, #6f9df0);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-text strong {
  font-size: 15px;
  letter-spacing: 0.2px;
}

.brand-sub {
  font-size: 11px;
  color: var(--muted);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Pills & buttons ---------------------------------------------------------- */

.pill {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel);
  white-space: nowrap;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pill-muted {
  color: var(--muted);
  font-weight: 500;
}

.pill-conn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.pill-conn::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--amber);
}

.pill-conn.is-live::before {
  background: var(--green);
}

.pill-conn.is-offline::before {
  background: var(--red);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 8px 14px;
  font-weight: 600;
  font-size: 13px;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #131320;
}

.btn-primary:hover {
  background: #a2c4ff;
}

.btn-secondary {
  background: var(--panel);
  border-color: var(--line);
  color: var(--text);
}

.btn-secondary:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
}

.btn-ghost:hover {
  color: var(--text);
  background: var(--panel);
}

.btn-danger {
  background: var(--red-soft);
  border-color: transparent;
  color: var(--red);
}

.btn-danger:hover {
  background: rgba(243, 139, 168, 0.22);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 7px;
}

.btn-block {
  width: 100%;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-icon {
  font-size: 15px;
  line-height: 1;
}

/* Sidebar ----------------------------------------------------------------- */

.sidebar {
  grid-area: sidebar;
  display: flex;
  flex-direction: column;
  background: var(--bg-deep);
  border-right: 1px solid var(--line-soft);
  padding: 12px 10px;
  overflow-y: auto;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  font-size: 13.5px;
}

.nav-item:hover {
  background: var(--panel);
  color: var(--text);
}

.nav-item.is-active {
  background: var(--primary-soft);
  color: var(--primary);
}

.nav-emoji {
  width: 18px;
  text-align: center;
  font-size: 14px;
}

.nav-badge {
  margin-left: auto;
  min-width: 19px;
  height: 19px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--red);
  color: #1b1120;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sidebar-foot {
  margin-top: auto;
  padding: 10px 8px 2px;
  border-top: 1px solid var(--line-soft);
}

.sidebar-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber);
  flex: 0 0 auto;
}

.dot.is-ok {
  background: var(--green);
}

.dot.is-bad {
  background: var(--red);
}

/* Main -------------------------------------------------------------------- */

.main {
  grid-area: main;
  overflow-y: auto;
  padding: 22px 26px 60px;
}

.view-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.view-title {
  margin: 0;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.view-sub {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
  max-width: 780px;
}

.view-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Stat cards --------------------------------------------------------------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.stat-card .stat-value {
  font-size: 27px;
  font-weight: 800;
  line-height: 1.1;
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
}

.stat-card .stat-note {
  font-size: 11.5px;
  color: var(--faint);
  margin-top: 2px;
}

.stat-value.c-green { color: var(--green); }
.stat-value.c-amber { color: var(--amber); }
.stat-value.c-red { color: var(--red); }
.stat-value.c-primary { color: var(--primary); }

/* Cards & lists ------------------------------------------------------------- */

.card {
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 16px;
}

.card + .card {
  margin-top: 12px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.card-title {
  font-weight: 700;
  font-size: 14px;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin: 4px 0 10px;
}

.shelf-row {
  display: grid;
  grid-template-columns: minmax(150px, 1.3fr) 104px 96px minmax(140px, 1fr) minmax(150px, 1.2fr) 16px;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.shelf-row:hover {
  border-color: var(--primary);
  background: var(--card-2);
}

.shelf-row + .shelf-row {
  margin-top: 6px;
}

.shelf-loc {
  font-weight: 700;
  font-size: 14px;
}

.shelf-meta {
  font-size: 11.5px;
  color: var(--faint);
  margin-top: 1px;
}

.shelf-count {
  font-weight: 800;
  font-size: 15px;
}

.shelf-cap {
  font-size: 11.5px;
  color: var(--faint);
}

.delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 7px;
}

.delta-up { background: var(--green-soft); color: var(--green); }
.delta-down { background: var(--red-soft); color: var(--red); }
.delta-flat { background: var(--panel); color: var(--faint); }

/* Chips & badges ------------------------------------------------------------ */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}

.chip-blue { background: var(--primary-soft); color: var(--primary); }
.chip-green { background: var(--green-soft); color: var(--green); }
.chip-amber { background: var(--amber-soft); color: var(--amber); }
.chip-red { background: var(--red-soft); color: var(--red); }
.chip-muted { background: var(--panel); color: var(--muted); }

.src-badge {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 6px;
}

.src-manual { background: var(--primary-soft); color: var(--primary); }
.src-drone { background: rgba(203, 166, 247, 0.16); color: #cba6f7; }

/* Bars (utilization, breakdown) ---------------------------------------------- */

.meter {
  height: 6px;
  background: var(--line-soft);
  border-radius: 999px;
  overflow: hidden;
  min-width: 60px;
}

.meter-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--primary);
}

.breakdown-row {
  display: grid;
  grid-template-columns: 110px 1fr 44px;
  align-items: center;
  gap: 10px;
  margin: 6px 0;
  font-size: 12.5px;
}

.breakdown-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
  margin-right: 7px;
  vertical-align: -1px;
}

/* Timeline ------------------------------------------------------------------- */

.timeline {
  position: relative;
  padding-left: 26px;
}

.timeline::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--line-soft);
  border-radius: 2px;
}

.tl-entry {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color 0.12s ease;
}

.tl-entry:hover {
  border-color: var(--primary);
}

.tl-entry::before {
  content: "";
  position: absolute;
  left: -23px;
  top: 17px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--bg);
}

.tl-entry.is-drone::before {
  background: #cba6f7;
}

.tl-entry.has-disc::before {
  background: var(--amber);
}

.tl-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.tl-date {
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 600;
}

.tl-count {
  font-weight: 800;
  font-size: 15px;
}

.tl-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

/* Detail layout ---------------------------------------------------------------- */

.detail-grid {
  display: grid;
  grid-template-columns: minmax(280px, 340px) 1fr;
  gap: 16px;
  align-items: start;
}

.detail-photo {
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-soft);
  display: block;
  background: var(--bg-deep);
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.three-col {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

@media (max-width: 1180px) {
  .two-col,
  .three-col {
    grid-template-columns: 1fr;
  }
}

/* Comparison photos (discrepancy) --------------------------------------------- */

.compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: start;
}

.compare figure {
  margin: 0;
}

.compare img,
.compare .photo-fallback {
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-soft);
}

.compare figcaption {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}

/* Tables ------------------------------------------------------------------------ */

.table-wrap {
  overflow-x: auto;
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.data th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  font-weight: 700;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
}

table.data td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}

table.data tbody tr:last-child td {
  border-bottom: 0;
}

table.data tbody tr:hover {
  background: var(--card-2);
}

/* Heatmap ----------------------------------------------------------------------- */

.hm-grid {
  display: inline-grid;
  gap: 6px;
}

.hm-cell {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 10.5px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.92);
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.08);
  position: relative;
}

.hm-cell .hm-code {
  font-size: 9.5px;
  opacity: 0.85;
  font-weight: 600;
}

.hm-cell.selected {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.hm-cell.is-empty {
  background: var(--bg-deep) !important;
  cursor: default;
}

.hm-legend {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 12px;
}

.hm-legend .swatch {
  width: 16px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
}

.hm-chart {
  margin-top: 4px;
}

.compare figure {
  min-width: 0;
}

.compare img {
  display: block;
}

@media (max-width: 860px) {
  .shelf-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }
}

.hm-scroll {
  overflow-x: auto;
}

/* Filters / segmented ----------------------------------------------------------- */

.seg {
  display: inline-flex;
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  padding: 3px;
  gap: 2px;
}

.seg button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 12.5px;
  padding: 6px 12px;
  border-radius: 7px;
}

.seg button.is-active {
  background: var(--primary-soft);
  color: var(--primary);
}

.filter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

/* Forms -------------------------------------------------------------------------- */

.form-row {
  margin-bottom: 12px;
}

.form-row label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
}

.form-hint {
  font-size: 11.5px;
  color: var(--faint);
  margin-top: 4px;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.select-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.select-row select {
  width: auto;
  flex: 1;
  min-width: 0;
}

/* Modal -------------------------------------------------------------------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(10, 10, 18, 0.66);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal {
  width: min(760px, 100%);
  max-height: 92vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line-soft);
}

.modal-head h3 {
  margin: 0;
  font-size: 16px;
}

.modal-body {
  padding: 18px;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--line-soft);
}

.modal-close {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 6px;
}

.modal-close:hover {
  color: var(--text);
  background: var(--card);
}

/* Toast --------------------------------------------------------------------------- */

.toast-root {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
}

.toast {
  background: var(--card-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--primary);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: toast-in 0.18s ease;
}

.toast.is-error {
  border-left-color: var(--red);
}

.toast.is-ok {
  border-left-color: var(--green);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Photo fallback + spinner ---------------------------------------------------------- */

.photo-fallback {
  aspect-ratio: 4 / 3;
  display: grid;
  place-items: center;
  background: var(--bg-deep);
  color: var(--faint);
  font-size: 12px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid var(--line);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.spinner-lg {
  width: 34px;
  height: 34px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.center-state {
  display: grid;
  place-items: center;
  gap: 10px;
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}

/* Alert list items -------------------------------------------------------------------- */

.alert-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}

.alert-item + .alert-item {
  margin-top: 8px;
}

.alert-main {
  flex: 1;
  min-width: 0;
}

.alert-title {
  font-weight: 700;
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.alert-desc {
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 3px;
}

.alert-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex: 0 0 auto;
}

.kv {
  font-size: 12.5px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 14px;
}

.kv dt {
  color: var(--faint);
}

.kv dd {
  margin: 0;
  font-weight: 600;
}

.big-num {
  font-size: 30px;
  font-weight: 800;
  line-height: 1;
}

.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.strong { font-weight: 700; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-12 { margin-bottom: 12px; }
.mono { font-family: var(--mono); }

/* Demo-only: the generated shelf photo is an inlined <svg> rather than an
   <img>, because this site's `img-src 'self'` refuses both data: and blob:
   image URLs (both measured against the real policy). The wrapper keeps the
   .detail-photo frame; this rule makes the inline drawing fill it. */
.detail-photo--inline > svg { display: block; width: 100%; height: auto; }

/* Demo-only narrow-width fixes: the shell is a fixed 224px sidebar beside a 1fr
   main and the KPI grid asks for four 150px columns, so at a 320px phone width
   the page scrolled sideways. Below 480px the sidebar becomes a block above the
   content and the KPI grid drops to two columns; nothing changes at desktop
   widths. */
@media (max-width: 480px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
    grid-template-areas: "topbar" "sidebar" "main";
    height: auto;
    min-height: 100vh;
  }
  .main,
  .sidebar { min-width: 0; }
  /* The topbar's single row of brand + pills + button is wider than a 320px
     phone, and as a grid item it set the column's min-content width, which is
     what pushed the page sideways. Let it wrap. */
  .topbar { flex-wrap: wrap; padding: 8px 12px; }
  .topbar-right { flex-wrap: wrap; row-gap: 6px; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
