/* ============================================================================
 * Module : artisan/styles/dashboard-shell.css
 * Rôle   : Layout commun à TOUTES les pages dashboard artisan.
 *          Styles de <mda-artisan-sidebar>, <mda-artisan-topbar>, .main-content,
 *          .dashboard-card, boutons standards, etc.
 *
 *          Toute page dashboard charge ce fichier. Les styles spécifiques à
 *          une page vont dans son propre `pages/<page>.css`.
 *
 * Dépend de : tokens.css (var(--brand-*), var(--gray-*), var(--sidebar-w), ...)
 * Utilisé par : toutes les pages /artisan/*.html
 * ============================================================================ */

/* ─── Layout racine ───────────────────────────────────────────────── */
body {
  background: var(--gray-50);
  color: var(--gray-800);
  min-height: 100vh;
}

/* ─── Sidebar (composant <mda-artisan-sidebar>) ──────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--brand-dark);
  padding: 24px 0;
  display: flex;
  flex-direction: column;
  z-index: 50;
  transition: transform .3s ease;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sidebar-logo {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 0 20px;
  margin-bottom: 36px;
  font-weight: var(--weight-black);
  font-size: 1.05rem;
  font-family: var(--font-heading);
  color: white;
  text-decoration: none;
}

.sidebar-logo .icon {
  width: 34px;
  height: 34px;
  background: var(--brand-mid);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-logo-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.sidebar-logo-sub {
  font-size: .66rem;
  font-weight: var(--weight-medium);
  opacity: .7;
  letter-spacing: .03em;
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  color: rgba(255, 255, 255, .6);
  text-decoration: none;
  font-size: .9rem;
  font-weight: var(--weight-medium);
  transition: background var(--transition-fast), color var(--transition-fast);
  border-left: 3px solid transparent;
}

.sidebar-nav a:hover {
  color: white;
  background: rgba(255, 255, 255, .05);
}

.sidebar-nav a.active {
  color: white;
  background: rgba(255, 255, 255, .08);
  border-left-color: var(--brand-light);
}

.sidebar-nav a .nav-icon {
  font-size: 1.15rem;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}

/* Lien vers une page pas encore migrée — visuellement atténué. */
.sidebar-nav a.todo {
  opacity: .45;
  cursor: not-allowed;
}
.sidebar-nav a.todo:hover {
  background: transparent;
  color: rgba(255, 255, 255, .6);
}

.sidebar-badge {
  margin-left: auto;
  background: #dc2626;
  color: white;
  border-radius: 10px;
  padding: 1px 8px;
  font-size: .7rem;
  font-weight: var(--weight-bold);
}

.sidebar-bottom {
  padding: 16px 20px;
  border-top: 1px solid rgba(255, 255, 255, .1);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  color: rgba(255, 255, 255, .7);
  font-size: .85rem;
}

.sidebar-user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-mid), #FBBF24);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: var(--weight-bold);
  color: white;
  font-size: .9rem;
  flex-shrink: 0;
}

.sidebar-user-info {
  min-width: 0;
}

.sidebar-user-name {
  font-weight: var(--weight-semibold);
  color: white;
  font-size: .88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-plan {
  font-size: .75rem;
  color: rgba(255, 255, 255, .55);
}

.sidebar-logout {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: rgba(255, 255, 255, .6);
  font-size: .82rem;
  font-weight: var(--weight-medium);
  background: rgba(255, 255, 255, .05);
  border: none;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background var(--transition-fast), color var(--transition-fast);
  font-family: inherit;
}
.sidebar-logout:hover {
  background: rgba(239, 68, 68, .15);
  color: #fca5a5;
}

.sidebar-logout .logout-icon {
  font-size: 1.1rem;
}

/* ─── Sidebar toggle (mobile) ─────────────────────────────────────── */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 60;
  width: 40px;
  height: 40px;
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
}

