/* ── Variables & Reset ─────────────────────────────── */
:root {
  --bg:   #f5f3ff;
  --surf: #fff;
  --pri:  #7c3aed;
  --pril: #ede9fe;
  --acc:  #f59e0b;
  --txt:  #1e1b4b;
  --mut:  #6b7280;
  --bdr:  #e5e7eb;
  --red:  #ef4444;
  --grn:  #10b981;
  --r:    10px;
  --sh:   0 2px 10px rgba(0, 0, 0, .07);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, sans-serif;
  background: var(--bg);
  color: var(--txt);
  min-height: 100vh;
}

/* ── Layout ────────────────────────────────────────── */
header {
  background: var(--pri);
  color: #fff;
  padding: 14px 22px;
  display: flex;
  align-items: center;
  gap: 10px;
}

header h1 {
  font-size: 1.3rem;
  font-weight: 700;
}

.app {
  display: flex;
  min-height: calc(100vh - 53px);
}

/* ── Sidebar ───────────────────────────────────────── */
.sb {
  width: 210px;
  background: var(--surf);
  border-right: 1px solid var(--bdr);
  padding: 14px 0;
  flex-shrink: 0;
}

.sb-lbl {
  font-size: .7rem;
  font-weight: 700;
  color: var(--mut);
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 10px 14px 5px;
}

.sb-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  cursor: pointer;
  font-size: .85rem;
  border-left: 3px solid transparent;
  color: var(--txt);
}

.sb-item:hover { background: var(--bg); }

.sb-item.active {
  background: var(--pril);
  color: var(--pri);
  border-left-color: var(--pri);
  font-weight: 600;
}

.sb-add {
  color: var(--pri) !important;
  font-size: .82rem;
}
.sb-export {
  color: var(--mut) !important;
  font-size: .78rem;
  margin-top: auto;
  border-top: 1px solid var(--bdr);
  padding-top: 10px !important;
}

/* ── Main content ──────────────────────────────────── */
.main {
  flex: 1;
  padding: 22px;
  overflow-y: auto;
}

.panel        { display: none; }
.panel.active { display: block; }

/* ── Cards ─────────────────────────────────────────── */
.card {
  background: var(--surf);
  border-radius: var(--r);
  box-shadow: var(--sh);
  padding: 18px;
  margin-bottom: 14px;
}

.ctitle {
  font-size: .95rem;
  font-weight: 700;
  margin-bottom: 14px;
}

/* ── Grid ──────────────────────────────────────────── */
.g2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

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

/* ── Form elements ─────────────────────────────────── */
.row {
  display: flex;
  gap: 7px;
  margin-bottom: 8px;
  align-items: center;
}

.row input,
.row select,
input.ib,
select.ib {
  flex: 1;
  padding: 8px 11px;
  border: 1px solid var(--bdr);
  border-radius: 7px;
  font-size: .85rem;
  outline: none;
  background: var(--surf);
  color: var(--txt);
}

.row input:focus,
.row select:focus {
  border-color: var(--pri);
}

/* ── Buttons ───────────────────────────────────────── */
.btn {
  padding: 8px 15px;
  border-radius: 7px;
  border: none;
  cursor: pointer;
  font-size: .85rem;
  font-weight: 600;
  transition: opacity .15s;
}

