/* keyword-research — Data-Dense Dashboard, light mode.
   Sémantique décision : vert = payant/argent · ambre = gratuit/piège à volume · rouge = mauvais marché. */
:root {
  /* surfaces */
  --bg:        #f6f8fb;
  --surface:   #ffffff;
  --surface-2: #f1f5f9;
  --elev:      #ffffff;
  --border:    #e2e8f0;
  --border-strong: #cbd5e1;
  /* texte */
  --text:      #0f172a;
  --text-2:    #475569;
  --text-3:    #64748b;
  /* data / accents */
  --blue:      #2563eb;
  --blue-dim:  #1d4ed8;
  --paid:      #059669;  /* commercial / argent */
  --paid-text: #047857;
  --paid-bg:   rgba(5, 150, 105, 0.12);
  --paid-bd:   #10b981;
  --free:      #d97706;  /* gratuit / apprentissage */
  --free-text: #b45309;
  --free-bg:   rgba(217, 119, 6, 0.13);
  --free-bd:   #f59e0b;
  --neutral:   #475569;
  --neutral-bg: rgba(100, 116, 139, 0.13);
  --danger:    #dc2626;
  --danger-bg: #fef2f2;
  --danger-bd: #fecaca;
  --danger-text: #b91c1c;
  --amber:     #c2410c;  /* CPC / money pockets (assez foncé pour contraste sur blanc) */
  /* échelle d'espacement 4/8 */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .05);
  --mono: "Fira Code", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: "Fira Sans", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

* { box-sizing: border-box; }
/* l'attribut [hidden] doit toujours gagner, même sur les éléments qui ont un display custom
   (ex: .warn { display:flex }) — sinon le toggle JS via .hidden est ignoré. */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2 { margin: 0; font-weight: 600; line-height: 1.25; }
small { font-size: .8em; color: var(--text-2); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ───────────── Layout ───────────── */
.app {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  min-height: 100dvh;
}

/* ───────────── Sidebar / formulaire ───────────── */
.panel {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: var(--s5);
  display: flex;
  flex-direction: column;
  gap: var(--s5);
  position: sticky;
  top: 0;
  height: 100dvh;       /* rail pleine hauteur : le blanc va jusqu'en bas, reste visible au scroll */
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: var(--s3); }
.brand__mark {
  display: grid; place-items: center;
  width: 38px; height: 38px; flex: none;
  color: var(--blue);
  background: rgba(37, 99, 235, .1);
  border: 1px solid rgba(37, 99, 235, .2);
  border-radius: var(--radius-sm);
}
.brand__title { font-size: 18px; font-family: var(--mono); font-weight: 600; letter-spacing: -.3px; color: var(--text); }
.brand__sub { margin: 2px 0 0; font-size: 12.5px; color: var(--text-2); }

.form { display: flex; flex-direction: column; gap: var(--s4); }
.field { display: flex; flex-direction: column; gap: var(--s2); }
.field label { font-size: 13px; font-weight: 500; color: var(--text-2); }
.req { color: var(--danger); }
.hint { margin: 0; font-size: 12px; line-height: 1.45; color: var(--text-3); }
.hint strong { color: var(--text-2); font-weight: 600; }

textarea, input, select {
  font-family: var(--sans);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  width: 100%;
  transition: border-color .15s ease, box-shadow .15s ease;
}
textarea { resize: vertical; min-height: 120px; font-family: var(--mono); line-height: 1.5; }
input[type="number"] { font-family: var(--mono); }
textarea::placeholder, input::placeholder { color: var(--text-3); }
textarea:focus, input:focus, select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .18);
}
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
  cursor: pointer;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }

