:root {
  --bg: #f5f7f6;
  --panel: #ffffff;
  --panel-soft: #eef4f2;
  --ink: #17211f;
  --muted: #66736f;
  --line: #d9e2df;
  --accent: #0f766e;
  --accent-strong: #0b5e57;
  --accent-soft: #dff3ef;
  --blue: #2563eb;
  --amber: #b45309;
  --red: #b42318;
  --green: #17803d;
  --slate: #31413d;
  --button-text: #ffffff;
  --sidebar-bg: #17211f;
  --sidebar-text: #dfe9e6;
  --sidebar-muted: #a6b6b1;
  --sidebar-border: rgba(255, 255, 255, 0.12);
  --sidebar-hover-bg: rgba(255, 255, 255, 0.07);
  --sidebar-active-bg: #9ee7dc;
  --sidebar-active-text: #10211d;
  --sidebar-icon-bg: rgba(255, 255, 255, 0.12);
  --sidebar-active-icon-bg: rgba(16, 33, 29, 0.12);
  --brand-mark-bg: #9ee7dc;
  --brand-mark-text: #10211d;
  --shadow: 0 18px 40px rgba(25, 39, 35, 0.11);
  --radius: 8px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

body.theme-dark {
  --bg: #111817;
  --panel: #192321;
  --panel-soft: #22302d;
  --ink: #edf6f3;
  --muted: #a7b8b3;
  --line: #334540;
  --accent: #48c6b5;
  --accent-strong: #8ee7dd;
  --accent-soft: #173d39;
  --blue: #79a7ff;
  --amber: #f0b35f;
  --red: #ff8b7d;
  --green: #5fd389;
  --slate: #d4e2de;
  --sidebar-bg: #0d1312;
  --sidebar-text: #dfe9e6;
  --sidebar-muted: #a7b8b3;
  --sidebar-active-bg: #48c6b5;
  --sidebar-active-text: #0d1312;
  --brand-mark-bg: #48c6b5;
  --brand-mark-text: #0d1312;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

html {
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  letter-spacing: 0;
}

img,
svg,
video {
  max-width: 100%;
}

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

button {
  cursor: pointer;
  touch-action: manipulation;
}

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

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 22px;
  height: 100vh;
  padding: 22px 18px;
  color: var(--sidebar-text);
  background: var(--sidebar-bg);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
}

.brand-mark {
  display: grid;
  place-items: center;
  overflow: hidden;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: var(--brand-mark-text);
  background: var(--brand-mark-bg);
  font-weight: 800;
}

.brand-logo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  font-size: 1.05rem;
}

.brand span {
  color: var(--sidebar-muted);
  font-size: 0.78rem;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item {
  display: grid;
  grid-template-columns: 34px 1fr;
  align-items: center;
  width: 100%;
  min-height: 42px;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--sidebar-text);
  background: transparent;
  text-align: left;
}

.nav-item:hover,
.nav-item:focus-visible {
  border-color: var(--sidebar-border);
  background: var(--sidebar-hover-bg);
  outline: none;
}

.nav-item.is-active {
  color: var(--sidebar-active-text);
  background: var(--sidebar-active-bg);
}

.nav-icon {
  display: grid;
  place-items: center;
  width: 24px;
  min-width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--sidebar-icon-bg);
  font-size: 0.72rem;
  font-weight: 800;
}

.is-active .nav-icon {
  background: var(--sidebar-active-icon-bg);
}

.sidebar-footer {
  display: grid;
  gap: 4px;
  margin-top: auto;
  padding: 12px;
  border: 1px solid var(--sidebar-border);
  border-radius: 8px;
  color: var(--sidebar-muted);
  font-size: 0.8rem;
}

.sidebar-footer strong {
  color: var(--sidebar-text);
}

.workspace {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 14px 26px;
  border-bottom: 1px solid var(--line);
  background: rgba(245, 247, 246, 0.92);
  backdrop-filter: blur(16px);
}

