:root {
  --bg: #f6f5f1; --panel: #ffffff; --side: #ecebe5; --text: #1f2328; --muted: #68707a;
  --line: #d9d7cf; --accent: #2f6f5e; --accent-text: #ffffff; --warn: #a15c00; --bad: #b3261e;
  --soft: #e6f0ec;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17191c; --panel: #202327; --side: #1b1d20; --text: #e6e6e3; --muted: #9aa1a9;
    --line: #34383d; --accent: #5fb39b; --accent-text: #0f1513; --warn: #e0a84f; --bad: #f08a80;
    --soft: #24332e;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 16px/1.5 "Segoe UI", system-ui, sans-serif; background: var(--bg); color: var(--text); }
h1, h2, h3 { line-height: 1.25; }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 14px; cursor: pointer; min-height: 40px;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.small { padding: 4px 10px; min-height: 34px; font-size: 14px; }
button.ghost { background: transparent; border-color: transparent; }
button:disabled, body.busy button.ai { opacity: .45; pointer-events: none; }
input[type=text], input[type=password], input[type=number], input[type=search], select, textarea {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%;
}
textarea { resize: vertical; min-height: 80px; }
a { color: var(--accent); text-decoration: none; }
.hint { color: var(--muted); font-size: 14px; margin: 4px 0 10px; }

#app { display: grid; grid-template-columns: 270px 1fr; height: 100%; }
#sidebar { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.brand { font-weight: 700; font-size: 20px; padding: 16px; display: flex; align-items: center; gap: 8px; }
.brand span { flex: 1; }
.brand button { font-weight: 400; }
.group-head { text-transform: uppercase; font-size: 12px; letter-spacing: .06em; color: var(--muted); padding: 10px 8px 4px; }
.edit-row { display: flex; gap: 4px; align-items: center; padding: 3px 4px; }
.edit-row input { flex: 1; min-width: 0; padding: 5px 8px; }
.edit-row input.group-input { flex: 0 0 84px; font-size: 13px; }
.edit-row.group input { text-transform: uppercase; font-size: 12px; letter-spacing: .06em; }
.edit-row button { padding: 2px 7px; min-height: 30px; }
#onenote-list { max-height: 50vh; overflow-y: auto; margin: 10px 0; }
#onenote-list label { padding: 7px 6px; border-radius: 8px; cursor: pointer; }
#onenote-list label:hover { background: var(--soft); }
#tree { flex: 1; overflow-y: auto; padding: 0 8px; }
.side-foot { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.side-foot button { flex: 1; }
.fach { margin-bottom: 10px; }
.fach-head { display: flex; align-items: center; font-weight: 600; padding: 6px 8px; }
.fach-head span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item {
  display: flex; align-items: center; gap: 6px; width: 100%; text-align: left; border: 0; background: transparent;
  padding: 8px 10px 8px 18px; border-radius: 8px; min-height: 40px;
}
.item span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item.active { background: var(--panel); box-shadow: inset 3px 0 0 var(--accent); }
.item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.item.add { color: var(--muted); }
.item.total { font-style: italic; }

#main { overflow-y: auto; padding: 22px 28px 60px; min-width: 0; }
.empty { max-width: 560px; margin: 12vh auto; text-align: center; color: var(--muted); }
.empty h1 { color: var(--text); }
.head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.head h1 { margin: 0; font-size: 26px; }
.head .crumb { color: var(--muted); }
.head .spacer { flex: 1; }
.banner { background: var(--soft); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin: 14px 0; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--line); margin: 18px 0 20px; }
.tabs button { border: 0; border-radius: 8px 8px 0 0; background: transparent; padding: 10px 16px; color: var(--muted); }
.tabs button.active { color: var(--text); font-weight: 600; box-shadow: inset 0 -3px 0 var(--accent); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; margin-bottom: 14px; }
.card h2 { margin: 0 0 10px; font-size: 20px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row .grow { flex: 1; min-width: 180px; }

.drop { border: 2px dashed var(--line); border-radius: 12px; padding: 28px; text-align: center; color: var(--muted); margin-bottom: 16px; }
.drop.over { border-color: var(--accent); background: var(--soft); }
.mat { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.mat .name { font-weight: 600; flex: 1; min-width: 200px; overflow-wrap: anywhere; }
.badge { font-size: 13px; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line); white-space: nowrap; }
.badge.ok { color: var(--accent); border-color: var(--accent); }
.badge.leer { color: var(--warn); border-color: var(--warn); }
.badge.fehler { color: var(--bad); border-color: var(--bad); }
.mat-hint { flex-basis: 100%; color: var(--muted); font-size: 14px; }

.focus-row { display: grid; grid-template-columns: 1fr 170px 40px; gap: 8px; margin-bottom: 8px; }
.outline-item { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.outline-item .row { margin-bottom: 8px; }
.outline-item .num { font-weight: 700; color: var(--muted); width: 26px; }

.sum-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.section h2 { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.section .tools { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.section .tools input { flex: 1; min-width: 180px; width: auto; }
.section textarea { min-height: 260px; font-family: Consolas, monospace; font-size: 14px; }
.section.writing { opacity: .6; }
.prose { overflow-wrap: anywhere; }
.prose h3 { font-size: 17px; margin: 16px 0 6px; }
.prose table { border-collapse: collapse; margin: 10px 0; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--line); padding: 5px 10px; text-align: left; }
.prose code { background: var(--bg); padding: 1px 5px; border-radius: 4px; }
.prose pre { background: var(--bg); padding: 10px; border-radius: 8px; overflow-x: auto; }
.prose blockquote { border-left: 3px solid var(--line); margin: 8px 0; padding-left: 12px; color: var(--muted); }
.placeholder { color: var(--muted); font-style: italic; }

.chat { position: sticky; top: 0; display: flex; flex-direction: column; max-height: calc(100vh - 60px); }
.chat-log { overflow-y: auto; flex: 1; min-height: 120px; margin-bottom: 10px; }
.msg { border-radius: 10px; padding: 8px 12px; margin-bottom: 8px; font-size: 15px; }
.msg.user { background: var(--soft); margin-left: 24px; white-space: pre-wrap; }
.msg.assistant { background: var(--bg); margin-right: 12px; }
.msg p:first-child { margin-top: 0; } .msg p:last-child { margin-bottom: 0; }
.change { border: 1px solid var(--accent); border-radius: 8px; padding: 8px; margin-top: 8px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.change span { flex: 1; min-width: 120px; font-size: 14px; }

.card-form { display: grid; grid-template-columns: minmax(180px, 1fr) 2fr; gap: 10px; align-items: start; }
.kcard { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; }
.kcard > div:first-child { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.kcard p { margin: 6px 0 0; white-space: pre-wrap; }
.card > .kcard { border-top: 1px solid var(--line); padding: 10px 0; }
.learn { text-align: center; padding: 40px 24px; max-width: 720px; margin: 0 auto; }
.learn-term { font-size: 30px; font-weight: 700; margin: 18px 0 26px; overflow-wrap: anywhere; }
.learn-def { font-size: 19px; white-space: pre-wrap; background: var(--soft); border-radius: 10px; padding: 18px; text-align: left; }
@media (max-width: 760px) { .card-form { grid-template-columns: 1fr; } }

#search { margin: 0 12px 12px; width: auto; }
.setup { text-align: left; margin-top: 22px; color: var(--text); }
.setup ol { padding-left: 22px; margin: 8px 0 14px; }
.setup input { flex: 1; min-width: 220px; }
.exam-head { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; }
#exam-timer { font-variant-numeric: tabular-nums; font-weight: 600; }
#exam-timer.over { color: var(--bad); }
#notice { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); width: min(760px, calc(100vw - 32px)); z-index: 40;
  background: var(--panel); border: 1px solid var(--line); border-left: 5px solid var(--warn); border-radius: 10px;
  padding: 12px 16px; box-shadow: 0 8px 28px #0004; display: flex; gap: 14px; align-items: center; }
#notice[hidden], #notice button[hidden] { display: none; }
#notice.error { border-left-color: var(--bad); }
#notice span { flex: 1; }
.pages { padding: 6px 10px; }
.chapter { font-weight: 600; font-size: 13px; color: var(--accent); padding: 10px 8px 2px; }
.menu.small summary { min-height: 34px; padding: 4px 10px; font-size: 14px; }
.menu.left .menu-items { right: auto; left: 0; }
.page { display: flex; gap: 10px; align-items: center; padding: 6px 8px; border-radius: 8px; cursor: pointer; }
.page:hover { background: var(--soft); }
.page input { width: 20px; height: 20px; flex: none; }
.page strong { width: 54px; flex: none; }
.page span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 14px; }
.page.off strong, .page.off span { opacity: .45; text-decoration: line-through; }
.tip { background: var(--soft); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 10px;
  padding: 10px 14px; margin-bottom: 16px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 15px; }
.tip span { flex: 1; min-width: 260px; }
button.on { border-color: var(--accent); color: var(--accent); }
button.src { min-height: 0; padding: 0 7px; margin: 0 2px; font-size: 12px; line-height: 1.6; border-radius: 999px;
  color: var(--accent); border-color: var(--line); vertical-align: 1px; white-space: nowrap; }
.math.block { display: block; margin: 10px 0; overflow-x: auto; }
button.src.ref { color: var(--text); }
.section.flash { box-shadow: 0 0 0 2px var(--accent); transition: box-shadow .3s; }
.tools.revise { border-top: 0; padding-top: 0; }
.spacer, .grow { flex: 1; }

.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px;
  min-height: 40px; background: var(--panel); display: flex; align-items: center; }
.menu summary::-webkit-details-marker { display: none; }
.menu summary::after { content: "▾"; margin-left: 8px; color: var(--muted); }
.menu-items { position: absolute; right: 0; top: calc(100% + 4px); z-index: 10; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 6px; min-width: 250px; box-shadow: 0 6px 24px #0003; display: flex; flex-direction: column; }
.menu-items a, .menu-items button { display: block; text-align: left; padding: 8px 10px; border-radius: 6px; color: var(--text);
  width: 100%; min-height: 0; }
.menu-items a:hover, .menu-items button:hover { background: var(--soft); }

.hit { display: block; width: 100%; text-align: left; }
.question textarea { margin-top: 10px; }
.question h2 { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.feedback, .solution { border-radius: 10px; padding: 12px 14px; margin-top: 12px; }
.feedback { background: var(--soft); }
.solution { background: var(--bg); }

#viewer { position: fixed; top: 0; right: 0; bottom: 0; width: min(48vw, 820px); background: var(--panel);
  border-left: 1px solid var(--line); box-shadow: -8px 0 28px #0003; z-index: 15; display: flex; flex-direction: column; }
#viewer[hidden] { display: none; }
#viewer header { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
#viewer-title { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#viewer-body { flex: 1; min-height: 0; overflow: auto; }
#viewer iframe { width: 100%; height: 100%; border: 0; display: block; }
#viewer img { max-width: 100%; display: block; }
.pdfview { padding: 8px; }
.pdfview .row { margin-bottom: 8px; }
.pdfview canvas { display: block; margin: 0 auto; background: #fff; }
@media (min-width: 1100px) { body.viewing #main { padding-right: calc(min(48vw, 820px) + 28px); } body.viewing .sum-layout { grid-template-columns: 1fr; } }
@media (max-width: 1099px) { #viewer { width: 100vw; } }

#busy {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; display: flex; gap: 10px; align-items: center; z-index: 20;
}
#busy[hidden], #toast[hidden] { display: none; }
.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#toast {
  position: fixed; right: 20px; top: 20px; max-width: 440px; background: var(--panel); border: 1px solid var(--line);
  border-left: 4px solid var(--accent); padding: 12px 16px; border-radius: 8px; z-index: 30; box-shadow: 0 6px 24px #0003;
}
#toast.error { border-left-color: var(--bad); }

dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text); padding: 22px; width: min(620px, 94vw); }
dialog::backdrop { background: #0006; }
dialog h2 { margin-top: 0; }
#dlg-text { width: min(900px, 94vw); }
#dlg-text textarea { height: 55vh; font-family: Consolas, monospace; font-size: 14px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 0 0 14px; padding: 10px 14px; }
fieldset label { display: block; margin: 8px 0; }
label.radio { display: flex; gap: 8px; align-items: center; }
label.radio input { width: auto; }
.dlg-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

@media (max-width: 1000px) {
  #app { grid-template-columns: 216px 1fr; }
  #main { padding: 16px 16px 60px; }
  .tabs button { padding: 9px 11px; }
}
@media (max-width: 1100px) {
  .sum-layout { grid-template-columns: 1fr; }
  .chat { position: static; max-height: none; }
}
@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  #sidebar { max-height: 38vh; border-right: 0; border-bottom: 1px solid var(--line); }
  #main { padding: 16px; }
  .focus-row { grid-template-columns: 1fr 130px 40px; }
}
@media print {
  #sidebar, .tabs, .tools, .chat, .head .row, #busy, #toast, #notice, .banner, .sum-actions, .tip, #viewer { display: none !important; }
  button.src { border: 0; padding: 0; color: #555; }
  #app { display: block; } #main { overflow: visible; padding: 0; }
  body { background: #fff; color: #000; }
  .card { border: 0; padding: 0; break-inside: auto; }
  .sum-layout { display: block; }
}
