/* FormDesk App – Design-Tokens identisch zum Renderer (public/shared/fd-renderer.css) */
:root {
  --bg: #f5f6f8; --card: #ffffff; --text: #1b1f24; --muted: #5d6670; --line: #dfe3e8;
  --accent: #0b6bcb; --accent-soft: #e6f0fb; --ok: #1a7f45; --ok-soft: #e3f4ea; --warn: #a15c00; --warn-soft: #fff4e0;
  --danger: #b42318; --danger-soft: #fdecea; --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121417; --card: #1b1e23; --text: #e7eaee; --muted: #9aa3ad; --line: #2d3239;
    --accent: #5aa6f0; --accent-soft: #1d2d40; --ok: #4cc286; --ok-soft: #173326; --warn: #f0a64a; --warn-soft: #3a2c14;
    --danger: #f2786d; --danger-soft: #3d1c1a; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 12px 0 8px; }
code, .mono { font-family: var(--mono); font-size: 13px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.center { text-align: center; display: block; }
.wrap { max-width: 1440px; margin: 0 auto; padding: 0 16px; }
.boot { padding: 40px; color: var(--muted); }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; background: var(--card); padding: 6px 10px; z-index: 100; }

/* Kopfzeile */
.topbar { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar-inner { display: flex; align-items: center; gap: 18px; min-height: 56px; flex-wrap: wrap; }
.brand { font-weight: 800; font-size: 17px; text-decoration: none; color: var(--text); letter-spacing: -.01em; }
.brand::before { content: ''; display: inline-block; width: 14px; height: 14px; border-radius: 4px; background: var(--accent); margin-right: 8px; vertical-align: -1px; }
.topnav { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.topnav a { padding: 8px 12px; border-radius: 8px; color: var(--text); text-decoration: none; white-space: nowrap; font-size: 14.5px; }
.topnav a:hover { background: var(--accent-soft); }
.topnav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.user { font-size: 14px; white-space: nowrap; }
.outlet { padding: 22px 0 60px; min-height: 60vh; }

/* Buttons & Eingaben */
.btn { display: inline-flex; align-items: center; gap: 6px; background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 7px; padding: 7px 13px; font: inherit; font-size: 14px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { color: var(--danger); }
.btn-danger:hover:not(:disabled) { border-color: var(--danger); background: var(--danger-soft); }
.btn-small { padding: 3px 8px; font-size: 12.5px; }
.btn.busy { opacity: .6; }
.btn-icon { background: none; border: 0; font-size: 18px; cursor: pointer; color: var(--muted); padding: 4px 8px; }
.input { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); font: inherit; }
.input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.input.invalid { outline: 2px solid var(--danger); }
.input-inline { width: auto; padding: 3px 6px; }
textarea.input { resize: vertical; }
.input.search { max-width: 360px; }
.checkline { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.langbar { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.langbar button { border: 0; background: var(--card); color: var(--text); padding: 5px 10px; font: inherit; font-size: 13px; cursor: pointer; }
.langbar button.on { background: var(--accent); color: #fff; }

/* Layout-Bausteine */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; box-shadow: var(--shadow); }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.section-head h2 { margin: 0; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .input:not(.search) { width: auto; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; }
.row.space { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-s { display: flex; flex-direction: column; gap: 6px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.form-actions { grid-column: 1 / -1; display: flex; gap: 8px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.field-help { font-size: 12px; color: var(--muted); }
.readonly-field { padding: 8px 0; }
.meta-line { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; color: var(--muted); font-size: 13px; margin: 8px 0 14px; }
.notice { background: var(--warn-soft); border-left: 3px solid var(--warn); padding: 8px 12px; border-radius: 4px; margin: 10px 0 0; }
.notice.info { background: var(--accent-soft); border-color: var(--accent); }
.notice.ok { background: var(--ok-soft); border-color: var(--ok); }
.empty-state { text-align: center; padding: 30px 10px; color: var(--muted); }
.loading { padding: 30px; color: var(--muted); }
.error-card { max-width: 560px; margin: 40px auto; text-align: center; }
.warnings { color: var(--warn); padding-left: 20px; }
.facts { padding-left: 20px; margin: 0; }

/* Badges & Chips */
.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--line); color: var(--text); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.role-admin { background: var(--danger-soft); color: var(--danger); }
.badge.role-editor { background: var(--accent-soft); color: var(--accent); }
.chips { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 3px; }
.chip { font-size: 11.5px; background: var(--bg); border: 1px solid var(--line); border-radius: 99px; padding: 1px 8px; }
.tag { font-size: 11px; background: var(--accent-soft); color: var(--accent); border-radius: 4px; padding: 0 5px; margin-left: 4px; }

/* Tabellen */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.card .table-wrap { border: 0; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--accent-soft); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions .row { flex-wrap: nowrap; justify-content: flex-end; }

/* Kacheln */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; text-decoration: none; color: var(--text); box-shadow: var(--shadow); }
.tile:hover { border-color: var(--accent); }
.tile-v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile-l { color: var(--muted); font-size: 13.5px; }

/* Menüs */
.menu { position: relative; display: inline-block; }
.menu-list { display: none; position: absolute; right: 0; top: calc(100% + 4px); min-width: 210px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 4px; z-index: 30; }
.menu.open .menu-list { display: block; }
.menu-item { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 6px; font: inherit; font-size: 14px; color: var(--text); cursor: pointer; }
.menu-item:hover { background: var(--accent-soft); }

/* Dialoge & Toasts */
dialog.modal { border: 1px solid var(--line); border-radius: 12px; padding: 0; width: min(620px, calc(100vw - 24px)); background: var(--card); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog.modal-wide { width: min(980px, calc(100vw - 24px)); }
dialog.modal::backdrop { background: rgba(10, 14, 20, .45); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; }
.modal-body { padding: 16px 18px; max-height: 70vh; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 1000; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; max-width: 420px; box-shadow: 0 6px 20px rgba(0,0,0,.2); transition: opacity .3s; }
.toast-err { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; }
.picklist { max-height: 46vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.pickrow { display: flex; gap: 10px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.pickrow:last-child { border-bottom: 0; }
.pickrow:hover { background: var(--accent-soft); }
.pickrow .muted { margin-left: auto; font-size: 13px; }
.linkbox { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.linkbox .input { flex: 1; min-width: 220px; }
.dropzone { border: 2px dashed var(--line); border-radius: 12px; padding: 40px; text-align: center; cursor: pointer; background: var(--card); margin-bottom: 18px; }
.dropzone.over, .dropzone:hover { border-color: var(--accent); background: var(--accent-soft); }
.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt { display: inline-flex; gap: 6px; align-items: center; border: 1px solid var(--line); border-radius: 6px; padding: 5px 9px; }

/* Instanz */
.instance-head .grid3 { margin-bottom: 4px; }
.savestate { font-size: 13px; }

/* Editor */
.editor { display: grid; grid-template-columns: 300px minmax(380px, 1fr) minmax(380px, 1fr); gap: 14px; align-items: start; }
.ed-col { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; max-height: calc(100vh - 180px); overflow: auto; position: sticky; top: 70px; }
.ed-col-preview { background: var(--bg); }
.ed-tree .tree-item { display: flex; align-items: center; gap: 4px; border-radius: 6px; }
.ed-tree .tree-item.sel { background: var(--accent-soft); outline: 1px solid var(--accent); }
.ed-tree .tree-main { flex: 1; text-align: left; background: none; border: 0; padding: 6px 6px; font: inherit; font-size: 13.5px; color: var(--text); cursor: pointer; overflow: hidden; text-overflow: ellipsis; }
.ed-tree .tree-actions { display: none; gap: 2px; }
.ed-tree .tree-item:hover .tree-actions, .ed-tree .tree-item.sel .tree-actions { display: inline-flex; }
.ed-tree .tree-actions .btn-small { padding: 1px 6px; }
.ed-tree .tree-sec { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 6px; }
.ed-tree .tree-qs { margin-left: 14px; border-left: 2px solid var(--line); padding-left: 4px; }
.ed-tree .tree-add { margin: 4px 0 4px 18px; }
.ed-tree .qtype { font-size: 10.5px; text-transform: uppercase; color: var(--muted); background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
.ed-tree .req { color: var(--danger); }
.ed-tree .num { color: var(--accent); font-variant-numeric: tabular-nums; }
.type-pick { display: flex; flex-wrap: wrap; gap: 4px; }
.ed-props { display: flex; flex-direction: column; gap: 12px; }
.ed-group { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px 12px; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.ed-group legend { font-weight: 700; font-size: 13px; padding: 0 6px; color: var(--accent); }
.ed-field { display: flex; flex-direction: column; gap: 4px; }
.i18n-grid { display: grid; gap: 6px; }
.i18n-grid.two { grid-template-columns: 1fr 1fr; }
.i18n-cell { position: relative; display: block; }
.lang-tag { position: absolute; right: 6px; top: 6px; font-size: 10px; color: var(--muted); background: var(--card); border-radius: 3px; padding: 0 3px; pointer-events: none; }
.opt-table { display: flex; flex-direction: column; gap: 4px; }
.opt-row { display: grid; grid-template-columns: 1fr 1.4fr 1.4fr 54px auto; gap: 4px; align-items: center; }
.opt-headrow { font-size: 11px; color: var(--muted); font-weight: 600; }
.cond { display: flex; flex-direction: column; gap: 6px; }
.cond-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.cond-row { display: grid; grid-template-columns: 1.6fr 1fr 1fr auto; gap: 4px; align-items: center; }
.ed-subcard { border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 8px; background: var(--bg); }
.ed-block { border-left: 3px solid var(--accent-soft); padding-left: 8px; display: flex; flex-direction: column; gap: 6px; }
.ed-info { display: flex; flex-direction: column; gap: 8px; }
.ed-preview-head { margin-bottom: 4px; }
.ed-preview-host .fd-sec { padding: 14px; }

/* Öffentliche Kunden-Seite */
.public-wrap { padding-top: 20px; padding-bottom: 50px; }
.public-head .langbar { float: right; }
.public-head h1 { margin-bottom: 6px; }

@media (max-width: 1300px) {
  .editor { grid-template-columns: 280px 1fr; }
  .ed-col-preview { grid-column: 1 / -1; position: static; max-height: none; }
}
@media (max-width: 860px) {
  .editor, .grid2, .grid3 { grid-template-columns: 1fr; }
  .ed-col { position: static; max-height: none; }
  .opt-row { grid-template-columns: 1fr 1fr; }
  .cond-row { grid-template-columns: 1fr 1fr; }
  .topbar-inner { padding: 6px 0; }
  .user { display: none; }
}
@media print {
  .topbar, .page-actions, .toolbar, .toasts, .public-head .row, .public-head .langbar { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; }
}
