:root {
  --bg: #0a0a0f;
  --surface: #13131f;
  --surface2: #1c1c2e;
  --border: #2a2a40;
  --accent: #4F6EE8;
  --accent2: #9B4EC5;
  --accent3: #E84B8A;
  --text: #e2e8f0;
  --muted: #7c8db5;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
  --radius-sm: 6px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

/* ── Header ── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 32px;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-size: 16px;
  font-weight: 700;
  background: linear-gradient(90deg, var(--accent), var(--accent2), var(--accent3));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
}

nav { display: flex; gap: 4px; }

nav button {
  background: none;
  border: none;
  color: var(--muted);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
}

nav button:hover { color: var(--text); background: var(--surface2); }
nav button.active { color: var(--accent); background: rgba(79,110,232,0.1); }

/* ── Layout ── */
main { padding: 24px; max-width: 1400px; margin: 0 auto; }

.tab { display: none; }
.tab.active { display: block; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #3d5bd4; }
.btn-ghost { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: rgba(239,68,68,0.1); color: var(--danger); border: 1px solid rgba(239,68,68,0.3); }
.btn-danger:hover { background: rgba(239,68,68,0.2); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px; background: none; border: none; cursor: pointer; color: var(--muted); border-radius: var(--radius-sm); transition: all 0.15s; }
.btn-icon:hover { color: var(--text); background: var(--surface2); }

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

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

.card-title { font-size: 15px; font-weight: 600; }

/* ── Grid ── */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-products { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }

/* ── Forms ── */
.form-group { margin-bottom: 14px; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 500; }

input, select, textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input::placeholder, textarea::placeholder { color: var(--muted); }
select option { background: var(--surface2); }

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

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
}

.badge-eco { background: rgba(34,197,94,0.15); color: #4ade80; border: 1px solid rgba(34,197,94,0.2); }
.badge-cat-sdb { background: rgba(79,110,232,0.15); color: #818cf8; border: 1px solid rgba(79,110,232,0.2); }
.badge-cat-menage { background: rgba(155,78,197,0.15); color: #c084fc; border: 1px solid rgba(155,78,197,0.2); }
.badge-cat-gourmand { background: rgba(232,75,138,0.15); color: #f472b6; border: 1px solid rgba(232,75,138,0.2); }
.badge-cat-libre { background: rgba(100,116,139,0.15); color: #94a3b8; border: 1px solid rgba(100,116,139,0.2); }
.badge-optional { background: rgba(245,158,11,0.1); color: var(--warning); border: 1px solid rgba(245,158,11,0.2); }

/* ── Product Card ── */
.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}

.product-card:hover { border-color: var(--accent); transform: translateY(-1px); }

.product-card-img {
  width: 100%;
  height: 140px;
  object-fit: cover;
  background: var(--surface2);
}

.product-card-img-placeholder {
  width: 100%;
  height: 140px;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 28px;
}

.product-card-body { padding: 14px; }
.product-card-name { font-weight: 600; font-size: 14px; margin-bottom: 6px; line-height: 1.3; }
.product-card-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.product-card-price { display: flex; align-items: baseline; gap: 6px; margin-top: 8px; }
.product-card-price .price-main { font-size: 18px; font-weight: 700; color: var(--accent); }
.product-card-price .price-unit { font-size: 11px; color: var(--muted); }
.product-card-footer { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-top: 1px solid var(--border); }
.source-count { font-size: 12px; color: var(--muted); }

/* ── Sources table ── */
.sources-table { width: 100%; border-collapse: collapse; }
.sources-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

.sources-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: middle;
}

.sources-table tr:last-child td { border-bottom: none; }
.sources-table tr.is-favorite { background: rgba(79,110,232,0.05); }

.fav-btn { background: none; border: none; cursor: pointer; font-size: 16px; padding: 2px 6px; border-radius: 4px; }
.fav-btn.active { color: #f59e0b; }
.fav-btn:not(.active) { color: var(--muted); }
.fav-btn:not(.active):hover { color: #f59e0b; }

/* ── Extract panel ── */
.extract-panel {
  background: var(--surface2);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
}

.extract-panel .title { font-weight: 600; margin-bottom: 12px; }

.extract-preview {
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 16px;
  display: none;
}

.extract-preview.show { display: flex; gap: 16px; align-items: flex-start; }

.extract-preview img {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--surface2);
  flex-shrink: 0;
}

.extract-preview-info { flex: 1; }
.extract-preview-name { font-weight: 600; font-size: 15px; margin-bottom: 6px; }
.extract-preview-price { color: var(--accent); font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.extract-preview-meta { color: var(--muted); font-size: 12px; }

/* ── Kit cards ── */
.kit-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.kit-card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kit-card-title { font-size: 15px; font-weight: 700; }
.kit-cost { font-size: 20px; font-weight: 700; color: var(--accent); }
.kit-cost-label { font-size: 11px; color: var(--muted); }

.kit-items-list { padding: 8px 0; min-height: 80px; }

.kit-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

.kit-item:last-child { border-bottom: none; }
.kit-item:hover { background: var(--surface2); }

.kit-item-name { flex: 1; font-size: 13px; }
.kit-item-qty { width: 70px; text-align: center; }
.kit-item-qty input { text-align: center; padding: 4px 8px; }
.kit-item-price { font-size: 13px; color: var(--muted); width: 80px; text-align: right; }
.kit-item-actions { display: flex; gap: 4px; }

.kit-add-row { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.kit-add-row select { flex: 1; }

.no-price { color: var(--warning); font-size: 12px; }

/* ── Simulation panel ── */
.sim-panel { display: grid; grid-template-columns: 360px 1fr; gap: 24px; align-items: start; }

.sim-controls .card { margin-bottom: 16px; }

.sim-result-big {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.result-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
}

.result-box.highlight { border-color: var(--accent); background: rgba(79,110,232,0.05); }
.result-box.positive { border-color: var(--success); background: rgba(34,197,94,0.05); }

.result-label { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.result-value { font-size: 28px; font-weight: 700; }
.result-value.green { color: var(--success); }
.result-value.blue { color: var(--accent); }
.result-value.purple { color: var(--accent2); }

.breakdown-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.breakdown-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

.breakdown-table td { padding: 9px 12px; border-bottom: 1px solid var(--border); }
.breakdown-table tr:last-child td { border-bottom: none; }
.breakdown-table .optional-row td { color: var(--muted); font-style: italic; }

/* ── Margin slider ── */
.slider-wrap { display: flex; align-items: center; gap: 12px; }
.slider-wrap input[type=range] {
  flex: 1;
  -webkit-appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  border: none;
  padding: 0;
}

.slider-wrap input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
}

.slider-value {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  width: 64px;
  text-align: center;
  font-weight: 600;
  color: var(--accent);
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-overlay.show { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 760px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
}

.modal-title { font-size: 16px; font-weight: 700; }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

/* ── Misc ── */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.section-title { font-size: 18px; font-weight: 700; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
.filter-btn { background: var(--surface2); border: 1px solid var(--border); color: var(--muted); padding: 5px 14px; border-radius: 20px; cursor: pointer; font-size: 12px; font-weight: 500; transition: all 0.15s; }
.filter-btn:hover, .filter-btn.active { background: rgba(79,110,232,0.1); border-color: var(--accent); color: var(--accent); }

.empty-state { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty-icon { font-size: 36px; margin-bottom: 12px; }
.empty-text { font-size: 15px; margin-bottom: 16px; }

.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 13px;
  z-index: 500;
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.2s;
  max-width: 320px;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { border-color: var(--success); color: #4ade80; }
.toast.error { border-color: var(--danger); color: #f87171; }

.persons-toggle { display: flex; gap: 6px; }
.persons-btn {
  padding: 6px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
}

.persons-btn.active { background: rgba(79,110,232,0.1); border-color: var(--accent); color: var(--accent); }

.divider { height: 1px; background: var(--border); margin: 16px 0; }

@media (max-width: 900px) {
  .grid-3 { grid-template-columns: 1fr; }
  .sim-panel { grid-template-columns: 1fr; }
  .sim-result-big { grid-template-columns: 1fr 1fr; }
}
