/* ==========================================================================
   Redstone Alert — dark theme
   Cherry red accent on dark / light grays.
   ========================================================================== */

:root {
  /* Grays */
  --bg:            #161618;
  --surface:       #1f1f23;
  --surface-2:     #28282d;
  --surface-3:     #323238;
  --border:        #3a3a41;
  --border-strong: #4a4a52;

  --text:          #e6e6ea;   /* light gray */
  --text-muted:    #a4a4ad;
  --text-faint:    #74747d;

  /* Cherry red */
  --cherry:        #d2042d;
  --cherry-hover:  #e8193f;
  --cherry-deep:   #7a0019;
  --cherry-tint:   rgba(210, 4, 45, 0.14);

  /* Response status (always shown with a text label) */
  --status-yes:    #3fb950;
  --status-no:     #f0606a;
  --status-other:  #d6a243;
  --status-none:   #8b8b93;

  --radius:        10px;
  --radius-sm:     6px;
  --shadow:        0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.25);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
}

a { color: var(--text); text-decoration-color: var(--cherry); text-underline-offset: 3px; }
a:hover { color: #fff; }

h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p  { margin: 0 0 1rem; }

:focus-visible { outline: 2px solid var(--cherry-hover); outline-offset: 2px; }

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

.container {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 16px;
}

main { flex: 1; padding: 28px 0 48px; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  border-top: 3px solid var(--cherry);
}
.topbar .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 60px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: .02em;
}
.brand img { width: 32px; height: 32px; }
.brand span b { color: var(--cherry-hover); font-weight: 700; }

.topbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: .9rem;
}
.topbar-user form { margin: 0; }

.footer {
  border-top: 1px solid var(--border);
  color: var(--text-faint);
  font-size: .85rem;
  padding: 18px 0;
  text-align: center;
}
.footer a { color: var(--text-muted); }

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 24px;
  margin-bottom: 24px;
}
.page-head p { color: var(--text-muted); margin: 0; }
.eyebrow {
  color: var(--cherry-hover);
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.stack > * + * { margin-top: 20px; }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
}
.card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.card-title h2 { margin: 0; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); border-color: var(--text-faint); color: #fff; }
.btn svg { width: 18px; height: 18px; flex: none; }

.btn-primary { background: var(--cherry); border-color: var(--cherry); color: #fff; }
.btn-primary:hover { background: var(--cherry-hover); border-color: var(--cherry-hover); }

.btn-danger { background: transparent; border-color: var(--cherry-deep); color: var(--status-no); }
.btn-danger:hover { background: var(--cherry-tint); border-color: var(--cherry); color: #fff; }

.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--border); }

.btn-sm { min-height: 34px; padding: 6px 12px; font-size: .875rem; }
.btn-block { width: 100%; }

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

.field { margin-bottom: 18px; }
.field label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: .92rem;
}
.field .hint { color: var(--text-faint); font-size: .82rem; margin-top: 6px; }
.field .hint-row { display: flex; justify-content: space-between; gap: 12px; }

input[type=text], input[type=email], input[type=tel], input[type=password],
select, textarea {
  width: 100%;
  padding: 11px 13px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 120px; line-height: 1.45; }
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--cherry);
  box-shadow: 0 0 0 3px var(--cherry-tint);
}
input[type=file] { color: var(--text-muted); font: inherit; }
input[type=file]::file-selector-button {
  margin-right: 12px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 18px;
}
.form-grid .span-2 { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

.counter.over { color: var(--status-no); }

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

.alert {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  border-left-width: 4px;
  background: var(--surface-2);
  margin-bottom: 20px;
}
.alert-error   { border-left-color: var(--cherry); background: var(--cherry-tint); }
.alert-success { border-left-color: var(--status-yes); }
.alert-info    { border-left-color: var(--status-none); }

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

.auth-wrap {
  min-height: calc(100vh - 140px);
  display: grid;
  place-items: center;
  padding: 32px 0;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--cherry);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}
.auth-card .logo { display: block; width: 72px; height: 72px; margin: 0 auto 14px; }
.auth-card h1 { text-align: center; font-size: 1.5rem; }
.auth-card .sub { text-align: center; color: var(--text-muted); margin-bottom: 24px; }
.auth-card .links { text-align: center; margin-top: 18px; font-size: .9rem; }
.auth-card .links a { color: var(--text-muted); }

.hero {
  min-height: calc(100vh - 140px);
  display: grid;
  place-items: center;
  text-align: center;
  padding: 48px 0;
  background:
    radial-gradient(ellipse 60% 50% at 50% 35%, rgba(210,4,45,.18), transparent 70%);
}
.hero .logo { width: 120px; height: 120px; margin-bottom: 20px; }
.hero h1 { font-size: clamp(2.2rem, 7vw, 3.6rem); letter-spacing: -.02em; }
.hero h1 b { color: var(--cherry-hover); }
.hero p { color: var(--text-muted); font-size: 1.1rem; max-width: 520px; margin: 0 auto 28px; }

