:root {
  --bg: #14161a;
  --panel: #1e2128;
  --panel2: #262a33;
  --border: #353a45;
  --text: #e8eaf0;
  --muted: #9aa1ad;
  --accent: #4f8cff;
  --accent2: #2f6fe0;
  --danger: #e05555;
  --ok: #3fae6a;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
}

/* ---------- Topbar ---------- */
#topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
#topbar .brand { font-weight: 700; margin-right: 10px; white-space: nowrap; }
#topbar .spacer { flex: 1; }
#topbar nav { display: flex; gap: 6px; }

button {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  font-size: 14px;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--accent2); }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
button.danger:hover { background: var(--danger); color: #fff; }
button.active, #topbar nav button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
button:disabled { opacity: 0.45; cursor: default; }
button.icon { padding: 6px 9px; }

input, select, textarea {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  width: 100%;
}
input[type="color"] { padding: 2px; height: 38px; cursor: pointer; }
input[type="range"] { padding: 0; }
input[type="checkbox"] { width: auto; transform: scale(1.25); accent-color: var(--accent); }
label { display: block; margin: 10px 0 4px; color: var(--muted); font-size: 13px; }
label > input, label > select { margin-top: 4px; color: var(--text); }

h1, h2, h3 { margin: 0 0 10px; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 18px; font-size: 13px; margin: 6px 0; }

main { padding: 0; }
.view { padding: 16px; max-width: 1500px; margin: 0 auto; }

/* ---------- Login ---------- */
.login-card {
  max-width: 380px; margin: 10vh auto;
  text-align: center;
}
.login-card form { text-align: left; }
.login-card button { width: 100%; margin-top: 10px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

/* ---------- Startansicht ---------- */
.section-head { display: flex; align-items: center; gap: 10px; margin: 18px 0 10px; flex-wrap: wrap; }
.section-head h2 { margin: 0; font-size: 18px; }
.section-head .count { color: var(--muted); }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 26px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone.dragover { border-color: var(--accent); background: rgba(79,140,255,.08); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.thumb {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
}
.thumb img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: #000; }
.thumb .name {
  font-size: 12px; color: var(--muted);
  padding: 6px 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thumb .actions {
  position: absolute; top: 6px; right: 6px;
  display: flex; gap: 4px; opacity: 0;
  transition: opacity .12s;
}
.thumb:hover .actions, body.mobile .thumb .actions { opacity: 1; }
.thumb .actions button { padding: 4px 8px; font-size: 13px; background: rgba(20,22,26,.85); }
.thumb.selected { outline: 3px solid var(--accent); }
.thumb .check {
  position: absolute; top: 6px; left: 6px;
  width: 22px; height: 22px; border-radius: 50%;
  background: rgba(20,22,26,.8); border: 2px solid #fff;
  display: none; align-items: center; justify-content: center; font-size: 13px;
}
.select-mode .thumb .check { display: flex; }
.thumb.selected .check { background: var(--accent); }
.thumb .actions button.has-note { border-color: var(--accent); color: var(--accent); }
a.muted { color: var(--muted); }

/* ---------- Einstellungen ---------- */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.list { display: flex; flex-direction: column; gap: 6px; }
.list .row {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel2); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px;
}
.list .row .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.font-preview { font-size: 19px; }
.sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.sticker-grid .tile {
  background: var(--panel2); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px; text-align: center; cursor: pointer; position: relative;
}
.sticker-grid .tile img { width: 100%; height: 56px; object-fit: contain; }
.sticker-grid .tile .name { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hf-preview { max-width: 100%; max-height: 80px; border: 1px solid var(--border); border-radius: 6px; background: #000; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline > * { width: auto; }

/* ---------- Workspace ---------- */
#view-workspace { max-width: none; padding: 10px; }
.ws-layout { display: flex; gap: 12px; height: calc(100vh - 110px); }
.ws-canvas-wrap {
  flex: 1; min-width: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: auto; position: relative;
}
#ws-stage { background: transparent; }
.ws-toolbar {
  width: 340px; flex-shrink: 0;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  overflow-y: auto; padding: 12px;
}
.ws-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.ws-head .grow { flex: 1; }
.tabs { display: flex; gap: 4px; margin-bottom: 10px; flex-wrap: wrap; }
.tabs button { flex: 1; padding: 7px 6px; font-size: 13px; }
.tabpane { display: none; }
.tabpane.active { display: block; }
.slider-row { display: grid; grid-template-columns: 90px 1fr 44px; gap: 8px; align-items: center; margin: 6px 0; font-size: 13px; color: var(--muted); }
.slider-row output { text-align: right; color: var(--text); }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.spruch-item {
  background: var(--panel2); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; margin: 5px 0; cursor: pointer; white-space: pre-wrap; font-size: 14px;
}
.spruch-item:hover { border-color: var(--accent); }
.tabs button[data-tab="element"] { border-color: var(--accent); color: var(--accent); }
.tabs button[data-tab="element"].active { background: var(--accent); color: #fff; }

/* Kontextmenü */
#ctx-menu {
  position: fixed; z-index: 200;
  background: var(--panel2); border: 1px solid var(--border); border-radius: 8px;
  padding: 4px; min-width: 180px;
  box-shadow: 0 6px 24px rgba(0,0,0,.5);
}
#ctx-menu button { display: block; width: 100%; text-align: left; border: none; background: none; padding: 8px 10px; border-radius: 6px; }
#ctx-menu button:hover { background: var(--accent); }

/* Modal */
#modal-root .overlay {
  position: fixed; inset: 0; z-index: 150;
  background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
#modal-root .modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; max-width: 460px; width: 100%; max-height: 88vh; overflow-y: auto;
}
#modal-root .modal .btn-row { justify-content: flex-end; margin-top: 14px; }

/* Toast */
#toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  z-index: 300; display: flex; flex-direction: column; gap: 6px; align-items: center;
}
#toast .msg {
  background: var(--panel2); border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 16px; box-shadow: 0 4px 18px rgba(0,0,0,.4);
}
#toast .msg.err { border-color: var(--danger); }

/* Text-Editor-Overlay im Workspace */
.ws-text-edit {
  position: absolute; z-index: 100;
  background: rgba(20,22,26,.92); color: #fff;
  border: 1px solid var(--accent); border-radius: 6px;
  padding: 6px; resize: none; overflow: hidden;
}

/* ---------- Mobil (Auftrag Abschnitt 4) ---------- */
body.mobile { font-size: 16px; }
body.mobile button { padding: 10px 14px; font-size: 15px; }
body.mobile .view { padding: 10px; }
body.mobile .grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
body.mobile .settings-grid { grid-template-columns: 1fr; }
body.mobile .ws-layout { flex-direction: column; height: auto; }
body.mobile .ws-canvas-wrap { height: 52vh; flex: none; }
body.mobile .ws-toolbar { width: 100%; max-height: none; }
body.mobile #topbar .brand { display: none; }
body.mobile #btn-account span { display: none; }

@media (max-width: 700px) {
  body:not(.desktop) .settings-grid { grid-template-columns: 1fr; }
}
