/* Agenda Famille / Home All – styles
   Mobile d'abord ; l'ordinateur (≥ 900px) affiche une barre latérale et des vues plus riches. */

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef2f9;
  --text: #0f172a;
  --muted: #64748b;
  --border: #dbe2ee;
  --primary: #1e40af;
  --primary-contrast: #ffffff;
  --accent: #f59e0b;
  --danger: #dc2626;
  --success: #16a34a;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 6px 20px rgba(15, 23, 42, .06);
  --tab-h: 64px;
  --top-h: 56px;
  --font-scale: 1;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220; --surface: #141d2f; --surface-2: #1c273b; --text: #e6ecf7; --muted: #94a3b8;
    --border: #253248; --primary: #60a5fa; --primary-contrast: #0b1220; --shadow: 0 1px 3px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  --bg: #0b1220; --surface: #141d2f; --surface-2: #1c273b; --text: #e6ecf7; --muted: #94a3b8;
  --border: #253248; --primary: #60a5fa; --primary-contrast: #0b1220; --shadow: 0 1px 3px rgba(0,0,0,.4);
}
:root[data-theme="epaper"] {
  --bg: #ffffff; --surface: #ffffff; --surface-2: #ffffff; --text: #000000; --muted: #333333;
  --border: #000000; --primary: #000000; --primary-contrast: #ffffff; --accent: #000000; --shadow: none; --radius: 0;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: calc(16px * var(--font-scale)) / 1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
}
a { color: var(--primary); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
p { margin: 0 0 .75rem; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.row { display: flex; align-items: center; gap: .6rem; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.wrap { flex-wrap: wrap; }
.mt { margin-top: 1rem; } .mb { margin-bottom: 1rem; }

/* ---- Structure ---- */
.app { display: grid; min-height: 100dvh; grid-template-rows: auto 1fr auto; }
.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--top-h); display: flex; align-items: center; gap: .5rem;
  padding: 0 .75rem; padding-top: env(safe-area-inset-top); background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-title { font-weight: 700; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-menu { display: none; background: none; border: 0; font-size: 1.4rem; padding: .3rem .5rem; cursor: pointer; }
.topbar-right { display: flex; gap: .35rem; }
.view { padding: 1rem; padding-bottom: calc(var(--tab-h) + 1.5rem + env(safe-area-inset-bottom)); max-width: 760px; width: 100%; margin: 0 auto; }
.sidebar { display: none; }
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: .72rem; color: var(--muted); }
.tabbar a.active { color: var(--primary); font-weight: 600; }
.tab-icon { font-size: 1.35rem; line-height: 1; }
.tabbar .tab-add .tab-icon { background: var(--primary); color: var(--primary-contrast); border-radius: 50%; width: 34px; height: 34px; display: grid; place-items: center; font-weight: 700; }

@media (min-width: 900px) {
  .app { grid-template-columns: 240px 1fr; grid-template-rows: auto 1fr; }
  .topbar { grid-column: 2; }
  .sidebar { display: flex; flex-direction: column; grid-row: 1 / span 2; grid-column: 1; background: var(--surface); border-right: 1px solid var(--border); padding: 1rem .75rem; position: sticky; top: 0; height: 100dvh; }
  .sidebar-brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; padding: .25rem .5rem 1rem; }
  .sidebar a.nav { display: flex; align-items: center; gap: .6rem; padding: .55rem .75rem; border-radius: 10px; color: var(--text); }
  .sidebar a.nav:hover { background: var(--surface-2); }
  .sidebar a.nav.active { background: var(--primary); color: var(--primary-contrast); }
  .sidebar .nav-section { margin: .9rem .75rem .3rem; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
  .sidebar-footer { margin-top: auto; padding: .5rem .75rem; font-size: .8rem; color: var(--muted); }
  .view { grid-column: 2; max-width: 1200px; padding: 1.5rem 2rem; padding-bottom: 2rem; }
  .tabbar { display: none; }
  .app.no-nav { grid-template-columns: 1fr; }
  .app.no-nav .view, .app.no-nav .topbar { grid-column: 1; }
}
.app.no-nav .sidebar, .app.no-nav .tabbar { display: none; }

/* ---- Composants ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.card.tight { padding: .5rem .75rem; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .6rem 1rem; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; min-height: 42px; text-align: center;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--primary); color: var(--primary-contrast); border-color: var(--primary); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.block { width: 100%; }
.btn.big { font-size: 1.1rem; padding: .9rem 1.2rem; }
.btn.icon { padding: .4rem .6rem; min-height: 36px; }
.btn.link { border: 0; background: none; color: var(--primary); padding: .3rem .5rem; min-height: 0; }
.field { margin-bottom: .9rem; }
.field label { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: .3rem; }
.input, select.input, textarea.input {
  width: 100%; padding: .65rem .8rem; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); min-height: 44px;
}
.input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.input.big { font-size: 1.15rem; min-height: 54px; }
textarea.input { min-height: 80px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.check { display: flex; align-items: center; gap: .5rem; padding: .4rem 0; cursor: pointer; }
.check input { width: 20px; height: 20px; }
.error { color: var(--danger); font-size: .9rem; margin: .5rem 0; }
.hint { font-size: .8rem; color: var(--muted); margin-top: .3rem; }
.pill { display: inline-flex; align-items: center; gap: .3rem; padding: .15rem .6rem; border-radius: 999px; font-size: .78rem; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.pill.on { background: var(--primary); color: var(--primary-contrast); border-color: var(--primary); }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip {
  display: inline-flex; align-items: center; gap: .4rem; padding: .35rem .7rem .35rem .4rem; border-radius: 999px; border: 2px solid var(--border);
  background: var(--surface); cursor: pointer; font-weight: 600; font-size: .9rem;
}
.chip.on { border-color: var(--chip, var(--primary)); background: color-mix(in srgb, var(--chip, var(--primary)) 15%, var(--surface)); }
.avatar {
  width: 26px; height: 26px; border-radius: 50%; display: inline-grid; place-items: center; font-size: .7rem; font-weight: 700; color: #fff;
  background: var(--chip, var(--muted)); flex: none;
}
.avatar.sm { width: 20px; height: 20px; font-size: .6rem; }
.avatars { display: inline-flex; }
.avatars .avatar { margin-left: -6px; border: 2px solid var(--surface); }
.avatars .avatar:first-child { margin-left: 0; }
.kbd { font-family: ui-monospace, monospace; background: var(--surface-2); padding: .1rem .4rem; border-radius: 6px; font-size: .9em; }
.key-display { font-family: ui-monospace, monospace; font-size: 1.6rem; letter-spacing: .08em; font-weight: 700; text-align: center; padding: .8rem; background: var(--surface-2); border-radius: 12px; user-select: all; }
.list { display: flex; flex-direction: column; gap: .4rem; }
.item { display: flex; align-items: center; gap: .75rem; padding: .65rem .75rem; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; cursor: pointer; }
.item:hover { background: var(--surface-2); }
.item .grow { min-width: 0; }
.item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { font-size: .82rem; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 1.5rem .5rem; }
.divider { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.toolbar .spacer { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: .45rem .8rem; cursor: pointer; font-weight: 600; }
.seg button.on { background: var(--primary); color: var(--primary-contrast); }

/* ---- Événements ---- */
.day-block { margin-bottom: 1.2rem; }
.day-head { display: flex; align-items: baseline; gap: .6rem; margin-bottom: .45rem; }
.day-head .name { font-weight: 800; font-size: 1.05rem; text-transform: uppercase; letter-spacing: .03em; }
.day-head .date { color: var(--muted); font-size: .85rem; }
.day-head.today .name { color: var(--primary); }
.event {
  display: grid; grid-template-columns: 58px 1fr auto; align-items: center; gap: .6rem; padding: .55rem .7rem; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border); border-left: 5px solid var(--cat, var(--border)); margin-bottom: .4rem; cursor: pointer;
}
.event:hover { background: var(--surface-2); }
.event .time { font-weight: 700; font-variant-numeric: tabular-nums; }
.event .time small { display: block; font-weight: 400; color: var(--muted); font-size: .72rem; }
.event .title { font-weight: 600; }
.event .meta { font-size: .78rem; color: var(--muted); }
.event.past { opacity: .5; }
.event.past .title { text-decoration: line-through; }
.event.allday .time { color: var(--muted); font-weight: 600; font-size: .8rem; }
.period {
  display: flex; align-items: center; gap: .5rem; padding: .35rem .7rem; border-radius: 999px; margin-bottom: .35rem; cursor: pointer; font-size: .9rem;
  background: color-mix(in srgb, var(--cat, var(--muted)) 18%, var(--surface)); border: 1px solid color-mix(in srgb, var(--cat, var(--muted)) 40%, transparent);
}
.period .title { font-weight: 600; }
.period .range { color: var(--muted); font-size: .8rem; margin-left: auto; white-space: nowrap; }

/* ---- Météo ---- */
.weather { display: flex; align-items: center; gap: 1rem; }
.weather .icon { font-size: 2.6rem; line-height: 1; }
.weather .temp { font-size: 2rem; font-weight: 800; line-height: 1; }
.weather .desc { color: var(--muted); font-size: .9rem; }
.weather .advice { font-weight: 600; margin-top: .2rem; }
.weather-mini { display: flex; gap: .6rem; align-items: center; font-size: .9rem; color: var(--muted); }

/* ---- Calendrier (grille) ---- */
.cal-head { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: .3rem; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-cell { min-height: 92px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: .3rem; font-size: .78rem; cursor: pointer; overflow: hidden; display: flex; flex-direction: column; }
.cal-cell.other { opacity: .45; }
.cal-cell.today { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.cal-cell.weekend { background: var(--surface-2); }
.cal-cell .num { font-weight: 700; margin-bottom: .2rem; }
.cal-cell.today .num { color: var(--primary); }
.cal-ev { border-left: 3px solid var(--cat, var(--muted)); padding: 1px 4px; margin-bottom: 2px; border-radius: 4px; background: color-mix(in srgb, var(--cat, var(--muted)) 12%, transparent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-ev.period { background: color-mix(in srgb, var(--cat, var(--muted)) 30%, transparent); border-left: 0; padding-left: 4px; }
.cal-more { color: var(--muted); font-size: .72rem; }
.cal-mini-dots { display: flex; gap: 2px; flex-wrap: wrap; }
.cal-mini-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--cat, var(--muted)); }
@media (max-width: 899px) { .cal-cell { min-height: 54px; } .cal-cell .cal-ev { display: none; } .cal-cell .cal-more { display: none; } }
@media (min-width: 900px) { .cal-cell .cal-mini-dots { display: none; } }
.week-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.week-col { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .5rem; min-height: 300px; }
.week-col.today { border-color: var(--primary); }
.week-col .wk-head { font-weight: 700; margin-bottom: .4rem; text-align: center; }
.week-col .wk-head small { display: block; color: var(--muted); font-weight: 400; }
.week-col .event { grid-template-columns: 1fr; gap: .1rem; padding: .35rem .5rem; font-size: .82rem; }
.week-col .event .time { font-size: .78rem; }

/* ---- Modale ---- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(2, 6, 23, .55); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--surface); width: 100%; max-height: 92dvh; overflow: auto; border-radius: 18px 18px 0 0; padding: 1rem; padding-bottom: calc(1rem + env(safe-area-inset-bottom)); box-shadow: var(--shadow); }
@media (min-width: 640px) { .modal-backdrop { align-items: center; } .modal { max-width: 560px; border-radius: 18px; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .8rem; }
.modal-head h2 { margin: 0; }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; flex-wrap: wrap; }

/* ---- Divers ---- */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + 1rem + env(safe-area-inset-bottom)); background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 999px; z-index: 60; box-shadow: var(--shadow); font-weight: 600; max-width: 90vw; }
@media (min-width: 900px) { .toast { bottom: 1.5rem; } }
.offline-banner { position: sticky; top: var(--top-h); z-index: 15; background: var(--accent); color: #111; text-align: center; font-size: .82rem; padding: .3rem .6rem; }
.onboarding { max-width: 440px; margin: 2rem auto; }
.onboarding .logo { text-align: center; margin-bottom: 1rem; }
.onboarding .logo img { width: 84px; height: 84px; }
.summary { background: var(--surface-2); border-radius: 12px; padding: .9rem 1rem; font-size: 1.05rem; }
.summary .line { padding: .12rem 0; }
.summary .line:first-child { font-weight: 800; font-size: 1.25rem; }
.warn { color: var(--accent); font-size: .85rem; }
.spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.color-dot { width: 14px; height: 14px; border-radius: 50%; display: inline-block; }
.weekday-picker { display: flex; gap: .3rem; }
.weekday-picker button { flex: 1; padding: .45rem 0; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; }
.weekday-picker button.on { background: var(--primary); color: var(--primary-contrast); border-color: var(--primary); }
table.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.tbl th, table.tbl td { text-align: left; padding: .5rem .4rem; border-bottom: 1px solid var(--border); vertical-align: top; }
table.tbl th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; }
.dash-grid { display: grid; gap: 1rem; }
@media (min-width: 900px) { .dash-grid { grid-template-columns: 2fr 1fr; align-items: start; } }

/* ---- Home All ---- */
body.homeall { background: var(--bg); }
.ha { min-height: 100dvh; padding: 3vmin 4vmin; display: flex; flex-direction: column; gap: 2.2vmin; font-size: calc(2.4vmin * var(--font-scale)); }
.ha-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 2vmin; border-bottom: 2px solid var(--border); padding-bottom: 1.5vmin; }
.ha-date { font-size: 2.2em; font-weight: 800; letter-spacing: .02em; line-height: 1; }
.ha-clock { font-size: 1.4em; color: var(--muted); font-variant-numeric: tabular-nums; }
.ha-weather { text-align: right; }
.ha-weather .big { font-size: 2.2em; font-weight: 800; line-height: 1; }
.ha-weather .big .wi { font-size: 1.1em; margin-right: .2em; }
.ha-weather .line { color: var(--muted); }
.ha-weather .advice { font-weight: 700; color: var(--text); }
.ha-days { display: grid; gap: 2vmin; flex: 1; }
.ha-day .ha-day-title { font-weight: 800; text-transform: uppercase; letter-spacing: .05em; font-size: 1.05em; margin-bottom: .6vmin; color: var(--primary); display: flex; gap: 1em; align-items: baseline; }
.ha-day .ha-day-title small { color: var(--muted); font-weight: 500; text-transform: none; letter-spacing: 0; font-size: .8em; }
.ha-period { display: flex; gap: 1em; align-items: baseline; padding: .3em .8em; border-radius: .5em; margin-bottom: .4vmin; background: color-mix(in srgb, var(--cat, var(--muted)) 18%, var(--surface)); }
.ha-period .t { font-weight: 700; }
.ha-period .who { margin-left: auto; color: var(--muted); }
.ha-event { display: grid; grid-template-columns: 3.4em 1fr auto; gap: 1em; align-items: baseline; padding: .32em 0; border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent); }
.ha-event .time { font-weight: 800; font-variant-numeric: tabular-nums; }
.ha-event .time.allday { font-size: .7em; color: var(--muted); font-weight: 600; }
.ha-event .t { font-weight: 600; }
.ha-event .t .ic { margin-right: .3em; }
.ha-event .who { color: var(--muted); text-align: right; white-space: nowrap; }
.ha-event .who b { color: var(--text); }
.ha-event.past { opacity: .4; }
.ha-event.past .t { text-decoration: line-through; }
.ha-empty { color: var(--muted); font-style: italic; padding: .3em 0; }
.ha-foot { display: flex; justify-content: space-between; color: var(--muted); font-size: .7em; border-top: 1px solid var(--border); padding-top: 1vmin; }
.ha-birthday { background: color-mix(in srgb, #ec4899 18%, var(--surface)); border-radius: .5em; padding: .4em .8em; }
@media (min-width: 1100px) and (min-aspect-ratio: 4/3) { .ha-days { grid-template-columns: 1.4fr 1fr 1fr; } .ha-days .ha-day:nth-child(n+4) { display: none; } }
.ha-exit { position: fixed; top: 0; right: 0; width: 60px; height: 60px; opacity: 0; }
:root[data-theme="epaper"] .ha-event, :root[data-theme="epaper"] .ha-period { border-bottom: 1px solid #000; background: none; }
:root[data-theme="epaper"] .ha-day .ha-day-title { color: #000; border-bottom: 3px solid #000; }

/* ---- Utilitaires ---- */
.mono { font-family: ui-monospace, monospace; }
.fab { position: fixed; right: 1rem; bottom: calc(var(--tab-h) + 1rem + env(safe-area-inset-bottom)); z-index: 18; width: 56px; height: 56px; border-radius: 50%; background: var(--primary); color: var(--primary-contrast); font-size: 1.8rem; border: 0; box-shadow: var(--shadow); cursor: pointer; }
@media (min-width: 900px) { .fab { display: none; } }
.legend { display: flex; flex-wrap: wrap; gap: .4rem .9rem; font-size: .82rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: .3rem; }
.sr-only { position: absolute; left: -9999px; }
.installed-hint { font-size: .8rem; color: var(--muted); }
