/* ── Reset & Root ──────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #FDFCFC;
  --bg-section:  #F5F4F4;
  --white:       #FFFFFF;
  --navy:        #1A1727;
  --navy-60:     rgba(26,23,39,.6);
  --teal:        #18BBA3;
  --teal-10:     rgba(24,187,163,.10);
  --teal-20:     rgba(24,187,163,.20);
  --amber:       #F6AF21;
  --amber-10:    rgba(246,175,33,.12);
  --purple:      #5F54BB;
  --purple-10:   rgba(95,84,187,.12);
  --red:         #EF4444;
  --red-10:      rgba(239,68,68,.10);
  --red-20:      rgba(239,68,68,.18);
  --text:        #3C3940;
  --muted:       #928E99;
  --border:      #E8E6EE;
  --border-dark: #D0CDD8;
  --shadow-sm:   0 1px 8px rgba(26,23,39,.06);
  --shadow:      0 4px 24px rgba(26,23,39,.09);
  --shadow-lg:   0 12px 48px rgba(26,23,39,.13);
  --r:           14px;
  --r-sm:        10px;
  --r-pill:      100px;
}

html { height: 100%; -webkit-text-size-adjust: 100%; }

body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ── App container ─────────────────────────────── */
.app {
  max-width: 520px;
  margin: 0 auto;
  padding: 0 20px 96px;
}

/* ── Desktop 2-column layout ───────────────────── */
.app-body {
  display: flex;
  flex-direction: column;
}
.app-col-left  {}
.app-col-right {}

/* ── Topbar ────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 0 6px;
  min-height: 64px;
}
.topbar-logo {
  width: 34px; height: 34px;
  border-radius: 9px;
  overflow: hidden;
  flex-shrink: 0;
  object-fit: cover;
}
.topbar-info { display: flex; flex-direction: column; }
.topbar-text {
  font-size: 11px; font-weight: 800;
  letter-spacing: .12em; text-transform: uppercase;
  color: var(--navy);
}
.topbar-sub {
  font-size: 10px; font-weight: 500;
  color: var(--muted); letter-spacing: .04em;
}
.topbar-spacer { flex: 1; }
.topbar-back {
  font-size: 12px; font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  background: var(--bg-section);
  border-radius: var(--r-pill);
  padding: 6px 14px;
  transition: background .15s, color .15s;
  -webkit-tap-highlight-color: transparent;
}
.topbar-back:hover { background: var(--border-dark); color: var(--navy); }

/* ── Hero ──────────────────────────────────────── */
.hero { padding: 24px 0 20px; }
.hero-eyebrow {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--amber-10);
  color: var(--amber);
  font-size: 10px; font-weight: 800;
  letter-spacing: .12em; text-transform: uppercase;
  padding: 4px 12px; border-radius: var(--r-pill);
  margin-bottom: 12px;
}
.hero-title {
  font-size: 32px; font-weight: 900;
  color: var(--navy); line-height: 1.15;
  margin-bottom: 8px;
}
.hero-title .accent { color: var(--teal); }
.hero-desc {
  font-size: 14px; font-weight: 500;
  color: var(--muted); line-height: 1.6;
}

/* ── Card ──────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

/* ── Form ──────────────────────────────────────── */
.field {
  display: flex; flex-direction: column; gap: 6px;
  margin-bottom: 14px;
}
.field:last-of-type { margin-bottom: 0; }

.field-row {
  display: flex; gap: 12px;
  margin-bottom: 14px;
}
.field-row .field { flex: 1; margin-bottom: 0; }

.label {
  font-size: 12px; font-weight: 700;
  color: var(--navy); letter-spacing: .01em;
}
.label-opt { font-weight: 500; color: var(--muted); }
.label-req { color: var(--teal); }

.input {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg-section);
  border: 1.5px solid transparent;
  border-radius: var(--r-sm);
  font-family: inherit;
  font-size: 14px; font-weight: 500;
  color: var(--navy);
  outline: none;
  transition: border-color .15s, background .15s;
  -webkit-appearance: none;
  appearance: none;
}
.input:focus { border-color: var(--teal); background: var(--white); }
.input::placeholder { color: var(--muted); font-weight: 400; }

.select {
  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='%23928E99' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
  cursor: pointer;
}

.error-msg {
  font-size: 13px; font-weight: 500;
  color: var(--red);
  min-height: 18px;
  margin-top: 8px;
}

/* ── Buttons ───────────────────────────────────── */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 14px 24px;
  border: none; border-radius: var(--r-pill);
  font-family: inherit; font-size: 15px; font-weight: 700;
  cursor: pointer; text-decoration: none;
  transition: opacity .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
  margin-top: 8px;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: default; }

