/* =========================================================
   🎨 ERP Viticole — Thème principal VITI-GEST
   ========================================================= */

/* Reset & base */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
a {
  text-decoration: none;
  color: inherit;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: #222;
  background: #f5f7fa;
}

/* Layout global */
.app-shell {
  display: flex;
  flex-direction: row;
  min-height: 100vh;
  background: #f5f7fa;
}

/* ======================= SIDEBAR ======================= */

.sidebar {
  position: fixed;           /* collée à l’écran */
  top: 0;
  left: 0;
  width: 240px;
  height: 100vh;             /* toute la hauteur fenêtre */
  background: #1e2d1f;
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  flex-shrink: 0;
  overflow-y: auto;          /* scroll interne si menu long */
  z-index: 0;
}

/* Entête ULTRA compact : le moins de hauteur possible */
.sidebar-header {
  padding: 1rem 5rem 1rem 1rem; /* presque pas de bas */
  border-bottom: 1px solid #2c3b2d;
  display: flex;
  align-items: center;
}

.brand {
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  line-height: 1;           /* pas d’interligne ajouté */
}

/* Liste de boutons */
.menu {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;               /* zéro espace au-dessus du 1er bouton */
}

/* Chaque bouton de menu */
.menu a {
  display: block;
  padding: 0.6rem 1rem;     /* un peu plus compact qu’avant */
  color: #cdd8cd;
  transition: background 0.2s ease, color 0.2s ease;
}

/* assure qu'il n'y a pas de marge entre les liens */
.menu a + a {
  margin-top: 0;
}

.menu a:hover {
  background: #324634;
  color: #fff;
}

.menu a.active {
  background: #456e47;
  color: #fff;
  font-weight: 600;
  border-left: 4px solid #b5d7b7;
}

.sidebar-footer {
  text-align: center;
  padding: 0.8rem;
  font-size: 0.85rem;
  color: #9bb59d;
  border-top: 1px solid #2c3b2d;
  margin-top: auto;
}

/* =================== CONTENU PRINCIPAL =================== */

.main,
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: #fff;
  margin-left: 240px;    /* décale le contenu pour ne pas passer sous la sidebar */
}

.site-header {
  background: #ffffff;
  border-bottom: 1px solid #dbe2da;
  padding: 0.75rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.site-title {
  font-size: 1rem;
  font-weight: 600;
  color: #3a4d3b;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-label {
  color: #777;
}

.user-name {
  font-weight: 600;
}

.user-avatar {
  background: #456e47;
  color: #fff;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: 600;
}

/* Zone de page */
.page,
.page-content {
  flex: 1;
  padding: 1.5rem;
  background: #f8faf8;
  max-width: none;
  width: 100%;
  margin: 0;
}

.page-title {
  font-size: 1.35rem;
  margin-bottom: 1rem;
  color: #2e402f;
  border-bottom: 2px solid #d8e4da;
  padding-bottom: 0.25rem;
}

/* ================= TABLES / FORM / BOUTONS ================= */

table {
  border-collapse: collapse;
  width: 100%;
  background: #fff;
}

th,
td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid #e2e8e4;
}

th {
  background: #edf4ee;
  font-weight: 600;
  color: #2d3e2f;
}

tr:hover {
  background: #f7fbf8;
}

button,
.btn {
  background: #456e47;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  transition: background 0.2s ease;
}

button:hover,
.btn:hover {
  background: #588a5a;
}

/* version petite des boutons */
.btn-sm {
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
}

.btn-secondary {
  background: #667e68;
}

.btn-secondary:hover {
  background: #7d9b7f;
}

/* Messages Django */
.messages {
  margin-bottom: 1rem;
}

.alert {
  position: relative;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  margin-bottom: 0.5rem;
  border: 1px solid transparent;
  line-height: 1.3;
  font-size: 0.95rem;
}

.alert .alert-close {
  position: absolute;
  right: 0.6rem;
  top: 0.4rem;
  border: none;
  background: transparent;
  font-size: 1.1rem;
  cursor: pointer;
  color: #444;
}

