/* =========================================================
   Fiche clinique — Aziz Malloul
   Identité visuelle : dossier médical calme et digne de confiance.
   Palette :
     --paper   : #F6F4EF  (fond papier)
     --ink     : #1C2B33  (texte principal, bleu-nuit encre)
     --teal    : #0E6B66  (accent principal, structure)
     --alert   : #A3271F  (termes cliniques — rouge gras)
     --med     : #17458C  (médicaments — bleu gras)
     --line    : #DCD5C6  (séparateurs)
   Typo : Arial (uniforme, display + lecture) — demande explicite du médecin
   ========================================================= */

:root {
  --paper: #f6f4ef;
  --paper-2: #efece3;
  --ink: #1c2b33;
  --ink-soft: #4b5a61;
  --teal: #0e6b66;
  --teal-dark: #0a4d49;
  --alert: #a3271f;
  --med: #17458c;
  --line: #dcd5c6;
  --white: #fffdf9;
  --radius: 10px;
  --shadow: 0 8px 30px rgba(28, 43, 51, 0.08);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .display {
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  letter-spacing: -0.01em;
  font-weight: 700;
}

/* ---------- Skip decoration reduction ---------- */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* =========================================================
   LOGIN PAGE
   ========================================================= */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 15% 20%, rgba(14, 107, 102, 0.10), transparent 45%),
    radial-gradient(circle at 85% 80%, rgba(163, 39, 31, 0.06), transparent 40%),
    var(--paper);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px 36px 32px;
  position: relative;
  overflow: hidden;
}

.login-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 5px;
  background: linear-gradient(90deg, var(--teal), var(--med) 55%, var(--alert));
}

.login-eyebrow {
  font-size: 12.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--teal-dark);
  font-weight: 600;
  margin-bottom: 6px;
}

.login-card h1 {
  font-size: 28px;
  margin: 0 0 4px;
}

.login-sub {
  color: var(--ink-soft);
  font-size: 14.5px;
  margin-bottom: 28px;
}

.form-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 6px;
}

.form-control {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 14px;
  font-size: 15px;
  background: var(--paper);
}

.form-control:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(14, 107, 102, 0.18);
  background: var(--white);
}

.btn-primary-clinical {
  background: var(--teal);
  border: none;
  color: var(--white);
  font-weight: 600;
  padding: 12px 18px;
  border-radius: 8px;
  width: 100%;
  transition: background 0.15s ease, transform 0.1s ease;
  letter-spacing: 0.01em;
}

.btn-primary-clinical:hover { background: var(--teal-dark); color: var(--white); }
.btn-primary-clinical:active { transform: translateY(1px); }
.btn-primary-clinical:focus-visible {
  outline: 3px solid rgba(14, 107, 102, 0.4);
  outline-offset: 2px;
}

.login-error {
  background: rgba(163, 39, 31, 0.08);
  border: 1px solid rgba(163, 39, 31, 0.25);
  color: var(--alert);
  font-size: 13.5px;
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 18px;
}

.login-hint {
  margin-top: 22px;
  font-size: 12px;
  color: var(--ink-soft);
  text-align: center;
}

/* =========================================================
   DASHBOARD / DOSSIER
   ========================================================= */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(246, 244, 239, 0.92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 34px; height: 34px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--teal), var(--teal-dark));
  display: flex; align-items: center; justify-content: center;
  color: var(--white);
  font-family: Arial, Helvetica, sans-serif;
  font-weight: 600;
  font-size: 15px;
  flex-shrink: 0;
}

.brand-text .name { font-weight: 700; font-size: 15px; line-height: 1.2; }
.brand-text .role { font-size: 12px; color: var(--ink-soft); }

.topbar-actions { display: flex; gap: 10px; }

.btn-outline-clinical {
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 600;
  padding: 9px 15px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: border-color .15s ease, color .15s ease;
}
.btn-outline-clinical:hover { border-color: var(--teal); color: var(--teal-dark); }

