:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --brand-navy: #1e3a5f;
  --brand-gold: #c9a86c;
  --accent: #c9a86c;
  --accent-dim: #a88b52;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html,
body {
  margin: 0;
  min-height: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

#app {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

img,
video {
  max-width: 100%;
  height: auto;
}

.screen {
  display: none;
  min-height: 100dvh;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

#screen-login {
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-right));
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

.login-shop-link {
  text-align: center;
  margin: 0 0 16px;
}

.login-shop-link a {
  color: var(--accent);
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
}

.login-shop-link a:hover {
  text-decoration: underline;
}

.topbar-shop-link {
  text-decoration: none;
  white-space: nowrap;
}

.logo-img {
  display: block;
  width: min(200px, 72vw);
  height: auto;
  margin: 0 auto 12px;
}

.logo {
  font-size: 1.75rem;
  font-weight: 700;
  text-align: center;
}

.logo span {
  color: var(--accent);
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

.auth-form label {
  display: block;
  margin-top: 14px;
}

.auth-subtitle {
  margin: 0 0 4px;
  font-size: 1.1rem;
}

.auth-switch {
  margin-top: 20px;
  text-align: center;
  font-size: 0.9rem;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: inherit;
  padding: 0;
  text-decoration: underline;
}

.link-btn:hover {
  opacity: 0.85;
}

.muted.small {
  font-size: 0.82rem;
  margin-top: 10px;
}

.admin-users-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 16px 0;
  max-height: 50vh;
  overflow-y: auto;
}

.admin-user-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px;
  background: var(--bg);
  border-radius: 8px;
}

.admin-user-row strong {
  flex: 1 1 120px;
}

.admin-user-row .meta {
  font-size: 0.8rem;
  color: var(--muted);
  width: 100%;
}

#btn-admin-users.has-pending {
  position: relative;
}

#btn-admin-users.has-pending::after {
  content: "";
  position: absolute;
  top: 2px;
  right: 2px;
  width: 8px;
  height: 8px;
  background: #e85d4c;
  border-radius: 50%;
}

#screen-app {
  padding-bottom: calc(var(--nav-h) + var(--safe-b));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  padding-top: max(16px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--surface2);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1rem, 4vw, 1.15rem);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 8px;
}

#main-content {
  flex: 1;
  padding: 12px max(12px, env(safe-area-inset-left)) 16px
    max(12px, env(safe-area-inset-right));
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
  min-width: 0;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.card h2 {
  margin: 0 0 12px;
  font-size: 1rem;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

@media (min-width: 520px) {
  .kpi-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.kpi {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
}

.kpi .label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi .value {
  font-size: 1.35rem;
  font-weight: 700;
  margin-top: 4px;
}

.kpi.ok .value {
  color: var(--ok);
}

.form-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

input,
select,
textarea,
button {
  font: inherit;
  max-width: 100%;
}

input,
select,
textarea {
  width: 100%;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--surface2);
  background: var(--bg);
  color: var(--text);
}

@media (max-width: 768px) {
  input,
  select,
  textarea {
    font-size: 16px;
  }
}

textarea {
  min-height: 72px;
  resize: vertical;
}

.btn {
  font: inherit;
  padding: 12px 16px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}

.btn.primary {
  background: var(--accent);
  color: #042f2e;
}

.btn.secondary {
  background: var(--surface2);
  color: var(--text);
}

.btn.ghost {
  background: transparent;
  color: var(--muted);
}

.btn.sm {
  padding: 8px 12px;
  font-size: 0.85rem;
}

.btn.danger {
  background: var(--danger);
  color: #fff;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 8px 0 12px;
}

.list-header h2 {
  margin: 0;
  font-size: 1rem;
}

.btn-add {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #042f2e;
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(9, 177, 186, 0.35);
}

.btn-add:active {
  transform: scale(0.96);
}

.item-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.item-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  border-left: 4px solid var(--accent);
}

.item-card.sold {
  border-left-color: var(--ok);
}

.item-card.sold.sale-row {
  cursor: pointer;
  transition: filter 0.15s ease;
}

.item-card.sold.sale-row:hover,
.item-card.sold.sale-row:focus-visible {
  filter: brightness(1.06);
  outline: none;
}

.item-card.sold .sale-hint {
  font-size: 0.78rem;
  opacity: 0.75;
  margin-top: 4px;
}

.sale-detail-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.detail-section h3 {
  margin: 0 0 8px;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(110px, 38%) 1fr;
  gap: 6px 12px;
  font-size: 0.9rem;
}

.detail-grid dt {
  margin: 0;
  color: var(--muted);
}

.detail-grid dd {
  margin: 0;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.item-card .title-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
}

.item-card h3 {
  margin: 0;
  font-size: 0.95rem;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.badge.wf-en_ligne {
  background: rgba(34, 197, 94, 0.2);
  color: #86efac;
}

.badge.wf-draft {
  background: rgba(201, 168, 108, 0.25);
  color: var(--accent);
}

.badge.wf-retire {
  background: rgba(148, 163, 184, 0.2);
  color: var(--muted);
}

.item-actions-secondary {
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.item-actions.vitrine-actions {
  flex-wrap: wrap;
  gap: 6px;
}

.vitrine-photo-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 4px;
}

.vitrine-photo-picker.hidden {
  display: none;
}

.vitrine-photo-picker button {
  padding: 0;
  border: 2px solid transparent;
  border-radius: 10px;
  background: var(--surface2);
  cursor: pointer;
  overflow: hidden;
  width: 72px;
  height: 72px;
}

.vitrine-photo-picker button.selected {
  border-color: var(--accent);
}

.vitrine-photo-picker img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.badge {
  font-size: 0.7rem;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--surface2);
  white-space: nowrap;
}

