/**
 * template-designer.css
 * Flight Strip Template Designer Styles - GridStack.js Integration
 *
 * Provides styling for:
 * - CRUD listing view for template management
 * - Visual drag-drop template designer interface using GridStack.js
 * - Grid canvas, block palette, properties panel, and preview area
 * - GridStack widget customizations for block appearance
 *
 * Version: 2.2.0
 * Copyright Paul Astle 2025
 */

/* ===== Templates List View (CRUD Listing) ===== */

.templates-page {
    padding: 1.5rem 2rem;
    max-width: 1400px;
    margin: 0 auto;
}

.templates-page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--color-border);
}

.templates-header-left {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.templates-header-left h1 {
    font-size: 1.5rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0;
    color: var(--color-text);
}

.templates-header-left h1 .brand-icon {
    width: 28px;
    height: 28px;
    color: var(--color-primary);
}

.templates-header-right {
    display: flex;
    gap: 0.75rem;
}

/* Filters Bar */
.filters-bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--color-surface);
    border-radius: 10px;
    border: 1px solid var(--color-border);
}

.search-input {
    flex: 1;
    max-width: 400px;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-bg);
    color: var(--color-text);
    transition: all 0.2s;
}

.search-input::placeholder {
    color: var(--color-text-secondary);
}

.search-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.filter-select {
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-bg);
    color: var(--color-text);
    cursor: pointer;
    transition: all 0.2s;
}

.filter-select:focus {
    outline: none;
    border-color: var(--color-primary);
}

/* Table styles inherited from admin.css - removed duplicates that used wrong CSS variables */

/* Status Indicator (Default template dot) */
.status-indicator {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--color-border);
}

.status-indicator.active {
    background: #10b981;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

/* Actions Cell */
.actions-cell {
    display: flex;
    gap: 0.5rem;
    flex-wrap: nowrap;
}

.actions-cell .btn {
    white-space: nowrap;
}

.actions-cell .btn svg,
.actions-cell .btn i {
    width: 14px;
    height: 14px;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    text-align: center;
    background: var(--color-surface);
    border-radius: 12px;
    border: 2px dashed var(--color-border);
}

.empty-state-icon {
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(59, 130, 246, 0.1);
    border-radius: 50%;
    margin-bottom: 1.5rem;
}

.empty-state-icon svg,
.empty-state-icon i {
    width: 40px;
    height: 40px;
    color: var(--color-primary);
}

.empty-state h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--color-text);
}

.empty-state p {
    color: var(--color-text-secondary);
    margin-bottom: 1.5rem;
    max-width: 400px;
}

/* Error button variant */
.btn-error {
    background: #ef4444;
    color: white;
    border: none;
}

.btn-error:hover {
    background: #dc2626;
}

/* ===== Designer Layout ===== */

/* Grid width calculation at 75% scale:
 * 40 columns × 36px = 1440px (48px tvOS × 0.75 = 36px)
 * + padding: 8px × 2 = 16px
 * + border: 2px × 2 = 4px
 * Total: 1460px
 * We use this for consistent width across header buttons and blocks strip
 */
:root {
    --designer-content-width: 1460px;
}

/* Designer view uses position fixed to break out of main-content constraints and span full viewport */
#template-designer-view {
    position: fixed;
    top: 60px;  /* Below nav header */
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    max-width: 100vw;
    z-index: 50;
    background: var(--color-bg);
}

.designer-header {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.designer-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.designer-header-buttons {
    justify-content: flex-start;
    gap: 0.5rem;
    /* Match grid width - align with canvas */
    max-width: var(--designer-content-width);
    margin-left: 2rem;  /* Match canvas-wrapper padding */
}

.designer-header-left {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.designer-header-left h1 {
    font-size: 1.25rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
}

.designer-header-left .brand-icon {
    width: 24px;
    height: 24px;
    color: var(--color-primary);
}

.back-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--color-text-secondary);
    text-decoration: none;
    font-size: 0.875rem;
    transition: color 0.2s;
}

.back-link:hover {
    color: var(--color-primary);
}

.back-link svg {
    width: 16px;
    height: 16px;
}

.designer-header-center {
    flex: 1;
    display: flex;
    justify-content: center;
}

.template-name-display {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--color-text);
    margin-left: 1rem;
}

.template-name-input {
    font-size: 1.125rem;
    font-weight: 600;
    text-align: center;
    border: none;
    background: transparent;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    min-width: 300px;
    transition: background 0.2s;
}