/* bloc niche + bouton générer */
.field--niche { padding-bottom: var(--s4); border-bottom: 1px solid var(--border); }
.niche-row { display: flex; gap: var(--s2); align-items: stretch; }
.niche-row input { flex: 1; min-width: 0; }
.btn--ghost {
  flex: none; min-height: 0; padding: 0 16px; font-size: 13px; white-space: nowrap;
  color: var(--blue); background: var(--surface-2); border: 1px solid var(--border-strong);
}
.btn--ghost:hover { background: #e8eef6; }
.btn--ghost:focus-visible { box-shadow: 0 0 0 3px rgba(37, 99, 235, .25); }
.btn--ghost .btn__spinner { border-color: rgba(37, 99, 235, .3); border-top-color: var(--blue); }
.hint--error { color: var(--danger-text); }

.adv { border-top: 1px solid var(--border); padding-top: var(--s3); }
.adv summary {
  cursor: pointer; font-size: 13px; color: var(--text-2); font-weight: 500;
  list-style: none; user-select: none;
}
.adv summary::-webkit-details-marker { display: none; }
.adv summary::before { content: "+ "; color: var(--text-3); }
.adv[open] summary::before { content: "− "; }
.adv .field { margin-top: var(--s3); }

.btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--sans); font-size: 15px; font-weight: 600;
  color: #ffffff;
  background: var(--blue);
  border: 0; border-radius: var(--radius-sm);
  padding: 12px 18px; min-height: 46px;
  cursor: pointer;
  transition: background .15s ease, transform .05s ease, opacity .15s ease;
}
.btn:hover { background: var(--blue-dim); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(37, 99, 235, .35); }
.btn[disabled] { opacity: .6; cursor: progress; }
.btn__spinner { display: none; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.45); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
.btn.is-loading .btn__spinner { display: inline-block; }
.form__note { margin: 0; font-size: 11.5px; color: var(--text-3); text-align: center; }

/* mode lecture seule (public) : on masque tout ce qui écrit */
.readonly-badge { display: none; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 11px; }
.readonly-badge svg { color: var(--text-3); flex: none; }
body.read-only .readonly-badge { display: flex; }
body.read-only .form { display: none; }
body.read-only #btn-synth { display: none; }

/* ───────────── Résultats ───────────── */
.results { padding: var(--s5) var(--s6); min-width: 0; }

.state { text-align: center; max-width: 460px; margin: 12vh auto; color: var(--text-2); }
.state__icon { color: var(--text-3); margin-bottom: var(--s3); display: flex; justify-content: center; }
.state h2 { font-size: 19px; color: var(--text); margin-bottom: var(--s2); }
.state p { margin: 0; font-size: 14.5px; }
.state--error .state__icon { color: var(--danger); }
.state--error h2 { color: var(--danger); }
#error-msg { font-family: var(--mono); font-size: 13px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; color: var(--text); white-space: pre-wrap; text-align: left; box-shadow: var(--shadow); }

.summary {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s4);
  flex-wrap: wrap;
  padding-bottom: var(--s4); margin-bottom: var(--s5);
  border-bottom: 1px solid var(--border);
}
.summary__title { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.summary__counts { font-size: 14px; color: var(--text-2); }
.summary__sep { color: var(--text-3); }
.summary__vol { display: flex; align-items: baseline; gap: 6px; }
.cache-tag { font-size: 12px; color: var(--paid-text); background: var(--paid-bg); padding: 2px 8px; border-radius: 999px; }
.btn--mini { padding: 5px 10px; font-size: 12px; gap: 5px; min-height: 0; }

/* historique */
.history { max-width: 640px; margin: 0 auto var(--s7); padding: 0 var(--s4); }
.history__title { display: flex; align-items: center; gap: var(--s2); font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-2); margin-bottom: var(--s3); }
.history__title svg { color: var(--text-3); }
.history__list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s2); }
.history__item { display: flex; align-items: center; gap: var(--s3); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 12px; transition: border-color .12s ease, background .12s ease; }
.history__item:hover { border-color: var(--border-strong); background: var(--surface-2); }
.history__btn { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: var(--s3); background: none; border: 0; padding: 0; cursor: pointer; text-align: left; font-family: var(--sans); }
.history__name { font-weight: 500; color: var(--text); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 320px; }
.hist-note { flex: none; font-size: 10.5px; font-weight: 700; padding: 1px 7px; border-radius: 999px; text-transform: uppercase; letter-spacing: .3px; white-space: nowrap; }
.hist-note b { font-family: var(--mono); }
.history__meta { font-size: 12px; color: var(--text-3); font-family: var(--mono); white-space: nowrap; margin-left: auto; }
.history__meta b { color: var(--text-2); font-weight: 500; }
.history__del { flex: none; width: 26px; height: 26px; display: grid; place-items: center; border: 0; background: none; color: var(--text-3); border-radius: 6px; cursor: pointer; font-size: 17px; line-height: 1; }
.history__del:hover { background: var(--danger-bg); color: var(--danger); }
.history__empty { font-size: 13px; color: var(--text-3); }

