:root {
  --navy-950: #071221;
  --navy-900: #0c1b2e;
  --navy-800: #13243c;
  --navy-700: #1c3250;
  --navy-600: #2a4668;
  --accent: #2f6fed;
  --accent-strong: #1d4fd7;
  --accent-soft: #eaf1fd;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --border: #e4e8ee;
  --border-strong: #d5dbe4;
  --text: #142033;
  --text-muted: #5d6b7e;
  --text-faint: #8794a6;
  --success: #0f7a4c;
  --success-bg: #e7f6ee;
  --danger: #c0392b;
  --danger-bg: #fdeeee;
  --warning: #b45309;
  --shadow: 0 1px 2px rgba(15, 28, 46, 0.04), 0 8px 24px rgba(15, 28, 46, 0.04);
  --sidebar-width: 248px;
  --sidebar-compact: 76px;
  --radius: 12px;
  font-family: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app[hidden],
.login-screen[hidden],
.nav-item[hidden],
.sidebar-session[hidden],
.debug-filters[hidden],
.login-form[hidden] {
  display: none !important;
}

.login-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at top left, rgba(47, 111, 237, 0.18), transparent 32%),
    var(--navy-950);
}

.login-card {
  width: min(440px, 100%);
  padding: 28px 28px 24px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-brand {
  padding: 0 0 22px;
}

.login-brand .brand-name {
  color: var(--navy-900);
}

.login-brand .brand-product {
  color: var(--text-faint);
}

.login-form {
  display: grid;
  gap: 12px;
}

.login-form h1 {
  font-size: 30px;
}

.login-submit {
  justify-content: center;
  width: 100%;
  margin-top: 4px;
}

.login-links {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.text-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.text-button:hover {
  color: var(--accent-strong);
}

.sidebar-session {
  display: grid;
  gap: 3px;
  margin-bottom: 14px;
}

.sidebar-session strong {
  color: #fff;
  font-size: 13px;
}

.sidebar-session span {
  color: #8ea0b8;
  font-size: 12px;
}

.sidebar-session .text-button {
  justify-self: start;
  margin-top: 6px;
  color: #c5d2e3;
}

.login-form input[data-login-code] {
  letter-spacing: 0.28em;
  font-weight: 600;
}

.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
  height: 100vh;
  height: 100dvh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--navy-900);
  color: #d7e0ec;
  padding: 22px 16px 18px;
  border-right: 1px solid #0a1626;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 8px 22px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

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

.brand-name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: #fff;
}

.brand-product {
  margin-top: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.28em;
  color: #8ea0b8;
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 42px;
  padding: 0 12px;
  border-radius: 10px;
  color: #c5d2e3;
  text-decoration: none;
  position: relative;
}

.nav-item.is-active {
  background: #1a4fa0;
  color: #fff;
}

