:root {
  --green-dark: #1f3d2b;
  --green: #2f5d3a;
  --green-light: #e8f0e6;
  --brown: #6b4a30;
  --sand: #f6f3ec;
  --white: #ffffff;
  --text: #24291f;
  --text-muted: #6b7263;
  --border: #dfe3d8;
  --red: #b3402c;
  --amber: #b8860b;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  background: var(--sand);
  color: var(--text);
}

.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  background: var(--green-dark);
  color: var(--white);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  flex-shrink: 0;
}

.brand {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 0 8px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  margin-bottom: 14px;
}
.brand-icon { font-size: 26px; }
.brand-title { font-weight: 700; font-size: 16px; line-height: 1.2; }
.brand-sub { font-size: 11px; color: rgba(255,255,255,0.65); }

.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 6px 8px;
  margin: -6px 4px -6px -8px;
  border-radius: 8px;
}
.menu-toggle:hover { background: var(--green-light); }

.sidebar-close {
  display: none;
  margin-left: auto;
  background: none;
  border: none;
  color: rgba(255,255,255,0.8);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 20, 0.45);
  z-index: 55;
}
.sidebar-backdrop.show { display: block; }

#nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  font-size: 14px;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,0.08); }
.nav-item.active { background: var(--green); color: #fff; font-weight: 600; }
.nav-item.disabled {
  color: rgba(255,255,255,0.35);
  cursor: default;
}
.nav-item.disabled:hover { background: transparent; }
.nav-tag {
  margin-left: auto;
  font-size: 10px;
  background: rgba(255,255,255,0.12);
  padding: 2px 6px;
  border-radius: 999px;
}

.nav-icon {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.nav-item.active .nav-icon { background: rgba(255,255,255,0.18); }
.nav-item.disabled .nav-icon { background: rgba(255,255,255,0.05); }

.nav-section-title {
  color: rgba(255,255,255,0.4);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 16px 12px 6px;
}
.nav-section-title:first-child { padding-top: 4px; }

.sidebar-footer {
  font-size: 11px;
  color: rgba(255,255,255,0.4);
  padding: 10px 8px 0 8px;
  border-top: 1px solid rgba(255,255,255,0.12);
}

.content {
  flex: 1;
  padding: 20px 36px 28px;
  max-width: 1100px;
}

.utility-bar {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  min-height: 56px;
  padding: 0;
  margin: 0 0 18px;
  border-bottom: 1px solid var(--border);
  /* Reste visible pendant le defilement, pour garder Tableau de bord /
     Utilisateurs / Suivi accessibles sans remonter en haut de page. */
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--sand);
}
.top-links { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.top-link {
  background: none;
  border: none;
  padding: 0 0 4px 0;
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.top-link:hover { color: var(--text); }
.top-link.active { color: var(--text); font-weight: 600; border-bottom-color: var(--green); }
.suivi-quick-add {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: var(--green);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
}
.suivi-quick-add:hover { background: var(--green-dark); }

.suivi-alert-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-bottom: none !important;
  padding: 0 !important;
}
.suivi-alert-icon { font-size: 15px; }
.suivi-alert-badge {
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.utility-right { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.user-inline { display: flex; align-items: center; gap: 16px; }
.top-user-name { font-size: 13px; color: var(--text); }
.top-user-ecurie {
  display: block;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.user-menu { position: relative; display: flex; align-items: center; gap: 2px; }
.user-menu-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 10px;
  padding: 6px 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.user-menu-toggle:hover { color: var(--text); }
.user-menu-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 6px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 6px;
  min-width: 150px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 40;
}
.user-menu:hover .user-menu-dropdown,
.user-menu.open .user-menu-dropdown {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.user-menu-dropdown .top-link {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 8px;
  border-bottom: none;
  border-radius: 6px;
}
.user-menu-dropdown .top-link:hover { background: var(--green-light); color: var(--text); }

.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 22px;
}
.topbar h1 { margin: 0; font-size: 22px; flex: 1; }
.today { color: var(--text-muted); font-size: 13px; white-space: nowrap; }

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

.search-input {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 240px;
  font-size: 14px;
  background: var(--white);
}

.btn {
  padding: 9px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 14px;
  cursor: pointer;
  font-weight: 600;
}
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-dark); }
.btn-secondary { background: var(--white); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--green-light); }
.btn-danger { background: var(--white); border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.horse-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.horse-card {
  padding: 16px;
  cursor: pointer;
  transition: transform 0.1s ease;
}
.horse-card:hover { transform: translateY(-2px); border-color: var(--green); }
.horse-card h3 { margin: 0 0 4px 0; font-size: 16px; }
.horse-meta { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.horse-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag {
  font-size: 11px;
  background: var(--green-light);
  color: var(--green-dark);
  padding: 3px 8px;
  border-radius: 999px;
}
.tag-danger { background: #fbe4e0; color: var(--red); font-weight: 600; }
.tag-warning { background: #fbf1d9; color: var(--amber); font-weight: 600; }
.tag-ok { background: var(--green-light); color: var(--green-dark); }

.alert-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.alert-row:last-child { border-bottom: none; }
.alert-row:hover { background: var(--green-light); }
.alert-row .alert-title { font-weight: 600; font-size: 14px; }
.alert-row .alert-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  padding: 16px;
}
.stat-card .stat-value { font-size: 26px; font-weight: 700; }
.stat-card .stat-label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.dashboard-greeting { font-size: 22px; font-weight: 700; margin: 0; }
.dashboard-greeting-sub { font-size: 13px; color: var(--text-muted); margin: 2px 0 20px; }

.tile-section-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 10px;
}
.tile-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 22px;
}
.tile {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 12px;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.1s ease;
}
.tile:hover { transform: translateY(-2px); border-color: var(--green); }
.tile-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--green-light);
  color: var(--green-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  margin: 0 auto 10px;
}
.tile-label { font-size: 12px; font-weight: 600; color: var(--text); }

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
  padding: 20px;
}
.form-grid .full { grid-column: 1 / -1; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--white);
}
.field textarea { resize: vertical; min-height: 60px; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 20, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal {
  background: var(--white);
  border-radius: var(--radius);
  width: min(560px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h2 { margin: 0; font-size: 17px; }
.modal-close {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-muted);
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 18px;
}
.detail-header h2 { margin: 0 0 4px 0; }
.back-link {
  background: none;
  border: none;
  color: var(--green);
  cursor: pointer;
  font-size: 13px;
  padding: 0 0 12px 0;
  font-weight: 600;
}
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 24px;
  padding: 18px 20px;
}
.detail-item .label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.detail-item .value { font-size: 14px; margin-top: 2px; }
.detail-item.full { grid-column: 1 / -1; }

.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 24px 0 8px 2px;
}

