/* 2458 Portal - works on phones and computers */
:root {
  --bg: #f2f4f8; --card: #ffffff; --text: #1b1f27; --muted: #667085;
  --line: #e2e6ee; --accent: #1d4ed8; --accent-text: #ffffff;
  --nav: #0f2a5a; --nav-text: #c9d4ee; --gold: #f2c230; --radius: 14px;
  --input-bg: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b; --card: #1c2028; --text: #ececf0; --muted: #9aa3b2;
    --line: #2f3541; --accent: #7aa2ff; --accent-text: #0b1220;
    --nav: #0b1a3a; --input-bg: #14181f;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); line-height: 1.45;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ---------- header ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--card); border-bottom: 1px solid var(--line); }
.topbar-inner {
  max-width: 1000px; margin: 0 auto; padding: 8px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); min-width: 0; }
.crest { height: 52px; width: auto; display: block; }
.brand-text { font-weight: 700; font-size: 1.25rem; letter-spacing: .02em; white-space: nowrap; }

.user-menu { position: relative; }
.user-menu summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px;
  padding: 4px 8px 4px 4px; border-radius: 999px; border: 1px solid var(--line);
  user-select: none; -webkit-tap-highlight-color: transparent;
}
.user-menu summary::-webkit-details-marker { display: none; }
.user-name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.caret { color: var(--muted); font-size: .8rem; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 230px; z-index: 30;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 10px 28px rgba(0,0,0,.2); padding: 6px;
}
.menu-who { padding: 8px 12px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; display: flex; flex-direction: column; }
.menu-panel a, .menu-panel button {
  display: block; width: 100%; text-align: left; padding: 12px; border-radius: 8px;
  color: var(--text); text-decoration: none; background: none; border: 0;
  font: inherit; cursor: pointer; min-height: 44px;
}
.menu-panel a:hover, .menu-panel button:hover { background: var(--bg); }

