:root {
  --bg: #f2f2f0;
  --dot: #c9c9c4;
  --ink: #1a1a1a;
  --muted: #6b6b66;
  --line: #e3e3de;
  --panel: #ffffff;
  --accent: #d4ff3a;          /* MV-Lime */
  --select: #3b5bfd;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .08);
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); font: 14px/1.4 var(--font); }
button { font: inherit; color: inherit; cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Canvas */
.viewport {
  position: fixed; inset: 0; overflow: hidden; touch-action: none;
  background-color: var(--bg);
  background-image: radial-gradient(var(--dot) 1px, transparent 1.2px);
  cursor: grab;
}
.viewport.panning { cursor: grabbing; }
.viewport.tool-sticky, .viewport.tool-text, .viewport.tool-table, .viewport.tool-frame { cursor: crosshair; }
.viewport.tool-comment { cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 24 24'%3E%3Cpath d='M4 5h16v11H9l-5 4z' fill='%23d4ff3a' stroke='%23111' stroke-width='1.6' stroke-linejoin='round'/%3E%3C/svg%3E") 4 24, crosshair; }
.world { position: absolute; left: 0; top: 0; transform-origin: 0 0; --s: 1; }
#layer { position: absolute; left: 0; top: 0; }

.item { position: absolute; user-select: none; -webkit-user-select: none; }
.item.selected { outline: calc(2px / var(--s)) solid var(--select); outline-offset: calc(1px / var(--s)); }
.item.editing { outline: calc(2px / var(--s)) solid var(--select); }
.item [contenteditable="true"] { outline: none; user-select: text; -webkit-user-select: text; cursor: text; }

.handle {
  position: absolute; right: calc(-7px / var(--s)); bottom: calc(-7px / var(--s));
  width: calc(14px / var(--s)); height: calc(14px / var(--s));
  background: #fff; border: calc(2px / var(--s)) solid var(--select); border-radius: 50%;
  cursor: nwse-resize; z-index: 5;
}

/* Seite / Rahmen */
.item-frame .frame-body { position: absolute; inset: 0; background: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .06), 0 2px 10px rgba(0, 0, 0, .05); }
.item-frame .frame-label {
  position: absolute; left: 0; bottom: 100%; margin-bottom: calc(8px / var(--s));
  font-size: calc(13px / var(--s)); color: var(--muted); white-space: nowrap; cursor: pointer;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}
.item-frame .frame-label:hover { color: var(--ink); }

/* Post-it */
.item-sticky .sticky-body {
  position: absolute; inset: 0; padding: 14px 14px 22px; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .08), 0 6px 12px -6px rgba(0, 0, 0, .25);
}
.item-sticky .sticky-text { width: 100%; max-height: 100%; overflow: hidden; text-align: center; word-wrap: break-word; line-height: 1.3; }
.item-sticky .sticky-author { position: absolute; right: 10px; bottom: 6px; font-size: 11px; color: rgba(0, 0, 0, .45); white-space: nowrap; max-width: 90%; overflow: hidden; text-overflow: ellipsis; }

