:root {
  color-scheme: dark;
  --bg: #141414;
  --bg-soft: #1e1f20;
  --panel: rgba(42, 42, 44, 0.58);
  --panel-strong: rgba(54, 54, 56, 0.76);
  --line: rgba(255, 255, 255, 0.16);
  --line-strong: rgba(255, 255, 255, 0.25);
  --text: #fbf7f0;
  --muted: rgba(251, 247, 240, 0.68);
  --faint: rgba(251, 247, 240, 0.46);
  --orange: #ff7a18;
  --orange-strong: #ff9438;
  --teal: #43d9c4;
  --red: #ff5c5c;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.38);
  --radius: 24px;
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(140deg, rgba(255, 122, 24, 0.18), transparent 34%),
    linear-gradient(215deg, rgba(67, 217, 196, 0.1), transparent 42%),
    linear-gradient(180deg, #262320 0%, #151617 46%, #0f1011 100%);
  letter-spacing: 0;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  content: "";
  background:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(to bottom, black, transparent 82%);
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.shell {
  width: min(1400px, 100%);
  margin: 0 auto;
  padding: 22px;
}

.topbar,
.glass-surface,
.item-card,
.stat {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(24px) saturate(1.35);
  -webkit-backdrop-filter: blur(24px) saturate(1.35);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 82px;
  gap: 16px;
  padding: 14px 16px;
  border-radius: var(--radius);
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
  gap: 10px;
}

.action-button {
  min-width: 118px;
  white-space: nowrap;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 14px;
}

.brand-mark {
  display: grid;
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 18px;
  color: #181614;
  background:
    linear-gradient(150deg, #ffb169, var(--orange) 58%, #ff5c00);
  font-size: 1.3rem;
  font-weight: 850;
  box-shadow:
    0 14px 30px rgba(255, 122, 24, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--orange-strong);
  font-size: 0.74rem;
  font-weight: 780;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 1.9rem;
  line-height: 1;
}

h2 {
  margin-bottom: 0;
  font-size: 1.18rem;
  line-height: 1.15;
}

h3 {
  margin-bottom: 0;
  font-size: 1.02rem;
  line-height: 1.22;
}

.user-badge {
  max-width: min(48vw, 420px);
  min-height: 38px;
  overflow: hidden;
  padding: 9px 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.08);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inventory-layout {
  margin-top: 18px;
}

.editor-panel,
.tools,
.modal {
  border-radius: var(--radius);
}

.editor-panel {
  position: sticky;
  top: 18px;
  padding: 18px;
}

.panel-head,
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.item-form,
#movementForm {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 8px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 650;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  outline: none;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  transition: border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

input,
select {
  padding: 0 13px;
}

textarea {
  min-height: 104px;
  padding: 12px 13px;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: var(--faint);
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(255, 148, 56, 0.72);
  background: rgba(255, 255, 255, 0.12);
  box-shadow: 0 0 0 4px rgba(255, 122, 24, 0.15);
}

select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 50%,
    calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.photo-drop {
  display: grid;
  grid-template-columns: 68px 1fr;
  align-items: center;
  min-height: 78px;
  padding: 9px;
  border: 1px dashed rgba(255, 255, 255, 0.22);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
}

.photo-drop input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.photo-preview {
  display: grid;
  width: 58px;
  height: 58px;
  overflow: hidden;
  place-items: center;
  border-radius: 16px;
  color: #191612;
  background: rgba(255, 122, 24, 0.92);
  font-size: 1.4rem;
  font-weight: 780;
}

.photo-preview.has-image {
  background-position: center;
  background-size: cover;
  color: transparent;
}

.photo-drop strong {
  display: block;
  color: var(--text);
}

.photo-drop small {
  display: block;
  overflow: hidden;
  color: var(--faint);
  font-size: 0.82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.placement-preview {
  display: grid;
  grid-template-columns: minmax(150px, 0.66fr) minmax(240px, 1.34fr);
  gap: 12px;
  align-items: stretch;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.06);
}

.placement-preview h3 {
  margin-bottom: 0;
  color: var(--text);
  font-size: 1rem;
}

.placement-cabinet-preview {
  width: 100%;
  height: clamp(260px, 34vh, 340px);
  min-height: 260px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 16px;
  background:
    radial-gradient(circle at 50% 16%, rgba(255, 122, 24, 0.14), transparent 40%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.055), rgba(0, 0, 0, 0.18));
  touch-action: none;
}

.placement-cabinet-preview canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}

.placement-cabinet-preview canvas:active {
  cursor: grabbing;
}

.primary-button,
.pill-button,
.icon-button {
  min-height: 44px;
  border: 0;
  border-radius: 16px;
  font-weight: 780;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  color: #171410;
  background:
    linear-gradient(145deg, #ffbb76 0%, var(--orange) 66%, #ff5c00 100%);
  box-shadow:
    0 14px 32px rgba(255, 122, 24, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.pill-button,
.icon-button {
  display: inline-grid;
  place-items: center;
  color: var(--text);
  background: rgba(255, 255, 255, 0.1);
}

.pill-button {
  grid-auto-flow: column;
  gap: 8px;
  padding: 0 13px;
}

.pill-button.add {
  color: #121414;
  background: rgba(67, 217, 196, 0.86);
}

.pill-button.withdraw {
  color: #191410;
  background: rgba(255, 148, 56, 0.9);
}

.icon-button {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  padding: 0;
}

.icon-button.ghost {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.07);
}

.tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 178px;
  gap: 12px;
  padding: 12px;
}

.search-box {
  position: relative;
  display: block;
}

.search-icon {
  position: absolute;
  top: 50%;
  left: 14px;
  z-index: 1;
  width: 18px;
  height: 18px;
  color: var(--faint);
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transform: translateY(-50%);
  pointer-events: none;
}

.search-box input {
  padding-left: 40px;
}

.overview-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
  gap: 14px;
  align-items: start;
  margin-top: 14px;
}

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

.inventory-main {
  min-width: 0;
}

.stat {
  min-height: 86px;
  padding: 14px;
  border-radius: 20px;
}

.stat span {
  display: block;
  color: var(--faint);
  font-size: 0.78rem;
  font-weight: 700;
}

.stat strong {
  display: block;
  margin-top: 7px;
  font-size: 1.55rem;
  line-height: 1;
}

.cabinet-panel {
  min-height: 430px;
  padding: 0;
}

.cabinet-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0 0;
}

