:root {
  color-scheme: light;
  --bg: #f6f7f2;
  --surface: #ffffff;
  --ink: #1e2528;
  --muted: #657071;
  --line: #dce2dc;
  --accent: #206f63;
  --accent-strong: #18584f;
  --accent-soft: #e4f2ee;
  --danger: #a23a34;
  --danger-soft: #fae7e4;
  --shadow: 0 16px 45px rgba(31, 42, 46, 0.09);
  --field: #fbfcf9;
  --button-soft: #fbfcf9;
}

body.dark-mode {
  color-scheme: dark;
  --bg: #111521;
  --surface: #1a2030;
  --ink: #eef3ff;
  --muted: #aeb8cc;
  --line: #343d52;
  --accent: #7c8cff;
  --accent-strong: #bec6ff;
  --accent-soft: #242a49;
  --danger: #ff9a91;
  --danger-soft: #3e211f;
  --shadow: 0 16px 45px rgba(0, 0, 0, 0.3);
  --field: #141b1d;
  --button-soft: #20292c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea,
.dashboard-link {
  font: inherit;
}

button {
  cursor: pointer;
}

.dashboard-link {
  min-height: 42px;
  display: inline-grid;
  place-items: center;
  text-decoration: none;
  justify-self: start;
}

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

.app-shell {
  width: min(1220px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.app-shell.auth-only {
  min-height: 100vh;
  display: grid;
  align-content: center;
}

.topbar,
.topbar-actions,
.account-dropdown,
.auth-actions,
.toolbar,
.mode-tabs,
.detail-header,
.detail-actions,
.section-heading,
.location-button,
.item-row,
.edit-actions,
.move-location-header {
  display: flex;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(260px, auto) minmax(150px, 1fr);
  align-items: center;
  gap: 18px;
  margin: -24px calc(50% - 50vw) 18px;
  padding: 18px max(24px, calc((100vw - 1220px) / 2 + 24px));
  border-bottom: 1px solid var(--line);
  background: #070b17;
}

.auth-only .topbar {
  grid-template-columns: 1fr;
  text-align: center;
}

.auth-only .topbar-actions {
  display: none;
}

.auth-only .dashboard-link,
.auth-only .search-bubble {
  display: none !important;
}

.topbar-actions {
  justify-self: end;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.topbar-title {
  text-align: center;
}

.topbar h1,
.panel h2,
.panel h3,
.empty-state h2,
.detail-header h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: clamp(1.35rem, 2vw, 1.95rem);
  line-height: 1.05;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sync-status {
  min-height: 34px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  padding: 0 12px;
}

.sync-status.online {
  border-color: #a9d6ca;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.dashboard,
.mode-panel,
.location-detail,
.items-list,
.location-list,
.edit-grid,
.move-board,
.add-grid {
  display: grid;
  gap: 16px;
}

.tag-list-scroll {
  max-height: 260px;
  overflow: auto;
  padding-right: 4px;
}

.panel,
.toolbar,
.empty-state,
.summary-card,
.mode-tabs {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.auth-panel {
  display: grid;
  grid-template-columns: minmax(220px, 0.9fr) minmax(280px, 1.1fr);
  gap: 18px;
  align-items: start;
  margin-bottom: 16px;
}

.auth-only .auth-panel {
  width: min(820px, 100%);
  margin: 0 auto;
  padding: 26px;
}

.auth-panel h2 {
  margin: 0;
  font-size: clamp(1.5rem, 2.2vw, 2.3rem);
  line-height: 1.1;
}

.label-designer,
.share-dialog {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(21, 28, 30, 0.48);
  padding: 18px;
}

.label-designer.hidden,
.share-dialog.hidden {
  display: none;
}

.label-designer-card,
.share-dialog-card {
  width: min(920px, 100%);
  max-height: min(92vh, 820px);
  overflow: auto;
  display: grid;
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(15, 23, 26, 0.22);
  padding: 20px;
}

.share-dialog-card {
  width: min(460px, 100%);
}

.label-designer-header,
.label-designer-actions,
.share-dialog-header,
.share-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.label-designer-header h2,
.share-dialog-header h2 {
  margin: 0;
}

.share-actions {
  justify-content: flex-end;
}

.account-menu {
  position: relative;
}

.account-button,
.action-dot {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 900;
}

.account-button {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.account-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 12;
  min-width: 170px;
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 8px;
}

.account-dropdown.hidden {
  display: none;
}

.account-dropdown button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font-weight: 800;
  text-align: left;
  padding: 0 10px;
}

.account-dropdown button:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.action-dot {
  flex: 0 0 auto;
  border-radius: 6px;
  background: var(--button-soft);
}

.shared-badge {
  display: inline-block;
  margin-top: 6px;
  border-radius: 999px;
  background: #eef0ff;
  color: #3d4b91;
  font-size: 0.75rem;
  font-weight: 850;
  padding: 4px 8px;
}

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

.label-checks {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 0;
  padding: 14px;
}

.label-checks legend {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  padding: 0 6px;
  text-transform: uppercase;
}

.label-checks label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.label-checks input {
  width: auto;
}

.label-live-preview {
  display: grid;
  align-items: center;
  justify-items: center;
  min-height: 220px;
  border: 1px dashed #b8c4bd;
  border-radius: 8px;
  background: var(--field);
  overflow: auto;
  padding: 16px;
}

.label-size-readout {
  justify-self: stretch;
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-align: center;
}

.preview-label {
  display: grid;
  border-style: solid;
  border-color: #11181a;
  background: white;
  color: #11181a;
  overflow: hidden;
  transform-origin: center;
}

.preview-scale-box {
  position: relative;
  overflow: hidden;
}

.preview-page {
  display: grid;
  overflow: hidden;
  background: white;
  box-shadow: 0 8px 24px rgba(31, 42, 46, 0.18);
}

.preview-qr {
  display: grid;
  align-content: start;
  justify-items: center;
}

.preview-qr img {
  display: block;
  border-style: solid;
  border-color: #d8ddd7;
}

.preview-url {
  max-width: 100%;
  overflow-wrap: anywhere;
  color: #485254;
}

.preview-body {
  min-width: 0;
}

.preview-place {
  color: #206f63;
  font-weight: 900;
  text-transform: uppercase;
}

.preview-parent {
  color: #485254;
  font-weight: 700;
}

.preview-count {
  font-weight: 800;
}

.preview-contents h4 {
  margin: 0;
  text-transform: uppercase;
}

.preview-contents li span {
  color: #5d686a;
}

.preview-more {
  color: #5d686a;
  font-weight: 700;
}

.preview-label h3,
.preview-label p,
.preview-label ul {
  margin: 0;
}

.preview-label ul {
  padding-left: 18px;
}

.label-designer-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.auth-form,
.compact-form,
.item-form,
.edit-form {
  display: grid;
  gap: 14px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.toggle-row small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
}

.toggle-row input {
  width: 24px;
  height: 24px;
}

.auth-actions {
  gap: 10px;
  flex-wrap: wrap;
}

.auth-message,
.muted-copy {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

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

.summary-card {
  padding: 16px;
}

.summary-card span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

.summary-card strong {
  display: block;
  margin-top: 8px;
  font-size: 2rem;
  line-height: 1;
}

.mode-tabs {
  align-items: center;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  padding: 10px;
}

.mobile-mode-control {
  display: none;
}

.mobile-mode-select {
  display: none;
}

.mode-tab {
  min-height: 58px;
  white-space: normal;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--button-soft);
  color: var(--ink);
  padding: 10px 14px;
  font-weight: 850;
  box-shadow: 0 8px 18px rgba(31, 42, 46, 0.05);
  text-align: center;
}

.mode-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  box-shadow: 0 12px 24px rgba(32, 111, 99, 0.18);
}

.mode-tab:hover:not(.active) {
  border-color: #b8ded4;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.toolbar {
  align-items: end;
  gap: 12px;
  padding: 14px;
}

.search-bubble {
  position: relative;
  flex: 1 1 420px;
  max-width: 640px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  align-items: end;
}

.topbar .search-bubble {
  display: none !important;
}

.search-bubble .search {
  min-width: 0;
  text-align: center;
}

.search-bubble .search span {
  text-align: center;
}

.search-bubble input {
  border-radius: 6px;
  min-width: 0;
}

.search-bubble .ghost-button {
  border-radius: 6px;
  min-width: 78px;
}

.search-icon-button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--button-soft);
  color: var(--ink);
  font-size: 1.25rem;
  font-weight: 900;
}

.search-results {
  position: absolute;
  z-index: 20;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 8px;
}

.search-result {
  width: 100%;
  display: grid;
  gap: 3px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  padding: 10px;
  text-align: left;
}

.search-result:hover {
  background: var(--accent-soft);
}

.search-result span {
  font-weight: 850;
}

.search-result small {
  color: var(--muted);
}

.search-page {
  display: grid;
  gap: 14px;
}

.search-page-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.search {
  flex: 1;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
  color: var(--ink);
  outline: none;
  padding: 11px 12px;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(32, 111, 99, 0.14);
}

.primary-button,
.ghost-button,
.danger-button {
  min-height: 42px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 800;
}

.primary-button {
  background: var(--accent);
  color: white;
}

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

.ghost-button {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}

.ghost-button:hover {
  background: var(--button-soft);
}

.danger-button {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: #f2c2bc;
}

.home-grid {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.section-heading {
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.count-pill,
.section-heading span {
  min-width: 34px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 800;
  text-align: center;
  padding: 4px 10px;
}

.location-button {
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--button-soft);
  color: var(--ink);
  padding: 12px;
  padding-left: calc(12px + (var(--location-depth, 0) * 18px));
  text-align: left;
}

.location-picker-details {
  display: grid;
  gap: 12px;
}

.location-picker-toggle {
  width: 100%;
  min-height: 46px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 850;
}

.location-picker-toggle.open {
  margin-bottom: 12px;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.place-group-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 14px 0 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.place-group-heading:first-child {
  margin-top: 0;
}

.place-group-heading strong {
  color: var(--accent-strong);
}

.tree-toggle {
  flex: 0 0 24px;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--surface);
  color: var(--accent-strong);
  font-weight: 900;
  line-height: 1;
}

.location-button > span:not(.tree-toggle) {
  min-width: 0;
  flex: 1;
}

.location-button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.location-name,
.item-name-text,
.move-item-name {
  display: block;
  font-weight: 850;
}

.location-meta,
.item-meta,
.move-item-meta {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.82rem;
}

.detail-header {
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.detail-header h2 {
  font-size: clamp(1.8rem, 2vw, 2.5rem);
}

.detail-actions,
.edit-actions {
  gap: 10px;
  flex-wrap: wrap;
}

.detail-grid,
.add-grid {
  grid-template-columns: minmax(250px, 0.85fr) minmax(280px, 1.15fr);
}

.qr-panel-body {
  display: grid;
  grid-template-columns: 140px 1fr;
  align-items: center;
  gap: 16px;
}

.qr-panel summary {
  cursor: pointer;
  color: var(--ink);
  font-weight: 850;
}

.qr-panel[open] summary {
  margin-bottom: 14px;
}

.qr-image {
  width: 140px;
  height: 140px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.item-form-grid {
  display: grid;
  grid-template-columns: 1fr 96px;
  gap: 12px;
}

.item-row {
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.item-photo-thumb {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 8px;
}

.location-photo {
  width: min(100%, 420px);
  max-height: 260px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.photo-action {
  min-height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 12px;
  font-weight: 800;
}

.photo-action input {
  display: none;
}

.mobile-move-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 10px;
}

.item-name-text {
  margin: 0;
}

.item-meta {
  margin: 3px 0 0;
}

.edit-grid {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.edit-card {
  display: grid;
  gap: 14px;
}

.move-board {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  align-items: start;
}

.move-location {
  min-height: 220px;
  display: grid;
  align-content: start;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 14px;
}

.move-location.drag-over {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(32, 111, 99, 0.16), var(--shadow);
}

.move-location-header {
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.move-location-title {
  margin: 0;
  font-size: 1rem;
}

.move-items {
  display: grid;
  gap: 8px;
  min-height: 120px;
}

.move-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--button-soft);
  padding: 11px;
  cursor: grab;
}

.move-item:active {
  cursor: grabbing;
}

.move-item.dragging {
  opacity: 0.45;
}

.drop-hint {
  border: 1px dashed #b8c4bd;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 800;
  padding: 14px;
  text-align: center;
}

.empty-state {
  min-height: 430px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  text-align: center;
  padding: 30px;
}

.empty-mark {
  display: grid;
  width: 82px;
  height: 82px;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: white;
  font-weight: 900;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
}

.hidden {
  display: none;
}

@media print {
  body {
    background: white;
  }

  .topbar,
  .auth-panel,
  .summary-grid,
  .mode-tabs,
  .toolbar,
  .location-browser,
  .item-form,
  .detail-actions,
  .items-list,
  .section-heading {
    display: none;
  }

  .app-shell {
    width: 100%;
    padding: 0;
  }

  .home-grid,
  .detail-grid {
    display: block;
  }

  .panel,
  .qr-panel-body {
    box-shadow: none;
    border: none;
  }
}

@media (max-width: 860px) {
  .home-grid,
  .detail-grid,
  .add-grid,
  .qr-panel-body {
    grid-template-columns: 1fr;
  }

  .toolbar,
  .detail-header {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
  }

  .topbar-title {
    grid-column: 1 / -1;
    grid-row: 1;
    text-align: center;
  }

  .dashboard-link {
    grid-column: 1;
    grid-row: 2;
  }

  .topbar-actions {
    grid-column: 2;
    grid-row: 2;
    width: auto;
    justify-self: end;
  }

  .search-bubble {
    display: none !important;
    max-width: none;
    width: 100%;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    padding: 8px;
    align-items: center;
  }

  .search-bubble.open {
    display: none !important;
  }

  .search-bubble .search {
    display: block;
    text-align: left;
  }

  .search-bubble .search span {
    display: none;
  }

  .search-bubble input {
    height: 42px;
    min-height: 42px;
    padding: 0 10px;
  }

  .search-bubble .ghost-button {
    height: 42px;
    min-height: 42px;
    min-width: 64px;
    padding: 0 10px;
    flex: 0 0 auto;
  }

  .search-icon-button:not(.hidden) {
    display: grid;
    flex: 0 0 44px !important;
  }

  .detail-actions,
  .topbar-actions {
    width: 100%;
  }

  .topbar-actions {
    width: auto;
  }

  .detail-actions button,
  .toolbar button,
  .topbar-actions button {
    flex: 1;
  }

  .topbar-actions button,
  .topbar-actions .dashboard-link {
    flex: 0 0 auto;
  }

  .topbar-actions .search-icon-button {
    flex: 0 0 44px !important;
  }

  .label-control-grid,
  .label-checks {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 20px, 1220px);
    padding-top: 12px;
  }

  .auth-panel,
  .label-control-grid,
  .label-checks,
  .item-form-grid {
    grid-template-columns: 1fr;
  }

  .summary-grid {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 6px !important;
  }

  .summary-card {
    min-width: 0;
    padding: 8px 5px;
    text-align: center;
  }

  .summary-card span {
    font-size: 0.58rem;
    line-height: 1.1;
  }

  .summary-card strong {
    margin-top: 4px;
    font-size: 1.15rem;
  }

  .search-page-actions {
    grid-template-columns: 1fr;
  }

  .search-page-actions .ghost-button {
    min-height: 42px;
  }

  .mode-tabs {
    display: none;
  }

  .mobile-mode-control {
    display: grid;
  }

  .mobile-mode-select {
    display: block;
  }

  .label-designer-header,
  .label-designer-actions,
  .share-dialog-header,
  .share-actions {
    align-items: stretch;
    flex-direction: column;
  }
}
