/* ─── Globale Theme-Overrides ────────────────────────────────────────────── */

:root {
    --bs-primary: #343a40;
    --bs-primary-rgb: 52, 58, 64;
}

body {
    background-color: var(--bs-body-bg);
}

.bg-primary {
    background-color: #343a40 !important;
}

.btn-primary {
    background-color: #343a40;
    border-color: #343a40;
}

.btn-primary:hover {
    background-color: #23272b;
    border-color: #1d2124;
}

.btn-primary:active,
.btn-primary:focus {
    background-color: #1d2124;
    border-color: #171a1d;
}

/* ─── Button-Rundungen: oben-rechts + unten-links rund ───────────────────── */

.btn {
    border-radius: 0 0.375rem 0 0.375rem;
}

/* Form State Styling */
.form-control-required-empty,
.form-control-required-filled,
.form-control-optional-empty,
.form-control-optional-filled {
    transition: border-color 0.2s ease-in-out, background-color 0.2s ease-in-out,
        box-shadow 0.2s ease-in-out;
}

.form-control-required-empty {
    border-color: var(--bs-danger) !important;
    background-color: var(--bs-body-bg);
    box-shadow: 0 0 0 0.125rem rgba(var(--bs-danger-rgb), 0.15);
}

.form-control-required-filled {
    border-color: var(--bs-success) !important;
    background-color: rgba(var(--bs-success-rgb), 0.12);
    box-shadow: 0 0 0 0.125rem rgba(var(--bs-success-rgb), 0.25);
}

.form-control-optional-empty {
    border-color: var(--bs-secondary) !important;
    background-color: var(--bs-body-bg);
    box-shadow: 0 0 0 0.125rem rgba(var(--bs-secondary-rgb), 0.1);
}

.form-control-optional-filled {
    border-color: var(--bs-success) !important;
    background-color: rgba(var(--bs-success-rgb), 0.12);
    box-shadow: 0 0 0 0.125rem rgba(var(--bs-success-rgb), 0.2);
}

/* Avatar Cropper */
.user-avatar {
    background-color: #f8f9fa;
    color: #4f5d75;
    font-size: 0.75rem;
}

.user-avatar img {
    object-fit: cover;
}

.user-avatar__initials {
    line-height: 1;
}

.avatar-crop-stage {
    position: relative;
    background-color: #f8f9fa;
    border: 1px dashed rgba(0, 0, 0, 0.15);
    border-radius: 1rem;
    overflow: hidden;
    min-height: 240px;
}

.avatar-crop-stage img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-crop-stage .cropper-container,
.avatar-crop-stage .cropper-wrap-box,
.avatar-crop-stage .cropper-crop-box {
    width: 100% !important;
    height: 100% !important;
}

.avatar-crop-stage .cropper-view-box,
.avatar-crop-stage .cropper-face {
    border-radius: 50%;
}

.avatar-crop-placeholder {
    position: absolute;
    inset: 0;
}

/* Responsive Darstellung für Übersichten */
.tenants-table .badge,
.users-table .badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

/* ─── CMS-Content: Navbar-Dropdowns nicht überdecken ─────────────────────── */

.cms-page {
    position: relative;
    z-index: 1;
    isolation: isolate;
}

.cms-content {
    position: relative;
    z-index: 1;
}

/* ─── Prompt Builder Layout ───────────────────────────────────────────────── */

.builder-layout {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 56px);
    overflow: hidden;
}

.builder-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    /* Keep canvas below navbar dropdowns without trapping modals */
    position: relative;
    z-index: 1;
}

.builder-sidebar {
    width: 280px;
    min-width: 280px;
    border-right: 1px solid #dee2e6;
    overflow-y: auto;
    background: #fff;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 0;
}

.builder-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}


.builder-context {
    width: 320px;
    min-width: 320px;
    flex-shrink: 0;
    border-left: 1px solid #dee2e6;
    overflow-y: auto;
    background: #fff;
    display: flex;
    flex-direction: column;
}

.builder-context .accordion-button {
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
    font-weight: 600;
}

.builder-context .accordion-body {
    padding: 0.5rem;
    font-size: 0.85rem;
}