.template-name-input:hover {
    background: var(--color-bg);
}

.template-name-input:focus {
    outline: none;
    background: var(--color-bg);
    box-shadow: 0 0 0 2px var(--color-primary);
}


.designer-header-right {
    display: flex;
    gap: 0.75rem;
}

/* Main Designer Container - Vertical Layout */
.designer-main {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;  /* Align all content to top, not distributed */
    min-height: calc(100% - 60px);  /* At least fill fixed container minus header */
    overflow-y: auto;  /* Scroll vertically if content exceeds viewport */
}

/* ===== Blocks Strip (Bottom) ===== */

.blocks-strip {
    display: flex;
    flex-direction: column;  /* Stack header and items vertically */
    gap: 10px;
    margin: 0 2rem 1rem 2rem;  /* Match canvas side margins */
    padding: 12px 16px;
    background: var(--color-surface);
    border: 2px solid var(--color-border);
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    flex-shrink: 0;
    /* Match grid width */
    max-width: var(--designer-content-width);
}

.blocks-strip-header {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.blocks-strip-title {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--color-text-secondary);
}

.blocks-strip-items {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    flex: 1;
    padding: 4px 0;
}

/* Scrollbar for blocks strip */
.blocks-strip-items::-webkit-scrollbar {
    height: 6px;
}

.blocks-strip-items::-webkit-scrollbar-track {
    background: var(--color-bg);
    border-radius: 3px;
}

.blocks-strip-items::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 3px;
}

.blocks-strip-items::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-secondary);
}

/* Block items in horizontal strip - compact to fit all blocks */
/* GridStack requires .grid-stack-item wrapper with .grid-stack-item-content child */
.block-item {
    min-width: 85px;
    flex-shrink: 0;
    cursor: grab;
    /* Override GridStack's default absolute positioning for palette items */
    position: relative !important;
    width: auto !important;
    height: auto !important;
    left: auto !important;
    top: auto !important;
}

.block-item .grid-stack-item-content,
.block-item .block-item-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 10px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    transition: all 0.2s;
    /* Override GridStack's content positioning */
    position: relative !important;
    inset: auto !important;
    width: auto !important;
    height: auto !important;
}

.block-item:hover .grid-stack-item-content,
.block-item:hover .block-item-inner {
    border-color: var(--color-primary);
    background: rgba(59, 130, 246, 0.05);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.block-item:active {
    cursor: grabbing;
}

.block-item-icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    margin-bottom: 4px;
    font-size: 1.25rem;
}

.block-item-icon svg {
    width: 18px;
    height: 18px;
}

.block-item-name {
    font-size: 0.6875rem;
    font-weight: 500;
    text-align: center;
    white-space: nowrap;
}

.block-item-size {
    font-size: 0.625rem;
    color: var(--color-text-secondary);
    margin-top: 1px;
}

