/* Palette tirée des photos de Pica : pierre sèche, feuille d'olivier, ciel de Provence, terre cuite. */
:root {
  --bg: #F4F0E6;          /* pierre claire */
  --card: #FFFDF8;
  --ink: #2A2B23;
  --muted: #6E6A5C;
  --line: #E1DACB;
  --accent: #5E7A3B;      /* olivier */
  --accent-hover: #4C6530;
  --accent-ink: #FFFFFF;
  --danger: #A63A2B;
  --today: #FBEFDF;       /* terre cuite très claire */
  --today-line: #E9C9A8;
  --empty: #ECE6D8;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 14px rgba(43,42,40,.06);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); -webkit-text-size-adjust: 100%; }
body { font-size: 16px; line-height: 1.4; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-size: .95rem; margin: .5rem 0 0; }
h1, h2 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
label { display: block; font-size: .9rem; color: var(--muted); margin: .9rem 0 .3rem; }
label.inline { display: inline-flex; align-items: center; gap: .5rem; margin: 0; }

input, select, button { font: inherit; }
input[type=text], input[type=password], input[type=number], input[type=date], input:not([type]), select {
  width: 100%; padding: .65rem .8rem; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink); min-height: 44px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
input[type=color] { width: 44px; height: 44px; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .6rem 1rem; min-height: 44px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #F6F2EB; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: #EFE9DF; }
.btn.danger { color: var(--danger); border-color: #F3C9C4; background: #FFF6F5; }
.btn.small { padding: .35rem .7rem; min-height: 36px; font-size: .9rem; }
.btn.wide { width: 100%; margin-top: 1rem; }

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

/* ---------- Connexion ---------- */
.screen {
  min-height: 100dvh; display: grid; place-items: center; padding: 16px;
  background: #6E7D5A url("/static/img/paysage.jpg") center 55% / cover no-repeat;
  position: relative;
}
.screen::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(20,30,20,.15) 0%, rgba(20,30,20,.45) 100%);
}
.login-card {
  position: relative; width: 100%; max-width: 380px; text-align: center; padding: 2rem 1.5rem;
  background: rgba(255,253,248,.92); backdrop-filter: blur(6px); border-color: rgba(255,255,255,.6);
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.login-card h1 { font-size: 2.4rem; letter-spacing: .02em; }
.login-card label { text-align: left; }

/* ---------- Bandeau photo ---------- */
.hero {
  position: relative; border-radius: var(--radius); overflow: hidden; margin-bottom: 1rem;
  height: 170px; box-shadow: var(--shadow);
}
/* Cadrage : les visages sont dans le tiers supérieur de la photo (≈ 14 % à 37 % de la hauteur). */
.hero img { width: 100%; height: 100%; object-fit: cover; object-position: center 18%; display: block; }
.hero-title {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 1.6rem 1rem .7rem; color: #fff;
  font-weight: 650; font-size: 1.2rem; letter-spacing: .01em;
  background: linear-gradient(180deg, rgba(0,0,0,0) 0%, rgba(0,0,0,.55) 100%);
  text-shadow: 0 1px 2px rgba(0,0,0,.4);
}
@media (min-width: 760px) { .hero { height: 260px; } .hero-title { font-size: 1.5rem; } }

/* ---------- Barre ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5; background: rgba(250,248,243,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .5rem 1rem;
  padding: .6rem 16px;
}
.brand { font-weight: 700; font-size: 1.15rem; }
.tabs { display: flex; gap: .25rem; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 0; background: transparent; padding: .5rem .8rem; border-radius: 999px; cursor: pointer;
  color: var(--muted); white-space: nowrap; min-height: 40px;
}
.tab.active { background: var(--ink); color: #fff; }
.topbar-actions { display: flex; gap: .4rem; }

main { max-width: 1100px; margin: 0 auto; padding: 16px; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.legend { font-size: .9rem; margin-top: 1rem; }

/* ---------- Segmented ---------- */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: transparent; padding: .55rem .9rem; min-height: 44px; cursor: pointer; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: var(--ink); color: #fff; }

/* ---------- Calendrier ---------- */
.now-box { margin-bottom: 1rem; padding: .9rem 1rem; }
.now-box h3 { margin: 0 0 .35rem; font-size: 1rem; }
.now-box .chips { margin-top: .3rem; }
.now-box .next { margin-top: .5rem; font-size: .92rem; }

.month-nav { display: flex; align-items: center; gap: .5rem; margin-bottom: .75rem; }
.month-nav h2 { font-size: 1.25rem; flex: 1; text-transform: capitalize; }
.month-nav .btn { font-size: 1.3rem; min-width: 44px; }
.month-nav .small { font-size: .9rem; }

.calendar { display: grid; gap: 6px; }
.cal-head { display: none; }
.day {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .5rem .6rem;
  min-height: 48px; cursor: pointer; display: grid; grid-template-columns: auto 1fr; gap: .25rem .6rem; align-items: start;
}
.day:hover { border-color: #CFC6B8; }
.day.other { opacity: .45; }
.day.today { background: var(--today); border-color: var(--today-line); }
.day.weekend .num { color: #B5603C; }
.day .num { font-weight: 650; font-variant-numeric: tabular-nums; min-width: 2.2rem; }
.day .num small { display: block; font-weight: 400; font-size: .72rem; color: var(--muted); text-transform: capitalize; }
.day .total { grid-column: 1; font-size: .75rem; color: var(--muted); }
.day .chips { grid-column: 2; grid-row: 1 / span 2; }
.empty-run {
  background: var(--empty); border-radius: 10px; padding: .45rem .8rem; color: var(--muted); font-size: .9rem; cursor: pointer;
}

.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  display: inline-flex; align-items: center; gap: .35rem; padding: .15rem .55rem .15rem .4rem;
  border-radius: 999px; font-size: .8rem; line-height: 1.5; background: var(--c, #888); color: #fff; max-width: 100%;
  cursor: pointer; border: 0;
}
.chip .n { background: rgba(255,255,255,.3); border-radius: 999px; padding: 0 .4rem; font-variant-numeric: tabular-nums; }
.chip.amis { background: #fff; color: var(--c, #888); box-shadow: inset 0 0 0 2px var(--c, #888); }
.chip.amis .n { background: var(--c, #888); color: #fff; }
.chip span.nom { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (min-width: 760px) {
  .calendar { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .cal-head { display: block; text-align: center; font-size: .8rem; color: var(--muted); text-transform: capitalize; padding-bottom: .2rem; }
  .day { min-height: 110px; grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; align-content: start; }
  .day .num small { display: none; }
  .day .chips { grid-column: 1; grid-row: 2; align-content: start; }
  .day .total { grid-column: 1; grid-row: 3; }
  .empty-run { display: none; }
  .legend { text-align: center; }
}

/* ---------- Listes ---------- */
.list { display: grid; gap: .6rem; }
.item {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem;
  display: grid; grid-template-columns: 6px 1fr auto; gap: .9rem; align-items: center; cursor: pointer;
}
.item:hover { border-color: #CFC6B8; }
.item .bar { width: 6px; align-self: stretch; border-radius: 3px; background: var(--c, #888); }
.item .title { font-weight: 600; }
.item .sub { color: var(--muted); font-size: .92rem; }
.item .tag { font-size: .78rem; padding: .1rem .5rem; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); margin-left: .4rem; }
.item .right { text-align: right; color: var(--muted); font-size: .9rem; white-space: nowrap; }
.item .right b { color: var(--ink); font-size: 1.1rem; }
.group-title { margin: 1rem 0 .3rem; font-size: .85rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }

.row-form { display: grid; grid-template-columns: 1fr auto auto; gap: .5rem; align-items: center; margin-bottom: 1rem; }

/* ---------- Familles & membres ---------- */
.famille-group { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: .8rem 1rem 1rem; margin-bottom: 1rem; }
.famille-head { display: flex; align-items: center; gap: .6rem; padding-bottom: .6rem; margin-bottom: .6rem; border-bottom: 3px solid var(--c, var(--line)); }
.famille-head input[type=color] { width: 36px; height: 36px; flex: none; }
.famille-head .name { flex: 1; min-width: 0; border: 0; background: transparent; padding: .3rem .4rem; font-weight: 700; font-size: 1.05rem; min-height: 40px; }
.famille-head .name:focus, .membre-item .name:focus { background: #F6F2EB; border-radius: 8px; outline: 2px solid var(--accent); }
.famille-head .count { font-size: .85rem; white-space: nowrap; }
.famille-group .list { gap: .4rem; }
.membre-item { grid-template-columns: 12px 1fr auto auto; gap: .6rem; padding: .35rem .6rem; cursor: default; box-shadow: none; }
.membre-item .dot { width: 12px; height: 12px; border-radius: 50%; }
.membre-item .name { border: 0; background: transparent; padding: .3rem .4rem; font-weight: 600; width: 100%; min-height: 40px; min-width: 0; }
.membre-item select { width: auto; min-height: 36px; padding: .3rem 1.6rem .3rem .6rem; font-size: .9rem; }
.membre-item.inactive { opacity: .55; }
.membre-form { margin: .7rem 0 0; grid-template-columns: 1fr auto; }
.membre-form input { min-height: 40px; }
.fam-name { font-weight: 400; font-size: .9rem; }

/* tableaux groupés par famille */
tr.fam td { background: #F7F3EA; font-weight: 600; }
tr.membre td.cig { padding-left: 1.6rem; font-weight: 400; }
.matrix tr.fam td:first-child { background: #F7F3EA; }
@media (max-width: 600px) {
  .membre-item { grid-template-columns: 12px 1fr auto; }
  .membre-item select { grid-column: 2 / -1; width: 100%; }
}

/* ---------- Tableau nuitées ---------- */
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: .6rem .5rem; text-align: right; border-bottom: 1px solid var(--line); }
th { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
th:first-child, td:first-child { text-align: left; }
td.cig { font-weight: 600; }
td.cig .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: .5rem; vertical-align: middle; }
tr.total td { font-weight: 700; border-top: 2px solid var(--ink); border-bottom: 0; }
.table-wrap { overflow-x: auto; }
@media (max-width: 600px) { th.opt, td.opt { display: none; } }
.matrix th, .matrix td { padding: .5rem .45rem; white-space: nowrap; }
.matrix th:first-child, .matrix td:first-child {
  position: sticky; left: 0; background: var(--card); z-index: 1; box-shadow: 1px 0 0 var(--line);
}
.matrix td.zero { color: #C9C2B2; }
.matrix td:last-child, .matrix th:last-child { background: #F7F3EA; }
.table-note { font-size: .85rem; margin: .7rem 0 0; }
.toolbar .seg button { min-height: 40px; padding: .4rem .7rem; font-size: .92rem; }

/* ---------- Dialog ---------- */
dialog {
  border: 0; border-radius: 16px; padding: 0; width: min(520px, calc(100vw - 32px));
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(43,42,40,.45); }
.dialog-form { padding: 1.25rem 1.25rem 1rem; }
.dialog-form h2 { font-size: 1.25rem; }
.two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .8rem; }
.two > div { min-width: 0; }
input[type=date] { min-width: 0; max-width: 100%; }
.resume { margin: 1rem 0 0; padding: .6rem .8rem; background: var(--today); border-radius: 10px; font-size: .95rem; }
.dialog-actions { display: flex; gap: .5rem; margin-top: 1.2rem; align-items: center; }
.spacer { flex: 1; }
@media (max-width: 480px) {
  .dialog-actions { flex-wrap: wrap; }
  .dialog-actions .spacer { display: none; }
  .dialog-actions .btn { flex: 1 1 40%; }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: .7rem 1.1rem; border-radius: 999px; font-size: .95rem; z-index: 50;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
}

@media (max-width: 760px) {
  .topbar { grid-template-columns: 1fr auto; }
  .tabs { grid-column: 1 / -1; order: 3; }
  .brand { order: 1; }
  .topbar-actions { order: 2; }
  #btn-logout { padding: .6rem .7rem; }
  .row-form { grid-template-columns: 1fr auto; }
  .row-form .btn { grid-column: 1 / -1; }
}
