/* ============================================================
   Critical Building — App Shell
   Styles partagés pour tous les modules /apps/
   Requiert colors_and_type.css chargé avant ce fichier.
   ============================================================ */

/* ── Reset ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  background: var(--cb-paper);
  color: var(--fg);
  height: 100vh;
  overflow: hidden;
}

/* ── Racine de l'app ──────────────────────────────────────── */
/* Wrapper flex-colonne : header fixe + zone de contenu */
.cb-app-root {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ── HEADER ───────────────────────────────────────────────── */
/* Bandeau noir 72 px, présent sur toutes les pages          */
.cb-header {
  height: 72px;
  background: var(--cb-black);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  z-index: 100;
  flex-shrink: 0;
}

.cb-header-left {
  display: flex;
  align-items: center;
  gap: 20px;
  min-width: 0;
}

/* Lien logo → retour portail (dashboard uniquement) */
.cb-logo-link {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  opacity: 0.9;
  transition: opacity 150ms;
}
.cb-logo-link:hover { opacity: 1; }

.cb-header-logo {
  height: 36px;
  filter: brightness(0) invert(1);
}

/* Bouton retour portail (apps uniquement — remplace le logo) */
.cb-back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  transition: background 150ms, color 150ms;
  flex-shrink: 0;
}
.cb-back-btn:hover { background: rgba(255,255,255,0.16); color: #fff; }
.cb-back-btn .material-icons { font-size: 20px; }

/* Boutons d'action dans le header (injectés via $HEADER_EXTRA) */
.cb-header-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.85);
  font-size: 12px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  font-family: var(--font-display);
  white-space: nowrap;
  text-decoration: none;
}
.cb-header-action:hover { background: rgba(255,255,255,0.13); color: #fff; }
.cb-header-action .material-icons { font-size: 16px; }

/* Burger dans le header (fond sombre, responsive) */
.cb-header #burger-btn {
  background: rgba(255,255,255,0.07);
  border-color: rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.8);
}
.cb-header #burger-btn:hover { background: rgba(255,255,255,0.14); color: #fff; }

/* Titre du module + point rouge (le .cb-dot vient de colors_and_type.css) */
.cb-app-title {
  color: #fff;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cb-header-right {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

/* ── User Chip ─────────────────────────────────────────────── */
.cb-user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 12px 5px 5px;
  background: rgba(255,255,255,0.06);
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.1);
}

.cb-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 12px;
  color: #fff;
  letter-spacing: 0.04em;
  flex-shrink: 0;
  background: var(--cb-blue);
}

.cb-user-meta {
  color: #fff;
  line-height: 1.25;
}

.cb-user-name {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 500;
}

.cb-user-role {
  font-family: var(--font-mono);
  font-size: 10px;
  color: rgba(255,255,255,0.5);
  letter-spacing: 0.05em;
}

/* ── Bouton déconnexion ────────────────────────────────────── */
.cb-btn-logout {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.8);
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  transition: border-color 150ms, color 150ms, background 150ms;
  white-space: nowrap;
  line-height: 1;
}
.cb-btn-logout:hover {
  border-color: var(--cb-red);
  color: #fff;
  background: rgba(227,6,19,0.1);
}
.cb-btn-logout .material-icons { font-size: 16px; }

/* ── Zone de contenu (sidebar + main) ────────────────────── */
.cb-content {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ── SIDEBAR ──────────────────────────────────────────────── */
#sidebar {
  width: 340px;
  min-width: 340px;
  background: var(--cb-gray-100);
  border-right: 1px solid var(--cb-gray-200);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 50;
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
}

/* Bandeau mobile en haut de la sidebar (close + titre app) */
.sidebar-top {
  display: none;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  padding: 0 16px;
  background: var(--cb-black);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}
.sidebar-top-title {
  color: #fff;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
}

#sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

#sidebar-footer {
  flex-shrink: 0;
  background: var(--cb-gray-100);
  border-top: 1px solid var(--cb-gray-200);
  padding: 12px 16px;
}

