/* ==========================================================================
   Copro-Eco — ModuleShell UI Unifié (Template + Engine CSS)
   Fournit la structure partagée : sidebar, footer bas-gauche (Copyright + git
   describe), topbar 3-slots avec nom de copropriété et bouton Actualiser à droite,
   cartes unifiées .eco-card et modales accessibles .eco-modal.
   ========================================================================== */

:root {
  --eco-primary: #3092a3;
  --eco-primary-dark: #227180;
  --eco-primary-soft: rgba(48, 146, 163, 0.12);
  --eco-green: #69a742;
  --eco-green-dark: #1b5e20;
  --eco-sidebar-bg: #102a36;
  --eco-sidebar-border: rgba(255, 255, 255, 0.08);
  --eco-sidebar-text: #cbd5e1;
  --eco-sidebar-width: 250px;
  --eco-topbar-height: 52px;
  --eco-surface: #ffffff;
  --eco-bg: #f4f7f9;
  --eco-border: #e2e8f0;
  --eco-text: #1e293b;
  --eco-muted: #64748b;
  --eco-shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --eco-shadow-md: 0 6px 20px rgba(15, 23, 42, 0.08);
  --eco-radius-card: 10px;
}

/* ---------- Layout principal multi-modules ---------- */
.eco-module-layout {
  display: flex;
  width: 100%;
  height: 100%;
  min-height: 100vh;
  background-color: var(--eco-bg);
  color: var(--eco-text);
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.eco-module-layout.eco-layout--no-sidebar {
  flex-direction: column;
  height: auto;
  min-height: 100vh;
  overflow: visible;
}

/* ---------- Sidebar unifiée ---------- */
.eco-sidebar {
  width: var(--eco-sidebar-width);
  flex-shrink: 0;
  background: var(--eco-sidebar-bg);
  color: var(--eco-sidebar-text);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--eco-sidebar-border);
  overflow: hidden;
  z-index: 20;
}

.eco-sidebar-header {
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid var(--eco-sidebar-border);
  flex-shrink: 0;
}

.eco-sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: #f8fafc;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
}

.eco-sidebar-nav {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.75rem 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.eco-sidebar-nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.55rem;
  width: 100%;
  padding: 0.58rem 0.75rem;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--eco-sidebar-text);
  font-size: 0.86rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.eco-sidebar-nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.eco-sidebar-nav-item.active {
  background: var(--eco-primary);
  color: #ffffff;
  font-weight: 600;
}

.eco-sidebar-nav-main {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.eco-sidebar-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.35rem;
  height: 1.25rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 700;
  flex-shrink: 0;
}

.eco-sidebar-nav-item.active .eco-sidebar-badge {
  background: rgba(255, 255, 255, 0.25);
}

.eco-sidebar-section-title {
  margin: 0.65rem 0.5rem 0.25rem;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #94a3b8;
}

/* ---------- Footer bas-gauche (Rôle + Copropriété + Copyright + git describe) ---------- */
.eco-sidebar-footer-role {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: #f1f5f9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.eco-sidebar-footer-role i {
  color: #94a3b8;
  font-size: 0.75rem;
  width: 14px;
  text-align: center;
  flex-shrink: 0;
}

.eco-sidebar-footer-copro {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.74rem;
  color: #94a3b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.eco-sidebar-footer-copro i {
  color: var(--ecoexpertise-green, #5FB130);
  font-size: 0.75rem;
  width: 14px;
  text-align: center;
  flex-shrink: 0;
}

.eco-sidebar-footer {
  margin-top: auto;
  flex-shrink: 0;
  width: 100%;
  box-sizing: border-box;
  padding: 0.72rem 0.85rem;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 0.71rem;
  line-height: 1.35;
  text-align: left;
  color: #94a3b8;
}

.eco-sidebar-footer-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  margin-top: 0.12rem;
  min-width: 0;
}

