:root {
  --bg: #f4f1ea;
  --card: #ffffff;
  --text: #1f2933;
  --muted: #667085;
  --border: #ded7ca;
  --primary: #8a4b17;
  --primary-dark: #63350f;
  --accent: #d6a64f;
  --danger: #b42318;
  --ok: #067647;
  --shadow: 0 12px 30px rgba(31, 41, 51, .10);
  --radius: 18px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #fff8ea 0%, var(--bg) 45%, #eee7dc 100%);
  min-height: 100vh;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255,255,255,.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 16px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 58px; height: 58px; border-radius: 16px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff; font-weight: 800;
  display: grid; place-items: center;
  box-shadow: var(--shadow);
}
.brand-logo-img {
  width: 76px;
  height: 76px;
  border-radius: 18px;
  object-fit: cover;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.brand-contact {
  margin-top: 3px !important;
  font-weight: 700;
  color: var(--primary) !important;
}
.brand h1 { margin: 0; font-size: 1.3rem; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: .92rem; }

.tabs, .admin-tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.tab, .admin-tab {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 10px 14px;
  border-radius: 999px;
}
.tab.active, .admin-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.badge { background: var(--accent); color: #2d1b00; border-radius: 999px; padding: 2px 7px; font-size: .8rem; }

.container { width: min(1180px, calc(100% - 28px)); margin: 24px auto 70px; }
.view, .admin-view { display: none; }
.view.active, .admin-view.active { display: block; }

.hero {
  background: linear-gradient(135deg, #fff, #fff0cc);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: grid;
  grid-template-columns: 1fr 310px;
  gap: 20px;
  box-shadow: var(--shadow);
}
.hero h2 { margin: 0 0 8px; font-size: 1.9rem; }
.hero p { margin: 0; color: var(--muted); line-height: 1.5; }
.hero-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.hero-card span { color: var(--muted); line-height: 1.4; }

.toolbar, .cart-layout, .form-grid { display: grid; gap: 14px; }
.toolbar {
  grid-template-columns: 1fr 210px 190px;
  margin: 18px 0;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: .86rem; font-weight: 700; color: #344054; }
input, select, textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 12px;
  padding: 11px 12px; background: #fff; color: var(--text);
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(138,75,23,.12); }
.grow { min-width: 0; }
.full { grid-column: 1 / -1; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; }
.product-card, .panel, .stat-card, .order-card, .client-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.product-card { overflow: hidden; display: flex; flex-direction: column; }
.product-image {
  height: 220px;
  display: block;
  padding: 0;
  border: 0;
  width: 100%;
  background: radial-gradient(circle at 20% 20%, #ffe4a6, #fff7e6 45%, #ecd8bd);
  cursor: zoom-in;
}
.product-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.product-image:hover img { transform: scale(1.02); }
.product-image img { transition: transform .25s ease; }
.image-preview {
  margin-top: 10px;
  border: 1px dashed var(--border);
  border-radius: 16px;
  min-height: 220px;
  display: grid;
  place-items: center;
  background: #fff;
  overflow: hidden;
  color: var(--muted);
}
.image-preview img {
  width: 100%;
  max-height: 320px;
  object-fit: cover;
  display: block;
}
.empty-preview { padding: 18px; }
.thumbnail {
  width: 68px;
  height: 56px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-right: 10px;
  vertical-align: middle;
}
.product-admin-name {
  display: flex;
  align-items: center;
}
.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 24, 40, .68);
}
.modal-content {
  position: relative;
  width: min(94vw, 900px);
  max-height: 92vh;
  background: #fff;
  border-radius: 24px;
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(0,0,0,.3);
  z-index: 1;
  display: flex;
  flex-direction: column;
}
.modal-image {
  width: 100%;
  height: min(68vh, 560px);
  min-height: 320px;
  object-fit: contain;
  background: #faf7f1;
  display: block;
}
.modal-caption {
  padding: 16px 20px 20px;
  background: #fff;
}
.modal-caption h3 { margin: 0 0 6px; }
.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  border: 0;
  background: rgba(255,255,255,.92);
  font-size: 1.8rem;
  line-height: 1;
}

.product-body { padding: 16px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.product-body h3 { margin: 0; font-size: 1.05rem; }
.product-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border-radius: 999px; background: #f2f4f7; color: #344054; padding: 5px 9px; font-size: .78rem; }
.chip.ok { background: #dcfae6; color: var(--ok); }
.chip.warn { background: #fff2cc; color: #7a4a00; }
.chip.danger { background: #fee4e2; color: var(--danger); }
.price-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-top: auto; }
.price { font-size: 1.25rem; font-weight: 800; color: var(--primary); }
.qty-row { display: grid; grid-template-columns: 82px 1fr; gap: 10px; align-items: center; }
.qty-row input { padding: 9px; }

.btn {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 14px;
  background: #fff;
  color: var(--text);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { border-color: var(--border); background: #fff; }
.btn.danger { background: #fee4e2; color: var(--danger); border-color: #fecdca; }
.btn.small-btn { padding: 8px 12px; font-size: .9rem; }
.full-btn { width: 100%; margin-top: 12px; }

.section-title { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.section-title h2, .section-title h3 { margin: 0; }
.section-title p { margin: 5px 0 0; color: var(--muted); }
.section-title.compact { margin-bottom: 12px; }

.cart-layout { grid-template-columns: 1fr 420px; align-items: start; }
.panel { padding: 18px; }
.panel h3 { margin-top: 0; }
.cart-item {
  display: grid;
  grid-template-columns: 1fr 92px 110px 42px;
  gap: 10px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.cart-item:last-child { border-bottom: none; }
.cart-item strong { display: block; }
.cart-item span { color: var(--muted); font-size: .9rem; }
.icon-btn { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border); background: #fff; }
.total-line { display: flex; justify-content: space-between; align-items: center; padding-top: 16px; margin-top: 6px; border-top: 2px solid var(--border); font-size: 1.12rem; }
.form-grid { grid-template-columns: repeat(2, 1fr); }
.notice { background: #ecfdf3; border: 1px solid #abefc6; color: var(--ok); padding: 12px; border-radius: 12px; }
.muted { color: var(--muted); }
.small { font-size: .88rem; line-height: 1.45; }

.login-panel { max-width: 480px; margin: 0 auto; }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat-card { padding: 16px; }
.stat-card span { color: var(--muted); font-size: .9rem; }
.stat-card strong { display: block; margin-top: 8px; font-size: 1.6rem; color: var(--primary); }
.admin-tabs { margin-bottom: 14px; }

.order-card, .client-card { padding: 14px; margin-bottom: 12px; box-shadow: none; }
.order-head { display: flex; justify-content: space-between; gap: 12px; align-items: start; }
.order-head h4 { margin: 0 0 5px; }
.order-lines { margin: 10px 0; padding-left: 18px; color: #344054; }
.row-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-actions.wrap { margin-top: 12px; }
.status-select { max-width: 230px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { text-align: left; border-bottom: 1px solid var(--border); padding: 10px 8px; vertical-align: top; }
th { color: #344054; background: #faf7f1; }
.product-form { margin: 12px 0 18px; border: 1px dashed var(--border); border-radius: 16px; padding: 14px; background: #fffaf0; }
.file-btn { position: relative; }
.footer {
  border-top: 1px solid var(--border);
  background: rgba(255,255,255,.75);
  padding: 14px 22px;
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: .88rem;
}
.empty { color: var(--muted); padding: 20px; text-align: center; border: 1px dashed var(--border); border-radius: 14px; background: #fff; }

@media (max-width: 900px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .hero, .cart-layout, .toolbar { grid-template-columns: 1fr; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 620px) {
  .container { width: min(100% - 18px, 1180px); margin-top: 12px; }
  .brand h1 { font-size: 1.05rem; }
  .brand p { font-size: .82rem; }
  .brand-logo-img { width: 62px; height: 62px; border-radius: 14px; }
  .identity-card { flex-direction: column; align-items: flex-start; }
  .identity-card img { width: 92px; height: 92px; }
  .grid, .form-grid, .stats-grid { grid-template-columns: 1fr; }
  .product-image { height: 250px; }
  .cart-item { grid-template-columns: 1fr; }
  .footer { flex-direction: column; gap: 6px; }
  .hero h2 { font-size: 1.45rem; }
}

.identity-card {
  margin-top: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(255,255,255,.72);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 12px;
  max-width: 760px;
}
.identity-card img {
  width: 104px;
  height: 104px;
  object-fit: cover;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: #fff;
  flex: 0 0 auto;
}
.identity-card strong {
  display: block;
  color: var(--primary);
  font-size: 1.12rem;
  margin-bottom: 4px;
}
.identity-card span {
  display: block;
  color: #344054;
  font-size: .94rem;
  line-height: 1.35;
}

.backup-box {
  margin-top: 14px;
  border: 1px dashed var(--border);
  border-radius: 16px;
  background: #fffaf0;
  padding: 14px;
}
.backup-box textarea {
  width: 100%;
  margin-top: 12px;
  min-height: 220px;
  font-family: Consolas, Monaco, monospace;
  font-size: .86rem;
  white-space: pre;
}


/* Correctif V3.2 : empêche la fenêtre photo cachée de bloquer les champs à remplir */
.modal[hidden],
#backupBox[hidden],
#adminPanel[hidden],
#productForm[hidden],
#checkoutMsg[hidden],
#exportMsg[hidden] {
  display: none !important;
}


/* V4.0 Cloud Supabase */
.cloud-banner {
  margin: 0 0 16px;
  border: 1px solid var(--border);
  background: #fff7df;
  color: #4a2d0b;
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  font-weight: 700;
}
.cloud-banner.ok {
  background: #ecfdf3;
  color: #05603a;
}
.cloud-banner.warn {
  background: #fff7df;
  color: #7a3d00;
}
.cloud-banner.error {
  background: #fff1f0;
  color: #912018;
}
.admin-only {
  opacity: .9;
}
.small-btn {
  padding: 7px 10px;
  margin-left: 8px;
}


/* V4.1 Admin Cloud */
.cloud-action-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}
.cloud-status {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: .82rem;
  font-weight: 800;
  background: #fff7df;
  color: #7a3d00;
}
.cloud-status.ok { background: #ecfdf3; color: #05603a; }
.cloud-status.danger { background: #fff1f0; color: #912018; }
.cloud-status.neutral { background: #eef2f6; color: #344054; }
.login-panel .form-grid { margin: 12px 0; }
.notice strong { color: inherit; }


/* V4.1.2 Dashboard / paiements */
.overpaid {
  color: #f79009;
}
.stats-grid {
  align-items: stretch;
}


/* V4.2.2 Public Client */
body.public-client #admin,
body.public-client .admin-only,
body.public-client .tab[data-view="admin"] {
  display: none !important;
}
body.public-client .tabs {
  justify-content: flex-end;
}
body.public-client .topbar {
  z-index: 20;
}
.public-client-badge {
  display: inline-flex;
  border-radius: 999px;
  padding: 4px 9px;
  background: #ecfdf3;
  color: #05603a;
  font-weight: 800;
  font-size: .82rem;
}
