/* WashU Racing Safety Portal
 *
 * Spec §25 asks for light and dark to be *deliberate*, not whatever the
 * browser does to an undefined palette. So: every colour is a token, defined
 * three times — once as the light default, once under prefers-color-scheme
 * for people who never touch the toggle, and once under [data-theme] so an
 * explicit choice beats the system in both directions. No component below
 * names a raw colour, which is what keeps the two modes from drifting apart.
 *
 * (Manufacturing's stylesheet leans on the CSS system colours Canvas/CanvasText
 * instead. That works, but it hands the palette to the browser — exactly what
 * this spec asks us not to do — so this is a deliberate divergence rather than
 * an inconsistency.)
 */

:root {
  --bg:          #f6f7f9;
  --surface:     #ffffff;
  --surface-2:   #f0f2f5;
  --border:      #d8dce3;
  --border-soft: #e8ebf0;
  --text:        #12161c;
  --text-dim:    #5a6474;
  --text-faint:  #8b94a3;

  --accent:      #a51417;  /* WashU Racing red */
  --accent-text: #ffffff;
  --accent-soft: #fdeaeb;
  --link:        #1f5fd0;

  --ok:          #17803d;
  --ok-soft:     #e6f4ea;
  --warn:        #a35c00;
  --warn-soft:   #fdf1de;
  --danger:      #c02434;
  --danger-soft: #fdeaec;
  --info:        #1f5fd0;
  --info-soft:   #e8f0fd;

  --shadow: 0 1px 2px rgba(16, 22, 30, .06), 0 1px 8px rgba(16, 22, 30, .04);
  --radius: 10px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:          #101318;
    --surface:     #171b22;
    --surface-2:   #1e232c;
    --border:      #2c3340;
    --border-soft: #232935;
    --text:        #e8ebf0;
    --text-dim:    #9aa4b4;
    --text-faint:  #6d7787;

    --accent:      #e8505c;
    --accent-text: #1a0d0f;
    --accent-soft: #2a151a;
    --link:        #7aa7f5;

    --ok:          #4ecb79;
    --ok-soft:     #14261a;
    --warn:        #e0a33c;
    --warn-soft:   #2a2113;
    --danger:      #f26d7d;
    --danger-soft: #2b1519;
    --info:        #7aa7f5;
    --info-soft:   #141d2e;

    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 1px 8px rgba(0, 0, 0, .25);

    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg:          #101318;
  --surface:     #171b22;
  --surface-2:   #1e232c;
  --border:      #2c3340;
  --border-soft: #232935;
  --text:        #e8ebf0;
  --text-dim:    #9aa4b4;
  --text-faint:  #6d7787;

  --accent:      #e8505c;
  --accent-text: #1a0d0f;
  --accent-soft: #2a151a;
  --link:        #7aa7f5;

  --ok:          #4ecb79;
  --ok-soft:     #14261a;
  --warn:        #e0a33c;
  --warn-soft:   #2a2113;
  --danger:      #f26d7d;
  --danger-soft: #2b1519;
  --info:        #7aa7f5;
  --info-soft:   #141d2e;

  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 1px 8px rgba(0, 0, 0, .25);

  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; letter-spacing: -.01em; }
h2 { font-size: 1.12rem; }
h3 { font-size: 1rem; }

/* Native <option> popups are painted by the OS: a select that only sets
   color:inherit gives light text on a light popup in dark mode. Pin both. */
select, option, optgroup { background-color: var(--surface); color: var(--text); }
::placeholder { color: var(--text-faint); opacity: 1; }

/* --- landing / status pages --- */

.landing { max-width: 34rem; margin: 0 auto; padding: 4rem 1.25rem; }
.landing h1 { font-size: 1.6rem; }
.landing .sub { color: var(--text-dim); margin: 0 0 1.75rem; }
.landing .hint { font-size: .85rem; color: var(--text-faint); margin-top: 2.5rem; }
.landing ul { font-size: .85rem; color: var(--text-dim); line-height: 1.9; padding-left: 1.1rem; }
.link { text-decoration: underline; }

/* --- buttons --- */

.button, .btn {
  display: inline-block;
  padding: .5rem 1rem;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  font-size: .9rem;
  cursor: pointer;
  text-decoration: none;
}
.button:hover, .btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; filter: none; }

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-small { padding: .3rem .6rem; font-size: .8rem; }

/* --- layout --- */

#root { max-width: 78rem; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }

.nav { background: var(--surface); border-bottom: 1px solid var(--border); }
.nav-inner {
  max-width: 78rem;
  margin: 0 auto;
  padding: .6rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}
.nav-brand { font-weight: 800; letter-spacing: -.01em; color: var(--text); white-space: nowrap; }
.nav-brand:hover { text-decoration: none; }
.nav-brand span { color: var(--accent); }
.nav-links { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.nav-link { padding: .35rem .7rem; border-radius: 7px; color: var(--text-dim); font-size: .9rem; font-weight: 500; }
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.nav-meta { display: flex; align-items: center; gap: .6rem; font-size: .82rem; color: var(--text-faint); }
.nav-linkbtn {
  background: none; border: none; padding: 0;
  text-decoration: underline; cursor: pointer;
  font: inherit; font-size: .82rem; color: var(--text-faint);
}
.nav-linkbtn:hover { color: var(--text); }

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: .25rem .5rem;
  cursor: pointer;
  color: var(--text-dim);
  font-size: .9rem;
  line-height: 1.2;
}
.theme-toggle:hover { background: var(--surface-2); }

