/* Mobile first : les styles de base visent le téléphone,
   les @media (min-width) n'ajoutent que ce qui change sur grand écran. */

:root {
  color-scheme: dark;

  --bg: #0C1110;
  --surface: #151C1A;
  --surface-hover: #1E2724;
  --surface-raised: #222C29;
  --text: #E9EEEC;
  --muted: #9DABA5;
  --border: #27322E;
  --border-strong: #6E7D77;
  --primary: #34D399;
  --primary-hover: #6EE7B7;
  --primary-soft: #123229;
  --on-primary: #04221A;
  --danger: #FCA5A5;
  --danger-soft: #3A1B1B;

  --radius: 10px;
  --duration: 180ms;
  --font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

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

button {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.sprite {
  position: absolute;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.icon {
  flex: none;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Page */

.page {
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: 24px 16px calc(96px + env(safe-area-inset-bottom));
}

.header h1 {
  margin: 0 0 16px;
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

/* Onglets */

.tabs-bar {
  display: flex;
  align-items: stretch;
  gap: 8px;
  box-shadow: inset 0 -1px var(--border);
}

/* Autant de listes qu'on veut : la barre défile au doigt plutôt que d'élargir la page. */
.tabs {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: 20px;
  overflow-x: auto;
  scrollbar-width: none;
}

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

.tab {
  flex: none;
  max-width: 240px;
  overflow: hidden;
  padding: 10px 0;
  min-height: 44px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1.3;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color var(--duration);
}

.tab:focus-visible {
  outline-offset: -2px;
}

.new-list {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--primary);
  font-size: 0.9375rem;
  font-weight: 600;
}

.new-list-label {
  display: none;
}

.list-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 12px;
}

.list-form .btn-ghost {
  justify-content: center;
  margin-left: 0;
  padding-inline: 12px;
}

.tab[aria-selected="true"] {
  border-bottom-color: var(--primary);
  color: var(--text);
  font-weight: 600;
}

.panel {
  padding-top: 24px;
}

.panel:focus {
  outline: none;
}

/* Progression */

.progress {
  margin-bottom: 24px;
}

.progress-text {
  margin: 0 0 8px;
  font-size: 0.9375rem;
  font-weight: 600;
}

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--border);
}

.progress-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
  transform: translateX(-100%);
  transition: transform 240ms ease-out;
}

/* Ajout */

.add-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.field {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color var(--duration);
}

.field::placeholder {
  color: var(--muted);
  opacity: 1;
}

.field:focus {
  border-color: var(--primary);
  outline: 2px solid var(--primary);
  outline-offset: -1px;
}

.field[aria-invalid="true"] {
  border-color: var(--danger);
}

.field-error {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--danger);
  font-size: 0.875rem;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 16px;
  border: 0;
  border-radius: var(--radius);
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 700;
  white-space: nowrap;
  transition: background-color var(--duration);
}

/* Filtres */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.filters {
  display: flex;
  gap: 4px;
  width: 100%;
}

.filter {
  flex: 1;
  min-height: 44px;
  padding: 8px;
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: var(--muted);
  font-size: 0.9375rem;
  font-weight: 500;
  transition: background-color var(--duration), color var(--duration);
}

.filter[aria-pressed="true"] {
  background: var(--primary-soft);
  color: var(--primary-hover);
  font-weight: 600;
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  margin-left: auto;
  padding: 8px 4px 8px 12px;
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: var(--muted);
  font-size: 0.9375rem;
  font-weight: 500;
  transition: color var(--duration);
}

/* Liste */

.task-list {
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  list-style: none;
}

.task-list:empty {
  display: none;
}

.task {
  display: flex;
  align-items: flex-start;
  padding: 4px 4px 4px 0;
}

.task + .task {
  border-top: 1px solid var(--border);
}

.task-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-height: 44px;
  padding: 10px 4px 10px 12px;
  cursor: pointer;
}

.check {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 22px;
  height: 22px;
  margin: 1px 0 0;
  border: 2px solid var(--border-strong);
  border-radius: 6px;
  background: transparent center / 16px no-repeat;
  cursor: pointer;
  transition: background-color var(--duration), border-color var(--duration);
}

.check:checked {
  border-color: var(--primary);
  background-color: var(--primary);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2304221A' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
}

.task-text {
  min-width: 0;
  overflow-wrap: anywhere;
  transition: color var(--duration);
}

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

.icon-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: var(--muted);
  transition: background-color var(--duration), color var(--duration);
}

.icon-btn--save {
  color: var(--primary);
}

.task--editing {
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
}

.field--edit {
  flex: 1;
  min-width: 0;
}

.empty {
  margin: 0;
  padding: 32px 16px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.list-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 16px;
}

.list-actions .btn-ghost {
  margin-left: 0;
  padding-inline: 8px;
}

.storage-warning {
  margin: 16px 0 0;
  color: var(--danger);
  font-size: 0.875rem;
}

/* Annulation d'une suppression */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 4px 4px 4px 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-raised);
  color: var(--text);
  font-size: 0.9375rem;
  transform: translateX(-50%);
}

.toast-action {
  min-height: 44px;
  padding: 8px 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--primary-hover);
  font-weight: 600;
}

/* Survol : uniquement sur les appareils qui ont une souris */

@media (hover: hover) {
  .tab:hover,
  .filter:hover,
  .btn-ghost:hover {
    color: var(--text);
  }

  .btn-ghost--danger:hover {
    color: var(--danger);
  }

  .new-list:hover {
    color: var(--primary-hover);
  }

  .btn-primary:hover {
    background: var(--primary-hover);
  }

  .task-main:hover .check {
    border-color: var(--primary);
  }

  .icon-btn:hover {
    background: var(--surface-hover);
    color: var(--text);
  }

  .icon-btn--danger:hover {
    background: var(--danger-soft);
    color: var(--danger);
  }

  .toast-action:hover {
    background: var(--surface-hover);
  }
}

/* Grand téléphone et plus */

@media (min-width: 520px) {
  .page {
    padding-top: 32px;
  }

  .tabs {
    gap: 24px;
  }

  .new-list-label {
    display: inline;
  }

  .add-form {
    grid-template-columns: 1fr auto;
  }

  .list-form {
    grid-template-columns: 1fr auto auto;
  }

  .toolbar {
    margin-bottom: 12px;
  }

  .filters {
    width: auto;
  }

  .filter {
    flex: none;
    padding-inline: 12px;
  }

  .btn-ghost {
    margin-left: 0;
    padding-right: 12px;
  }

  .task {
    gap: 4px;
    padding-right: 8px;
  }

  .task-main {
    padding-left: 16px;
    padding-right: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
