:root {
  color-scheme: light;
  --canvas: #f3f6f8;
  --surface: #ffffff;
  --surface-muted: #f7f9fb;
  --ink: #172133;
  --ink-soft: #344054;
  --muted: #6c7789;
  --line: #dfe5eb;
  --line-strong: #cbd5df;
  --navy: #0b1728;
  --teal: #079d8b;
  --teal-dark: #067567;
  --blue: #2e6cba;
  --amber: #a66309;
  --red: #b13a32;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-md: 0 10px 30px rgba(28, 39, 55, .07);
  --shadow-lg: 0 24px 70px rgba(7, 19, 34, .22);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  font-family: Inter, Aptos, "Segoe UI Variable", "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--canvas); }

body {
  min-height: 100vh;
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

button,
input,
select,
textarea { font: inherit; }

button,
.file-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink-soft);
  padding: 9px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  transition: border-color .16s ease, background-color .16s ease, color .16s ease, box-shadow .16s ease, transform .16s ease;
}

button:hover,
.file-button:hover { border-color: #aebbc8; background: var(--surface-muted); }

button:active,
.file-button:active { transform: translateY(1px); }

button:focus-visible,
.file-button:focus-within,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(7, 157, 139, .2);
  outline-offset: 2px;
}

h1,
h2,
p { margin-top: 0; }

h1,
h2 { text-wrap: balance; }

h1 { margin-bottom: 0; }

h2 {
  margin-bottom: 8px;
  font-size: 18px;
  line-height: 1.25;
  letter-spacing: -.025em;
}

.eyebrow,
.brand-kicker,
.sidebar-label {
  margin: 0;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.eyebrow { margin-bottom: 7px; color: var(--teal-dark); }

.primary {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
  box-shadow: 0 5px 14px rgba(7, 117, 103, .16);
}

.primary:hover { border-color: var(--teal-dark); background: var(--teal-dark); color: #fff; }

/* Authentication */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at 72% 16%, rgba(21, 154, 140, .18), transparent 25rem), linear-gradient(135deg, #081321, #10233a);
}

.login-card {
  width: min(100%, 410px);
  display: grid;
  gap: 16px;
  padding: 34px;
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, .98);
  box-shadow: var(--shadow-lg);
}

.login-card img {
  width: 112px;
  height: 82px;
  object-fit: contain;
  justify-self: center;
}

.login-card h1 { color: var(--ink); font-size: 30px; letter-spacing: -.04em; }
.login-error { min-height: 18px; margin: 0; color: var(--red); font-size: 13px; font-weight: 700; }
.login-hint { margin: 0; color: var(--muted); font-size: 12px; text-align: center; }

/* Application shell */
.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px 18px 18px;
  overflow-y: auto;
  background: var(--navy);
  color: white;
  box-shadow: inset -1px 0 rgba(255, 255, 255, .06);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 0 4px;
}

.logo-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 11px;
  background: white;
}

.logo-mark img { width: 100%; height: 100%; object-fit: contain; padding: 3px; }

.brand-block h1 {
  overflow: hidden;
  color: white;
  font-size: 17px;
  line-height: 1.2;
  letter-spacing: -.02em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-kicker { margin-bottom: 3px; color: #70d9cd; font-size: 8px; }
.brand-subtitle { margin: 2px 0 0; color: rgba(255, 255, 255, .54); font-size: 11px; }
.sidebar-label { padding: 0 10px; color: rgba(255, 255, 255, .4); }

.actions { display: flex; flex: 1; flex-direction: column; gap: 6px; }

.actions button,
.actions .file-button {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 11px;
  justify-content: flex-start;
  border-color: transparent;
  background: transparent;
  color: rgba(255, 255, 255, .68);
  padding: 10px 11px;
  box-shadow: none;
  text-align: left;
}

.actions svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.actions button:hover,
.actions .file-button:hover {
  border-color: rgba(255, 255, 255, .05);
  background: rgba(255, 255, 255, .07);
  color: white;
}

.actions .nav-action[aria-pressed="true"] {
  border-color: rgba(80, 210, 195, .18);
  background: rgba(7, 157, 139, .18);
  color: #8ce8de;
  box-shadow: inset 3px 0 var(--teal);
}

.tools-label { margin-top: 20px; margin-bottom: 4px; }
.logout-action { margin-top: auto; }

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, .035);
}