/* ---------- Menu tiles ---------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}
.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  text-align: left;
  font: inherit;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .15s;
}
.tile:hover { border-color: var(--cherry); background: var(--surface-2); color: var(--text); transform: translateY(-1px); }
.tile .icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 9px;
  background: var(--surface-3);
  color: var(--text);
}
.tile .icon svg { width: 22px; height: 22px; }
.tile strong { font-size: 1.05rem; }
.tile small { color: var(--text-muted); font-size: .88rem; }
.tile.primary { border-color: var(--cherry-deep); background: linear-gradient(160deg, rgba(210,4,45,.18), var(--surface) 70%); }
.tile.primary .icon { background: var(--cherry); color: #fff; }
.tile.danger .icon { color: var(--status-no); }
.tile-form { margin: 0; display: contents; }

.section-label {
  color: var(--text-faint);
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  margin: 32px 0 12px;
}

/* ---------- Dashboard ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}
@media (max-width: 860px) { .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 520px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 16px 14px;
  border-top: 3px solid var(--border-strong);
}
.stat .label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: .85rem;
  font-weight: 600;
}
.stat .value {
  font-size: 2.1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  margin-top: 6px;
  color: var(--text);
}
.stat.yes   { border-top-color: var(--status-yes); }
.stat.no    { border-top-color: var(--status-no); }
.stat.other { border-top-color: var(--status-other); }
.stat.none  { border-top-color: var(--status-none); }

.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; background: var(--status-none); }
.dot.yes   { background: var(--status-yes); }
.dot.no    { background: var(--status-no); }
.dot.other { background: var(--status-other); }

.live {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: .88rem;
}
.live .pulse {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--cherry-hover);
  box-shadow: 0 0 0 0 rgba(232,25,63,.6);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(232,25,63,.55); }
  70%  { box-shadow: 0 0 0 9px rgba(232,25,63,0); }
  100% { box-shadow: 0 0 0 0 rgba(232,25,63,0); }
}
@media (prefers-reduced-motion: reduce) { .live .pulse { animation: none; } }

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

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; position: relative; }  /* relative: keeps .sr-only labels inside the scroll box */
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th {
  color: var(--text-muted);
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  background: var(--surface-2);
  white-space: nowrap;
}
tbody tr:hover td { background: rgba(255,255,255,.025); }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { text-align: right; white-space: nowrap; }
td.actions form { display: inline; margin: 0; }
td .muted, .muted { color: var(--text-muted); }
.nowrap { white-space: nowrap; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: .82rem;
  font-weight: 600;
  background: var(--surface-3);
  color: var(--text);
  white-space: nowrap;
}
.badge.role-admin { background: var(--cherry-tint); color: #ff9aac; }
.badge.role-user  { background: var(--surface-3); color: var(--text); }
.badge.role-recipient { background: transparent; border: 1px solid var(--border-strong); color: var(--text-muted); }

.response-text { color: var(--text); overflow-wrap: anywhere; }

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

/* Mobile: turn wide tables into stacked rows */
@media (max-width: 640px) {
  .table-stack thead { display: none; }
  .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
  .table-stack tr { padding: 12px 4px; border-bottom: 1px solid var(--border); }
  .table-stack tr:last-child { border-bottom: 0; }
  .table-stack td { border: 0; padding: 3px 8px; text-align: left; }
  .table-stack td[data-label]::before {
    content: attr(data-label);
    display: inline-block;
    min-width: 96px;
    color: var(--text-faint);
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .05em;
  }
  .table-stack td.actions { text-align: left; padding-top: 8px; }
  .card { padding: 16px; }
  h1 { font-size: 1.5rem; }
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ---------- Group selection (compose page, contact form) ---------- */

fieldset.field { border: 0; padding: 0; margin: 0 0 18px; min-width: 0; }
fieldset.field legend { font-weight: 600; font-size: .92rem; margin-bottom: 8px; padding: 0; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  cursor: pointer;
  font-weight: 500;
}
.check:hover { border-color: var(--text-faint); }
.check:has(input:checked) { border-color: var(--cherry); background: var(--cherry-tint); }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--cherry); }
.check .count { color: var(--text-muted); font-size: .85rem; }
.badge.group { background: var(--surface-3); color: var(--text); margin: 2px 4px 2px 0; }

/* ---------- Contacts list (admin/users): always fits its card, buttons always visible ---------- */

/* Wide screens: fixed column shares, long values wrap, Modifier / Effacer stacked in a narrow column. */
@media (min-width: 1001px) {
  .roster { table-layout: fixed; }
  .roster th, .roster td { padding-left: 8px; padding-right: 8px; }
  .roster td { overflow-wrap: anywhere; }
  .roster td.nowrap { white-space: normal; }
  .roster th:nth-child(1) { width: 15%; }   /* Nom */
  .roster th:nth-child(2) { width: 13%; }   /* Téléphone */
  .roster th:nth-child(3) { width: 21%; }   /* Courriel */
  .roster th:nth-child(4) { width: 15%; }   /* Rôle */
  .roster th:nth-child(5) { width: 12%; }   /* Utilisateur */
  .roster th:nth-child(6) { width: 14%; }   /* Groupes */
  .roster th:nth-child(7) { width: 10%; }   /* Actions */
  .roster td.actions { white-space: normal; text-align: right; }
  .roster td.actions .btn { width: 100%; padding-left: 6px; padding-right: 6px; }
  .roster td.actions form { display: block; margin-top: 6px; }
}

/* Narrower screens: seven columns cannot fit, so each contact becomes a captioned block (as on phones). */
@media (max-width: 1000px) {
  .roster thead { display: none; }
  .roster, .roster tbody, .roster tr, .roster td { display: block; width: 100%; }
  .roster tr { padding: 12px 4px; border-bottom: 1px solid var(--border); }
  .roster tr:last-child { border-bottom: 0; }
  .roster td { border: 0; padding: 3px 8px; text-align: left; overflow-wrap: anywhere; }
  .roster td.nowrap { white-space: normal; }
  .roster td[data-label]::before {
    content: attr(data-label);
    display: inline-block;
    min-width: 96px;
    color: var(--text-faint);
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .05em;
  }
  .roster td.actions { text-align: left; padding-top: 8px; white-space: normal; }
}
