/* Flow Designer Styles */

.flow-designer {
    display: flex;
    height: calc(100vh - 64px); /* Assuming top nav height */
    overflow: hidden;
    background-color: #f8f9fa; /* Slightly cleaner background */
    font-family: 'Poppins', sans-serif; /* Match new RoboDesk font */
    min-width: 0; /* Allow flex children to shrink below content size */
}

/* Palette Styles */
.fd-palette {
    width: 260px;
    flex-shrink: 0;
    background-color: #ffffff;
    border-right: 1px solid #e9ecef;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.fd-section-header {
    padding: 16px 20px;
    font-size: 13px;
    font-weight: 700;
    color: var(--secondary-color, #622695);
    background-color: #fbfbfb;
    border-bottom: 1px solid #e9ecef;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.fd-palette-group {
    padding: 18px;
}

.fd-palette-group-title {
    font-size: 11px;
    font-weight: 600;
    color: #adb5bd;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.fd-palette-item {
    padding: 12px;
    margin-bottom: 12px;
    background-color: #fff;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    cursor: grab;
    transition: all 0.2s ease;
    user-select: none;
    font-size: 13px;
    display: flex;
    align-items: center;
    color: #495057;
}

.fd-palette-item:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    border-color: var(--secondary-color, #622695);
    color: var(--secondary-color, #622695);
    transform: translateY(-1px);
}

.fd-palette-item i {
    margin-right: 8px;
    font-size: 18px;
    opacity: 0.7;
}

/* Canvas Styles */
.fd-canvas-area {
    flex: 1 1 0;
    min-width: 0; /* Critical: allow flex child to shrink below content size */
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.fd-canvas-header {
    min-height: 48px;
    background-color: #fff;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    padding: 6px 12px;
    justify-content: space-between;
    gap: 6px;
    overflow-x: auto; /* Last-resort horizontal scroll for very narrow views */
    overflow-y: visible;
    flex-shrink: 0; /* Header must never collapse vertically */
}

.fd-tabs-container {
    display: flex;
    background-color: #fff;
    border-bottom: 1px solid #e9ecef;
    overflow-x: auto;
    padding: 0 24px;
    align-items: center;
}

.fd-tab {
    padding: 18px 20px;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    font-size: 14px;
    font-weight: 500;
    color: #6c757d;
    white-space: nowrap;
    display: flex;
    align-items: center;
    transition: all 0.2s;
}

.fd-tab:hover {
    color: var(--secondary-color, #622695);
    background-color: rgba(98, 38, 149, 0.05);
}

.fd-tab.active {
    color: var(--secondary-color, #622695);
    border-bottom: 3px solid var(--secondary-color, #622695);
    font-weight: 600;
}

.fd-tab i.remove-tab {
    font-size: 16px;
    margin-left: 12px;
    color: #ced4da;
    transition: color 0.2s;
}

.fd-tab i.remove-tab:hover {
    color: #dc3545;
}

.fd-add-tab {
    padding: 10px 15px;
    cursor: pointer;
    color: var(--secondary-color, #622695);
    display: flex;
    align-items: center;
    font-size: 13px;
    font-weight: 600;
    border-radius: 4px;
}

.fd-add-tab:hover {
    background-color: rgba(98, 38, 149, 0.08);
}

.fd-canvas {
    flex: 1;
    padding: 40px;
    overflow-y: auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    background-color: #f1f3f5;
}

.fd-screen-container {
    width: 100%;
    max-width: 480px;
    background-color: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.08);
    min-height: 500px;
    height: auto;
    display: flex;
    flex-direction: column;
    margin-bottom: 40px;
    border: 1px solid #e9ecef;
}

.fd-screen-header {
    padding: 18px 24px;
    border-bottom: 1px solid #e9ecef;
    background-color: #fafbfb;
    border-radius: 12px 12px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* ========== SCREEN HEADER CHECKBOX ALIGNMENT FIX ========== */
/* Scoped to .fd-screen-header only — does NOT affect Properties panel or global styles */

/* 1. Label container: inline-flex centers the checkbox+text pair vertically */
.fd-screen-header label {
    display: inline-flex !important;
    align-items: center;
    line-height: 1;
    cursor: pointer;
    margin: 0;
    padding: 0;
}

/* 2. Span (the clickable text next to the hidden input): relative anchor for pseudo-elements */
.fd-screen-header label [type="checkbox"] + span:not(.lever) {
    position: relative;
    padding-left: 26px !important; /* Slightly closer to text */
    line-height: normal !important;
    display: inline-flex !important;
    align-items: center !important; 
}

/* 3. Override Materialize's absolute-positioned ::before (border box) and ::after (checkmark) */
/*    Explicit pixel placement for a pixel-perfect match with the label baseline */
.fd-screen-header label [type="checkbox"].filled-in + span:not(.lever)::before,
.fd-screen-header label [type="checkbox"].filled-in + span:not(.lever)::after {
    top: 50% !important;
    margin-top: -10px !important; /* -9px is exact geometric center of 18px box, -10px is optical center */
    /* DO NOT use transform here! Materialize uses transform: rotateZ(37deg) to draw the checkmark */
}

/* 4. Theme sync: unchecked border uses --secondary-color */
/* 4. Theme sync: unchecked border uses --secondary-color */
.fd-screen-header label [type="checkbox"].filled-in:not(:checked) + span:not(.lever)::after {
    border: 2px solid var(--secondary-color, #622695);
}

/* 5. Theme sync: checked background and border use --secondary-color */
.fd-screen-header label [type="checkbox"].filled-in:checked + span:not(.lever)::after {
    border: 2px solid var(--secondary-color, #622695);
    background-color: var(--secondary-color, #622695);
}

.fd-screen-dropzone {
    flex: 1;
    padding: 24px;
}

.fd-comp-wrapper {
    position: relative;
    padding: 16px;
    margin-bottom: 16px;
    border: 1px dashed #dee2e6;
    border-radius: 8px;
    background-color: #fff;
    cursor: pointer;
    transition: all 0.2s;
}

.fd-comp-wrapper:hover {
    border-color: var(--secondary-color, #622695);
    background-color: rgba(98, 38, 149, 0.02);
}

.fd-comp-wrapper.selected {
    border-color: var(--secondary-color, #622695);
    border-style: solid;
    background-color: rgba(98, 38, 149, 0.05);
    box-shadow: 0 0 0 3px rgba(98, 38, 149, 0.1);
}

.fd-comp-controls {
    position: absolute;
    top: -12px;
    right: -12px;
    display: none;
    background-color: #fff;
    border-radius: 24px;
    padding: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 10;
}

.fd-comp-wrapper:hover .fd-comp-controls,
.fd-comp-wrapper.selected .fd-comp-controls {
    display: flex;
    align-items: center;
}

.fd-comp-ctrl-btn {
    padding: 6px;
    cursor: pointer;
    color: #adb5bd;
    transition: color 0.2s;
}

.fd-comp-ctrl-btn:hover {
    color: #dc3545;
}

.fd-drag-handle {
    cursor: grab;
    color: #ced4da;
    margin-right: 12px;
}

/* Properties Styles */
.fd-properties {
    width: 340px;
    flex-shrink: 0;
    background-color: #fff;
    border-left: 1px solid #e9ecef;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.fd-prop-form {
    padding: 24px;
}

.fd-prop-group {
    margin-bottom: 24px;
}

.fd-prop-group label {
    font-size: 11px;
    font-weight: 700;
    color: #495057;
    display: block;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Checkbox label alignment fix for Materialize filled-in checkboxes.
   Materialize hides the <input> (position:absolute; opacity:0) and renders
   the visual checkbox via ::before/::after on the adjacent <span>.
   The base .fd-prop-group label { display:block } breaks inline layout,
   so we override it on labels that carry .fd-checkbox-label. */
.fd-checkbox-label {
    display: inline-flex !important; /* Force horizontal layout */
    align-items: center !important;  /* Center box and text vertically */
    white-space: nowrap !important;  /* Prevents 'Required' from jumping to next line */
    width: 100% !important;
    cursor: pointer !important;
    margin-bottom: 8px !important;
    position: relative;
    text-transform: none !important; /* Optional: keeps it 'Required' instead of 'REQUIRED' */
}

.fd-checkbox-label > [type="checkbox"] {
    /* Materialize already hides these, but ensure they don't affect layout */
    position: absolute !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* Ensure the Materialize span matches the working .fd-screen-header pattern */
.fd-checkbox-label [type="checkbox"] + span:not(.lever) {
    position: relative !important;
    padding-left: 26px !important;
    line-height: normal !important;
    display: inline-flex !important;
    align-items: center !important;
    height: auto !important;
    font-size: 13px !important;
    font-weight: 600 !important;
    color: #495057 !important;
    letter-spacing: 0.5px !important;
    cursor: pointer;
    -webkit-user-select: none;
       -moz-user-select: none;
        -ms-user-select: none;
            user-select: none;
}

/* Override Materialize's absolute-positioned ::before/::after AND
   the global style.css margin-top:10px.  Same approach as .fd-screen-header. */
.fd-checkbox-label [type="checkbox"].filled-in + span:not(.lever)::before,
.fd-checkbox-label [type="checkbox"].filled-in + span:not(.lever)::after {
    top: 50% !important;
    margin-top: -10px !important;
    /* DO NOT use transform here — Materialize uses rotateZ(37deg) for the checkmark */
}

.fd-prop-group input[type="text"],
.fd-prop-group select,
.fd-prop-group textarea {
    width: 100%;
    box-sizing: border-box;
    display: block;
    border: 1px solid #ced4da;
    border-radius: 6px;
    padding: 10px 12px;
    font-size: 13px;
    transition: border-color 0.2s;
}

.fd-prop-group input:focus, .fd-prop-group select:focus, .fd-prop-group textarea:focus {
    border-color: var(--secondary-color, #622695);
    outline: none;
    box-shadow: 0 0 0 3px rgba(98, 38, 149, 0.1);
}

.fd-options-list {
    margin-top: 12px;
}

.fd-option-item {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
}

.fd-option-item input {
    margin: 0 6px !important;
    height: 2.2rem !important;
}

/* Validation Output — Collapsible Panel */
.fd-validation-container {
    position: relative;
}

.fd-validation-panel {
    border-bottom: 1px solid #ffe3e3;
    background-color: #fff5f5;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease, opacity 0.3s ease;
}

.fd-validation-panel.fd-panel-warnings {
    background-color: #fff8e1;
    border-bottom-color: #ffe0b2;
}

.fd-validation-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 24px;
    cursor: pointer;
    user-select: none;
}

.fd-validation-panel-header strong {
    display: flex;
    align-items: center;
    gap: 5px;
}

.fd-validation-panel-header .fd-panel-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.fd-validation-panel-header .fd-panel-actions i {
    font-size: 20px;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s, transform 0.3s;
    border-radius: 50%;
    padding: 2px;
}

.fd-validation-panel-header .fd-panel-actions i:hover {
    opacity: 1;
}

.fd-validation-panel-header .fd-chevron {
    transition: transform 0.3s ease;
}

.fd-validation-panel-header .fd-chevron.collapsed {
    transform: rotate(-90deg);
}

.fd-validation-panel-body {
    max-height: 300px;
    overflow-y: auto;
    transition: max-height 0.3s ease, padding 0.3s ease;
    padding: 0 24px 10px 24px;
}

.fd-validation-panel-body.collapsed {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
}

.fd-validation-panel ul {
    margin: 4px 0 0 0;
    padding-left: 20px;
    color: #e03131;
    font-size: 13px;
}

.fd-validation-panel.fd-panel-warnings ul {
    color: #e65100;
}

.fd-validation-panel ul li {
    padding: 4px 0;
    cursor: pointer;
    border-radius: 4px;
    padding-left: 4px;
    transition: background-color 0.15s;
}

.fd-validation-panel ul li:hover {
    background-color: rgba(0,0,0,0.05);
}

/* Floating Badge (collapsed state) */
.fd-validation-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 14px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    margin: 4px 8px;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}

.fd-validation-badge:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(0,0,0,0.18);
}

.fd-validation-badge.badge-errors {
    background-color: #ffebee;
    color: #c62828;
    border: 1px solid #ef9a9a;
}

.fd-validation-badge.badge-warnings {
    background-color: #fff3e0;
    color: #e65100;
    border: 1px solid #ffcc80;
}

.fd-validation-badge i {
    font-size: 16px;
}

/* Scroll-to-fix highlight pulse */
@keyframes fd-highlight-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(198, 40, 40, 0.5); }
    50%  { box-shadow: 0 0 0 8px rgba(198, 40, 40, 0.15); }
    100% { box-shadow: 0 0 0 0 rgba(198, 40, 40, 0); }
}

.fd-comp-wrapper.fd-highlight-error {
    animation: fd-highlight-pulse 0.8s ease 2;
    outline: 2px solid #e03131;
    outline-offset: 2px;
    border-radius: 6px;
}

/* Dummy Components */
.fd-dummy-heading { 
    font-size: 24px; 
    font-weight: 700; 
    margin: 0; 
    color: var(--secondary-color, #622695); 
    line-height: 1.2;
}

.fd-dummy-subheading { 
    font-size: 18px; 
    font-weight: 600;
    margin: 0; 
    color: #495057; 
}

.fd-dummy-body { 
    font-size: 14px; 
    margin: 0; 
    color: #495057;
    line-height: 1.5;
}

.fd-dummy-input { 
    width: 100%; 
    padding: 12px; 
    border: 1px solid #ced4da; 
    border-radius: 6px; 
    box-sizing: border-box; 
    background: #f8f9fa;
    color: #adb5bd;
    font-size: 14px;
}

.fd-dummy-btn { 
    width: 100%; 
    padding: 12px; 
    background: var(--secondary-color, #622695); 
    color: #fff; 
    border: none; 
    border-radius: 8px; 
    font-weight: 700; 
    text-align: center;
    box-shadow: 0 4px 12px rgba(98, 38, 149, 0.2);
    transition: transform 0.2s;
}

.fd-dummy-img { 
    width: 100%; 
    height: 150px; 
    background: #f1f3f5; 
    border: 2px dashed #dee2e6;
    border-radius: 8px;
    display: flex; 
    flex-direction: column;
    align-items: center; 
    justify-content: center; 
    color: #adb5bd; 
}

/* ========== HEADER ACTIONS BAR ========== */
.fd-header-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* ========== STATUS BADGE ========== */
.fd-status-badge {
    display: inline-block;
    padding: 5px 16px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: capitalize;
    line-height: 1;
    border: none;
}

.fd-status-draft {
    background-color: rgba(245, 166, 35, 0.12);
    color: #e6a117;
}

.fd-status-published {
    background-color: rgba(56, 142, 60, 0.1);
    color: #388e3c;
}

.fd-status-deprecated {
    background-color: rgba(117, 117, 117, 0.1);
    color: #757575;
}

.fd-status-blocked {
    background-color: rgba(211, 47, 47, 0.1);
    color: #d32f2f;
}

/* ========== BUTTON GROUP ========== */
.fd-btn-group {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-left: 0;
    flex-shrink: 0;
}

.fd-btn-save {
    background-color: transparent !important;
    border: 2px solid #495057 !important;
    color: #495057 !important;
    box-shadow: none !important;
    height: 38px;
    line-height: 34px;
    padding: 0 20px;
    border-radius: 8px !important;
    font-weight: 600;
    font-size: 13px;
    text-transform: none;
    transition: all 0.2s;
}

.fd-btn-save:hover:not([disabled]) {
    background-color: #f8f9fa !important;
    border-color: #212529 !important;
    color: #212529 !important;
}

.fd-btn-publish {
    background-color: var(--secondary-color, #622695) !important;
    color: #fff !important;
    box-shadow: none !important;
    height: 38px;
    line-height: 38px;
    padding: 0 24px;
    border-radius: 8px !important;
    font-weight: 700;
    font-size: 13px;
    text-transform: none;
    border: none !important;
    transition: opacity 0.3s ease, background-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.fd-btn-publish:hover:not([disabled]) {
    background-color: var(--secondary-color, #622695) !important;
    box-shadow: 0 4px 14px rgba(98, 38, 149, 0.4) !important;
    transform: translateY(-1px);
}

/* Disabled state: keep purple bg but dim with opacity — overrides Materialize's grey #dfdfdf */
.fd-btn-save[disabled],
.fd-btn-publish[disabled] {
    background-color: var(--secondary-color, #622695) !important;
    color: #fff !important;
    opacity: 0.4 !important;
    cursor: not-allowed !important;
    pointer-events: auto !important;
}

/* Enabled state: explicitly reset opacity to beat any residual Materialize overrides */
.fd-btn-save:not([disabled]),
.fd-btn-publish:not([disabled]) {
    opacity: 1 !important;
}


/* ========== READ-ONLY BANNER ========== */
.fd-readonly-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 24px;
    background-color: #fff9db;
    border-bottom: 1px solid #fff3bf;
    color: #f08c00;
    font-size: 13px;
    font-weight: 600;
}

.fd-readonly-banner i {
    font-size: 20px;
}

/* ========== PUBLISHED EDIT INFO BANNER ========== */
.fd-published-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 24px;
    background-color: #e3f2fd;
    border-bottom: 1px solid #bbdefb;
    color: #1565c0;
    font-size: 13px;
    font-weight: 600;
}

.fd-published-banner i {
    font-size: 20px;
}

/* ========== FLOW TABLE ACTION ICONS ========== */
.fb-action-icon {
    font-size: 20px;
    vertical-align: middle;
    cursor: pointer;
    transition: opacity 0.2s, color 0.2s;
}

.disabled-icon {
    opacity: 0.4 !important;
    cursor: not-allowed !important;
    pointer-events: none !important;
}

/* ========== RESPONSIVE: HEADER & SIDEBARS ========== */

/* Medium: compact buttons and shrink sidebars */
@media (max-width: 1400px) {
    .fd-palette {
        width: 200px;
    }
    .fd-properties {
        width: 280px;
    }
    .fd-btn-save,
    .fd-btn-publish {
        padding: 0 10px !important;
        font-size: 12px !important;
        height: 32px !important;
    }
    .fd-status-badge {
        padding: 4px 8px;
        font-size: 10px;
    }
    .fd-header-actions {
        gap: 4px;
    }
}

/* Narrow: icon-only buttons */
@media (max-width: 1200px) {
    .fd-palette {
        width: 180px;
    }
    .fd-properties {
        width: 240px;
    }
    .fd-btn-label {
        display: none !important; /* Hide button text, icon-only */
    }
    .fd-btn-save,
    .fd-btn-publish {
        padding: 0 8px !important;
        min-width: 32px !important;
        height: 32px !important;
    }
    .fd-preview-label {
        display: none !important; /* Hide 'Preview' text */
    }
    .fd-canvas-header input[type="text"] {
        font-size: 14px !important;
    }
}

/* Tight: hide palette, give canvas full width */
@media (max-width: 1000px) {
    .fd-palette {
        display: none;
    }
    .fd-properties {
        width: 220px;
    }
}

/* Very tight: stack header rows */
@media (max-width: 800px) {
    .fd-properties {
        width: 200px;
    }
    .fd-canvas-header {
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
        padding: 6px 8px;
    }
    .fd-header-actions {
        justify-content: flex-end;
        width: 100%;
    }
}

/* ═══════ EMPTY STATE ═══════ */
.fb-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    text-align: center;
}