/* ── Sections accordéon ────────────────────────────────────── */
.sidebar-section {
  border-bottom: 1px solid var(--cb-gray-200);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  cursor: pointer;
  transition: background 0.15s;
  user-select: none;
}
.section-header:hover { background: rgba(31,107,181,0.05); }

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  color: var(--fg);
  text-transform: uppercase;
  letter-spacing: 0.09em;
}
.section-title .material-icons {
  font-size: 17px;
  color: var(--accent);
}

.section-header .chevron {
  font-size: 17px;
  color: var(--fg-soft);
  transition: transform 0.25s;
}
.section-header.open .chevron { transform: rotate(180deg); }

.section-body {
  padding: 0 16px 14px;
  display: none;
}
.section-body.open { display: block; }

/* ── Zone principale (main) ────────────────────────────────── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* ── Barre d'outils contextuelle (sous le header, dans main) ─ */
#toolbar {
  height: 52px;
  background: #fff;
  border-bottom: 1px solid var(--cb-gray-200);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  flex-shrink: 0;
}

#toolbar-title {
  flex: 1;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 500;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.toolbar-actions .cb-btn { width: auto; padding: 6px 12px; font-size: 12px; }

/* ── Onglets ───────────────────────────────────────────────── */
.cb-tabs {
  display: flex;
  background: var(--cb-gray-100);
  border-bottom: 1px solid var(--cb-gray-200);
  flex-shrink: 0;
  height: 44px;
}

.cb-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 20px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-display);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  color: var(--fg-soft);
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
  height: 100%;
  letter-spacing: 0.02em;
}
.cb-tab .material-icons { font-size: 16px; }
.cb-tab:hover { color: var(--fg); }
.cb-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-content { display: none; flex: 1; overflow: hidden; }
.tab-content.active { display: flex; flex-direction: column; }

/* ── Contrôles de formulaire ───────────────────────────────── */
.cb-label {
  display: block;
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 700;
  color: var(--fg-soft);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 5px;
}

.cb-input {
  width: 100%;
  background: #fff;
  border: 1.5px solid var(--cb-gray-300);
  border-radius: 6px;
  padding: 8px 11px;
  font-size: 13px;
  color: var(--fg);
  font-family: var(--font-sans);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  box-sizing: border-box;
}
.cb-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31,107,181,0.1);
}
.cb-input::placeholder { color: var(--cb-gray-400); }
.cb-input:disabled { opacity: 0.4; cursor: not-allowed; background: var(--cb-gray-100); }
select.cb-input { cursor: pointer; }

/* ── Boutons ───────────────────────────────────────────────── */
.cb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-display);
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  width: 100%;
  white-space: nowrap;
  line-height: 1;
}
.cb-btn:disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }
.cb-btn .material-icons { font-size: 15px; }

.cb-btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 6px rgba(31,107,181,0.2);
}
.cb-btn-primary:hover { filter: brightness(1.1); box-shadow: 0 4px 10px rgba(31,107,181,0.28); }

.cb-btn-secondary {
  background: rgba(14,40,65,0.05);
  color: var(--fg);
  border: 1.5px solid var(--cb-gray-300);
}
.cb-btn-secondary:hover { background: rgba(14,40,65,0.1); }

.cb-btn-danger {
  background: rgba(227,6,19,0.07);
  color: var(--cb-red);
  border: 1.5px solid rgba(227,6,19,0.2);
}
.cb-btn-danger:hover { background: rgba(227,6,19,0.14); }

.cb-btn-success {
  background: rgba(39,174,96,0.09);
  color: #1a7a46;
  border: 1.5px solid rgba(39,174,96,0.25);
}
.cb-btn-success:hover { background: rgba(39,174,96,0.18); }

/* ── Mise en page formulaire ───────────────────────────────── */
.form-row { margin-bottom: 11px; }
.row-2col { display: flex; gap: 8px; }
.row-2col > * { flex: 1; }
.row-2col > *.shrink { flex: 0 0 auto; }