.btn-teal { background: var(--teal); color: #fff; }
.btn-teal:hover:not(:disabled) { opacity: .88; }

.btn-ghost {
  background: transparent; color: var(--navy);
  border: 1.5px solid var(--border-dark);
}
.btn-ghost:hover:not(:disabled) { border-color: var(--navy); }

.btn-star { font-size: 13px; }

/* Small action buttons */
.btn-action {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border: none; border-radius: var(--r-pill);
  font-family: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
  background: var(--navy); color: #fff;
}
.btn-action:hover { opacity: .85; }
.btn-action:active { transform: scale(.97); }

.btn-action.btn-outline {
  background: transparent; color: var(--navy);
  border: 1.5px solid var(--border-dark);
}
.btn-action.btn-outline:hover { border-color: var(--navy); }

.btn-text-muted {
  font-size: 12px; font-weight: 600; color: var(--muted);
  background: none; border: none; cursor: pointer;
  padding: 2px 0;
  transition: color .15s;
}
.btn-text-muted:hover { color: var(--red); }

/* ── Section ───────────────────────────────────── */
.section { margin-bottom: 16px; }

/* ── Panel ─────────────────────────────────────── */
.panel {
  background: var(--white);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  margin-bottom: 12px;
}

.panel-header {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 14px;
}
.panel-title {
  font-size: 13px; font-weight: 700;
  color: var(--navy); letter-spacing: .02em;
  flex: 1;
}

/* ── Badges ────────────────────────────────────── */
.badge {
  font-size: 10px; font-weight: 800;
  letter-spacing: .1em; text-transform: uppercase;
  padding: 3px 8px; border-radius: var(--r-pill);
  flex-shrink: 0;
}
.badge-ia     { background: var(--purple); color: #fff; }
.badge-custom { background: var(--navy); color: #fff; }

/* ── Custom tag input ──────────────────────────── */
.custom-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}
.custom-tag-input { flex: 1; min-width: 0; }
.btn-add {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px;
  border-radius: var(--r-pill);
  font-family: inherit; font-size: 12px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
  border: 1.5px solid transparent;
  transition: all .12s; flex-shrink: 0; line-height: 1;
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.btn-add:active { transform: scale(.96); }
.btn-add-include { background: var(--teal-10); color: var(--teal); border-color: var(--teal); }
.btn-add-include:hover { background: var(--teal-20); }
.btn-add-exclude { background: var(--red-10); color: var(--red); border-color: rgba(239,68,68,.35); }
.btn-add-exclude:hover { background: var(--red-20); }

/* ── Loading ───────────────────────────────────── */
.loading-card {
  background: var(--white);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
  padding: 24px 20px;
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 12px;
}
.spinner {
  width: 22px; height: 22px;
  border: 2.5px solid var(--teal-20);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-title {
  font-size: 14px; font-weight: 600; color: var(--navy);
  margin-bottom: 2px;
}
.loading-sub { font-size: 12px; color: var(--muted); }

/* ── Tag hint ──────────────────────────────────── */
.tag-hint {
  font-size: 11px; font-weight: 500; color: var(--muted);
  margin-bottom: 14px;
}
.hint-include { color: var(--teal); font-weight: 600; }
.hint-exclude { color: var(--red); font-weight: 600; }

/* ── Tag Groups ────────────────────────────────── */
.tag-group { margin-bottom: 16px; }
.tag-group:last-child { margin-bottom: 0; }
.tag-group-label {
  font-size: 11px; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}
.tag-list {
  display: flex; flex-wrap: wrap; gap: 7px;
  min-height: 34px;
}

/* ── Tags ──────────────────────────────────────── */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px;
  border-radius: var(--r-pill);
  font-family: inherit; font-size: 12px; font-weight: 600;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: all .12s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  line-height: 1;
}
.tag:active { transform: scale(.96); }

/* Neutral */
.tag-neutral {
  background: var(--bg-section);
  color: var(--muted);
  border-color: var(--border);
}
.tag-neutral:hover {
  border-color: var(--border-dark);
  color: var(--text);
}

/* Include */
.tag-include {
  background: var(--teal-10);
  color: var(--teal);
  border-color: var(--teal);
}
.tag-include:hover { background: var(--teal-20); }

/* Exclude */
.tag-exclude {
  background: var(--red-10);
  color: var(--red);
  border-color: rgba(239,68,68,.35);
}
.tag-exclude:hover { background: var(--red-20); }

/* State icons */
.tag-icon {
  font-size: 11px; font-weight: 700;
  display: none; line-height: 1;
}
.tag-include .tag-icon,
.tag-exclude .tag-icon { display: inline; }

/* ── Output Section ────────────────────────────── */
.output-card {
  background: var(--white);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 12px;
}
.output-top {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.output-platform {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 700; color: var(--navy);
}
.platform-icon {
  width: 26px; height: 26px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 900;
  color: #fff;
  flex-shrink: 0;
}
.platform-li { background: #0A66C2; }
.platform-g  { background: #4285F4; }

.char-badge {
  font-size: 11px; font-weight: 700;
  padding: 3px 10px; border-radius: var(--r-pill);
  background: var(--bg-section); color: var(--muted);
  transition: background .2s, color .2s;
  flex-shrink: 0;
}
.char-badge.ok   { background: var(--teal-10);  color: var(--teal);  }
.char-badge.warn { background: var(--amber-10); color: var(--amber); }
.char-badge.over { background: var(--red-10);   color: var(--red);   }

.output-warning {
  font-size: 12px; font-weight: 600;
  color: var(--red);
  margin-bottom: 10px;
  margin-top: -6px;
  padding: 8px 12px;
  background: var(--red-10);
  border-radius: var(--r-sm);
}

.output-string {
  font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Mono', 'Courier New', monospace;
  font-size: 12px; line-height: 1.75;
  color: var(--text);
  background: var(--bg-section);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  word-break: break-all;
  white-space: pre-wrap;
  min-height: 52px;
  margin-bottom: 12px;
  border: 1.5px solid var(--border);
}

.output-actions {
  display: flex; gap: 8px; flex-wrap: wrap;
}

/* ── History ───────────────────────────────────── */
.history-empty {
  font-size: 13px; color: var(--muted);
  padding: 8px 0;
}

.history-list { display: flex; flex-direction: column; gap: 8px; }

.history-item {
  background: var(--white);
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  padding: 12px 16px;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
  display: flex; align-items: center; gap: 12px;
  -webkit-tap-highlight-color: transparent;
}
.history-item:hover {
  border-color: var(--teal);
  box-shadow: 0 2px 12px rgba(24,187,163,.12);
}
.history-info { flex: 1; min-width: 0; }
.history-title {
  font-size: 14px; font-weight: 700; color: var(--navy);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 2px;
}
.history-meta {
  font-size: 11px; color: var(--muted); font-weight: 500;
}
.history-arrow { color: var(--border-dark); font-size: 18px; }

/* ── Toast ─────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 28px; left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--navy); color: #fff;
  font-size: 13px; font-weight: 600;
  padding: 11px 20px; border-radius: var(--r-pill);
  box-shadow: var(--shadow-lg);
  transition: transform .28s cubic-bezier(.34,1.56,.64,1), opacity .28s;
  opacity: 0; pointer-events: none;
  z-index: 9999; white-space: nowrap;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ── Animations ─────────────────────────────────── */
@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}
.panel-appear {
  animation: slideUp 0.42s cubic-bezier(0.16, 1, 0.3, 1) var(--delay, 0ms) both;
}

/* ── Contrat toggle ──────────────────────────────── */
.contrat-toggle {
  display: flex;
  background: var(--bg-section);
  border-radius: var(--r-pill);
  padding: 3px;
  gap: 2px;
}
.contrat-btn {
  flex: 1; padding: 7px 14px;
  border: none; border-radius: var(--r-pill);
  font-family: inherit; font-size: 13px; font-weight: 600;
  color: var(--muted); background: transparent;
  cursor: pointer; transition: all .15s;
  -webkit-tap-highlight-color: transparent;
}
.contrat-btn.active {
  background: var(--white);
  color: var(--navy);
  box-shadow: 0 1px 6px rgba(26,23,39,.1);
}

/* ── Load more button ───────────────────────────── */
.btn-load-more {
  display: flex; align-items: center; justify-content: center; gap: 5px;
  width: 100%; padding: 7px 16px; margin-top: 10px;
  font-family: inherit; font-size: 12px; font-weight: 600;
  color: var(--muted); background: transparent;
  border: 1.5px dashed var(--border-dark);
  border-radius: var(--r-pill);
  cursor: pointer; transition: color .15s, border-color .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-load-more:hover:not(:disabled) { color: var(--navy); border-color: var(--navy); }
.btn-load-more:disabled { opacity: .45; cursor: default; }

/* ── Reset button ────────────────────────────────── */
.btn-reset {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; padding: 10px 20px; margin-top: 10px;
  font-family: inherit; font-size: 13px; font-weight: 600;
  color: var(--muted); background: transparent;
  border: 1.5px dashed var(--border-dark);
  border-radius: var(--r-pill);
  cursor: pointer; transition: color .15s, border-color .15s;
}
.btn-reset:hover { color: var(--navy); border-color: var(--navy); }

/* ── Responsive ─────────────────────────────────── */
@media (max-width: 480px) {
  .field-row { flex-direction: column; gap: 14px; }
  .hero-title { font-size: 28px; }
  .output-actions { flex-direction: column; }
  .btn-action { width: 100%; justify-content: center; }
}

@media (min-width: 800px) {
  .app { max-width: 1060px; padding: 0 40px 96px; }

  /* État initial : form centré */
  .app-body {
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    gap: 36px;
  }
  .app-col-left {
    width: 420px;
    flex-shrink: 0;
    position: sticky;
    top: 24px;
    transition: width 0.5s cubic-bezier(0.16, 1, 0.3, 1);
  }
  .app-col-right {
    display: none;
    flex: 1;
    min-width: 0;
  }

  /* Après résultats : 2 colonnes */
  .app-body.has-results { justify-content: flex-start; }
  .app-body.has-results .app-col-left { width: 340px; }
  .app-body.has-results .app-col-right {
    display: flex;
    flex-direction: column;
    animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1) 0.1s both;
  }

  .hero { padding-top: 32px; }
  .hero-title { font-size: 36px; }
  #historySection { margin-top: 8px; }
}