.navbar { background: var(--nav); }
.navbar-inner {
  max-width: 1000px; margin: 0 auto; padding: 0 8px; display: flex;
  overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.navbar-inner::-webkit-scrollbar { display: none; }
.navbar a {
  color: var(--nav-text); text-decoration: none; padding: 13px 16px; white-space: nowrap;
  font-weight: 500; border-bottom: 3px solid transparent;
}
.navbar a:hover { color: #fff; }
.navbar a.active { color: #fff; border-bottom-color: var(--gold); }
.count, .pill {
  display: inline-block; background: #dc2626; color: #fff; border-radius: 999px;
  font-size: .75rem; font-weight: 700; padding: 1px 7px; vertical-align: middle;
}

/* ---------- layout ---------- */
.page { max-width: 1000px; margin: 0 auto; padding: 16px 14px 32px; }
.page-title { margin-bottom: 14px; }
.footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 8px 14px 28px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; }
.card.narrow { max-width: 460px; margin-left: auto; margin-right: auto; }
.two-col { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
@media (min-width: 760px) { .two-col { grid-template-columns: 1fr 1fr; } }

.flashes { margin-bottom: 12px; }
.flash { padding: 12px 14px; border-radius: 10px; margin-bottom: 8px; border: 1px solid var(--line); background: var(--card); }
.flash.success { border-color: #16a34a; }
.flash.error { border-color: #dc2626; }

/* ---------- people & avatars ---------- */
.avatar { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; flex: none; display: inline-block; }
.avatar.sm { width: 34px; height: 34px; font-size: .8rem; }
.avatar.lg { width: 92px; height: 92px; font-size: 1.8rem; }
.avatar.placeholder {
  background: var(--nav); color: #fff; font-weight: 700; letter-spacing: .03em;
  display: inline-flex; align-items: center; justify-content: center;
}
.profile-head { display: flex; align-items: center; gap: 16px; }
.details { display: grid; grid-template-columns: 40% 60%; gap: 0; margin: 0; }
.details dt, .details dd { padding: 10px 0; border-bottom: 1px solid var(--line); margin: 0; }
.details dt { color: var(--muted); }
.details dt:last-of-type, .details dd:last-of-type { border-bottom: 0; }

.people { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 640px) { .people { grid-template-columns: 1fr 1fr; } }
@media (min-width: 960px) { .people { grid-template-columns: 1fr 1fr 1fr; } }
.person { display: block; text-decoration: none; color: var(--text); margin: 0; }
.person:hover { border-color: var(--accent); }
.person-top { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.person-id { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.person-grades { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.person-grades > div { display: flex; align-items: center; gap: 4px; }
.person-grades .muted { margin-right: 4px; }
.tag {
  display: inline-block; font-size: .75rem; padding: 2px 9px; border-radius: 999px;
  background: var(--bg); border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters input[type=search] { flex: 1 1 220px; }

/* ---------- grades (A/1 green ... E/5 red) ---------- */
.grades { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 12px; margin-bottom: 12px; }
.grade-tile {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 14px 8px; border: 1px solid var(--line); border-radius: 12px;
}
.grade-label { color: var(--muted); font-size: .9rem; }
.grade {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 3rem; height: 3rem; padding: 0 .7rem; border-radius: 12px;
  font-weight: 800; font-size: 1.4rem;
}
.grade.sm { min-width: 1.8rem; height: 1.8rem; padding: 0 .4rem; font-size: .95rem; border-radius: 8px; }
.grade-1 { background: #16a34a; color: #fff; }          /* A / 1  green */
.grade-2 { background: #b4d531; color: #1c2600; }       /* B / 2  greenish yellow */
.grade-3 { background: #facc15; color: #2b2200; }       /* C / 3  yellow */
.grade-4 { background: #fb923c; color: #2a1300; }       /* D / 4  orange */
.grade-5 { background: #dc2626; color: #fff; }          /* E / 5  red */
.grade-none { background: transparent; color: var(--muted); border: 1px dashed var(--line); font-weight: 500; font-size: .85rem; }
.grade-none.sm { font-size: .95rem; }
.key { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; margin: 4px 0 14px; font-size: .85rem; color: var(--muted); }
.key-item { display: inline-flex; align-items: center; gap: 6px; }
.key .grade.sm { min-width: 3.2rem; font-size: .8rem; }

/* ---------- notes & messages ---------- */
.note, .message { padding: 12px 0; border-bottom: 1px solid var(--line); }
.note:last-child, .message:last-child { border-bottom: 0; }
.note-text { margin-bottom: 4px; }
.message.new { background: rgba(29, 78, 216, .07); margin: 0 -18px; padding: 12px 18px; }
.message-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.message p { margin: 0 0 6px; overflow-wrap: anywhere; }
.reply { font-size: .9rem; }
.tabs { display: flex; gap: 8px; margin: 4px 0 12px; }
.tabs a {
  padding: 8px 18px; border-radius: 999px; text-decoration: none; color: var(--text);
  border: 1px solid var(--line); background: var(--card);
}
.tabs a.active { background: var(--nav); color: #fff; border-color: var(--nav); }

/* ---------- forms ---------- */
.stack { display: flex; flex-direction: column; gap: 14px; }
.field label { display: block; font-weight: 500; margin-bottom: 6px; }
input[type=text], input[type=password], input[type=search], textarea, select {
  width: 100%; padding: 12px; font: inherit; font-size: 16px; /* 16px stops iPhones zooming in */
  color: var(--text); background: var(--input-bg); border: 1px solid var(--line); border-radius: 10px;
}
input[type=file] { max-width: 100%; font-size: 16px; }
textarea { resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; }
button, .btn {
  display: inline-block; background: var(--accent); color: var(--accent-text); border: 0;
  border-radius: 10px; padding: 12px 20px; font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none; min-height: 44px; text-align: center;
}
.stack > button { align-self: flex-start; }
.error { color: #dc2626; font-size: .9rem; margin-top: 4px; }
.helptext { color: var(--muted); font-size: .85rem; margin-top: 6px; }
.helptext ul { margin: 4px 0 0; padding-left: 18px; }

/* ---------- small screens ---------- */
@media (max-width: 520px) {
  .user-name { display: none; }
  .crest { height: 44px; }
  .brand-text { font-size: 1.1rem; }
  .profile-head { gap: 12px; }
  .avatar.lg { width: 72px; height: 72px; font-size: 1.4rem; }
  .card { padding: 14px; }
  .message.new { margin: 0 -14px; padding: 12px 14px; }
  .details { grid-template-columns: 38% 62%; }
  .stack > button { align-self: stretch; }
}

/* =====================================================================
   Added: home page, chat, links, Admin page
   ===================================================================== */
:root {
  --warn-bg: #fff4d6; --warn-line: #e5b92b; --warn-text: #5a4300;
  --ok: #16a34a; --danger: #dc2626; --mine: #e8efff;
}
@media (prefers-color-scheme: dark) {
  :root { --warn-bg: #2f2710; --warn-line: #a9831c; --warn-text: #f3d98a; --mine: #1f2a44; }
}
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.page-head .page-title, .page-head h2 { margin-bottom: 0; }
.grow { flex: 1 1 240px; margin: 0; }
.right { text-align: right; }
code { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; font-size: .9em; }

/* ---------- buttons ---------- */
.btn-small {
  display: inline-block; padding: 7px 12px; min-height: 36px; border-radius: 8px; font: inherit;
  font-size: .9rem; font-weight: 600; cursor: pointer; text-decoration: none; text-align: center;
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
}
.btn-small:hover { border-color: var(--accent); }
.btn-small.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-small.no { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--line); }
.btn-danger { background: var(--danger); color: #fff; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.actions form, .link-tools form { margin: 0; }
.link-button { background: none; border: 0; padding: 0; min-height: 0; color: var(--danger); font: inherit; font-size: .85rem; font-weight: 500; cursor: pointer; text-decoration: underline; }
.inline-form { display: inline; margin-left: 8px; }
.tag.warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn-text); }

/* ---------- home ---------- */
.hero {
  display: grid; grid-template-columns: auto 1fr; gap: 6px 18px; align-items: center;
  background: var(--nav); color: #fff; border-radius: var(--radius); padding: 22px 24px;
  border-left: 6px solid var(--gold); margin-bottom: 14px;
}
.hero-crest { height: 84px; width: auto; grid-row: span 2; }
.hero-greet { margin: 0; color: var(--nav-text); font-size: 1rem; }
.hero-name { font-size: 2rem; line-height: 1.15; margin: 0; letter-spacing: -.01em; }
.hero-meta { margin: 2px 0 0; color: var(--nav-text); }
.hero-motto { grid-column: 2; margin: 6px 0 0; color: var(--gold); font-style: italic; font-size: .95rem; }
@media (max-width: 520px) {
  .hero { padding: 16px; gap: 4px 14px; }
  .hero-crest { height: 60px; }
  .hero-name { font-size: 1.5rem; }
}
.nudge {
  display: block; padding: 12px 16px; margin-bottom: 14px; border-radius: 12px; text-decoration: none;
  background: var(--warn-bg); color: var(--warn-text); border: 1px solid var(--warn-line);
}
.attention { border-color: var(--warn-line); background: var(--warn-bg); color: var(--warn-text); }
.attention h2 { color: var(--warn-text); }
.attention-list { display: flex; flex-direction: column; gap: 8px; }
.attention-list a { color: inherit; text-decoration: none; font-weight: 500; }
.attention-list a:hover { text-decoration: underline; }
.tiles { display: grid; grid-template-columns: 1fr; gap: 12px; margin-bottom: 14px; }
@media (min-width: 560px) { .tiles { grid-template-columns: 1fr 1fr; } }
@media (min-width: 900px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
.tile {
  display: flex; flex-direction: column; gap: 8px; text-decoration: none; color: var(--text);
  background: var(--card); border: 1px solid var(--line); border-top: 4px solid var(--nav);
  border-radius: var(--radius); padding: 16px 18px; min-height: 140px;
}
.tile:hover { border-color: var(--accent); border-top-color: var(--gold); }
.tile h2 { margin: 0; }
.tile p { margin: 0; }
.tile-grades { display: flex; gap: 6px; }
.tile-quote { overflow-wrap: anywhere; flex: 1; }

/* ---------- links & extra pages ---------- */
.link-list { list-style: none; margin: 0; padding: 0; }
.link-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.link-list li:last-child { border-bottom: 0; }
.link-main { display: flex; flex-direction: column; min-width: 0; }
.link-title { font-weight: 600; overflow-wrap: anywhere; }
.link-tools { display: flex; gap: 8px; }
.page-body p { max-width: 70ch; overflow-wrap: anywhere; }

/* ---------- Admin page ---------- */
.subnav { display: flex; gap: 8px; overflow-x: auto; margin: 0 0 14px; padding-bottom: 4px; scrollbar-width: none; }
.subnav::-webkit-scrollbar { display: none; }
.subnav a {
  padding: 9px 16px; border-radius: 999px; text-decoration: none; color: var(--text); white-space: nowrap;
  border: 1px solid var(--line); background: var(--card);
}
.subnav a.active { background: var(--nav); color: #fff; border-color: var(--nav); }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { color: var(--muted); font-weight: 500; font-size: .85rem; }
.table tr:last-child td { border-bottom: 0; }
.table td.right { text-align: right; }
.table tr.off { opacity: .6; }
.cell-person { display: flex; align-items: center; gap: 10px; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 700px) { .form-grid { grid-template-columns: 1fr 1fr; } }
.form-grid .wide { grid-column: 1 / -1; }
.checklist ul { list-style: none; margin: 0; padding: 0; max-height: 360px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; }
.checklist li { padding: 4px 12px; border-bottom: 1px solid var(--line); }
.checklist li:last-child { border-bottom: 0; }
.checklist label { display: flex; align-items: center; gap: 10px; min-height: 40px; }
.photo-review { display: flex; gap: 16px; align-items: flex-start; padding: 14px 0; border-bottom: 1px solid var(--line); }
.photo-review:last-child { border-bottom: 0; }
.photo-big { width: 160px; height: 160px; object-fit: cover; border-radius: 12px; flex: none; }
.photo-info { display: flex; flex-direction: column; gap: 8px; }
.photo-state { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.mute-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.mute-row:last-child { border-bottom: 0; }
.flag-row { padding: 12px; margin-bottom: 10px; border-radius: 10px; background: var(--warn-bg); border-left: 4px solid var(--warn-line); color: var(--text); }
.flag-head { display: flex; gap: 8px; flex-wrap: wrap; align-items: baseline; margin-bottom: 4px; }
@media (max-width: 520px) {
  .photo-review { flex-direction: column; }
  .photo-big { width: 100%; height: auto; aspect-ratio: 1; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }

[hidden] { display: none !important; }

/* ---------- pictures on extra pages ---------- */
.page-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-top: 14px; }
.page-gallery img { width: 100%; height: 180px; object-fit: cover; border-radius: 12px; display: block; }
.page-pic { margin: 0; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.people-pick #id_viewers, .people-pick #id_editors { max-height: 280px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; }
.people-pick ul { list-style: none; margin: 0; padding: 0; }
.people-pick label { display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 4px 12px; margin: 0; font-weight: 400; border-bottom: 1px solid var(--line); }

/* =====================================================================
   Flights: A Flight red, B Flight green, C Flight yellow
   ===================================================================== */
:root { --flight-red: #dc2626; --flight-green: #16a34a; --flight-yellow: #eab308; }

/* Ring around profile pictures */
.avatar.flight-A { box-shadow: 0 0 0 3px var(--flight-red); margin: 3px; }
.avatar.flight-B { box-shadow: 0 0 0 3px var(--flight-green); margin: 3px; }
.avatar.flight-C { box-shadow: 0 0 0 3px var(--flight-yellow); margin: 3px; }

.flight-tabs a.flight-tab-red { border-left: 5px solid var(--flight-red); }
.flight-tabs a.flight-tab-green { border-left: 5px solid var(--flight-green); }
.flight-tabs a.flight-tab-yellow { border-left: 5px solid var(--flight-yellow); }
.flight-text-red { color: var(--flight-red); }
.flight-text-green { color: var(--flight-green); }
.flight-text-yellow { color: #b88a00; }
@media (prefers-color-scheme: dark) { .flight-text-yellow { color: var(--flight-yellow); } }
.flight-border-red { border-left: 6px solid var(--flight-red); }
.flight-border-green { border-left: 6px solid var(--flight-green); }
.flight-border-yellow { border-left: 6px solid var(--flight-yellow); }

.flight-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 760px) { .flight-grid { grid-template-columns: repeat(3, 1fr); } }
.flight-grid .card { margin-bottom: 0; }
.flight-grid { margin-bottom: 14px; }
.flight-card h2, .flight-banner h2 { margin: 0; }
.flight-card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.flight-total { font-size: 2rem; font-weight: 700; }
.flight-top-label { margin: 12px 0 6px; }
.flight-top { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.flight-top-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.flight-winner { font-size: 1.5rem; }
.flight-banner p { margin: 0 0 4px; }

.flight-standings { list-style: none; margin: 0; padding: 0; }
.flight-standings li { display: flex; justify-content: space-between; padding: 10px 12px; margin-bottom: 8px; background: var(--bg); border-radius: 8px; }

.leaderboard { list-style: none; margin: 0; padding: 0; }
.leaderboard li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.leaderboard li:last-child { border-bottom: 0; }
.leaderboard li.top { background: rgba(242, 194, 48, .12); border-radius: 8px; padding-left: 8px; padding-right: 8px; }
.lb-rank { width: 1.8em; text-align: center; color: var(--muted); font-weight: 600; }
.lb-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.flight-history { list-style: none; margin: 0; padding: 0; }
.flight-history li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.flight-history li:last-child { border-bottom: 0; }
.flight-history .pos { color: var(--ok); }
.flight-history .neg { color: var(--danger); }