/* Block category colors */
.block-item[data-category="flight"] .block-item-icon { background: rgba(59, 130, 246, 0.1); color: #3b82f6; }
.block-item[data-category="dispatch"] .block-item-icon { background: rgba(34, 197, 94, 0.1); color: #22c55e; }
.block-item[data-category="weather"] .block-item-icon { background: rgba(234, 179, 8, 0.1); color: #eab308; }
.block-item[data-category="crew"] .block-item-icon { background: rgba(168, 85, 247, 0.1); color: #a855f7; }
.block-item[data-category="status"] .block-item-icon { background: rgba(239, 68, 68, 0.1); color: #ef4444; }
.block-item[data-category="custom"] .block-item-icon { background: rgba(107, 114, 128, 0.1); color: #6b7280; }

/* ===== Context Menu ===== */

.context-menu {
    position: fixed;
    background: #ffffff;  /* Solid white - no transparency */
    border: 1px solid var(--color-border);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    display: none;
    min-width: 140px;
    padding: 4px 0;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

/* Dark mode context menu */
[data-theme="dark"] .context-menu,
.dark .context-menu {
    background: #1f2937;  /* Solid dark - no transparency */
}

.context-menu.visible {
    display: block;
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 14px;
    text-align: left;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--color-text);
    transition: background 0.15s;
}

.context-menu-item:hover {
    background: var(--color-bg);
}

.context-menu-item svg {
    width: 16px;
    height: 16px;
    color: var(--color-text-secondary);
}

.context-menu-item.danger {
    color: #ef4444;
}

.context-menu-item.danger svg {
    color: #ef4444;
}

/* ===== Header Toolbar Controls ===== */

.toolbar-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.toolbar-controls label {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
}

.category-dropdown {
    padding: 0.375rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-bg);
    color: var(--color-text);
    cursor: pointer;
    transition: all 0.2s ease;
}

.category-dropdown:hover {
    border-color: var(--color-primary);
}

.category-dropdown:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* ===== Canvas Area ===== */

.designer-canvas-container {
    /* No flex: 1 - size to content, don't expand to fill viewport */
    display: block;
    background: var(--color-bg);
    overflow-x: auto;  /* Horizontal scroll for wide grids */
    overflow-y: visible;
    flex-shrink: 0;
}

.toolbar-select {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-bg);
    cursor: pointer;
}

.canvas-wrapper {
    /* No flex: 1 - size to content */
    overflow-x: scroll; /* ALWAYS show horizontal scrollbar */
    overflow-y: visible;
    padding: 1rem 2rem;
    display: block;
}

/* Custom Scrollbar Styling - Always Visible */
.canvas-wrapper::-webkit-scrollbar {
    height: 14px;
    width: 14px;
}

.canvas-wrapper::-webkit-scrollbar-track {
    background: var(--color-surface);
    border-radius: 7px;
    border: 1px solid var(--color-border);
    margin: 0 1rem;
}

.canvas-wrapper::-webkit-scrollbar-thumb {
    background: var(--color-text-secondary);
    border-radius: 7px;
    border: 3px solid var(--color-surface);
    min-width: 40px;
}

.canvas-wrapper::-webkit-scrollbar-thumb:hover {
    background: var(--color-primary);
}

.canvas-wrapper::-webkit-scrollbar-corner {
    background: var(--color-surface);
}

/* Firefox scrollbar - always show */
.canvas-wrapper {
    scrollbar-width: auto;
    scrollbar-color: var(--color-text-secondary) var(--color-surface);
}

/* Grid Canvas
 * CALIBRATION NOTE: These dimensions match tvOS DynamicFlightRowView at 75% scale
 * Optimized for MacBook Air (13": 1440×900, 15": 1680×1050)
 *
 * tvOS actual dimensions:
 * - Available grid width: 1920pt
 * - Column width: 1920 / 40 = 48pt
 * - Row height: configurable (default 45pt)
 * - Row spacing: 10pt
 *
 * Admin preview at 75% scale:
 * - Column width: 48 × 0.75 = 36px
 * - Row height: configurable × 0.75
 * - Row spacing: 10 × 0.75 = 7.5px
 * - Total width: 1920 × 0.75 = 1440px
 */
.canvas-grid {
    display: grid;
    grid-template-columns: repeat(40, 36px);  /* 75% of tvOS: 48pt × 0.75 = 36px */
    column-gap: 0;      /* tvOS has no horizontal gaps between columns */
    row-gap: 7.5px;     /* 75% of tvOS 10pt row spacing */
    background: var(--color-surface);
    border: 2px solid var(--color-border);
    border-radius: 12px;
    padding: 8px;
    width: fit-content;  /* Size to content, don't expand to fill container */
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    position: relative;
}

/* Grid Cells - height set dynamically via JS based on rowHeight (75% scale for preview) */
/* Column number header cells - non-interactive reference markers */
.grid-column-number {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 500;
    color: var(--color-text-secondary, #666);
    background: var(--color-bg-secondary, #f5f5f5);
    border-bottom: 1px solid var(--color-border, #ddd);
    user-select: none;
    pointer-events: none;  /* Exclude from drag-drop interactions */
}

.grid-cell {
    /* height set dynamically via inline style */
    background: var(--color-bg);
    border: 1px solid rgba(128, 128, 128, 0.3);
    border-radius: 4px;
    transition: all 0.2s;
    position: relative;
    z-index: 1;  /* Below blocks which are z-index: 2 */
}

/* Add subtle grid pattern inside cells */
.grid-cell::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(to right, rgba(128, 128, 128, 0.1) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(128, 128, 128, 0.1) 1px, transparent 1px);
    background-size: 10px 10px;
    pointer-events: none;
}

.grid-cell.drag-over {
    background: rgba(59, 130, 246, 0.1);
    border-color: var(--color-primary);
    border-style: solid;
}

.grid-cell.invalid-drop {
    background: rgba(239, 68, 68, 0.1);
    border-color: #ef4444;
}

/* Placed Blocks on Canvas */
.canvas-block {
    position: relative;
    z-index: 2;  /* Overlay grid cells which are z-index: 1 */
    background: var(--surface);
    border: 2px solid var(--border);  /* Visible border at all times */
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: move;
    opacity: 0.85;  /* More visible when not selected */
    /* Smooth transitions for position changes and visual states */
    transition:
        grid-column 0.12s ease-out,
        grid-row 0.12s ease-out,
        box-shadow 0.2s ease,
        border-color 0.2s ease,
        opacity 0.15s ease;
    overflow: hidden;
    user-select: none;
}

.canvas-block:hover {
    opacity: 0.95;  /* More visible on hover */
    border-color: var(--color-primary);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.canvas-block.selected,
.canvas-block.selected:hover {
    opacity: 1;  /* Full opacity when selected - always */
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* During active drag - disable position transitions for instant response */
.canvas-block.dragging {
    opacity: 0.5;
    z-index: 1000;
    transition: opacity 0.15s ease, box-shadow 0.2s ease;
}

/* Preview position during drag - shows where block will land */
.canvas-block.preview-position {
    opacity: 0.85;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3), 0 8px 24px rgba(0, 0, 0, 0.2);
}

.canvas-block-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.25rem;
    text-align: center;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.canvas-block-icon {
    font-size: 1.125rem;
    margin-bottom: 0.125rem;
    flex-shrink: 0;
}

.canvas-block-name {
    font-size: 0.625rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

/* Block resize handles */
.resize-handle {
    position: absolute;
    background: var(--color-primary);
    border-radius: 2px;
    opacity: 0;
    transition: opacity 0.2s;
}

.canvas-block:hover .resize-handle,
.canvas-block.selected .resize-handle {
    opacity: 1;
}

.resize-handle-right {
    right: -4px;
    top: 50%;
    transform: translateY(-50%);
    width: 8px;
    height: 24px;
    cursor: ew-resize;
}

.resize-handle-bottom {
    bottom: -4px;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 8px;
    cursor: ns-resize;
}

.resize-handle-corner {
    right: -4px;
    bottom: -4px;
    width: 12px;
    height: 12px;
    cursor: nwse-resize;
    border-radius: 50%;
}

/* ===== Properties Panel ===== */

/* Properties header layout */
.properties-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.properties-section {
    padding: 1rem;
}

.properties-section h4 {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--color-border);
}

.property-group {
    margin-bottom: 1rem;
}

.property-group > label {
    display: block;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.property-group input[type="text"],
.property-group input[type="number"],
.property-group textarea,
.property-group select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-bg);
}

.property-group textarea {
    resize: vertical;
    min-height: 60px;
}

.position-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.input-group label {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
}

.small-input {
    width: 100%;
    padding: 0.375rem 0.5rem;
    font-size: 0.875rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    background: var(--color-bg);
}

.checkbox-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    cursor: pointer;
}

.checkbox-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.property-actions {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--color-border);
}

/* ===== Preview Area ===== */

.preview-area {
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    padding: 1.5rem;
}

.preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.preview-header h4 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    margin: 0;
}

.preview-strip {
    background: #1a1a1a;
    border-radius: 12px;
    padding: 1rem;
    min-height: 200px;
}

/* Theme-specific preview backgrounds */
.preview-strip.theme-light {
    background: #f5f5f5;
}

.preview-strip.theme-cat {
    background: #0a1628;
}

/* ===== Modal Overrides for Designer ===== */

.template-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 400px;
    overflow-y: auto;
}

.template-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.template-list-item:hover {
    border-color: var(--color-primary);
    background: var(--color-surface);
}

.template-list-item.selected {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.template-list-item-info h4 {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.template-list-item-info p {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    margin: 0;
}

.template-list-item-badge {
    font-size: 0.625rem;
    font-weight: 600;
    text-transform: uppercase;
    padding: 0.25rem 0.5rem;
    background: var(--color-primary);
    color: white;
    border-radius: 4px;
}

/* Custom Block Modal Tabs */
.custom-block-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 0.5rem;
}

.tab-btn {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    background: transparent;
    color: var(--color-text-secondary);
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}

.tab-btn:hover {
    background: var(--color-bg);
}

.tab-btn.active {
    background: var(--color-primary);
    color: white;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.code-editor {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8125rem;
    line-height: 1.5;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    padding: 1rem;
    resize: vertical;
}

/* ===== Responsive Adjustments ===== */

@media (max-width: 1400px) {
    .designer-sidebar {
        width: 240px;
        min-width: 240px;
    }

    .designer-sidebar.properties-panel {
        width: 260px;
        min-width: 260px;
    }
}

@media (max-width: 1200px) {
    .canvas-grid {
        min-width: 900px;
    }

    .designer-sidebar {
        width: 220px;
        min-width: 220px;
    }

    .designer-sidebar.properties-panel {
        width: 240px;
        min-width: 240px;
    }
}

@media (max-width: 992px) {
    /* On smaller screens, sidebars start collapsed */
    .designer-sidebar {
        width: 200px;
        min-width: 200px;
    }

    .designer-sidebar.properties-panel {
        width: 200px;
        min-width: 200px;
    }

    .block-list {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .block-item {
        flex: 0 0 auto;
        width: 160px;
    }
}

/* ===== Utility Classes ===== */

.btn-full-width {
    width: 100%;
}

.btn-small {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn.danger {
    color: #ef4444;
    border-color: #ef4444;
}

.btn.danger:hover {
    background: #ef4444;
    color: white;
}

/* ===== Toast Notifications ===== */

.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    padding: 12px 20px;
    border-radius: 8px;
    color: white;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    animation: toastSlideIn 0.3s ease-out;
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: auto;
}

.toast.success {
    background: #10b981;
}

.toast.error {
    background: #ef4444;
}

.toast.warning {
    background: #f59e0b;
}

.toast i {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

@keyframes toastSlideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes toastSlideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* ===== Apply to TV Modal ===== */

.tv-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 400px;
    overflow-y: auto;
}

.tv-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.tv-list-item:hover {
    border-color: var(--color-primary);
    background: rgba(59, 130, 246, 0.05);
}

.tv-list-item.active {
    border-color: var(--color-primary);
    background: rgba(59, 130, 246, 0.1);
}

.tv-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tv-name {
    font-weight: 600;
    font-size: 0.9375rem;
    color: var(--color-text);
}

.tv-details {
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
}

.tv-current-template {
    font-size: 0.8125rem;
    color: #10b981;
    font-weight: 500;
}

.tv-list-loading,
.tv-list-error {
    padding: 2rem;
    text-align: center;
    color: var(--color-text-secondary);
}

.tv-list-error {
    color: var(--color-error, #ef4444);
}

.modal-description {
    margin-bottom: 1rem;
    color: var(--color-text-secondary);
}

.empty-state-small {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
    color: var(--color-text-secondary);
    gap: 0.75rem;
}

.empty-state-small i,
.empty-state-small svg {
    width: 48px;
    height: 48px;
    opacity: 0.5;
}

/* ===== GridStack Integration Styles ===== */

/* Grid container wrapper - holds both header and grid at fixed width */
.grid-container-wrapper {
    display: flex;
    flex-direction: column;
    width: fit-content;
    margin: 0 auto;  /* Center in canvas-wrapper */
}

/* Column numbers header - clamped to top of grid */
.column-numbers-header {
    display: flex;
    padding: 4px 0;
    margin: 0;
    background: rgba(248, 250, 252, 0.98);
    border: 2px solid var(--color-border);
    border-bottom: 1px solid var(--color-border);
    border-radius: 12px 12px 0 0;
    position: relative;
    z-index: 10;
    /* Match exact grid width - set by JS inline style */
}

.column-numbers-header .grid-column-number {
    flex: 1;
    text-align: center;
    font-size: 9px;
    font-weight: 500;
    color: var(--color-text-secondary);
    user-select: none;
}

/* GridStack container styling */
.grid-stack {
    background: var(--color-surface);
    border: 2px solid var(--color-border);
    border-top: none;
    border-radius: 0 0 12px 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    /* Height is set dynamically by JS based on row count - do not use min-height here */
    /* Grid background pattern - 2.5% columns (100%/40), row height set by GridStack */
    background-image:
        linear-gradient(to right, rgba(128, 128, 128, 0.15) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(128, 128, 128, 0.15) 1px, transparent 1px);
    background-size: 2.5% var(--gs-cell-height, 33px);
    background-position: 0 0;
}

/* GridStack widget (block) styling */
/* Use higher specificity to override gridstack.min.css */
.grid-stack > .grid-stack-item > .grid-stack-item-content {
    background: #ffffff !important;
    border: 1px solid #3b82f6 !important;  /* Blue stroke on all blocks */
    border-radius: 6px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: move;
    transition: border-color 0.2s, box-shadow 0.2s, opacity 0.2s;
    overflow: hidden;
    opacity: 0.85 !important;  /* 85% opacity at rest */
}

.grid-stack > .grid-stack-item > .grid-stack-item-content:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Selected widget state */
.grid-stack > .grid-stack-item.selected > .grid-stack-item-content {
    opacity: 1 !important;  /* Fully opaque when selected */
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.4) !important;
    border-width: 2px !important;
}

/* Dragging state - override GridStack's default opacity */
.grid-stack > .grid-stack-item.ui-draggable-dragging > .grid-stack-item-content {
    opacity: 0.9 !important;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2) !important;
}

/* Resizing state */
.grid-stack > .grid-stack-item.ui-resizable-resizing > .grid-stack-item-content {
    opacity: 0.9 !important;
    border-color: #3b82f6 !important;
}

/* Block content inside GridStack widget */
.block-content {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    height: 100%;
    padding: 4px;
    text-align: center;
    position: relative !important;  /* For alignment indicator positioning */
    overflow: visible !important;   /* Allow accent to show */
}

/* Alignment indicator accent line using pseudo-element */
/* Left alignment - vertical accent on left edge, content aligned left */
.block-content[data-alignment="leading"] {
    justify-content: flex-start !important;
    padding-left: 10px !important;
}
.block-content[data-alignment="leading"]::before {
    content: '';
    position: absolute;
    left: 3px;
    top: 20%;
    width: 3px;
    height: 60%;
    background: #3b82f6;
    opacity: 0.6;
    border-radius: 2px;
    pointer-events: none;
    z-index: 10;
}

/* Center alignment - horizontal accent at top center, content centered */
.block-content[data-alignment="center"] {
    justify-content: center !important;
}
.block-content[data-alignment="center"]::before {
    content: '';
    position: absolute;
    left: 30%;
    top: 3px;
    width: 40%;
    height: 3px;
    background: #3b82f6;
    opacity: 0.6;
    border-radius: 2px;
    pointer-events: none;
    z-index: 10;
}

/* Right alignment - vertical accent on right edge, content aligned right */
.block-content[data-alignment="trailing"] {
    justify-content: flex-end !important;
    padding-right: 10px !important;
}
.block-content[data-alignment="trailing"]::before {
    content: '';
    position: absolute;
    right: 3px;
    top: 20%;
    width: 3px;
    height: 60%;
    background: #3b82f6;
    opacity: 0.6;
    border-radius: 2px;
    pointer-events: none;
    z-index: 10;
}

/* Brighter accent on hover/selection */
.grid-stack-item:hover .block-content[data-alignment]::before,
.grid-stack-item.selected .block-content[data-alignment]::before {
    opacity: 1;
}

.block-icon {
    font-size: 1rem;
    flex-shrink: 0;
}

.block-name {
    font-size: 0.625rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

/* GridStack placeholder (drop target) - hidden */
.grid-stack-placeholder {
    display: none !important;
}

/* GridStack resize handles - custom styling */
.grid-stack-item > .ui-resizable-handle {
    background: transparent;
}

.grid-stack-item > .ui-resizable-se,
.grid-stack-item > .ui-resizable-e,
.grid-stack-item > .ui-resizable-s {
    opacity: 0;
    transition: opacity 0.2s;
}

.grid-stack-item:hover > .ui-resizable-se,
.grid-stack-item:hover > .ui-resizable-e,
.grid-stack-item:hover > .ui-resizable-s,
.grid-stack-item.selected > .ui-resizable-se,
.grid-stack-item.selected > .ui-resizable-e,
.grid-stack-item.selected > .ui-resizable-s {
    opacity: 1;
}

/* Corner resize handle */
.grid-stack-item > .ui-resizable-se {
    width: 16px !important;
    height: 16px !important;
    background: var(--color-primary);
    border-radius: 50%;
    right: 2px !important;
    bottom: 2px !important;
}

/* Right edge resize handle */
.grid-stack-item > .ui-resizable-e {
    width: 8px !important;
    right: 0 !important;
    background: linear-gradient(to left, var(--color-primary), transparent);
    border-radius: 0 8px 8px 0;
}

/* Bottom edge resize handle */
.grid-stack-item > .ui-resizable-s {
    height: 8px !important;
    bottom: 0 !important;
    background: linear-gradient(to top, var(--color-primary), transparent);
    border-radius: 0 0 8px 8px;
}

/* Drag helper from palette */
.ui-draggable-dragging.block-item {
    z-index: 10000 !important;
    opacity: 0.8;
    background: var(--color-surface);
    border: 2px solid var(--color-primary);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}
