/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242736;
  --border: #2e3248;
  --text: #e8eaf0;
  --text-muted: #8890a8;
  --primary: #4f8ef7;
  --primary-dark: #3a7ae0;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
  --nav-h: 64px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

/* ── Nav ── */
.nav {
  position: fixed;
  bottom: 0;
  left: 0; right: 0;
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  padding: 8px 4px;
  transition: color 0.15s;
}

.nav-btn .nav-icon { font-size: 20px; }
.nav-btn.active { color: var(--primary); }
.nav-btn:hover { color: var(--text); }

/* ── Views ── */
.view {
  min-height: calc(100vh - var(--nav-h));
  padding: 16px 16px calc(var(--nav-h) + 16px);
  max-width: 600px;
  margin: 0 auto;
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.view-header h1 {
  font-size: 22px;
  font-weight: 700;
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 6px;
}

.card-desc {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.mt-8 { margin-top: 8px; }

.card-list { display: flex; flex-direction: column; gap: 8px; }

/* ── Upload area ── */
.upload-area {
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}

.upload-prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 40px 20px;
}

.upload-icon { font-size: 48px; }
.upload-text { color: var(--text-muted); font-size: 14px; text-align: center; }

.upload-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px;
}

.upload-preview img {
  max-width: 100%;
  max-height: 280px;
  border-radius: var(--radius-sm);
  object-fit: contain;
}

/* ── Loading ── */
.loading-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 32px;
  color: var(--text-muted);
}

.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Result card ── */
.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.result-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.result-name { font-size: 18px; font-weight: 700; }
.result-meta { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.result-description { font-size: 14px; color: var(--text-muted); }

.confidence-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
}
.confidence-high { background: rgba(34,197,94,0.15); color: var(--success); }
.confidence-med  { background: rgba(245,158,11,0.15); color: var(--warning); }
.confidence-low  { background: rgba(239,68,68,0.15); color: var(--danger); }

.location-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
}
.location-badge.found { background: rgba(34,197,94,0.12); color: var(--success); }
.location-badge.new   { background: rgba(245,158,11,0.12); color: var(--warning); }
.location-icon { font-size: 18px; }

/* ── Part number lookup ── */
.lookup-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-muted);
}
.spinner-sm {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
.lookup-found {
  margin-top: 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}
.lookup-body {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.lookup-part-img {
  width: 72px;
  height: 72px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  background: #fff;
  padding: 4px;
  flex-shrink: 0;
}
.lookup-name { font-size: 15px; font-weight: 700; margin-bottom: 2px; }
.lookup-meta { font-size: 12px; color: var(--text-muted); }
.lookup-actions { display: flex; gap: 8px; }
.lookup-not-found {
  margin-top: 10px;
  font-size: 13px;
  color: var(--danger);
}

/* ── Brick Architect links ── */
.ba-divider {
  border-top: 1px solid var(--border);
  margin: 4px 0;
}
.ba-header {
  display: flex;
  align-items: center;
  gap: 8px;
}
.ba-part-img {
  width: 100%;
  max-height: 140px;
  object-fit: contain;
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 6px;
  margin-bottom: 10px;
  display: block;
}
.ba-icon {
  width: 16px;
  height: 16px;
  border-radius: 3px;
}
.ba-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
}
.ba-title:hover { text-decoration: underline; }
.ba-downloads {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

/* ── Input ── */
.input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s;
}
.input:focus { border-color: var(--primary); }

.input-row {
  display: flex;
  gap: 8px;
}
.input-row .input { flex: 1; }

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: rgba(239,68,68,0.15); color: var(--danger); }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.w-full { width: 100%; }

/* ── Search ── */
.search-bar { margin-bottom: 12px; }

/* ── Catalog search ── */
.catalog-results {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.catalog-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.catalog-result-item:hover { border-color: var(--primary); }
.catalog-result-info { flex: 1; min-width: 0; }
.catalog-result-name { font-size: 14px; font-weight: 600; }
.catalog-result-num { font-size: 12px; color: var(--text-muted); margin-top: 1px; }
.catalog-result-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
}
.catalog-badge-cataloged { background: rgba(34,197,94,0.15); color: var(--success); }
.catalog-badge-new { background: rgba(245,158,11,0.12); color: var(--warning); }
.catalog-no-results { margin-top: 8px; font-size: 13px; color: var(--text-muted); }
.catalog-load-prompt { margin-top: 8px; font-size: 13px; color: var(--text-muted); }
.btn-link {
  background: none; border: none; color: var(--primary);
  font-size: 13px; font-weight: 600; cursor: pointer; padding: 0; text-decoration: underline;
}