.sidebar-toggle span,
.sidebar-toggle span::before,
.sidebar-toggle span::after {
  display: block;
  position: absolute;
  width: 20px;
  height: 2px;
  background: var(--brand-dark);
  border-radius: 1px;
  content: '';
}
.sidebar-toggle span::before { top: -6px; left: 0; }
.sidebar-toggle span::after  { top: 6px;  left: 0; }
.sidebar-toggle span { position: relative; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .35);
  z-index: 45;
}

/* ─── Topbar (composant <mda-artisan-topbar>) ────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 32px;
  gap: 12px;
}

.topbar h1 {
  font-size: 1.6rem;
  font-weight: var(--weight-black);
  font-family: var(--font-heading);
  color: var(--brand-dark);
  margin: 0;
}

.topbar-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

/* ─── Main content ────────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  padding: 32px;
  min-height: 100vh;
}

/* ─── Carte dashboard (réutilisable) ──────────────────────────────── */
.dashboard-card {
  background: white;
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .06);
}

.dashboard-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.dashboard-card-header .icon-bubble {
  width: 42px;
  height: 42px;
  background: var(--brand-50);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.dashboard-card-header h2 {
  font-family: var(--font-heading);
  font-weight: var(--weight-black);
  font-size: 1.15rem;
  color: var(--brand-dark);
  margin: 0;
}

.dashboard-card-header p {
  font-size: .82rem;
  color: var(--gray-500);
  margin: 2px 0 0;
}

/* ─── Boutons standards (réutilisables sur toutes pages dashboard) ─ */
.btn {
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-weight: var(--weight-semibold);
  font-size: .88rem;
  cursor: pointer;
  border: none;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--brand);
  color: white;
}
.btn-primary:hover:not(:disabled) { background: var(--brand-dark); }

.btn-ghost {
  background: white;
  color: var(--brand);
  border: 1.5px solid var(--brand);
}
.btn-ghost:hover:not(:disabled) { background: var(--brand-50); }

.btn-secondary {
  background: white;
  color: var(--gray-600);
  border: 1.5px solid var(--gray-200);
}
.btn-secondary:hover:not(:disabled) { border-color: var(--gray-300); }

