@import url("https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,600;9..144,700&family=Source+Sans+3:wght@400;600;700&display=swap");

:root {
  --bg: #f3f1ec;
  --bg-2: #e8e4db;
  --ink: #1c2430;
  --muted: #5c6673;
  --accent: #0f4c81;
  --accent-2: #c45c26;
  --card: #fffdf8;
  --line: #d5d0c4;
  --danger: #9b1c1c;
  --ok: #1f6b3a;
  --shadow: 0 18px 50px rgba(28, 36, 48, 0.08);
  --font-display: "Fraunces", "Iowan Old Style", "Palatino Linotype", serif;
  --font-body: "Source Sans 3", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font-body);
  background:
    radial-gradient(1200px 600px at 10% -10%, #fff8e8 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #d9e7f5 0%, transparent 50%),
    linear-gradient(180deg, var(--bg), var(--bg-2));
}

.topbar {
  position: sticky; top: 0; z-index: 10;
  backdrop-filter: blur(10px);
  background: rgba(243, 241, 236, 0.86);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1100px; margin: 0 auto; padding: 0.85rem 1.25rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.brand {
  font-family: var(--font-display); font-weight: 700; font-size: 1.25rem;
  color: var(--ink); text-decoration: none; letter-spacing: -0.02em;
}
.brand span { color: var(--accent); }
.nav { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.nav a { color: var(--ink); text-decoration: none; font-weight: 600; }
.nav a:hover { color: var(--accent); }
.user { color: var(--muted); font-size: 0.9rem; }
.btn-link {
  background: none; border: none; color: var(--accent); cursor: pointer;
  font: inherit; font-weight: 600; padding: 0; text-decoration: none;
}

.main { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }

.auth-wrap {
  min-height: calc(100vh - 80px); display: grid; place-items: center;
}
.auth-card {
  width: min(420px, 100%); background: var(--card); border: 1px solid var(--line);
  border-radius: 18px; padding: 2rem; box-shadow: var(--shadow);
}
.auth-card h1 { font-family: var(--font-display); margin: 0 0 0.25rem; }
.muted { color: var(--muted); }
.auth-form { display: grid; gap: 1rem; margin-top: 1.25rem; }
label { display: grid; gap: 0.4rem; font-weight: 600; font-size: 0.92rem; }
input[type="email"], input[type="password"], input[type="text"], input[type="search"], input[type="file"] {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 0.8rem 0.95rem;
  font: inherit; background: #fff;
}
input:focus { outline: 2px solid color-mix(in srgb, var(--accent) 35%, white); border-color: var(--accent); }

.btn {
  border: none; border-radius: 999px; padding: 0.8rem 1.25rem; font: inherit; font-weight: 700; cursor: pointer;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }

.alert {
  background: #fde8e8; color: var(--danger); border: 1px solid #f2c3c3;
  border-radius: 12px; padding: 0.75rem 0.9rem; margin: 0.75rem 0;
}
.alert.success { background: #e8f6ec; color: var(--ok); border-color: #b9e0c4; }

.search-hero {
  min-height: calc(100vh - 140px); display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; gap: 0.75rem;
  transition: min-height 0.35s ease;
}
.search-hero.has-query { min-height: auto; padding: 1rem 0 1.5rem; align-items: stretch; text-align: left; }
.logo-title {
  font-family: var(--font-display); font-size: clamp(2.8rem, 7vw, 4.8rem);
  margin: 0; letter-spacing: -0.04em; color: var(--accent);
}
.tagline { margin: 0; color: var(--muted); font-size: 1.05rem; }
.search-hero.has-query .logo-title { font-size: 1.8rem; }
.search-hero.has-query .tagline { display: none; }

.search-form {
  width: min(720px, 100%); display: flex; gap: 0.45rem; margin-top: 0.75rem;
  align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 0.35rem 0.35rem 0.35rem 0.85rem; box-shadow: var(--shadow);
}
.search-form input[type="search"] {
  border: none; background: transparent; padding: 0.7rem 0.4rem; border-radius: 0;
  flex: 1; min-width: 0;
}
.search-form input[type="search"]:focus { outline: none; }
.search-hero.has-query .search-form { width: 100%; }
.btn.icon-btn {
  width: 2.55rem; height: 2.55rem; border-radius: 999px; padding: 0;
  display: inline-grid; place-items: center; flex: 0 0 auto;
  background: #eaf2fa; color: var(--accent); border: 1px solid #c9daf0;
  cursor: pointer;
}
.btn.icon-btn:hover { background: #dceaf8; }
.btn.icon-btn:disabled { opacity: 0.55; cursor: wait; }
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
.image-search-form { width: min(720px, 100%); margin-top: 0.75rem; }
.search-hero.has-query .image-search-form { width: 100%; }
.image-pick-panel {
  display: flex; align-items: center; gap: 0.85rem; flex-wrap: wrap;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 0.75rem 0.9rem; box-shadow: var(--shadow);
}
.image-pick-panel[hidden] { display: none !important; }
.image-local-preview {
  width: 72px; height: 72px; object-fit: cover; border-radius: 10px; background: #eef2f6;
}
.image-pick-actions {
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; flex: 1;
}
.image-search-hint { margin-top: 0.65rem; font-size: 0.92rem; }
.image-search-meta {
  display: grid; grid-template-columns: 96px 1fr; gap: 0.9rem; align-items: start;
  margin: 0.25rem 0 1rem; padding: 0.85rem; background: var(--card);
  border: 1px solid var(--line); border-radius: 16px;
}
.image-search-preview {
  width: 96px; height: 96px; object-fit: cover; border-radius: 12px; background: #eef2f6;
}
.image-desc { margin: 0.2rem 0; color: var(--ink); }
@media (max-width: 700px) {
  .image-search-meta { grid-template-columns: 72px 1fr; }
  .image-search-preview { width: 72px; height: 72px; }
}

.results-meta { color: var(--muted); margin: 0.5rem 0 1rem; }
.result-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.85rem; }
.result-item {
  display: grid; grid-template-columns: 110px 1fr; gap: 1rem; background: var(--card);
  border: 1px solid var(--line); border-radius: 16px; padding: 0.9rem; box-shadow: var(--shadow);
}
.thumb, .thumb-placeholder {
  width: 110px; height: 90px; border-radius: 12px; overflow: hidden; background: #eef2f6;
  display: grid; place-items: center; color: var(--muted); font-size: 0.85rem;
}
.thumb-btn,
.thumb-link {
  width: 100%; height: 100%; padding: 0; border: none; background: #fff; cursor: zoom-in;
  display: block; text-decoration: none; color: inherit;
}
.thumb-btn:focus-visible,
.thumb-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.thumb img {
  width: 100%; height: 100%; object-fit: contain; background: #fff; display: block;
  pointer-events: none;
}

body.lightbox-open { overflow: hidden; }
.lightbox {
  position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center;
  padding: 1rem;
}
.lightbox[hidden] { display: none !important; }
.lightbox-backdrop {
  position: absolute; inset: 0; background: rgba(18, 24, 32, 0.72); backdrop-filter: blur(3px);
  cursor: zoom-out;
}
.lightbox-dialog {
  position: relative; z-index: 1; width: min(1100px, 96vw); max-height: 92vh;
  background: #fff; border-radius: 16px; border: 1px solid var(--line);
  box-shadow: var(--shadow); padding: 1rem 1rem 0.85rem; display: grid; gap: 0.75rem;
}
.lightbox-image {
  width: 100%; max-height: calc(92vh - 5rem); object-fit: contain; background: #f7f5f0;
  border-radius: 10px;
}
.lightbox-caption {
  margin: 0; color: var(--muted); font-size: 0.95rem; text-align: center;
}
.lightbox-close {
  position: absolute; top: 0.55rem; right: 0.65rem; width: 2.2rem; height: 2.2rem;
  border: none; border-radius: 999px; background: rgba(28, 36, 48, 0.85); color: #fff;
  font-size: 1.4rem; line-height: 1; cursor: pointer;
}
.lightbox-close:hover { background: rgba(28, 36, 48, 1); }
.code-row { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.code-btn {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700;
  background: #eaf2fa; color: var(--accent); border: 1px solid #c9daf0; border-radius: 8px;
  padding: 0.25rem 0.55rem; cursor: pointer;
}
.code-btn:hover { background: #dceaf8; }
.catalog-badge {
  font-size: 0.78rem; color: var(--muted); background: #f0eee8; border-radius: 999px; padding: 0.2rem 0.55rem;
}
.supplier-badge {
  font-size: 0.78rem; font-weight: 700; color: #7a3e00; background: #ffe8c7;
  border: 1px solid #f0c48a; border-radius: 999px; padding: 0.35rem 0.7rem;
  display: inline-block; vertical-align: middle;
  max-width: 11.5rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: help;
}
.europarts-badge {
  font-size: 0.78rem; font-weight: 700; color: #0f4c81; background: #e7f0f8;
  border: 1px solid #c5d8ea; border-radius: 999px; padding: 0.35rem 0.7rem;
  display: inline-block; white-space: nowrap; vertical-align: middle;
}
.table .col-origine {
  min-width: 140px;
  width: 16%;
  white-space: nowrap;
}
.table .col-origine .supplier-badge {
  max-width: 12.5rem;
}
.result-body .supplier-badge {
  max-width: 10.5rem;
}
.result-item.is-supplier {
  border-color: #efc48d;
  background: linear-gradient(180deg, #fffaf2, #fffdf8);
  box-shadow: 0 18px 50px rgba(122, 62, 0, 0.06);
}
.supplier-note {
  margin: 0.2rem 0 0.35rem; color: #7a3e00; font-size: 0.9rem; font-weight: 600;
}
.admin-hint { margin: 0 0 1rem; }
.owner-fields {
  border: 1px solid var(--line); border-radius: 12px; padding: 0.9rem; display: grid; gap: 0.75rem;
}
.row-supplier td { background: #fffaf2; }
.product-name { margin: 0.35rem 0 0.2rem; font-size: 1.05rem; }
.compat, .oem { margin: 0.15rem 0; color: var(--muted); font-size: 0.92rem; }
.empty { color: var(--muted); }

.admin-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.admin-head h1 { font-family: var(--font-display); margin: 0; }
.table-wrap { overflow: auto; background: var(--card); border: 1px solid var(--line); border-radius: 16px; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 0.85rem 0.9rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table th { font-size: 0.85rem; color: var(--muted); background: #faf7f0; }
.actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.inline { display: inline; }
.status { text-transform: uppercase; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.04em; }
.status-ready { color: var(--ok); }
.status-processing, .status-uploaded { color: var(--accent); }
.status-failed { color: var(--danger); }
.error-row td { color: var(--danger); font-size: 0.9rem; background: #fff5f5; }

.upload-form { display: grid; gap: 1rem; max-width: 680px; background: var(--card); padding: 1.25rem; border-radius: 16px; border: 1px solid var(--line); }
.csv-map { border: 1px dashed var(--line); border-radius: 12px; padding: 0.9rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.check { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; }

@media (max-width: 700px) {
  .result-item { grid-template-columns: 1fr; }
  .thumb, .thumb-placeholder { width: 100%; height: 140px; }
  .search-form { flex-direction: column; border-radius: 18px; padding: 0.6rem; }
  .grid-2 { grid-template-columns: 1fr; }
}
