/**
 * Form Builder Styles
 * Custom styling for GridStack-based form designer
 */

/* ========================================
   Page Layout
   ======================================== */

.form-builder-page {
    height: 100%;
    padding: 0.5rem
}

.form-builder-content {
    display: flex;
    gap: 1rem;
    height: 100%;
}

/* ========================================
   Widget Toolbox
   ======================================== */

.widget-toolbox {
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.widget-toolbox .rz-button {
    transition: all 0.2s ease;
}

.widget-toolbox .rz-button:hover {
    transform: translateX(4px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

/* ========================================
   Canvas Area
   ======================================== */

.canvas-area {
    flex: 1;
    overflow: auto;
    background: #f1f1f1;
    border-radius: 8px;
}

.form-builder-canvas {
    height: 100%;
    min-height: 600px;
    min-width: 1000px; /* Ensure canvas doesn't shrink below this width */
    background: #ffffff;
    border-radius: 4px;
}

/* ========================================
   GridStack Customization
   ======================================== */

.grid-stack {
    background: #fafafa;
    background-image:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 59px,
            #e0e0e0 59px,
            #e0e0e0 60px
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent calc(8.333% - 1px),
            #e0e0e0 calc(8.333% - 1px),
            #e0e0e0 8.333%
        );
    height: 100%;
    min-height: 100%;
    min-width: 960px; /* Maintain 12-column grid layout (12 cols × 80px = 960px minimum) */
    position: relative;
}

.grid-stack-item {
    transition: all 0.2s ease;
}

.grid-stack-item:hover {
    z-index: 100;
}

.grid-stack-item-content {
    background: #ffffff;
    border: 2px solid #d0d0d0;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease;
    cursor: default;
}

.grid-stack-item:hover .grid-stack-item-content {
    border-color: #268bbf;
    box-shadow: 0 4px 12px rgba(38, 139, 191, 0.2);
}

.grid-stack-item.ui-draggable-dragging .grid-stack-item-content,
.grid-stack-item.ui-resizable-resizing .grid-stack-item-content {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    border-color: #1976D2;
    opacity: 0.9;
}

/* ========================================
   Widget Container
   ======================================== */

.widget-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.widget-header {
    background: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
    padding: 0.5rem 0.75rem;
    flex-shrink: 0;
}

.widget-drag-handle {
    cursor: move;
}

.widget-drag-handle:active {
    cursor: grabbing;
}

/* Prevent buttons from interfering with drag */
.widget-header .rz-button {
    pointer-events: auto;
    position: relative;
    z-index: 10;
}

.widget-header .rz-button:hover {
    background: rgba(0, 0, 0, 0.05);
}

.widget-body {
    flex: 1;
    padding: 1rem;
    overflow: auto;
}

/* ========================================
   Widget Styling
   ======================================== */

.form-widget {
    height: 100%;
}

/* Text Input Widget */
.text-input-widget .rz-textbox {
    width: 100%;
}

/* Text Area Widget */
.text-area-widget .rz-textarea {
    width: 100%;
    resize: vertical;
}

/* Dropdown Widget */
.dropdown-widget .rz-dropdown {
    width: 100%;
}

/* Checkbox Widget */
.checkbox-widget {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Radio Button Widget */
.radio-button-widget .rz-radiobutton-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* Date Picker Widget */
.date-picker-widget .rz-datepicker {
    width: 100%;
}

/* File Upload Widget */
.file-upload-widget .rz-fileupload {
    width: 100%;
}

/* Signature Widget */
.signature-widget .signature-pad {
    border: 2px dashed #d0d0d0;
    border-radius: 4px;
    background: #fafafa;
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.signature-widget .signature-pad:hover {
    border-color: #268bbf;
    background: #f0f8ff;
}

/* Multi-Select Widget */
.multi-select-widget .rz-dropdown {
    width: 100%;
}

/* Inventory Lookup Widget */
.inventory-lookup-widget .inventory-item-card {
    background: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 0.75rem;
    transition: all 0.2s ease;
}

.inventory-lookup-widget .inventory-item-card:hover {
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.inventory-lookup-widget .search-results {
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    max-height: 200px;
    overflow-y: auto;
    background: #ffffff;
}

.inventory-lookup-widget .search-result-item {
    padding: 0.5rem;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.15s ease;
}

.inventory-lookup-widget .search-result-item:hover {
    background: #f0f8ff;
}

.inventory-lookup-widget .search-result-item:last-child {
    border-bottom: none;
}

/* User Picker Widget */
.user-picker-widget .user-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.75rem;
    background: #e3f2fd;
    border: 1px solid #90caf9;
    border-radius: 16px;
    font-size: 0.875rem;
    transition: all 0.2s ease;
}

.user-picker-widget .user-chip:hover {
    background: #bbdefb;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.user-picker-widget .search-results {
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    max-height: 250px;
    overflow-y: auto;
    background: #ffffff;
}

.user-picker-widget .search-result-item {
    padding: 0.75rem;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.15s ease;
}

.user-picker-widget .search-result-item:hover {
    background: #f0f8ff;
}

.user-picker-widget .search-result-item:last-child {
    border-bottom: none;
}

.user-picker-widget .user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
    flex-shrink: 0;
}

/* ========================================
   Properties Panel
   ======================================== */

.properties-panel {
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.properties-panel .rz-textbox,
.properties-panel .rz-dropdown {
    width: 100%;
}

/* ========================================
   GridStack Resize Handles
   ======================================== */

.grid-stack-item > .ui-resizable-handle {
    background: transparent;
    transition: all 0.2s ease;
}

.grid-stack-item:hover > .ui-resizable-handle::after {
    opacity: 1;
}

.grid-stack-item > .ui-resizable-se::after {
    content: "";
    position: absolute;
    right: 4px;
    bottom: 4px;
    width: 8px;
    height: 8px;
    background: #268bbf;
    border-radius: 50%;
    opacity: 0.6;
    transition: all 0.2s ease;
}

.grid-stack-item:hover > .ui-resizable-se::after {
    width: 10px;
    height: 10px;
    right: 3px;
    bottom: 3px;
    opacity: 1;
}

/* ========================================
   Placeholder Styling
   ======================================== */

.grid-stack-placeholder > .placeholder-content {
    background: rgba(38, 139, 191, 0.1) !important;
    border: 2px dashed #268bbf !important;
    border-radius: 6px;
}

/* ========================================
   Animation Classes
   ======================================== */

.grid-stack-animate .grid-stack-item {
    transition: left 0.3s, top 0.3s, width 0.3s, height 0.3s;
}

.grid-stack-item.ui-draggable-dragging,
.grid-stack-item.ui-resizable-resizing {
    transition: none !important;
    z-index: 1000 !important;
}

/* ========================================
   Responsive Adjustments
   ======================================== */

@media (max-width: 1400px) {
    .widget-toolbox {
        width: 240px;
    }

    .properties-panel {
        width: 260px;
    }
}

@media (max-width: 1200px) {
    .form-builder-content {
        flex-direction: column;
    }

    .widget-toolbox,
    .properties-panel {
        width: 100%;
        max-height: 300px;
    }
}

/* ========================================
   Utility Classes
   ======================================== */

.widget-icon {
    font-size: 1.25rem;
    vertical-align: middle;
    margin-right: 0.5rem;
}

.widget-label-required {
    color: #dc3545;
    margin-left: 0.25rem;
}

.widget-validation-error {
    color: #dc3545;
    font-size: 0.75rem;
    margin-top: 0.25rem;
}

/* ========================================
   Scrollbar Styling
   ======================================== */

.canvas-area::-webkit-scrollbar,
.widget-toolbox::-webkit-scrollbar,
.properties-panel::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.canvas-area::-webkit-scrollbar-track,
.widget-toolbox::-webkit-scrollbar-track,
.properties-panel::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.canvas-area::-webkit-scrollbar-thumb,
.widget-toolbox::-webkit-scrollbar-thumb,
.properties-panel::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

.canvas-area::-webkit-scrollbar-thumb:hover,
.widget-toolbox::-webkit-scrollbar-thumb:hover,
.properties-panel::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* ========================================
   Form Preview (runtime view)
   ======================================== */

.form-preview-page {
    padding: 1rem 0;
}

.form-preview-card {
    padding: 1.25rem;
}

.form-preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1rem;
}

.form-preview-item {
    padding: 1rem;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}
