/* === Builder gateway (Apollo-style) === */

.fwd-gw-overlay {
    position: fixed;
    inset: 0;
    z-index: 11000;
    background: rgba(0, 0, 0, 0.78);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.fwd-gw-dialog {
    width: min(900px, 100%);
    max-height: min(760px, 100%);
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 18px;
    box-shadow: var(--shadow-modal);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.fwd-gw-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 24px 12px;
    border-bottom: 1px solid var(--border-color);
}

.fwd-gw-header h2 {
    margin: 0 0 6px;
    font-size: 20px;
    color: #fff;
}

.fwd-gw-header p {
    margin: 0;
    font-size: 13px;
    color: var(--text-muted);
}

.fwd-gw-close,
.fwd-gw-back {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    padding: 8px 14px;
    font-size: 13px;
    cursor: pointer;
    flex-shrink: 0;
}

.fwd-gw-close:hover,
.fwd-gw-back:hover {
    border-color: var(--primary-color);
    color: #fff;
}

.fwd-gw-back {
    align-self: flex-start;
    margin-bottom: 12px;
}

.fwd-gw-body {
    padding: 20px 24px 24px;
    overflow-y: auto;
}

.fwd-gw-choice-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}

.fwd-gw-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-align: left;
    background: rgba(255, 255, 255, 0.045);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px 18px;
    cursor: pointer;
    transition: transform 0.15s var(--ease), border-color 0.15s var(--ease), background 0.15s var(--ease);
}

.fwd-gw-card:hover {
    transform: translateY(-2px);
    border-color: var(--primary-color);
    background: rgba(var(--primary-rgb), 0.16);
}

.fwd-gw-card-title {
    font-size: 15px;
    font-weight: 600;
    color: #fff;
}

.fwd-gw-card-desc {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.45;
}

.fwd-gw-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 20px;
    margin-bottom: 16px;
    font-size: 12px;
    color: var(--text-muted);
}

.fwd-gw-legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.fwd-gw-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: 4px;
    border: 1px solid transparent;
}

.fwd-gw-badge.commander {
    color: #4ade80;
    background: rgba(34, 197, 94, 0.14);
    border-color: rgba(34, 197, 94, 0.35);
}

.fwd-gw-badge.master {
    color: #ffce3a;
    background: rgba(255, 206, 58, 0.12);
    border-color: rgba(255, 206, 58, 0.35);
}

.fwd-gw-badge.manager {
    color: #c4b5fd;
    background: rgba(var(--primary-rgb), 0.18);
    border-color: rgba(var(--primary-rgb), 0.4);
}

.fwd-gw-badge.any {
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--border-color);
}

.fwd-gw-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 14px;
}

.fwd-gw-tpl-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
    text-align: left;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 14px;
    cursor: pointer;
    transition: border-color 0.15s var(--ease);
}

.fwd-gw-tpl-card:hover {
    border-color: var(--primary-color);
}

.fwd-gw-preview {
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: linear-gradient(180deg, rgba(55, 55, 60, 0.9) 0%, rgba(40, 40, 45, 0.9) 100%);
    border-radius: var(--radius-md);
    padding: 8px;
    min-height: 72px;
}

.fwd-gw-preview-row {
    display: flex;
    gap: 3px;
    flex: 1;
    min-height: 14px;
}

.fwd-gw-preview-cell {
    border-radius: 3px;
    min-height: 12px;
}

.fwd-gw-tpl-title {
    font-size: 14px;
    font-weight: 600;
    color: #fff;
}

.fwd-gw-tpl-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 4px 0;
}

.fwd-gw-cat {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.06);
    padding: 2px 7px;
    border-radius: 4px;
}

.fwd-gw-tpl-desc {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.4;
}

.fwd-gw-existing-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.fwd-gw-existing-row {
    display: flex;
    align-items: stretch;
    gap: 8px;
}

.fwd-gw-existing-main {
    flex: 1;
    text-align: left;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    cursor: pointer;
}

.fwd-gw-existing-main:hover {
    border-color: var(--primary-color);
}

.fwd-gw-existing-title {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
}

.fwd-gw-existing-desc {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.fwd-gw-del {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--danger-color);
    padding: 0 14px;
    cursor: pointer;
}

