/* Thème sombre minimaliste : fond uni, surfaces plates, mouvements doux */
:root {
  --bg: #0a0a0b;
  --surface: #131316;
  --surface-hi: #1b1b1f;
  --border: #232328;
  --sep: #26262c; /* séparateur entre deux lignes : discret mais visible */
  --text: #ececef;
  --muted: #74747c;
  --danger: #f08a8a;
  --radius: 14px;
  --col: 3.4rem; /* colonne quantité / icône, partagée par toutes les listes */
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  padding-bottom: 110px;
  -webkit-font-smoothing: antialiased;
}

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

[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- En-tête et recherche ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: calc(18px + env(safe-area-inset-top)) 16px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  animation: fadeDown 0.5s var(--ease) both;
}

.search {
  position: relative;
  display: block;
}

.search svg {
  position: absolute;
  left: 14px;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
  transition: color 0.25s var(--ease);
}

.search:focus-within svg { color: var(--text); }

#search,
.field input,
.field select {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  /* 16px minimum : évite le zoom automatique sur iPhone */
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s var(--ease);
}

#search {
  padding-left: 42px;
}

#search::placeholder,
.field input::placeholder {
  color: var(--muted);
}

#search:focus,
.field input:focus,
.field select:focus {
  border-color: #3a3a41;
}

/* ---------- Contenu ---------- */

main {
  padding: 16px 16px 0;
  max-width: 720px;
  margin: 0 auto;
}

.status {
  padding: 12px 14px;
  border-radius: var(--radius);
  background: rgba(240, 138, 138, 0.08);
  color: var(--danger);
  font-size: 12.5px;
  animation: fadeUp 0.4s var(--ease) both;
}

.count {
  margin: 2px 2px 14px;
  color: var(--muted);
  font-size: 11.5px;
  animation: fadeUp 0.35s var(--ease) both;
}

.results,
.containers {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
}

.results {
  gap: 0;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.results:empty {
  display: none;
}

.result,
.container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease);
}

.result {
  display: grid;
  grid-template-columns: var(--col) 1fr auto;
  align-items: center;
  padding: 13px 16px;
  animation: rise 0.45s var(--ease) both;
  animation-delay: calc(var(--i, 0) * 40ms);
}

.result {
  border: none;
  border-radius: 0;
  background: transparent;
}

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

.result:active,
.container summary:active { background: var(--surface-hi); }

.item-name {
  grid-column: 2;
  grid-row: 1;
  font-weight: 500;
  line-height: 1.35;
}

