/* app.css — ACHAT Campus, mobile-first, system fonts only.
   Reads from tokens.css. Phase A.1 Commit 1 keeps behaviour identical
   to the prior hardcoded version; the visual shift happens in the
   per-page commits and in the theme.css cleanup (Commit 5). */

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

body {
  font-family: system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  margin: 0;
}

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

header, main, footer { max-width: 40rem; margin: 0 auto; padding: 0 1rem; }

/* --- Header ------------------------------------------------------- */

header {
  position: sticky;
  top: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 0.75rem;
  padding-bottom: 0.75rem;
  max-width: 100%;
  z-index: 10;
}

.site-name { font-weight: 700; font-size: 1.1rem; text-decoration: none; color: var(--text); }
header nav { display: flex; align-items: center; gap: 0.75rem; flex-wrap: nowrap; }
header nav span { color: var(--text-muted); font-size: 0.9rem; white-space: nowrap; }
header nav a { color: var(--accent); text-decoration: none; font-size: 0.9rem; }
header nav a:hover { text-decoration: underline; }
header nav .nav-messages {
    color: var(--accent);
    font-size: 0.9rem;
    font-weight: 500;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    white-space: nowrap;
}
header nav .nav-messages:hover { text-decoration: underline; }
.messaging-unread-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    background: var(--accent);
    color: var(--text-on-accent);
    font-size: 0.72rem;
    font-weight: 700;
    min-width: 1.5rem;
    text-align: center;
    line-height: 1.2;
}
header nav .btn-logout {
    background: var(--accent);
    color: var(--text-on-accent);
    border: none;
    border-radius: 999px;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
}
header nav .btn-logout:hover { background: var(--accent-dark); }
.inline-form { display: inline; margin: 0; padding: 0; }

/* Glassmorphism for the sticky header in dark mode. @supports-gated
   so the 2017 Android falls back to a solid semi-transparent surface
   if backdrop-filter is too expensive to paint. --blur-amount is a
   knob in tokens.css — dial down to 4px or 0 if perf complains. */
@supports (backdrop-filter: blur(1px)) {
    html[data-theme="dark"] header { backdrop-filter: blur(var(--blur-amount)); }
}

/* --- Main --------------------------------------------------------- */

main { padding-top: 2rem; padding-bottom: 2rem; min-height: 60vh; }

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

.hero, .dashboard { text-align: center; padding: 3rem 0 2rem; }
.hero h1, .dashboard h1 { font-size: 1.75rem; margin-bottom: 0.5rem; }
.hero p, .hero-sub, .dashboard p, .muted { color: var(--text-muted); margin-bottom: 1rem; }

.hero-actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1.5rem;
}

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

.btn {
  display: inline-block;
  padding: 0.6rem 1.25rem;
  background: var(--accent);
  color: var(--text-on-accent);
  border: 1px solid var(--accent);
  border-radius: 4px;
  font-size: 1rem;
  cursor: pointer;
  text-decoration: none;
  min-height: 2.75rem;
  line-height: 1.5;
}
.btn:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-secondary { background: transparent; color: var(--accent); }
.btn-secondary:hover { background: var(--accent-pale); }

.btn-logout {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0;
  text-decoration: underline;
}
.btn-logout:hover { color: var(--accent-dark); }

/* --- Theme toggle ------------------------------------------------- */

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: none;
  background: none;
  color: var(--accent);
  border-radius: 999px;
  cursor: pointer;
}
.theme-toggle:hover { background: var(--accent-pale); }
.theme-toggle .icon-sun { display: none; }
html[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
html[data-theme="dark"] .theme-toggle .icon-sun { display: block; }

/* --- Presence ----------------------------------------------------- */
/* presence-dot colors stay literal: they are semantic status signals
   (offline gray, online green), not brand colors. */

.presence-line { display: flex; align-items: center; gap: 0.45rem; margin: 0.35rem 0 0; font-size: 0.85rem; color: var(--text-muted); }
.presence-dot { display: inline-block; width: 0.6rem; height: 0.6rem; border-radius: 999px; background: #c5c5c5; }
.presence-dot.is-online { background: #2ecc71; }
.presence-dot-on-avatar { position: absolute; bottom: 0; right: 0; }

.messaging-typing { margin: 0.35rem 0.25rem 0; font-size: 0.82rem; color: var(--text-muted); font-style: italic; min-height: 1.2rem; }
.messaging-typing[hidden] { display: none; }

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

form { max-width: 24rem; }
.field { margin-bottom: 1.25rem; }
.field label { display: block; font-size: 0.9rem; font-weight: 600; margin-bottom: 0.3rem; }

.field input {
  display: block;
  width: 100%;
  padding: 0.6rem 0.75rem;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid #bbb;
  border-radius: 4px;
  min-height: 2.75rem;
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }

button[type="submit"] {
  margin-top: 0.25rem;
  padding: 0.65rem 1.5rem;
  background: var(--accent);
  color: var(--text-on-accent);
  border: 1px solid var(--accent);
  border-radius: 4px;
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  min-height: 2.75rem;
}
button[type="submit"]:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.form-alt { margin-top: 1.25rem; font-size: 0.9rem; color: var(--text-muted); }

/* --- Errors ------------------------------------------------------- */

.errors {
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  border-radius: 4px;
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
  max-width: 24rem;
}
.errors ul { margin: 0; padding-left: 1.25rem; }
.errors li { color: var(--danger); font-size: 0.9rem; line-height: 1.6; }

/* --- Footer ------------------------------------------------------- */

footer {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  padding-bottom: 1.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  max-width: 100%;
}

/* --- Mobile header (< 600px) ─────────────────────────────────── */
@media (max-width: 600px) {
    header { padding: 0.6rem 1rem; }
    .site-name { font-size: 1rem; }
    header nav { gap: 0.5rem; }
    header nav span {
        /* Hide the greeting on phones — saves space, user is logged in anyway */
        display: none;
    }
    header nav .btn-logout {
        padding: 0.4rem 0.85rem;
        font-size: 0.85rem;
        min-height: 2.75rem;
    }
    header nav a {
        font-size: 0.85rem;
        min-height: 2.75rem;
    }
}