.map-summary {
  min-height: 28px;
  margin: 10px 0 8px;
  padding: 6px 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.07);
  font-size: 0.82rem;
  font-weight: 760;
}

.camera-presets {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 8px;
}

.camera-presets button {
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.07);
  font-size: 0.78rem;
  font-weight: 780;
}

.camera-presets button.active {
  color: #171410;
  background: rgba(255, 148, 56, 0.92);
  box-shadow: 0 8px 20px rgba(255, 122, 24, 0.22);
}

.cabinet-map {
  width: min(100%, 330px);
  height: min(64vh, 520px);
  min-height: 390px;
  margin: 0 auto;
  touch-action: none;
}

.cabinet-map svg,
.cabinet-map canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.cabinet-map canvas {
  cursor: grab;
}

.cabinet-map canvas:active {
  cursor: grabbing;
}

.cabinet-shadow {
  fill: rgba(0, 0, 0, 0.42);
}

.cabinet-back {
  fill: url(#cabinetMetal);
  stroke: rgba(255, 255, 255, 0.2);
  stroke-width: 2;
}

.cabinet-inner {
  fill: url(#cabinetInside);
  stroke: rgba(255, 255, 255, 0.12);
  stroke-width: 1.5;
}

.cabinet-side,
.cabinet-top,
.bottom-base,
.front-left-post,
.front-right-post,
.door-frame {
  fill: url(#cabinetMetal);
  stroke: rgba(255, 255, 255, 0.2);
  stroke-width: 2;
}

.cabinet-side {
  fill: rgba(23, 24, 26, 0.9);
}

.cabinet-top {
  fill: rgba(56, 57, 60, 0.92);
}

.door-left {
  filter: drop-shadow(12px 18px 22px rgba(0, 0, 0, 0.32));
}

.door-glass {
  fill: url(#glassDoor);
  stroke: rgba(255, 255, 255, 0.2);
  stroke-width: 1.5;
}

.door-rail {
  fill: rgba(20, 21, 22, 0.86);
  stroke: rgba(255, 255, 255, 0.12);
}

.front-frame {
  fill: none;
  stroke: rgba(255, 255, 255, 0.26);
  stroke-width: 3;
}

.shelf-board {
  fill: rgba(255, 255, 255, 0.055);
  stroke: rgba(255, 255, 255, 0.12);
  stroke-width: 1;
}

.shelf-front {
  stroke: rgba(255, 255, 255, 0.22);
  stroke-linecap: round;
  stroke-width: 2;
}

.map-cell {
  cursor: pointer;
  outline: none;
}

.cell-hit {
  fill: rgba(255, 255, 255, 0.01);
  stroke: rgba(255, 255, 255, 0.02);
  transition: fill 160ms ease, stroke 160ms ease, filter 160ms ease;
}

.map-cell.has-items .cell-hit {
  fill: rgba(255, 122, 24, 0.17);
  stroke: rgba(255, 148, 56, 0.46);
}

.map-cell.active .cell-hit,
.map-cell:hover .cell-hit,
.map-cell:focus .cell-hit {
  fill: rgba(255, 148, 56, 0.55);
  stroke: rgba(255, 255, 255, 0.72);
  filter: drop-shadow(0 0 12px rgba(255, 122, 24, 0.54));
}

.map-count-dot {
  fill: rgba(255, 148, 56, 0.92);
  stroke: rgba(255, 255, 255, 0.42);
  stroke-width: 1;
}

.map-floor-label,
.map-axis,
.map-q-label,
.map-count {
  fill: rgba(251, 247, 240, 0.76);
  font-weight: 780;
  text-anchor: middle;
}

.map-floor-label {
  font-size: 11px;
}

.map-axis {
  font-size: 11px;
}

.map-q-label {
  font-size: 10px;
}

.map-count {
  fill: #15120f;
  font-size: 12px;
  font-weight: 850;
}

.items-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 14px;
}

.item-card {
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr) 112px auto;
  align-items: stretch;
  min-height: 112px;
  overflow: hidden;
  border-radius: 22px;
}

.item-photo {
  position: relative;
  display: grid;
  min-height: 112px;
  padding: 0;
  border: 0;
  overflow: hidden;
  place-items: center;
  background:
    linear-gradient(135deg, rgba(255, 122, 24, 0.24), rgba(255, 255, 255, 0.06)),
    rgba(255, 255, 255, 0.06);
}

.item-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-open {
  color: inherit;
}

.photo-open img {
  transition: transform 180ms ease, filter 180ms ease;
}

.photo-open:hover img,
.photo-open:focus-visible img {
  filter: brightness(0.72);
  transform: scale(1.04);
}

.photo-open:focus-visible {
  outline: 3px solid rgba(255, 148, 56, 0.74);
  outline-offset: -3px;
}

.photo-open-hint {
  position: absolute;
  inset: auto 10px 10px auto;
  padding: 6px 9px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  color: #191410;
  background: rgba(255, 184, 113, 0.92);
  font-size: 0.74rem;
  font-weight: 850;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.photo-open:hover .photo-open-hint,
.photo-open:focus-visible .photo-open-hint {
  opacity: 1;
  transform: translateY(0);
}

.item-photo .fallback {
  color: rgba(255, 255, 255, 0.44);
  font-size: 2.4rem;
  font-weight: 850;
}

.qty-chip {
  position: absolute;
  right: 10px;
  bottom: 10px;
  min-width: 74px;
  padding: 8px 11px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  color: #15120f;
  background: rgba(255, 184, 113, 0.92);
  text-align: center;
  font-weight: 850;
}

.item-body {
  display: grid;
  align-content: center;
  gap: 10px;
  padding: 14px;
}

.item-title {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
}

.item-title h3 {
  min-width: 0;
  overflow-wrap: anywhere;
}

.floor-tag {
  flex: 0 0 auto;
  padding: 6px 9px;
  border-radius: 999px;
  color: rgba(251, 247, 240, 0.9);
  background: rgba(255, 255, 255, 0.08);
  font-size: 0.78rem;
  font-weight: 750;
}

.meta {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.88rem;
}

.meta p {
  margin: 0;
  overflow-wrap: anywhere;
}

.item-quantity {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 6px;
  padding: 12px;
  border-left: 1px solid rgba(255, 255, 255, 0.1);
}

.item-quantity span {
  color: var(--faint);
  font-size: 0.75rem;
  font-weight: 760;
}

.item-quantity strong {
  color: var(--orange-strong);
  font-size: 1.65rem;
  line-height: 1;
}

.card-actions {
  display: grid;
  grid-template-columns: 112px 104px 44px 44px;
  align-content: center;
  gap: 8px;
  padding: 14px;
}

.empty-state {
  min-height: 300px;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
}

.empty-state strong {
  display: block;
  margin-bottom: 7px;
  color: var(--text);
  font-size: 1.2rem;
}

.modal {
  width: min(440px, calc(100vw - 28px));
  max-height: calc(100vh - 32px);
  padding: 18px;
  color: var(--text);
}

.modal.wide {
  width: min(760px, calc(100vw - 28px));
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.52);
  backdrop-filter: blur(8px);
}

.history-list {
  display: grid;
  gap: 10px;
  max-height: 62vh;
  overflow: auto;
  padding-right: 4px;
}

.history-row {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 12px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.06);
}

.history-row strong {
  color: var(--text);
}

.history-row span,
.history-row p {
  color: var(--muted);
}

.history-row p {
  margin-bottom: 0;
  overflow-wrap: anywhere;
}

.photo-dialog {
  width: min(980px, calc(100vw - 28px));
}

.photo-viewer {
  display: grid;
  min-height: min(62vh, 620px);
  max-height: calc(100vh - 190px);
  overflow: hidden;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.28);
}

