/* ==========================================================================
   Grand Livre — design tokens
   ========================================================================== */
@font-face {
  font-family: "Plex Serif";
  src: local("IBM Plex Serif");
}

:root {
  --paper: #faf6ef;
  --paper-raised: #ffffff;
  --ink: #1f2a28;
  --ink-soft: #5b6663;
  --teal: #17514f;
  --teal-light: #2c7a73;
  --teal-wash: #e9f1ef;
  --amber: #c1791f;
  --amber-wash: #faedd9;
  --green: #3d7a5c;
  --green-wash: #e6f0ea;
  --red: #b5443a;
  --red-wash: #f8e8e6;
  --line: #e4ddd0;
  --line-strong: #cfc6b4;
  --shadow: 0 1px 2px rgba(31, 42, 40, 0.06), 0 4px 16px rgba(31, 42, 40, 0.06);
  --radius: 14px;
  --font-serif: "Source Serif 4", "IBM Plex Serif", Georgia, serif;
  --font-sans: "IBM Plex Sans", "Inter", system-ui, -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", "SFMono-Regular", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

h1, h2, h3 { font-family: var(--font-serif); margin: 0; font-weight: 600; }

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

button { font-family: inherit; }

::selection { background: var(--teal-light); color: white; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ==========================================================================
   Header
   ========================================================================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top) + 14px) 18px 12px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.topbar .brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.topbar .brand .eyebrow {
  font-size: 11px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.topbar .brand h1 {
  font-size: 20px;
  color: var(--teal);
}

.year-switch {
  display: flex;
  background: var(--teal-wash);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}

.year-switch button {
  border: none;
  background: transparent;
  padding: 6px 13px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--teal);
  cursor: pointer;
  font-family: var(--font-mono);
}

.year-switch button.active {
  background: var(--teal);
  color: white;
}

/* ==========================================================================
   Layout / views
   ========================================================================== */
main {
  padding: 16px 16px 8px;
  max-width: 720px;
  margin: 0 auto;
}

.view { display: none; animation: fade-in 0.22s ease; }
.view.active { display: block; }

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

section + section { margin-top: 22px; }

.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-soft);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ==========================================================================
   KPI hero cards
   ========================================================================== */
.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.kpi-card {
  background: var(--paper-raised);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}

