:root {
  /* Thème Sombre adouci (moins foncé que le noir profond) */
  --bg-primary: #1e2430;
  --bg-card: #2a3342;
  --bg-card-hover: #353f52;
  --header-bg: rgba(30, 36, 48, 0.92);
  --modal-bg: rgba(30, 36, 48, 0.95);
  --input-bg: rgba(22, 27, 36, 0.85);
  --tag-bg: rgba(255, 255, 255, 0.09);
  --accent: #10b981;
  --accent-hover: #059669;
  --accent-light: rgba(16, 185, 129, 0.15);
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #3b4557;
  --danger: #ef4444;
  --danger-light: rgba(239, 68, 68, 0.15);
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.28);
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Thème Clair adouci (pas trop clair, tons gris/ardoise doux) */
[data-theme="light"] {
  --bg-primary: #e9edf2;
  --bg-card: #ffffff;
  --bg-card-hover: #f4f6f9;
  --header-bg: rgba(233, 237, 242, 0.93);
  --modal-bg: rgba(233, 237, 242, 0.97);
  --input-bg: #f8fafc;
  --tag-bg: rgba(0, 0, 0, 0.06);
  --accent: #059669;
  --accent-hover: #047857;
  --accent-light: rgba(5, 150, 105, 0.15);
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border: #cbd5e1;
  --danger: #e11d48;
  --danger-light: rgba(225, 29, 72, 0.12);
  --shadow: 0 4px 16px rgba(100, 116, 139, 0.12);
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-main);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  touch-action: manipulation;
  overflow-x: hidden;
}

/* App Container */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
  padding-bottom: env(safe-area-inset-bottom, 20px);
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background-color: var(--header-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px 16px;
  transition: background-color 0.25s, border-color 0.25s;
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-logo {
  font-size: 28px;
  line-height: 1;
}

.app-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #f59e0b; /* Yellow by default */
  transition: background-color 0.3s;
}

.status-dot.online {
  background-color: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

.status-dot.offline {
  background-color: var(--danger);
}

.icon-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-main);
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  transition: transform 0.2s, background-color 0.2s, border-color 0.2s, color 0.2s;
}

.icon-btn:active {
  transform: scale(0.92);
  background: var(--bg-card-hover);
}

/* Lists Horizontal Navigation Tabs */
.lists-nav-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px 4px 16px;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.lists-nav-wrapper::-webkit-scrollbar {
  display: none;
}

.lists-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.list-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 30px;
  cursor: pointer;
  transition: transform 0.2s, background-color 0.2s, border-color 0.2s, color 0.2s, box-shadow 0.2s;
  user-select: none;
  font-family: inherit;
}

.list-pill:hover {
  background-color: var(--bg-card-hover);
  color: var(--text-main);
}

.list-pill.active {
  background-color: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  box-shadow: 0 2px 10px rgba(16, 185, 129, 0.35);
}

.list-pill-badge {
  font-size: 11px;
  background-color: rgba(255, 255, 255, 0.2);
  padding: 1px 6px;
  border-radius: 12px;
  font-weight: 600;
}

.list-pill:not(.active) .list-pill-badge {
  background-color: var(--tag-bg);
  color: var(--text-muted);
}

.add-list-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: 30px;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  transition: background-color 0.2s, border-color 0.2s, color 0.2s, transform 0.2s, opacity 0.2s;
}

.add-list-pill-btn:hover,
.add-list-pill-btn:active {
  border-color: var(--accent);
  color: var(--accent);
}

/* Modal Backdrop & Sheet */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 95;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

@media (min-width: 640px) {
  .modal-backdrop {
    align-items: center;
    padding: 20px;
  }
}

.modal-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-sheet {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  width: 100%;
  max-width: 500px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom, 0px)) 20px;
  box-shadow: var(--shadow);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  overflow-y: auto;
}

@media (min-width: 640px) {
  .modal-sheet {
    border-radius: 24px;
    transform: scale(0.95);
  }
}

.modal-backdrop.active .modal-sheet {
  transform: translateY(0);
}

@media (min-width: 640px) {
  .modal-backdrop.active .modal-sheet {
    transform: scale(1);
  }
}

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

.modal-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
}

.close-modal-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
}

.modal-section {
  margin-bottom: 16px;
}

.modal-section.border-top {
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.modal-subtitle {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.modal-lists {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
}

.modal-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.modal-list-item:hover {
  background-color: var(--bg-card-hover);
}

.modal-list-item.active {
  border-color: var(--accent);
}

.modal-list-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-list-emoji {
  font-size: 20px;
}

.modal-list-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
}

.modal-list-counts {
  font-size: 12px;
  color: var(--text-muted);
}

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

.delete-list-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: color 0.2s;
}

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

/* Emoji Selector */
.emoji-selector {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 12px;
  scrollbar-width: none;
}

.emoji-selector::-webkit-scrollbar {
  display: none;
}

.emoji-option {
  font-size: 20px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 0.2s, border-color 0.2s, color 0.2s, transform 0.2s, opacity 0.2s;
}

.emoji-option.selected {
  border-color: var(--accent);
  background: var(--accent-light);
  transform: scale(1.1);
}

.create-list-inputs {
  display: flex;
  gap: 8px;
}

.new-list-input {
  flex: 1;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 16px;
  padding: 10px 14px;
  outline: none;
  font-family: inherit;
}

.new-list-input:focus {
  border-color: var(--accent);
}