.btn-download {
  border: none;
  background: var(--med);
  color: var(--white);
  font-size: 13.5px;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background .15s ease, transform .1s ease;
}
.btn-download:hover { background: #103a70; color: var(--white); }
.btn-download:active { transform: translateY(1px); }

.page-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 40px 24px 100px;
}

/* Hero */
.hero {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 32px;
  margin-bottom: 44px;
  align-items: stretch;
}

@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; }
}

.hero-title-block .eyebrow {
  font-size: 12.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--teal-dark);
  font-weight: 700;
  margin-bottom: 10px;
}

.hero-title-block h1 {
  font-size: 38px;
  margin: 0 0 14px;
  line-height: 1.15;
}

.hero-title-block p {
  color: var(--ink-soft);
  font-size: 15.5px;
  max-width: 46ch;
}

.legend {
  display: flex;
  gap: 18px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-soft);
}

.legend-swatch {
  width: 12px; height: 12px;
  border-radius: 3px;
}

.identity-card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px 26px 22px;
  box-shadow: var(--shadow);
}

.identity-card h2 {
  font-size: 16px;
  margin: 0 0 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.id-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 14px;
}
.id-row:last-child { border-bottom: none; }
.id-row .k { color: var(--ink-soft); }
.id-row .v { font-weight: 600; text-align: right; }

/* Family panel */
.family-panel {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px 28px;
  margin-bottom: 44px;
  box-shadow: var(--shadow);
}

.family-panel h2 {
  font-size: 19px;
  margin: 0 0 18px;
}

.sibling-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.sibling-row:last-child { border-bottom: none; }

.sibling-num {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--paper-2);
  color: var(--ink);
  font-weight: 700;
  font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  border: 1px solid var(--line);
}

.sibling-row.is-patient .sibling-num {
  background: var(--teal);
  color: var(--white);
  border-color: var(--teal);
}

.sibling-row.has-history .sibling-num {
  background: rgba(163, 39, 31, 0.12);
  border-color: rgba(163, 39, 31, 0.35);
  color: var(--alert);
}

.sibling-info { flex: 1; }
.sibling-info .label { font-size: 14.5px; font-weight: 600; }
.sibling-info .detail { font-size: 13px; color: var(--ink-soft); margin-top: 1px; }

.tag {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  letter-spacing: 0.02em;
}
.tag-patient { background: rgba(14, 107, 102, 0.12); color: var(--teal-dark); }
.tag-history { background: rgba(163, 39, 31, 0.1); color: var(--alert); }

.contact-strip {
  margin-top: 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--paper-2);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 14px;
}
.contact-strip strong { color: var(--ink); }
.contact-strip a { color: var(--teal-dark); font-weight: 700; text-decoration: none; }
.contact-strip a:hover { text-decoration: underline; }

/* Timeline dossier layout */
.dossier {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 0 28px;
}

@media (max-width: 700px) {
  .dossier { grid-template-columns: 56px 1fr; }
}

.rail {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.rail-line {
  position: absolute;
  top: 6px; bottom: 6px;
  width: 2px;
  background: var(--line);
  left: 50%;
  transform: translateX(-50%);
}

.section-block {
  padding-bottom: 40px;
  position: relative;
}

.section-block .year-marker {
  position: sticky;
  top: 90px;
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 1;
}

.year-dot {
  width: 15px; height: 15px;
  border-radius: 50%;
  background: var(--white);
  border: 3px solid var(--teal);
  margin-bottom: 6px;
}

.year-label {
  font-family: Arial, Helvetica, sans-serif;
  font-weight: 600;
  font-size: 13px;
  color: var(--teal-dark);
  writing-mode: vertical-rl;
  text-orientation: mixed;
  letter-spacing: 0.02em;
}

@media (max-width: 700px) {
  .year-label { writing-mode: horizontal-tb; font-size: 11px; }
}

.report-card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 26px;
  box-shadow: var(--shadow);
}

