/* =========================================================================
   Charpente Calard — Back-office
   ========================================================================= */
:root {
  --clay: #aa9d89;
  --clay-dark: #8a7d68;
  --clay-darker: #6b5d4a;
  --clay-deep: #4a4031;
  --clay-light: #c4baa9;
  --cream: #f7f4ee;
  --cream-2: #efe9df;
  --sand: #e7dfd2;
  --ink: #2b2720;
  --ink-soft: #5d564a;
  --ink-mute: #8c8478;
  --white: #fff;
  --danger: #b04a3a;
  --ok: #5b7f53;
  --radius: 12px;
  --shadow-sm: 0 2px 10px rgba(43, 39, 32, 0.06);
  --shadow-md: 0 14px 40px rgba(43, 39, 32, 0.12);
  --grad-clay: linear-gradient(135deg, #aa9d89 0%, #8a7d68 100%);
  --grad-dark: linear-gradient(160deg, #4a4031 0%, #2b2720 100%);
  --font-serif: "Cormorant Garamond", Georgia, serif;
  --font-sans: "Inter", system-ui, sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--ink);
  background: var(--cream);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------- Boutons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45em;
  padding: 0.7em 1.4em;
  border-radius: 100px;
  font-family: var(--font-sans);
  font-size: 0.92rem;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease),
    background 0.25s var(--ease), color 0.25s var(--ease);
}
.btn-primary {
  background: var(--grad-clay);
  color: var(--white);
  box-shadow: 0 8px 20px rgba(138, 125, 104, 0.35);
}
.btn-primary:hover { transform: translateY(-2px); }
.btn-ghost {
  background: var(--white);
  border-color: var(--sand);
  color: var(--ink-soft);
}
.btn-ghost:hover { border-color: var(--clay); color: var(--clay-dark); }
.btn-danger { background: transparent; color: var(--danger); border-color: rgba(176, 74, 58, 0.4); }
.btn-danger:hover { background: var(--danger); color: var(--white); }
.btn-block { width: 100%; }
.btn-sm { padding: 0.45em 0.9em; font-size: 0.84rem; }

/* ------------------------------------------------------------- Connexion */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--grad-dark);
  position: relative;
}
.login-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    115deg,
    rgba(255, 255, 255, 0.03) 0px,
    rgba(255, 255, 255, 0.03) 2px,
    transparent 2px,
    transparent 30px
  );
}
.login-card {
  position: relative;
  width: 100%;
  max-width: 400px;
  background: var(--white);
  border-radius: 20px;
  padding: 2.6rem 2.4rem;
  box-shadow: var(--shadow-md);
}
.login-brand {
  text-align: center;
  margin-bottom: 1.8rem;
}
.login-mark { color: var(--clay-dark); display: inline-flex; }
.login-brand h1 {
  font-family: var(--font-serif);
  font-size: 1.8rem;
  margin: 0.5rem 0 0.2rem;
  color: var(--ink);
}
.login-brand p {
  margin: 0;
  color: var(--ink-mute);
  font-size: 0.92rem;
}
.login-error {
  background: rgba(176, 74, 58, 0.1);
  color: var(--danger);
  border-radius: 10px;
  padding: 0.7rem 1rem;
  font-size: 0.9rem;
  margin: 0 0 1rem;
}
.login-back {
  display: block;
  text-align: center;
  margin-top: 1.2rem;
  font-size: 0.9rem;
  color: var(--ink-mute);
}
.login-back:hover { color: var(--clay-dark); }

/* ------------------------------------------------------------- Champs */
.field { margin-bottom: 1.1rem; }
.field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--ink-soft);
  margin-bottom: 0.4rem;
}
.field input,
.field textarea,
.field select {
  width: 100%;
  padding: 0.75em 0.95em;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--cream);
  border: 1px solid var(--sand);
  border-radius: 10px;
  transition: border-color 0.25s var(--ease), box-shadow 0.25s var(--ease);
}
.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: none;
  border-color: var(--clay);
  box-shadow: 0 0 0 4px rgba(170, 157, 137, 0.16);
}
.field textarea { resize: vertical; min-height: 90px; }
.field-hint { font-size: 0.8rem; color: var(--ink-mute); margin: 0.35rem 0 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* ------------------------------------------------------------- App */
.admin-app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  background: var(--grad-dark);
  color: rgba(255, 255, 255, 0.78);
  display: flex;
  flex-direction: column;
  padding: 1.6rem 1.1rem;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-serif);
  font-size: 1.4rem;
  color: var(--white);
  padding: 0 0.6rem 1.4rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.sidebar-brand .login-mark { color: var(--clay-light); }
.sidebar-brand small {
  font-family: var(--font-sans);
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--clay-light);
  vertical-align: super;
}
.sidebar-nav { display: grid; gap: 0.3rem; flex: 1; }
.nav-item {
  text-align: left;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.72);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  padding: 0.8rem 1rem;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.25s var(--ease), color 0.25s var(--ease);
}
.nav-item:hover { background: rgba(255, 255, 255, 0.07); color: var(--white); }
.nav-item.active {
  background: var(--grad-clay);
  color: var(--white);
  box-shadow: var(--shadow-sm);
}
.sidebar-foot {
  display: grid;
  gap: 0.6rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 0.9rem;
}
.sidebar-foot a { color: var(--clay-light); padding: 0.4rem 1rem; }
.sidebar-foot a:hover { color: var(--white); }
.logout-btn {
  text-align: left;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: rgba(255, 255, 255, 0.8);
  padding: 0.6rem 1rem;
  border-radius: 10px;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  transition: all 0.25s var(--ease);
}
.logout-btn:hover { background: rgba(255, 255, 255, 0.1); color: var(--white); }