.connection-status > span:last-child { display: grid; gap: 2px; }
.connection-status strong { color: rgba(255, 255, 255, .84); font-size: 11px; }
.connection-status small { color: rgba(255, 255, 255, .42); font-size: 10px; }

.connection-dot,
.signal-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
}

.signal-dot,
.connection-status[data-state="online"] .connection-dot {
  background: #35c697;
  box-shadow: 0 0 0 4px rgba(53, 198, 151, .12);
}

.connection-status[data-state="offline"] .connection-dot {
  background: #ef5b66;
  box-shadow: 0 0 0 4px rgba(239, 91, 102, .13);
}

.app-main {
  width: 100%;
  min-width: 0;
  max-width: 1600px;
  margin: 0 auto;
  padding: 30px clamp(20px, 3vw, 48px) 44px;
}

/* Dashboard */
.home-screen { display: grid; gap: 18px; }

.home-screen > *,
.home-panels > *,
.stats-grid > * { min-width: 0; }

.home-hero,
.available-preview,
.brand-preview,
.home-panel,
.stat-card,
.inventory,
.movement-log {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.home-hero {
  position: relative;
  min-height: 242px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px 32px;
  overflow: hidden;
  padding: clamp(28px, 4vw, 48px);
  border-color: transparent;
  background: var(--navy);
  color: white;
  box-shadow: var(--shadow-md);
}

.home-hero::after {
  content: "";
  position: absolute;
  width: 360px;
  height: 360px;
  right: -130px;
  top: -190px;
  border: 58px solid rgba(35, 183, 165, .08);
  border-radius: 50%;
  pointer-events: none;
}

.home-hero-copy,
.availability-console,
.home-hero-actions { position: relative; z-index: 1; }
.home-hero .eyebrow { color: #70d9cd; }

.home-hero h2 {
  max-width: 650px;
  margin-bottom: 13px;
  color: white;
  font-size: clamp(32px, 4vw, 48px);
  line-height: 1.02;
  letter-spacing: -.055em;
}

.home-hero p:not(.eyebrow) {
  max-width: 640px;
  margin-bottom: 0;
  color: rgba(255, 255, 255, .66);
  font-size: 15px;
  line-height: 1.65;
}

.availability-console {
  min-width: 205px;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 6px 10px;
  padding: 19px;
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 15px;
  background: rgba(255, 255, 255, .055);
}

.availability-console span:not(.signal-dot) {
  color: #8ce8de;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.availability-console strong,
.availability-console small { grid-column: 1 / -1; }

.availability-console strong {
  margin-top: 7px;
  color: white;
  font-size: 46px;
  line-height: 1;
  letter-spacing: -.05em;
}

.availability-console small { color: rgba(255, 255, 255, .5); font-size: 11px; }

.home-hero-actions { grid-column: 1 / -1; display: flex; gap: 9px; }

.home-hero-actions button:not(.primary) {
  border-color: rgba(255, 255, 255, .16);
  background: transparent;
  color: rgba(255, 255, 255, .82);
}

.home-hero-actions button:not(.primary):hover { background: rgba(255, 255, 255, .08); color: white; }

.stats-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }

.stat-card {
  position: relative;
  min-height: 118px;
  display: grid;
  align-content: center;
  gap: 9px;
  overflow: hidden;
  padding: 22px 24px;
}

.stat-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--teal);
}

.stat-card::after {
  content: "";
  position: absolute;
  width: 72px;
  height: 72px;
  right: 22px;
  border: 1px solid currentColor;
  border-radius: 50%;
  opacity: .08;
}

