:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --surface: #ffffff;
    --background: #f8fafc;
    --border: #e2e8f0;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --danger: #ef4444;
    --success: #10b981;
    --sidebar: #1e293b;
    --sidebar-text: #f8fafc;
    --sidebar-hover: #334155;
    --radius: 8px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', system-ui, sans-serif; background: var(--background); color: var(--text-main); height: 100vh; display: flex; overflow: hidden; }

/* Layout */
#app { display: flex; width: 100%; height: 100%; }

.sidebar { width: 250px; background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column; }
.logo { padding: 20px; font-size: 1.5rem; font-weight: 700; border-bottom: 1px solid rgba(255,255,255,0.1); display: flex; align-items: center; gap: 10px; }
.logo i { color: #38bdf8; }
.nav-links { list-style: none; padding: 15px 10px; flex: 1; }
.nav-links li { padding: 12px 15px; margin-bottom: 5px; border-radius: var(--radius); cursor: pointer; display: flex; align-items: center; gap: 12px; transition: 0.2s; color: #cbd5e1; font-weight: 500; }
.nav-links li:hover { background: var(--sidebar-hover); color: white; }
.nav-links li.active { background: var(--primary); color: white; }

.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--background); }
.header { height: 70px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 30px; }
.header h1 { font-size: 1.25rem; font-weight: 600; }
.header-actions { display: flex; gap: 15px; }

.view { flex: 1; overflow-y: auto; padding: 30px; display: none; }
.view.active { display: block; }