.nav-icon {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.nav-icon svg {
  width: 20px;
  height: 20px;
}

.nav-label {
  font-size: 14px;
  font-weight: 500;
}

.sidebar-footer {
  margin-top: auto;
  padding: 16px 10px 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-footer-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.sidebar-footer-text strong {
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}

.sidebar-footer-text span {
  color: #8ea0b8;
  font-size: 12px;
}

.main {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 28px 32px 24px;
  overflow: hidden;
}

.view {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.view[hidden] {
  display: none !important;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 22px;
  flex-shrink: 0;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

h1 {
  margin: 0;
  font-size: 32px;
  letter-spacing: -0.03em;
  font-weight: 700;
}

.page-subtitle {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 14px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sync-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 188px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #b8c2d0;
  flex-shrink: 0;
}

.sync-indicator[data-sync="loading"] .sync-dot {
  background: var(--warning);
  box-shadow: 0 0 0 4px rgba(180, 83, 9, 0.12);
  animation: pulse 1.2s ease-in-out infinite;
}

.sync-indicator[data-sync="live"] .sync-dot {
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(15, 122, 76, 0.12);
}

.sync-indicator[data-sync="error"] .sync-dot {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(192, 57, 43, 0.12);
}

.sync-copy {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.sync-copy strong {
  font-size: 13px;
}

.sync-copy small {
  color: var(--text-muted);
  font-size: 11px;
}

.primary-button,
.refresh-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.primary-button svg,
.refresh-button svg {
  width: 16px;
  height: 16px;
}

.primary-button:hover,
.refresh-button:hover {
  background: var(--accent-strong);
}

.primary-button:disabled,
.refresh-button:disabled {
  opacity: 0.65;
  cursor: progress;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
  flex-shrink: 0;
}

.summary-grid[hidden] {
  display: none;
}

.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px 14px;
}

.summary-card p {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
}

.summary-card strong {
  display: block;
  margin: 8px 0 4px;
  font-size: 28px;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

.summary-card span {
  color: var(--text-faint);
  font-size: 12px;
}

.panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-toolbar {
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) minmax(340px, 1.8fr) minmax(150px, 0.7fr) auto;
  gap: 12px;
  align-items: end;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.search-field,
.warehouse-field,
.debug-field {
  position: relative;
  display: flex;
  align-items: center;
}

.debug-filters {
  display: grid;
  gap: 6px;
  min-width: 0;
  padding: 8px 10px 10px;
  border: 1px dashed #ddd4b8;
  border-radius: 12px;
  background: #fbfaf5;
}

.debug-badge {
  justify-self: start;
  padding: 1px 7px;
  border-radius: 999px;
  background: #efe6c9;
  color: #8a7a4b;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.debug-filters-row {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 8px;
}

.debug-field {
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
}

.debug-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #8a7a4b;
}

.search-field svg {
  position: absolute;
  left: 12px;
  width: 16px;
  height: 16px;
  color: var(--text-faint);
}

.search-field input,
.warehouse-field select,
.debug-field select {
  width: 100%;
  height: 42px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: #fbfcfe;
  color: var(--text);
}

.search-field input {
  padding: 0 12px 0 38px;
}

.warehouse-field select,
.debug-field select {
  padding: 0 36px 0 12px;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none'><path d='M4 6l4 4 4-4' stroke='%235d6b7e' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.debug-field select {
  border-color: #ddd4b8;
  background-color: #fffdf6;
}

.search-field input:focus,
.warehouse-field select:focus,
.debug-field select:focus,
.field input:focus,
.field select:focus,
.primary-button:focus-visible,
.refresh-button:focus-visible,
.ghost-button:focus-visible,
.danger-button:focus-visible,
.row-action:focus-visible {
  outline: 2px solid rgba(47, 111, 237, 0.35);
  outline-offset: 1px;
}

.admin-toolbar {
  grid-template-columns: minmax(200px, 1fr) auto;
}

.users-table {
  width: 100%;
}

.users-table .name-cell {
  font-weight: 600;
}

.users-table .col-actions {
  width: 168px;
  white-space: nowrap;
}

.row-actions {
  display: flex;
  gap: 6px;
}

.row-action,
.ghost-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.row-action,
.ghost-button {
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--text);
}

.row-action:hover,
.ghost-button:hover {
  background: #f7f9fc;
}

.row-action.is-danger {
  color: var(--danger);
}

.danger-button {
  border: 0;
  background: var(--danger);
  color: #fff;
}

.danger-button:hover {
  background: #a33025;
}

.danger-button:disabled {
  opacity: 0.65;
  cursor: progress;
}

.ghost-button {
  height: 42px;
  padding: 0 14px;
}

.state-block .primary-button {
  margin-top: 16px;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(7, 18, 33, 0.46);
}

.overlay[hidden] {
  display: none !important;
}

.modal {
  width: min(480px, 100%);
  padding: 22px 22px 18px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal-narrow {
  width: min(420px, 100%);
}

.modal h2 {
  margin: 0 0 16px;
  font-size: 22px;
  letter-spacing: -0.03em;
}

.modal-copy {
  margin: 0 0 18px;
  color: var(--text-muted);
}

.user-form {
  display: grid;
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.field input,
.field select {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: #fbfcfe;
  color: var(--text);
}

.field select {
  padding-right: 36px;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none'><path d='M4 6l4 4 4-4' stroke='%235d6b7e' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.form-error {
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

.form-error[hidden] {
  display: none !important;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

.toast-region {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 30;
  display: grid;
  gap: 8px;
}

.toast {
  min-width: 220px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #13243c;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow);
}

.toast.is-leaving {
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.record-count {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  justify-self: end;
}

.table-shell {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.table-scroll {
  flex: 1;
  min-height: 240px;
  overflow: auto;
}

.inventory-table {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

.inventory-table th,
.inventory-table td {
  padding: 12px 16px;
  border-right: 1px solid var(--border-strong);
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
  background-clip: padding-box;
}

.inventory-table th:first-child,
.inventory-table td:first-child {
  border-left: 1px solid var(--border-strong);
}

.inventory-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f8fafc;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  box-shadow: 0 1px 0 var(--border-strong);
}

.inventory-table tbody td {
  background: var(--surface);
}

.inventory-table td:not(.product-cell):not(.location-cell):not(.col-actions) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inventory-table tbody tr:hover td {
  background: #f7f9fc;
}

.inventory-table th.is-numeric,
.inventory-table td.is-numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.sort-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: calc(100% - 8px);
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
}

.sort-button span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.resize-handle {
  position: absolute;
  top: 0;
  right: 0;
  width: 9px;
  height: 100%;
  cursor: col-resize;
  z-index: 4;
}

.resize-handle::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  width: 1px;
  background: var(--border-strong);
}

.resize-handle:hover::after,
.resize-handle.is-active::after {
  background: var(--accent);
}

body.is-col-resizing,
body.is-col-resizing * {
  cursor: col-resize !important;
  user-select: none !important;
}

.sort-button .sort-icon {
  width: 10px;
  color: #b4becb;
}

.sort-button[data-dir="asc"] .sort-icon,
.sort-button[data-dir="desc"] .sort-icon {
  color: var(--accent);
}

.sku-cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 13px;
  font-weight: 600;
}

.product-cell {
  font-weight: 400;
  line-height: 1.4;
  white-space: normal;
  overflow-wrap: anywhere;
}

.product-cell.is-empty {
  color: var(--text-faint);
}

.location-cell small {
  display: block;
  margin-top: 2px;
  color: var(--text-faint);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 11px;
}

.badge {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-in {
  background: var(--success-bg);
  color: var(--success);
}

.badge-out {
  background: var(--danger-bg);
  color: var(--danger);
}

.state-block {
  display: grid;
  justify-items: center;
  text-align: center;
  padding: 72px 24px;
}

.state-block h2,
.state-block h3 {
  margin: 16px 0 6px;
  font-size: 18px;
}

.state-block p {
  margin: 0;
  max-width: 420px;
  color: var(--text-muted);
}

.state-error {
  color: var(--danger);
}

.spinner {
  width: 28px;
  height: 28px;
  border: 2.5px solid #d9e3f5;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

@keyframes pulse {
  50% {
    opacity: 0.45;
  }
}

@media (max-width: 1100px) {
  .summary-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 960px) {
  :root {
    --sidebar-width: var(--sidebar-compact);
  }

  .brand-text,
  .nav-label,
  .sidebar-footer-text {
    display: none;
  }

  .sidebar {
    padding: 18px 12px;
    align-items: center;
  }

  .brand {
    padding: 0 0 18px;
  }

  .nav-item {
    justify-content: center;
    padding: 0;
    width: 44px;
  }

  .main {
    padding: 20px 16px 32px;
  }

  .page-header {
    flex-direction: column;
  }

  .panel-toolbar {
    grid-template-columns: 1fr;
  }

  .debug-filters-row {
    grid-template-columns: 1fr;
  }

  .record-count {
    justify-self: start;
  }
}

@media (max-width: 640px) {
  .app {
    height: auto;
    min-height: 100dvh;
  }

  .main {
    overflow: visible;
  }

  .table-scroll {
    flex: none;
    max-height: 70vh;
  }
  .summary-grid {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 26px;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
  }
}