.report-card h3 {
  font-size: 16.5px;
  margin: 0 0 10px;
  color: var(--teal-dark);
}

.report-card p {
  margin: 0 0 12px;
  font-size: 15.2px;
  color: var(--ink);
}
.report-card p:last-child { margin-bottom: 0; }

.term { color: var(--alert); font-weight: 700; }
.med  { color: var(--med); font-weight: 700; }
.year-inline {
  font-weight: 700;
  color: var(--teal-dark);
  background: rgba(14, 107, 102, 0.10);
  padding: 1px 6px;
  border-radius: 5px;
  white-space: nowrap;
}

.conclusion-card {
  background: linear-gradient(180deg, var(--white), var(--paper-2));
  border: 1px solid var(--line);
  border-left: 5px solid var(--teal);
  border-radius: var(--radius);
  padding: 26px 28px;
  margin-top: 8px;
  box-shadow: var(--shadow);
}

.conclusion-card h3 {
  font-size: 17px;
  margin: 0 0 12px;
}

.footer-note {
  text-align: center;
  font-size: 12.5px;
  color: var(--ink-soft);
  margin-top: 50px;
}

/* Print / PDF export tuning */
@page {
  size: A4;
  margin: 14mm 12mm 16mm;
}

@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }

  .topbar, .footer-note { display: none !important; }

  body {
    background: var(--white);
    font-size: 12.5px;
    line-height: 1.55;
  }

  .page-shell {
    padding: 0;
    max-width: 100%;
  }

  .legend { display: none; }

  /* Le hero repasse en une seule colonne pour ne pas écraser la fiche d'identité */
  .hero {
    grid-template-columns: 1fr;
    gap: 16px;
    margin-bottom: 24px;
  }

  .identity-card,
  .family-panel,
  .conclusion-card,
  .report-card {
    box-shadow: none;
    border: 1px solid var(--line);
  }

  /* La frise devient une simple colonne : plus de grille, plus de sticky,
     plus de texte vertical — c'est ce qui cassait la mise en page du PDF */
  .dossier-content {
    display: block !important;
  }

  .year-marker {
    position: static !important;
    top: auto !important;
    flex-direction: row !important;
    align-items: center;
    gap: 8px;
    margin: 22px 0 8px;
  }

  .year-marker:first-child { margin-top: 0; }

  .year-dot { margin-bottom: 0; }

  .year-label {
    writing-mode: horizontal-tb !important;
    font-size: 13px;
    letter-spacing: 0.03em;
    text-transform: uppercase;
  }

  .section-block { padding-bottom: 18px; }

  /* Chaque bloc reste groupé sur une seule page dans la mesure du possible */
  .section-block,
  .report-card,
  .identity-card,
  .family-panel,
  .conclusion-card,
  .sibling-row {
    break-inside: avoid;
  }

  .family-panel { break-after: avoid; }

  /* La conclusion démarre sur une page propre */
  .conclusion-card { break-before: page; }

  .report-card p { orphans: 3; widows: 3; }
}

.pdf-print-header {
  display: none;
}

@media print {
  .pdf-print-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    border-bottom: 2px solid var(--teal);
    padding-bottom: 8px;
    margin-bottom: 20px;
    font-size: 11px;
    color: var(--ink-soft);
  }
  .pdf-print-header strong { color: var(--ink); }
}

/* =========================================================
   Dissuasion clic droit / outils dev — voir script.js
   ========================================================= */
.no-copy {
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
}

/* Les champs de saisie restent toujours utilisables normalement */
.no-copy input,
.no-copy textarea {
  -webkit-user-select: text;
  -moz-user-select: text;
  user-select: text;
}

/* Le verrou de selection ne doit jamais s'appliquer a l'impression / export PDF */
@media print {
  .no-copy,
  .no-copy * {
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    user-select: text !important;
  }
}

#security-toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(12px);
  background: var(--ink);
  color: var(--white);
  font-size: 13px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 999;
}

#security-toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
