/* ==========================================================================
   StatGo — Design system
   Tokens carried over from the original "Planificateur de Statuts WhatsApp"
   palette (see DOCUMENTATION-TECHNIQUE §7), refined for V2.
   No external fonts/assets: the app must keep working 100% offline.
   ========================================================================== */

:root {
  color-scheme: light;
  --bg: #FAF9F5;
  --surface: #FFFFFF;
  --surface-2: #F3F1EA;
  --ink: #1B2420;
  --ink-soft: #5C6B63;
  --ink-faint: #93A199;
  --accent: #2F9E68;
  --accent-ink: #FFFFFF;
  --accent-soft: #E4F3EA;
  --accent-strong: #22754D;
  --border: #E6E3D9;
  --danger: #C4573B;
  --danger-soft: #FBE9E2;
  --shadow: 0 1px 2px rgba(27, 36, 32, 0.04), 0 8px 24px -12px rgba(27, 36, 32, 0.18);
  --shadow-lg: 0 16px 40px -16px rgba(27, 36, 32, 0.32);
  --radius-s: 10px;
  --radius-m: 16px;
  --radius-l: 22px;
  --radius-pill: 999px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(.22, 1, .36, 1);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #12160F;
    --surface: #1B2118;
    --surface-2: #202A1E;
    --ink: #EDEFEA;
    --ink-soft: #9BAAA1;
    --ink-faint: #5E6B62;
    --accent: #4BC585;
    --accent-ink: #0D140F;
    --accent-soft: rgba(75, 197, 133, 0.14);
    --accent-strong: #6FDA9F;
    --border: rgba(237, 239, 234, 0.09);
    --danger: #E58469;
    --danger-soft: rgba(229, 132, 105, 0.14);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 8px 24px -12px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 20px 48px -18px rgba(0, 0, 0, 0.6);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12160F;
  --surface: #1B2118;
  --surface-2: #202A1E;
  --ink: #EDEFEA;
  --ink-soft: #9BAAA1;
  --ink-faint: #5E6B62;
  --accent: #4BC585;
  --accent-ink: #0D140F;
  --accent-soft: rgba(75, 197, 133, 0.14);
  --accent-strong: #6FDA9F;
  --border: rgba(237, 239, 234, 0.09);
  --danger: #E58469;
  --danger-soft: rgba(229, 132, 105, 0.14);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 8px 24px -12px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 20px 48px -18px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }

html {
  height: 100%;
  scroll-padding-top: var(--safe-t);
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  padding-top: var(--safe-t);
  padding-bottom: var(--safe-b);
  transition: background .25s var(--ease), color .25s var(--ease);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font-family: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: var(--safe-t);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 20px 8px;
  background: var(--bg);
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--ink);
  display: grid; place-items: center;
  flex-shrink: 0;
}
.brand-mark svg { width: 20px; height: 20px; }

.brand-name {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
}
.brand-name span { color: var(--accent); }

.topbar-actions { display: flex; align-items: center; gap: 6px; }

.icon-btn {
  width: 38px; height: 38px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  display: grid; place-items: center;
  color: var(--ink-soft);
  transition: transform .15s var(--ease), background .15s var(--ease), color .15s var(--ease);
}
.icon-btn:active { transform: scale(0.92); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.is-on { background: var(--accent-soft); color: var(--accent-strong); border-color: transparent; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  margin: 6px 20px 14px;
  background: var(--surface-2);
  border-radius: var(--radius-pill);
}
.tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 9px 8px;
  border-radius: var(--radius-pill);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-soft);
  transition: background .2s var(--ease), color .2s var(--ease), box-shadow .2s var(--ease);
}
.tab.is-active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- Main / sections ---------- */
main { flex: 1; padding: 0 20px 100px; }
.view { display: none; animation: fadeIn .25s var(--ease); }
.view.is-active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.subtitle { color: var(--ink-soft); font-size: 14px; margin: 0 0 16px; line-height: 1.5; }

/* ---------- Due banner ---------- */
.due-banner {
  display: none;
  align-items: center;
  gap: 10px;
  background: var(--ink);
  color: var(--bg);
  border-radius: var(--radius-m);
  padding: 13px 16px;
  margin-bottom: 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  animation: pop .3s var(--ease);
}
.due-banner.is-visible { display: flex; }
.due-banner .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex-shrink: 0; animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes pop { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }

/* ---------- Section label ---------- */
.section-label {
  font-size: 13px;
  font-weight: 650;
  color: var(--ink-soft);
  margin: 22px 0 10px;
}
.section-label:first-child { margin-top: 0; }

