:root {
  color-scheme: light dark;
  --border: #d7dde8;
  --accent: #1d4ed8;
  --accent-strong: #1e40af;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --text: #0f172a;
  --text-muted: #475569;
}

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

body {
  font-family: system-ui, sans-serif;
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #f8fafc 0%, #eef2ff 100%);
  color: var(--text);
}

header, main {
  width: min(1100px, calc(100% - 2rem));
  margin: 0 auto;
}

header {
  padding: 1rem 0 0.75rem;
}

main {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 1.25rem;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.08);
  margin-bottom: 1.5rem;
}

header h1 a {
  color: inherit;
  text-decoration: none;
}

header h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: -0.03em;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.topnav {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.topnav a {
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 600;
  padding-bottom: 0.2rem;
  border-bottom: 2px solid transparent;
}

.topnav a.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.subnav {
  display: flex;
  gap: 1rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.subnav a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.user-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.module-card {
  display: block;
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  text-decoration: none;
  color: inherit;
  background: var(--surface-muted);
  transition: border-color 0.15s ease;
}

.module-card:hover {
  border-color: var(--accent);
}

.module-card h2 {
  margin: 0 0 0.4rem;
  font-size: 1.1rem;
}

.module-card p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.module-card-soon {
  opacity: 0.55;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  margin: 1rem 0;
}

.stat-tile {
  padding: 1rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-muted);
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 600;
  font-variant-numeric: proportional-nums;
  color: var(--text);
}

.stat-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0 0 1rem;
}

.status-chip {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
}

/* Change ticket status. "open" is a new blue -- neither "good" nor "bad",
   just "still active". "closed" reuses flock-cad's own
   status-chip-available green ("nothing outstanding here"), same meaning
   in both apps: nothing left to do on this one. */
.status-chip-open {
  color: #1d4ed8;
  background: #dbeafe;
  border-color: #93c5fd;
}

.status-chip-closed {
  color: #15803d;
  background: #dcfce7;
  border-color: #86efac;
}

/* Admin is deliberately the same blue as status-chip-open rather than a
   warning color -- being an admin is a normal state, not a problem. */
.status-chip-admin {
  color: #1d4ed8;
  background: #dbeafe;
  border-color: #93c5fd;
}

.page-intro {
  color: var(--text-muted);
  max-width: 60ch;
}

.user-cell {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.user-avatar {
  border-radius: 50%;
  flex: 0 0 auto;
}

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

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 1rem 0 1.25rem;
  gap: 0.875rem;
  flex-wrap: wrap;
}

.search-form {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  align-items: center;
}

.search-form input,
.search-form select,
.item-form input,
.item-form select,
.item-form textarea,
.item-form button,
.button,
.link-button {
  font: inherit;
}

input[type="text"],
input[type="number"],
input[type="file"],
select,
textarea {
  width: 100%;
  box-sizing: border-box;
  min-height: 2.75rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}

