/* ===== Gestion ABR · Routine Plus — style Apple ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --ink: #1d1d1f;
  --ink2: #6e6e73;
  --ink3: #aeaeb2;
  --line: #e5e5ea;
  --blue: #0071e3;
  --blue-soft: #eaf3fe;
  --red: #ff3b30;
  --green: #34c759;
  --orange: #ff9500;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,.07), 0 8px 24px rgba(0,0,0,.04);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
}
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
}
#app { display: flex; height: 100vh; overflow: hidden; }

/* ===== Sidebar ===== */
#sidebar {
  width: 218px; flex: 0 0 218px;
  background: rgba(246,246,248,.92);
  backdrop-filter: blur(20px);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 20px 12px 14px;
}
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 4px 8px 16px; }
.brand-img { width: 132px; margin-left: -6px; }
.brand-sub { font-size: 12px; color: var(--ink2); font-weight: 600; padding-left: 2px; margin-top: -14px; }
#nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 9px;
  color: var(--ink); cursor: pointer; font-size: 13.5px; font-weight: 500;
  border: none; background: none; text-align: left; width: 100%;
  font-family: var(--font);
}
.nav-item:hover { background: rgba(0,0,0,.045); }
.nav-item.active { background: var(--blue); color: #fff; }
.nav-item.active svg { stroke: #fff; }
.nav-item svg { width: 17px; height: 17px; stroke: var(--blue); flex: 0 0 17px; }
.nav-badge {
  margin-left: auto; background: var(--red); color: #fff;
  font-size: 10.5px; font-weight: 700; border-radius: 999px;
  min-width: 18px; height: 18px; padding: 0 5px;
  display: flex; align-items: center; justify-content: center;
}
.nav-item.active .nav-badge { background: rgba(255,255,255,.3); }
.sidebar-foot {
  margin-top: auto; padding: 10px 8px 0;
  font-size: 11px; color: var(--ink3); line-height: 1.5;
  border-top: 1px solid var(--line);
}
.sidebar-foot b { color: var(--ink2); font-weight: 600; }

/* ===== Main ===== */
#main { flex: 1; overflow-y: auto; padding: 24px 28px 40px; }
.page-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 18px;
}
.page-title { font-size: 22px; font-weight: 700; letter-spacing: -.3px; margin-right: auto; }
.cal-nav { display: inline-flex; gap: 4px; }
.cal-tools { display: flex; gap: 8px; flex-wrap: wrap; margin: -8px 0 16px; }
.page-sub { color: var(--ink2); font-size: 13px; margin: -14px 0 18px; }

/* ===== Boutons ===== */
.btn {
  font-family: var(--font); font-size: 13px; font-weight: 500;
  padding: 7px 14px; border-radius: 999px; border: none; cursor: pointer;
  background: #e9e9eb; color: var(--ink);
  transition: filter .15s;
}
.btn:hover { filter: brightness(.96); }
.btn.primary { background: var(--blue); color: #fff; }
.btn.danger { background: #feeceb; color: var(--red); }
.btn.small { font-size: 12px; padding: 5px 11px; }
.btn.ghost { background: transparent; color: var(--blue); }
.icon-btn {
  background: none; border: none; cursor: pointer; color: var(--ink3);
  padding: 4px 6px; border-radius: 7px; font-size: 14px; line-height: 1;
}
.icon-btn:hover { background: rgba(0,0,0,.05); color: var(--ink); }

/* Segmented control */
.seg { display: inline-flex; background: #e9e9eb; border-radius: 9px; padding: 2px; }
.seg button {
  font-family: var(--font); font-size: 12.5px; font-weight: 500;
  border: none; background: transparent; padding: 5px 14px;
  border-radius: 7px; cursor: pointer; color: var(--ink);
}
.seg button.active { background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }

/* ===== Formulaires ===== */
select, input[type="text"], input[type="date"], input[type="time"], input[type="tel"],
input[type="email"], input[type="number"], textarea {
  font-family: var(--font); font-size: 13.5px;
  padding: 7px 10px; border: 1px solid #d2d2d7; border-radius: 9px;
  background: #fff; color: var(--ink); outline: none;
}
select:focus, input:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0,113,227,.15); }
textarea { resize: vertical; min-height: 60px; }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--ink2); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }

/* Pastilles de couleur */
.swatches { display: flex; gap: 7px; flex-wrap: wrap; }
.swatch {
  width: 24px; height: 24px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; box-shadow: inset 0 0 0 1px rgba(0,0,0,.08);
}
.swatch.sel { border-color: var(--ink); }

/* Chips employés */
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.emp-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px 4px 4px; border-radius: 999px; cursor: pointer;
  background: #f0f0f2; border: 1.5px solid transparent; font-size: 12.5px; font-weight: 500;
  font-family: var(--font);
}
.emp-chip.sel { background: var(--blue-soft); border-color: var(--blue); }
.avatar {
  width: 21px; height: 21px; border-radius: 50%; color: #fff;
  font-size: 9.5px; font-weight: 700; display: inline-flex;
  align-items: center; justify-content: center; flex: 0 0 21px;
}

/* ===== Calendrier — semaine ===== */
.cal-banner {
  background: #fff8ec; border: 1px solid #ffe3b3; border-radius: 11px;
  padding: 9px 14px; font-size: 12.5px; color: #8a5a00;
  margin-bottom: 14px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.cal-banner .job-link {
  background: #fff; border: 1px solid #ffd48a; border-radius: 999px;
  padding: 2px 10px; cursor: pointer; font-size: 12px; font-weight: 600; color: #8a5a00;
  font-family: var(--font);
}
.week-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px;
  align-items: stretch;
}
.day-col {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 10px 8px 8px; min-height: 320px; display: flex; flex-direction: column; gap: 7px;
}
.day-col.today { outline: 2px solid var(--blue); outline-offset: -2px; }
.day-head { text-align: center; padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.day-head .dname { font-size: 11px; font-weight: 600; color: var(--ink2); text-transform: uppercase; letter-spacing: .4px; }
.day-head .dnum { font-size: 19px; font-weight: 700; }
.day-col.today .dnum { color: var(--blue); }
.day-add {
  border: 1.5px dashed #d2d2d7; background: none; border-radius: 9px;
  color: var(--ink3); cursor: pointer; padding: 4px; font-size: 13px;
  font-family: var(--font);
}
.day-add:hover { color: var(--blue); border-color: var(--blue); }
.day-foot { margin-top: auto; text-align: center; font-size: 11px; color: var(--ink3); padding-top: 5px; }

.ev-card {
  border-radius: 10px; padding: 7px 9px; cursor: pointer;
  background: var(--evbg, #f0f6ff);
  border-left: 4px solid var(--evc, var(--blue));
  position: relative;
}
.ev-card:hover { filter: brightness(.975); }
.ev-time { font-size: 11px; color: var(--ink2); font-weight: 600; }
.ev-name { font-size: 12.5px; font-weight: 650; line-height: 1.25; margin: 1px 0 3px; }
.ev-loc { font-size: 11px; color: var(--ink2); margin-bottom: 3px; }
.ev-avatars { display: flex; gap: 3px; flex-wrap: wrap; }
.ev-avatars .avatar { width: 19px; height: 19px; font-size: 8.5px; flex-basis: 19px; }
.ev-conflict {
  position: absolute; top: 6px; right: 7px; width: 8px; height: 8px;
  background: var(--red); border-radius: 50%;
}
.ev-side-tag { font-size: 9.5px; font-weight: 700; color: var(--ink2); text-transform: uppercase; letter-spacing: .4px; }

/* ===== Calendrier — mois ===== */
.month-grid { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.month-dows { display: grid; grid-template-columns: repeat(7, 1fr); border-bottom: 1px solid var(--line); }
.month-dows div { text-align: center; font-size: 11px; font-weight: 600; color: var(--ink2); padding: 8px 0; text-transform: uppercase; letter-spacing: .4px; }
.month-week { display: grid; grid-template-columns: repeat(7, 1fr); }
.month-cell {
  min-height: 96px; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line);
  padding: 6px; cursor: pointer; overflow: hidden;
}
.month-cell:nth-child(7n) { border-right: none; }
.month-week:last-child .month-cell { border-bottom: none; }
.month-cell:hover { background: #fafafa; }
.month-cell .num {
  font-size: 12px; font-weight: 600; width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center; border-radius: 50%;
  margin-bottom: 3px;
}
.month-cell.dim .num { color: var(--ink3); font-weight: 400; }
.month-cell.today .num { background: var(--blue); color: #fff; }
.pill {
  display: flex; align-items: center; gap: 4px;
  font-size: 10.5px; font-weight: 550; border-radius: 5px; padding: 1.5px 5px;
  margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: var(--evbg, #f0f6ff);
}
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--evc, var(--blue)); flex: 0 0 6px; }
.pill-more { font-size: 10.5px; color: var(--ink2); font-weight: 600; padding-left: 4px; }

/* ===== Cartes génériques ===== */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; cursor: pointer; transition: transform .12s;
}
.card:hover { transform: translateY(-1px); }
.card h3 { font-size: 15px; font-weight: 650; display: flex; align-items: center; gap: 8px; }
.card .meta { font-size: 12.5px; color: var(--ink2); margin-top: 6px; line-height: 1.6; }
.card .meta a { color: var(--blue); text-decoration: none; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: 0 0 10px; }
.tag {
  display: inline-block; font-size: 10.5px; font-weight: 700; letter-spacing: .4px;
  text-transform: uppercase; border-radius: 5px; padding: 2px 7px;
  background: #f0f0f2; color: var(--ink2);
}
.tag.side { background: #fff3e0; color: #b26a00; }
.tag.inactive { background: #feeceb; color: var(--red); }
.section-title { font-size: 15px; font-weight: 700; margin: 26px 0 12px; }
.empty {
  text-align: center; color: var(--ink3); padding: 44px 20px; font-size: 13.5px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
}

/* ===== To-do ===== */
.todo-add {
  display: flex; gap: 8px; background: var(--card); padding: 12px;
  border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; flex-wrap: wrap;
}
.todo-add input[type="text"] { flex: 1; min-width: 180px; }
.todo-list { display: flex; flex-direction: column; gap: 6px; }
.todo-row {
  display: flex; align-items: center; gap: 11px;
  background: var(--card); border-radius: 11px; box-shadow: var(--shadow);
  padding: 10px 14px;
}
.todo-row.done { opacity: .5; }
.todo-row.done .todo-text { text-decoration: line-through; }
.todo-check {
  width: 21px; height: 21px; border-radius: 50%; border: 1.5px solid #c7c7cc;
  background: none; cursor: pointer; flex: 0 0 21px; position: relative;
}
.todo-row.done .todo-check { background: var(--green); border-color: var(--green); }
.todo-row.done .todo-check::after {
  content: "✓"; color: #fff; font-size: 12px; font-weight: 700;
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
}
.todo-text { flex: 1; font-size: 13.5px; }
.due-chip { font-size: 11.5px; font-weight: 600; color: var(--ink2); background: #f0f0f2; border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
.due-chip.late { background: #feeceb; color: var(--red); }
.due-chip.today { background: var(--blue-soft); color: var(--blue); }

/* ===== Documents ===== */
.doc-cats { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 16px; }
.doc-cat {
  font-family: var(--font); font-size: 12.5px; font-weight: 550;
  padding: 6px 14px; border-radius: 999px; border: none; cursor: pointer;
  background: #e9e9eb; color: var(--ink);
}
.doc-cat.active { background: var(--ink); color: #fff; }
.doc-row {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--card); border-radius: 11px; box-shadow: var(--shadow);
  padding: 11px 15px; margin-bottom: 6px;
}
.doc-icon {
  width: 34px; height: 34px; border-radius: 8px; flex: 0 0 34px;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 800; color: #fff; letter-spacing: .3px;
}
.doc-name { flex: 1 1 160px; font-size: 13.5px; font-weight: 550; overflow-wrap: break-word; min-width: 0; }
.doc-meta { font-size: 11.5px; color: var(--ink3); white-space: nowrap; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.32);
  display: none; align-items: flex-start; justify-content: center;
  padding: 7vh 16px; z-index: 100; overflow-y: auto;
}
.modal-overlay.open { display: flex; }
.modal-sheet {
  background: #fff; border-radius: 18px; width: 100%; max-width: 520px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25); padding: 24px;
  animation: pop .18s ease-out;
}
@keyframes pop { from { transform: scale(.97) translateY(6px); opacity: 0; } }
.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 18px; display: flex; align-items: center; }
.modal-title .icon-btn { margin-left: auto; font-size: 16px; }
.modal-actions { display: flex; gap: 8px; margin-top: 22px; flex-wrap: wrap; }
.modal-actions .spacer { flex: 1; }
.periode-row {
  display: grid; grid-template-columns: 1.3fr 1fr 1fr auto;
  gap: 7px; align-items: end; margin-bottom: 7px;
  background: #f7f7f9; border-radius: 10px; padding: 8px;
}
.mini {
  display: flex; flex-direction: column; gap: 3px;
  font-size: 10px; font-weight: 700; color: var(--ink3);
  text-transform: uppercase; letter-spacing: .4px;
}
.hint { font-size: 11.5px; color: var(--ink3); margin-top: 4px; }

/* ===== Finances (fiche job) ===== */
.fin-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  background: #f7f7f9; border-radius: 12px; padding: 12px;
}
.fin-grid input, .fin-grid select { width: 100%; min-width: 0; box-sizing: border-box; }
.modal-sheet { overflow-x: hidden; }
.fin-result { border-radius: 12px; padding: 11px 14px; font-size: 13px; line-height: 1.75; margin-top: 8px; }
.fin-result .big { font-size: 15.5px; font-weight: 700; }
.fin-result.pos { background: #e8f7ee; }
.fin-result.pos .big { color: #1e8e3e; }
.fin-result.neg { background: #feeceb; }
.fin-result.neg .big { color: var(--red); }
.tag.money-pos { background: #e8f7ee; color: #1e8e3e; text-transform: none; letter-spacing: 0; }
.tag.money-neg { background: #feeceb; color: var(--red); text-transform: none; letter-spacing: 0; }
.upcoming { font-size: 12.5px; color: var(--ink2); line-height: 1.8; }

/* ===== Écrans étroits (téléphone / petite fenêtre) ===== */
@media (max-width: 720px) {
  #app { flex-direction: column; height: auto; min-height: 100dvh; }

  /* Barre du haut collante, avec zone sécurisée iPhone (encoche) */
  #sidebar {
    width: 100%; flex: none; flex-direction: row; align-items: center;
    padding: 6px 10px calc(6px);
    padding-top: calc(6px + env(safe-area-inset-top));
    border-right: none; border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 50;
  }
  .brand { flex-direction: row; padding: 0 6px 0 0; }
  .brand-img { width: auto; height: 30px; margin: 0; }
  .brand-sub { display: none; }
  #nav { flex-direction: row; flex: 1; justify-content: space-around; gap: 0; }
  .nav-item { padding: 10px; min-height: 44px; justify-content: center; position: relative; }
  .nav-item svg { width: 21px; height: 21px; flex-basis: 21px; }
  .nav-item .nav-label { display: none; }
  .nav-badge { position: absolute; top: 3px; right: 2px; margin: 0; }
  .sidebar-foot { display: none; }

  #main { padding: 14px 12px calc(30px + env(safe-area-inset-bottom)); overflow: visible; }
  .page-title { font-size: 19px; flex-basis: 100%; }
  .page-head { gap: 8px; margin-bottom: 12px; }
  .cal-nav { margin-left: auto; }
  .cal-nav .btn, .seg button { min-height: 36px; }

  /* Outils du calendrier : grille 2 colonnes bien rangée */
  .cal-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 0 14px; }
  .cal-tools select { width: 100%; min-height: 42px; }
  .cal-tools .btn { min-height: 42px; }

  /* Semaine : une carte par jour; les jours vides deviennent une mince rangée */
  .week-grid { grid-template-columns: 1fr; gap: 7px; }
  .day-col { min-height: 0; padding: 10px 12px; }
  .day-head { display: flex; align-items: baseline; gap: 8px; text-align: left; padding-bottom: 6px; }
  .day-head .dnum { font-size: 17px; }
  .day-head .dname { font-size: 12px; }
  .ev-card { padding: 10px 12px; }
  .ev-name { font-size: 14px; }
  .ev-time, .ev-loc { font-size: 12px; }
  .ev-avatars .avatar { width: 22px; height: 22px; font-size: 9.5px; flex-basis: 22px; }
  .day-add { min-height: 38px; }
  .day-col.no-ev { flex-direction: row; align-items: center; padding: 6px 12px; }
  .day-col.no-ev .day-head { border: none; padding: 0; }
  .day-col.no-ev .day-add { margin-left: auto; min-height: 32px; width: 52px; border: none; font-size: 17px; }
  .day-col.no-ev .day-foot { display: none; }

  /* Mois : cellules compactes, événements = points de couleur */
  .month-cell { min-height: 56px; padding: 4px 3px; }
  .month-cell .num { width: 20px; height: 20px; font-size: 11.5px; }
  .month-cell .pill { font-size: 0; padding: 2px 1px; margin: 0 1px 1px 0; background: none; display: inline-flex; }
  .month-cell .pill .dot { width: 7px; height: 7px; flex-basis: 7px; }
  .pill-more { font-size: 10px; }

  /* Modales en feuille du bas, plein écran tactile */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal-sheet {
    max-width: none; border-radius: 18px 18px 0 0;
    max-height: 92dvh; overflow-y: auto;
    padding: 20px 18px calc(24px + env(safe-area-inset-bottom));
  }
  .form-grid { grid-template-columns: 1fr; gap: 14px; }
  .fin-grid { grid-template-columns: 1fr; }
  .modal-actions .btn { min-height: 44px; }

  /* iOS zoome si la police d'un champ < 16 px — on force 16 px */
  select, input[type="text"], input[type="date"], input[type="time"], input[type="tel"],
  input[type="email"], input[type="number"], textarea { font-size: 16px; min-height: 42px; }

  /* Cibles tactiles confortables partout */
  .btn { min-height: 38px; }
  .icon-btn { padding: 9px 11px; font-size: 16px; }
  .todo-check { width: 25px; height: 25px; flex: 0 0 25px; }
  .todo-row { padding: 12px 14px; }
  .todo-add { padding: 12px; }
  .todo-add input[type="text"] { min-width: 100%; }
  .todo-add input[type="date"], .todo-add select { flex: 1; }
  .todo-add .btn { flex-basis: 100%; }
  .emp-chip { min-height: 38px; padding: 6px 12px 6px 6px; }
  .doc-cat { min-height: 38px; }
  .card { padding: 15px; }
  .periode-row { grid-template-columns: 1fr; gap: 5px; background: #f7f7f9; border-radius: 10px; padding: 9px; }
}

/* ===== Impression ===== */
#print-root { display: none; }
@media print {
  #app, .modal-overlay { display: none !important; }
  #print-root { display: block; }
  body { background: #fff; }
  .p-logo { height: 46px; margin-bottom: 8px; }
  #print-root h1 { font-size: 20px; margin-bottom: 2px; }
  .p-sub { color: #555; font-size: 13px; margin-bottom: 4px; }
  .p-week { font-size: 14px; font-weight: 600; margin-bottom: 16px; }
  .p-day { margin-bottom: 12px; break-inside: avoid; }
  .p-day-head {
    font-size: 13px; font-weight: 700; text-transform: capitalize;
    border-bottom: 1.5px solid #000; padding-bottom: 3px; margin-bottom: 5px;
  }
  .p-ev { display: flex; gap: 12px; padding: 4px 0; border-bottom: 1px solid #e5e5e5; font-size: 12px; }
  .p-ev-time { width: 95px; font-weight: 600; flex: 0 0 95px; }
  .p-ev-body b { font-size: 12.5px; }
  .p-ev-loc, .p-ev-notes, .p-ev-emps { color: #444; }
  .p-none { color: #999; font-size: 12px; font-style: italic; padding: 3px 0; }
  .p-foot { margin-top: 24px; font-size: 10.5px; color: #888; }
}