.alert-success {
  background: #e6f7ee;
  border-color: #b7e2c7;
  color: #25442c;
}

.alert-error {
  background: #fdecea;
  border-color: #f5c2c0;
  color: #611a15;
}

.alert-warning {
  background: #fff8e1;
  border-color: #ffe2a8;
  color: #5b4100;
}

.alert-info {
  background: #eef5ff;
  border-color: #c9dcff;
  color: #1f3a60;
}

/* Accessibilité & inputs */
.menu a:focus {
  outline: 2px solid #88b694;
  outline-offset: 2px;
}

.menu a:focus-visible {
  outline: 2px solid #88b694;
  outline-offset: 2px;
}

input,
select,
textarea {
  font-family: inherit;
  font-size: 1rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 0.4rem 0.5rem;
  width: 100%;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #7bbf7e;
  outline: none;
  box-shadow: 0 0 0 2px rgba(88, 138, 90, 0.2);
}

/* Cards */
.card {
  background: #fff;
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.card-header {
  font-weight: 600;
  color: #2e402f;
  margin-bottom: 0.5rem;
}

/* ==================== PATCH LAYOUT GÉNÉRAL ==================== */

/* Fallback pour anciens templates */
.container,
.content,
.content-wrapper,
.wrapper,
.page-wrapper {
  width: 100%;
  max-width: none;      /* plus de limite à 1200px */
  margin: 0;            /* plus de centrage au milieu */
  padding: 1rem 2rem;   /* un peu d’air sur les côtés */
}

/* Tables larges: scroll horizontal propre */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.table-responsive table {
  min-width: 720px;
}

/* Images et iframes responsives */
img,
video {
  max-width: 100%;
  height: auto;
  display: block;
}

iframe {
  max-width: 100%;
}

/* ======================= RESPONSIVE ======================= */

@media (max-width: 768px) {
  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    position: static;     /* on redevient “normal” sur mobile */
    width: 100%;
    height: auto;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    overflow-y: visible;
  }

  .menu {
    flex-direction: row;
    gap: 0.25rem;
    padding: 0.5rem;
    overflow-x: auto;
  }

  .menu a {
    flex: 1;
    text-align: center;
    padding: 0.6rem;
  }

  .main,
  .main-content {
    margin-left: 0;       /* plus de sidebar fixe à gauche sur mobile */
  }

  .site-header {
    padding: 0.6rem 1rem;
  }

  .page,
  .page-content {
    max-width: none;
    margin: 0;
    padding: 1rem;
  }
}

/* Titres de sections du dashboard */
.dashboard-section-title {
  font-size: 1.1rem;
  font-weight: 600;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #2b3b2b;
  margin: 0;
  padding: 0.35rem 0.75rem;
  display: flex;
  align-items: center;
  gap: .35rem;
}

.dashboard-section-title span.icon {
  font-size: 2rem;
}

/* ======================= DESIGN SYSTÈME PAGES ======================= */

/* Section de page générique */
.page-section {
  padding: 1.5rem;
}

/* Header de page */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.page-subtitle {
  margin: 0;
  font-size: .9rem;
  color: #555;
}

.page-actions {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}

/* Bouton secondaire “pilule” */
.btn-pill-secondary {
  display: inline-block;
  padding: .45rem .9rem;
  border-radius: .75rem;
  border: 1px solid #d1d5db;
  font-size: .8rem;
  background: white;
  color: #555;
  text-decoration: none;
}

/* Grille de panneaux (3 colonnes responsives) */
.grid-panels-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}

/* Variantes de texte / liens */
.card-subtitle {
  margin: 0 0 .75rem 0;
  font-size: .8rem;
  color: #777;
}