/* ---------- Cards ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  padding: 14px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  transition: border-color .2s var(--ease), transform .15s var(--ease), box-shadow .2s var(--ease);
}
.card:active { transform: scale(0.99); }
.card.is-due { border-color: transparent; background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.card.is-history { opacity: .8; }

.card-thumb {
  width: 46px; height: 46px; border-radius: 12px; flex-shrink: 0;
  background: var(--surface-2);
  object-fit: cover;
  display: grid; place-items: center; color: var(--ink-faint);
}
.card-thumb svg { width: 18px; height: 18px; }

.card-body { flex: 1; min-width: 0; }
.card-text {
  font-size: 14.5px; line-height: 1.45; margin: 0 0 6px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  word-break: break-word;
}
.card-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-soft); }
.card-meta .sep { opacity: .5; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: var(--radius-pill);
  background: var(--surface-2); color: var(--ink-soft); font-size: 11.5px; font-weight: 600;
}
.chip.chip-accent { background: var(--accent-soft); color: var(--accent-strong); }
.chip svg { width: 11px; height: 11px; }

.card-actions { display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; }
.card-go {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); border: none;
  display: grid; place-items: center;
  transition: transform .15s var(--ease);
}
.card-go:active { transform: scale(.9); }
.card-go svg { width: 16px; height: 16px; }
.card-more { width: 36px; height: 36px; border-radius: 50%; border: none; background: transparent; color: var(--ink-faint); display: grid; place-items: center; }
.card-more svg { width: 18px; height: 18px; }

/* ---------- Empty state ---------- */
.empty {
  text-align: center;
  padding: 56px 20px;
  color: var(--ink-soft);
}
.empty-ring {
  width: 64px; height: 64px; margin: 0 auto 16px;
  border-radius: 50%; border: 2.5px dashed var(--border);
  display: grid; place-items: center; color: var(--ink-faint);
}
.empty-ring svg { width: 26px; height: 26px; }
.empty h3 { margin: 0 0 6px; font-size: 15.5px; color: var(--ink); }
.empty p { margin: 0; font-size: 13.5px; line-height: 1.5; max-width: 260px; margin-inline: auto; }

/* ---------- Template chips (grid) ---------- */
.template-grid { display: flex; flex-direction: column; gap: 10px; }
.template-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-m);
  padding: 14px; display: flex; gap: 12px; align-items: center;
}
.template-icon { width: 40px; height: 40px; border-radius: 11px; background: var(--accent-soft); color: var(--accent-strong); display: grid; place-items: center; flex-shrink: 0; }
.template-icon svg { width: 18px; height: 18px; }
.template-name { font-weight: 650; font-size: 14.5px; margin: 0 0 3px; }
.template-text { font-size: 13px; color: var(--ink-soft); margin: 0; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.template-use { border: 1px solid var(--border); background: var(--surface); color: var(--ink); font-size: 12.5px; font-weight: 600; padding: 8px 12px; border-radius: var(--radius-pill); flex-shrink: 0; }

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  right: max(20px, calc((100% - 480px) / 2 + 20px));
  bottom: calc(24px + var(--safe-b));
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); border: none;
  display: grid; place-items: center;
  box-shadow: var(--shadow-lg);
  z-index: 30;
  transition: transform .18s var(--ease);
}
.fab:active { transform: scale(.92); }
.fab svg { width: 24px; height: 24px; }

/* ---------- Overlay & bottom sheet ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(10, 14, 10, 0.44);
  backdrop-filter: blur(2px);
  opacity: 0; pointer-events: none; transition: opacity .25s var(--ease);
  z-index: 40;
  display: flex; align-items: flex-end; justify-content: center;
}
.overlay.is-open { opacity: 1; pointer-events: auto; }

.sheet {
  width: 100%; max-width: 480px;
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  padding: 8px 20px calc(22px + var(--safe-b));
  max-height: 88dvh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform .32s var(--ease);
  box-shadow: var(--shadow-lg);
}
.overlay.is-open .sheet { transform: translateY(0); }
.sheet-handle { width: 36px; height: 4px; border-radius: var(--radius-pill); background: var(--border); margin: 8px auto 14px; }
.sheet-title { font-size: 17px; font-weight: 700; margin: 0 0 18px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 650; color: var(--ink-soft); margin-bottom: 7px; }
.field textarea, .field input[type="text"], .field input[type="datetime-local"], .field select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--radius-s);
  padding: 12px 13px;
  font-size: 14.5px;
  color: var(--ink);
  resize: none;
  transition: border-color .15s var(--ease), background .15s var(--ease);
}
.field textarea:focus, .field input:focus, .field select:focus { border-color: var(--accent); background: var(--surface); }
.field textarea { min-height: 84px; line-height: 1.5; }
.field-hint { font-size: 12px; color: var(--ink-faint); margin-top: 6px; }

.seg { display: flex; gap: 6px; background: var(--surface-2); border-radius: var(--radius-pill); padding: 3px; }
.seg button {
  flex: 1; border: none; background: transparent; padding: 8px 6px;
  border-radius: var(--radius-pill); font-size: 13px; font-weight: 600; color: var(--ink-soft);
  transition: background .18s var(--ease), color .18s var(--ease);
}
.seg button.is-active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.chip-row { display: flex; gap: 7px; flex-wrap: wrap; }
.chip-toggle {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink-soft);
  font-size: 12.5px; font-weight: 600; padding: 7px 12px; border-radius: var(--radius-pill);
  transition: all .15s var(--ease);
}
.chip-toggle.is-active { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.day-row { display: flex; gap: 6px; }
.day-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink-soft); font-size: 12.5px; font-weight: 650;
}
.day-btn.is-active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.image-drop {
  border: 1.5px dashed var(--border); border-radius: var(--radius-m);
  padding: 16px; display: flex; align-items: center; gap: 12px; cursor: pointer;
  color: var(--ink-soft); font-size: 13.5px;
}
.image-drop svg { width: 20px; height: 20px; flex-shrink: 0; }
.image-preview-wrap { position: relative; }
.image-preview { width: 100%; max-height: 160px; object-fit: cover; border-radius: var(--radius-m); display: block; }
.image-remove {
  position: absolute; top: 8px; right: 8px; width: 28px; height: 28px; border-radius: 50%;
  background: rgba(0,0,0,.55); color: #fff; border: none; display: grid; place-items: center;
}
.image-remove svg { width: 14px; height: 14px; }

.sheet-actions { display: flex; gap: 10px; margin-top: 6px; }
.btn {
  flex: 1; border: none; border-radius: var(--radius-s); padding: 13px 16px;
  font-size: 14.5px; font-weight: 650; transition: transform .15s var(--ease), opacity .15s var(--ease);
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: var(--surface-2); color: var(--ink); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }

/* ---------- Action sheet (card menu) ---------- */
.action-sheet .sheet { padding-bottom: calc(14px + var(--safe-b)); }
.action-sheet .sheet-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.action-list { display: flex; flex-direction: column; }
.action-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 4px; border: none; background: transparent; color: var(--ink);
  font-size: 14.5px; font-weight: 600; text-align: left; border-bottom: 1px solid var(--border);
}
.action-item:last-child { border-bottom: none; }
.action-item svg { width: 18px; height: 18px; color: var(--ink-soft); flex-shrink: 0; }
.action-item.is-danger { color: var(--danger); }
.action-item.is-danger svg { color: var(--danger); }