.search-box {
  position: relative;
  flex: 1 1 440px;
  max-width: 700px;
}

.search-box span {
  position: absolute;
  left: 14px;
  top: 50%;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  transform: translateY(-50%);
}

.search-box input {
  width: 100%;
  min-height: 44px;
  padding: 0 16px 0 72px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  outline: none;
}

body.theme-dark .topbar {
  background: rgba(17, 24, 23, 0.92);
}

body.theme-dark .search-box input,
body.theme-dark .field input,
body.theme-dark .field select,
body.theme-dark .field textarea,
body.theme-dark .compact-input,
body.theme-dark .filters input,
body.theme-dark .filters select,
body.theme-dark .button-secondary,
body.theme-dark .icon-button {
  color: var(--ink);
  background: #111817;
}

body.theme-dark th,
body.theme-dark .activity-list li,
body.theme-dark .alert-list li,
body.theme-dark .plain-list li,
body.theme-dark .barcode-card {
  background: #15201e;
}

.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.topbar-actions,
.toolbar,
.button-row,
.filters,
.inline-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.main-content {
  display: grid;
  gap: 18px;
  padding: 24px 26px 40px;
}

.view-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.view-kicker {
  color: var(--accent-strong);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  margin-top: 3px;
  font-size: clamp(1.65rem, 3vw, 2.5rem);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  font-size: 1.15rem;
  letter-spacing: 0;
}

h3 {
  font-size: 0.98rem;
  letter-spacing: 0;
}

.subtle {
  color: var(--muted);
}

.button,
.button-secondary,
.button-danger,
.ghost-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.button {
  padding: 0 14px;
  color: var(--button-text);
  background: var(--accent);
}

.button:hover,
.button:focus-visible {
  background: var(--accent-strong);
  outline: none;
}

.button-secondary {
  padding: 0 14px;
  color: var(--slate);
  border-color: var(--line);
  background: #ffffff;
}

.button-secondary:hover,
.button-secondary:focus-visible {
  border-color: #b7c6c1;
  background: #f9fbfa;
  outline: none;
}

.button-danger {
  padding: 0 14px;
  color: #ffffff;
  background: var(--red);
}

.tiny-reset-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid #cfd6d3;
  border-radius: 6px;
  color: #68736f;
  background: #eef1f0;
  font-size: 0.72rem;
  font-weight: 800;
}

.tiny-reset-button:hover,
.tiny-reset-button:focus-visible {
  color: #4b5551;
  background: #e2e7e5;
  outline: none;
}

.ghost-button {
  min-height: 34px;
  padding: 0 10px;
  color: var(--slate);
  border-color: transparent;
  background: transparent;
}

.ghost-button:hover,
.ghost-button:focus-visible {
  background: var(--panel-soft);
  outline: none;
}

.ghost-button.is-danger {
  color: var(--red);
}

.ghost-button.is-danger:hover,
.ghost-button.is-danger:focus-visible {
  background: #fee2e2;
}

.icon-button {
  width: 38px;
  min-width: 38px;
  height: 38px;
  padding: 0;
  color: var(--slate);
  border-color: var(--line);
  background: #ffffff;
}

.icon-button:hover,
.icon-button:focus-visible {
  border-color: #b7c6c1;
  background: #f8fbfa;
  outline: none;
}

.card,
.metric-card,
.table-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 1px 0 rgba(18, 33, 29, 0.03);
}

.card {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.auth-card {
  width: min(520px, 100%);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric-card {
  display: grid;
  gap: 8px;
  padding: 16px;
  min-height: 118px;
}

.metric-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.metric-value {
  font-size: clamp(1.45rem, 3vw, 2.15rem);
  font-weight: 850;
}

.metric-note {
  color: var(--muted);
  font-size: 0.82rem;
}

.split-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.8fr);
  gap: 16px;
}

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

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

.table-card {
  overflow: hidden;
}

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

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  font-size: 0.9rem;
}