.stat-card span,
.brand-card span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.stat-card strong { font-size: 38px; line-height: 1; letter-spacing: -.05em; }
.stat-assigned::before { background: var(--blue); }

.available-preview,
.brand-preview,
.home-panel,
.inventory,
.movement-log { padding: 22px; }

.brand-preview-head,
.inventory-head,
.editor-head,
.query-head,
.home-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand-preview-head,
.inventory-head { margin-bottom: 17px; }

.brand-preview-head p,
.inventory-head p,
.home-panel p,
.movement-log p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.brand-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }

button.brand-card {
  position: relative;
  min-height: 108px;
  display: grid;
  gap: 7px;
  overflow: hidden;
  padding: 17px;
  border-color: var(--line);
  background: var(--surface-muted);
  text-align: left;
}

button.brand-card:hover {
  border-color: #b8c5d0;
  background: white;
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.brand-card strong { color: var(--ink); font-size: 32px; line-height: 1; letter-spacing: -.04em; }
.brand-card small,
.empty-brand-preview { color: var(--muted); font-size: 12px; }

.empty-brand-preview {
  margin: 0;
  padding: 14px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface-muted);
}

.home-panels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.home-panel { min-height: 138px; }

/* Inventory workspace */
.workspace,
.inventory { min-width: 0; }

.filters,
.form-actions { display: flex; flex-wrap: wrap; gap: 9px; }

.filters {
  margin-bottom: 16px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-muted);
}

.filters input { flex: 1 1 300px; }
.filters select { flex: 0 1 180px; }
form { display: grid; gap: 13px; }

label {
  display: grid;
  gap: 6px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  outline: none;
  background: white;
  color: var(--ink);
  transition: border-color .16s ease, box-shadow .16s ease;
}

input::placeholder,
textarea::placeholder { color: #99a2b1; }

input:focus,
select:focus,
textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(7, 157, 139, .1); }

textarea { min-height: 86px; resize: vertical; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }

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