/* --- cards / panels --- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 1rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .75rem; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); }

.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); font-size: .85rem; }
.stack > * + * { margin-top: .6rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.section-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); margin: 1.5rem 0 .6rem; font-weight: 700; }

/* --- badges --- */

.badge {
  display: inline-block;
  padding: .12rem .5rem;
  border-radius: 99px;
  font-size: .73rem;
  font-weight: 700;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge-ok     { background: var(--ok-soft);     color: var(--ok);     border-color: var(--ok); }
.badge-warn   { background: var(--warn-soft);   color: var(--warn);   border-color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.badge-info   { background: var(--info-soft);   color: var(--info);   border-color: var(--info); }
.badge-quiet  { background: var(--surface-2);   color: var(--text-dim); border-color: var(--border); }

/* --- progress --- */

.progress { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--border-soft); }
.progress-fill { height: 100%; background: var(--ok); transition: width .2s ease; }
.progress-count { font-size: 1.7rem; font-weight: 800; letter-spacing: -.02em; }

/* --- training checklist --- */

.check-list { list-style: none; padding: 0; margin: 0; }
.check-list li { display: flex; align-items: baseline; gap: .55rem; padding: .4rem 0; border-bottom: 1px solid var(--border-soft); }
.check-list li:last-child { border-bottom: none; }
.check-mark { font-weight: 700; width: 1.1rem; flex: none; }
.check-done .check-mark { color: var(--ok); }
.check-todo .check-mark { color: var(--text-faint); }

/* --- tables --- */

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border-soft); vertical-align: top; }
th { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); font-weight: 700; white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* --- forms --- */

label { display: block; font-size: .82rem; font-weight: 600; color: var(--text-dim); margin-bottom: .25rem; }
input[type="text"], input[type="search"], input[type="date"], input[type="email"], select, textarea {
  width: 100%;
  padding: .45rem .6rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: .9rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--link); outline-offset: -1px; border-color: var(--link); }
textarea { min-height: 5rem; resize: vertical; }
.field { margin-bottom: .8rem; }
.field-row { display: flex; gap: .8rem; flex-wrap: wrap; }
.field-row > .field { flex: 1 1 12rem; }
input[type="checkbox"] { width: auto; accent-color: var(--accent); }
label.inline { display: flex; align-items: center; gap: .4rem; font-weight: 500; color: var(--text); margin: 0; }

/* --- document viewer --- */

.doc-frame {
  width: 100%;
  height: min(80vh, 900px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

/* --- messages --- */

.notice { padding: .6rem .8rem; border-radius: 8px; font-size: .88rem; border: 1px solid transparent; }
.notice-error { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.notice-ok    { background: var(--ok-soft);     color: var(--ok);     border-color: var(--ok); }
.notice-warn  { background: var(--warn-soft);   color: var(--warn);   border-color: var(--warn); }
.notice-info  { background: var(--info-soft);   color: var(--info);   border-color: var(--info); }

.empty { padding: 2rem 1rem; text-align: center; color: var(--text-faint); font-size: .9rem; }

/* --- tabs --- */

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; flex-wrap: wrap; }
.tab {
  padding: .45rem .85rem;
  border: none;
  background: none;
  font: inherit;
  font-size: .9rem;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* --- modal --- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 9, 14, .55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 1rem;
  overflow-y: auto;
  z-index: 50;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  width: min(38rem, 100%);
  box-shadow: 0 8px 40px rgba(0, 0, 0, .3);
}
.modal-wide { width: min(56rem, 100%); }

/* --- SOP library --- */

.sop-list { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(19rem, 1fr)); }
.sop-card { display: block; color: inherit; }
.sop-card:hover { border-color: var(--accent); text-decoration: none; }
.sop-card h3 { margin: 0 0 .3rem; }
.sop-card p { margin: 0 0 .6rem; font-size: .86rem; color: var(--text-dim); }

.person-chip {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .2rem .55rem;
  border-radius: 99px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: .82rem;
  color: inherit;
}
.person-chip:hover { border-color: var(--accent); text-decoration: none; }
.chip-list { display: flex; gap: .35rem; flex-wrap: wrap; }

/* --- team matrix --- */

.matrix td, .matrix th { padding: .35rem .45rem; }
.matrix .yes { color: var(--ok); font-weight: 700; text-align: center; }
.matrix .no  { color: var(--text-faint); text-align: center; }
.matrix .missing { color: var(--danger); font-weight: 700; text-align: center; }
.matrix th.rot { writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; height: 8rem; vertical-align: bottom; }

@media (max-width: 640px) {
  #root { padding: 1rem .75rem 3rem; }
  .nav-inner { padding: .5rem .75rem; gap: .6rem; }
  .nav-meta .nav-name { display: none; }
}
