:root {
  --bg: #0b1320;
  --panel: #131e2e;
  --panel-2: #18253a;
  --panel-border: #24344a;
  --brass: #c9963a;
  --brass-bright: #e0b35c;
  --teal: #2dd4bf;
  --text-primary: #e7edf5;
  --text-muted: #8da3bf;
  --status-ok: #3ddc97;
  --status-soon: #f2b134;
  --status-overdue: #ef4444;
  --radius: 14px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }

/* The hidden attribute must always win over any display rule below,
   including .modal/.lightbox's display:flex. Without !important here,
   author CSS of equal specificity beats the browser's built-in
   [hidden]{display:none}, so "hidden" elements render anyway. */
[hidden] { display: none !important; }

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

body {
  padding: 16px 16px 48px;
  max-width: 720px;
  margin: 0 auto;
}

/* ---------- Header ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-dial {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 3px solid var(--brass);
  position: relative;
  flex-shrink: 0;
  background: var(--panel);
}
.brand-dial::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2px;
  height: 12px;
  background: var(--teal);
  transform-origin: bottom center;
  transform: translate(-50%, -100%) rotate(35deg);
}

.brand-text h1 {
  font-size: 1.15rem;
  margin: 0;
  letter-spacing: 0.02em;
  font-weight: 800;
}
.brand-sub {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: ui-monospace, "Courier New", monospace;
}

/* ---------- Buttons ---------- */
button {
  font-family: inherit;
  cursor: pointer;
}

.btn-primary {
  background: var(--brass);
  color: #1a1305;
  border: none;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.95rem;
  min-height: 44px;
}
.btn-primary:active { background: var(--brass-bright); }

.btn-secondary {
  background: var(--panel-2);
  color: var(--text-primary);
  border: 1px solid var(--panel-border);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  min-height: 44px;
}

.btn-text {
  background: none;
  border: none;
  color: var(--status-overdue);
  text-decoration: underline;
  padding: 8px 0;
  font-size: 0.9rem;
}

.btn-icon {
  background: var(--panel-2);
  border: 1px solid var(--panel-border);
  color: var(--text-primary);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.stat-pill {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 10px 6px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-num { font-size: 1.4rem; font-weight: 800; font-family: ui-monospace, "Courier New", monospace; }
.stat-label { font-size: 0.68rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

.stat-overdue .stat-num { color: var(--status-overdue); }
.stat-soon .stat-num { color: var(--status-soon); }
.stat-ok .stat-num { color: var(--status-ok); }

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.toolbar input, .toolbar select {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text-primary);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  min-height: 44px;
}
#search { flex: 1 1 160px; min-width: 0; }
.toolbar select { flex: 0 1 140px; }
.toolbar .btn-secondary { flex: 0 0 auto; }

/* ---------- List / Cards ---------- */
.list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 14px 14px 14px 16px;
  position: relative;
  border-left: 5px solid var(--panel-border);
}
.card[data-status="overdue"] { border-left-color: var(--status-overdue); }
.card[data-status="soon"] { border-left-color: var(--status-soon); }
.card[data-status="ok"] { border-left-color: var(--status-ok); }

/* rivet motif, echoes the app icon, used sparingly */
.card::before, .card::after {
  content: "";
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--panel-border);
  top: 8px;
}
.card::before { right: 10px; }
.card::after { right: 22px; }

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

.card-name { font-size: 1.02rem; font-weight: 700; margin: 0 0 2px; }
.card-meta { font-size: 0.82rem; color: var(--text-muted); margin: 0; }

.status-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}
.status-badge.overdue { background: rgba(239,68,68,0.15); color: var(--status-overdue); }
.status-badge.soon { background: rgba(242,177,52,0.15); color: var(--status-soon); }
.status-badge.ok { background: rgba(61,220,151,0.15); color: var(--status-ok); }

.card-body { margin-top: 10px; font-size: 0.88rem; color: var(--text-primary); }
.card-body .due-line { font-family: ui-monospace, "Courier New", monospace; color: var(--text-muted); margin: 4px 0; }
.card-notes { margin: 6px 0 0; white-space: pre-wrap; word-break: break-word; }