/* ── Part images from Brick Architect ── */
.part-img-sm {
  width: 48px;
  height: 48px;
  object-fit: contain;
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 3px;
  flex-shrink: 0;
}
.part-img-lg {
  width: 100%;
  max-height: 120px;
  object-fit: contain;
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 8px;
  display: block;
  margin-bottom: 14px;
}

/* ── Part list item ── */
.part-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.part-item:hover { border-color: var(--primary); }

.part-info { flex: 1; min-width: 0; }
.part-item-name { font-size: 15px; font-weight: 600; }
.part-item-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.drawer-chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Drawers grid ── */
.drawers-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cabinet-section { margin-bottom: 20px; }
.cabinet-label { font-size: 13px; font-weight: 700; color: var(--text-muted); margin-bottom: 10px; text-transform: uppercase; letter-spacing: 0.05em; }

.drawer-row-label-group { margin-bottom: 10px; }
.drawer-row-label { font-size: 11px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }

.drawer-grid-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 8px;
}

.drawer-tile {
  border-radius: var(--radius-sm);
  padding: 8px 6px;
  text-align: center;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.drawer-tile:active { transform: scale(0.96); }

/* Occupied — red */
.drawer-tile.occupied {
  background: rgba(239,68,68,0.12);
  border: 1px solid rgba(239,68,68,0.35);
}
.drawer-tile.occupied:hover { border-color: rgba(239,68,68,0.7); }
.drawer-tile.occupied .drawer-tile-id { color: #f87171; }

/* Empty real drawer — green */
.drawer-tile.empty {
  background: rgba(34,197,94,0.10);
  border: 1px solid rgba(34,197,94,0.30);
}
.drawer-tile.empty:hover { border-color: rgba(34,197,94,0.6); }
.drawer-tile.empty .drawer-tile-id { color: #4ade80; }

/* Virtual (inferred) empty slot — muted green */
.drawer-tile.virtual {
  background: rgba(34,197,94,0.05);
  border: 1px dashed rgba(34,197,94,0.25);
}
.drawer-tile.virtual:hover { border-color: rgba(34,197,94,0.5); }
.drawer-tile.virtual .drawer-tile-id { color: #4ade80; opacity: 0.7; }

.drawer-tile-id { font-size: 13px; font-weight: 700; }
.drawer-tile-img {
  width: 56px;
  height: 56px;
  object-fit: contain;
  background: #fff;
  border-radius: 4px;
  padding: 3px;
}
.drawer-tile-count { font-size: 10px; color: var(--text-muted); }
.drawer-tile-label { font-size: 10px; color: var(--text-muted); max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Stats ── */
.stats-row {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}
.stat-box {
  flex: 1;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 10px;
  text-align: center;
}
.stat-num { font-size: 20px; font-weight: 700; }
.stat-label { font-size: 11px; color: var(--text-muted); }

/* ── Import result ── */
.import-result {
  margin-top: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
}
.import-result.success { background: rgba(34,197,94,0.12); color: var(--success); }
.import-result.error   { background: rgba(239,68,68,0.12); color: var(--danger); }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: flex-end;
  z-index: 200;
}

.modal {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px 16px calc(var(--nav-h) + 16px);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-header h2 { font-size: 18px; font-weight: 700; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

/* ── Drawer picker ── */
.drawer-picker-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.drawer-option {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: border-color 0.15s;
}
.drawer-option:hover { border-color: var(--primary); }
.drawer-option.selected { border-color: var(--primary); background: rgba(79,142,247,0.1); }
.drawer-option-id { font-size: 14px; font-weight: 700; color: var(--primary); }
.drawer-option-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.drawer-option-count { font-size: 12px; color: var(--text-muted); }

.new-drawer-form { display: flex; flex-direction: column; gap: 10px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

/* ── Login overlay ── */
.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-logo {
  font-size: 48px;
  text-align: center;
}

.login-title {
  font-size: 26px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 8px;
}

.login-hint {
  font-size: 14px;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 4px;
}

#login-form, #new-password-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.login-error {
  font-size: 13px;
  color: var(--danger);
  text-align: center;
  padding: 8px;
  background: rgba(239,68,68,0.1);
  border-radius: var(--radius-sm);
}
