:root {
  --c-bg: #f4f6f8;
  --c-surface: #ffffff;
  --c-ink: #1f2933;
  --c-muted: #66727d;
  --c-line: #e1e6ea;
  --c-brand: #c8102e;        /* UCalgary red */
  --c-brand-dk: #a50d26;
  --c-accent: #ffcd00;        /* UCalgary gold */
  --c-type-bg: #fdeaec;
  --c-unit-bg: #eef3f7;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16,24,32,.08), 0 4px 14px rgba(16,24,32,.06);
  --maxw: 1200px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--c-bg); color: var(--c-ink); }

/* ---------- top bar ---------- */
.topbar {
  background: var(--c-brand);
  color: #fff;
  border-bottom: 4px solid var(--c-accent);
}
.topbar-inner {
  max-width: var(--maxw); margin: 0 auto; padding: 14px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.topbar h1 { font-size: 1.15rem; margin: 0; font-weight: 650; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.month-pill {
  background: rgba(255,255,255,.18); padding: 4px 12px; border-radius: 999px;
  font-size: .9rem; font-weight: 600;
}
.btn-link { color: #fff; text-decoration: none; font-size: .9rem; opacity: .92; }
.btn-link:hover { opacity: 1; text-decoration: underline; }
.month-switch {
  max-width: var(--maxw); margin: 0 auto; padding: 8px 20px;
  font-size: .9rem; color: #fff;
}
.month-switch select { padding: 3px 6px; border-radius: 6px; border: 0; }

/* ---------- wall ---------- */
.wall {
  max-width: var(--maxw); margin: 0 auto; padding: 22px 20px 60px;
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  align-items: start;
}
.card {
  background: var(--c-surface); border: 1px solid var(--c-line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; position: relative;
}
.add-tile {
  border: 2px dashed var(--c-brand); background: #fff; color: var(--c-brand);
  cursor: pointer; font: inherit; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; min-height: 120px; transition: background .15s;
}
.add-tile:hover { background: var(--c-type-bg); }
.add-tile .plus { font-size: 2rem; line-height: 1; }

.entry .title { margin: 6px 0 8px; font-size: 1.05rem; line-height: 1.3; }
.entry .notes { margin: 0 0 10px; color: var(--c-muted); font-size: .92rem; white-space: pre-wrap; }
.entry.empty { grid-column: 1 / -1; text-align: center; padding: 30px; }

.badges { min-height: 0; }
.tag {
  display: inline-block; font-size: .72rem; font-weight: 600;
  padding: 3px 9px; border-radius: 999px; margin: 0 4px 4px 0;
}
.tag.type { background: var(--c-type-bg); color: var(--c-brand-dk); }
.tag.unit { background: var(--c-unit-bg); color: #3a4a57; font-weight: 500; }
.tag.topic { background: #fff3d6; color: #7a5800; font-weight: 500; }
.tag.team { background: #e6f0ea; color: #2f5d43; font-weight: 500; }
.tag.part { background: #eef1f4; color: #3a4a57; }
.units { margin-top: 8px; }
.meta { margin-top: 8px; }
.author { font-size: .82rem; color: var(--c-muted); font-style: italic; }

.card-controls { position: absolute; top: 8px; right: 8px; display: flex; gap: 2px; }
.icon-btn {
  border: 0; background: transparent; cursor: pointer; font-size: .95rem;
  padding: 4px 6px; border-radius: 6px; color: var(--c-muted);
}
.icon-btn:hover { background: var(--c-bg); color: var(--c-ink); }

.muted { color: var(--c-muted); }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(16,24,32,.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto; z-index: 50;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  width: 100%; max-width: 560px; padding: 24px;
}
.modal h2 { margin: 0 0 16px; font-size: 1.2rem; }

/* Each section (Type, Topic, Units) is a full-width row so every option is
   visible at once. On wider screens the modal grows so those chip rows wrap
   horizontally across the width instead of running tall. */
.modal-grid { display: block; }
@media (min-width: 720px)  { .modal { max-width: 880px; } }
@media (min-width: 1080px) { .modal { max-width: 1000px; } }
.field { display: block; margin-bottom: 16px; }
.field > span, .field > legend { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.field em { color: var(--c-brand); font-style: normal; }
.field small { color: var(--c-muted); font-weight: 400; }
.field input[type=text], .field textarea, .field select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--c-line);
  border-radius: 8px; font: inherit;
}
.field input:focus, .field textarea:focus { outline: 2px solid var(--c-brand); border-color: var(--c-brand); }
fieldset.field { border: 0; padding: 0; margin: 0 0 16px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
/* No height cap: every option is always visible (browsers often hide
   scrollbars, so a scroll box would hide choices). The modal backdrop
   scrolls if the whole form is taller than the viewport. */
.chips-wrap { padding: 2px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-block; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--c-line); font-size: .85rem; cursor: pointer; user-select: none;
}
.chip input:checked + span { background: var(--c-brand); color: #fff; border-color: var(--c-brand); }
.chip input:focus-visible + span { outline: 2px solid var(--c-accent); }

.hp { position: absolute; left: -9999px; height: 0; overflow: hidden; }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.btn { font: inherit; padding: 9px 18px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.btn.primary { background: var(--c-brand); color: #fff; }
.btn.primary:hover { background: var(--c-brand-dk); }
.btn.ghost { background: #fff; border-color: var(--c-line); color: var(--c-ink); }
.btn.ghost:hover { background: var(--c-bg); }
.btn:disabled { opacity: .6; cursor: default; }
.form-error { color: var(--c-brand-dk); font-size: .9rem; margin: 10px 0 0; }

/* ---------- admin ---------- */
.admin-wrap { max-width: var(--maxw); margin: 0 auto; padding: 24px 20px 60px; }
.admin-nav { display: flex; gap: 6px; margin-bottom: 22px; flex-wrap: wrap; }
.admin-nav a {
  text-decoration: none; color: var(--c-ink); padding: 7px 14px;
  border-radius: 8px; font-size: .9rem; border: 1px solid var(--c-line); background: #fff;
}
.admin-nav a.active { background: var(--c-brand); color: #fff; border-color: var(--c-brand); }
.login-box { max-width: 380px; margin: 8vh auto; background: #fff; padding: 28px;
  border-radius: var(--radius); box-shadow: var(--shadow); }
.login-box h1 { font-size: 1.2rem; margin: 0 0 18px; }

.stat-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(160px,1fr)); margin-bottom: 26px; }
.stat { background: #fff; border: 1px solid var(--c-line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat .n { font-size: 1.8rem; font-weight: 700; color: var(--c-brand); }
.stat .l { font-size: .85rem; color: var(--c-muted); }
.stat .delta { font-size: .78rem; font-weight: 600; margin: 2px 0 2px; }
.stat .delta .muted { font-weight: 400; }
.delta.up { color: #1b5e20; }
.delta.down { color: var(--c-brand-dk); }
.delta.flat { color: var(--c-muted); }

/* ---------- dashboard: participation, recent, leaderboard ---------- */
.cov-head { font-size: 1.05rem; margin-bottom: 10px; }
.progress { background: var(--c-bg); border: 1px solid var(--c-line); border-radius: 999px; height: 14px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--c-brand); transition: width .3s; }
.cov-label { margin: 14px 0 8px; font-size: .85rem; }
.gaps { display: flex; flex-wrap: wrap; gap: 6px; }
.tag.gap { background: var(--c-bg); color: var(--c-muted); border: 1px solid var(--c-line); font-weight: 500; }

.recent { list-style: none; margin: 0; padding: 0; }
.recent li { padding: 9px 0; border-bottom: 1px solid var(--c-line); }
.recent li:last-child { border-bottom: 0; }
.r-title { display: block; font-weight: 600; font-size: .92rem; }
.r-meta { display: block; color: var(--c-muted); font-size: .82rem; margin-top: 2px; }

table.data.lb { box-shadow: none; }
table.data.lb td { padding: 7px 10px; border-bottom: 1px solid var(--c-line); }
table.data.lb .rank { color: var(--c-muted); width: 1.5em; text-align: right; font-variant-numeric: tabular-nums; }
table.data.lb .num { text-align: right; font-weight: 700; color: var(--c-brand); width: 2.5em; }
table.data.lb .share { text-align: right; width: 3em; font-size: .82rem; }

.chart-grid { display: grid; gap: 20px; grid-template-columns: 1fr 1fr; margin-bottom: 26px; }
.chart-card { background: #fff; border: 1px solid var(--c-line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.chart-card h3 { margin: 0 0 12px; font-size: 1rem; }
@media (max-width: 760px) { .chart-grid { grid-template-columns: 1fr; } }

table.data { width: 100%; border-collapse: collapse; background: #fff; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table.data th, table.data td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--c-line); font-size: .9rem; vertical-align: top; }
table.data th { background: var(--c-bg); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--c-muted); }

.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar select, .toolbar input { padding: 7px 10px; border: 1px solid var(--c-line); border-radius: 8px; font: inherit; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: .9rem; }
.flash.ok { background: #e8f5ea; color: #1b5e20; }
.flash.err { background: var(--c-type-bg); color: var(--c-brand-dk); }

/* ---------- settings: sortable type/unit lists ---------- */
.sortable { list-style: none; margin: 0 0 12px; padding: 0; }
.sort-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 4px; border-bottom: 1px solid var(--c-line); background: #fff;
}
.sort-row:last-child { border-bottom: 0; }
.sort-row.inactive { opacity: .5; }
.sort-row.dragging { box-shadow: var(--shadow); border-bottom: 0; border-radius: 8px; background: #fff; }
.sort-row.placeholder { background: var(--c-type-bg); border: 1px dashed var(--c-brand); border-radius: 8px; }
.drag-handle {
  cursor: grab; color: var(--c-muted); font-size: 1.1rem; line-height: 1;
  padding: 0 4px; user-select: none; touch-action: none;
}
.drag-handle:active { cursor: grabbing; }
.dragging-active { user-select: none; cursor: grabbing; }
.row-rename { display: flex; flex: 1; gap: 6px; margin: 0; align-items: center; min-width: 0; }
.row-rename input[type=text] {
  flex: 1; min-width: 0; padding: 6px 9px; border: 1px solid var(--c-line);
  border-radius: 8px; font: inherit; font-size: .9rem;
}
.row-rename input:focus { outline: 2px solid var(--c-brand); border-color: var(--c-brand); }
.row-ops { display: flex; gap: 4px; margin: 0; }
.sort-row .btn { padding: 6px 10px; font-size: .82rem; }
.btn.ghost.danger { color: var(--c-brand-dk); }
.btn.ghost.danger:hover { background: var(--c-type-bg); }
@media (max-width: 560px) {
  .sort-row { flex-wrap: wrap; }
  .row-ops { flex-basis: 100%; justify-content: flex-end; margin-top: 2px; }
}