textarea {
  min-height: 7rem;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
button:focus,
a:focus {
  outline: 3px solid rgba(29, 78, 216, 0.2);
  outline-offset: 2px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 16px;
}

.mobile-inventory-list {
  display: none;
}

.sticker-selection {
  display: none;
}

body.sticker-mode th.sticker-selection,
body.sticker-mode td.sticker-selection {
  display: table-cell;
}

body.sticker-mode input.sticker-selection {
  display: inline-block;
}

.sticker-download {
  display: none;
}

body.sticker-mode .sticker-download {
  display: inline-flex;
}

body.sticker-mode .sticker-create {
  display: none;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
  background: var(--surface);
}

th, td {
  text-align: left;
  padding: 0.8rem 0.9rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  background: var(--surface-muted);
  color: var(--text-muted);
  font-size: 0.92rem;
  letter-spacing: 0.01em;
}

tbody tr:hover td {
  background: #f8fbff;
}

.actions {
  display: flex;
  gap: 0.85rem;
  align-items: center;
  flex-wrap: wrap;
  min-width: 10.5rem;
}

.desktop-inventory .actions form {
  margin: 0;
}

.item-name-cell {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.link-button {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

.sign-out-link {
  color: var(--accent);
}

.button {
  display: inline-block;
  padding: 0.65rem 0.9rem;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: white;
  text-decoration: none;
  border-radius: 12px;
  border: none;
  box-shadow: 0 8px 18px rgba(29, 78, 216, 0.18);
  min-height: 2.35rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
}

.button-secondary {
  padding: 0.5rem 0.75rem;
  min-height: 2rem;
  font-size: 0.9rem;
}

.button-upload-csv {
  align-self: flex-start;
  padding: 0.3rem 0.55rem;
  min-height: 1.75rem;
  font-size: 0.8rem;
  border-radius: 999px;
}

.search-form button {
  min-height: 3rem;
  padding: 0.9rem 1.15rem;
  border: none;
  border-radius: 12px;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: white;
  font-weight: 700;
  box-shadow: 0 8px 18px rgba(29, 78, 216, 0.18);
}

.destructive-link {
  color: #b91c1c;
}

.scan-page {
  max-width: 680px;
  margin: 0 auto;
  /* Which QR code the scanner is expecting right now -- item or
     location -- is the one thing someone glancing at a phone mid-scan
     most needs to see, so it gets a real background wash and border,
     not just a small label. Blue/amber rather than green/red: stays
     distinguishable for the most common forms of color blindness, and
     doesn't accidentally read as "good/bad" the way green/red would --
     neither state is an error. */
  --scan-color: var(--accent);
  --scan-soft: #dbeafe;
  --scan-ring: #93c5fd;
  background: var(--scan-soft);
  border: 1px solid var(--scan-ring);
  border-radius: 20px;
  padding: 1.5rem 1.5rem 1.75rem;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.scan-page[data-scan-state="expecting-location"] {
  --scan-color: #b45309;
  --scan-soft: #fef3e2;
  --scan-ring: #fbbf67;
}

.scan-heading {
  margin: 1rem 0 1.5rem;
}

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--scan-color, var(--accent));
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.scan-heading h2 {
  margin: 0;
}

.scan-status {
  color: var(--text-muted);
}

.scan-actions {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin: 2rem 0;
}

.scan-action {
  width: 100%;
  min-height: 7rem;
  padding: 1rem;
  border: 0;
  border-radius: 16px;
  color: white;
  font: inherit;
  font-size: 1.35rem;
  font-weight: 800;
  text-align: center;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scan-action-checkout {
  background: #15803d;
  box-shadow: 0 8px 18px rgba(21, 128, 61, 0.2);
  cursor: pointer;
}

.scan-action-cancel {
  background: var(--surface);
  color: #b91c1c;
  border: 2px solid #b91c1c;
  cursor: pointer;
}

.scan-actions form {
  max-width: 22rem;
  width: 100%;
}

.scan-action-place {
  background: #15803d;
  box-shadow: 0 8px 18px rgba(21, 128, 61, 0.2);
}

.scanner-panel {
  max-width: 520px;
  margin: 1.5rem auto;
  text-align: center;
}

.scanner-panel h3 {
  margin-bottom: 0.35rem;
}

.scanner-panel p {
  color: var(--text-muted);
}

#qr-reader {
  width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border: 2px solid var(--scan-color, var(--border));
  border-radius: 16px;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  transition: border-color 0.2s ease;
}

#qr-reader video {
  border-radius: 15px;
}

.zoom-control {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin: 0.75rem 0;
}

.zoom-control label {
  color: var(--text-muted);
  font-weight: 600;
}

.zoom-control input[type="range"] {
  flex: 1;
}

.scanner-message {
  min-height: 1.5rem;
}

.scanner-file-label {
  display: inline-block;
  margin-top: 0.5rem;
  color: var(--accent);
  cursor: pointer;
  font-weight: 700;
  text-decoration: underline;
}

.scanner-file {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.scan-reset {
  display: block;
  margin: 2rem 0 0;
  color: var(--accent);
  text-align: center;
  font-weight: 700;
}

.consume-dialog {
  border: none;
  border-radius: 20px;
  padding: 1.75rem;
  max-width: 24rem;
  width: calc(100% - 2rem);
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.25);
  background: var(--surface);
  color: var(--text);
}

.consume-dialog::backdrop {
  background: rgba(15, 23, 42, 0.5);
}

.consume-dialog h2 {
  margin: 0 0 0.5rem;
}

.consume-form {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  margin-top: 1.25rem;
}

.consume-form label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-weight: 700;
  color: var(--text-muted);
}

.consume-form input[type="number"] {
  font-size: 1.75rem;
  font-variant-numeric: tabular-nums;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  text-align: center;
}

.consume-form .scan-actions {
  margin: 0;
}

.item-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 560px;
}

