:root {
  --bg: #f5f6f8; --surface: #fff; --text: #1d2330; --muted: #6b7385; --line: #e3e6ec;
  --brand: #1f5fbf; --brand-ink: #fff; --danger: #c0392b; --ok-bg: #e7f4ec; --ok: #1e7a45;
  --err-bg: #fbeaea; --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #12151b; --surface: #1b1f27; --text: #e6e9ef; --muted: #959cab; --line: #2b313c;
          --brand: #5b9bff; --brand-ink: #0b1220; --ok-bg: #16301f; --ok: #6fd39a; --err-bg: #3a1a1a; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
       font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.4rem 0 .6rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }

.topbar { display: flex; align-items: center; gap: 1.5rem; padding: .6rem 1.25rem; background: var(--surface);
          border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.topbar nav { display: flex; gap: 1rem; flex: 1; flex-wrap: wrap; }
.topbar nav a { color: var(--text); }
.me { display: flex; align-items: center; gap: .6rem; font-size: .9rem; }
.brand { display: inline-flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--text); }
.brand.big { font-size: 1.5rem; }
.logo { display: inline-grid; place-items: center; width: 1.8em; height: 1.8em; border-radius: 8px;
        background: var(--brand); color: var(--brand-ink); font-weight: 800; }

.page { max-width: 1100px; margin: 0 auto; padding: 1.25rem 16px 3rem; }
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: min(380px, 100%); }
.auth-card .flash { margin-bottom: 1rem; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
        padding: 1rem 1.1rem; margin-bottom: .8rem; display: block; color: var(--text); }
a.card:hover { border-color: var(--brand); text-decoration: none; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .8rem; }
.course-card { display: flex; flex-direction: column; gap: .2rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 760px) { .grid2 { grid-template-columns: 1fr; } }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .8rem; margin-bottom: 1rem; }
@media (max-width: 600px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem; }
.stat b { display: block; font-size: 1.6rem; }
.stat span { color: var(--muted); font-size: .85rem; }

.row { display: flex; justify-content: space-between; gap: 1rem; padding: .55rem .2rem;
       border-bottom: 1px solid var(--line); color: var(--text); }
.body { white-space: pre-wrap; margin: .3rem 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.late { color: var(--danger); }
.code { font: 600 .75rem ui-monospace, Menlo, monospace; color: var(--brand); letter-spacing: .02em; }
.pill { display: inline-block; font-size: .72rem; padding: .05rem .5rem; border-radius: 99px;
        background: var(--line); color: var(--text); text-transform: capitalize; }
.pill.admin { background: #f3e2ff; color: #6a2c91; }
.pill.teacher { background: #e1efff; color: #1f5fbf; }
.pill.student { background: #e5f6ea; color: #1e7a45; }
.flash { background: var(--ok-bg); color: var(--ok); padding: .6rem .9rem; border-radius: var(--radius); margin-bottom: 1rem; }
.flash.error { background: var(--err-bg); color: var(--danger); }

.course-head h1 { margin: 0; }
.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--line); margin: 1rem 0; overflow-x: auto; }
.tabs a { padding: .5rem .9rem; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs a.on { color: var(--text); border-color: var(--brand); font-weight: 600; }
.material { padding: .5rem 0; border-top: 1px solid var(--line); }
.material:first-of-type { border-top: 0; }
.file { display: inline-block; margin-top: .2rem; }
.grade { margin-top: .6rem; padding: .6rem; border-radius: 8px; background: var(--bg); }

label { display: block; margin: .5rem 0; font-size: .9rem; color: var(--muted); }
input, select, textarea { display: block; width: 100%; margin-top: .25rem; padding: .5rem .6rem; font: inherit;
        color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
input[type=file] { padding: .35rem; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
@media (max-width: 600px) { .cols { grid-template-columns: 1fr; } }
button, .button { display: inline-block; font: inherit; padding: .45rem .9rem; border-radius: 8px; cursor: pointer;
        border: 1px solid var(--line); background: var(--surface); color: var(--text); }
button.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
button.wide { width: 100%; margin-top: .6rem; }
button.link { border: 0; background: none; padding: 0; color: var(--brand); }
.danger, button.link.danger { color: var(--danger); }
form.inline, details.inline { display: inline; }
.inline-form { display: flex; gap: .5rem; align-items: center; margin-bottom: .8rem; flex-wrap: wrap; }
.inline-form input, .inline-form select { flex: 1; min-width: 160px; margin: 0; width: auto; }
details summary { cursor: pointer; color: var(--brand); }
details[open] summary { margin-bottom: .5rem; }
.grade-form { margin-top: .6rem; border-top: 1px solid var(--line); padding-top: .4rem; }
.grade-form input[type=number] { display: inline-block; width: 6rem; }

table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line);
        border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: .55rem .75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .82rem; color: var(--muted); font-weight: 600; }
tr.total td { font-weight: 700; }
tr.inactive td { opacity: .55; }
td.actions { white-space: nowrap; }
.scroll { overflow-x: auto; }