/* Module Suivi (tableau Kanban). */
.suivi-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  align-items: start;
}
.suivi-column-header {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.suivi-column-count {
  background: var(--border);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 1px 7px;
  font-weight: 600;
  font-size: 11px;
}
.suivi-column-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 40px;
}
.suivi-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  cursor: pointer;
}
.suivi-card-urgent { border-left: 3px solid var(--red); }
.suivi-card-title { font-size: 14px; font-weight: 600; margin: 8px 0 4px; line-height: 1.3; }
.suivi-card-cheval { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.suivi-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: 8px;
  gap: 8px;
}
.suivi-card-actions { display: flex; gap: 6px; margin-top: 10px; }
.suivi-card-actions .btn { flex: 1; }

.suivi-comment {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.suivi-comment:last-child { border-bottom: none; }
.suivi-comment-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 3px;
}
.suivi-comment-del {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
}
.suivi-comment-del:hover { color: var(--red); }
.suivi-comment-texte { font-size: 13px; }

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--green-dark);
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.2s ease;
  pointer-events: none;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--red); }

.hidden { display: none !important; }

.auth-screen {
  position: fixed;
  inset: 0;
  background: var(--sand);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.auth-wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.auth-card { width: min(380px, 92vw); padding: 30px 26px; }
.auth-card .brand { border-bottom: none; padding: 0 0 20px 0; margin-bottom: 6px; color: var(--text); }
.auth-card .brand-title { color: var(--text); font-size: 18px; }
.auth-card .brand-sub { color: var(--text-muted); }
.auth-card h1 { margin: 0 0 4px 0; font-size: 18px; }
.auth-card .auth-sub { color: var(--text-muted); font-size: 13px; margin-bottom: 18px; line-height: 1.4; }
.auth-card .field { margin-bottom: 14px; }
.auth-card .btn { width: 100%; }
.auth-card .auth-error { color: var(--red); font-size: 13px; margin: -6px 0 12px 0; }
.auth-link {
  background: none;
  border: none;
  color: var(--green);
  cursor: pointer;
  font-size: 13px;
  padding: 10px 0 0 0;
  width: 100%;
  text-align: center;
}
.auth-link:hover { text-decoration: underline; }

/* Panneau "connexion rapide", uniquement affiche sur le bac a sable (voir
   sandboxDisponible dans app.js) -- accent ambre pour bien le distinguer
   visuellement d'un vrai ecran de connexion. */
.auth-sandbox {
  width: min(380px, 92vw);
  padding: 14px 16px;
  border: 1px dashed var(--amber);
  border-radius: var(--radius);
  background: #fbf1d9;
}
.auth-sandbox-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 10px;
}
.auth-sandbox-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.auth-sandbox-grid .btn { width: 100%; }

.auth-sandbox-ecuries { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.auth-sandbox-pill {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
}
.auth-sandbox-pill.active { background: var(--green-dark); border-color: var(--green-dark); color: #fff; font-weight: 600; }


/* Sous 900px, OU sur tout ecran tactile quelle que soit sa largeur (un iPad
   en paysage depasse souvent 900px mais reste un ecran tactile ou la
   sidebar fixe prend une place precieuse) : le menu devient un tiroir qui
   glisse par-dessus le contenu plutot que de pousser tout en pleine largeur
   en haut de l'ecran. */
@media (max-width: 900px), (pointer: coarse) {
  .menu-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .sidebar-close { display: block; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(280px, 82vw);
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 4px 0 18px rgba(0,0,0,0.18);
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }
  .topbar { align-items: center; }
}

@media (max-width: 720px) {
  .app { flex-direction: column; }
  .content { padding: 14px 18px 18px; }
  .form-grid, .detail-grid { grid-template-columns: 1fr; }
  .today { display: none; }
  .tile-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .suivi-board { grid-template-columns: 1fr; }
}

/* Cibles tactiles agrandies sur les ecrans a doigt (tablette/mobile),
   independamment de la largeur d'ecran -- un mode paysage large reste
   tactile. Les zones interactives tres denses (grille Entrainements, plan
   Localisation) restent a leur propre echelle, geree au cas par cas. */
@media (pointer: coarse) {
  .btn { padding: 11px 18px; min-height: 44px; }
  .btn-sm { padding: 9px 14px; min-height: 38px; }
  .nav-item { padding: 13px 12px; min-height: 44px; }
  .field input, .field select, .field textarea { padding: 11px 12px; }
}