.btn:hover    { opacity: .84; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.bp { background: var(--pri); color: #fff; }
.ba { background: var(--acc); color: #fff; }
.bg { background: transparent; color: var(--mut); border: 1px solid var(--bdr); }
.bd { background: var(--red); color: #fff; }
.bs { background: var(--grn); color: #fff; }
.sm { padding: 4px 9px; font-size: .76rem; }

/* ── List items ────────────────────────────────────── */
.li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 0;
  border-bottom: 1px solid var(--bdr);
  font-size: .85rem;
}

.li:last-child { border-bottom: none; }

.liname {
  flex: 1;
  font-weight: 500;
}

.fbadge {
  background: var(--pril);
  color: var(--pri);
  font-size: .7rem;
  padding: 2px 8px;
  border-radius: 7px;
  font-weight: 600;
}

/* ── Tabs ──────────────────────────────────────────── */
.stabs {
  display: flex;
  gap: 5px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.stab {
  padding: 7px 16px;
  border-radius: 7px;
  cursor: pointer;
  font-size: .84rem;
  font-weight: 500;
  color: var(--mut);
  border: 1px solid transparent;
}

.stab.active              { background: var(--pri); color: #fff; }
.stab:not(.active):hover  { background: var(--pril); color: var(--pri); }

.spanel        { display: none; }
.spanel.active { display: block; }

/* ── Preference items ──────────────────────────────── */
.pitem {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: var(--bg);
  border-radius: 7px;
  margin-bottom: 5px;
  flex-wrap: wrap;
}

.plabel {
  font-weight: 600;
  font-size: .83rem;
  min-width: 110px;
}

.tag {
  display: inline-block;
  background: var(--pril);
  color: var(--pri);
  padding: 2px 7px;
  border-radius: 5px;
  font-size: .73rem;
  margin: 2px;
}

/* ── Presence grid ─────────────────────────────────── */
.pgrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 9px;
}

.pcard {
  background: var(--bg);
  border: 2px solid var(--bdr);
  border-radius: 9px;
  padding: 11px;
  text-align: center;
  cursor: pointer;
  transition: all .12s;
}

.pcard.yes { background: #ecfdf5; border-color: var(--grn); }
.pcard.no  { background: #fef2f2; border-color: #fca5a5; }

.pcname   { font-weight: 600; font-size: .88rem; }
.pcfoyer  { font-size: .72rem; color: var(--mut); }
.pcst     { font-size: .73rem; margin-top: 5px; font-weight: 600; }

.pcard.yes .pcst { color: var(--grn); }
.pcard.no  .pcst { color: var(--red); }

/* ── Sub-event matrix ──────────────────────────────── */
.sematrix {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
  margin-top: 14px;
}

.sematrix th {
  background: var(--pril);
  color: var(--pri);
  padding: 9px 11px;
  text-align: center;
  font-weight: 600;
  white-space: nowrap;
}

.sematrix th.person-col {
  text-align: left;
  background: var(--bg);
  color: var(--txt);
}

.sematrix td {
  padding: 8px 11px;
  border-bottom: 1px solid var(--bdr);
  text-align: center;
}

.sematrix td.person-cell {
  text-align: left;
  font-weight: 500;
}

.sematrix tr:last-child td  { border-bottom: none; }
.sematrix tr:hover td       { background: rgba(124, 58, 237, .03); }

.ck {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--pri);
}

/* ── Prefs table ───────────────────────────────────── */
.ptbl {
  width: 100%;
  border-collapse: collapse;
  font-size: .83rem;
}

.ptbl th {
  background: var(--pril);
  color: var(--pri);
  padding: 9px 11px;
  text-align: left;
  font-weight: 600;
}

.ptbl td { padding: 9px 11px; border-bottom: 1px solid var(--bdr); }

.ptbl select,
.ptbl input {
  padding: 4px 7px;
  border: 1px solid var(--bdr);
  border-radius: 5px;
  font-size: .8rem;
  width: 100%;
  background: var(--surf);
  color: var(--txt);
}

/* ── Pair cards grid ───────────────────────────────── */
.pair-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 4px;
}

.pair-card {
  background: var(--surf);
  border: 1px solid var(--bdr);
  border-top: 3px solid var(--pri);
  border-radius: 9px;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
  box-shadow: var(--sh);
}

.pair-giver    { font-weight: 700; font-size: .9rem; color: var(--txt); }
.pair-arrow    { font-size: 1.3rem; line-height: 1; margin: 2px 0; }
.pair-receiver { font-weight: 700; font-size: .95rem; color: var(--pri); }
.pair-prefs    { font-size: .72rem; color: var(--mut); margin-top: 4px; line-height: 1.4; }
.pair-comment  { font-size: .72rem; color: var(--txt); margin-top: 4px; font-style: italic; }

.pair-sub {
  font-size: .7rem;
  background: var(--pril);
  color: var(--pri);
  border-radius: 5px;
  padding: 2px 7px;
  margin-top: 4px;
}

.mperson {
  background: var(--bg);
  border-radius: 9px;
  padding: 13px;
  margin-bottom: 8px;
  border-left: 4px solid var(--acc);
}

.mpname  { font-weight: 700; font-size: .9rem; }
.mpprefs { font-size: .81rem; color: var(--mut); margin: 5px 0; }
.mpfrom  { font-size: .78rem; color: var(--pri); }

/* ── Sub-event section ─────────────────────────────── */
.se-section {
  border: 1px solid var(--bdr);
  border-radius: 9px;
  padding: 14px;
  margin-bottom: 14px;
  background: var(--bg);
}

.se-section .ctitle { font-size: .86rem; margin-bottom: 10px; }

.se-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--bdr);
  font-size: .85rem;
}

.se-item:last-child { border-bottom: none; }

/* ── Toggle switch ─────────────────────────────────── */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  font-size: .85rem;
}

.toggle {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.tslider {
  position: absolute;
  inset: 0;
  background: #ccc;
  border-radius: 11px;
  cursor: pointer;
  transition: .2s;
}

.tslider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: .2s;
}

input:checked + .tslider               { background: var(--pri); }
input:checked + .tslider::before       { transform: translateX(18px); }

/* ── Alerts ────────────────────────────────────────── */
.al {
  padding: 11px 14px;
  border-radius: 7px;
  font-size: .83rem;
  margin-bottom: 11px;
}

.alw { background: #fffbeb; border: 1px solid #fbbf24; color: #92400e; }
.alo { background: #ecfdf5; border: 1px solid var(--grn); color: #065f46; }
.ale { background: #fef2f2; border: 1px solid var(--red); color: #991b1b; }
.ali { background: var(--pril); border: 1px solid var(--pri); color: var(--pri); }

/* ── Empty state ───────────────────────────────────── */
.empty {
  text-align: center;
  padding: 32px;
  color: var(--mut);
  font-size: .87rem;
}

.empty .ei { font-size: 2.2rem; margin-bottom: 8px; }

/* ── Sub-event tabs ────────────────────────────────── */
.se-tabs {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.se-tab {
  padding: 5px 14px;
  border-radius: 20px;
  cursor: pointer;
  font-size: .8rem;
  font-weight: 500;
  background: var(--bg);
  border: 1px solid var(--bdr);
  color: var(--mut);
}

.se-tab.active { background: var(--pri); color: #fff; border-color: var(--pri); }

/* ── Export modal ──────────────────────────────────── */
.export-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 900;
  padding: 16px;
}

.export-modal {
  background: var(--surf);
  border-radius: var(--r);
  box-shadow: 0 8px 32px rgba(0, 0, 0, .18);
  padding: 22px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.export-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.export-title {
  font-weight: 700;
  font-size: .95rem;
}

.export-hint {
  font-size: .8rem;
  color: var(--mut);
  margin-bottom: 10px;
}

.export-ta {
  flex: 1;
  width: 100%;
  min-height: 280px;
  max-height: 50vh;
  padding: 12px;
  border: 1px solid var(--bdr);
  border-radius: 7px;
  font-family: monospace;
  font-size: .82rem;
  line-height: 1.6;
  resize: vertical;
  background: var(--bg);
  color: var(--txt);
  outline: none;
}

/* ── Foyer checkbox (création / édition occasion) ──── */
.group-check-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 7px;
  margin-bottom: 5px;
  cursor: pointer;
  font-size: .85rem;
  user-select: none;
}

.group-check-item:hover { background: var(--pril); }

.group-check-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--pri);
  cursor: pointer;
  flex-shrink: 0;
}

.group-check-name  { flex: 1; font-weight: 600; }
.group-check-count { font-size: .72rem; color: var(--mut); }

/* Label foyer dans l'onglet Présences */
.group-presence-lbl {
  font-size: .78rem;
  font-weight: 700;
  color: var(--mut);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 7px;
}

/* ── Tree (Groupe panel) ───────────────────────────── */
.tree-group {
  border: 1px solid var(--bdr);
  border-radius: 10px;
  margin-bottom: 10px;
  overflow: hidden;
  background: var(--surf);
}

.tree-group-hd {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--pril);
  border-bottom: 1px solid var(--bdr);
}

.tree-group-icon { font-size: .95rem; flex-shrink: 0; }

.tree-group-name {
  font-weight: 700;
  font-size: .9rem;
  flex: 1;
  min-width: 0;
}

.tree-group-count {
  font-size: .72rem;
  color: var(--pri);
  background: rgba(124,58,237,.1);
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  flex-shrink: 0;
}

.tree-persons { padding: 4px 12px 4px 32px; }

.tree-empty-group {
  font-size: .78rem;
  color: var(--mut);
  padding: 8px 0;
  font-style: italic;
}

.tree-person {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 0;
  border-bottom: 1px solid var(--bdr);
}

.tree-person:last-child { border-bottom: none; }

.tree-person-icon { font-size: .82rem; color: var(--mut); flex-shrink: 0; }

.tree-person-name {
  flex: 1;
  font-size: .86rem;
  font-weight: 500;
  min-width: 0;
}

/* Drag handle */
.tree-drag-handle {
  cursor: grab;
  color: var(--mut);
  font-size: 1rem;
  padding: 0 3px;
  flex-shrink: 0;
  opacity: .35;
  user-select: none;
  line-height: 1;
  touch-action: none;
}

.tree-drag-handle:hover { opacity: .75; }
.tree-drag-handle:active { cursor: grabbing; }

/* Ghost while dragging */
.tree-drag-ghost { opacity: .3 !important; }

/* Shared actions row */
.tree-actions { display: flex; gap: 2px; flex-shrink: 0; }

.tree-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 5px;
  cursor: pointer;
  font-size: .75rem;
  padding: 3px 6px;
  color: var(--mut);
  line-height: 1;
  transition: background .1s, color .1s, border-color .1s;
}

.tree-btn:hover:not(:disabled) {
  background: var(--bg);
  border-color: var(--bdr);
  color: var(--txt);
}

.tree-btn:disabled { opacity: .25; cursor: default; }

.tree-btn-del:hover:not(:disabled) {
  background: #fef2f2;
  border-color: #fca5a5;
  color: var(--red);
}

/* Inline rename input */
.tree-rename-input {
  border: 1px solid var(--pri);
  border-radius: 5px;
  padding: 2px 7px;
  font-size: .87rem;
  outline: none;
  width: 100%;
  font-weight: inherit;
  background: var(--surf);
  color: var(--txt);
}

/* Add person row */
.tree-add-person-row {
  display: flex;
  gap: 6px;
  padding: 7px 12px 8px 32px;
  border-top: 1px dashed var(--bdr);
  background: var(--bg);
}

.tree-add-person-row input {
  flex: 1;
  padding: 5px 10px;
  border: 1px solid var(--bdr);
  border-radius: 7px;
  font-size: .82rem;
  outline: none;
  background: var(--surf);
  color: var(--txt);
}

.tree-add-person-row input:focus { border-color: var(--pri); }

/* Add group row */
.tree-add-group-row {
  display: flex;
  gap: 7px;
  margin-top: 6px;
}

.tree-add-group-row input {
  flex: 1;
  padding: 8px 11px;
  border: 1px solid var(--bdr);
  border-radius: 7px;
  font-size: .85rem;
  outline: none;
  background: var(--surf);
  color: var(--txt);
}

.tree-add-group-row input:focus { border-color: var(--pri); }

/* ── Header tagline ────────────────────────────────── */
.header-tagline {
  font-size: .75rem;
  opacity: .7;
  font-weight: 400;
}

/* ── Hamburger button ──────────────────────────────── */
.sb-toggle {
  display: none;
  background: none;
  border: none;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  flex-shrink: 0;
}

/* ── Sidebar overlay ───────────────────────────────── */
.sb-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  z-index: 150;
}

.sb-overlay.show { display: block; }

/* ── Mobile layout (≤ 720px) ───────────────────────── */
@media (max-width: 720px) {
  .sb-toggle { display: block; }

  .sb {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 200;
    width: 240px;
    padding-top: 60px;
    transform: translateX(-100%);
    transition: transform .25s cubic-bezier(.4, 0, .2, 1);
    box-shadow: none;
    border-right: none;
  }

  .sb.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, .18);
  }

  .main {
    padding: 16px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }

  .header-tagline { display: none; }

  .pair-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }

  .stabs { gap: 4px; }
  .stab  { padding: 6px 10px; font-size: .8rem; }
}

