:root {
  --bg: #111111;
  --surface: #1b1b1b;
  --surface2: #262626;
  --text: #f0ede6;
  --muted: #9a958a;
  --accent: #c9a24b;
  --accent-dim: #7a6230;
  --danger: #c0564d;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--surface2);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

header h1 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: 0.02em;
}

#storage-indicator {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
}

main { padding: 12px 16px 120px; }

.view { display: none; }
.view.active { display: block; }
.hidden { display: none !important; }

/* ---------- Buttons & inputs: big touch targets ---------- */
.btn {
  min-height: 52px;
  padding: 12px 18px;
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  background: var(--surface2);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #111; font-weight: 700; }
.btn.secondary { background: transparent; }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.big { width: 100%; font-size: 1.15rem; }

input[type="text"],
input[type="search"],
select,
textarea {
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  margin-top: 6px;
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  border-color: var(--accent);
}
textarea { resize: vertical; }

.field { display: block; margin: 18px 0 0; font-weight: 600; }
.field-label { margin: 18px 0 0; font-weight: 600; }

/* ---------- Chips ---------- */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.chip {
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid var(--surface2);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  cursor: pointer;
  touch-action: manipulation;
}
.chip.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #111;
  font-weight: 700;
}

/* ---------- Toolbar ---------- */
.toolbar { margin-bottom: 12px; }
.toolbar select { margin-top: 10px; }

/* ---------- Grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 12px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  padding: 0 0 10px;
  text-align: left;
  color: var(--text);
  cursor: pointer;
  overflow: hidden;
  touch-action: manipulation;
}
.card:active { transform: scale(0.98); }
.card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  background: var(--surface2);
}
.card-name {
  display: block;
  padding: 8px 10px 2px;
  font-weight: 600;
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-meta {
  display: block;
  padding: 0 10px;
  font-size: 0.8rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-loan {
  display: block;
  padding: 2px 10px 0;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}
.empty-state p { margin: 6px 0; font-size: 1.05rem; }
.empty-state .plus {
  display: inline-block;
  width: 30px; height: 30px; line-height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #111;
  font-weight: 700;
}

/* ---------- Backup row ---------- */
.backup-row {
  display: flex;
  gap: 10px;
  margin-top: 24px;
}
.backup-row .btn { flex: 1; }

/* ---------- Form ---------- */
.photo-area { margin-top: 14px; }
#photo-preview {
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  border-radius: var(--radius);
  background: var(--surface);
  display: block;
}
#photo-placeholder {
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--surface2);
  border-radius: var(--radius);
}
.photo-buttons { display: flex; gap: 10px; margin-top: 10px; }
.photo-buttons .btn { flex: 1; }

.stepper {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 10px;
}
.stepper .step {
  width: 64px;
  font-size: 1.5rem;
  font-weight: 700;
}
#qty-value {
  font-size: 1.5rem;
  font-weight: 700;
  min-width: 48px;
  text-align: center;
}

.form-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 24px;
}

/* ---------- Detail ---------- */
#detail-photo {
  width: 100%;
  max-height: 420px;
  object-fit: contain;
  border-radius: var(--radius);
  background: var(--surface);
  margin-top: 12px;
  display: block;
}
#detail-name { margin: 14px 0 6px; font-size: 1.3rem; }
#detail-fields { margin: 0; }
#detail-fields dt {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-top: 14px;
}
#detail-fields dd { margin: 4px 0 0; font-size: 1.05rem; }

/* ---------- FAB ---------- */
#fab {
  position: fixed;
  right: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #111;
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  touch-action: manipulation;
  z-index: 20;
}
#fab:active { transform: scale(0.94); }

/* ---------- Wider screens ---------- */
@media (min-width: 640px) {
  .grid { grid-template-columns: repeat(3, 1fr); }
  main { max-width: 720px; margin: 0 auto; }
}
