/* Theme sombre fixe (avec photo) : c'est l'esthetique concue pour l'app,
   volontairement independante du reglage clair/sombre du telephone pour
   que la photo et les accents rouges s'affichent toujours. */
:root {
  --bg: #0f1115;
  --surface: #1a1d24;
  --surface-2: #23272f;
  --text: #eef0f3;
  --text-muted: #96a0af;
  --border: #2c313b;
  --primary: #3b82f6;
  --primary-dark: #60a5fa;
  --accent: #22d3ee;
  --success-bg: #113322;
  --success-text: #6ee7a3;
  --error-bg: #3a1414;
  --error-text: #fca5a5;
  --danger: #f87171;
  --select-accent: #e6394f;
  --radius: 14px;
  --radius-sm: 9px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html { background: transparent; }

body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background-color: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* Photo d'arriere-plan (camion), toujours visible : les cartes "verre
   depoli" flottent par-dessus. */
body {
  background-image:
    linear-gradient(180deg, rgba(8, 9, 12, 0.3) 0%, rgba(8, 9, 12, 0.5) 45%, rgba(8, 9, 12, 0.72) 100%),
    url('/images/hero-truck.jpg');
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  background-attachment: fixed;
}

a { color: var(--primary); }

h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 0.75rem; }

/* Les h1 flottent directement sur la photo de fond (hors carte) : on
   garantit leur lisibilite quel que soit le contenu de la photo derriere. */
h1 { text-shadow: 0 2px 16px rgba(0, 0, 0, 0.85), 0 1px 3px rgba(0, 0, 0, 0.9); }

.muted { color: var(--text-muted); }
.hint { color: var(--text-muted); font-size: 0.85rem; margin: 0.25rem 0 0.75rem; }

/* ---------- Layout ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(0.75rem + var(--safe-top)) 1rem 0.75rem;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-title {
  font-weight: 700;
  font-size: 1.1rem;
}

.topbar-actions { display: flex; gap: 0.4rem; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: none;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
}
.icon-btn svg { width: 19px; height: 19px; }

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem 1rem calc(6rem + var(--safe-bottom));
}

.bottomnav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}

.bottomnav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 0.5rem 0 0.4rem;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 600;
}
.bottomnav a svg { width: 22px; height: 22px; }
.bottomnav a.active { color: var(--primary); }

/* ---------- Auth ---------- */

.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.auth-card {
  width: 100%;
  max-width: 360px;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
  text-align: center;
}
.auth-card h1 { margin-bottom: 0.25rem; }
.auth-card p { margin-top: 0; }
.auth-card form { text-align: left; margin-top: 1.25rem; }

/* ---------- Forms ---------- */

.stack { display: flex; flex-direction: column; gap: 0.9rem; }

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

input[type="text"], input[type="password"], input[type="date"], input[type="time"], input[type="month"],
input[type="number"], textarea, select {
  font: inherit;
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

textarea { resize: vertical; font-family: inherit; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.75rem; }
@media (max-width: 480px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.7rem 1.1rem;
  border-radius: var(--radius-sm);
  border: none;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-ghost { background: var(--surface-2); color: var(--text); }
.btn-danger { color: var(--danger); }
.btn-block { width: 100%; }
.btn-lg { padding: 0.9rem 1.1rem; font-size: 1.02rem; }
.btn-icon { width: 42px; height: 42px; padding: 0; flex-shrink: 0; }

.chip {
  display: inline-block;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.8rem;
  text-decoration: none;
  margin-bottom: 0.75rem;
}

/* ---------- Alerts ---------- */

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}
.alert-success { background: var(--success-bg); color: var(--success-text); }
.alert-error { background: var(--error-bg); color: var(--error-text); }

/* ---------- Cards ---------- */

.card {
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: blur(10px);
  border-radius: var(--radius);
  padding: 1.1rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
}

/* ---------- Date nav ---------- */

.date-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.date-nav-form { display: flex; flex-direction: column; align-items: center; gap: 0.2rem; flex: 1; }
.date-nav-form input[type="date"], .date-nav-form input[type="month"] { text-align: center; max-width: 200px; }
.date-nav-label { font-weight: 700; text-align: center; font-size: 0.95rem; }

/* ---------- Dashboard readout bars (temps de travail, estimation) ---------- */

.dash-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: linear-gradient(135deg, rgba(24, 26, 32, 0.94), rgba(24, 26, 32, 0.8));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  padding: 0.95rem 1.1rem;
  margin-top: 0.6rem;
  color: #fff;
}
.dash-bar-label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.7rem;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.62);
}
.dash-bar-label svg { width: 15px; height: 15px; flex-shrink: 0; }
.dash-bar-value { font-size: 1.5rem; font-weight: 800; white-space: nowrap; }
.dash-bar-value.accent-blue { color: #5b9dff; }
.dash-bar-value.accent-red { color: var(--select-accent); }

/* ---------- Meal cards ---------- */

.meal-section { margin-bottom: 1.1rem; }
.meal-section:last-of-type { margin-bottom: 0; }
.meal-section-title {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
}
.meal-section-title svg { width: 15px; height: 15px; }

.meal-grid-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }

