:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-soft: #dbeafe;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --fach: #2563eb;
  --fue: #9333ea;
  --pflicht: #475569;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(15 23 42 / .06), 0 4px 16px rgb(15 23 42 / .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120; --surface: #111827; --surface-2: #0f172a; --border: #1f2937;
    --text: #e5e7eb; --muted: #94a3b8; --primary: #60a5fa; --primary-soft: #1e3a8a55;
    --ok: #4ade80; --ok-soft: #14532d55; --warn: #fbbf24; --warn-soft: #78350f55;
    --bad: #f87171; --bad-soft: #7f1d1d55; --fach: #60a5fa; --fue: #c084fc; --pflicht: #94a3b8;
    --shadow: 0 1px 2px rgb(0 0 0 / .3); color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
a { color: var(--primary); }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem;
  padding: .75rem 1rem; background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .6rem; }
.brand strong { display: block; font-size: 1rem; }
.brand small { display: block; color: var(--muted); font-size: .75rem; }
.brand-mark {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
  background: var(--primary); color: #fff; font-weight: 700; font-size: .9rem;
}
.tabs { display: none; gap: .25rem; margin-left: auto; }
.tabs button {
  border: 0; background: none; padding: .5rem .9rem; border-radius: 999px; cursor: pointer; color: var(--muted); font-weight: 500;
}
.tabs button.active { background: var(--primary-soft); color: var(--primary); }
.logout { margin-left: auto; font-size: .85rem; color: var(--muted); text-decoration: none; }
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav button {
  border: 0; background: none; padding: .55rem 0 .6rem; display: flex; flex-direction: column; align-items: center;
  font-size: .72rem; color: var(--muted); cursor: pointer;
}
.bottomnav button span { font-size: 1.15rem; line-height: 1.2; }
.bottomnav button.active { color: var(--primary); }
@media (min-width: 820px) {
  body { padding-bottom: 0; }
  .tabs { display: flex; }
  .logout { margin-left: .5rem; }
  .bottomnav { display: none; }
}

main { max-width: 1200px; margin: 0 auto; padding: 1rem; }
.loading { color: var(--muted); }

/* Cards & grid */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.grid { display: grid; gap: 1rem; }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.section { margin-top: 1.5rem; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: .6rem; flex-wrap: wrap; }

.stat .value { font-size: 1.9rem; font-weight: 700; }
.stat .label { color: var(--muted); font-size: .85rem; }
.progress { height: 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; margin: .5rem 0 .25rem; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: 99px; transition: width .3s; }
.progress.done > span { background: var(--ok); }
.progress.over > span { background: var(--warn); }

