:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --text: #16181d;
  --muted: #646a76;
  --border: #e3e5ea;
  --accent: #5b5bd6;
  --accent-text: #ffffff;
  --ok: #1f9d55;
  --warn: #c98a00;
  --err: #d64545;
  --idle: #9aa1ad;
  --ok-bg: #e6f6ec;
  --warn-bg: #fff4d6;
  --err-bg: #fde8e8;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1f232b;
    --text: #e8eaee;
    --muted: #9aa1ad;
    --border: #2a2f38;
    --accent: #8b8bf0;
    --accent-text: #0f1115;
    --ok: #4cc584;
    --warn: #e5b23b;
    --err: #f07272;
    --idle: #6b7280;
    --ok-bg: #12291c;
    --warn-bg: #2d2611;
    --err-bg: #331a1a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.5rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1rem; margin: 2rem 0 .75rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
code { background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.nowrap { white-space: nowrap; }

/* layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; padding: 1.25rem 1rem;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 1.5rem;
}
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.1rem; color: var(--text); }
.logo {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent); color: var(--accent-text); font-weight: 800;
}
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { padding: .5rem .75rem; border-radius: 8px; color: var(--muted); font-weight: 500; }
.side nav a:hover { background: var(--surface-2); color: var(--text); }
.side nav a.active { background: var(--surface-2); color: var(--text); }
.logout { margin-top: auto; }
main { padding: 1.75rem 2rem 3rem; max-width: 1200px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.head-actions { display: flex; gap: .5rem; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side {
    position: sticky; height: auto; z-index: 5; flex-direction: row; align-items: center;
    padding: .6rem 1rem; gap: .75rem; border-right: 0; border-bottom: 1px solid var(--border); overflow-x: auto;
  }
  .side .brand span:not(.logo) { display: none; }
  .side nav { flex-direction: row; }
  .side nav a { padding: .4rem .6rem; white-space: nowrap; }
  .logout { margin-top: 0; margin-left: auto; }
  main { padding: 1.25rem 1rem 2.5rem; }
}

/* components */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); }
.grid { display: grid; gap: .75rem; }
.stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.cards { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.courses { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.stat-label { color: var(--muted); font-size: .8rem; }
.stat-value { font-size: 1.25rem; font-weight: 650; }
.stat.good .stat-value { color: var(--ok); }
.stat.bad .stat-value { color: var(--err); }

.conn-head { display: flex; align-items: center; gap: .5rem; }
.conn-head .small { margin-left: auto; }
.conn p { margin: .4rem 0 0; font-size: .9rem; word-break: break-word; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--idle); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-bg); }
.dot.error { background: var(--err); box-shadow: 0 0 0 3px var(--err-bg); }

.pill { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.pill.ok, .pill.approved, .pill.posted { background: var(--ok-bg); color: var(--ok); }
.pill.error, .pill.dismissed { background: var(--err-bg); color: var(--err); }
.pill.running, .pill.pending { background: var(--warn-bg); color: var(--warn); }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .65rem .9rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
td.actions { display: flex; gap: .4rem; justify-content: flex-end; }
.clip { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live { margin-top: 1rem; }

.btn {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 8px; padding: .5rem .9rem;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: .3rem .65rem; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: .5rem .75rem; }
.link:hover { color: var(--text); }

.notice { padding: .7rem 1rem; border-radius: 10px; margin: 0 0 1rem; font-weight: 500; }
.notice.ok { background: var(--ok-bg); color: var(--ok); }
.notice.err { background: var(--err-bg); color: var(--err); }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg a { padding: .4rem .8rem; color: var(--muted); font-weight: 500; }
.seg a.active { background: var(--surface-2); color: var(--text); }

/* calendar */
.days { display: grid; gap: .75rem; }
.event { display: grid; grid-template-columns: 110px 1fr auto; gap: .75rem; padding: .45rem 0; border-top: 1px solid var(--border); align-items: baseline; }
.event:first-of-type { border-top: 0; }
.event .when { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .9rem; }
@media (max-width: 560px) { .event { grid-template-columns: 1fr; gap: 0; } .event .cal { justify-self: start; } }

/* grades */
.course-head { display: flex; justify-content: space-between; align-items: center; }
.total { margin: 0 0 .5rem; }
.items { list-style: none; padding: 0; margin: 0; }
.items li { display: flex; justify-content: space-between; gap: 1rem; padding: .35rem 0; border-top: 1px solid var(--border); font-size: .92rem; }
.items li .val { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.items li.done .val { color: var(--ok); }
.items li.short .val { color: var(--warn); }

/* messages */
.question { margin-bottom: .75rem; display: flex; justify-content: space-between; gap: 1rem; align-items: center; flex-wrap: wrap; }
.question .actions { display: flex; gap: .4rem; }
.msg-text { white-space: pre-wrap; word-break: break-word; }

/* forms */
.form { display: flex; flex-direction: column; gap: 1.1rem; max-width: 560px; }
.field { display: flex; flex-direction: column; gap: .35rem; border: 0; padding: 0; margin: 0; }
.field.two { flex-direction: row; gap: 1rem; flex-wrap: wrap; }
.field.two > div { flex: 1; min-width: 180px; display: flex; flex-direction: column; gap: .35rem; }
label, legend { font-weight: 600; font-size: .9rem; }
input, select {
  font: inherit; padding: .55rem .7rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.check input { width: auto; }
.info { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1.25rem; margin: 0 0 .75rem; }
.info dt { color: var(--muted); }
.info dd { margin: 0; word-break: break-word; }

/* login */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.login { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: .75rem; padding: 1.75rem; }
.login .brand { margin-bottom: .5rem; }

/* live badge (WebSocket state) */
.live-badge { display: inline-flex; align-items: center; gap: .4rem; font-size: .8rem; font-weight: 600; color: var(--muted); padding: .3rem .6rem; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); }
.live-badge[hidden] { display: none; }
.live-badge[data-state="live"] .dot { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); }
.live-badge[data-state="down"] .dot { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-bg); }

/* layout fixes */
main { min-width: 0; }              /* let wide tables scroll inside .table-wrap instead of widening the page */
.btn { white-space: nowrap; }
td.next { white-space: nowrap; }
@media (max-width: 760px) {
  /* jobs table becomes one compact card per job */
  .jobs thead, .jobs .desc, .jobs .clip { display: none; }
  .jobs tr { display: grid; grid-template-columns: 1fr auto; gap: .2rem .75rem; padding: .75rem .9rem; border-bottom: 1px solid var(--border); }
  .jobs tr:last-child { border-bottom: 0; }
  .jobs td { border: 0; padding: 0; }
  .jobs td.last, .jobs td.next { font-size: .85rem; color: var(--muted); }
  .jobs td.last::before { content: "Last "; }
  .jobs td.next::before { content: "Next "; }
  .jobs td.actions { grid-column: 1 / -1; justify-content: flex-start; margin-top: .35rem; }
  th.details, td.details { display: none; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat-value { font-size: 1.05rem; }
}

/* mail */
.mail-list { display: grid; gap: .6rem; }
.mail p { margin: .45rem 0 0; }
.mail-head { display: flex; gap: .5rem; align-items: baseline; }
.mail-head .subject { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.mail.low { opacity: .7; }
.mail.high { border-left: 3px solid var(--err); }
.mail .action { font-weight: 600; }