.card-list {
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.item-card {
  border-radius: .75rem;
  border: 1px solid #e5e7eb;
  padding: .6rem .7rem;
}

.item-card-header {
  display: flex;
  justify-content: space-between;
  font-size: .85rem;
  gap: .5rem;
}

.item-card-meta {
  margin-top: .2rem;
  font-size: .8rem;
  color: #555;
}

.item-card-actions {
  margin-top: .35rem;
  display: flex;
  justify-content: flex-end;
  gap: .4rem;
  font-size: .75rem;
}

.item-card-date {
  font-size: .8rem;
  color: #666;
}

.link-muted {
  color: #2563eb;
  text-decoration: none;
}

.link-danger {
  color: #b91c1c;
  text-decoration: none;
}

.empty-text {
  font-size: .8rem;
  color: #999;
}

/* Chips / badges simples */
.chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin-bottom: 1rem;
}

.chips-row.small {
  font-size: .8rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: .18rem .55rem;
  border-radius: 999px;
  font-size: .75rem;
  background: #edf4ee;
  color: #2d3e2f;
}

.chip-muted {
  background: #e5e7eb;
  color: #555;
}

.chip-success {
  background: #e6f7ee;
  color: #25623a;
}

.chip-active {
  box-shadow: 0 0 0 1px #456e47 inset;
}
.item-card-appellation {
  font-style: italic;
  font-weight: 400;
  color: #6b7280;
  margin-left: 0.35rem;
}

/* Filtres */
.filters-card {
  margin-top: .75rem;
  margin-bottom: 1rem;
}

.filters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: .75rem 1rem;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: .2rem;
}
.filter-field.checkbox-field {
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
}
.filter-field.checkbox-field .filter-label {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  margin: 0;
}
.filter-field.checkbox-field .form-check-input {
  margin: 0;
}

.filter-label {
  font-size: .8rem;
  color: #777;
}

.filters-actions {
  margin-top: .75rem;
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}

/* Ligne de pagination */
.pagination-row {
  margin-top: 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .75rem;
  font-size: .85rem;
}

.pagination-row .page-links {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
}

/* Notes et détails dans les cards (parcelles) */
.item-card-title {
  margin: 0 0 .15rem 0;
  font-size: 1rem;
}

.link-strong {
  color: #2e402f;
  text-decoration: none;
}

.item-card-side {
  text-align: right;
  display: flex;
  flex-direction: column;
  gap: .25rem;
  align-items: flex-end;
}

.item-card-badge {
  font-weight: 600;
}

.item-card-notes {
  margin-top: .5rem;
  font-size: .8rem;
  color: #666;
}

/* =================== TRAVAUX — BOARD KANBAN =================== */

.kanban-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.25rem;
  align-items: flex-start;
  width: 100%;
}

@media (max-width: 900px) {
  .kanban-board {
    grid-template-columns: 1fr;
  }
}

.kanban-column {
  min-width: 0;
}

.kanban-column-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  color: #2e402f;
  font-size: 0.9rem;
  font-weight: 600;
}

.kanban-column-header h2 {
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin: 0;
}

.kanban-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.8rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.75rem;
  background: #e4ebe4;
  color: #435343;
}

.kanban-column-body {
  background: #f7f9f7;
  border-radius: 0.75rem;
  padding: 0.75rem;
  box-shadow: 0 0 0 1px #e2e6e2;
}

.kanban-card {
  background: #ffffff;
  border-radius: 0.75rem;
  padding: 0.6rem 0.7rem 0.55rem 0.7rem;
  margin-bottom: 0.6rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  border: 1px solid #e2e6e2;
  font-size: 0.85rem;
}

.kanban-card-done {
  opacity: 0.9;
}

.kanban-card-main {
  flex: 1;
  min-width: 0;
}

.kanban-card-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: #2e402f;
  margin: 0 0 0.2rem 0;
}

.kanban-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.4rem;
}

.kanban-card-actions .btn,
.kanban-card-actions .btn-pill-secondary {
  font-size: 0.8rem;
  padding: 0.25rem 0.6rem;
}

.kanban-empty {
  margin: 0.25rem 0;
  font-size: 0.85rem;
  color: #777;
  font-style: italic;
}

/* variantes de chips supplémentaires pour les compteurs travaux */
.chip-info {
  background: #eef5ff;
  color: #1f3a60;
}

.chip-warning {
  background: #fff8e1;
  color: #5b4100;
}
