: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;
  --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;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

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

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

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

button {
  cursor: pointer;
}

.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: #f7fbfa;
  background: #17211f;
}

.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: #10211d;
  background: #9ee7dc;
  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: #a6b6b1;
  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: #dfe9e6;
  background: transparent;
  text-align: left;
}

.nav-item:hover,
.nav-item:focus-visible {
  border-color: rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.07);
  outline: none;
}

.nav-item.is-active {
  color: #10211d;
  background: #9ee7dc;
}

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

.is-active .nav-icon {
  background: rgba(16, 33, 29, 0.12);
}

.sidebar-footer {
  display: grid;
  gap: 4px;
  margin-top: auto;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  color: #a6b6b1;
  font-size: 0.8rem;
}

.sidebar-footer strong {
  color: #ffffff;
}

.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;
}

body.theme-dark .sidebar {
  background: #0d1312;
}

.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: #ffffff;
  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);
}

.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;
}

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);
}

.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;
  }

  .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;
  }
}

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

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

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .nav-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .topbar-actions {
    justify-content: flex-start;
  }

  .metric-grid,
  .two-grid,
  .storage-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .line-row,
  .line-row.bom-line,
  .line-row.sales-line {
    grid-template-columns: 1fr;
  }

  .barcode-labels {
    grid-template-columns: 1fr;
  }
}
