/* To-Do List — application mobile (PWA). Mêmes couleurs que l'extension ; conçue d'abord pour iPhone. */

@font-face {
  font-family: 'DM Sans';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url(fonts/dm-sans/dm-sans-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'DM Sans';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url(fonts/dm-sans/dm-sans-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --bg: #0f0f12;
  --bg-2: #18181c;
  --card: #1e1e24;
  --hover: #25252d;
  --text: #f4f4f5;
  --text-2: #a1a1aa;
  --muted: #71717a;
  --accent: #6366f1;
  --accent-muted: rgba(99, 102, 241, 0.2);
  --danger: #ef4444;
  --danger-muted: rgba(239, 68, 68, 0.15);
  --success: #22c55e;
  --border: #27272a;
  --radius: 14px;
  --radius-sm: 10px;
  --nav-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --p-critical: #ef4444;
  --p-high: #f97316;
  --p-medium: #eab308;
  --p-normal: #3b82f6;
  --p-low: #22c55e;
  --p-none: #71717a;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #fafafa;
  --bg-2: #f4f4f5;
  --card: #ffffff;
  --hover: #f4f4f5;
  --text: #18181b;
  --text-2: #52525b;
  --muted: #a1a1aa;
  --accent: #4f46e5;
  --accent-muted: rgba(79, 70, 229, 0.12);
  --danger: #dc2626;
  --danger-muted: rgba(220, 38, 38, 0.1);
  --border: #e4e4e7;
  color-scheme: light;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', -apple-system, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

/* 16 px minimum : iOS ne zoome pas sur les champs */
input,
select,
textarea {
  font-size: 16px;
  width: 100%;
  padding: 0.7rem 0.8rem;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
}

textarea {
  min-height: 96px;
  resize: vertical;
}

[hidden] {
  display: none !important;
}

.app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100vh;
  padding: calc(var(--safe-t) + 12px) 16px calc(var(--nav-h) + var(--safe-b) + 88px);
}

/* ---------- En-tête ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.topbar h1 {
  font-size: 1.6rem;
  margin: 0;
}

.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 0.8rem;
  color: var(--text-2);
  cursor: pointer;
}

.sync-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.sync-pill[data-state="ok"] .dot {
  background: var(--success);
}

.sync-pill[data-state="syncing"] .dot {
  background: var(--accent);
  animation: pulse 1s infinite alternate;
}

.sync-pill[data-state="error"] .dot {
  background: var(--danger);
}

@keyframes pulse {
  to {
    opacity: 0.3;
  }
}

/* ---------- Boutons ---------- */

.btn {
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
  font-weight: 600;
  cursor: pointer;
}

.btn:disabled {
  opacity: 0.6;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-danger {
  color: var(--danger);
  background: var(--danger-muted);
  border-color: transparent;
}

.btn-block {
  width: 100%;
}

.row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.row>* {
  flex: 1;
}

/* ---------- Dossiers, filtres, recherche ---------- */

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin: 0 -16px 10px;
  padding-left: 16px;
  padding-right: 16px;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: none;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text-2);
  font-size: 0.9rem;
  cursor: pointer;
}

.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--bg-2);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-bottom: 10px;
}

.segmented button {
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  font-size: 0.85rem;
  cursor: pointer;
}

.segmented button.active {
  background: var(--card);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.search {
  margin-bottom: 12px;
}

/* ---------- Liste des tâches ---------- */

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.task {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.check {
  flex: none;
  width: 28px;
  height: 28px;
  margin-top: 1px;
  border-radius: 50%;
  border: 2px solid var(--muted);
  background: transparent;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: transparent;
  font-size: 15px;
  font-weight: 700;
}

.task[data-priority="critical"] .check {
  border-color: var(--p-critical);
}

.task[data-priority="high"] .check {
  border-color: var(--p-high);
}

.task[data-priority="medium"] .check {
  border-color: var(--p-medium);
}

.task[data-priority="normal"] .check {
  border-color: var(--p-normal);
}

.task[data-priority="low"] .check {
  border-color: var(--p-low);
}

.task.done .check {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

.task-body {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.task-title {
  word-break: break-word;
}

.task.done .task-title {
  text-decoration: line-through;
  color: var(--muted);
}

.tag {
  color: var(--accent);
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-top: 4px;
  font-size: 0.8rem;
  color: var(--text-2);
}

.meta .overdue {
  color: var(--danger);
  font-weight: 600;
}

.trash-actions {
  display: flex;
  gap: 6px;
}

.trash-actions .btn {
  min-height: 36px;
  padding: 0 10px;
  font-size: 0.85rem;
}

.empty {
  text-align: center;
  color: var(--text-2);
  padding: 48px 16px;
}

.group-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 18px 4px 8px;
}

.group-title.overdue {
  color: var(--danger);
}

/* ---------- Bouton d'ajout et navigation ---------- */

.fab {
  position: fixed;
  right: max(16px, calc(50% - 304px));
  bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-size: 30px;
  line-height: 1;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}

.nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--card);
  border-top: 1px solid var(--border);
}

.nav button {
  border: 0;
  background: transparent;
  color: var(--text-2);
  font-size: 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
}

.nav button .icon {
  font-size: 20px;
}

.nav button.active {
  color: var(--accent);
  font-weight: 600;
}

/* ---------- Feuille (ajout / modification) ---------- */

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 10;
}

.sheet {
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(16px + var(--safe-b));
  animation: up 0.2s ease-out;
}

@keyframes up {
  from {
    transform: translateY(30px);
    opacity: 0;
  }
}

.sheet h2 {
  font-size: 1.15rem;
  margin: 0 0 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.field>span {
  font-size: 0.8rem;
  color: var(--text-2);
  font-weight: 600;
}

.note-preview {
  padding: 0.6rem 0.8rem;
  background: var(--bg-2);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}

.note-preview a {
  color: var(--accent);
}

.subtask {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.subtask input[type="checkbox"] {
  width: 22px;
  height: 22px;
  flex: none;
  accent-color: var(--accent);
}

.subtask .icon-btn {
  flex: none;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 0;
  background: transparent;
  color: var(--text-2);
  font-size: 20px;
  cursor: pointer;
}

/* ---------- Écrans de connexion et réglages ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.card h2 {
  font-size: 1rem;
  margin: 0 0 10px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hint {
  font-size: 0.85rem;
  color: var(--text-2);
  margin: 0;
}

.error {
  color: var(--danger);
  font-size: 0.9rem;
  min-height: 1.2em;
  margin: 0;
}

details summary {
  cursor: pointer;
  color: var(--text-2);
  min-height: 32px;
  display: flex;
  align-items: center;
}

.recovery-code {
  font-family: ui-monospace, monospace;
  font-size: 1rem;
  background: var(--bg-2);
  padding: 12px;
  border-radius: var(--radius-sm);
  word-break: break-all;
  user-select: all;
  -webkit-user-select: all;
}

.devices {
  list-style: none;
  margin: 0;
  padding: 0;
}

.devices li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 44px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--nav-h) + var(--safe-b) + 88px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.9rem;
  z-index: 20;
  max-width: calc(100% - 32px);
}