.card-thumb {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  margin-top: 10px;
  cursor: pointer;
}

.card-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.card-actions button {
  flex: 1;
  padding: 9px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid var(--panel-border);
  background: var(--panel-2);
  color: var(--text-primary);
}
.card-actions .delete-btn { color: var(--status-overdue); }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  margin-top: 60px;
  padding: 0 20px;
  line-height: 1.5;
}

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}
.modal-panel {
  background: var(--panel);
  border-radius: var(--radius) var(--radius) 0 0;
  border-top: 1px solid var(--panel-border);
  width: 100%;
  max-width: 720px;
  max-height: 92vh;
  overflow-y: auto;
  padding: 18px 18px 24px;
}
@media (min-width: 600px) {
  .modal { align-items: center; }
  .modal-panel { border-radius: var(--radius); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.modal-header h2 { margin: 0; font-size: 1.1rem; }

.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 0.82rem; color: var(--text-muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--panel-border);
  color: var(--text-primary);
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  min-height: 44px;
}
.field textarea { min-height: 70px; resize: vertical; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.field-hint {
  font-size: 0.8rem;
  color: var(--teal);
  margin: -4px 0 14px;
  font-family: ui-monospace, "Courier New", monospace;
}

.photo-preview-wrap { margin: -4px 0 14px; }
.photo-preview-wrap img {
  width: 100%;
  max-height: 200px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  background: #000;
}

.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions button { flex: 1; }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
}
.lightbox img { max-width: 94%; max-height: 90%; border-radius: var(--radius-sm); }
.lightbox-close { position: absolute; top: 16px; right: 16px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--panel-border);
  color: var(--text-primary);
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  z-index: 70;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

/* ---------- Misc ---------- */
:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- Yeilvastore Branding ---------- */
.brand-by {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 1px;
  letter-spacing: 0.03em;
}

.brand-store-link {
  color: var(--brass);
  text-decoration: none;
  font-weight: 700;
}
.brand-store-link:hover { color: var(--brass-bright); }

.app-footer {
  margin-top: 48px;
  padding: 20px 0 12px;
  border-top: 1px solid var(--panel-border);
  text-align: center;
}
.app-footer p {
  margin: 6px 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.5;
}
.app-footer a {
  color: var(--brass);
  text-decoration: none;
  font-weight: 600;
}
.app-footer a:hover { color: var(--brass-bright); }

.footer-cta {
  margin-top: 10px !important;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 10px 14px !important;
  font-size: 0.85rem !important;
  color: var(--text-primary) !important;
}

/* ---------- Backup Notice ---------- */
.backup-notice {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: rgba(201, 150, 58, 0.08);
  border: 1px solid rgba(201, 150, 58, 0.3);
  border-left: 4px solid var(--brass);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 16px;
}

.backup-icon {
  font-size: 1.3rem;
  flex-shrink: 0;
  margin-top: 1px;
}

.backup-text strong {
  display: block;
  font-size: 0.88rem;
  color: var(--brass-bright);
  margin-bottom: 3px;
}

.backup-text p {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.backup-notice-btn {
  background: none;
  border: none;
  color: var(--brass);
  font-weight: 700;
  font-size: 0.8rem;
  padding: 0;
  text-decoration: underline;
  cursor: pointer;
  font-family: inherit;
}
.backup-notice-btn:hover { color: var(--brass-bright); }

/* ---------- Multi-photo grid (form) ---------- */
.photo-grid-form {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px;
  margin: -4px 0 14px;
}
.photo-grid-form .thumb-wrap {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--panel-border);
  background: #000;
  cursor: pointer;
}
.photo-grid-form .thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.photo-grid-form .thumb-remove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(239,68,68,0.9);
  color: white;
  border: none;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  line-height: 1;
}