/* Text */
.item-text .text-body { line-height: 1.25; word-wrap: break-word; min-height: 1em; }
.item-text .text-body:empty::before { content: "Text"; color: #aaa; }

/* Tabelle */
.item-table table { width: 100%; border-collapse: collapse; table-layout: fixed; background: #fff; font-size: 17px; line-height: 1.4; }
.item-table td { border: 1px solid #c8c8c8; padding: 10px 12px; vertical-align: top; word-wrap: break-word; min-height: 2em; }
.item-table tr.hdr td { background: #a6a6a6; color: #111; font-weight: 700; text-align: center; padding: 6px 12px; }
.item-table td.editing-cell { box-shadow: inset 0 0 0 2px var(--select); }
.item-table td:empty::after { content: "\00a0"; }

/* Bild */
.item-image img { width: 100%; height: 100%; object-fit: contain; display: block; pointer-events: none; }

.marquee { position: absolute; border: 1px solid var(--select); background: rgba(59, 91, 253, .08); pointer-events: none; }

/* Oberleiste */
.topbar {
  position: fixed; top: 12px; left: 12px; right: 12px; display: flex; justify-content: space-between; align-items: center; gap: 12px;
  pointer-events: none; z-index: 20;
}
.topbar > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 8px; background: var(--panel); padding: 8px 14px; border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.brand .logo { width: 18px; height: 18px; border-radius: 4px; background: #111; box-shadow: inset 0 0 0 4px #111, inset 0 0 0 9px var(--accent); flex: none; }
.brand .sep { color: #bbb; }
#boardName { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 8px; background: var(--panel); padding: 6px 8px; border-radius: var(--radius); box-shadow: var(--shadow); }
.status { font-size: 12px; color: var(--muted); padding: 0 6px; white-space: nowrap; }
.status.offline { color: #c0392b; }
.presence { display: flex; }
.presence .avatar { margin-left: -6px; border: 2px solid #fff; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #111; border: 0; flex: none;
}
.btn-pill { display: flex; align-items: center; gap: 6px; border: 0; background: transparent; padding: 6px 10px; border-radius: 8px; }
.btn-pill:hover { background: #f1f1ee; }
.btn-pill b { background: var(--accent); border-radius: 10px; padding: 0 7px; font-size: 12px; }
.btn-pill b:empty { display: none; }

/* Werkzeuge */
.toolbar {
  position: fixed; left: 12px; top: 50%; transform: translateY(-50%); z-index: 20;
  display: flex; flex-direction: column; gap: 2px; background: var(--panel); padding: 6px; border-radius: var(--radius); box-shadow: var(--shadow);
}
.toolbar button { width: 40px; height: 40px; border: 0; background: transparent; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.toolbar button:hover { background: #f1f1ee; }
.toolbar button.active { background: #111; color: var(--accent); }
.tool-sep { height: 1px; background: var(--line); margin: 4px 6px; }

.color-pop, .ctx {
  position: fixed; z-index: 30; background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px; display: flex; gap: 4px; align-items: center;
}
.color-pop { left: 64px; flex-wrap: wrap; width: 156px; }
.swatch { width: 26px; height: 26px; border-radius: 6px; border: 1px solid rgba(0, 0, 0, .1); padding: 0; }
.swatch.active { box-shadow: 0 0 0 2px #fff, 0 0 0 4px #111; }
.ctx button:not(.swatch) { border: 0; background: transparent; padding: 6px 9px; border-radius: 7px; font-size: 13px; white-space: nowrap; display: flex; align-items: center; gap: 4px; }
.ctx button:not(.swatch):hover { background: #f1f1ee; }
.ctx .sep { width: 1px; align-self: stretch; background: var(--line); margin: 2px 2px; }
.ctx .danger { color: #c0392b; }

/* Unterleiste: Tabs + Zoom */
.bottombar { position: fixed; left: 12px; right: 12px; bottom: 12px; display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; z-index: 20; pointer-events: none; }
.bottombar > * { pointer-events: auto; }
.tabs { display: flex; gap: 2px; background: var(--panel); padding: 4px; border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; max-width: calc(100vw - 260px); scrollbar-width: none; }
.tab { border: 0; background: transparent; padding: 7px 14px; border-radius: 7px; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.tab:hover { background: #f1f1ee; }
.tab.active { background: #111; color: #fff; }
.tab .badge { background: var(--accent); color: #111; border-radius: 9px; font-size: 11px; padding: 0 6px; font-weight: 700; }
.tab input { font: inherit; border: 0; outline: 0; background: transparent; color: inherit; width: 10ch; }
.tab.add { color: var(--muted); font-size: 18px; padding: 4px 12px; }
.zoom { display: flex; align-items: center; background: var(--panel); padding: 4px; border-radius: var(--radius); box-shadow: var(--shadow); }
.zoom button { border: 0; background: transparent; min-width: 34px; height: 32px; border-radius: 7px; display: flex; align-items: center; justify-content: center; font-size: 16px; }
.zoom button:hover { background: #f1f1ee; }
#zoomLabel { font-size: 13px; min-width: 56px; }

/* Kommentare */
.pins { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.pin {
  position: absolute; transform: translate(-4px, -100%); pointer-events: auto; cursor: pointer;
  display: flex; align-items: center; gap: 2px; padding: 3px; border-radius: 16px 16px 16px 2px;
  background: #fff; box-shadow: var(--shadow);
}
.pin .avatar { width: 26px; height: 26px; font-size: 11px; }
.pin .count { font-size: 11px; font-weight: 700; padding: 0 5px 0 2px; }
.pin.resolved { opacity: .55; }
.pin.active { box-shadow: 0 0 0 2px #111, var(--shadow); }

.panel {
  position: fixed; top: 68px; right: 12px; bottom: 68px; width: 340px; z-index: 25; background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column;
}
.panel-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.panel-head strong { flex: 1; }
.check { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.icon-btn { border: 0; background: transparent; font-size: 20px; line-height: 1; padding: 2px 6px; border-radius: 6px; }
.icon-btn:hover { background: #f1f1ee; }
.panel-list { overflow-y: auto; padding: 6px; }
.thread-card { padding: 10px; border-radius: 8px; cursor: pointer; display: flex; gap: 10px; }
.thread-card:hover { background: #f6f6f3; }
.thread-card.resolved { opacity: .6; }
.thread-card .meta { font-size: 12px; color: var(--muted); }
.thread-card .txt { white-space: pre-wrap; word-wrap: break-word; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.empty { color: var(--muted); padding: 24px 14px; text-align: center; }

.popover {
  position: fixed; z-index: 40; width: 320px; max-height: 70vh; display: flex; flex-direction: column;
  background: var(--panel); border-radius: var(--radius); box-shadow: 0 8px 32px rgba(0, 0, 0, .18);
}
.pop-head { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.pop-head .grow { flex: 1; font-size: 12px; color: var(--muted); }
.pop-head button { border: 0; background: transparent; padding: 5px 8px; border-radius: 6px; font-size: 12px; }
.pop-head button:hover { background: #f1f1ee; }
.pop-head .done { background: var(--accent); font-weight: 600; }
.pop-body { overflow-y: auto; padding: 4px 12px; }
.msg { padding: 8px 0; display: flex; gap: 8px; }
.msg + .msg { border-top: 1px solid #f0f0ec; }
.msg .avatar { width: 26px; height: 26px; font-size: 11px; }
.msg .who { font-weight: 600; font-size: 13px; }
.msg .when { color: var(--muted); font-size: 11px; margin-left: 4px; font-weight: 400; }
.msg .txt { white-space: pre-wrap; word-wrap: break-word; }
.msg .del { border: 0; background: none; color: var(--muted); font-size: 11px; padding: 0; margin-left: 6px; }
.msg .del:hover { color: #c0392b; }
.pop-foot { padding: 8px 10px; border-top: 1px solid var(--line); display: flex; gap: 6px; align-items: flex-end; }
.pop-foot textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; font: inherit; min-height: 36px; max-height: 140px; outline: none; }
.pop-foot textarea:focus { border-color: #111; }
.pop-foot button { border: 0; background: #111; color: #fff; border-radius: 8px; padding: 8px 12px; font-weight: 600; }
.pop-foot button:disabled { opacity: .35; cursor: default; }

.menu { position: fixed; z-index: 50; background: var(--panel); border-radius: 8px; box-shadow: var(--shadow); padding: 4px; min-width: 170px; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 7px 10px; border-radius: 6px; }
.menu button:hover { background: #f1f1ee; }
.menu .danger { color: #c0392b; }

.modal { position: fixed; inset: 0; z-index: 60; background: rgba(20, 20, 18, .35); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-card { background: #fff; border-radius: 14px; box-shadow: 0 12px 48px rgba(0, 0, 0, .25); padding: 24px; width: 100%; max-width: 400px; }
.modal-card h2 { margin: 0 0 6px; font-size: 20px; }
.modal-card p { margin: 0 0 16px; color: var(--muted); }
.modal-card input { width: 100%; font: inherit; font-size: 16px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; outline: none; }
.modal-card input:focus { border-color: #111; }
.modal-card .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal-card .primary { border: 0; background: #111; color: #fff; padding: 10px 16px; border-radius: 8px; font-weight: 600; }
.modal-card .secondary { border: 1px solid var(--line); background: #fff; padding: 10px 16px; border-radius: 8px; }
.modal-card dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 13px; }
.modal-card dt { font-weight: 600; white-space: nowrap; }
.modal-card dd { margin: 0; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: 72px; transform: translateX(-50%); background: #111; color: #fff; padding: 8px 14px; border-radius: 8px; z-index: 70; font-size: 13px; }

@media (max-width: 640px) {
  .btn-pill span, .status { display: none; }
  .panel { left: 12px; width: auto; }
  .tabs { max-width: calc(100vw - 120px); }
  .zoom #zoomLabel, .zoom #btnHelp, .zoom #zoomIn, .zoom #zoomOut { display: none; }
}