.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip {
  display: inline-flex; align-items: center; gap: .25rem; padding: .1rem .55rem; border-radius: 99px; font-size: .75rem;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.chip.fach { color: var(--fach); border-color: color-mix(in srgb, var(--fach) 35%, transparent); background: color-mix(in srgb, var(--fach) 8%, transparent); }
.chip.fue { color: var(--fue); border-color: color-mix(in srgb, var(--fue) 35%, transparent); background: color-mix(in srgb, var(--fue) 8%, transparent); }
.chip.pflicht { color: var(--pflicht); }
.chip.ok { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.chip.warn { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.chip.bad { color: var(--bad); background: var(--bad-soft); border-color: transparent; }

.btn {
  border: 1px solid var(--border); background: var(--surface); padding: .45rem .85rem; border-radius: 10px; cursor: pointer;
  font-weight: 500; display: inline-flex; align-items: center; gap: .35rem; text-decoration: none; color: var(--text);
}
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.small { padding: .25rem .6rem; font-size: .8rem; }
.btn[aria-pressed="true"] { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }

/* Filters */
.filters { display: grid; gap: .6rem; margin-bottom: 1rem; }
.filters input[type=search] {
  width: 100%; padding: .65rem .9rem; border-radius: 12px; border: 1px solid var(--border); background: var(--surface);
}
.filter-row { display: flex; gap: .5rem; overflow-x: auto; padding-bottom: .2rem; scrollbar-width: none; }
.filter-row::-webkit-scrollbar { display: none; }
.filter-row select {
  padding: .45rem .6rem; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); min-width: 0; flex: 0 0 auto;
}
.count { color: var(--muted); font-size: .85rem; margin-bottom: .5rem; }

/* Module list */
.module-list { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); }
@media (max-width: 420px) { .module-list { grid-template-columns: 1fr; } }
.module {
  text-align: left; cursor: pointer; display: grid; gap: .45rem; border-left: 4px solid var(--border);
}
.module.fach { border-left-color: var(--fach); }
.module.fue { border-left-color: var(--fue); }
.module.pflicht { border-left-color: var(--pflicht); }
.module.done { opacity: .5; }
.module .title { font-weight: 600; }
.module .code { color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.module .row { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.module .kp { font-weight: 700; white-space: nowrap; }
.module .times { font-size: .8rem; color: var(--muted); }

/* Detail sheet */
dialog.sheet {
  border: 0; padding: 0; margin: auto; width: min(760px, 100%); max-height: 92vh; border-radius: 18px; background: var(--surface); color: var(--text);
  box-shadow: 0 20px 60px rgb(0 0 0 / .3);
}
dialog.sheet::backdrop { background: rgb(15 23 42 / .5); }
@media (max-width: 640px) {
  dialog.sheet { margin: auto 0 0; max-width: 100%; width: 100%; max-height: 90vh; border-radius: 18px 18px 0 0; }
}
.sheet-head { position: sticky; top: 0; background: var(--surface); padding: 1rem 1rem .75rem; border-bottom: 1px solid var(--border); z-index: 1; }
.sheet-head .close { position: absolute; right: .75rem; top: .75rem; border: 0; background: var(--surface-2); width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: 1.1rem; }
.sheet-body { padding: 1rem; display: grid; gap: 1.1rem; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .5rem; }
.fact { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: .5rem .7rem; }
.fact .k { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.fact .v { font-weight: 600; font-size: .9rem; }
.sheet-body ul { margin: .25rem 0 0; padding-left: 1.1rem; }
.sheet-body li { margin: .15rem 0; }
details.more summary { cursor: pointer; color: var(--primary); font-weight: 500; }
.session { border: 1px solid var(--border); border-radius: 10px; padding: .55rem .7rem; margin-top: .4rem; font-size: .88rem; }
.session .t { font-weight: 600; }
.sheet-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* Plan */
.plan-head { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; justify-content: space-between; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: .45rem .8rem; cursor: pointer; color: var(--muted); }
.seg button.active { background: var(--primary); color: #fff; }
.picked { display: grid; gap: .5rem; }
.picked-item { display: grid; grid-template-columns: 10px 1fr auto; gap: .6rem; align-items: start; padding: .55rem .6rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.picked-item .dot { width: 10px; height: 10px; border-radius: 50%; margin-top: .4rem; }
.picked-item .sess { display: grid; gap: .15rem; margin-top: .3rem; }
.picked-item label { font-size: .8rem; color: var(--muted); display: flex; gap: .35rem; align-items: flex-start; }
.picked-item .rm { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 1.1rem; }

.timetable { position: relative; display: grid; grid-template-columns: 44px repeat(5, 1fr); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.tt-head { position: sticky; top: 0; background: var(--surface-2); text-align: center; font-weight: 600; font-size: .8rem; padding: .4rem 0; border-bottom: 1px solid var(--border); }
.tt-col { position: relative; border-left: 1px solid var(--border); }
.tt-hours { position: relative; }
.tt-hour { position: absolute; left: 0; right: 0; font-size: .7rem; color: var(--muted); text-align: right; padding-right: 6px; transform: translateY(-.5em); }
.tt-line { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--border); }
.tt-block {
  position: absolute; left: 3px; right: 3px; border-radius: 8px; padding: 3px 5px; font-size: .72rem; line-height: 1.2; overflow: hidden;
  color: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .2); cursor: pointer;
}
.tt-block b { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: .74rem; }
.tt-block.conflict { outline: 2px solid var(--bad); outline-offset: 1px; }
.tt-block.conflict::after { content: "⚠"; position: absolute; right: 4px; top: 2px; }

.daylist { display: none; }
@media (max-width: 700px) {
  .timetable { display: none; }
  .daylist { display: grid; gap: .75rem; }
}
.daylist .day h3 { font-size: .9rem; margin: 0 0 .35rem; color: var(--muted); }
.daylist .slot { display: grid; grid-template-columns: 74px 1fr; gap: .6rem; padding: .5rem .6rem; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); border-left: 4px solid; margin-bottom: .35rem; font-size: .88rem; }
.daylist .slot.conflict { background: var(--bad-soft); }
.daylist .slot .time { font-variant-numeric: tabular-nums; font-weight: 600; }

.notice { padding: .65rem .8rem; border-radius: 10px; font-size: .88rem; }
.notice.warn { background: var(--warn-soft); }
.notice.bad { background: var(--bad-soft); }
.notice.info { background: var(--primary-soft); }
.notice.ok { background: var(--ok-soft); }

.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }
.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th, .table td { text-align: left; padding: .45rem .4rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { color: var(--muted); font-weight: 500; font-size: .78rem; text-transform: uppercase; }
.scroll-x { overflow-x: auto; }

.toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: .55rem 1rem; border-radius: 99px; font-size: .88rem; opacity: 0; pointer-events: none; transition: .25s; z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%); }
@media (min-width: 820px) { .toast { bottom: 24px; } }

/* Login */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 1.5rem; box-shadow: var(--shadow); }
.login-card form { display: grid; gap: .9rem; margin-top: 1.25rem; }
.login-card label { display: grid; gap: .3rem; font-size: .85rem; color: var(--muted); }
.login-card input { padding: .65rem .8rem; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 1rem; }
.login-card .btn { justify-content: center; padding: .65rem; }
.login-error { color: var(--bad); margin: 0; font-size: .88rem; }

@media print {
  .topbar, .bottomnav, .no-print, .filters { display: none !important; }
  body { background: #fff; padding: 0; }
  .timetable { display: grid !important; }
  .daylist { display: none !important; }
  .card { box-shadow: none; }
}
