:root {
  --navy: #eaf2ff;
  --navy-mid: #f7fbff;
  --navy-light: #dceaff;
  --navy-border: #c9dcf5;
  --blue: #2563eb;
  --blue-bright: #3b82f6;
  --blue-glow: rgba(37, 99, 235, 0.35);
  --blue-soft: rgba(59, 130, 246, 0.12);
  --white: #ffffff;
  --off-white: #f8fafc;
  --ink: #0f172a;
  --body: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-dark: #334155;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --amber: #d97706;
  --amber-soft: #fef3c7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --sidebar-w: 260px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
}

body {
  display: flex;
  min-height: 100vh;
  background: var(--off-white);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

/* ─── Sidebar ─────────────────────────────────────────── */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #f6faff 0%, var(--navy) 100%);
  border-right: 1px solid var(--navy-border);
  z-index: 100;
}

.sidebar-top {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 1rem;
}

.sidebar-bottom {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--navy-border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 2.5rem;
  padding: 0 0.25rem;
}

.brand-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  flex-shrink: 0;
  border-radius: 0.7rem;
  background: linear-gradient(135deg, var(--blue), #1d4ed8);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.08), 0 8px 20px var(--blue-glow);
  color: white;
  font-size: 0.9rem;
}

.brand-name {
  color: #153056;
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.2;
}

.brand-sub {
  color: #64748b;
  font-size: 0.74rem;
  font-weight: 500;
  margin-top: 0.15rem;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 2rem;
}

.sidebar-divider {
  height: 1px;
  margin: 0.75rem 0;
  background: var(--navy-border);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.72rem 0.9rem;
  border: 1px solid transparent;
  border-radius: 0.85rem;
  background: transparent;
  color: #52677f;
  font-size: 0.88rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.nav-item:hover {
  background: var(--navy-light);
  color: #17365f;
}

.nav-item.active {
  background: #ffffff;
  border-color: #b8d1f5;
  color: var(--blue);
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.11);
}

.nav-icon {
  font-size: 1rem;
  width: 1.2rem;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-section-label {
  color: #6b7f99;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin: 0 0.25rem 0.5rem;
}

.sidebar-select {
  display: block;
  width: 100%;
  margin-bottom: 1.5rem;
  padding: 0.72rem 0.9rem;
  border: 1px solid var(--navy-border);
  border-radius: 0.85rem;
  background: var(--navy-mid);
  color: #153056;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%232563eb' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.9rem center;
}

.sidebar-select:focus {
  border-color: var(--blue-bright);
}

.status-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.status-dot {
  width: 0.55rem;
  height: 0.55rem;
  flex-shrink: 0;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.2);
}

.status-text {
  color: #52677f;
  font-size: 0.8rem;
  font-weight: 600;
}

/* ─── Main ────────────────────────────────────────────── */

.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ─── Topbar ──────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 2rem;
  background: rgba(248, 250, 252, 0.88);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.page-title {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--ink);
}

.ghost-btn {
  padding: 0.55rem 1rem;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: white;
  color: var(--body);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.ghost-btn:hover {
  border-color: var(--blue-bright);
  box-shadow: 0 0 0 3px var(--blue-soft);
}

/* ─── Content grid ────────────────────────────────────── */

.content {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 2rem;
  padding: 2rem;
  flex: 1;
}

/* ─── Input area ──────────────────────────────────────── */

.input-area {
  display: flex;
  flex-direction: column;
}

.lookup-panel { display: none; flex-direction: column; gap: 1rem; }
.lookup-panel.active { display: flex; }

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.field-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

input, textarea {
  width: 100%;
  padding: 0.9rem 1rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: white;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, textarea:focus {
  border-color: var(--blue-bright);
  box-shadow: 0 0 0 4px var(--blue-soft);
}

textarea {
  resize: vertical;
  min-height: 130px;
  line-height: 1.6;
}

.primary-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border: none;
  border-radius: 1rem;
  background: linear-gradient(135deg, var(--blue), #1d4ed8);
  color: white;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 12px 28px var(--blue-glow);
  transition: transform 0.15s, box-shadow 0.15s;
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 36px var(--blue-glow);
}

.primary-btn:active { transform: translateY(0); }

.btn-arrow {
  font-size: 1.1rem;
  opacity: 0.8;
}

.outline-btn {
  padding: 0.75rem 1rem;
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  background: white;
  color: var(--body);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.outline-btn:hover {
  border-color: var(--blue-bright);
  background: var(--blue-soft);
  color: var(--blue);
}

.btn-row {
  display: flex;
  gap: 0.65rem;
}

.btn-row .outline-btn { flex: 1; }

.camera-box {
  position: relative;
  overflow: hidden;
  min-height: 200px;
  border-radius: 1.1rem;
  background: var(--navy);
  border: 1px solid var(--navy-border);
}

.camera-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.scan-line {
  position: absolute;
  top: 50%;
  left: 10%;
  right: 10%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--blue-bright), transparent);
  box-shadow: 0 0 12px var(--blue-bright);
  animation: scan 2s ease-in-out infinite;
}

@keyframes scan {
  0%, 100% { top: 30%; opacity: 0.6; }
  50% { top: 70%; opacity: 1; }
}

video, #photo-preview {
  display: block;
  width: 100%;
  max-height: 320px;
  object-fit: contain;
}

.crop-workspace {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.crop-stage {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: #0f172a;
  user-select: none;
  touch-action: none;
}

.crop-stage.cropping {
  cursor: crosshair;
}

#photo-preview {
  max-height: 420px;
}