.meal-card {
  position: relative;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.6rem;
  padding: 0.85rem 0.9rem;
  border-radius: 18px;
  border: 1.5px solid var(--border);
  background: color-mix(in srgb, var(--surface) 75%, transparent);
  backdrop-filter: blur(6px);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease, transform 0.1s ease;
}
.meal-card:active { transform: scale(0.97); }
.meal-card input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  margin: 0;
}
.meal-card svg { width: 22px; height: 22px; flex-shrink: 0; color: var(--text-muted); transition: color 0.15s ease; }
.meal-card span { font-weight: 700; font-size: 0.92rem; line-height: 1.2; color: var(--text); transition: color 0.15s ease; }

.meal-card.is-checked {
  border-color: var(--select-accent);
  background: color-mix(in srgb, var(--select-accent) 18%, var(--surface) 65%);
}
.meal-card.is-checked svg,
.meal-card.is-checked span { color: var(--select-accent); }

.checkbox-row {
  flex-direction: row;
  align-items: center;
  gap: 0.6rem;
}
.checkbox-row input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--primary); flex-shrink: 0; }
.checkbox-row span { font-weight: 500; color: var(--text); }

.chip-inline {
  margin-bottom: 0;
  padding: 0.1rem 0.5rem;
  font-size: 0.7rem;
  font-weight: 700;
  color: #fff;
  background: var(--select-accent);
  vertical-align: middle;
}

.filter-chips { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.filter-chip {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 75%, transparent);
  border: 1.5px solid var(--border);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}
.filter-chip input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  margin: 0;
}
.filter-chip:has(input:checked) {
  border-color: var(--select-accent);
  background: color-mix(in srgb, var(--select-accent) 18%, var(--surface) 65%);
  color: var(--select-accent);
}

/* ---------- Entry list ---------- */

.entry-list { display: flex; flex-direction: column; gap: 0.5rem; }
.entry-row, .entry-row-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  text-decoration: none;
  color: inherit;
}
.entry-row {
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
}
.entry-row-link { flex: 1; min-width: 0; }
.entry-row-date { display: flex; flex-direction: column; gap: 0.15rem; }
.entry-row-date span { font-size: 0.8rem; }
.entry-row-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 0.15rem; font-size: 0.82rem; }
.entry-row-delete { flex-shrink: 0; }

.pagination { display: flex; align-items: center; justify-content: space-between; margin-top: 1rem; }

/* ---------- Stats ---------- */

.tabs { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.tab {
  flex: 1;
  text-align: center;
  padding: 0.55rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 700;
}
.tab.active { background: var(--primary); color: #fff; }

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.stat-tile {
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.stat-tile-accent { border-color: var(--accent); }
.stat-value { font-size: 1.25rem; font-weight: 800; }
.stat-label { font-size: 0.75rem; color: var(--text-muted); }

/* ---------- Tables ---------- */

.table-full { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.table-full th, .table-full td { padding: 0.5rem 0.4rem; border-bottom: 1px solid var(--border); text-align: left; }
.table-full tfoot td { border-top: 2px solid var(--border); border-bottom: none; font-weight: 600; }
.table-full .total-row td { font-size: 1rem; color: var(--primary); }
.muted-row { color: var(--text-muted); }

.table-compact { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.table-compact td { padding: 0.4rem 0.3rem; border-bottom: 1px solid var(--border); }
.table-compact td:last-child { text-align: right; font-weight: 600; }

/* ---------- Disclosure ---------- */

.disclosure { margin-top: 1rem; }
.disclosure summary { cursor: pointer; font-weight: 700; color: var(--primary); padding: 0.4rem 0; }
.disclosure form { margin-top: 0.75rem; }

/* ---------- Bar chart ---------- */

.bar-chart {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.5rem;
  height: 140px;
  padding-top: 1rem;
}
.bar-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; flex: 1; height: 100%; gap: 0.25rem; }
.bar { width: 60%; min-width: 18px; background: var(--accent); border-radius: 6px 6px 0 0; }
.bar-value { font-size: 0.7rem; font-weight: 700; }
.bar-label { font-size: 0.65rem; color: var(--text-muted); }

@media (min-width: 640px) {
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
}
