/* BMS Service Dashboard — Responsive iOS-inspired */
:root {
  color-scheme: light;
  --primary: #d62c2c;
  --primary-dark: #b91c1c;
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #1c1c1e;
  --text-secondary: #8e8e93;
  --text-tertiary: #6b7280;
  --separator: #e5e5ea;
  --blue: #007aff;
  --green: #34c759;
  --orange: #ff9500;
  --red: #ff3b30;
  --purple: #af52de;
  --yellow: #ffcc00;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 20px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  font-size: 16px;
  line-height: 1.5;
}

body {
  padding-bottom: calc(env(safe-area-inset-bottom) + 40px);
  min-height: 100vh;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ---- Header ---- */
.hero {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  padding: calc(env(safe-area-inset-top) + 24px) 0 24px;
  margin-bottom: 16px;
  position: relative;
}
.hero .container { padding: 0 16px; }
.hero-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.hero h1 { font-size: 26px; font-weight: 700; }
.hero-subtitle { opacity: 0.85; font-size: 13px; }

.refresh-btn {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  width: 38px; height: 38px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  transition: transform 0.5s ease, background 0.15s;
}
.refresh-btn:active { background: rgba(255,255,255,0.4); }
.refresh-btn.spinning { animation: spin 1s linear infinite; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* ---- Sections ---- */
section { margin-bottom: 24px; }
.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  font-weight: 600;
  margin-bottom: 8px;
  padding-left: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.count-badge {
  background: var(--separator);
  color: var(--text-tertiary);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.count-badge.danger { background: #fee; color: var(--red); }
.count-badge.warning { background: #fff3e0; color: var(--orange); }
.count-badge.success { background: #e8f8ed; color: var(--green); }

/* ---- Stats grid ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}
@media (min-width: 600px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
}
.stat {
  background: var(--card);
  padding: 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.stat-label { font-size: 11px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
.stat-value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.stat.danger .stat-value { color: var(--red); }
.stat.warning .stat-value { color: var(--orange); }
.stat.success .stat-value { color: var(--green); }

/* ---- Cards ---- */
.dossier-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  position: relative;
}
.dossier-card.urgent { border-left: 4px solid var(--red); }
.dossier-card.warning { border-left: 4px solid var(--orange); }
.dossier-card.success { border-left: 4px solid var(--green); }
.dossier-card.info { border-left: 4px solid var(--blue); }

.dossier-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 6px; }
.dossier-client { font-size: 17px; font-weight: 600; }
.dossier-meta { font-size: 13px; color: var(--text-secondary); line-height: 1.5; margin-bottom: 8px; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.badge-attente { background: #fff3e0; color: var(--orange); }
.badge-cours { background: #e3f2ff; color: var(--blue); }
.badge-devis-envoye { background: #f3e8ff; color: var(--purple); }
.badge-devis-signe { background: #e8f8ed; color: var(--green); }
.badge-intervention-faite { background: #d4f4dd; color: var(--green); }
.badge-facture-envoyee { background: #fff8d4; color: #b8860b; }
.badge-payee { background: #d4f4dd; color: var(--green); }
.badge-cloture { background: var(--separator); color: var(--text-tertiary); }
.badge-relance { background: #ffe5e5; color: var(--red); }

.dossier-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.action-btn {
  flex: 1 1 auto;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: opacity 0.15s;
  min-width: 120px;
}
.action-btn:active { opacity: 0.6; }
.action-btn-primary { background: var(--blue); color: white; }
.action-btn-success { background: var(--green); color: white; }
.action-btn-secondary { background: var(--separator); color: var(--text); }
.action-btn-link { background: transparent; color: var(--blue); padding: 10px 0; }

/* ---- Empty state ---- */
.empty {
  background: var(--card);
  padding: 32px 16px;
  text-align: center;
  color: var(--text-secondary);
  border-radius: var(--radius);
  font-size: 14px;
}
.empty-icon { font-size: 32px; margin-bottom: 8px; }

/* ---- Procès card ---- */
.proces-card {
  background: linear-gradient(135deg, var(--orange) 0%, #ea580c 100%);
  color: white;
  padding: 22px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  text-align: center;
  box-shadow: var(--shadow-md);
}
.proces-card.urgent { background: linear-gradient(135deg, var(--red) 0%, #991b1b 100%); }
.proces-countdown { font-size: 56px; font-weight: 800; line-height: 1; }
.proces-label { font-size: 13px; opacity: 0.9; margin-top: 6px; }
.proces-info { font-size: 14px; margin-top: 14px; opacity: 0.95; }

/* ---- Portfolio table ---- */
.portfolio-card {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.portfolio-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--separator);
}
.portfolio-row:last-child { border-bottom: none; }
.portfolio-row-label { font-size: 15px; color: var(--text); }
.portfolio-row-value { font-size: 17px; font-weight: 600; }

/* ---- Footer ---- */
footer {
  text-align: center;
  color: var(--text-secondary);
  font-size: 12px;
  padding: 32px 16px 16px;
}
footer p { margin-bottom: 4px; }

/* ---- Bottom sheet ---- */
.sheet-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  align-items: flex-end;
  justify-content: center;
}
.sheet-overlay.active { display: flex; animation: fadeIn 0.2s; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  background: var(--bg);
  width: 100%;
  max-width: 720px;
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 16px);
  max-height: 85vh;
  overflow-y: auto;
  animation: slideUp 0.3s cubic-bezier(0.2, 0.9, 0.3, 1);
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-handle {
  width: 40px; height: 5px;
  background: var(--separator);
  border-radius: 999px;
  margin: 0 auto 14px;
}
.sheet h3 { font-size: 18px; text-align: center; margin-bottom: 4px; }
.sheet-subtitle { font-size: 13px; color: var(--text-secondary); text-align: center; margin-bottom: 16px; }
.sheet-actions { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.sheet-actions a, .sheet-actions button {
  display: block;
  padding: 14px;
  background: var(--card);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--blue);
  font-size: 16px;
  font-weight: 500;
  text-align: center;
  border: none;
  cursor: pointer;
  width: 100%;
}
.sheet-actions a.danger, .sheet-actions button.danger { color: var(--red); }
.sheet-cancel {
  width: 100%;
  background: var(--card);
  border: none;
  padding: 14px;
  border-radius: var(--radius-sm);
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  margin-top: 8px;
}

/* ---- Loading ---- */
.loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--separator);
  border-top-color: var(--primary);
  border-radius: 50%;
  margin: 0 auto 16px;
  animation: spin 0.8s linear infinite;
}

/* ---- Desktop tweaks ---- */
@media (min-width: 900px) {
  .container { padding: 0 24px; }
  .hero h1 { font-size: 32px; }
  .hero-subtitle { font-size: 15px; }
}