.crop-box {
  position: absolute;
  border: 2px solid #ffffff;
  background: rgba(37, 99, 235, 0.16);
  box-shadow: 0 0 0 9999px rgba(15, 23, 42, 0.52), 0 0 0 1px var(--blue-bright);
  pointer-events: none;
}

.outline-btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.file-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 2.5rem 1rem;
  border: 2px dashed var(--line);
  border-radius: 1.1rem;
  background: white;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}

.file-drop:hover {
  border-color: var(--blue-bright);
  background: var(--blue-soft);
}

.file-drop input { display: none; }

.file-icon {
  font-size: 2rem;
  color: var(--muted);
}

.file-label {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
}

.hint-text {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.55;
}

/* ─── Results ─────────────────────────────────────────── */

.results-area {
  display: flex;
  flex-direction: column;
}

.empty-result {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  flex: 1;
  min-height: 360px;
  padding: 3rem 2.5rem;
  border: 1px solid var(--line);
  border-radius: 1.5rem;
  background: white;
}

.empty-icon {
  font-size: 2.5rem;
  color: var(--blue-bright);
  opacity: 0.35;
  margin-bottom: 1.25rem;
}

.empty-result h2 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--ink);
  margin-bottom: 0.65rem;
}

.empty-result p {
  color: var(--muted);
  max-width: 420px;
  line-height: 1.7;
}

.loading-state {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 2rem;
  border: 1px solid var(--line);
  border-radius: 1.5rem;
  background: white;
  color: var(--muted);
  font-weight: 500;
}

.spinner {
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
  border: 2px solid var(--line);
  border-top-color: var(--blue-bright);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ─── Result card ─────────────────────────────────────── */

.result-card {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 2rem;
  border: 1px solid var(--line);
  border-radius: 1.5rem;
  background: white;
}

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

.result-title {
  font-size: clamp(1.4rem, 2.5vw, 2rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--ink);
  line-height: 1.15;
  margin-bottom: 0.4rem;
}

.result-meta {
  color: var(--muted);
  font-size: 0.88rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.38rem 0.8rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  flex-shrink: 0;
}

.badge.high { background: var(--green-soft); color: var(--green); }
.badge.medium { background: var(--amber-soft); color: var(--amber); }
.badge.low { background: var(--red-soft); color: var(--red); }

.price-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.price-card {
  padding: 1.25rem;
  border: 1px solid #cbd5e1;
  border-radius: 1.1rem;
  background: #ffffff;
}

.price-card.featured {
  border-color: var(--blue-bright);
  background: linear-gradient(135deg, #eff6ff, #dbeafe);
  box-shadow: 0 0 0 1px var(--blue-bright), 0 12px 28px var(--blue-soft);
}

.price-label {
  display: block;
  color: #334155;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.5rem;
}

.price-card.featured .price-label {
  color: var(--blue);
}

.price-value {
  display: block;
  font-size: clamp(1.8rem, 3vw, 2.6rem);
  font-weight: 900;
  letter-spacing: -0.05em;
  color: #0f172a;
  line-height: 1;
}

.price-card.featured .price-value {
  color: var(--blue);
}

.price-range-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.warning-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  list-style: none;
  padding: 0;
}

.warning-list li {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.75rem 1rem;
  border: 1px solid #fde68a;
  border-radius: 0.85rem;
  background: #fffbeb;
  color: #78350f;
  font-size: 0.88rem;
  line-height: 1.5;
}

.warning-list li::before {
  content: "⚠";
  flex-shrink: 0;
  font-size: 0.9rem;
}

.comps-section h3 {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 0.75rem;
}

.comps {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.comps th {
  padding: 0.6rem 0.75rem;
  border-bottom: 2px solid var(--line);
  text-align: left;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.comps td {
  padding: 0.72rem 0.75rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  color: var(--body);
}

.comps tr:last-child td { border-bottom: 0; }

.comps td a {
  color: var(--blue-dark, var(--blue));
  font-weight: 500;
}

.comp-price {
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
}

.comp-source {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: var(--off-white);
  border: 1px solid var(--line);
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--muted);
}

.no-comps {
  padding: 1.5rem;
  border: 1px dashed var(--line);
  border-radius: 1rem;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

/* ─── History ─────────────────────────────────────────── */

.history-section {
  padding: 2rem 2rem 3rem;
}

.history-header {
  display: grid;
  gap: 0.25rem;
  margin-bottom: 1.25rem;
}

.section-heading {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.history-subtitle {
  color: var(--muted);
  font-size: 0.9rem;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.85rem;
}

.history-item {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 1rem 1.15rem;
  border: 1px solid var(--line);
  border-radius: 1.1rem;
  background: white;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.history-item:hover {
  border-color: var(--blue-bright);
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.1);
  transform: translateY(-2px);
}

.history-item-name {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-price {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--blue);
  letter-spacing: -0.03em;
}

.history-item-meta {
  color: var(--muted);
  font-size: 0.78rem;
}

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

/* ─── Responsive ──────────────────────────────────────── */

@media (max-width: 1024px) {
  .content {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }

  .sidebar {
    display: none;
  }

  .main {
    margin-left: 0;
  }

  .content {
    padding: 1rem;
    gap: 1.25rem;
  }

  .history-section {
    padding: 0 1rem 2rem;
  }

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

  .topbar {
    padding: 1rem;
  }
}

@media (max-width: 480px) {
  .price-grid {
    grid-template-columns: 1fr;
  }
}
