:root {
  --accent: #fb5066;
  --accent-dark: #c22e42;
  --bg: #faf8f6;
  --card-bg: #ffffff;
  --border: #e6e1dd;
  --text: #2b2b2b;
  --muted: #6b6b6b;
  --today-bg: #fff4f0;
}

* { box-sizing: border-box; }

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

.site-header {
  background: var(--accent);
  color: white;
  padding: 1.25rem 1rem;
}
.site-header h1 { margin: 0 0 0.25rem; font-size: 1.3rem; }
.site-header .subtitle { margin: 0; font-size: 0.85rem; opacity: 0.9; }
.site-header a { color: white; text-decoration: underline; }

main { max-width: 1200px; margin: 0 auto; padding: 1rem; }

.week-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.week-nav a {
  color: var(--accent-dark);
  text-decoration: none;
  font-weight: 600;
}
.week-nav a:hover { text-decoration: underline; }
.week-nav .today-link {
  background: var(--accent);
  color: white;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
}

.week-grid {
  display: grid;
  /* minmax(0, ...) lets a column shrink below its content's min width —
     otherwise one long unwrappable location widens the whole grid. */
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.6rem;
}

.day-column {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.day-column.is-today {
  background: var(--today-bg);
  border-color: var(--accent);
}

.day-header {
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.35rem;
  margin-bottom: 0.15rem;
}
.day-header .weekday { font-weight: 700; font-size: 0.85rem; text-transform: uppercase; }
.day-header .daynum { color: var(--muted); font-size: 0.8rem; }

.empty-day { color: var(--border); font-size: 0.85rem; margin: 0.5rem 0 0; }

.event-card {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  text-decoration: none;
  color: var(--text);
  font-size: 0.82rem;
  line-height: 1.25;
  /* Background/border are tinted from the source's own color (see the
     event-source--* rules below) so a card visually matches its legend dot. */
  background: color-mix(in srgb, var(--source-color, var(--muted)) 18%, white);
  border-left: 3px solid var(--source-color, var(--muted));
}
.event-card:hover { filter: brightness(0.97); }

.banner-event { font-weight: 600; }

.banner-overflow {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.banner-overflow summary {
  cursor: pointer;
  list-style: none;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent-dark);
  padding: 0.15rem 0.2rem;
}
.banner-overflow summary::-webkit-details-marker { display: none; }
.banner-overflow summary:hover { text-decoration: underline; }
.banner-overflow[open] summary { margin-bottom: 0.1rem; }
.banner-overflow .event-card { margin-top: 0; }

.event-time {
  font-weight: 700;
  color: var(--accent-dark);
  font-size: 0.78rem;
}
.event-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.1rem;
}
.event-meta,
.event-title,
.event-location { min-width: 0; }
.event-title { overflow-wrap: anywhere; }
.event-location {
  color: var(--muted);
  font-size: 0.75rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.event-source {
  width: 7px;
  height: 7px;
  margin-left: auto;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--source-color, var(--muted));
}
/* Colors are set inline per source_id (see app/services/source_registry.py)
   rather than declared per-class here — a dynamic source (a WhatsApp group)
   gets one automatically without touching this file. */

.source-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1.2rem;
  margin: 1.5rem 0 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}
.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--source-color, var(--muted));
}

.site-footer {
  text-align: center;
  padding: 1.5rem 1rem 2.5rem;
}
.site-footer a {
  color: var(--accent-dark);
  font-weight: 600;
  text-decoration: none;
}
.site-footer a:hover { text-decoration: underline; }
.site-footer .footer-sep { color: var(--border); margin: 0 0.5rem; }