.builder-context .ctx-var-input {
    border-color: #fd7e14;
    background-color: #fff8f0;
    transition: border-color 0.2s, background-color 0.2s;
}
.builder-context .ctx-var-input:focus {
    border-color: #e8590c;
    background-color: #fff;
    box-shadow: 0 0 0 0.2rem rgba(253, 126, 20, 0.25);
}
.builder-context .ctx-var-input:not(:placeholder-shown) {
    border-color: #198754;
    background-color: #f0fff4;
}

@media (max-width: 767.98px) {
    .builder-context {
        display: none !important;
    }
    .builder-sidebar {
        width: 220px;
        min-width: 220px;
    }
}

.builder-toolbar {
    padding: 0.4rem 0.75rem;
    border-bottom: 1px solid #dee2e6;
    background: #f8f9fa;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.builder-canvas-area {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #f0f2f5;
    /* Contain Drawflow's internal z-indexes within this stacking context */
    z-index: 0;
}

.builder-canvas-area > #drawflow {
    width: 100%;
    height: 100%;
}

.builder-result {
    border-top: 2px solid #dee2e6;
    background: #fff;
    padding: 0.75rem 1rem;
    max-height: 260px;
    overflow-y: auto;
    flex-shrink: 0;
}

/* ─── Drawflow Node Custom Styles ─────────────────────────────────────────── */

.drawflow .drawflow-node {
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 0.5rem;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    padding: 0;
    min-width: 160px;
}

.drawflow .drawflow-node.selected {
    border-color: #0d6efd;
    box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.25);
}

.drawflow .drawflow-node.df-node-orphan {
    border-color: #fd7e14;
    box-shadow: 0 0 0 2px rgba(253, 126, 20, 0.25);
}

.drawflow .df-node-inner {
    padding: 0.5rem 0.75rem;
}

.drawflow .df-node-header {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-bottom: 0.2rem;
}

.drawflow .df-node-icon {
    font-size: 1rem;
    line-height: 1;
}

.drawflow .df-node-title {
    font-size: 0.82rem;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
}

.drawflow .df-node-category {
    font-size: 0.7rem;
    color: #6c757d;
}

.drawflow .df-node-variable .form-control {
    font-size: 0.75rem;
}

/* AI Generate node */
.drawflow .drawflow-node.ai-generate-node {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-color: #667eea;
}

.drawflow .drawflow-node.ai-generate-node .df-node-inner {
    color: #fff;
}

.drawflow .drawflow-node.ai-generate-node .df-node-category {
    color: rgba(255, 255, 255, 0.8);
}

/* Merge node */
.drawflow .drawflow-node.merge-node {
    background: #f8f9fa;
    border-color: #adb5bd;
}

/* Text node */
.drawflow .drawflow-node.text-node {
    background: #fffbf0;
    border-color: #ffc107;
}

/* ─── Sidebar Droplet Cards ───────────────────────────────────────────────── */

.droplet-card {
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
    border-radius: 0.375rem;
    padding: 0.4rem 0.6rem;
    background: #fff;
    border: 1px solid #dee2e6;
    margin-bottom: 0.3rem;
    user-select: none;
}

.droplet-card:hover {
    border-color: #0d6efd;
    background: #f0f4ff;
    transform: translateX(3px);
}

.droplet-card:active {
    transform: translateX(1px);
    background: #e0eaff;
}

.droplet-card-icon {
    font-size: 1rem;
    line-height: 1;
    min-width: 1.25rem;
    flex-shrink: 0;
}

.droplet-card-title {
    font-size: 0.8rem;
    font-weight: 500;
    line-height: 1.2;
}

.droplet-card-desc {
    font-size: 0.7rem;
    color: #6c757d;
    line-height: 1.2;
}

/* ─── Preview Panel: Colored Structure Blocks ──────────────────────────── */