table {
  width: 100%;
  min-width: 760px;
  border-collapse: separate;
  border-spacing: 0;
  background: white;
  font-size: 13px;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid #e8edf1;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f6f8fa;
  color: #596579;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .095em;
  text-transform: uppercase;
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background-color .14s ease; }
tbody tr:hover { background: #f7fbfa; }
.preview-table { min-width: 620px; }
.readonly-table { min-width: 680px; }
.name-cell strong { display: block; color: var(--ink); font-size: 13px; }
.name-cell small,
.notes { color: var(--muted); }

.notes { max-width: 330px; margin-top: 5px; font-size: 11px; line-height: 1.4; }

.thumb-link {
  width: 62px;
  height: 46px;
  min-height: 46px;
  display: block;
  margin-top: 7px;
  overflow: hidden;
  padding: 0;
  border-color: var(--line-strong);
  border-radius: 7px;
  background: #edf1f4;
}

.thumb-link:hover {
  border-color: var(--teal);
  background: #edf1f4;
  box-shadow: 0 0 0 3px rgba(7, 157, 139, .1);
  transform: none;
}

.thumb-link img,
.image-preview img { width: 100%; height: 100%; display: block; object-fit: cover; }
.image-preview { min-height: 0; display: flex; align-items: center; gap: 10px; }
.image-preview img { width: 92px; height: 68px; border: 1px solid var(--line); border-radius: var(--radius-sm); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.Available { border-color: #bde8dc; background: #eaf8f4; color: var(--teal-dark); }
.Assigned { border-color: #cbdcf0; background: #edf4fb; color: var(--blue); }
.In-repair { border-color: #ecd7ae; background: #fff7e7; color: var(--amber); }
.Retired,
.low { border-color: #ecc8c5; background: #fdf0ef; color: var(--red); }

.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.row-actions button { min-height: 30px; padding: 5px 9px; font-size: 11px; }
.empty { display: none; margin: 0; padding: 24px; color: var(--muted); text-align: center; }

.movement-log {
  margin-top: 16px;
  display: grid;
  grid-template-columns: minmax(220px, 320px) 1fr;
  gap: 20px;
}

.movement-log ol { margin: 0; padding-left: 20px; color: var(--ink-soft); font-size: 13px; line-height: 1.5; }
.movement-log li + li { margin-top: 6px; }

/* Editors and viewers */
.editor-screen,
.query-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(5, 14, 26, .76);
  backdrop-filter: blur(10px);
}

.editor-card,
.query-card {
  width: min(100%, 760px);
  max-height: calc(100vh - 36px);
  overflow: auto;
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}

.query-card { width: min(100%, 920px); }

.editor-head,
.query-head { margin-bottom: 20px; padding-bottom: 15px; border-bottom: 1px solid var(--line); }

.editor-head h2,
.query-head h2 { margin-bottom: 0; }

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 30;
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  border: 0;
  background: rgba(4, 11, 20, .88);
  backdrop-filter: blur(12px);
}

.image-viewer:not([open]) { display: none; }
.image-viewer::backdrop { background: transparent; }

.image-viewer-card {
  width: min(100%, 1120px);
  max-height: calc(100vh - 36px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: var(--radius-lg);
  background: #081321;
  box-shadow: 0 36px 100px rgba(0, 0, 0, .54);
}

.image-viewer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: white; }
.image-viewer-head h2 { margin: 0; }
.image-viewer-head button { border-color: rgba(255, 255, 255, .16); background: rgba(255, 255, 255, .08); color: white; }

.image-viewer-card > img {
  width: 100%;
  max-height: calc(100vh - 122px);
  object-fit: contain;
  border-radius: var(--radius-md);
  background: #020711;
}

@media (max-width: 1080px) {
  .home-hero { grid-template-columns: 1fr; }
  .availability-console { width: min(100%, 320px); }
}

@media (max-width: 860px) {
  .app-shell { display: block; }

  .topbar {
    position: sticky;
    height: auto;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    padding: 12px 16px;
    overflow: visible;
  }

  .topbar > .sidebar-label,
  .tools-label { display: none; }

  .connection-status {
    grid-column: 1 / -1;
    padding: 8px 10px;
  }

  .actions { flex-direction: row; align-items: center; }

  .actions button,
  .actions .file-button {
    width: auto;
    min-height: 40px;
    justify-content: center;
    padding: 9px 11px;
  }

  .actions .logout-action { margin-top: 0; }

  .actions .tool-action,
  .actions .file-button,
  .actions .logout-action { width: 40px; }

  .actions .tool-action span,
  .actions .file-button span,
  .actions .logout-action span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .app-main { padding: 22px 18px 34px; }
  .movement-log { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .topbar { position: relative; grid-template-columns: 1fr; }
  .brand-subtitle,
  .brand-kicker { display: none; }
  .actions { display: grid; grid-template-columns: 1fr 1fr repeat(3, 40px); }
  .actions button,
  .actions .file-button { width: 100%; }
  .app-main { padding: 14px 10px 26px; }

  .home-hero,
  .available-preview,
  .brand-preview,
  .inventory,
  .movement-log { border-radius: 14px; }

  .home-hero { min-height: 0; padding: 24px 20px; }
  .home-hero h2 { font-size: 34px; }

  .home-hero-actions,
  .brand-preview-head,
  .inventory-head,
  .home-panel,
  .editor-head,
  .query-head { align-items: stretch; flex-direction: column; }

  .home-hero-actions button,
  .brand-preview-head button,
  .inventory-head button,
  .home-panel button,
  .form-actions button { width: 100%; }

  .stats-grid,
  .home-panels,
  .field-row { grid-template-columns: 1fr; }

  .available-preview,
  .brand-preview,
  .home-panel,
  .inventory,
  .movement-log { padding: 17px; }

  .filters select { flex: 1 1 140px; }
  .editor-screen,
  .query-screen { padding: 8px; }

  .editor-card,
  .query-card { max-height: calc(100vh - 16px); padding: 18px; border-radius: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
}
