/* ============================================================
   Calculatrice Honoraires de Location - Courtès Groupe
   ============================================================ */

:root {
  /* Charte Courtès Groupe */
  --orange: #F16423;
  --orange-600: #d8521a;
  --blue-dark: #203368;
  --blue-light: #58B2E5;

  /* Thème clair (par défaut) */
  --bg: #F8F9FA;
  --bg-grad: radial-gradient(1200px 600px at 85% -10%, rgba(88,178,229,.18), transparent 60%),
             radial-gradient(900px 500px at -10% 110%, rgba(241,100,35,.10), transparent 55%);
  --surface: #ffffff;
  --surface-2: #f3f5f9;
  --border: #e6e9f0;
  --text: #203368;
  --text-soft: #5b6886;
  --muted: #97a0b5;
  --shadow: 0 10px 30px -12px rgba(32,51,104,.20);
  --shadow-sm: 0 2px 8px -2px rgba(32,51,104,.14);
  --accent: var(--orange);
  --accent-soft: rgba(241,100,35,.10);
  --ring: rgba(88,178,229,.45);
}

[data-theme="dark"] {
  --bg: #0e1426;
  --bg-grad: radial-gradient(1200px 600px at 85% -10%, rgba(88,178,229,.16), transparent 60%),
             radial-gradient(900px 500px at -10% 110%, rgba(241,100,35,.14), transparent 55%);
  --surface: #161e36;
  --surface-2: #1d2742;
  --border: #2a3556;
  --text: #eef2fb;
  --text-soft: #aab6d6;
  --muted: #6f7da3;
  --shadow: 0 18px 40px -16px rgba(0,0,0,.55);
  --shadow-sm: 0 2px 10px -2px rgba(0,0,0,.45);
  --accent: var(--orange);
  --accent-soft: rgba(241,100,35,.16);
  --ring: rgba(88,178,229,.55);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background-color .35s ease, color .35s ease;
}

.app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 22px clamp(14px, 4vw, 32px) 40px;
}

/* ===== Header ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand__logo {
  width: 46px; height: 46px;
  object-fit: contain;
  border-radius: 12px;
  background: var(--surface);
  padding: 6px;
  box-shadow: var(--shadow-sm);
}
.brand__text { display: flex; flex-direction: column; line-height: 1.15; }
.brand__title { font-weight: 750; font-size: 1.18rem; letter-spacing: -.01em; }
.brand__sub { font-size: .82rem; color: var(--text-soft); }

.theme-toggle {
  display: grid; place-items: center;
  width: 44px; height: 44px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform .15s ease, border-color .2s ease, background-color .3s ease;
}
.theme-toggle:hover { transform: translateY(-1px); border-color: var(--blue-light); }
/* On affiche l'icône de la cible : lune en mode clair, soleil en mode sombre */
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }

/* ===== Mode switch (type d'honoraires) ===== */
.mode-switch {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  border-radius: 14px;
  padding: 4px;
  margin-bottom: 22px;
}
.mode-switch__btn {
  position: relative; z-index: 1;
  min-width: 0;
  border: 0; background: transparent;
  padding: 12px 10px;
  font-size: .92rem; font-weight: 600;
  color: var(--text-soft);
  cursor: pointer;
  border-radius: 10px;
  transition: color .25s ease;
}
.mode-switch__btn.is-active { color: #fff; }
.mode-switch__pill {
  position: absolute;
  top: 4px; left: 4px;
  width: calc(50% - 4px);
  height: calc(100% - 8px);
  background: linear-gradient(135deg, var(--orange), var(--orange-600));
  border-radius: 10px;
  box-shadow: 0 6px 16px -6px rgba(241,100,35,.6);
  transition: transform .3s cubic-bezier(.4,0,.2,1);
}
.mode-switch.location .mode-switch__pill { transform: translateX(100%); }

/* ===== Layout ===== */
.layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
  align-items: start;
}
/* Autorise les colonnes à rétrécir sous la largeur de leur contenu (anti-débordement) */
.layout > * { min-width: 0; }
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
}

