:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #15171a;
  --muted: #5d6673;
  --line: #dde2e8;
  --line-strong: #c5ccd6;
  --accent: #1b6b5f;
  --accent-dark: #0f4d44;
  --accent-soft: #e3f2ee;
  --danger: #b42318;
  --danger-soft: #fee4e2;
  --warning: #9a6700;
  --warning-soft: #fff4ce;
  --ok: #16703c;
  --ok-soft: #ddf4e7;
  --shadow: 0 8px 24px rgba(23, 28, 38, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.4;
}

body.no-scroll {
  overflow: hidden;
}

body:not(.is-admin) .admin-only {
  display: none !important;
}

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

button {
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 12px;
  cursor: pointer;
  white-space: nowrap;
}

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

.primary {
  background: var(--accent);
  color: #ffffff;
}

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

.danger-button {
  background: var(--danger);
  color: #ffffff;
}

.danger-button:hover {
  background: #8f1a12;
}

.danger-outline {
  background: #ffffff;
  border-color: #f4b1aa;
  color: var(--danger);
}

.danger-outline:hover {
  background: var(--danger-soft);
  border-color: var(--danger);
}

.secondary {
  background: #ffffff;
  border-color: var(--line-strong);
  color: var(--text);
}

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

.secondary.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  box-shadow: 0 0 0 2px rgba(27, 107, 95, 0.16);
}

.secondary.active:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.ghost {
  min-height: 30px;
  background: transparent;
  color: var(--muted);
  padding: 0 8px;
}