.location {
  grid-column: 2;
  grid-row: 2;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.loc-icon {
  grid-column: 1;
  grid-row: 2;
  justify-self: center;
  margin-top: 4px;
  width: 16px;
  height: 16px;
  color: var(--muted);
}

.loc-thumb {
  display: block;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  border-radius: 5px;
  overflow: hidden;
  background: var(--surface-hi);
  cursor: pointer;
}

.loc-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.loc-icon svg,
.summary-icon svg {
  display: block;
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.summary-icon {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  color: var(--muted);
}

/* Quantité : chiffre gras dans une colonne fixe, pour que les noms restent alignés */
.qty {
  grid-column: 1;
  grid-row: 1;
  justify-self: center;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* ---------- Photos ---------- */

.media {
  grid-column: 3;
  align-self: center;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.2s var(--ease), transform 0.2s var(--ease);
}

.result .media { grid-row: 1 / span 2; }

/* Quantité et nom partagent la même hauteur de ligne : ils restent alignés sur la première ligne */
.qty,
.item-name {
  line-height: 1.35;
}



.media:hover { color: var(--text); }

/* Photo du contenant : poussée à droite, exactement comme la photo des objets */
.container summary .media {
  margin-left: auto;
}

.summary-name {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.photo-pick {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 52px;
  margin: 2px 0 14px;
  padding: 0 14px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.2s var(--ease), color 0.2s var(--ease);
}

.photo-pick:hover { border-color: #3a3a41; color: var(--text); }

.photo-pick svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.photo-pick .photo-preview {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}
.media:active { transform: scale(0.94); }

.media svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.media.thumb {
  overflow: hidden;
  background: var(--surface-hi);
}

.media.thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.detail-dialog {
  width: min(92vw, 420px);
  padding: 14px;
}

.detail-dialog img {
  display: block;
  width: 100%;
  max-height: 62vh;
  object-fit: contain;
  border-radius: 12px;
  background: var(--bg);
  margin-bottom: 12px;
}

/* ---------- Fiche, suppression et lignes cliquables ---------- */

.tappable { cursor: pointer; }

.detail-title {
  margin: 4px 4px 2px;
  font-size: 15px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.detail-sub {
  margin: 0 4px 14px;
  color: var(--muted);
  font-size: 12px;
}

.detail-actions .spacer {
  flex: 1;
}

.detail-actions {
  align-items: center;
  margin-top: 14px;
}

.confirm-dialog {
  width: min(92vw, 380px);
  padding: 20px;
}

.confirm-text {
  margin: 4px 2px 18px;
  font-size: 13px;
  line-height: 1.5;
}

.actions button.danger {
  background: var(--danger);
  color: #1a0b0b;
}

.actions button.danger-text {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(240, 138, 138, 0.3);
  font-weight: 500;
}

.link-btn {
  display: block;
  width: 100%;
  padding: 10px 16px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}

.link-btn:hover { color: var(--text); }

.container-footer {
  border-top: 1px solid var(--sep);
}

/* ---------- Contenants (liste dépliable) ---------- */

.container {
  animation: rise 0.45s var(--ease) both;
  animation-delay: calc(var(--i, 0) * 40ms);
}

.container summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 14px 16px;
  cursor: pointer;
  list-style: none;
  font-weight: 500;
  user-select: none;
}

.container summary::-webkit-details-marker { display: none; }

.container summary::before {
  content: "";
  flex-shrink: 0;
  width: 6px;
  height: 6px;
  margin: 0 2px 0 0;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.3s var(--ease);
}

.container[open] summary::before {
  transform: rotate(45deg);
}

.container .meta {
  flex-shrink: 0;
  min-width: 64px;
  white-space: nowrap;
  text-align: right;
  color: var(--muted);
  font-weight: 400;
  font-size: 11px;
}

.container ul {
  margin: 0;
  padding: 0 16px 4px;
  list-style: none;
  display: grid;
  border-top: 1px solid var(--sep);
}

.container li + li {
  border-top: 1px solid var(--sep);
}

.container li {
  display: grid;
  grid-template-columns: var(--col) 1fr auto;
  align-items: center;
  min-height: 52px;
  padding: 7px 0;
  color: #cfcfd5;
  font-size: 13px;
  animation: fadeUp 0.35s var(--ease) both;
  animation-delay: calc(var(--j, 0) * 25ms);
}

/* ---------- Squelette de chargement ---------- */

.skeleton {
  display: grid;
  gap: 8px;
}

.skeleton div {
  height: 52px;
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-hi) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  border: 1px solid var(--border);
  animation: shimmer 1.4s linear infinite;
}

.skeleton div:nth-child(2) { opacity: 0.6; }
.skeleton div:nth-child(3) { opacity: 0.35; }

/* ---------- Bouton d'ajout ---------- */

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 20;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
  cursor: pointer;
  transition: transform 0.3s var(--ease);
  animation: popIn 0.5s 0.15s var(--ease) both;
}

.fab svg {
  width: 24px;
  height: 24px;
  transition: transform 0.4s var(--ease);
}

.fab:hover svg { transform: rotate(90deg); }
.fab:active { transform: scale(0.92); }

/* ---------- Feuille d'ajout ---------- */

dialog {
  width: min(92vw, 420px);
  margin: auto;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.8);
}

dialog[open] {
  animation: dialogIn 0.35s var(--ease) both;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

dialog[open]::backdrop {
  animation: fade 0.25s ease both;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 3px;
  margin-bottom: 18px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.tabs button {
  min-height: 40px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.25s var(--ease), color 0.25s var(--ease);
}

.tabs button[aria-selected="true"] {
  background: var(--surface-hi);
  color: var(--text);
}

.field {
  display: block;
  margin-bottom: 14px;
  font-size: 11.5px;
  color: var(--muted);
  animation: fadeUp 0.3s var(--ease) both;
}

.field input,
.field select {
  margin-top: 6px;
  color: var(--text);
  appearance: none;
  -webkit-appearance: none;
}

.field select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 55%, calc(100% - 14px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.field select option {
  background: var(--surface);
  color: var(--text);
}

.error {
  margin: 0 0 12px;
  color: var(--danger);
  font-size: 12.5px;
  animation: shake 0.4s var(--ease);
}

.actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
}

.actions button {
  min-height: 44px;
  padding: 0 18px;
  border: none;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s var(--ease), opacity 0.2s;
}

.actions button:active { transform: scale(0.97); }
.actions button:disabled { opacity: 0.5; cursor: progress; }

.actions button.secondary {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  font-weight: 500;
}

.actions button.secondary:hover { color: var(--text); }

/* ---------- Notification ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  z-index: 30;
  transform: translateX(-50%);
  max-width: min(90vw, 420px);
  padding: 11px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 12.5px;
  text-align: center;
  box-shadow: 0 12px 30px -12px rgba(0, 0, 0, 0.6);
  animation: toastIn 0.4s var(--ease) both;
}

/* ---------- Mobile : la feuille remonte du bas ---------- */

@media (max-width: 600px) {
  /* Seul le formulaire d'ajout est une feuille du bas ; les autres fenêtres restent centrées */
  dialog.sheet {
    position: fixed;
    inset: auto 0 0 0;
    width: 100%;
    max-width: 100%;
    margin: 0;
    border-radius: 22px 22px 0 0;
    padding-bottom: calc(22px + env(safe-area-inset-bottom));
  }

  dialog.sheet[open] {
    animation: sheetIn 0.4s var(--ease) both;
  }
}

/* ---------- Animations ---------- */

@keyframes fadeDown {
  from { opacity: 0; transform: translateY(-10px); }
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
}

@keyframes fade {
  from { opacity: 0; }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

@keyframes shimmer {
  to { background-position: -200% 0; }
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.5); }
}

@keyframes dialogIn {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
}

@keyframes sheetIn {
  from { opacity: 0; transform: translateY(100%); }
}

@keyframes shake {
  20% { transform: translateX(-5px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-2px); }
  80% { transform: translateX(1px); }
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 16px); }
}

/* Respect des utilisateurs qui désactivent les animations */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Boutons à icône (fiche, confirmation, formulaire) ---------- */

.actions .icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: transform 0.2s var(--ease), color 0.2s var(--ease), background 0.2s var(--ease);
}

.actions .icon-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

.actions .icon-btn.primary {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}

.actions .icon-btn.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #1a0b0b;
}

.actions .icon-btn.danger-outline {
  color: var(--danger);
  border-color: rgba(240, 138, 138, 0.35);
}

.actions .icon-btn.danger-outline:hover {
  background: rgba(240, 138, 138, 0.08);
}

.actions .icon-btn:disabled { opacity: 0.5; cursor: progress; }

/* ---------- Page de connexion ---------- */

.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px 16px;
  padding-bottom: 24px;
}

.login {
  width: min(92vw, 360px);
}

.login h1 {
  margin: 0 0 24px;
  font-size: 18px;
  font-weight: 600;
  text-align: center;
}

.login-btn {
  width: 100%;
  min-height: 46px;
  margin-top: 6px;
  border: none;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  cursor: pointer;
}

.login-btn:disabled { opacity: 0.5; cursor: progress; }

.logout {
  margin: 24px 0 0;
  text-align: center;
}

.logout .link-btn {
  display: inline-block;
  width: auto;
  padding: 8px 12px;
}
