:root {
  --bg: #f6f4ef; --surface: #ffffff; --surface-2: #efece4; --text: #1f2522; --muted: #66706b; --line: #ddd8cc;
  --accent: #2f5d50; --accent-2: #e8f0ec; --accent-text: #ffffff; --warn: #9a5b00; --warn-bg: #fff4de;
  --danger: #a33a2c; --danger-bg: #fbe9e6; --ok: #2c7a4b; --ok-bg: #e5f4ea; --info-bg: #e9eef8; --info: #33508a;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151917; --surface: #1d2320; --surface-2: #252c28; --text: #e6ebe8; --muted: #9aa59f; --line: #333c37;
    --accent: #7fc0a9; --accent-2: #22332c; --accent-text: #0f1a16; --warn: #f0b45b; --warn-bg: #3a2e1a;
    --danger: #f08a7c; --danger-bg: #3d2420; --ok: #7fd3a0; --ok-bg: #1e3326; --info-bg: #222b3b; --info: #9fb6e6;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 var(--font); }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .6rem; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.05rem; }
.loading { padding: 3rem; text-align: center; color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: .875rem; }
.hidden { display: none !important; }

/* układ */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
nav.side { background: var(--surface); border-right: 1px solid var(--line); padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: .25rem; }
nav.side .brand { font-weight: 700; font-size: 1.15rem; padding: .25rem .6rem 1rem; display: flex; gap: .5rem; align-items: center; }
nav.side .brand img { width: 28px; height: 28px; }
nav.side a { display: flex; align-items: center; gap: .6rem; padding: .55rem .7rem; border-radius: 10px; color: var(--text); text-decoration: none; }
nav.side a:hover { background: var(--surface-2); }
nav.side a.on { background: var(--accent-2); color: var(--accent); font-weight: 600; }
nav.side .who { margin-top: auto; font-size: .85rem; color: var(--muted); padding: .6rem; border-top: 1px solid var(--line); }
main { padding: 1.5rem clamp(1rem, 3vw, 2.5rem) 5rem; max-width: 1100px; width: 100%; }
.ico { width: 20px; height: 20px; flex: none; }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  nav.side { position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: auto; flex-direction: row; justify-content: space-around;
    padding: .3rem .25rem calc(.3rem + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line); z-index: 10; gap: 0; }
  nav.side .brand, nav.side .who { display: none; }
  nav.side a { flex-direction: column; gap: .1rem; font-size: .68rem; padding: .35rem .3rem; flex: 1; text-align: center; }
  main { padding: 1rem 16px 6rem; }
}