/* UI Components */
.btn { padding: 8px 16px; border: none; border-radius: var(--radius); font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; transition: 0.2s; font-size: 0.9rem; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-main); }
.btn-outline:hover { background: #f1f5f9; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }

/* Builder Grid */
.builder-layout { display: flex; gap: 20px; height: calc(100vh - 150px); }
.tools-panel { width: 250px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 15px; overflow-y: auto; }
.tools-panel h3 { font-size: 0.85rem; text-transform: uppercase; color: var(--text-muted); margin-bottom: 15px; letter-spacing: 0.05em; }
.tool { padding: 10px; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; cursor: grab; display: flex; align-items: center; gap: 10px; background: var(--surface); transition: 0.2s; font-size: 0.9rem; }
.tool:hover { border-color: var(--primary); color: var(--primary); transform: translateY(-1px); box-shadow: 0 2px 4px rgba(0,0,0,0.05); }

.canvas-panel { flex: 1; background: #f1f5f9; border: 2px dashed var(--border); border-radius: var(--radius); padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.canvas-panel.dragover { background: #e0f2fe; border-color: var(--primary); }
.canvas-empty { margin: auto; color: var(--text-muted); text-align: center; }
.canvas-empty i { font-size: 3rem; margin-bottom: 10px; color: #cbd5e1; }

.field-item { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: var(--radius); padding: 15px; display: flex; align-items: center; gap: 15px; cursor: pointer; transition: 0.2s; position: relative; }
.field-item:hover { box-shadow: var(--shadow); }
.field-item.selected { border-color: var(--primary); background: #f8fafc; }
.field-drag { cursor: grab; color: #cbd5e1; }
.field-content { flex: 1; }
.field-label { font-weight: 500; font-size: 0.95rem; margin-bottom: 4px; }
.field-type { font-size: 0.75rem; color: var(--text-muted); background: #e2e8f0; padding: 2px 6px; border-radius: 4px; display: inline-block; }
.field-actions { color: var(--text-muted); display: flex; gap: 10px; }
.field-actions i { cursor: pointer; transition: 0.2s; }
.field-actions i:hover { color: var(--danger); }

.props-panel { width: 300px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; overflow-y: auto; }
.form-group { margin-bottom: 15px; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 500; margin-bottom: 5px; color: var(--text-main); }
.form-control { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 0.9rem; font-family: inherit; }
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,0.2); }

/* Workflows */
.workflow-step { background: var(--background); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; display: flex; gap: 20px; margin-bottom: 15px; }
.step-icon { width: 50px; height: 50px; background: white; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1.5rem; color: var(--primary); box-shadow: var(--shadow); }
.step-content { flex: 1; }
.step-content h4 { margin-bottom: 10px; font-size: 1rem; }

/* Mobile Preview Simulator */
.mobile-wrapper { display: flex; justify-content: center; align-items: center; height: calc(100vh - 130px); }
.mobile-device { width: 375px; height: 812px; background: #000; border: 12px solid #1e293b; border-radius: 40px; overflow: hidden; display: flex; flex-direction: column; position: relative; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5); }
.mobile-notch { position: absolute; top: 0; left: 50%; transform: translateX(-50%); width: 150px; height: 25px; background: #1e293b; border-bottom-left-radius: 20px; border-bottom-right-radius: 20px; z-index: 10; }
.mobile-app-header { background: var(--primary); color: white; padding: 40px 20px 15px; text-align: center; font-weight: 600; font-size: 1.1rem; }
.mobile-app-tabs { display: flex; background: var(--primary); color: rgba(255,255,255,0.7); font-size: 0.85rem; font-weight: 500; }
.mobile-app-tabs .tab { flex: 1; text-align: center; padding: 10px 0; border-bottom: 3px solid transparent; cursor: pointer; }
.mobile-app-tabs .tab.active { color: white; border-bottom-color: white; }
.mobile-app-body { flex: 1; background: #f1f5f9; padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 15px; }
.mobile-app-body.hidden { display: none; }
.mobile-app-footer { background: var(--surface); padding: 15px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; }
.mobile-field { background: var(--surface); padding: 15px; border-radius: var(--radius); border: 1px solid var(--border); box-shadow: 0 1px 2px rgba(0,0,0,0.05); }
.mobile-field label { display: block; font-size: 0.85rem; font-weight: 500; margin-bottom: 8px; color: var(--text-muted); }
.mobile-input { width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 1rem; background: #f8fafc; }
.mobile-signature { height: 120px; border: 1px dashed var(--border); background: white; border-radius: 6px; display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 0.8rem; }
.mobile-btn { flex: 2; padding: 12px; background: var(--primary); color: white; border: none; border-radius: 8px; font-size: 1rem; font-weight: 600; cursor: pointer; }
.mobile-btn-outline { flex: 1; padding: 12px; background: transparent; border: 1px solid var(--border); color: var(--text-main); border-radius: 8px; font-size: 0.9rem; font-weight: 600; cursor: pointer; }

/* Modal */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-overlay.hidden { display: none; }
.modal-content { background: var(--surface); width: 500px; border-radius: var(--radius); box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25); overflow: hidden; }
.modal-header { padding: 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 20px; }
.modal-footer { padding: 20px; background: var(--background); border-top: 1px solid var(--border); text-align: right; }
.btn-close { background: transparent; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text-muted); }

/* ── Phase 2: Canvas Drag-Sortierung ──────────────────────────────────────── */
.field-item { transition: opacity 0.15s, box-shadow 0.15s; }
.field-item.dragging { opacity: 0.35; }
.field-item.separator-item { padding: 10px 15px; }
.field-item.heading-item { border-left-color: #8b5cf6; }

/* Badge für bedingte Logik */
.logic-badge { display: inline-flex; align-items: center; gap: 4px; font-size: 0.7rem; background: #ede9fe; color: #7c3aed; padding: 2px 6px; border-radius: 4px; margin-left: 6px; font-weight: 500; }

/* Eigenschaften: Logik-Box */
.logic-box { margin-top: 20px; background: #f8fafc; padding: 12px; border-radius: 6px; border: 1px solid var(--border); }
.logic-box label { font-size: 0.8rem; color: var(--primary); margin-bottom: 6px; display: block; font-weight: 600; }

/* ── Ja/Nein Toggle ────────────────────────────────────────────────────────── */
.yes-no-toggle { display: flex; gap: 8px; }
.yes-no-btn { flex: 1; padding: 10px; border: 1px solid var(--border); border-radius: 8px; background: white; font-size: 0.95rem; font-weight: 600; cursor: pointer; transition: 0.15s; }
.yes-no-btn.active[data-val="ja"]   { background: var(--success); color: white; border-color: var(--success); }
.yes-no-btn.active[data-val="nein"] { background: var(--danger);  color: white; border-color: var(--danger); }

/* ── Sterne-Bewertung ───────────────────────────────────────────────────────── */
.rating-stars { display: flex; gap: 6px; font-size: 1.6rem; }
.rating-stars i { cursor: pointer; color: #d1d5db; transition: color 0.1s; }
.rating-stars i:hover, .rating-stars i:hover ~ i { color: #f59e0b; }

/* ── Wiederholungsgruppe ─────────────────────────────────────────────────────── */
.repeat-widget { width: 100%; overflow-x: auto; }
.repeat-table  { display: flex; flex-direction: column; gap: 4px; min-width: 100%; }
.repeat-row    { display: flex; gap: 4px; }
.repeat-header .repeat-cell { font-size: 0.75rem; font-weight: 600; color: var(--text-muted); background: #e2e8f0; padding: 6px 8px; border-radius: 4px; }
.repeat-cell   { flex: 1; }
.repeat-cell-del { flex: 0 0 36px; }
.repeat-input  { width: 100%; padding: 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 0.9rem; background: white; }
.repeat-del-btn { width: 36px; height: 36px; border: 1px solid var(--border); border-radius: 6px; background: white; cursor: pointer; color: var(--danger); display: flex; align-items: center; justify-content: center; }

/* ── Multi-Photo Grid ────────────────────────────────────────────────────────── */
.multi-photo-grid { display: flex; flex-wrap: wrap; gap: 8px; }

/* ── Offline / Sync Banner ───────────────────────────────────────────────────── */
.offline-banner, .sync-banner {
    position: fixed; top: 0; left: 0; right: 0; z-index: 200;
    padding: 10px 20px; font-size: .9rem; font-weight: 500;
    display: flex; align-items: center; gap: 10px;
    animation: slideDown .3s ease;
}
.offline-banner { background: #fef3c7; color: #92400e; border-bottom: 1px solid #fcd34d; }
.sync-banner    { background: #d1fae5; color: #065f46; border-bottom: 1px solid #6ee7b7; }
.offline-banner.hidden, .sync-banner.hidden { display: none; }
@keyframes slideDown { from { transform: translateY(-100%); } to { transform: translateY(0); } }

/* ── Offline Badge (Postausgang) ─────────────────────────────────────────────── */
.offline-badge { font-size: .75rem; background: #fef3c7; color: #92400e; padding: 2px 8px; border-radius: 12px; }

/* ── Entwurf / Draft Cards ───────────────────────────────────────────────────── */
.draft-card { background: white; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
.draft-title { font-weight: 600; font-size: .95rem; }
.draft-meta  { font-size: .78rem; color: var(--text-muted); margin-top: 4px; }

/* ── Mobile Heading ──────────────────────────────────────────────────────────── */
.mobile-heading { font-weight: 700; font-size: 1rem; padding: 6px 0 4px;
    border-bottom: 2px solid var(--primary); color: var(--primary); margin-bottom: 4px; }

/* ── Kamera Label ────────────────────────────────────────────────────────────── */
.camera-label { display: flex; align-items: center; justify-content: center; gap: 8px;
    width: 100%; padding: 12px; border: 1px dashed var(--border); border-radius: var(--radius);
    cursor: pointer; font-weight: 500; color: var(--text-main); background: white;
    transition: .15s; }
.camera-label:hover { border-color: var(--primary); color: var(--primary); }

/* ── Foto Thumbnails ─────────────────────────────────────────────────────────── */
.photo-preview { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.photo-thumb   { width: 72px; height: 72px; object-fit: cover; border-radius: 6px;
    border: 1px solid var(--border); }

/* ── Unterschriften-Canvas ───────────────────────────────────────────────────── */
.sig-canvas { width: 100%; height: 120px; border: 1px solid var(--border); border-radius: 6px;
    background: white; cursor: crosshair; touch-action: none; }

/* ── Workflow-Saved Hint ─────────────────────────────────────────────────────── */
#workflow-saved-hint.hidden { display: none; }

/* ── PDF-Download Button (Mobile Footer) ─────────────────────────────────────── */
.pdf-download-btn { animation: fadeIn .3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: scale(.9); } to { opacity: 1; transform: scale(1); } }

/* ── pds Live-Picker ──────────────────────────────────────────────────────────── */
.pds-picker-wrap   { position: relative; }
.pds-search-input  { width: 100%; box-sizing: border-box; }

.pds-picker-chip   {
    display: flex; align-items: center; gap: 8px;
    background: #eff6ff; border: 1.5px solid #2563eb; border-radius: 8px;
    padding: 8px 12px; font-size: .88rem; color: #1e3a8a;
    margin-bottom: 6px;
}
.pds-picker-chip.hidden { display: none; }
.pds-chip-clear {
    margin-left: auto; background: none; border: none; cursor: pointer;
    font-size: 1.1rem; color: #64748b; line-height: 1; padding: 0 2px;
}
.pds-chip-clear:hover { color: var(--danger); }

.pds-dropdown {
    position: absolute; left: 0; right: 0; top: calc(100% + 4px);
    background: white; border: 1px solid var(--border); border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,.12); z-index: 200;
    max-height: 240px; overflow-y: auto;
}
.pds-drop-item {
    display: flex; align-items: baseline; gap: 10px;
    padding: 9px 14px; cursor: pointer; font-size: .88rem;
    border-bottom: 1px solid var(--border); transition: background .1s;
}
.pds-drop-item:last-child   { border-bottom: none; }
.pds-drop-item:hover        { background: #eff6ff; }
.pds-drop-nr    { font-weight: 600; color: #2563eb; white-space: nowrap; flex-shrink: 0; font-size: .8rem; }
.pds-drop-label { color: var(--text-main); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pds-drop-empty { color: var(--text-muted); cursor: default; justify-content: center; }
.pds-drop-empty:hover { background: none; }

/* ── Input Error State ────────────────────────────────────────────────────── */
.input-error { border-color: var(--danger) !important; animation: shake .3s ease; }
@keyframes shake {
    0%,100% { transform: translateX(0); }
    25%      { transform: translateX(-6px); }
    75%      { transform: translateX(6px); }
}