/* ---------- Multi-photo strip (card) ---------- */
.photo-strip {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--panel-border) transparent;
}
.photo-strip::-webkit-scrollbar { height: 3px; }
.photo-strip::-webkit-scrollbar-thumb { background: var(--panel-border); border-radius: 2px; }

.photo-strip .card-thumb {
  width: 72px;
  height: 72px;
  flex-shrink: 0;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  cursor: pointer;
  margin-top: 0;
}
.photo-count-badge {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
  font-family: ui-monospace, "Courier New", monospace;
}

/* ---------- Lightbox nav ---------- */
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0,0,0,0.6);
  border: 1px solid var(--panel-border);
  color: var(--text-primary);
  width: 48px;
  height: 64px;
  font-size: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  cursor: pointer;
  z-index: 61;
  line-height: 1;
}
.lightbox-prev { left: 12px; }
.lightbox-next { right: 12px; }
.lightbox-nav[hidden] { display: none !important; }

.lightbox-counter {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.82rem;
  color: var(--text-muted);
  font-family: ui-monospace, "Courier New", monospace;
  background: rgba(0,0,0,0.5);
  padding: 4px 10px;
  border-radius: 999px;
  margin: 0;
}

.field-sub {
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 400;
  margin-left: 6px;
}

/* ═══ TAB BAR ════════════════════════════════════════════════════════════ */
.tab-bar {
  display: flex;
  gap: 4px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 16px;
}
.tab-btn {
  flex: 1;
  padding: 10px 8px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  min-height: 44px;
  transition: background 0.15s, color 0.15s;
}
.tab-btn.active {
  background: var(--brass);
  color: #1a1305;
}

/* ═══ SPARE PARTS CARDS ══════════════════════════════════════════════════ */
.spare-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 14px 14px 14px 16px;
  position: relative;
  border-left: 5px solid var(--panel-border);
}
.spare-card[data-stock="out"]  { border-left-color: var(--status-overdue); }
.spare-card[data-stock="low"]  { border-left-color: var(--status-soon); }
.spare-card[data-stock="ok"]   { border-left-color: var(--status-ok); }

/* rivet motif */
.spare-card::before, .spare-card::after {
  content: ""; position: absolute;
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--panel-border); top: 8px;
}
.spare-card::before { right: 10px; }
.spare-card::after  { right: 22px; }

.spare-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.spare-name    { font-size: 1.02rem; font-weight: 700; margin: 0 0 2px; }
.spare-partno  { font-size: 0.8rem; color: var(--text-muted);
                 font-family: ui-monospace,"Courier New",monospace; margin: 0; }

/* Quantity badge */
.qty-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  min-width: 56px;
}
.qty-num {
  font-size: 1.8rem;
  font-weight: 800;
  font-family: ui-monospace,"Courier New",monospace;
  line-height: 1;
}
.qty-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-top: 2px;
}
[data-stock="out"]  .qty-num { color: var(--status-overdue); }
[data-stock="low"]  .qty-num { color: var(--status-soon); }
[data-stock="ok"]   .qty-num { color: var(--status-ok); }

.spare-meta {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin: 8px 0 0;
  line-height: 1.5;
}
.spare-meta span { display: inline-block; margin-right: 10px; }
.spare-linked {
  font-size: 0.8rem;
  color: var(--teal);
  margin: 4px 0 0;
}

/* Quick quantity adjust buttons */
.qty-adjust {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
}
.qty-adjust-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: var(--panel-2);
  color: var(--text-primary);
  font-size: 1.3rem;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-family: inherit;
  flex-shrink: 0;
}
.qty-adjust-btn.plus  { color: var(--status-ok);  border-color: var(--status-ok); }
.qty-adjust-btn.minus { color: var(--status-overdue); border-color: var(--status-overdue); }
.qty-adjust-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  flex: 1;
}

.spare-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.spare-actions button {
  flex: 1;
  padding: 9px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid var(--panel-border);
  background: var(--panel-2);
  color: var(--text-primary);
  font-family: inherit;
  cursor: pointer;
}
.spare-actions .delete-btn { color: var(--status-overdue); }