th {
  color: var(--muted);
  background: #fbfcfc;
  font-size: 0.72rem;
  font-weight: 850;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.item-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
}

.thumb {
  width: 48px;
  min-width: 48px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: cover;
  background: var(--panel-soft);
}

.location-photo {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: cover;
  background: var(--panel-soft);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  color: var(--slate);
  background: var(--panel-soft);
  font-size: 0.74rem;
  font-weight: 850;
}

.badge.raw {
  color: #7c2d12;
  background: #ffedd5;
}

.badge.finished {
  color: #14532d;
  background: #dcfce7;
}

.badge.wip {
  color: #1d4ed8;
  background: #dbeafe;
}

.badge.supply {
  color: #713f12;
  background: #fef3c7;
}

.badge.warn {
  color: #8a3412;
  background: #ffedd5;
}

.badge.good {
  color: #14532d;
  background: #dcfce7;
}

.badge.danger {
  color: #991b1b;
  background: #fee2e2;
}

.badge.neutral {
  color: #374151;
  background: #f3f4f6;
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--muted);
}

.status-dot.good {
  background: var(--green);
}

.status-dot.warn {
  background: var(--amber);
}

.status-dot.danger {
  background: var(--red);
}

.progress {
  overflow: hidden;
  height: 8px;
  border-radius: 999px;
  background: #edf1ef;
}

.progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

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

.form-grid .wide,
.wide {
  grid-column: 1 / -1;
}

label.field {
  display: grid;
  gap: 6px;
  color: var(--slate);
  font-size: 0.82rem;
  font-weight: 800;
}

.field input,
.field select,
.field textarea,
.compact-input,
.filters input,
.filters select {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  outline: none;
}