/* elementy */
.head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.head h1 { margin: 0; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.card + .card { margin-top: .75rem; }
.grid .card + .card { margin-top: 0; }
.card h3 { margin-bottom: .3rem; }
.list { display: flex; flex-direction: column; gap: .5rem; }
.item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem 1rem; display: flex; gap: .75rem; align-items: center; cursor: pointer; text-decoration: none; color: inherit; }
.item:hover { border-color: var(--accent); }
.item .grow { flex: 1; min-width: 0; }
.item .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.stat { font-size: 1.6rem; font-weight: 700; }
.btn { border: 1px solid var(--line); background: var(--surface); padding: .5rem .9rem; border-radius: 10px; cursor: pointer; display: inline-flex; gap: .4rem; align-items: center; text-decoration: none; color: var(--text); white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.small { padding: .3rem .6rem; font-size: .875rem; }
.btn:disabled { opacity: .55; cursor: default; }
.tag { display: inline-block; font-size: .75rem; padding: .1rem .5rem; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.tag.free { background: var(--info-bg); color: var(--info); }
.tag.requested { background: var(--warn-bg); color: var(--warn); }
.tag.planned { background: var(--accent-2); color: var(--accent); }
.tag.done { background: var(--ok-bg); color: var(--ok); }
.tag.cancelled { background: var(--danger-bg); color: var(--danger); text-decoration: line-through; }
.tag.error { background: var(--danger-bg); color: var(--danger); }
.tag.pending { background: var(--warn-bg); color: var(--warn); }
.neg { color: var(--danger); font-weight: 600; } .pos { color: var(--ok); font-weight: 600; }
.notice { padding: .75rem 1rem; border-radius: var(--radius); background: var(--info-bg); color: var(--info); margin-bottom: 1rem; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; border: 1px dashed var(--line); border-radius: var(--radius); }
.tabs { display: flex; gap: .25rem; margin-bottom: 1rem; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a { padding: .5rem .9rem; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--accent); border-color: var(--accent); font-weight: 600; }

/* formularze */
label { display: block; font-size: .875rem; color: var(--muted); margin: .6rem 0 .2rem; }
input, select, textarea { width: 100%; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type=checkbox] { width: auto; }
.check { display: flex; gap: .5rem; align-items: center; color: var(--text); font-size: 1rem; }
textarea { min-height: 80px; resize: vertical; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .75rem; }
@media (max-width: 520px) { .cols { grid-template-columns: 1fr; } }
.actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1.25rem; flex-wrap: wrap; }
.err { color: var(--danger); font-size: .9rem; margin-top: .5rem; }
.copy { display: flex; gap: .5rem; } .copy input { font-size: .85rem; }

dialog { border: 0; border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px); background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog form { padding: 1.25rem; }

/* logowanie */
.auth { max-width: 380px; margin: 10vh auto; padding: 0 16px; }
.auth .brand { text-align: center; margin-bottom: 1.5rem; }
.auth .brand img { width: 56px; height: 56px; }

/* terminarz */
.week { display: flex; flex-direction: column; gap: 1rem; }
.day h3 { font-size: .95rem; color: var(--muted); margin-bottom: .4rem; }
.day h3::first-letter { text-transform: uppercase; }
.day.today h3 { color: var(--accent); }
.lesson { border-left: 4px solid var(--accent); }
.lesson.free { border-left-color: var(--info); border-style: dashed; border-left-style: solid; }
.lesson.requested { border-left-color: var(--warn); }
.lesson.done { border-left-color: var(--ok); }
.lesson.cancelled { border-left-color: var(--danger); opacity: .7; }
.time { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 3.2rem; }

/* czat */
.chat { display: grid; grid-template-columns: 260px 1fr; gap: 1rem; height: calc(100vh - 7rem); }
.chat .convs { overflow-y: auto; display: flex; flex-direction: column; gap: .35rem; }
.chat .conv { padding: .55rem .75rem; border-radius: 10px; text-decoration: none; color: var(--text); display: block; }
.chat .conv:hover { background: var(--surface-2); }
.chat .conv.on { background: var(--accent-2); color: var(--accent); }
.chat .conv .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; font-size: .95rem; }
.thread { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.msgs { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .75rem; }
.msg { max-width: 88%; padding: .6rem .9rem; border-radius: 14px; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 4px; }
.msg.user a { color: inherit; }
.msg.assistant { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.msg.assistant.error { background: var(--danger-bg); color: var(--danger); }
.msg img.att { max-width: 240px; max-height: 240px; border-radius: 8px; display: block; margin-bottom: .4rem; cursor: zoom-in; }
.msg .md > :first-child { margin-top: 0; } .msg .md > :last-child { margin-bottom: 0; }
.typing span { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); margin-right: 3px; animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; } .typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.composer { border-top: 1px solid var(--line); padding: .6rem; display: flex; gap: .5rem; align-items: flex-end; }
.composer textarea { min-height: 44px; max-height: 180px; resize: none; }
.composer .preview { position: relative; } .composer .preview img { height: 44px; border-radius: 6px; }
.composer .preview button { position: absolute; top: -8px; right: -8px; border-radius: 50%; width: 22px; height: 22px; padding: 0; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: 12px; }
.iconbtn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; width: 44px; height: 44px; display: grid; place-items: center; cursor: pointer; flex: none; color: var(--text); }
.iconbtn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.starters { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; margin-top: 1rem; }
@media (max-width: 760px) {
  .chat { grid-template-columns: 1fr; height: calc(100vh - 9.5rem); height: calc(100dvh - 9.5rem); }
  .chat.has-conv .convs-wrap { display: none; } .chat:not(.has-conv) .thread { display: none; }
}

/* treść (Markdown + wzory) */
.md { overflow-wrap: anywhere; }
.md table { border-collapse: collapse; } .md td, .md th { border: 1px solid var(--line); padding: .3rem .5rem; }
.md pre { background: var(--surface-2); padding: .75rem; border-radius: 8px; overflow-x: auto; }
.md .katex-display { overflow-x: auto; overflow-y: hidden; padding: .2rem 0; }
.material { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(1rem, 4vw, 2.5rem); }
.material details.answers { margin-top: 1.5rem; border-top: 2px dashed var(--line); padding-top: 1rem; }
.material details.answers > summary { cursor: pointer; font-weight: 700; font-size: 1.1rem; }

@media print {
  nav.side, .noprint, .head .row, #toast { display: none !important; }
  .shell { display: block; } main { padding: 0; max-width: none; }
  body { background: #fff; color: #000; }
  .material { border: 0; padding: 0; }
  .material details.answers { break-before: page; }
  .material.no-answers details.answers { display: none; }
  .material details.answers > summary { list-style: none; }
}
#toast { position: fixed; left: 50%; bottom: 5.5rem; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 100; max-width: 90vw; }
#toast.show { opacity: 1; }
