/* Worksheet Creator – Oberfläche. Ruhig, große Klickflächen, ohne Build-Schritt. */

:root {
  --bg: #f6f5f1;
  --panel: #ffffff;
  --ink: #23262b;
  --muted: #6b6f76;
  --line: #e2e0d9;
  --accent: #2f6b9a;
  --accent-ink: #ffffff;
  --accent-soft: #e6eff6;
  --ok: #2e7d4f;
  --warn: #a8650b;
  --err: #b3261e;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 4px 14px rgba(0, 0, 0, .04);
  font-size: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: var(--ink); background: var(--bg); line-height: 1.45;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
[x-cloak] { display: none !important; }

/* --- Kopfleiste ---------------------------------------------------------- */
.topnav {
  display: flex; align-items: center; gap: 1rem; padding: .6rem 1.2rem;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.topnav .brand { font-weight: 700; color: var(--ink); text-decoration: none; font-size: 1.1rem; }
.topnav nav { display: flex; gap: .3rem; flex: 1; }
.topnav nav a {
  padding: .45rem .8rem; border-radius: 8px; color: var(--ink); text-decoration: none;
}
.topnav nav a:hover, .topnav nav a.active { background: var(--accent-soft); }
.topnav form { margin: 0; }

main.page { padding: 1.2rem; max-width: 1400px; margin: 0 auto; }
main.page.wide { max-width: none; padding: 0; }

/* --- Buttons & Formulare ------------------------------------------------- */
.btn, button.btn {
  display: inline-flex; align-items: center; gap: .4rem; justify-content: center;
  min-height: 2.5rem; padding: .45rem 1rem; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  font: inherit; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: #c9c6bd; background: #fbfaf7; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--err); }
.btn.small { min-height: 2rem; padding: .25rem .6rem; font-size: .9rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

label { font-weight: 600; font-size: .95rem; }
input[type=text], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; font: inherit; padding: .55rem .7rem; border: 1px solid #cfccc3;
  border-radius: 8px; background: #fff; color: var(--ink);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.field { margin-bottom: 1rem; }
.field .help { color: var(--muted); font-size: .85rem; margin-top: .2rem; }
.field .errors { color: var(--err); font-size: .9rem; }
.field ul { list-style: none; padding: 0; margin: .3rem 0 0; display: flex; gap: .4rem; flex-wrap: wrap; }
.field ul li label { font-weight: normal; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: normal; }
.check input { width: 1.2rem; height: 1.2rem; }

/* Radio-Gruppen als Segmente */
.segmented { display: inline-flex; border: 1px solid #cfccc3; border-radius: 8px; overflow: hidden; }
.segmented label {
  margin: 0; padding: .45rem .9rem; cursor: pointer; font-weight: normal; background: #fff;
  border-right: 1px solid #e3e0d8;
}
.segmented label:last-child { border-right: 0; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input:checked) { background: var(--accent); color: #fff; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.1rem;
}
.muted { color: var(--muted); }
.notice {
  padding: .7rem 1rem; border-radius: 8px; background: var(--accent-soft); margin-bottom: 1rem;
}
.notice.warn { background: #fdf3e2; }
.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.messages li { padding: .6rem 1rem; border-radius: 8px; background: #e7f3ec; margin-bottom: .4rem; }
.messages li.error { background: #fbe9e7; }

/* --- Dashboard ------------------------------------------------------------ */
.filterbar {
  display: grid; grid-template-columns: 2fr repeat(4, 1fr) auto; gap: .6rem; align-items: end;
  margin-bottom: 1.2rem;
}
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.sheet-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column;
}
.sheet-card a.thumb { display: block; background: #eceae4; aspect-ratio: 210 / 297; }
.sheet-card .thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.sheet-card .thumb .placeholder {
  height: 100%; display: flex; align-items: center; justify-content: center; color: var(--muted);
}
.sheet-card .body { padding: .7rem .8rem .8rem; }
.sheet-card .title { font-weight: 600; color: var(--ink); text-decoration: none; display: block; }
.sheet-card .meta { color: var(--muted); font-size: .85rem; }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .4rem; }
.chip {
  display: inline-block; padding: .1rem .55rem; border-radius: 99px; background: var(--accent-soft);
  font-size: .8rem; color: var(--ink); text-decoration: none;
}
.chip.variant { background: #f1ead9; }
.chip.active { background: var(--accent); color: #fff; }

/* --- Neues Blatt ---------------------------------------------------------- */
.new-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); gap: 1.2rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.form-grid .full { grid-column: 1 / -1; }
details.advanced summary { cursor: pointer; font-weight: 600; margin-bottom: .8rem; }
.lin-demo svg { display: block; margin: .3rem 0 .8rem; }
.lin-demo .lin-band { fill: #e6f0fa; }
.lin-demo .lin-line { stroke: #888; stroke-width: .7; }
.lin-demo .lin-base { stroke: #333; stroke-width: 1; }
.lin-demo .lin-house polygon, .lin-demo .lin-house rect { fill: none; stroke: #555; stroke-width: .8; }

/* --- Arbeitsansicht -------------------------------------------------------- */
.workspace { display: flex; flex-direction: column; height: calc(100vh - 3.4rem); }
.ws-topbar {
  display: flex; align-items: center; gap: 1rem; padding: .6rem 1rem; background: var(--panel);
  border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.ws-topbar .title { flex: 1; min-width: 200px; }
.ws-topbar .title h1 { margin: 0; font-size: 1.2rem; }
.ws-columns { display: grid; grid-template-columns: minmax(320px, 400px) 1fr; flex: 1; min-height: 0; }

.chat-panel {
  display: flex; flex-direction: column; border-right: 1px solid var(--line);
  background: var(--panel); min-height: 0;
}
.chat-scroll { flex: 1; overflow-y: auto; padding: 1rem; }
.msg { margin-bottom: .8rem; display: flex; flex-direction: column; }
.msg .bubble {
  padding: .6rem .8rem; border-radius: 12px; white-space: pre-wrap; max-width: 92%;
  overflow-wrap: anywhere;
}
.msg.user { align-items: flex-end; }
.msg.user .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant .bubble { background: #f1efe9; border-bottom-left-radius: 4px; }
.msg.system .bubble { background: #fdf3e2; font-size: .9rem; }
.msg .meta { font-size: .75rem; color: var(--muted); margin-top: .2rem; }
.msg.streaming .bubble { background: #f1efe9; }
.status-line { display: flex; align-items: center; gap: .5rem; color: var(--muted); font-size: .9rem; }
.spinner {
  width: 1rem; height: 1rem; border: 2px solid #c8d6e3; border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.chat-form { border-top: 1px solid var(--line); padding: .8rem; }
.chat-form textarea { min-height: 4.2rem; }
.chat-form .hint { font-size: .78rem; color: var(--muted); margin-top: .3rem; }
.notes-box { border-top: 1px solid var(--line); padding: .6rem .8rem; }
.notes-box summary { cursor: pointer; font-weight: 600; }
.notes-box textarea { margin-top: .5rem; min-height: 5rem; }
.saved { color: var(--ok); font-size: .8rem; }

.preview-panel { display: flex; flex-direction: column; min-height: 0; background: #e3e1da; }
.preview-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .9rem; padding: .5rem 1rem;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.preview-toolbar form { margin: 0; display: inline-flex; align-items: center; gap: .3rem; }
.preview-toolbar select { width: auto; padding: .3rem .5rem; }
.preview-toolbar .sep { width: 1px; height: 1.6rem; background: var(--line); }
.toggle { display: inline-flex; align-items: center; gap: .35rem; font-weight: normal; cursor: pointer; }
.toggle input { width: 1.1rem; height: 1.1rem; }
.preview-scroll { flex: 1; overflow: auto; padding: 1.2rem; }
.pages { display: flex; flex-direction: column; align-items: center; gap: 1.2rem; }
.pages img {
  width: calc(var(--zoom, 1) * 640px); max-width: none; background: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .18); display: block;
}
.page-label { font-size: .8rem; color: var(--muted); text-align: center; margin-top: .2rem; }
.lint { margin: 0 auto 1rem; max-width: 640px; }
.lint li { margin-bottom: .2rem; }
.lint .error { color: var(--err); }
.lint .warning { color: var(--warn); }
.lint .info { color: var(--muted); }
.empty-preview {
  margin: 3rem auto; max-width: 420px; text-align: center; color: var(--muted);
}
.version-banner {
  max-width: 640px; margin: 0 auto 1rem; display: flex; gap: .8rem; align-items: center;
  justify-content: space-between; background: #fdf3e2; padding: .6rem .9rem; border-radius: 8px;
}
.family-bar { display: flex; gap: .3rem; flex-wrap: wrap; align-items: center; }

dialog {
  border: 0; border-radius: 12px; padding: 1.3rem; width: min(560px, 94vw);
  box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(30, 30, 30, .35); }
dialog h2 { margin-top: 0; }
.version-list { list-style: none; padding: 0; margin: 0; max-height: 60vh; overflow: auto; }
.version-list li {
  display: flex; gap: .7rem; align-items: center; padding: .5rem 0;
  border-bottom: 1px solid var(--line);
}
.version-list img { width: 52px; border: 1px solid var(--line); }
.version-list .grow { flex: 1; }

.source-editor textarea { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9rem; min-height: 60vh; }

.settings-section { margin-bottom: 1.4rem; }
table.simple { border-collapse: collapse; width: 100%; }
table.simple th, table.simple td { text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }

.login-box { max-width: 380px; margin: 10vh auto; }

@media (max-width: 900px) {
  .ws-columns { grid-template-columns: 1fr; }
  .workspace { height: auto; }
  .chat-panel { border-right: 0; max-height: 70vh; }
  .new-layout, .form-grid { grid-template-columns: 1fr; }
  .filterbar { grid-template-columns: 1fr 1fr; }
  .pages img { width: calc(var(--zoom, 1) * 92vw); }
}