/* ── Alertes ───────────────────────────────────────────────── */
.cb-alert {
  padding: 9px 12px;
  border-radius: 6px;
  font-family: var(--font-sans);
  font-size: 12px;
  margin-bottom: 10px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  line-height: 1.5;
}
.cb-alert .material-icons { font-size: 16px; flex-shrink: 0; margin-top: 1px; }
.cb-alert.info    { background: rgba(31,107,181,0.07);  border: 1px solid rgba(31,107,181,0.18); color: var(--cb-blue-dark); }
.cb-alert.success { background: rgba(39,174,96,0.07);   border: 1px solid rgba(39,174,96,0.25);  color: #165c37; }
.cb-alert.error   { background: rgba(227,6,19,0.07);    border: 1px solid rgba(227,6,19,0.22);   color: var(--cb-red-dark); }
.cb-alert.warning { background: rgba(230,126,34,0.07);  border: 1px solid rgba(230,126,34,0.22); color: #8B4513; }

/* ── Spinner ───────────────────────────────────────────────── */
.cb-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--cb-gray-300);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: cb-spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes cb-spin { to { transform: rotate(360deg); } }

/* ── Modale générique ──────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(14,40,65,0.5);
  backdrop-filter: blur(4px);
  z-index: 900;
  display: none;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }

/* Deux variantes de sélecteur pour compatibilité avec les apps existantes */
/* Cachées par défaut — affichées quand la classe .open est ajoutée par JS  */
.modal-box,
.modal {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(440px, 92vw);
  background: #fff;
  border: 1px solid var(--cb-gray-200);
  border-radius: 12px;
  box-shadow: var(--sh-lg);
  z-index: 901;
  overflow: hidden;
}
.modal-box.open,
.modal.open {
  display: block;
  animation: cb-modal-in 200ms var(--ease-out);
}
@keyframes cb-modal-in {
  from { opacity: 0; transform: translate(-50%, calc(-50% + 10px)) scale(0.97); }
  to   { opacity: 1; transform: translate(-50%, -50%); }
}

.modal-header,
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--cb-gray-200);
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  color: var(--cb-blue-dark);
}

.modal-body { padding: 20px; }

.modal-footer,
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--cb-gray-200);
}

.modal-close,
.btn-modal-close {
  background: none;
  border: none;
  color: var(--fg-soft);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  transition: color 150ms, background 150ms;
}
.modal-close:hover,
.btn-modal-close:hover { color: var(--fg); background: var(--cb-gray-100); }
.modal-close .material-icons,
.btn-modal-close .material-icons { font-size: 18px; }

/* ── Burger (mobile) ───────────────────────────────────────── */
#burger-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  background: var(--cb-gray-100);
  border: 1px solid var(--cb-gray-200);
  cursor: pointer;
  color: var(--fg);
  flex-shrink: 0;
}
#burger-btn .material-icons { font-size: 22px; }

/* ── Bouton fermeture sidebar (mobile) ─────────────────────── */
#sidebar-close {
  display: none;
  background: none;
  border: none;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  align-items: center;
  justify-content: center;
  transition: color 150ms;
}
#sidebar-close:hover { color: #fff; }
#sidebar-close .material-icons { font-size: 20px; }

/* ── Overlay sidebar (mobile) ──────────────────────────────── */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 49;
}
#sidebar-overlay.open { display: block; }

/* ── Barre de défilement ───────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--cb-gray-300); border-radius: 2px; }

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 900px) {
  #burger-btn { display: flex; }

  /* La sidebar devient un drawer par-dessus le contenu */
  #sidebar {
    position: fixed;
    top: 72px;
    left: 0;
    height: calc(100vh - 72px);
    transform: translateX(-110%);
    z-index: 100;
    box-shadow: 4px 0 24px rgba(0,0,0,0.15);
  }
  #sidebar.open { transform: translateX(0); }

  .sidebar-top { display: flex; }
  #sidebar-close { display: flex; }

  #sidebar-overlay { z-index: 99; }
}

@media (max-width: 600px) {
  .cb-tab span:not(.material-icons) { display: none; }
  .cb-user-meta { display: none; }
  .cb-header { padding: 0 16px; }
}
