/* form-builder.css — Admin Form Template Builder
   All selectors scoped to .fb-* / .fbp-* (no global side-effects)
*/

/* ── Wrapper ─────────────────────────────────────────────────────────── */
.fb-wrapper {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #f0f2f5;
}

/* ── Header ──────────────────────────────────────────────────────────── */
.fb-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #1a1f2e;
    color: #e8ecf4;
    padding: 0 20px;
    height: 52px;
    flex-shrink: 0;
    gap: 12px;
}

.fb-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.fb-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.fb-logo {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: .04em;
    color: #7dd3fc;
    white-space: nowrap;
}

.fb-template-select {
    background: #2a3148;
    color: #e8ecf4;
    border: 1px solid #3a4262;
    border-radius: 5px;
    padding: 5px 10px;
    font-size: 13px;
    max-width: 320px;
    min-width: 180px;
}

.fb-template-select:focus {
    outline: none;
    border-color: #60a5fa;
}

/* ── Status bar ──────────────────────────────────────────────────────── */
.fb-status-bar {
    padding: 6px 20px;
    font-size: 13px;
    flex-shrink: 0;
}

.fb-status-ok    { background: #d4f4e1; color: #1a7f45; border-bottom: 1px solid #bbf0d0; }
.fb-status-error { background: #fee2e2; color: #b91c1c; border-bottom: 1px solid #fca5a5; }

/* ── Body (3-column grid) ────────────────────────────────────────────── */
.fb-body {
    display: grid;
    grid-template-columns: 240px 1fr 320px;
    flex: 1;
    overflow: hidden;
}

/* ── Left sidebar ────────────────────────────────────────────────────── */
.fb-sidebar {
    background: #1e2436;
    color: #c9d1e8;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #2d3553;
    overflow: hidden;
}

.fb-sidebar-title {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .1em;
    color: #6b7999;
    padding: 10px 14px 6px;
    text-transform: uppercase;
    flex-shrink: 0;
}

.fb-sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 8px;
}

.fb-sidebar-scroll::-webkit-scrollbar { width: 4px; }
.fb-sidebar-scroll::-webkit-scrollbar-track { background: transparent; }
.fb-sidebar-scroll::-webkit-scrollbar-thumb { background: #3a4262; border-radius: 2px; }

.fb-sidebar-empty {
    font-size: 12px;
    color: #6b7999;
    padding: 12px 14px;
    font-style: italic;
}

/* Sections */
.fb-section { border-bottom: 1px solid #2d3553; }
.fb-section-active > .fb-section-header { background: #252d48; }

.fb-section-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    cursor: pointer;
    user-select: none;
    font-size: 13px;
    transition: background .1s;
}

.fb-section-header:hover { background: #252d48; }

.fb-section-chevron {
    font-size: 11px;
    color: #6b7999;
    flex-shrink: 0;
    width: 12px;
    text-align: center;
}

.fb-section-title {
    flex: 1;
    font-size: 12px;
    font-weight: 600;
    color: #c9d1e8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.fb-sec-delete {
    background: none;
    border: none;
    color: #6b7999;
    cursor: pointer;
    font-size: 11px;
    padding: 1px 4px;
    border-radius: 3px;
    opacity: 0;
    transition: opacity .15s;
    flex-shrink: 0;
}

.fb-section-header:hover .fb-sec-delete { opacity: 1; }
.fb-sec-delete:hover { color: #ef4444; background: #3d1a1a; }

/* Field items */
.fb-field-item {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 5px 10px 5px 28px;
    cursor: pointer;
    font-size: 12px;
    transition: background .1s;
}

.fb-field-item:hover { background: #252d48; }
.fb-field-active { background: #1e3256 !important; }

.fb-field-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}

.fb-field-label {
    flex: 1;
    color: #a8b4d4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 12px;
}

/* Sidebar footer */
.fb-sidebar-footer {
    display: flex;
    gap: 6px;
    padding: 8px 10px;
    border-top: 1px solid #2d3553;
    flex-shrink: 0;
}

.fb-sidebar-add-btn {
    flex: 1;
    background: #2a3148;
    color: #7dd3fc;
    border: 1px solid #3a4262;
    border-radius: 5px;
    padding: 5px 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background .1s;
    white-space: nowrap;
}

.fb-sidebar-add-btn:hover:not(:disabled) { background: #344068; }
.fb-sidebar-add-btn:disabled { color: #4a5580; cursor: not-allowed; }

/* ── Middle editor ───────────────────────────────────────────────────── */
.fb-editor {
    background: #fff;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #e0e4ef;
    overflow: hidden;
}

.fb-editor-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    border-bottom: 1px solid #e0e4ef;
    background: #f7f8fc;
    flex-shrink: 0;
}

.fb-editor-title {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: .04em;
    color: #1a1f2e;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fb-editor-form {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.fb-editor-form::-webkit-scrollbar { width: 4px; }
.fb-editor-form::-webkit-scrollbar-thumb { background: #d0d5e8; border-radius: 2px; }

.fb-editor-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 18px;
    border-top: 1px solid #e0e4ef;
    background: #f7f8fc;
    flex-shrink: 0;
}

.fb-editor-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: #94a3c4;
    font-size: 14px;
    text-align: center;
    padding: 24px;
}

/* Field groups */
.fb-field-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.fb-field-row {
    display: flex;
    gap: 12px;
}

.fb-field-half { flex: 1; min-width: 0; }

.fb-required-row {
    flex-direction: row;
    align-items: center;
    gap: 10px;
}

/* Labels and inputs */
.fb-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .08em;
    color: #6b7999;
    text-transform: uppercase;
}

.fb-input, .fb-select, .fb-textarea {
    border: 1px solid #d0d5e8;
    border-radius: 5px;
    padding: 7px 10px;
    font-size: 13px;
    color: #1a1f2e;
    background: #fff;
    transition: border-color .15s;
    width: 100%;
    box-sizing: border-box;
}

.fb-input:focus, .fb-select:focus, .fb-textarea:focus {
    outline: none;
    border-color: #60a5fa;
    box-shadow: 0 0 0 3px rgba(96,165,250,.15);
}

.fb-input-mono { font-family: "Cascadia Code", "Fira Code", monospace; font-size: 12px; }

.fb-textarea { resize: vertical; min-height: 80px; font-family: inherit; }

.fb-hint {
    font-size: 11px;
    color: #94a3c4;
}

/* Visibility toggle */
.fb-vis-toggle {
    display: flex;
    border: 1px solid #d0d5e8;
    border-radius: 5px;
    overflow: hidden;
}

.fb-vis-opt {
    flex: 1;
    background: #f7f8fc;
    border: none;
    border-right: 1px solid #d0d5e8;
    padding: 6px 8px;
    font-size: 12px;
    color: #6b7999;
    cursor: pointer;
    transition: background .1s, color .1s;
}

.fb-vis-opt:last-child { border-right: none; }
.fb-vis-opt:hover { background: #e8ecf8; }

.fb-vis-opt-active {
    background: #1a1f2e !important;
    color: #fff !important;
}

/* Required toggle (CSS-only checkbox toggle) */
.fb-toggle-check { display: none; }

.fb-toggle-label {
    display: inline-flex;
    align-items: center;
    width: 36px;
    height: 20px;
    background: #d0d5e8;
    border-radius: 10px;
    cursor: pointer;
    position: relative;
    transition: background .2s;
    flex-shrink: 0;
}

.fb-toggle-label::after {
    content: "";
    width: 14px;
    height: 14px;
    background: #fff;
    border-radius: 50%;
    position: absolute;
    left: 3px;
    transition: transform .2s;
    box-shadow: 0 1px 3px rgba(0,0,0,.2);
}

.fb-toggle-check:checked + .fb-toggle-label { background: #0052cc; }
.fb-toggle-check:checked + .fb-toggle-label::after { transform: translateX(16px); }

/* ── Right preview ───────────────────────────────────────────────────── */
.fb-preview {
    background: #f3f5fb;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.fb-preview-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #d0d5e8;
    background: #eaecf8;
    flex-shrink: 0;
}

.fb-preview-title {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .08em;
    color: #1a1f2e;
    text-transform: uppercase;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.fb-preview-subtitle {
    font-size: 11px;
    font-weight: 400;
    letter-spacing: normal;
    color: #6b7999;
    text-transform: none;
}

.fb-preview-mode-toggle {
    display: flex;
    border: 1px solid #d0d5e8;
    border-radius: 4px;
    overflow: hidden;
    flex-shrink: 0;
}

.fb-preview-mode-btn {
    background: #fff;
    border: none;
    border-right: 1px solid #d0d5e8;
    padding: 4px 10px;
    font-size: 11px;
    color: #6b7999;
    cursor: pointer;
    transition: background .1s;
}

.fb-preview-mode-btn:last-child { border-right: none; }
.fb-preview-mode-active { background: #1a1f2e !important; color: #fff !important; }

.fb-preview-body {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
}

.fb-preview-body::-webkit-scrollbar { width: 4px; }
.fb-preview-body::-webkit-scrollbar-thumb { background: #d0d5e8; border-radius: 2px; }

/* ── Buttons ──────────────────────────────────────────────────────────── */
.fb-btn-primary {
    background: #0052cc;
    color: #fff;
    border: none;
    border-radius: 5px;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
}
.fb-btn-primary:hover:not(:disabled) { background: #003f9e; }
.fb-btn-primary:disabled { background: #9ab5e0; cursor: not-allowed; }

.fb-btn-outline {
    background: transparent;
    color: #c9d1e8;
    border: 1px solid #3a4262;
    border-radius: 5px;
    padding: 5px 12px;
    font-size: 13px;
    cursor: pointer;
    transition: background .15s;
}
.fb-btn-outline:hover { background: #2a3148; }

/* Outline for editor (light bg) */
.fb-editor-footer .fb-btn-outline {
    color: #1a1f2e;
    border-color: #d0d5e8;
}
.fb-editor-footer .fb-btn-outline:hover { background: #e8ecf8; }

.fb-btn-ghost {
    background: transparent;
    color: #c9d1e8;
    border: none;
    border-radius: 5px;
    padding: 5px 10px;
    font-size: 13px;
    cursor: pointer;
    transition: background .15s;
}
.fb-btn-ghost:hover { background: #2a3148; }

.fb-btn-danger {
    background: #7f1d1d;
    color: #fca5a5;
    border: none;
    border-radius: 5px;
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
    transition: background .15s;
}
.fb-btn-danger:hover { background: #991b1b; }

/* ── Badges ───────────────────────────────────────────────────────────── */
.fb-vis-badge {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .06em;
    padding: 2px 7px;
    border-radius: 10px;
    text-transform: uppercase;
    flex-shrink: 0;
}
.fb-vis-badge.fb-vis-sm { font-size: 9px; padding: 1px 5px; }

.fb-vis-both     { background: #1e3a5f; color: #7dd3fc; }
.fb-vis-internal { background: #2e1e5f; color: #c4b5fd; }
.fb-vis-external { background: #1a3d2b; color: #6ee7b7; }

.fb-type-badge {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .06em;
    padding: 2px 6px;
    border-radius: 3px;
    background: #2d3553;
    color: #94a3c4;
    text-transform: uppercase;
    flex-shrink: 0;
}
.fb-type-badge-lg { font-size: 11px; padding: 3px 8px; }

.fb-type-form { background: #1e3a5f; color: #7dd3fc; }
.fb-type-list { background: #2a2060; color: #c4b5fd; }
.fb-type-grid { background: #1a3d2b; color: #6ee7b7; }

/* ── Patient view overlay ─────────────────────────────────────────────── */
.fb-patient-view-overlay {
    position: absolute;
    inset: 52px 0 0 0;
    background: #f3f5fb;
    z-index: 100;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.fb-patient-view-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: #1a1f2e;
    color: #e8ecf4;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
}

.fb-patient-view-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    max-width: 640px;
    margin: 0 auto;
    width: 100%;
}

/* ── Preview content (fbp-*) ─────────────────────────────────────────── */
.fbp-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid #d0d5e8;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.fbp-tab {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    padding: 7px 12px;
    font-size: 12px;
    color: #6b7999;
    cursor: pointer;
    transition: color .1s, border-color .1s;
    font-weight: 500;
}

.fbp-tab:hover { color: #1a1f2e; }
.fbp-tab-active { color: #0052cc !important; border-bottom-color: #0052cc !important; font-weight: 700; }

.fbp-section-body { display: flex; flex-direction: column; gap: 14px; }

.fbp-section-heading {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid #e0e4ef;
}

.fbp-section-title {
    font-size: 13px;
    font-weight: 700;
    color: #1a1f2e;
    flex: 1;
}

.fbp-type-badge {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: .06em;
    padding: 2px 6px;
    border-radius: 3px;
    background: #e0e4ef;
    color: #6b7999;
}

.fbp-field-count {
    font-size: 11px;
    color: #94a3c4;
}

.fbp-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.fbp-field-label {
    font-size: 13px;
    font-weight: 600;
    color: #1a1f2e;
}

.fbp-required { color: #b91c1c; }

.fbp-field-hint {
    font-size: 11px;
    color: #94a3c4;
    margin-bottom: 2px;
}

/* Preview field controls — disabled but visible */
.fbp-ctrl {
    pointer-events: none;
}

.fbp-input, .fbp-textarea, .fbp-select {
    border: 1px solid #d0d5e8;
    border-radius: 5px;
    padding: 7px 10px;
    font-size: 13px;
    color: #5a6080;
    background: #f7f8fc;
    width: 100%;
    box-sizing: border-box;
}

.fbp-textarea { min-height: 72px; resize: none; font-family: inherit; }

.fbp-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 0;
}

.fbp-chip {
    background: #e8ecf8;
    color: #3a4580;
    border-radius: 20px;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 500;
    border: 1px solid #d0d5e8;
}

.fbp-slider-wrap {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.fbp-slider {
    width: 100%;
    accent-color: #0052cc;
}

.fbp-slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: #94a3c4;
}

.fbp-bool-row {
    display: flex;
    gap: 20px;
}

.fbp-bool-opt {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #5a6080;
    cursor: default;
}