.kpi-card .label {
  font-size: 11.5px;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.kpi-card .value {
  font-family: var(--font-mono);
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.kpi-card .value.small { font-size: 17px; }

.kpi-card.hero {
  grid-column: 1 / -1;
  background: linear-gradient(135deg, var(--teal), #123f3d);
  color: white;
  border: none;
}
.kpi-card.hero .label { color: rgba(255,255,255,0.72); }
.kpi-card.hero .value { font-size: 30px; }
.kpi-card.hero .sub { font-size: 12.5px; color: rgba(255,255,255,0.72); margin-top: 4px; }

.tone-ok { color: var(--green); }
.tone-warn { color: var(--amber); }
.tone-bad { color: var(--red); }

/* ==========================================================================
   Signature element : la frise du mois (31 barres)
   ========================================================================== */
.strip-wrap {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 14px 10px;
  box-shadow: var(--shadow);
}

.strip-legend {
  display: flex;
  gap: 14px;
  font-size: 11px;
  color: var(--ink-soft);
  margin-bottom: 10px;
}
.strip-legend span { display: flex; align-items: center; gap: 5px; }
.strip-legend i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

.strip {
  display: flex;
  align-items: flex-end;
  gap: 2.5px;
  height: 84px;
}

.strip .bar {
  flex: 1;
  min-width: 3px;
  border-radius: 3px 3px 1px 1px;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
  transform-origin: bottom;
}
.strip .bar:active { transform: scaleY(0.94); }
.strip .bar.bar-ok { background: var(--green); opacity: 0.55; }
.strip .bar.bar-warn { background: var(--amber); }
.strip .bar.bar-bad { background: var(--red); }

.strip-axis {
  display: flex;
  justify-content: space-between;
  font-size: 9.5px;
  color: var(--ink-soft);
  margin-top: 4px;
  font-family: var(--font-mono);
}

/* ==========================================================================
   Callout (alerte / info)
   ========================================================================== */
.callout {
  border-radius: var(--radius);
  padding: 13px 15px;
  display: flex;
  gap: 11px;
  border: 1px solid var(--line);
}
.callout .icon { font-size: 18px; line-height: 1; }
.callout .txt { font-size: 13.5px; line-height: 1.45; }
.callout .txt b { font-family: var(--font-mono); }
.callout.warn { background: var(--amber-wash); border-color: #eeddb8; }
.callout.ok { background: var(--green-wash); border-color: #cfe4d7; }

/* ==========================================================================
   Cards / lists (jours, services, patients)
   ========================================================================== */
.card-list { display: flex; flex-direction: column; gap: 8px; }

.row-card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
}

.row-card .row-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.row-card .row-top > div:first-child { min-width: 0; }
.row-card .row-top > div:last-child { flex-shrink: 0; }

.row-card .row-title {
  font-weight: 600;
  font-size: 14.5px;
}

.row-card .row-sub {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 2px;
}

.row-card .row-value {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.badge-ok { background: var(--green-wash); color: var(--green); }
.badge-warn { background: var(--amber-wash); color: var(--amber); }
.badge-bad { background: var(--red-wash); color: var(--red); }

.detail-grid {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--line-strong);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px 14px;
  display: none;
}
.row-card.open .detail-grid { display: grid; }
.detail-grid .d-label { font-size: 11px; color: var(--ink-soft); }
.detail-grid .d-value { font-family: var(--font-mono); font-size: 13.5px; font-weight: 600; }

.progress-bar {
  height: 5px;
  border-radius: 3px;
  background: var(--line);
  overflow: hidden;
  margin-top: 8px;
}
.progress-bar > div { height: 100%; background: var(--teal-light); }

/* ==========================================================================
   Recherche patients
   ========================================================================== */
.search-wrap { position: relative; margin-bottom: 12px; }
.search-wrap input {
  width: 100%;
  padding: 12px 14px 12px 38px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: var(--paper-raised);
  font-size: 15px;
  font-family: var(--font-sans);
  color: var(--ink);
}
.search-wrap input:focus {
  outline: 2px solid var(--teal-light);
  outline-offset: 1px;
}
.search-wrap .icon {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-soft);
  font-size: 15px;
}

.filter-chips { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; padding-bottom: 2px; }
.chip {
  border: 1px solid var(--line-strong);
  background: var(--paper-raised);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12.5px;
  color: var(--ink-soft);
  cursor: pointer;
  white-space: nowrap;
  font-weight: 500;
}
.chip.active { background: var(--teal); border-color: var(--teal); color: white; }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--ink-soft);
}
.empty-state .icon { font-size: 30px; margin-bottom: 8px; }
.empty-state p { margin: 0; font-size: 13.5px; }

/* ==========================================================================
   Bottom tab bar
   ========================================================================== */
nav.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  background: var(--paper-raised);
  border-top: 1px solid var(--line);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
}

nav.tabbar button {
  flex: 1;
  border: none;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px 4px 8px;
  color: var(--ink-soft);
  cursor: pointer;
}

nav.tabbar button .tab-icon { font-size: 20px; line-height: 1; }
nav.tabbar button .tab-label { font-size: 10.5px; font-weight: 600; }
nav.tabbar button.active { color: var(--teal); }
nav.tabbar button:focus-visible { outline: 2px solid var(--teal-light); outline-offset: -2px; border-radius: 8px; }

/* ==========================================================================
   Footer note / loading
   ========================================================================== */
.footnote {
  font-size: 11px;
  color: var(--ink-soft);
  text-align: center;
  padding: 18px 20px 4px;
  line-height: 1.5;
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 60vh;
  color: var(--ink-soft);
  font-size: 13px;
}