/* bouton historique permanent (sidebar) */
.side-history { width: 100%; justify-content: center; gap: 7px; }

/* toolbar actions (lien + synthèse) */
.actions { display: flex; gap: var(--s2); flex-wrap: wrap; margin-bottom: var(--s5); }

/* section synthèse IA */
.synth { background: #f5f7ff; border: 1px solid #dfe3f5; border-radius: var(--radius); padding: var(--s4) var(--s5); margin-bottom: var(--s6); box-shadow: var(--shadow); }
.synth__top { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; margin-bottom: var(--s3); }
.synth__verdict { font-weight: 700; font-size: 13px; padding: 4px 12px; border-radius: 999px; text-transform: uppercase; letter-spacing: .4px; }
.v-build { background: var(--paid-bg); color: var(--paid-text); }
.v-test { background: var(--free-bg); color: var(--free-text); }
.v-skip { background: var(--danger-bg); color: var(--danger-text); }
.synth__score { font-family: var(--mono); font-size: 14px; color: var(--text-3); }
.synth__score b { font-size: 22px; color: var(--text); }
.synth__label { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-3); margin-right: auto; }
.synth__potentiel { margin: 0 0 var(--s3); font-size: 14.5px; line-height: 1.55; color: var(--text); }
.synth__points { margin: 0 0 var(--s3); padding-left: 18px; display: flex; flex-direction: column; gap: 5px; }
.synth__points li { font-size: 13.5px; color: var(--text-2); }
.synth__avis { margin: 0; font-size: 14px; font-weight: 500; color: var(--text); border-left: 3px solid var(--blue); padding-left: 12px; }
.synth__foot { margin: var(--s3) 0 0; font-size: 11.5px; color: var(--text-3); font-style: italic; }
.summary__vol-num { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 26px; font-weight: 600; color: var(--text); }
.summary__vol-unit { font-size: 13px; color: var(--text-2); }

.block { margin-bottom: var(--s6); }
.block__title { display: flex; align-items: center; gap: var(--s2); font-size: 14px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-2); margin-bottom: var(--s3); }
.block__title svg { color: var(--text-3); flex: none; }
.block__count { font-family: var(--mono); text-transform: none; letter-spacing: 0; color: var(--text-3); font-weight: 400; }

