/* --- Charte Piffaudiere --- */
:root {
  --piff-dark: #182628;
  --piff-primary: #65CCB8;
  --piff-secondary: #57BA98;
  --piff-accent: #3B945E;
  --piff-bg: #F2F2F2;
}

body {
  background-color: var(--piff-bg);
}

.navbar {
  background: linear-gradient(135deg, var(--piff-dark), #1e3538) !important;
}

.navbar-brand {
  font-weight: 700;
  letter-spacing: 0.5px;
}

.card {
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  border-radius: 8px;
}

.table th {
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  color: #6c757d;
}

/* Auth pages */
.auth-container {
  max-width: 400px;
  margin: 80px auto;
}

.auth-container h2 {
  font-weight: 700;
  color: var(--piff-dark);
}

/* Bootstrap overrides — charte Piff */
.btn-primary { background-color: var(--piff-secondary); border-color: var(--piff-secondary); }
.btn-primary:hover, .btn-primary:active { background-color: var(--piff-accent); border-color: var(--piff-accent); }
.btn-outline-primary { color: var(--piff-secondary); border-color: var(--piff-secondary); }
.btn-outline-primary:hover { background-color: var(--piff-secondary); border-color: var(--piff-secondary); color: #fff; }
.btn-success { background-color: var(--piff-accent); border-color: var(--piff-accent); }
.btn-success:hover, .btn-success:active { background-color: #2d7a4a; border-color: #2d7a4a; }
.btn-outline-success { color: var(--piff-accent); border-color: var(--piff-accent); }
.btn-outline-success:hover { background-color: var(--piff-accent); border-color: var(--piff-accent); color: #fff; }
a { color: var(--piff-accent); }
a:hover { color: var(--piff-dark); }
.badge.bg-primary { background-color: var(--piff-secondary) !important; }
.badge.bg-success { background-color: var(--piff-accent) !important; }
.text-primary { color: var(--piff-secondary) !important; }

/* Status badges reseau */
.status-ok { color: var(--piff-accent); }
.status-ko { color: #dc3545; }

/* Responsive table */
@media (max-width: 768px) {
  .table-responsive .btn-sm {
    padding: 0.15rem 0.35rem;
    font-size: 0.8rem;
  }
}

/* PWA install prompt */
.pwa-install {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1050;
}

/* --- Offline / Sync styles --- */

/* Indicateur hors ligne (pulse) */
#offlineIndicator {
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* Enregistrements en attente de sync */
.sync-pending {
  border-left: 3px solid #ffc107 !important;
}
.sync-badge {
  font-size: 0.7rem;
}

/* Bouton sync : rotation pendant la sync */
.sync-spinning {
  animation: spin 1s linear infinite;
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Elements desactives en mode offline */
.offline-disabled {
  opacity: 0.4;
  pointer-events: none;
  cursor: not-allowed;
}

/* --- Leaflet / Cartes --- */
#geoMapContainer .leaflet-pane,
#pleinsMapSummary .leaflet-pane,
#stationsMap .leaflet-pane {
  z-index: 1;
}
#geoMapContainer .leaflet-control,
#pleinsMapSummary .leaflet-control,
#stationsMap .leaflet-control {
  z-index: 2;
}
@media (max-width: 768px) {
  #geoMapContainer { height: 200px !important; }
  #stationsMap { height: 350px !important; }
  #baladeMap { height: 250px !important; }
  #baladeViewMap { height: 250px !important; }
  .animal-card img { height: 100px; }
}

/* --- Animaux --- */
.animal-card img { height: 150px; object-fit: cover; }
.animal-card .badge { font-size: 0.75rem; }

/* Categories depenses */
.cat-alimentation { color: var(--piff-accent); }
.cat-veterinaire { color: #dc3545; }
.cat-accessoires { color: var(--piff-secondary); }
.cat-toilettage { color: #6f42c1; }

/* Balade recording */
.recording-timer { font-size: 2.5rem; font-weight: 700; font-family: monospace; }
.recording-distance { font-size: 1.5rem; }
#baladeMap,
#baladeViewMap { height: 350px; border-radius: 8px; overflow: hidden; border: 1px solid #dee2e6; }

/* Leaflet z-index fix balades */
#baladeMap .leaflet-pane,
#baladeViewMap .leaflet-pane { z-index: 1; }
#baladeMap .leaflet-control,
#baladeViewMap .leaflet-control { z-index: 2; }

/* --- Zone selector overlay (facture) --- */
.zone-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #fff;
  display: flex;
  flex-direction: column;
}
.zone-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--piff-dark);
  color: #fff;
  font-weight: 600;
  flex-shrink: 0;
}
.zone-canvas-wrap {
  flex: 1;
  overflow: auto;
  position: relative;
  background: #e9ecef;
  -webkit-overflow-scrolling: touch;
}
.zone-canvas-wrap canvas {
  display: block;
}
#zoneDrawCanvas {
  position: absolute;
  top: 0;
  left: 0;
  touch-action: none;
  cursor: crosshair;
}
.zone-footer {
  padding: 8px 12px;
  border-top: 1px solid #dee2e6;
  background: #f8f9fa;
  flex-shrink: 0;
  min-height: 48px;
}
.zone-footer code {
  display: inline-block;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
  font-size: 1rem;
  padding: 2px 6px;
  background: #e9ecef;
  border-radius: 4px;
}

/* --- Agenda / Calendar --- */
.calendar-grid { width: 100%; table-layout: fixed; border-collapse: collapse; }
.calendar-grid th { text-align: center; font-size: 0.75rem; color: #6c757d; padding: 4px; font-weight: 600; }
.calendar-grid td { vertical-align: top; height: 60px; border: 1px solid #e9ecef; padding: 4px; cursor: pointer; font-size: 0.85rem; }
.calendar-grid td:hover { background: #e0f5ef; }
.calendar-grid td.today { background: #d4f1e8; font-weight: 700; }
.calendar-grid td.other-month { color: #ccc; background: #fafafa; cursor: default; }
.calendar-grid td.selected { background: #b8e8d8; border-color: var(--piff-secondary); }
.calendar-grid .day-number { font-weight: 600; margin-bottom: 2px; }
.calendar-grid .event-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin: 0 1px; }
.calendar-grid .week-col { width: 28px; text-align: center; color: #adb5bd; font-size: 0.65rem; }
.calendar-grid .week-number { width: 28px; text-align: center; vertical-align: middle; font-size: 0.7rem; color: #adb5bd; border: none; background: transparent; cursor: default; height: auto; padding: 2px; }
.calendar-grid .week-number:hover { background: transparent; }
.calendar-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.calendar-nav h5 { margin: 0; text-transform: capitalize; }
.agenda-event-item { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-left: 3px solid; border-radius: 4px; margin-bottom: 6px; background: #fff; }
.agenda-event-item .event-time { font-size: 0.8rem; color: #6c757d; min-width: 45px; }
.agenda-event-item .event-title { font-weight: 500; flex: 1; }
.color-swatch { display: inline-block; width: 24px; height: 24px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; }
.color-swatch.active { border-color: #333; box-shadow: 0 0 0 2px #fff, 0 0 0 4px #333; }
@media (max-width: 768px) {
  .calendar-grid td { height: 45px; font-size: 0.75rem; padding: 2px; }
  .calendar-grid .event-dot { width: 5px; height: 5px; }
}

/* --- Parkinson --- */
.pk-btn { min-height: 60px; font-size: 1.3rem; font-weight: 700; border-radius: 12px; border: none; }
.pk-btn-on { background: var(--piff-accent); color: #fff; }
.pk-btn-on:hover, .pk-btn-on:active { background: #2d7a4a; color: #fff; }
.pk-btn-off { background: #dc3545; color: #fff; }
.pk-btn-off:hover, .pk-btn-off:active { background: #bb2d3b; color: #fff; }
.pk-btn-dys { background: #fd7e14; color: #fff; }
.pk-btn-dys:hover, .pk-btn-dys:active { background: #e96b08; color: #fff; }
.pk-btn-pris { background: var(--piff-accent); color: #fff; min-height: 48px; font-size: 1.1rem; font-weight: 600; border: none; border-radius: 10px; padding: 8px 16px; }
.pk-btn-pris:hover, .pk-btn-pris:active { background: #2d7a4a; color: #fff; }
.pk-state-banner { padding: 16px; border-radius: 12px; text-align: center; font-size: 1.2rem; font-weight: 600; }
.pk-timeline { height: 32px; border-radius: 6px; overflow: hidden; position: relative; background: #e9ecef; }
.pk-timeline-segment { height: 100%; position: absolute; }
.pk-med-card { border-left: 4px solid; border-radius: 8px; padding: 12px 16px; }
.pk-med-done { opacity: 0.55; }
.pk-input { font-size: 1.1rem; padding: 10px; }
.pk-chip { padding: 6px 10px; }

/* --- PTI (Protection Travailleur Isole) --- */
.pk-btn-pti { background: #dc3545; color: #fff; border: none; border-radius: 12px; font-weight: 700; }
.pk-btn-pti:hover, .pk-btn-pti:active { background: #bb2d3b; color: #fff; }
.pk-btn-sos { background: #dc3545; color: #fff; border: none; border-radius: 12px; font-weight: 700; animation: pti-pulse-sos 2s infinite; }
.pk-btn-sos:hover, .pk-btn-sos:active { background: #bb2d3b; color: #fff; }
.pk-btn-ok { background: var(--piff-accent); color: #fff; border: none; border-radius: 12px; font-weight: 700; }
.pk-btn-ok:hover, .pk-btn-ok:active { background: #2d7a4a; color: #fff; }

.pti-banner { padding: 24px; border-radius: 16px; text-align: center; color: #fff; }
.pti-banner-ok { background: linear-gradient(135deg, var(--piff-accent), var(--piff-secondary)); }
.pti-banner-alert { background: linear-gradient(135deg, #dc3545, #fd7e14); }

.pti-countdown-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(220, 53, 69, 0.95);
  display: flex; align-items: center; justify-content: center;
}
.pti-countdown-content {
  text-align: center; color: #fff; padding: 24px; max-width: 400px; width: 100%;
}
.pti-countdown-icon { font-size: 4rem; animation: pti-shake 0.5s infinite; }
.pti-countdown-number { font-size: 5rem; font-weight: 900; font-family: monospace; line-height: 1; margin: 8px 0; }

@keyframes pti-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}
@keyframes pti-pulse-sos {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.7); }
  50% { box-shadow: 0 0 0 12px rgba(220, 53, 69, 0); }
}

/* --- Home page --- */
.home-card { transition: transform 0.15s, box-shadow 0.15s; cursor: pointer; }
.home-card:hover { transform: translateY(-4px); box-shadow: 0 8px 25px rgba(0,0,0,0.1); }
.home-icon { font-size: 3.5rem; }
