:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --primary: #722f37;
  --primary-soft: #f7eef1;
  --text: #111827;
  --muted: #667085;
  --border: #d0d5dd;
  --green: #15803d;
  --red: #be123c;
  --amber: #b45309;
  --blue: #2563eb;
  --shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  line-height: 1.4;
}

.app-header {
  max-width: 1480px;
  margin: 0 auto;
  padding: 18px 16px 10px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}
.app-header h1 { margin: 0; font-size: 24px; color: var(--primary); }
.app-header p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.header-stack { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.header-stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 800;
  color: var(--primary);
  box-shadow: var(--shadow);
}
.header-stat.subtle { color: var(--muted); }

.container {
  max-width: 1480px;
  margin: 0 auto;
  padding: 0 16px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 16px;
}
.card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}
h2 { margin: 0; font-size: 15px; color: var(--primary); }
h3 { margin: 16px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #f2f4f7;
  color: #475467;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}
.badge.good { background: #ecfdf3; color: var(--green); }
.badge.warn { background: #fffaeb; color: var(--amber); }
.badge.bad { background: #fff1f3; color: var(--red); }

.hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  background: linear-gradient(135deg, #ffffff, #fff7f8);
}
.hero h2 { font-size: 20px; }
.hero p { margin: 6px 0 0; max-width: 760px; color: var(--muted); font-size: 13px; }
.hero-actions {
  position: fixed;
  right: 18px;
  top: 68px;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 210px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.12);
  backdrop-filter: blur(10px);
}

.btn-generate, .btn-secondary {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.18;
}
.hero-actions .btn-generate,
.hero-actions .btn-secondary {
  width: 100%;
  min-height: 40px;
}
.hero-actions .btn-generate { min-height: 48px; }
.btn-generate { background: var(--primary); color: #fff; }
.btn-secondary { background: #f2f4f7; color: #344054; border: 1px solid var(--border); }
.btn-generate:hover, .btn-secondary:hover { filter: brightness(0.97); }

.quiz-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 14px;
  align-items: start;
}
.quiz-panel { display: flex; flex-direction: column; gap: 14px; }
.quiz-question { padding: 14px; }
.quiz-question-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}
.quiz-question h2 { font-size: 16px; }
.quiz-question p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.question-weight {
  font-size: 11px;
  color: var(--primary);
  font-weight: 900;
  background: var(--primary-soft);
  border-radius: 999px;
  padding: 5px 8px;
}
.answer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
}
.answer-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: #fcfcfd;
  min-height: 118px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: .15s ease;
}
.answer-card:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.answer-card.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: inset 0 0 0 1px var(--primary);
}
.answer-title { font-size: 14px; font-weight: 900; color: #1d2939; }
.answer-subtitle { color: var(--muted); font-size: 12px; }
.answer-tags { display: flex; gap: 5px; flex-wrap: wrap; margin-top: auto; }
.tag-pill {
  font-size: 10px;
  color: #344054;
  background: #eef2f6;
  border-radius: 999px;
  padding: 3px 6px;
  font-weight: 700;
}
.answer-card.selected .tag-pill { background: #fff; color: var(--primary); }

.sticky-summary { position: sticky; top: 14px; }
.profile-kpis {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.profile-kpis div {
  background: #f8fafc;
  border: 1px solid #eef2f6;
  border-radius: 10px;
  padding: 10px;
}
.profile-kpis span { display: block; color: var(--muted); font-size: 10px; text-transform: uppercase; font-weight: 800; }
.profile-kpis strong { display: block; font-size: 14px; margin-top: 4px; }
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 95px 1fr 44px; align-items: center; gap: 8px; font-size: 11px; }
.bar-track { height: 9px; border-radius: 999px; background: #eef2f6; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--primary); border-radius: 999px; }
.prob-list { display: flex; flex-direction: column; gap: 7px; }
.prob-group { border: 1px solid #eef2f6; border-radius: 10px; padding: 8px; background: #fcfcfd; }
.prob-group strong { display: block; margin-bottom: 5px; font-size: 11px; color: var(--primary); }
.prob-items { display: flex; flex-wrap: wrap; gap: 5px; }
.prob-item { font-size: 10px; background: #f2f4f7; border-radius: 999px; padding: 3px 6px; }
.tag-cloud { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-cloud .tag-pill { background: var(--primary-soft); color: var(--primary); }
.calc-details {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fcfcfd;
  padding: 12px;
}
.calc-details h3 { margin-top: 0; }
.calc-table-wrap {
  overflow-x: auto;
  border: 1px solid #eef2f6;
  border-radius: 10px;
}
.calc-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 560px;
  font-size: 10px;
}
.calc-table th,
.calc-table td {
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid #eef2f6;
  padding: 7px 8px;
}
.calc-table th {
  color: var(--muted);
  text-transform: uppercase;
  font-size: 9px;
  font-weight: 900;
  background: #f8fafc;
}
.calc-table tr:last-child td { border-bottom: 0; }
.calc-table td:first-child { color: var(--primary); font-weight: 800; }
.calc-table td:nth-child(3) { white-space: nowrap; color: #101828; }

.expert-card { padding: 0; overflow: hidden; }
details summary {
  list-style: none;
  cursor: pointer;
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-weight: 900;
  color: var(--primary);
}
details summary::-webkit-details-marker { display: none; }
details summary small { color: var(--muted); font-weight: 600; }
details[open] summary { border-bottom: 1px solid var(--border); }
.controls-grid {
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(4, minmax(220px, 1fr));
  gap: 16px;
}
.control-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.control-row label { width: 132px; flex: 0 0 132px; font-size: 11px; color: var(--muted); font-weight: 800; }
.control-row input[type="range"] { flex: 1; accent-color: var(--primary); }
.control-row span { width: 38px; text-align: right; font-size: 11px; color: var(--primary); font-weight: 900; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.field label { font-size: 10px; text-transform: uppercase; color: var(--muted); font-weight: 900; }
input[type="number"], select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px;
  font-size: 12px;
  background: #fff;
}
.form-grid.three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.sub-panel { background: #f8fafc; border: 1px solid #eef2f6; border-radius: 10px; padding: 10px; margin-top: 8px; }
.hidden { display: none !important; }

.filter-note {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.alert-banner {
  margin: 0 16px 0;
  background: #fffaeb;
  border: 1px solid #fedf89;
  color: #92400e;
  border-radius: 10px;
  padding: 10px;
  font-size: 12px;
  display: none;
}

.results-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(420px, 0.75fr);
  gap: 14px;
}
.recs-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
}
.rec-card {
  border: 1px solid var(--border);
  border-top: 5px solid var(--primary);
  border-radius: 12px;
  padding: 12px;
  background: #fff;
}
.rec-card.exploration { border-top-color: var(--blue); }
.rec-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.rec-name {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 13px;
  font-weight: 900;
  color: var(--primary);
  min-height: 36px;
  overflow-wrap: anywhere;
}
.rec-role-badge {
  flex: 0 1 128px;
  justify-content: center;
  max-width: 128px;
  min-height: 0;
  border-radius: 10px;
  line-height: 1.2;
  text-align: center;
  white-space: normal;
  overflow-wrap: anywhere;
}
.rec-card.exploration .rec-name { color: var(--blue); }
.rec-score { font-size: 24px; font-weight: 950; }
.rec-meta { color: var(--muted); font-size: 10px; margin: 6px 0 8px; }
.wine-sensory-profile {
  border: 1px solid #eef2f6;
  border-radius: 10px;
  background: #fcfcfd;
  padding: 8px;
  margin: 8px 0;
}
.wine-sensory-title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
  margin-bottom: 6px;
  font-size: 10px;
  font-weight: 900;
  color: var(--primary);
  text-transform: uppercase;
}
.wine-sensory-title small {
  font-size: 9px;
  color: var(--muted);
  text-transform: none;
  font-weight: 700;
}

.legend-target,
.legend-wine {
  display: inline-block;
  vertical-align: middle;
  position: relative;
}
.legend-target {
  width: 2px;
  height: 14px;
  border-radius: 2px;
  background: #111827;
  margin: 0 4px 0 2px;
  transform: translateY(-1px);
}
.legend-wine {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--primary);
  border: 1px solid #ffffff;
  box-shadow: 0 0 0 1px rgba(114,47,55,.25);
  margin: 0 4px 0 2px;
}
.sensory-legend-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin: -1px 0 7px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
}
.sensory-legend-row span {
  white-space: nowrap;
}
.sensory-scale-list { display: flex; flex-direction: column; gap: 5px; }
.sensory-row {
  display: grid;
  grid-template-columns: 62px minmax(72px, 1fr) 70px;
  gap: 6px;
  align-items: center;
  font-size: 10px;
}
.sensory-label { color: #344054; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sensory-scale {
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: visible;
}
.sensory-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  border-radius: 999px;
  background: rgba(114, 47, 55, 0.28);
}
.target-marker {
  position: absolute;
  top: -4px;
  width: 2px;
  height: 16px;
  border-radius: 2px;
  background: #111827;
  transform: translateX(-1px);
}
.wine-marker {
  position: absolute;
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--primary);
  border: 1px solid #ffffff;
  transform: translate(-4px, -50%);
  box-shadow: 0 0 0 1px rgba(114,47,55,.25);
}
.sensory-value {
  color: var(--muted);
  font-weight: 800;
  text-align: right;
  white-space: nowrap;
}
.rec-reasons { display: flex; flex-direction: column; gap: 4px; font-size: 11px; }
.reason-line { background: #f8fafc; border-radius: 8px; padding: 5px 7px; display: flex; justify-content: space-between; gap: 10px; }
.empty-state { color: var(--muted); padding: 18px; text-align: center; border: 1px dashed var(--border); border-radius: 12px; }
.table-container { overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
.contribution-table-wrap { overflow: visible; }
.contribution-card .table-container { overflow: visible; }
.contribution-card table { table-layout: auto; }
.debug-scroll { max-height: 520px; }
table { width: 100%; border-collapse: collapse; font-size: 11px; }
th, td { padding: 8px 10px; border-bottom: 1px solid #eef2f6; text-align: left; vertical-align: top; }
th { background: #f8fafc; color: var(--muted); text-transform: uppercase; font-size: 10px; white-space: nowrap; }
tr.selected { background: #f0fdf4; }
tr.exploration-row { background: #eff6ff; }
tr.skipped { opacity: .55; }

@media (max-width: 1660px) {
  .hero-actions {
    top: auto;
    right: 16px;
    bottom: 16px;
    width: auto;
    flex-direction: row;
  }
  .hero-actions .btn-generate,
  .hero-actions .btn-secondary {
    width: auto;
  }
  body { padding-bottom: 76px; }
}

@media (max-width: 1180px) {
  .quiz-layout, .results-grid { grid-template-columns: 1fr; }
  .sticky-summary { position: static; }
  .controls-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 720px) {
  .app-header, .hero, details summary { flex-direction: column; align-items: stretch; }
  .hero-actions {
    top: auto;
    right: 10px;
    bottom: 10px;
    left: 10px;
    width: auto;
    flex-direction: row;
  }
  .hero-actions .btn-generate,
  .hero-actions .btn-secondary {
    min-width: 0;
    white-space: normal;
  }
  body { padding-bottom: 78px; }
  .controls-grid { grid-template-columns: 1fr; }
  .answer-grid { grid-template-columns: 1fr; }
  .profile-kpis { grid-template-columns: 1fr; }
}


.profile-radar-block {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fcfcfd;
  padding: 12px;
}
.profile-radar-block h3 { margin-top: 0; }
.radar-chart {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 380px;
  overflow: visible;
  padding: 6px 0;
}
.radar-chart svg { width: 100%; max-width: 460px; height: auto; display: block; overflow: visible; }
.radar-ring { fill: none; stroke: #e5e7eb; stroke-width: 1; }
.radar-axis { stroke: #cbd5e1; stroke-width: 1; }
.radar-profile { fill: rgba(114, 47, 55, 0.18); stroke: var(--primary); stroke-width: 2.5; }
.radar-point { fill: var(--primary); stroke: #ffffff; stroke-width: 1.5; }
.radar-label { font-size: 10px; font-weight: 800; fill: #475467; }
.radar-value { font-size: 9px; font-weight: 700; fill: var(--primary); }
.radar-note { margin-top: 6px; color: var(--muted); font-size: 11px; text-align: center; }

/* V5.6 layout adjustment: wider debug table and fixed radar label space */
.debug-card table { min-width: 1180px; }


/* V5.8 price corridor step */
.price-question {
  border-top: 3px solid rgba(114, 47, 55, 0.25);
}
.price-grid {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}
.price-card .price-range {
  display: inline-block;
  margin: 4px 0 6px 0;
  font-size: 12px;
  font-weight: 800;
  color: var(--primary);
}
.price-card.selected .price-range {
  color: #ffffff;
}


/* V5.9 feedback and LocalStorage session log */
.feedback-panel {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.feedback-title {
  font-size: 10px;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.feedback-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 7px;
}
.feedback-btn {
  border: 1px solid var(--border);
  background: #ffffff;
  color: #344054;
  border-radius: 8px;
  padding: 7px 6px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
}
.feedback-btn:hover { border-color: rgba(114, 47, 55, 0.55); }
.feedback-btn.selected[data-feedback="positive"] { background: #ecfdf3; border-color: #16a34a; color: #166534; }
.feedback-btn.selected[data-feedback="neutral"] { background: #fffbeb; border-color: #f59e0b; color: #92400e; }
.feedback-btn.selected[data-feedback="negative"] { background: #fef2f2; border-color: #ef4444; color: #991b1b; }
.feedback-reason {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 8px;
  font-size: 11px;
  background: #fff;
  color: #344054;
}
.feedback-log-card { margin-top: 0; }
.log-note {
  color: var(--muted);
  font-size: 12px;
  margin-top: 0;
}
.log-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}
.btn-secondary.danger {
  border-color: #fecaca;
  color: #991b1b;
}
.log-preview {
  min-height: 70px;
  max-height: 180px;
  overflow: auto;
  background: #0f172a;
  color: #e5e7eb;
  border-radius: 10px;
  padding: 10px;
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-wrap;
}


/* V5.10 imported JSON log reader */
.log-reader-block {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.log-reader-block h3 {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--primary);
}
.file-input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  background: #fff;
  font-size: 12px;
  color: #344054;
}
.log-reader-summary {
  margin: 8px 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f8fafc;
  font-size: 12px;
  color: #344054;
}
.log-reader-table-wrap {
  max-height: 340px;
}
.log-reader-table {
  min-width: 1120px;
}
.log-reader-table td, .log-reader-table th {
  font-size: 11px;
}
.feedback-positive { color: #027a48; font-weight: 800; }
.feedback-neutral { color: #b54708; font-weight: 800; }
.feedback-negative { color: #b42318; font-weight: 800; }
.feedback-missing { color: #667085; font-weight: 800; }

.btn-generate:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}