.photo-viewer img {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 210px);
  object-fit: contain;
}

.photo-open-link {
  width: 100%;
  margin-top: 12px;
  text-decoration: none;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 36px));
  padding: 13px 15px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 18px;
  color: var(--text);
  background: rgba(35, 35, 37, 0.88);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  border-color: rgba(255, 92, 92, 0.55);
}

@media (max-width: 1040px) {
  .item-card {
    grid-template-columns: 96px minmax(0, 1fr) 96px;
  }

  .card-actions {
    grid-column: 1 / -1;
    grid-template-columns: 1fr 1fr 44px 44px;
    padding-top: 0;
  }
}

@media (max-width: 720px) {
  .shell {
    padding: 8px 10px 12px;
  }

  .topbar {
    position: sticky;
    top: 8px;
    z-index: 30;
    align-items: center;
    flex-direction: row;
    min-height: 58px;
    gap: 8px;
    padding: 8px;
    border-radius: 20px;
  }

  .top-actions {
    display: flex;
    gap: 6px;
    margin-left: auto;
  }

  .brand {
    gap: 8px;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 14px;
    font-size: 1rem;
  }

  .brand .eyebrow {
    display: none;
  }

  h1 {
    font-size: 1.2rem;
  }

  .action-button {
    min-width: 82px;
    min-height: 38px;
    padding: 0 10px;
    border-radius: 14px;
    font-size: 0.86rem;
  }

  .pill-button.action-button {
    padding: 0 10px;
  }

  .inventory-layout {
    margin-top: 12px;
  }

  .tools,
  .overview-row,
  .placement-preview,
  .field-row {
    grid-template-columns: 1fr;
  }

  .placement-cabinet-preview {
    height: 300px;
    min-height: 300px;
  }

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

  .stat {
    min-height: 66px;
    padding: 10px 8px;
    border-radius: 16px;
  }

  .stat span {
    font-size: 0.68rem;
  }

  .stat strong {
    margin-top: 5px;
    font-size: 1.25rem;
  }

  .cabinet-panel {
    min-height: 360px;
  }

  .cabinet-map {
    height: 380px;
    min-height: 340px;
  }

  .items-grid {
    grid-template-columns: 1fr;
  }

  .item-card {
    grid-template-columns: 82px minmax(0, 1fr);
  }

  .item-photo {
    min-height: 106px;
  }

  .item-quantity {
    grid-column: 1 / -1;
    grid-template-columns: 1fr auto;
    justify-items: stretch;
    align-items: center;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    border-left: 0;
  }

  .item-quantity strong {
    text-align: right;
  }

  .card-actions {
    grid-column: 1 / -1;
    grid-template-columns: 1fr 1fr 44px 44px;
  }
}

@media (max-width: 420px) {
  .card-actions {
    grid-template-columns: 1fr 1fr;
  }

  .card-actions .icon-button {
    width: 100%;
  }
}