/* Bouton danger (red outline) — utilisé pour suppression/avoir/etc. */
.btn-danger {
  background: white;
  color: #dc2626;
  border: 1.5px solid #fca5a5;
  padding: 8px 14px;
  font-size: .82rem;
}
.btn-danger:hover:not(:disabled) { background: #fef2f2; }

.btn-small { font-size: .82rem; padding: 8px 14px; }
.btn-large { padding: 14px; font-size: 1rem; border-radius: var(--radius); width: 100%; }

/* ─── Modal générique (pour toutes pages dashboard) ──────────────── */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-backdrop.open { display: flex; }

.modal-card {
  background: white;
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.modal-header h3 {
  margin: 0;
  font-family: var(--font-heading);
  font-weight: var(--weight-black);
  color: var(--brand-dark);
  font-size: 1.1rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--gray-400);
  line-height: 1;
}

/* ─── Form fields génériques ──────────────────────────────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.field label {
  font-size: .78rem;
  font-weight: var(--weight-semibold);
  color: var(--gray-600);
}
.field input,
.field select,
.field textarea {
  padding: 10px 12px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: .9rem;
  outline: none;
  background: white;
  transition: border-color var(--transition-fast);
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--brand-mid);
}
.field textarea { resize: vertical; min-height: 80px; }

.field .hint {
  color: var(--gray-400);
  font-weight: var(--weight-normal);
  font-size: .78rem;
}
.field .hint-brand {
  color: var(--brand);
  font-weight: var(--weight-semibold);
  font-size: .7rem;
}

/* Surlignage rouge sur champ invalide (utilisé par profil + nouveau) */
.field.field-error input,
.field.field-error select,
.field.field-error textarea {
  border-color: #ef4444;
  background: #fef2f2;
}

/* Form feedback (validation client-side, sous le form) */
.form-feedback {
  font-size: .85rem;
  min-height: 18px;
}
.form-feedback.error   { color: #dc2626; }
.form-feedback.success { color: #16a34a; }

/* ─── États (loading / empty / error) — factorisés depuis 10 pages ─ */
.state-loading,
.state-empty,
.state-error {
  text-align: center;
  padding: 40px 20px;
  color: var(--gray-400);
}
.state-empty .empty-sub {
  display: block;
  font-size: .82rem;
  margin-top: 6px;
}
.state-empty .empty-sub strong { color: var(--brand-dark); }
.state-error   { color: #dc2626; }
.state-success {
  background: #dcfce7;
  color: #16a34a;
  font-weight: var(--weight-semibold);
  border-radius: var(--radius-sm);
  padding: 14px;
}

/* ─── KPI stats row (factorisé depuis clients, devis, factures, dashboard) ─ */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
}

.stat-card {
  background: white;
  border-radius: var(--radius);
  padding: 22px;
  border: 1px solid var(--gray-100);
  transition: box-shadow var(--transition-fast);
}
.stat-card:hover { box-shadow: var(--shadow-md); }

.stat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.stat-label {
  font-size: .82rem;
  color: var(--gray-500);
  font-weight: var(--weight-medium);
}

.stat-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}
.stat-icon-brand  { background: var(--brand-50); }
.stat-icon-green  { background: #D1FAE5; }
.stat-icon-amber  { background: #FEF3C7; }
.stat-icon-orange { background: #FED7AA; }
.stat-icon-red    { background: #FEE2E2; }

.stat-value {
  font-size: 1.8rem;
  font-weight: var(--weight-black);
  font-family: var(--font-heading);
  color: var(--brand-dark);
}

.stat-change {
  font-size: .78rem;
  font-weight: var(--weight-semibold);
  margin-top: 4px;
  color: var(--gray-500);
}
.stat-change.up   { color: #16a34a; }
.stat-change.down { color: #dc2626; }

.stat-sub {
  font-size: .78rem;
  color: var(--gray-400);
  margin-top: 4px;
}

/* ─── Topbar search (slot — clients, devis, factures) ─────────────── */
.topbar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: white;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  transition: border-color var(--transition-fast);
  min-width: 280px;
}
.topbar-search:focus-within { border-color: var(--brand-mid); }

.topbar-search-icon { color: var(--gray-400); font-size: .9rem; }

.topbar-search input {
  border: none;
  outline: none;
  font-family: inherit;
  font-size: .9rem;
  color: var(--gray-800);
  background: transparent;
  flex: 1;
}

/* ─── Filtres avancés (devis + factures) ────────────────────────── */
.advanced-filters {
  background: white;
  border-radius: var(--radius);
  padding: 14px 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}

.filter-field {
  display: flex;
  flex-direction: column;
  min-width: 140px;
}

.filter-label {
  font-size: .72rem;
  font-weight: var(--weight-bold);
  color: var(--brand);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 4px;
}

.filter-input,
.filter-select {
  border: 2px solid var(--brand-100);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: .88rem;
  font-family: inherit;
  color: var(--brand-dark);
  background: var(--brand-50);
  outline: none;
  transition: border-color var(--transition-fast);
  width: 100%;
}
.filter-input:focus,
.filter-select:focus { border-color: var(--brand-mid); }

.filter-select {
  cursor: pointer;
  appearance: none;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="%23065F46" stroke-width="2.5"><polyline points="6 9 12 15 18 9"/></svg>');
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}

.filter-reset { font-size: .85rem; padding: 10px 18px; }

/* ─── Table header + tabs + listing (clients, devis, factures) ──── */
.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.table-title {
  font-family: var(--font-heading);
  font-weight: var(--weight-bold);
  color: var(--gray-900);
  margin: 0;
  font-size: 1.05rem;
}

.table-header-right {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.table-tabs {
  display: flex;
  gap: 6px;
  background: var(--gray-100);
  padding: 4px;
  border-radius: var(--radius-sm);
}

.table-tab {
  padding: 6px 14px;
  background: transparent;
  border: none;
  border-radius: 6px;
  font-family: var(--font-heading);
  font-weight: var(--weight-semibold);
  font-size: .82rem;
  color: var(--gray-600);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.table-tab:hover { color: var(--brand-dark); }
.table-tab.active {
  background: white;
  color: var(--brand-dark);
  box-shadow: var(--shadow-sm);
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.t-center { text-align: center; }
.t-right  { text-align: right; }

/* ─── Row actions (boutons icône 32×32 ou 34×34) ───────────────── */
.row-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.row-actions button,
.row-actions a {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  cursor: pointer;
  font-size: .9rem;
  color: var(--gray-700);
  text-decoration: none;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}
.row-actions button:hover,
.row-actions a:hover {
  border-color: var(--brand-mid);
  background: var(--brand-50);
  color: var(--brand);
}
.row-actions button:disabled { opacity: .5; cursor: not-allowed; }

.row-actions button.danger:hover {
  border-color: #fca5a5;
  background: #fef2f2;
  color: #dc2626;
}

/* ─── Banner d'aide fermable (utilisé par <mda-tut-banner>) ───── */
.tut-banner {
  position: relative;
  background: #FEF3C7;
  border: 1px solid #FCD34D;
  border-radius: var(--radius);
  padding: 16px 40px 16px 18px;
  font-size: .88rem;
  color: #78350F;
}
.tut-banner h4 {
  margin: 0 0 8px;
  font-size: .95rem;
  font-weight: var(--weight-bold);
  font-family: var(--font-heading);
  color: #78350F;
}
.tut-banner ul {
  margin: 0;
  padding-left: 20px;
  line-height: 1.6;
}
.tut-banner code {
  background: white;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: .78rem;
  color: #78350F;
}
.tut-dismiss {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: #92400E;
  line-height: 1;
  padding: 4px 10px;
  border-radius: 6px;
}
.tut-dismiss:hover { background: rgba(0, 0, 0, .05); }

/* ─── Responsive (tablet & mobile) ───────────────────────────────── */
@media (max-width: 1024px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-toggle { display: flex; }
  .sidebar-overlay.open { display: block; }

  .main-content {
    margin-left: 0;
    padding: 16px;
    padding-top: 70px; /* place pour le sidebar-toggle */
  }

  .topbar {
    flex-wrap: wrap;
    margin-bottom: 20px;
  }
  .topbar h1 { font-size: 1.3rem; }
  .topbar-actions { width: 100%; }

  .topbar-search { min-width: 0; width: 100%; }
  .table-header { flex-direction: column; align-items: stretch; }
  .advanced-filters { padding: 12px 14px; }
}

@media (max-width: 480px) {
  .sidebar { width: min(85vw, 280px); }
  .topbar h1 { font-size: 1.15rem; }
  .stats-row { grid-template-columns: 1fr; }
  .stat-value { font-size: 1.5rem; }
  .filter-field { min-width: 0; flex: 1; }
}

/* ─── Bloc filtres avancés repliable (HTML5 <details>) ─────────────────
 * Pattern : <details class="filters-disclosure"> > <summary> + bloc.
 * Au repos, le bouton seul est visible. Au clic, le bloc se révèle.
 * Cohérent avec le legacy qui cache les filtres par défaut.
 * ─────────────────────────────────────────────────────────────── */
.filters-disclosure {
  margin-bottom: 20px;
}
.filters-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 8px 14px;
  background: white;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-weight: var(--weight-semibold);
  font-size: .85rem;
  color: var(--gray-700);
  list-style: none;
  user-select: none;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}
.filters-toggle::-webkit-details-marker { display: none; }
.filters-toggle::after {
  content: " ⌄";
  margin-left: 4px;
  transition: transform 0.2s ease;
}
.filters-disclosure[open] .filters-toggle::after {
  transform: rotate(180deg);
}
.filters-toggle:hover {
  background: var(--gray-50);
  border-color: var(--brand);
  color: var(--brand);
}
.filters-disclosure[open] .filters-toggle {
  border-color: var(--brand);
  color: var(--brand);
}
.filters-disclosure[open] .advanced-filters {
  margin-top: 12px;
}