/* ── iOS install banner ────────────────────────────── */
#ios-install-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 999;
  padding: 0 16px 16px;
  pointer-events: none;
  animation: ios-banner-in .35s cubic-bezier(.22,.68,0,1.2) both;
}

@keyframes ios-banner-in {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}

.ios-install-card {
  background: var(--surf);
  border: 1px solid var(--bdr);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: all;
}

.ios-install-card img { flex-shrink: 0; border-radius: 8px; }

.ios-install-text { flex: 1; min-width: 0; }
.ios-install-text strong { display: block; font-size: .9rem; margin-bottom: 2px; }
.ios-install-text span   { font-size: .78rem; color: var(--mut); line-height: 1.4; }
.ios-install-text .ios-share {
  display: inline-block;
  vertical-align: middle;
  margin: 0 2px;
}

.ios-install-dismiss {
  background: none;
  border: none;
  color: var(--mut);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px;
  flex-shrink: 0;
  line-height: 1;
}

/* arrow pointing toward the Safari bottom bar */
.ios-install-arrow {
  width: 0; height: 0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 10px solid var(--surf);
  margin: 0 auto;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,.08));
}

/* ── Update banner ─────────────────────────────────── */
#update-banner {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--pri);
  color: #fff;
  padding: 12px 18px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 6px 24px rgba(124, 58, 237, .45);
  z-index: 998;
  font-size: .88rem;
  font-weight: 500;
  white-space: nowrap;
  animation: slide-up .3s ease;
}