.preview-block {
    border-left: 4px solid var(--category-color, #6b7280);
    background-color: color-mix(in srgb, var(--category-color, #6b7280) 6%, transparent);
    border-radius: 0 0.375rem 0.375rem 0;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.5rem;
}

.preview-block-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--category-color, #6b7280);
    margin-bottom: 0.2rem;
}

.preview-block-content {
    font-size: 0.8rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    color: #1e293b;
}

@media (max-width: 767.98px) {
    .tenants-table table,
    .users-table table {
        border: 0;
    }

    .tenants-table thead,
    .users-table thead {
        display: none;
    }

    .tenants-table tbody tr,
    .users-table tbody tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid rgba(0, 0, 0, 0.075);
        border-radius: 0.75rem;
        padding: 1rem;
        background-color: #fff;
        box-shadow: 0 0.25rem 0.75rem rgba(0, 0, 0, 0.05);
    }

    .tenants-table tbody tr td,
    .users-table tbody tr td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        padding: 0.35rem 0;
        border-top: none;
        font-size: 0.95rem;
    }

    .tenants-table tbody tr td::before,
    .users-table tbody tr td::before {
        content: attr(data-label);
        flex: 0 0 45%;
        font-weight: 600;
        color: #6c757d;
        padding-right: 0.5rem;
    }

    .tenants-table tbody tr td.table-actions,
    .users-table tbody tr td.table-actions {
        flex-direction: column;
    }

    .tenants-table tbody tr td.table-actions::before,
    .users-table tbody tr td.table-actions::before {
        margin-bottom: 0.5rem;
    }

    .tenants-table tbody tr td.table-actions .btn-group,
    .users-table tbody tr td.table-actions .btn-group {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .tenants-table tbody tr td.table-actions .btn-group .btn,
    .users-table tbody tr td.table-actions .btn-group .btn {
        flex: 1 1 auto;
    }
}

/* ─── Mobile Flow View ──────────────────────────────────────────────────── */

.builder-mobile-flow {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 1rem;
    background: #f8f9fa;
}

.mf-connector {
    text-align: center;
    padding: .25rem 0;
    color: #94a3b8;
    font-size: 1.25rem;
    position: relative;
}
.mf-connector::before {
    content: '';
    display: block;
    width: 2px;
    height: .75rem;
    background: #cbd5e1;
    margin: 0 auto .125rem;
}

.mf-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: .5rem;
    box-shadow: 0 1px 4px rgba(0,0,0,.06);
    overflow: hidden;
    margin-bottom: 0;
}

.mf-card-header {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem .75rem;
    background: #f8fafc;
    cursor: pointer;
    user-select: none;
}
.mf-card-header:hover {
    background: #f1f5f9;
}

.mf-card-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.mf-card-title {
    font-weight: 600;
    font-size: .9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mf-chevron {
    transition: transform .2s ease;
    flex-shrink: 0;
    font-size: .75rem;
    color: #94a3b8;
}
.mf-card-header[aria-expanded="false"] .mf-chevron,
.mf-card-header.collapsed .mf-chevron {
    transform: rotate(-90deg);
}

.mf-card-body {
    padding: .5rem .75rem .75rem;
    border-top: 1px solid #f1f5f9;
}

/* Variable inputs in mobile cards – same orange accent as desktop */
.mf-card-body .form-control,
.mf-card-body .form-select {
    border-color: #fd7e14;
    background-color: #fff8f0;
}
.mf-card-body .form-control:focus,
.mf-card-body .form-select:focus {
    border-color: #e8590c;
    background-color: #fff;
    box-shadow: 0 0 0 .2rem rgba(253,126,20,.25);
}
.mf-card-body .form-control:not(:placeholder-shown),
.mf-card-body .form-select:not([value=""]) {
    border-color: #198754;
    background-color: #f0fff4;
}

/* Level row spacing */
.mf-level {
    margin-bottom: 0;
}
.mf-level + .mf-connector + .mf-level,
.mf-level:first-child {
    margin-top: 0;
}


/* Column narrowing: when many nodes per level, shrink card text */
@media (max-width: 575.98px) {
    .mf-level .col-4 .mf-card-title,
    .mf-level .col-6 .mf-card-title {
        font-size: .78rem;
    }
    .mf-level .col-4 .mf-card-body {
        padding: .35rem .5rem .5rem;
    }
    .mf-level .col-4 .form-control,
    .mf-level .col-4 .form-select {
        font-size: .78rem;
    }
}