/* ===== Card ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  transition: background-color .3s ease, border-color .3s ease;
}
.panel { padding: 20px; }

/* ===== Fields ===== */
.input-block.hidden { display: none; }
.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.field label {
  display: block;
  font-size: .82rem; font-weight: 600;
  color: var(--text-soft);
  margin-bottom: 7px;
  letter-spacing: .01em;
}
.muted { color: var(--muted); font-weight: 500; }

.input-euro {
  display: flex; align-items: center;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 13px;
  padding: 0 14px;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.input-euro:focus-within {
  border-color: var(--blue-light);
  box-shadow: 0 0 0 4px var(--ring);
}
.input-euro input {
  flex: 1; min-width: 0;
  border: 0; background: transparent;
  color: var(--text);
  font-family: inherit;
  font-weight: 700;
  outline: none;
  padding: 14px 0;
}
.input-euro__suffix { color: var(--text-soft); font-weight: 600; padding-left: 8px; }

.field--hero .input-euro { padding: 0 18px; }
.field--hero .input-euro input { font-size: 1.9rem; padding: 16px 0; letter-spacing: -.02em; }
.field--hero label { font-size: .9rem; }

.input-euro--sm input { font-size: 1.05rem; padding: 11px 0; }

/* ===== Liste déroulante personnalisée (type de logement) ===== */
.dropdown { position: relative; }
.dropdown__native { display: none; }

.dropdown__btn {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 13px;
  padding: 12px 14px;
  color: var(--text);
  font-family: inherit; font-weight: 700; font-size: 1.05rem;
  cursor: pointer;
  text-align: left;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.dropdown__btn:hover { border-color: var(--blue-light); }
.dropdown.is-open .dropdown__btn,
.dropdown__btn:focus-visible {
  border-color: var(--blue-light);
  box-shadow: 0 0 0 4px var(--ring);
  outline: none;
}
.dropdown__value { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dropdown__chevron { color: var(--text-soft); flex-shrink: 0; transition: transform .2s ease; }
.dropdown.is-open .dropdown__chevron { transform: rotate(180deg); }

.dropdown__list {
  position: absolute;
  top: calc(100% + 6px); left: 0; right: 0;
  z-index: 20;
  margin: 0; padding: 6px;
  list-style: none;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 13px;
  box-shadow: var(--shadow);
  opacity: 0; transform: translateY(-6px);
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.dropdown.is-open .dropdown__list {
  opacity: 1; transform: none; pointer-events: auto;
}
.dropdown__opt {
  padding: 11px 12px;
  border-radius: 9px;
  font-weight: 600; font-size: .98rem;
  color: var(--text);
  cursor: pointer;
  transition: background-color .15s ease, color .15s ease;
}
.dropdown__opt:hover, .dropdown__opt.is-active {
  background: var(--surface-2);
}
.dropdown__opt.is-selected {
  color: var(--accent);
  background: var(--accent-soft);
}

/* ===== Paramètres ===== */
.params {
  margin-top: 6px;
  border-top: 1px dashed var(--border);
  padding-top: 14px;
}
.params > summary {
  display: flex; align-items: baseline; gap: 10px;
  cursor: pointer;
  list-style: none;
  padding: 6px 2px;
  border-radius: 8px;
  user-select: none;
}
.params > summary::-webkit-details-marker { display: none; }
.params__title { font-weight: 650; font-size: .92rem; }
.params__hint { font-size: .78rem; color: var(--muted); }
.params[open] > summary .params__hint { opacity: .6; }

.params__body { padding-top: 14px; animation: fade .25s ease; }

/* ===== Barème (lecture seule) ===== */
.bareme { width: 100%; border-collapse: collapse; font-size: .85rem; table-layout: fixed; }
.bareme th, .bareme td { padding: 9px 6px; text-align: left; }
.bareme thead th {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .03em;
  color: var(--muted); border-bottom: 1px solid var(--border); font-weight: 700;
}
.bareme tbody td { border-bottom: 1px solid var(--border); color: var(--text); word-break: break-word; }
.bareme tbody tr:last-child td { border-bottom: 0; }
.bareme tbody td:last-child { font-weight: 700; color: var(--accent); text-align: right; }
.bareme__note { margin: 12px 2px 0; font-size: .75rem; color: var(--muted); line-height: 1.4; }

/* ===== Résultats ===== */
.results { display: flex; flex-direction: column; gap: 16px; }
#resGestion, #resLocation { display: flex; flex-direction: column; gap: 16px; }
.hidden { display: none !important; }

.result-hero {
  padding: 26px 24px;
  background: linear-gradient(140deg, var(--blue-dark), #2c4488);
  border: 0;
  color: #fff;
  display: flex; flex-direction: column; gap: 4px;
  overflow: hidden; position: relative;
}
.result-hero::after {
  content: ""; position: absolute; right: -40px; top: -40px;
  width: 180px; height: 180px;
  background: radial-gradient(circle, rgba(241,100,35,.45), transparent 70%);
  pointer-events: none;
}
.result-hero__label { font-size: .85rem; opacity: .85; font-weight: 600; letter-spacing: .02em; }
.result-hero__value {
  font-size: clamp(2.1rem, 6vw, 2.9rem); font-weight: 800;
  letter-spacing: -.02em; line-height: 1.05;
}
.result-hero__pct {
  display: inline-block; margin-top: 6px;
  font-size: .86rem; font-weight: 600;
  color: #fff; background: rgba(255,255,255,.16);
  padding: 4px 11px; border-radius: 999px;
  width: fit-content;
}

.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.stat { padding: 16px 18px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.stat__label { font-size: .78rem; color: var(--text-soft); font-weight: 600; }
.stat__value { font-size: 1.25rem; font-weight: 750; letter-spacing: -.01em; }
.stat--accent { border-color: transparent; background: var(--accent-soft); }
.stat--accent .stat__value { color: var(--accent); }

/* ===== Détail bailleur / locataire ===== */
.breakdown { padding: 0; overflow: hidden; }
.breakdown > summary {
  padding: 15px 18px;
  cursor: pointer; list-style: none;
  font-weight: 650; font-size: .9rem;
  display: flex; align-items: center; gap: 8px;
  user-select: none;
}
.breakdown > summary::-webkit-details-marker { display: none; }
.breakdown > summary::before {
  content: "▸"; color: var(--accent); transition: transform .2s ease;
}
.breakdown[open] > summary::before { transform: rotate(90deg); }
.breakdown__table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.breakdown__table th, .breakdown__table td { padding: 9px 18px; text-align: left; }
.breakdown__table thead th {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.breakdown__table tbody td { border-bottom: 1px solid var(--border); color: var(--text-soft); }
.breakdown__table tbody td:first-child { color: var(--text); font-weight: 500; min-width: 0; }
.breakdown__table td:last-child { white-space: nowrap; }
.breakdown__table tfoot td {
  font-weight: 750; padding-top: 12px; padding-bottom: 14px;
  color: var(--text);
}
.ta-r { text-align: right !important; }

/* ===== Footer ===== */
.footer {
  margin-top: 30px; text-align: center;
  font-size: .78rem; color: var(--muted);
}

@keyframes fade { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* ===== Responsive / mobile ===== */
/* Anti-débordement horizontal : rien ne dépasse la largeur de l'écran */
html, body { max-width: 100%; overflow-x: hidden; }

@media (max-width: 560px) {
  .app { padding: 5px; }            /* marge de 5px tout autour */
  .topbar { margin-bottom: 14px; gap: 10px; }
  .brand__logo { width: 40px; height: 40px; }
  .brand__title { font-size: 1.05rem; }
  .mode-switch { margin-bottom: 12px; }
  .mode-switch__btn { padding: 10px 6px; font-size: .82rem; }
  .layout { gap: 12px; }
  .results { gap: 12px; }
  .panel { padding: 14px; }
  .result-hero { padding: 18px 16px; }
  .stat { padding: 13px 14px; }
  .field--hero .input-euro input { font-size: 1.55rem; }
  .breakdown > summary { padding: 13px 14px; }
  .breakdown__table { font-size: .76rem; }
  .breakdown__table th, .breakdown__table td { padding: 7px 5px; }
  .breakdown__table th:first-child, .breakdown__table td:first-child { padding-left: 14px; }
  .breakdown__table th:last-child, .breakdown__table td:last-child { padding-right: 14px; }
  .bareme { font-size: .8rem; }
}

@media (max-width: 380px) {
  .result-grid { grid-template-columns: 1fr; }   /* cartes empilées sur très petits écrans */
  .stat__value { font-size: 1.15rem; }
}