@keyframes slide-up {
  from { opacity: 0; transform: translateX(-50%) translateY(16px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Toast notifications ───────────────────────────── */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--surf);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0,0,0,.14);
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: .88rem;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  transition: opacity .22s, transform .22s;
  z-index: 1100;
  pointer-events: none;
  border: 1px solid var(--bdr);
}

.toast.toast-show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast-error {
  border-left: 4px solid var(--red);
  color: #991b1b;
  background: #fef2f2;
}

.toast-success {
  border-left: 4px solid var(--grn);
  color: #065f46;
  background: #ecfdf5;
}

.toast-icon { font-size: 1rem; flex-shrink: 0; }

/* ── Loading screen ────────────────────────────────── */
#loading {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  z-index: 999;
}

/* ── Shared tirage view ────────────────────────────── */
.shared-wrap  { min-height: 100vh; background: var(--bg); padding: 24px 16px; }
.shared-card  { max-width: 760px; margin: 0 auto; background: var(--surf); border-radius: 14px;
                box-shadow: var(--sh); padding: 28px; }
.shared-hd    { display: flex; align-items: center; gap: 14px; margin-bottom: 4px;
                padding-bottom: 18px; border-bottom: 1px solid var(--bdr); }
.shared-title { font-size: 1.2rem; font-weight: 800; }
.shared-sub   { font-size: .8rem; color: var(--mut); margin-top: 3px; }
.shared-footer{ margin-top: 28px; text-align: center; }