.badge.publish {
  background: #164e63;
  color: #a5f3fc;
}

.badge.live {
  background: #14532d;
  color: #bbf7d0;
}

.meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 8px;
  line-height: 1.5;
}

.meta strong {
  color: var(--text);
}

.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.preview {
  margin-top: 12px;
  padding: 10px;
  background: var(--bg);
  border-radius: 8px;
  font-size: 0.9rem;
}

.preview.positive {
  color: var(--ok);
}

.error {
  color: var(--danger);
  font-size: 0.85rem;
}

.hidden {
  display: none !important;
}

.empty {
  text-align: center;
  padding: 32px;
  color: var(--muted);
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--surface2);
  z-index: 20;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.65rem;
  cursor: pointer;
}

.nav-btn.active {
  color: var(--accent);
}

.nav-icon {
  font-size: 1.2rem;
}

a.link {
  color: var(--accent);
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.toolbar #btn-refresh {
  width: 100%;
}

.toolbar select {
  width: 100%;
  min-width: 0;
}

@media (min-width: 480px) {
  .toolbar {
    grid-template-columns: auto 1fr 1fr;
    align-items: stretch;
  }

  .toolbar #btn-refresh {
    width: auto;
    white-space: nowrap;
  }
}

.shop-status {
  margin: 0 0 12px;
  font-size: 0.85rem;
}

.stats-toolbar {
  margin-bottom: 12px;
}

.filter-user-label {
  width: 100%;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--muted);
}

.filter-user-label select {
  flex: 1;
  min-width: 0;
}

.shop-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  width: 100%;
}

@media (min-width: 640px) {
  .shop-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1024px) {
  .shop-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.shop-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  border-left: 4px solid var(--accent);
}

@media (min-width: 400px) {
  .shop-card {
    flex-direction: row;
    align-items: stretch;
  }
}

.shop-card.gone {
  opacity: 0.55;
  border-left-color: var(--muted);
}

.shop-card.owned {
  border-left-color: var(--ok);
}

.shop-photo {
  flex-shrink: 0;
  width: 100%;
  aspect-ratio: 1;
  max-height: 200px;
  background: var(--surface2);
  overflow: hidden;
}

@media (min-width: 400px) {
  .shop-photo {
    width: 100px;
    max-width: 36%;
    aspect-ratio: 1;
    max-height: none;
  }
}

.shop-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}

.no-photo {
  width: 100%;
  height: 100%;
  min-height: 88px;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 1.5rem;
}

.shop-body {
  flex: 1;
  min-width: 0;
  padding: 12px;
  display: flex;
  flex-direction: column;
}

.shop-body h3 {
  margin: 6px 0;
  font-size: 0.9rem;
  line-height: 1.35;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.shop-top {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.brand-tag {
  font-size: 0.7rem;
  color: var(--accent);
}

.badge.wf-disponible {
  background: #164e63;
  color: #a5f3fc;
}
.badge.wf-interesse {
  background: #713f12;
  color: #fde68a;
}
.badge.wf-achete,
.badge.wf-revendu {
  background: #14532d;
  color: #bbf7d0;
}
.badge.wf-vinted_vendu {
  background: #374151;
  color: #d1d5db;
}

.shop-meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0;
  line-height: 1.45;
}

.modal {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  margin: auto;
  max-width: min(420px, calc(100vw - 24px));
  width: calc(100% - 24px);
  max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow: hidden;
  background: var(--surface);
  color: var(--text);
}

@media (max-width: 480px) {
  .modal {
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
  }

  .modal-inner {
    max-height: 100dvh;
    overflow-y: auto;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.65);
}

.modal-inner {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-inner h2 {
  margin: 0;
}

.modal-inner h3 {
  margin: 12px 0 4px;
  font-size: 0.9rem;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
  padding: 0;
}

.modal-actions .btn {
  flex: 1 1 auto;
  min-width: min(140px, 100%);
}

@media (max-width: 380px) {
  .modal-actions {
    flex-direction: column;
  }

  .modal-actions .btn {
    width: 100%;
  }
}

.config-brands {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
}

.brand-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px 36px;
  gap: 8px;
  align-items: center;
}

.brand-row strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.row-2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 88px;
  gap: 8px;
}

@media (max-width: 400px) {
  .brand-row {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }

  .brand-row .brand-del {
    justify-self: end;
  }

  .row-2 {
    grid-template-columns: 1fr;
  }
}

.item-actions .btn {
  flex: 1 1 calc(50% - 4px);
  min-width: 0;
}

@media (min-width: 520px) {
  .item-actions .btn {
    flex: 0 1 auto;
  }
}

.topbar-actions .btn {
  flex-shrink: 0;
}

@media (max-width: 360px) {
  .topbar-actions .btn.sm {
    padding: 8px;
    font-size: 0.75rem;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  .bottom-nav {
    height: 52px;
  }

  :root {
    --nav-h: 52px;
  }

  .nav-btn span:not(.nav-icon) {
    display: none;
  }
}

hr {
  border: none;
  border-top: 1px solid var(--surface2);
  margin: 8px 0;
}

.positive {
  color: var(--ok);
}