.sources-picker {
  max-width: 480px;
  margin: 2rem auto;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
}
.sources-picker h2 { margin-top: 0; font-size: 1.1rem; }
.sources-subheading { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.sources-hint { color: var(--muted); font-size: 0.85rem; margin-top: -0.5rem; }
.source-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  border-bottom: 1px solid var(--border);
}
.source-choice {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.2rem;
  font-size: 0.95rem;
  cursor: pointer;
  flex: 1;
}
.event-type-choice { border-bottom: 1px solid var(--border); }
.source-choice input { width: 1.1rem; height: 1.1rem; flex-shrink: 0; accent-color: var(--accent); }
.source-order-buttons { display: flex; gap: 0.3rem; flex-shrink: 0; }
.order-btn {
  width: 1.8rem;
  height: 1.8rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: white;
  border-radius: 6px;
  color: var(--accent-dark);
  font-size: 0.9rem;
  text-decoration: none;
  cursor: pointer;
}
.order-btn:hover:not(:disabled) { background: var(--today-bg); }
.order-btn:disabled { color: var(--border); cursor: default; }
.delete-link { color: var(--muted); font-size: 0.8rem; }
.delete-link:hover { background: #fbe4e4; color: #c22e42; }
.sources-submit {
  margin-top: 1.2rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 999px;
  padding: 0.6rem 1.4rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}
.sources-submit:hover { background: var(--accent-dark); }
.danger-btn {
  margin-top: 1.2rem;
  background: #c22e42;
  color: white;
  border: none;
  border-radius: 999px;
  padding: 0.6rem 1.4rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}
.danger-btn:hover { background: #9c1f31; }

/* Mobile: stack days vertically instead of a cramped 7-col grid */
@media (max-width: 900px) {
  .week-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Phone ergonomics (also applies when installed as a home-screen app) */
html { -webkit-text-size-adjust: 100%; }
a, button, summary, label { -webkit-tap-highlight-color: rgba(251, 80, 102, 0.15); }

/* Keep content clear of the notch / home indicator in standalone mode */
.site-header { padding-top: max(1.25rem, env(safe-area-inset-top)); }
.site-footer { padding-bottom: max(2.5rem, calc(env(safe-area-inset-bottom) + 1rem)); }

@media (max-width: 600px) {
  main { padding: 0.75rem; }

  /* Week navigation: three equal tap targets instead of text wrapping badly */
  .week-nav {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 0.5rem;
    font-size: 0.85rem;
  }
  .week-nav a { padding: 0.55rem 0.25rem; }
  .week-nav a:first-child { text-align: left; }
  .week-nav a:last-child { text-align: right; }
  .week-nav .today-link { padding: 0.55rem 1rem; }

  /* Fingertip-sized targets (>= 44px) */
  .event-card { padding: 0.6rem 0.7rem; font-size: 0.9rem; }
  .event-location { font-size: 0.8rem; }
  .banner-overflow summary { padding: 0.7rem 0.4rem; font-size: 0.85rem; }
  .source-choice { padding: 0.85rem 0.2rem; }
  .source-choice input { width: 1.35rem; height: 1.35rem; }
  .order-btn { width: 2.75rem; height: 2.75rem; font-size: 1.05rem; }
  .source-order-buttons { gap: 0.4rem; }
  .sources-submit,
  .danger-btn,
  .moderation-approve,
  .moderation-reject { min-height: 2.75rem; padding-left: 1.4rem; padding-right: 1.4rem; }
  .moderation-actions { flex-wrap: wrap; }

  .sources-picker { margin: 1rem auto; padding: 1.1rem; }

  /* Footer links stacked, easy to hit */
  .site-footer { display: flex; flex-direction: column; gap: 0.2rem; }
  .site-footer a { padding: 0.6rem; }
  .site-footer .footer-sep { display: none; }
}

/* WhatsApp upload page */
.privacy-hint {
  background: var(--today-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  margin-top: 0.8rem;
}
.upload-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-top: 1.2rem;
  font-size: 0.9rem;
  font-weight: 600;
}
.upload-field input[type="text"],
.upload-field input[type="file"] {
  font-weight: 400;
  font-size: 1rem; /* >= 16px: iOS zooms the page on focus below that */
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
}
.upload-result {
  margin-top: 1.5rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--border);
}
.upload-result h3 { margin-top: 0; font-size: 1rem; }
.upload-result ul { padding-left: 1.2rem; font-size: 0.9rem; color: var(--text); }

/* Moderation */
.moderation-picker { max-width: 700px; }
.moderation-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  margin-top: 1rem;
}
.moderation-card-header {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  margin-bottom: 0.6rem;
}
.moderation-group {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 700;
  color: var(--accent-dark);
}
.moderation-fields { font-size: 0.92rem; display: flex; flex-direction: column; gap: 0.2rem; }
.moderation-raw {
  margin-top: 0.6rem;
  font-size: 0.82rem;
  color: var(--muted);
}
.moderation-raw summary { cursor: pointer; }
.moderation-raw p { white-space: pre-wrap; margin: 0.4rem 0 0; }
.moderation-actions { display: flex; gap: 0.6rem; margin-top: 0.8rem; }
.moderation-approve,
.moderation-reject {
  border: none;
  border-radius: 999px;
  padding: 0.45rem 1.1rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.moderation-approve { background: #2f9e6b; color: white; }
.moderation-approve:hover { background: #257d54; }
.moderation-reject { background: var(--border); color: var(--text); }
.moderation-reject:hover { background: #d8d2cc; }

/* WhatsApp import: errors and progress of background imports */
.form-error {
  background: #fbe4e4;
  border: 1px solid #f0b8b8;
  color: #8f1f2e;
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  font-size: 0.9rem;
}
.import-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.8rem 1rem;
  margin-top: 0.8rem;
}
.import-title { font-weight: 700; display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.import-state {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--border);
  color: var(--text);
}
.import-running, .import-queued { background: #fff0c9; }
.import-done { background: #d5eede; }
.import-error { background: #fbe4e4; }
.import-card progress { width: 100%; height: 0.6rem; margin-top: 0.6rem; accent-color: var(--accent); }
.import-card ul { margin: 0.6rem 0 0.4rem; }

/* "Se déconnecter" is a POST form, styled to sit with the footer links */
.logout-form { display: inline; }
.link-button {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-weight: 600;
  color: var(--accent-dark);
  cursor: pointer;
}
.link-button:hover { text-decoration: underline; }
@media (max-width: 600px) {
  .logout-form { display: block; }
  .link-button { padding: 0.6rem; }
}