.field textarea {
  min-height: 84px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.compact-input:focus,
.filters input:focus,
.filters select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.line-editor {
  display: grid;
  gap: 10px;
}

.line-row {
  display: grid;
  grid-template-columns: minmax(190px, 1fr) 88px 105px 38px;
  gap: 8px;
  align-items: end;
}

.line-row.bom-line {
  grid-template-columns: minmax(190px, 1fr) 88px 88px 38px;
}

.line-row.sales-line {
  grid-template-columns: minmax(190px, 1fr) 88px 105px 38px;
}

.mini-stat {
  display: grid;
  gap: 4px;
}

.mini-stat strong {
  font-size: 1rem;
}

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

.location-card {
  display: grid;
  gap: 12px;
  box-shadow: inset calc(var(--depth, 0) * 4px) 0 0 rgba(15, 118, 110, 0.24);
}

.sub-location-list {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.activity-list,
.alert-list,
.plain-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.activity-list li,
.alert-list li,
.plain-list li {
  display: grid;
  gap: 4px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.alert-list li {
  border-left: 4px solid var(--amber);
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 180px;
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

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

.barcode-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px dashed #9fb0ab;
  border-radius: 8px;
  background: #ffffff;
}

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

.media-card {
  display: grid;
  gap: 10px;
}

.media-preview {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  overflow: hidden;
}

.media-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.file-icon {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 8px;
  color: #ffffff;
  background: var(--slate);
  font-weight: 850;
}

.barcode-bars {
  height: 42px;
  border-radius: 4px;
  background: repeating-linear-gradient(90deg, #17211f 0 2px, #fff 2px 5px, #17211f 5px 8px, #fff 8px 11px);
}

.qr-modal-intro {
  padding: 2px 0;
}

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

.qr-card {
  display: grid;
  gap: 12px;
  break-inside: avoid;
  padding: 14px;
  border: 1px dashed #9fb0ab;
  border-radius: 8px;
  color: #17211f;
  background: #ffffff;
}

.qr-code {
  display: grid;
  place-items: center;
  width: 100%;
  max-width: 210px;
  margin: 0 auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.qr-svg {
  display: block;
  width: 100%;
  height: auto;
}

.qr-card-copy {
  display: grid;
  gap: 3px;
  text-align: center;
}

.qr-card-copy span,
.qr-card-copy small {
  color: #66736f;
}

.scan-toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.qr-scanner-panel {
  display: grid;
  gap: 10px;
}

.qr-scanner-panel[hidden] {
  display: none;
}

.qr-scanner-video {
  width: 100%;
  max-height: min(52vh, 420px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101918;
  object-fit: cover;
}

.scan-results {
  display: grid;
  gap: 8px;
}

.scan-result {
  display: grid;
  gap: 3px;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel);
  text-align: left;
}

.scan-result:hover,
.scan-result:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.scan-result span {
  color: var(--muted);
  font-size: 0.84rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(14, 24, 22, 0.46);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-panel {
  width: min(920px, 100%);
  max-height: min(88vh, 920px);
  overflow: auto;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.modal-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.modal-form {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 4px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 80;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 8px;
  color: #ffffff;
  background: #17211f;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 150ms ease, transform 150ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

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

@media print {
  body {
    background: #ffffff;
  }

  body.printing-modal .app-shell {
    display: none !important;
  }

  .sidebar,
  .topbar,
  .modal-header .icon-button,
  .modal-footer,
  .toast {
    display: none !important;
  }

  .app-shell,
  .workspace,
  .main-content {
    display: block;
    padding: 0;
  }

  .modal-backdrop {
    position: static;
    display: block;
    padding: 0;
    background: transparent;
  }

  .modal-panel {
    max-height: none;
    box-shadow: none;
  }

  .qr-grid,
  .barcode-labels {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .qr-card,
  .barcode-card {
    box-shadow: none;
  }
}

@media (max-width: 1180px) {
  .metric-grid,
  .storage-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .split-grid,
  .three-grid,
  .media-grid,
  .qr-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1024px) and (min-width: 861px) {
  .app-shell {
    grid-template-columns: 232px minmax(0, 1fr);
  }

  .sidebar {
    gap: 16px;
    padding: 18px 14px;
  }

  .nav-item {
    min-height: 40px;
    padding: 7px 8px;
  }

  .topbar {
    padding: 12px 20px;
  }

  .main-content {
    padding: 20px;
  }
}

@media (hover: none) and (pointer: coarse) and (max-width: 1180px) {
  .button,
  .button-secondary,
  .button-danger,
  .ghost-button,
  .icon-button,
  .field input,
  .field select,
  .field textarea,
  .compact-input,
  .filters input,
  .filters select {
    min-height: 44px;
  }
}

@media (max-width: 860px), (hover: none) and (pointer: coarse) and (max-height: 560px) and (orientation: landscape) {
  .app-shell {
    grid-template-columns: 1fr;
    min-height: 100dvh;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 30;
    gap: 10px;
    height: auto;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 10px;
    box-shadow: 0 1px 0 var(--sidebar-border);
  }

  .brand {
    gap: 10px;
    min-height: 38px;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
  }

  .brand span {
    display: none;
  }

  .nav-list {
    display: flex;
    gap: 8px;
    margin: 0 -2px;
    padding: 0 2px 4px;
    overflow-x: auto;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
  }

  .nav-list::-webkit-scrollbar {
    display: none;
  }

  .nav-item {
    display: flex;
    flex: 0 0 auto;
    grid-template-columns: none;
    gap: 8px;
    width: auto;
    min-width: max-content;
    min-height: 40px;
    padding: 8px 11px;
    scroll-snap-align: start;
  }

  .nav-icon {
    width: 22px;
    min-width: 22px;
    height: 22px;
  }

  .sidebar-footer {
    display: none;
  }

  .topbar,
  .view-header {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    position: static;
    gap: 10px;
    min-height: 0;
    padding: 12px;
  }

  .search-box {
    flex: 1 1 auto;
    width: 100%;
    max-width: none;
  }

  .search-box input {
    min-height: 44px;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: 44px repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
  }

  .topbar-actions > * {
    width: 100%;
  }

  #logoutButton {
    grid-column: 1 / -1;
  }

  .main-content {
    gap: 14px;
    padding: 14px 12px calc(28px + env(safe-area-inset-bottom, 0px));
  }

  .view-header {
    gap: 10px;
  }

  .view-header .toolbar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
    width: 100%;
  }

  .view-header .toolbar > * {
    width: 100%;
  }

  .toolbar,
  .button-row,
  .filters,
  .inline-actions {
    gap: 8px;
  }

  .metric-grid,
  .split-grid,
  .three-grid,
  .two-grid,
  .storage-grid,
  .media-grid,
  .qr-grid,
  .barcode-labels,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .metric-card {
    min-height: 98px;
  }

  .card,
  .metric-card {
    padding: 14px;
  }

  .table-header {
    align-items: flex-start;
    flex-direction: column;
    padding: 12px;
  }

  .table-wrap {
    margin: 0 -1px;
    border-top: 1px solid var(--line);
  }

  .table-wrap table {
    min-width: 720px;
  }

  th,
  td {
    padding: 10px 12px;
    font-size: 0.86rem;
  }

  .item-cell {
    min-width: 220px;
  }

  .line-row,
  .line-row.bom-line,
  .line-row.sales-line {
    grid-template-columns: 1fr;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-soft);
  }

  .line-row .icon-button {
    justify-self: end;
  }

  .modal-backdrop {
    align-items: end;
    justify-items: stretch;
    padding: 0;
  }

  .modal-panel {
    width: 100%;
    max-height: min(92dvh, 920px);
    border-radius: 8px 8px 0 0;
    background: var(--panel);
  }

  .modal-header {
    padding: 14px 12px;
    background: var(--panel);
  }

  .modal-form {
    padding: 14px 12px calc(14px + env(safe-area-inset-bottom, 0px));
  }

  .modal-footer {
    position: sticky;
    bottom: 0;
    z-index: 2;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 12px;
    border-top: 1px solid var(--line);
    background: var(--panel);
  }

  .modal-footer .button,
  .modal-footer .button-secondary {
    width: 100%;
  }

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

  .scan-toolbar > * {
    width: 100%;
  }

  .field input,
  .field select,
  .field textarea,
  .compact-input,
  .filters input,
  .filters select {
    min-height: 44px;
    font-size: 16px;
  }

  .toast {
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    left: 12px;
    max-width: none;
  }
}

@media (max-width: 520px) {
  h1 {
    font-size: 1.48rem;
    line-height: 1.12;
  }

  h2 {
    font-size: 1.02rem;
  }

  .topbar-actions {
    grid-template-columns: 42px repeat(2, minmax(0, 1fr));
  }

  .button,
  .button-secondary,
  .button-danger,
  .ghost-button {
    padding-right: 10px;
    padding-left: 10px;
    font-size: 0.86rem;
  }

  .icon-button {
    width: 42px;
    min-width: 42px;
  }

  .nav-item {
    min-height: 38px;
    padding: 8px 10px;
    font-size: 0.86rem;
  }

  .metric-card {
    min-height: 92px;
  }

  .table-wrap table {
    min-width: 660px;
  }

  .item-cell {
    min-width: 200px;
  }

  .thumb {
    width: 42px;
    min-width: 42px;
    height: 42px;
  }

  .location-photo {
    aspect-ratio: 4 / 3;
  }

  .modal-panel {
    max-height: 100dvh;
    border-radius: 0;
  }
}

@media (hover: none) and (pointer: coarse) and (orientation: landscape) and (max-width: 900px) {
  .main-content {
    padding-right: 14px;
    padding-left: 14px;
  }

  .metric-grid,
  .two-grid,
  .storage-grid,
  .media-grid,
  .qr-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .modal-panel {
    max-height: 96dvh;
  }
}