.create-list-btn {
  background-color: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

/* Main Content */
.main-content {
  flex: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Add Item Form */
.add-form {
  position: relative;
}

.input-group {
  display: flex;
  gap: 8px;
  background-color: var(--bg-card);
  padding: 6px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  transition: border-color 0.2s;
}

.input-group:focus-within {
  border-color: var(--accent);
}

.input-name {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  font-size: 16px;
  padding: 10px 12px;
  font-family: inherit;
  min-width: 0;
}

.input-qty {
  width: 90px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  color: var(--text-main);
  font-size: 16px;
  padding: 8px 10px;
  font-family: inherit;
  text-align: center;
}

.input-name::placeholder,
.input-qty::placeholder {
  color: var(--text-muted);
}

.add-btn {
  background-color: var(--accent);
  color: white;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
  flex-shrink: 0;
}

.add-btn:active {
  transform: scale(0.92);
  background-color: var(--accent-hover);
}

/* Stats Bar */
.stats-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--text-muted);
  padding: 0 4px;
}

.text-btn {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background-color 0.2s;
}

.text-btn:active {
  background-color: var(--danger-light);
}

/* Lists */
.items-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.item-card {
  display: flex;
  align-items: center;
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 4px;
  gap: 4px;
  transition: background-color 0.25s, border-color 0.25s, opacity 0.25s;
  user-select: none;
}

.item-card:active {
  background-color: var(--bg-card-hover);
}

.checkbox-custom {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 2px solid var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 0.2s, border-color 0.2s, transform 0.2s;
  background: transparent;
}

.checkbox-custom svg {
  display: none;
  stroke: white;
  stroke-width: 3;
}

.item-card.completed .checkbox-custom {
  background-color: var(--accent);
  border-color: var(--accent);
}

.item-card.completed .checkbox-custom svg {
  display: block;
}

.item-content {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  min-width: 0;
}

.item-name {
  font-size: 16px;
  font-weight: 500;
  word-break: break-word;
  color: var(--text-main);
  transition: color 0.2s, text-decoration 0.2s;
}

.item-qty-tag {
  font-size: 12px;
  background-color: var(--tag-bg);
  color: var(--text-muted);
  padding: 2px 8px;
  border-radius: 20px;
  white-space: nowrap;
}

.item-card.completed .item-name {
  text-decoration: line-through;
  color: var(--text-muted);
}

.item-card.completed {
  opacity: 0.65;
  background-color: rgba(30, 41, 59, 0.5);
}

.delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, background-color 0.2s;
}

.delete-btn:hover,
.delete-btn:active {
  color: var(--danger);
  background-color: var(--danger-light);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.empty-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 4px;
}

.empty-subtitle {
  font-size: 14px;
}

/* Completed Section */
.completed-section {
  margin-top: 10px;
  border-top: 1px dashed var(--border);
  padding-top: 16px;
}

.completed-header {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 8px 0;
  margin-bottom: 8px;
  font-family: inherit;
}

.completed-arrow {
  font-size: 10px;
  transition: transform 0.2s;
}

.completed-section.collapsed .completed-arrow {
  transform: rotate(-90deg);
}

.completed-section.collapsed .completed-items {
  display: none;
}

/* PIN Modal */
.pin-modal {
  position: fixed;
  inset: 0;
  background-color: var(--modal-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.pin-modal.active {
  opacity: 1;
  pointer-events: auto;
}

.pin-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 32px 24px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: var(--shadow);
}

.pin-icon {
  font-size: 44px;
  margin-bottom: 12px;
}

.pin-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
}

.pin-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 24px;
  line-height: 1.4;
}

.pin-input {
  width: 100%;
  background: var(--input-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-main);
  font-size: 22px;
  letter-spacing: 5px;
  text-align: center;
  padding: 12px 8px;
  outline: none;
  margin-bottom: 12px;
  font-family: inherit;
  transition: border-color 0.2s;
}

.pin-input:focus {
  border-color: var(--accent);
}

.pin-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 20px;
  margin-bottom: 16px;
}

.pin-submit-btn {
  width: 100%;
  background-color: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
}

.pin-submit-btn:active {
  transform: scale(0.98);
  background-color: var(--accent-hover);
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 12px 20px;
  border-radius: 30px;
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 90;
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  pointer-events: none;
}

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


/* ---- Ajouts d'optimisation ---- */

[hidden] {
  display: none !important;
}

/* Meilleure navigation clavier / accessibilité */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Respect du réglage système "réduire les animations" */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Modification d'une liste */
.edit-list-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s;
}

.edit-list-btn:active {
  background-color: var(--tag-bg);
  color: var(--text-main);
}

.cancel-edit-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
}

.modal-list-item.editing {
  border-color: var(--accent);
}

.create-list-inputs {
  flex-wrap: wrap;
}

.cancel-edit-btn {
  flex: 1 1 100%;
  padding: 12px 14px;
}

.create-list-inputs .new-list-input {
  flex: 1 1 0;
  min-width: 0;
}

.create-list-inputs .create-list-btn {
  flex: 0 0 auto;
}

/* Réorganisation des articles */
.drag-handle {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 8px 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  touch-action: none; /* le doigt déplace l'article au lieu de faire défiler la page */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  opacity: 0.75;
}

.drag-handle:active,
.drag-handle:hover {
  opacity: 1;
  color: var(--text-main);
}

.items-list.is-sorting {
  cursor: grabbing;
}

.items-list.is-sorting .item-card:not(.dragging) {
  pointer-events: none;
}

.item-card.dragging {
  position: relative;
  z-index: 20;
  transition: none;
  border-color: var(--accent);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  opacity: 0.97;
}