.eco-sidebar-footer-copy {
  color: #cbd5e1;
  font-size: 0.68rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.eco-sidebar-footer-version {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.68rem;
  font-weight: 600;
  color: #bae6fd;
  background: rgba(48, 146, 163, 0.22);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: 4px;
  padding: 0.06rem 0.36rem;
  max-width: 96px;
  flex-shrink: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Zone principale + Topbar 3-slots ---------- */
.eco-main-column {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.eco-layout--no-sidebar .eco-main-column {
  height: auto;
  overflow: visible;
}

.eco-topbar {
  min-height: var(--eco-topbar-height);
  background: var(--eco-surface);
  border-bottom: 1px solid var(--eco-border);
  box-shadow: var(--eco-shadow-sm);
  padding: 0.45rem 1.25rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
  box-sizing: border-box;
  z-index: 15;
}

.eco-topbar-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  justify-self: start;
  max-width: 100%;
}

.eco-topbar-copro-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  color: #1b3a4b;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.3;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.eco-topbar-copro-pill .eco-topbar-copro-icon,
.eco-topbar-copro-pill i {
  color: #5fb130;
  font-size: 0.95rem;
  flex-shrink: 0;
}

.eco-topbar-copro-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.eco-topbar-center {
  display: flex;
  align-items: center;
  justify-content: center;
  justify-self: center;
  gap: 0.5rem;
  min-width: 0;
  flex-wrap: wrap;
}

.eco-topbar-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  justify-self: end;
  gap: 0.5rem;
  flex-shrink: 0;
}

.eco-btn-refresh {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 7px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #334155;
  font-size: 0.88rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  box-sizing: border-box;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.eco-btn-refresh:hover {
  background: #f1f5f9;
  border-color: var(--eco-primary);
  color: var(--eco-primary-dark);
}

.eco-btn-refresh:disabled {
  opacity: 0.6;
  cursor: wait;
}

.eco-btn-refresh .eco-refresh-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s ease;
}

.eco-btn-refresh.is-spinning .eco-refresh-icon {
  animation: ecoSpin 0.8s linear infinite;
}

/* Variante compacte icône seule (ex. en-tête de volet liste) */
.eco-btn-refresh--sm {
  width: 30px;
  height: 30px;
  padding: 0;
  font-size: 0.82rem;
}

@keyframes ecoSpin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.eco-topbar-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.38rem;
  height: 34px;
  padding: 0 0.78rem;
  border-radius: 7px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #1e293b;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.eco-topbar-action-btn:hover {
  background: #f8fafc;
  border-color: var(--eco-primary);
  color: var(--eco-primary-dark);
}

.eco-topbar-action-btn--primary {
  background: var(--eco-primary);
  border-color: var(--eco-primary);
  color: #ffffff;
}

.eco-topbar-action-btn--primary:hover {
  background: var(--eco-primary-dark);
  border-color: var(--eco-primary-dark);
  color: #ffffff;
}

.eco-content-area {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1rem 1.25rem;
}

.eco-content-area--flush {
  padding: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- Cartes unifiées (.eco-card) ---------- */
.eco-card {
  background: var(--eco-surface);
  border: 1px solid var(--eco-border);
  border-radius: var(--eco-radius-card);
  box-shadow: var(--eco-shadow-sm);
  overflow: hidden;
}

.eco-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1.2rem;
  border-bottom: 1px solid var(--eco-border);
  background: #f8fafc;
}

.eco-card-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--eco-text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.eco-card-subtitle {
  margin: 0.18rem 0 0;
  font-size: 0.82rem;
  color: var(--eco-muted);
}

.eco-card-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.eco-card-body {
  padding: 1.15rem 1.2rem;
}

.eco-card--centered {
  margin-left: auto;
  margin-right: auto;
}

.eco-card--narrow {
  width: fit-content;
  min-width: min(100%, 760px);
  max-width: min(100%, 1080px);
}

.eco-card--wide {
  width: 100%;
  max-width: 100%;
}

/* ---------- Footer pleine page (écrans sans sidebar: dashboard, profil) ---------- */
.eco-page-footer {
  margin-top: 2rem;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--eco-border);
  background: rgba(255, 255, 255, 0.85);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  font-size: 0.75rem;
  color: var(--eco-muted);
}

.eco-page-footer-left {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.eco-page-footer .eco-sidebar-footer-copy {
  color: #334155;
}

.eco-page-footer .eco-sidebar-footer-version {
  color: #0369a1;
  background: #e0f2fe;
  border-color: #bae6fd;
}

/* ---------- Modales unifiées (.eco-modal) ---------- */
.eco-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 2000;
}

.eco-modal-overlay.is-open {
  display: flex;
}

.eco-modal {
  width: 100%;
  max-width: 820px;
  max-height: 88vh;
  background: #ffffff;
  border-radius: 12px;
  border: 1px solid var(--eco-border);
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.eco-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.95rem 1.2rem;
  border-bottom: 1px solid var(--eco-border);
  background: #f8fafc;
}

.eco-modal-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--eco-text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.eco-modal-close {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: #64748b;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

.eco-modal-close:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.eco-modal-body {
  padding: 1rem 1.2rem;
  overflow-y: auto;
  flex: 1 1 auto;
}

.eco-modal-footer {
  padding: 0.75rem 1.2rem;
  border-top: 1px solid var(--eco-border);
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
}

@media (max-width: 900px) {
  .eco-topbar {
    grid-template-columns: 1fr auto;
    row-gap: 0.4rem;
  }
  .eco-topbar-center {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }
  .eco-sidebar {
    width: 210px;
  }
}