/* bandeau warning */
.warn {
  display: flex; align-items: flex-start; gap: var(--s2);
  background: var(--danger-bg); border: 1px solid var(--danger-bd);
  color: var(--danger-text); border-radius: var(--radius-sm);
  padding: 12px 14px; margin-bottom: var(--s4); font-size: 13.5px;
}
.warn svg { color: var(--danger); flex: none; margin-top: 1px; }
.warn strong { color: #7f1d1d; }

/* bandeau positif « marché commercial actif » */
.note { display: flex; align-items: flex-start; gap: var(--s2); border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: var(--s4); font-size: 13.5px; }
.note--ok { background: var(--paid-bg); border: 1px solid rgba(5, 150, 105, .3); color: var(--paid-text); }
.note--ok svg { color: var(--paid); flex: none; margin-top: 1px; }
.note--ok strong { color: #065f46; }

/* cartes intention */
.cards3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s4); }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-left-width: 3px; border-radius: var(--radius); padding: var(--s4);
  box-shadow: var(--shadow);
}
.card--free { border-left-color: var(--free-bd); }
.card--paid { border-left-color: var(--paid-bd); }
.card--comp { border-left-color: var(--blue); }
.dot--comp { background: var(--blue); }
.card__head { display: flex; align-items: center; gap: var(--s2); margin-bottom: var(--s3); }
.card__name { font-size: 13px; font-weight: 600; color: var(--text-2); }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.dot--free { background: var(--free-bd); }
.dot--paid { background: var(--paid-bd); }
.card__vol { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 24px; font-weight: 600; color: var(--text); display: flex; align-items: baseline; gap: 6px; }
.card__vol small { font-weight: 400; }
.card__pct { font-size: 13px; padding: 2px 8px; border-radius: 999px; background: var(--neutral-bg); color: var(--text-2); margin-left: auto; align-self: center; }
.card--free .card__pct { background: var(--free-bg); color: var(--free-text); }
.card--paid .card__pct { background: var(--paid-bg); color: var(--paid-text); }
.card__meta { margin-top: var(--s2); font-size: 12.5px; color: var(--text-3); }
.card__meta .mono { color: var(--text-2); }

/* tables data-dense */
.tablewrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th, table.data td { padding: 9px 14px; text-align: left; white-space: nowrap; }
table.data thead th {
  position: sticky; top: 0;
  background: var(--surface-2);
  font-size: 11px; text-transform: uppercase; letter-spacing: .5px; font-weight: 600; color: var(--text-3);
  border-bottom: 1px solid var(--border);
}
table.data th.num, table.data td.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
table.data tbody tr { border-top: 1px solid var(--border); transition: background .12s ease; }
table.data tbody tr:first-child { border-top: 0; }
table.data tbody tr:hover { background: var(--surface-2); }
td .kw { color: var(--text); }
td .cluster-name { color: var(--text); font-weight: 500; }
td .n-badge { font-family: var(--mono); color: var(--text-3); }

/* badges intention */
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: .4px; }
.badge--paid { background: var(--paid-bg); color: var(--paid-text); }
.badge--free { background: var(--free-bg); color: var(--free-text); }
.badge--neutre { background: var(--neutral-bg); color: var(--neutral); }
.comp { font-family: var(--mono); font-size: 12px; color: var(--text-2); }

/* CPC */
.cpc { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.cpc--high { color: var(--amber); font-weight: 500; }
.cpc--floor { color: var(--text-3); }

/* saison */
.season { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-family: var(--mono); color: var(--free-text); background: rgba(217, 119, 6, .1); padding: 1px 7px; border-radius: 999px; }
.season--none { color: var(--text-3); }

/* poches commerciales */
.money { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--s3); }
.money__item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--s3) var(--s4); border-top: 2px solid var(--amber); box-shadow: var(--shadow); }
.money__kw { font-weight: 500; color: var(--text); font-size: 14px; margin-bottom: 4px; word-break: break-word; }
.money__meta { display: flex; align-items: center; gap: var(--s3); font-size: 12.5px; color: var(--text-2); flex-wrap: wrap; }
.money__cpc { font-family: var(--mono); color: var(--amber); font-weight: 600; }
.money__empty { color: var(--text-3); font-size: 13.5px; }

.tag { display: inline-block; font-size: 12px; padding: 3px 9px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2); }
.tag--mono { font-family: var(--mono); font-weight: 500; color: var(--text); }

/* spinner */
.spinner { width: 18px; height: 18px; border: 2px solid var(--border-strong); border-top-color: var(--blue); border-radius: 50%; animation: spin .7s linear infinite; }
.spinner--lg { width: 34px; height: 34px; border-width: 3px; margin: 0 auto var(--s4); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ───────────── Responsive ───────────── */
@media (max-width: 880px) {
  .app { grid-template-columns: 1fr; }
  .panel { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .results { padding: var(--s4); }
  .cards3 { grid-template-columns: 1fr; }
  .state { margin: 8vh auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
  .spinner, .btn__spinner { animation: spin 1s linear infinite; }
}