/* ---------- Settings ---------- */
.settings-group { margin-bottom: 22px; }
.settings-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-m);
  padding: 14px; margin-bottom: 8px;
}
.settings-row + .settings-row { margin-top: 0; }
.settings-row-text { min-width: 0; }
.settings-row-title { font-size: 14px; font-weight: 650; margin: 0 0 2px; }
.settings-row-sub { font-size: 12.5px; color: var(--ink-soft); margin: 0; line-height: 1.4; }

.theme-seg { display: flex; gap: 6px; background: var(--surface-2); border-radius: var(--radius-pill); padding: 3px; width: 100%; }
.theme-seg button { flex: 1; border: none; background: transparent; padding: 9px 4px; border-radius: var(--radius-pill); font-size: 12.5px; font-weight: 650; color: var(--ink-soft); display: flex; flex-direction: column; align-items: center; gap: 4px; }
.theme-seg button.is-active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.theme-seg svg { width: 15px; height: 15px; }

.switch { position: relative; width: 44px; height: 26px; border-radius: var(--radius-pill); background: var(--surface-2); border: 1px solid var(--border); flex-shrink: 0; transition: background .2s var(--ease); }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: var(--surface); box-shadow: var(--shadow); transition: transform .2s var(--ease); }
.switch.is-on { background: var(--accent); border-color: var(--accent); }
.switch.is-on::after { transform: translateX(18px); background: #fff; }

.about-block { text-align: center; padding: 18px 0 6px; color: var(--ink-faint); font-size: 12px; line-height: 1.6; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b));
  transform: translate(-50%, 16px);
  background: var(--ink); color: var(--bg);
  padding: 12px 14px 12px 16px; border-radius: var(--radius-pill);
  display: flex; align-items: center; gap: 12px;
  font-size: 13.5px; font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none; transition: opacity .25s var(--ease), transform .25s var(--ease);
  z-index: 60;
  max-width: calc(100% - 40px);
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { border: none; background: transparent; color: var(--accent-strong); font-weight: 700; font-size: 13px; flex-shrink: 0; }

/* ---------- Install banner ---------- */
.install-banner {
  display: none; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-m);
  padding: 13px 14px; margin: 0 0 16px;
  box-shadow: var(--shadow);
}
.install-banner.is-visible { display: flex; }
.install-banner-icon { width: 38px; height: 38px; border-radius: 11px; background: var(--ink); display: grid; place-items: center; flex-shrink: 0; }
.install-banner-icon svg { width: 20px; height: 20px; }
.install-banner-text { flex: 1; min-width: 0; }
.install-banner-text strong { display: block; font-size: 13.5px; }
.install-banner-text span { font-size: 12px; color: var(--ink-soft); }
.install-banner button.btn { flex: none; padding: 9px 14px; font-size: 13px; }
.install-banner-close { border: none; background: transparent; color: var(--ink-faint); width: 28px; height: 28px; display: grid; place-items: center; flex-shrink: 0; }
.install-banner-close svg { width: 15px; height: 15px; }

/* ---------- Utility ---------- */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
::selection { background: var(--accent-soft); color: var(--accent-strong); }