.item-qr {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.75rem;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.item-qr h3 {
  margin: 0;
}

.item-qr img {
  display: block;
  width: 240px;
  height: 240px;
  max-width: 100%;
  border: 1px solid var(--border);
}

.item-form label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.toolbar-stack {
  margin-top: -0.5rem;
  margin-bottom: 1rem;
  justify-content: flex-start;
}

.flashes {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}

.flashes li {
  background: #fff7ed;
  color: #9a3412;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  margin-bottom: 0.65rem;
  border: 1px solid #fed7aa;
}

@media (max-width: 720px) {
  header, main {
    width: calc(100% - 1rem);
  }

  header h1 {
    font-size: 1.45rem;
  }

  .topbar {
    align-items: flex-start;
  }

  main {
    padding: 1rem;
    border-radius: 16px;
  }

  .scan-actions {
    gap: 0.75rem;
    margin: 1.5rem 0;
  }

  .scan-action {
    min-height: 5.5rem;
    font-size: 1.25rem;
  }

  .toolbar {
    align-items: stretch;
  }

  .toolbar > * {
    width: 100%;
  }

  .search-form {
    width: 100%;
  }

  .search-form input,
  .search-form select,
  .search-form button,
  .toolbar .button {
    width: 100%;
  }

  .toolbar .button {
    min-height: 2.5rem;
    padding: 0.6rem 0.85rem;
  }

  .toolbar .button-secondary {
    min-height: 2.05rem;
    padding: 0.45rem 0.7rem;
    font-size: 0.88rem;
  }

  .search-form button {
    min-height: 3.2rem;
    padding: 0.95rem 1rem;
    font-size: 1rem;
    font-weight: 700;
  }

  .toolbar .button-new-item {
    min-height: 3.2rem;
    padding: 0.95rem 1rem;
    font-size: 1rem;
    font-weight: 700;
  }

  .table-wrap {
    overflow-x: visible;
  }

  .desktop-inventory {
    display: none;
  }

  .mobile-inventory-list {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
  }

  .mobile-inventory-item {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    padding: 0.75rem 0.65rem;
    border-bottom: 1px solid var(--border);
    color: inherit;
    text-decoration: none;
  }

  .mobile-inventory-item > .mobile-inventory-info {
    display: grid;
    flex: 1;
    grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr) minmax(3.5rem, 0.55fr);
    gap: 0.5rem;
    align-items: center;
    color: inherit;
    text-decoration: none;
  }

  .mobile-inventory-item:last-child {
    border-bottom: 0;
  }

  .mobile-inventory-item span:last-child {
    text-align: right;
  }

  .mobile-inventory-heading {
    background: var(--surface-muted);
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }

  .csv-toolbar {
    display: none;
  }

  .sticker-toolbar {
    display: none;
  }

  table {
    min-width: 0;
    table-layout: fixed;
  }

  .inventory-table th:nth-child(2),
  .inventory-table td:nth-child(2),
  .inventory-table th:nth-child(3),
  .inventory-table td:nth-child(3),
  .inventory-table th:nth-child(4),
  .inventory-table td:nth-child(4),
  .inventory-table th:nth-child(5),
  .inventory-table td:nth-child(5),
  .inventory-table th:nth-child(6),
  .inventory-table td:nth-child(6),
  .inventory-table th:nth-child(7),
  .inventory-table td:nth-child(7),
  .inventory-table th:nth-child(10),
  .inventory-table td:nth-child(10) {
    display: none;
  }

  .inventory-table th:nth-child(1),
  .inventory-table td:nth-child(1) {
    width: 44%;
  }

  .inventory-table th:nth-child(8),
  .inventory-table td:nth-child(8) {
    width: 20%;
    text-align: center;
  }

  .inventory-table th:nth-child(9),
  .inventory-table td:nth-child(9) {
    width: 36%;
  }

  .locations-table th:nth-child(1),
  .locations-table td:nth-child(1) {
    width: 34%;
  }

  .locations-table th:nth-child(2),
  .locations-table td:nth-child(2) {
    width: 34%;
  }

  .locations-table th:nth-child(3),
  .locations-table td:nth-child(3) {
    width: 32%;
  }

  .locations-table img {
    width: min(120px, 100%);
    height: auto;
  }

  th, td {
    padding: 0.55rem 0.4rem;
    font-size: 0.88rem;
  }

  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .danger-actions {
    margin-top: 0.75rem;
  }

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

  .actions {
    flex-direction: column;
    align-items: flex-start;
  }
}