.fwd-gw-del:hover {
    border-color: var(--danger-color);
}

.fwd-gw-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 32px 16px;
    font-size: 14px;
}

/* === Full-screen designer overlay === */

.fwd-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    flex-direction: column;
}

/* The widget settings modal opens from inside the full-screen builder, so it
   must sit above the builder overlay (10000) and gateway (11000) - otherwise
   the cog appears to "do nothing" because the modal is hidden behind them. */
.modal-overlay.fwd-widget-cfg-overlay {
    z-index: 11500;
}

.fwd-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

.fwd-topbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.04);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.fwd-layout-select,
.fwd-layout-name {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: #fff;
    padding: 8px 12px;
    font-size: 13px;
}

.fwd-layout-select {
    min-width: 160px;
}

.fwd-layout-name {
    min-width: 180px;
    font-weight: 600;
}

.fwd-topbar-spacer {
    flex: 1;
}

.fwd-secondary-btn,
.fwd-cancel-btn,
.fwd-save-btn {
    border-radius: var(--radius-md);
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--border-color);
}

.fwd-secondary-btn {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary);
}

.fwd-secondary-btn:hover {
    border-color: var(--border-light);
    color: #fff;
}

.fwd-cancel-btn {
    background: transparent;
    color: var(--text-muted);
}

.fwd-save-btn {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: #fff;
}

.fwd-save-btn:hover {
    filter: brightness(1.08);
}

.fwd-body {
    display: flex;
    flex: 1;
    min-height: 0;
}

.fwd-palette {
    width: 196px;
    flex-shrink: 0;
    border-right: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.02);
    overflow-y: auto;
    padding: 12px 10px;
}

.fwd-palette-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 10px;
    padding: 0 4px;
}

.fwd-palette-section {
    margin-bottom: 14px;
}

.fwd-palette-cat {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    margin-bottom: 6px;
    padding: 0 4px;
}

.fwd-palette-item {
    padding: 8px 10px;
    margin-bottom: 4px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid transparent;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: grab;
    user-select: none;
}

.fwd-palette-item:hover {
    border-color: var(--primary-color);
    color: #fff;
    background: rgba(var(--primary-rgb), 0.12);
}

.fwd-palette-item:active {
    cursor: grabbing;
}

.fwd-canvas-area {
    flex: 1;
    min-width: 0;
    padding: 16px;
    overflow: auto;
    display: flex;
    justify-content: center;
}

.fwd-canvas {
    width: 100%;
    max-width: 1100px;
    min-height: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.fwd-empty-msg {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    color: var(--text-muted);
    font-size: 14px;
    min-height: 200px;
}

.fwd-empty-msg.drag-over {
    border-color: var(--primary-color);
    background: rgba(var(--primary-rgb), 0.1);
}

.fwd-row {
    position: relative;
    display: flex;
    flex-direction: column;
    flex-basis: 0;
    flex-shrink: 1;
    min-height: 100px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-lg);
    background: rgba(255, 255, 255, 0.02);
    padding: 8px 8px 14px;
}

.fwd-row:hover .fwd-row-toolbar {
    opacity: 1;
}

.fwd-row-toolbar {
    position: absolute;
    top: 6px;
    right: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 2;
}

.fwd-row-grip {
    color: var(--text-muted);
    font-size: 12px;
    letter-spacing: -2px;
}

.fwd-icon-btn {
    width: 24px;
    height: 24px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--danger-color);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
}

.fwd-row-cols {
    position: relative;
    display: flex;
    flex: 1;
    gap: 0;
    min-height: 0;
    align-items: stretch;
    padding-top: 20px;
}

.fwd-col-shell {
    display: flex;
    min-width: 0;
    align-items: stretch;
}

.fwd-col {
    position: relative;
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: var(--radius-md);
    padding: 8px;
    min-height: 60px;
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
    border: 1px dashed transparent;
}

.fwd-col.drag-over {
    border-color: var(--primary-color);
    background: rgba(var(--primary-rgb), 0.12);
}

.fwd-col.drop-split-left {
    box-shadow: inset 3px 0 0 var(--primary-color);
}