.wide {
  width: 100%;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand-lockup {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.brand-mark {
  width: 58px;
  height: 44px;
  object-fit: contain;
}

.brand-copy {
  min-width: 0;
}

.center-name {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.15;
  letter-spacing: 0;
}

h2 {
  font-size: 15px;
  line-height: 1.2;
  letter-spacing: 0;
}

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

.header-actions,
.section-title,
.form-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 3px;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.header-meta .muted {
  font-weight: 600;
}

.mode-badge,
.count-pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 700;
}

.mode-badge {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
}

.login-panel {
  display: grid;
  min-height: calc(100vh - 94px);
  place-items: start center;
  padding: 42px 18px;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-card h2 {
  margin-top: 4px;
  font-size: 20px;
}

.form-message {
  min-height: 20px;
  color: var(--danger);
  font-weight: 700;
}

.side-panel,
.inventory-panel {
  min-width: 0;
}

.side-panel {
  display: grid;
  align-content: start;
  gap: 14px;
}

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

.metric,
.filters,
.inventory-date-panel,
.access-settings,
.editor,
.unmatched,
.inventory-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  min-height: 74px;
  padding: 12px;
}

.metric span {
  display: block;
  font-size: 23px;
  font-weight: 800;
}

.metric label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.metric.danger span {
  color: var(--danger);
}

.metric.warning span {
  color: var(--warning);
}

.filters,
.inventory-date-panel,
.access-settings,
.editor,
.unmatched {
  padding: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.label-with-help {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.help-dot {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 17px;
  height: 17px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: #ffffff;
  color: var(--accent-dark);
  cursor: help;
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
}

.help-dot:hover::after,
.help-dot:focus::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  z-index: 30;
  width: min(300px, calc(100vw - 36px));
  padding: 9px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #ffffff;
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.35;
  text-transform: none;
  white-space: normal;
}

input,
select,
textarea {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  padding: 7px 9px;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  outline: 2px solid rgba(27, 107, 95, 0.16);
}

.password-field {
  position: relative;
  display: block;
}

.password-field input {
  padding-right: 42px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 5px;
  display: inline-grid;
  width: 32px;
  height: 32px;
  min-height: 32px;
  place-items: center;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  transform: translateY(-50%);
}

.password-toggle:hover,
.password-toggle.active {
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.password-toggle svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
}

.filters,
form {
  display: grid;
  gap: 12px;
}

.inventory-date-form {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 8px;
}

.inventory-date-form input {
  min-height: 38px;
}

.access-settings-form {
  display: grid;
  gap: 10px;
}

.access-settings-status {
  margin: 9px 0;
  font-size: 12px;
}

.access-settings-help {
  margin-bottom: 9px;
  font-size: 12px;
  line-height: 1.35;
}

.quantity-filter {
  display: grid;
  grid-template-columns: 1fr;
  align-items: end;
  gap: 10px;
}

.quantity-filter.has-threshold {
  grid-template-columns: 1fr;
}

.quantity-filter label {
  display: grid;
  grid-template-columns: 108px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.quantity-filter label > span {
  line-height: 1.18;
}

.quantity-filter input,
.quantity-filter select {
  min-height: 42px;
}

.section-title {
  justify-content: space-between;
  margin-bottom: 12px;
}

.form-row {
  align-items: end;
}

.form-row > * {
  flex: 1;
}

.check-row {
  min-height: 36px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-transform: none;
}

.check-row input {
  width: 16px;
  min-height: 16px;
}

.photo-drop {
  display: grid;
  gap: 4px;
  min-height: 86px;
  padding: 14px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: #f8fafb;
  color: var(--muted);
  cursor: pointer;
  place-items: center;
  text-align: center;
}

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

.photo-drop.drag-over,
.item-card.drag-over {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.pending-photos {
  display: grid;
  gap: 6px;
}

.pending-photo {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--muted);
  font-size: 12px;
}

.pending-photo button {
  min-height: 26px;
  padding: 0 8px;
}

.unmatched-list {
  display: grid;
  gap: 6px;
  max-height: 180px;
  overflow: auto;
}

.unmatched-list code {
  display: block;
  padding: 7px 8px;
  background: #f4f5f7;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow-wrap: anywhere;
}

.inventory-panel {
  padding: 16px;
}

.list-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.filter-summary {
  margin-top: 4px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

.item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 12px;
}

.item-card {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  align-items: start;
  gap: 12px;
  min-height: 190px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 10px;
}

.item-card.low,
.item-card.out {
  border-color: #f4b1aa;
  background: #fffafa;
}

.item-card.uncounted {
  border-color: #ead08c;
}

.photo-box {
  position: relative;
  width: 112px;
  aspect-ratio: 2 / 3;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f5f7f9;
  overflow: hidden;
  display: grid;
  place-items: center;
  padding: 5px;
}

.photo-button {
  padding: 0;
}

.photo-button:hover {
  border-color: var(--accent);
}

.photo-box img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.photo-dots {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 7px;
  display: flex;
  justify-content: center;
  gap: 4px;
  pointer-events: none;
}

.photo-dot,
.lightbox-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.62);
  border: 1px solid rgba(0, 0, 0, 0.22);
}

.photo-dot.active,
.lightbox-dot.active {
  background: var(--accent);
  border-color: #ffffff;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(10, 13, 18, 0.82);
}

.lightbox-frame {
  display: grid;
  gap: 10px;
  max-width: min(980px, 94vw);
  max-height: 92vh;
  margin: 0;
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  width: 46px;
  height: 46px;
  min-height: 46px;
  border-radius: 50%;
  background: #ffffff;
  color: var(--text);
  font-size: 28px;
  line-height: 1;
  transform: translateY(-50%);
}

.lightbox-nav:disabled {
  display: none;
}

.lightbox-prev {
  left: 18px;
}

.lightbox-next {
  right: 18px;
}

.lightbox img {
  max-width: 100%;
  max-height: 82vh;
  border-radius: 8px;
  object-fit: contain;
  background: #111111;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.32);
}

.lightbox figcaption {
  color: #ffffff;
  text-align: center;
  font-weight: 700;
}

.lightbox-dots {
  display: flex;
  justify-content: center;
  gap: 7px;
}

.lightbox-dot {
  width: 10px;
  height: 10px;
  min-height: 10px;
  padding: 0;
  border-color: rgba(255, 255, 255, 0.72);
}

.lightbox-admin {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.lightbox-close {
  position: absolute;
  top: 18px;
  right: 18px;
  background: #ffffff;
  border-color: transparent;
  color: var(--text);
}

.photo-placeholder {
  padding: 8px;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.item-body {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.item-topline,
.item-actions,
.item-admin-actions,
.stock-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.item-topline {
  justify-content: space-between;
}

.item-id {
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

.item-name {
  font-size: 15px;
  font-weight: 800;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.item-description,
.item-category {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.stock-controls {
  flex-wrap: wrap;
}

.stock-field {
  display: grid;
  gap: 4px;
}

.stock-field label {
  font-size: 10px;
}

.stock-field input {
  width: 72px;
  min-height: 32px;
}

.stock-field.price-field input {
  width: 92px;
}

.readonly-stock {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.readonly-stock strong {
  font-size: 18px;
}

.status-pill.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.status-pill.low,
.status-pill.out {
  background: var(--danger-soft);
  color: var(--danger);
}

.status-pill.uncounted {
  background: var(--warning-soft);
  color: var(--warning);
}

.status-pill.missing-photo {
  background: #edf1f7;
  color: #445064;
}

.edit-btn {
  min-height: 30px;
}

.delete-item-btn {
  min-height: 30px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
  color: var(--text);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

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

.hidden,
.admin-only.hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .app-header,
  .list-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .header-actions,
  .section-title {
    flex-wrap: wrap;
  }
}

@media (max-width: 520px) {
  .app-header {
    padding: 16px;
  }

  .brand-lockup {
    grid-template-columns: 48px minmax(0, 1fr);
    gap: 10px;
  }

  .brand-mark {
    width: 48px;
    height: 38px;
  }

  .center-name {
    font-size: 11px;
  }

  h1 {
    font-size: 20px;
  }

  .app-shell {
    padding: 12px;
  }

  .quantity-filter {
    grid-template-columns: 1fr;
  }

  .quantity-filter.has-threshold {
    grid-template-columns: 1fr;
  }

  .quantity-filter label {
    grid-template-columns: 1fr;
    align-items: start;
    gap: 6px;
  }

  .inventory-date-form {
    grid-template-columns: 1fr;
  }

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

  .item-card {
    grid-template-columns: 86px minmax(0, 1fr);
    min-height: 158px;
  }

  .photo-box {
    width: 86px;
  }

  .readonly-stock {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }
}