/* Main */
.admin-main { display: flex; flex-direction: column; min-width: 0; }
.admin-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 1rem;
  background: rgba(247, 244, 238, 0.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--sand);
  padding: 1.1rem clamp(1.2rem, 4vw, 2.4rem);
}
.admin-topbar h2 {
  font-family: var(--font-serif);
  font-size: 1.6rem;
  margin: 0;
  flex: 1;
}
.topbar-user { font-size: 0.88rem; color: var(--ink-mute); }
.topbar-user strong { color: var(--clay-dark); }
.burger {
  display: none;
  flex-direction: column;
  gap: 4px;
  width: 38px;
  height: 38px;
  border: none;
  background: transparent;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}
.burger span { width: 22px; height: 2px; background: var(--ink); }

.admin-content { padding: clamp(1.4rem, 4vw, 2.4rem); }

/* ------------------------------------------------------------- Cartes/stats */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.2rem;
  margin-bottom: 2rem;
}
.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 1.6rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid rgba(170, 157, 137, 0.16);
}
.stat-card .num {
  font-family: var(--font-serif);
  font-size: 2.4rem;
  font-weight: 600;
  color: var(--clay-dark);
  line-height: 1;
}
.stat-card .lbl { color: var(--ink-mute); font-size: 0.92rem; margin-top: 0.3rem; }

.panel {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid rgba(170, 157, 137, 0.16);
  padding: clamp(1.2rem, 3vw, 1.8rem);
  margin-bottom: 1.6rem;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.4rem;
  flex-wrap: wrap;
}
.panel-head h3 {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  margin: 0;
}
.panel-head p { margin: 0.2rem 0 0; color: var(--ink-mute); font-size: 0.9rem; }
.intro-text { color: var(--ink-soft); margin: 0 0 1.6rem; max-width: 70ch; }

/* ------------------------------------------------------------- Listes */
.item-list { display: grid; gap: 0.9rem; }
.item-row {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--sand);
  border-radius: var(--radius);
  background: var(--cream);
  transition: border-color 0.25s var(--ease), box-shadow 0.25s var(--ease);
}
.item-row:hover { border-color: var(--clay-light); box-shadow: var(--shadow-sm); }
.item-thumb {
  flex: 0 0 70px;
  width: 70px;
  height: 56px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--grad-clay);
}
.item-thumb.ph {
  display: grid;
  place-items: center;
  color: rgba(255, 255, 255, 0.7);
}
.item-thumb.ph svg { width: 26px; height: 26px; }
.item-body { flex: 1; min-width: 0; }
.item-title { font-weight: 600; color: var(--ink); }
.item-meta { font-size: 0.85rem; color: var(--ink-mute); margin-top: 0.15rem; }
.item-cat {
  display: inline-block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--clay-dark);
  background: var(--cream-2);
  padding: 0.15rem 0.6rem;
  border-radius: 100px;
  margin-bottom: 0.3rem;
}
.item-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }
.empty-state {
  text-align: center;
  padding: 2.6rem 1rem;
  color: var(--ink-mute);
}

/* ------------------------------------------------------------- Modale */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(43, 39, 32, 0.55);
  backdrop-filter: blur(3px);
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal {
  background: var(--white);
  border-radius: 18px;
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow: auto;
  box-shadow: var(--shadow-md);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.4rem 1.6rem;
  border-bottom: 1px solid var(--sand);
  position: sticky;
  top: 0;
  background: var(--white);
}
.modal-head h3 { font-family: var(--font-serif); font-size: 1.4rem; margin: 0; }
.modal-close {
  border: none;
  background: var(--cream);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: var(--ink-soft);
}
.modal-close:hover { background: var(--sand); }
#modalForm { padding: 1.6rem; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.8rem;
  margin-top: 1.4rem;
}
.img-preview {
  margin-top: 0.6rem;
  border-radius: 10px;
  max-height: 160px;
  border: 1px solid var(--sand);
}
.img-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 0.6rem;
  margin-top: 0.6rem;
}
.img-tile {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--sand);
  background: var(--cream-2);
}
.img-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.img-del {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 50%;
  background: rgba(43, 39, 32, 0.65);
  color: var(--white);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.2s var(--ease);
}
.img-del:hover {
  background: var(--danger);
}
.img-cover {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.66rem;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 0.2rem;
  background: rgba(138, 125, 104, 0.92);
  color: var(--white);
}

/* ------------------------------------------------------------- Toasts */
.toast-wrap {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 300;
  display: grid;
  gap: 0.6rem;
}
.toast {
  background: var(--ink);
  color: var(--white);
  padding: 0.85rem 1.3rem;
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  font-size: 0.92rem;
  animation: toastIn 0.3s var(--ease);
}
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

/* ------------------------------------------------------------- Responsive */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(43, 39, 32, 0.45);
  z-index: 49;
}
@media (max-width: 860px) {
  .admin-app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 260px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.35s var(--ease);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.show { display: block; }
  .burger { display: flex; }
  .field-row { grid-template-columns: 1fr; }
}