.fwd-col.drop-split-right {
    box-shadow: inset -3px 0 0 var(--primary-color);
}

/* Where a dragged widget will land: a line between widgets, or a vertical bar
   on the edge that will be split into a new column. */
.fwd-drop-indicator {
    height: 3px;
    margin: 2px 0;
    border-radius: 2px;
    background: var(--primary-color);
    box-shadow: 0 0 6px rgba(var(--primary-rgb), 0.8);
    pointer-events: none;
}

.fwd-drop-indicator.vertical {
    position: absolute;
    top: 6px;
    bottom: 6px;
    width: 3px;
    height: auto;
    margin: 0;
}

/* Alignment guide shown while resizing a column near a boundary above/below. */
.fwd-snap-guide {
    position: absolute;
    top: 20px;
    bottom: 0;
    width: 0;
    border-left: 2px dashed var(--primary-color);
    transform: translateX(-1px);
    opacity: 0;
    pointer-events: none;
    z-index: 3;
}

.fwd-snap-guide.visible {
    opacity: 1;
}

.fwd-drop-placeholder {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: var(--text-muted);
    min-height: 48px;
}

.fwd-col-resize {
    width: 12px;
    flex-shrink: 0;
    cursor: col-resize;
    align-self: stretch;
    margin: 0 2px;
    border-radius: 4px;
}

.fwd-col-resize:hover {
    background: rgba(var(--primary-rgb), 0.35);
}

.fwd-row-resize {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 0;
    height: 8px;
    cursor: row-resize;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.fwd-row-resize:hover {
    background: rgba(var(--primary-rgb), 0.35);
}

.fwd-add-col,
.fwd-add-row {
    align-self: center;
    background: transparent;
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
}

.fwd-add-col {
    width: 28px;
    height: 28px;
    padding: 0;
    margin-left: 4px;
    flex-shrink: 0;
    align-self: center;
}

.fwd-add-col:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.fwd-add-row {
    margin-top: 4px;
}

.fwd-add-col:hover:not(:disabled),
.fwd-add-row:hover {
    border-color: var(--primary-color);
    color: #fff;
}

/* A placed widget: a live preview of the real widget with a slim builder
   control strip (drag / settings / remove) beneath it. */
.fwd-widget {
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 110px;
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.fwd-widget.dragging {
    outline: 2px dashed var(--primary-color);
    outline-offset: -2px;
}

.fwd-widget-preview {
    flex: 1;
    min-height: 0;
    display: flex;
    padding: 6px;
    overflow: hidden;
    /* The live widget is a non-interactive preview; drags and clicks belong to
       the builder tile and its control strip, not the widget inside. */
    pointer-events: none;
}

.fwd-widget-preview > .fw {
    pointer-events: none;
}

.fwd-widget-preview-note {
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
}

.fwd-widget-chrome {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    background: rgba(0, 0, 0, 0.35);
    border-top: 1px solid var(--border-color);
}

.fwd-widget-grip {
    color: var(--text-muted);
    font-size: 10px;
    letter-spacing: -2px;
    cursor: grab;
}

.fwd-widget-grip:active {
    cursor: grabbing;
}

.fwd-widget-type {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.fwd-widget-edit,
.fwd-widget-del {
    width: 22px;
    height: 22px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-panel);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
    flex-shrink: 0;
}

.fwd-widget-edit:hover {
    border-color: var(--primary-color);
    color: #fff;
}

.fwd-widget-del:hover {
    border-color: var(--danger-color);
    color: var(--danger-color);
}

/* Floating clone that follows the finger during a touch drag. */
.fwd-touch-ghost {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 12000;
    pointer-events: none;
    opacity: 0.85;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    transform: scale(0.98);
}

body.fwd-resizing {
    user-select: none;
}

@media (max-width: 768px) {
    .fwd-gw-choice-grid {
        grid-template-columns: 1fr;
    }

    .fwd-body {
        flex-direction: column;
    }

    .fwd-palette {
        width: 100%;
        max-height: 140px;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .fwd-row-cols {
        flex-direction: column;
    }

    .fwd-col-shell {
        flex: none !important;
        width: 100%;
    }

    .fwd-col-resize {
        display: none;
    }
}
