/* ============================================================
   Canvas / Smart Board — Standalone CSS Module
   Covers: workspace layout, feed grid, cards, card types,
           single-page-view, expanded overlay, drag & drop
   ============================================================ */

/* ── Workspace Canvas Scroll Container ────────────────────── */
.workspace-canvas-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px;
    position: relative;
    container-type: inline-size;
    container-name: boardPanel;
}

.panel-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    scroll-behavior: smooth;
    position: relative;
    container-type: inline-size;
    container-name: boardPanel;
}

/* ── Empty State ──────────────────────────────────────────── */
.empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-3);
    opacity: 0.7;
    width: 100%;
}

/* ── Feed Grid ────────────────────────────────────────────── */
.feed-grid {
    display: grid;
    grid-template-columns: 1fr;
    /* mobile-first: single column */
    gap: 12px;
    align-items: start;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    position: relative;
}

/* On narrow canvas containers force strict single-column feed
   to prevent card overlap/overflow when cards request wide spans. */
@container boardPanel (max-width: 760px) {
    .feed-grid:not(.single-page-view):not(.single-card-view) {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }

    .feed-grid .feed-card.card-span-2,
    .feed-grid .feed-card.card-span-wide {
        grid-column: auto;
    }
}

/* Multi-column when container is wide enough */
@container boardPanel (min-width: 540px) {
    .feed-grid:not(.single-page-view):not(.single-card-view) {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
        gap: 16px;
    }
}

@container boardPanel (min-width: 900px) {
    .feed-grid:not(.single-page-view):not(.single-card-view) {
        grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
    }
}

/* Card spanning helpers (grid mode only) */
.feed-card.card-span-2 {
    grid-column: span 2;
}

.feed-card.card-span-wide {
    grid-column: 1 / -1;
}

/* User-toggled multi-column */
.feed-grid.multi-column:not(.single-page-view):not(.single-card-view) {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)) !important;
    gap: 16px !important;
}

/* ── Single Page View — multiple cards, vertical stack ───── */
/* Category selected with 2+ cards: clean stacked list */
.feed-grid.single-page-view {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Cards in page view stay normal — just stacked */
.feed-grid.single-page-view .feed-card {
    /* inherits normal card styles */
}

/* ── Single Card View — one card fills the whole panel ───── */
/* Category selected with exactly 1 card: immersive full-screen */
.workspace-canvas-scroll.single-card-view-panel,
.panel-content.single-card-view-panel {
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.feed-grid.single-card-view {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    gap: 0;
}

.feed-grid.single-card-view .feed-card {
    flex: 1;
    min-height: 0;
    border-radius: 0;
    border: none;
    border-bottom: none;
    box-shadow: none;
    animation: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0;
    background: var(--bg-primary);
}

.feed-grid.single-card-view .card-header {
    padding: 14px 20px;
    margin-bottom: 0;
    border-bottom: 1px solid var(--surface-border);
    background: var(--surface-1);
    flex-shrink: 0;
}

/* All direct content children fill remaining space */
.feed-grid.single-card-view .feed-card>.task-list,
.feed-grid.single-card-view .feed-card>.doc-content,
.feed-grid.single-card-view .feed-card>.data-table-wrapper,
.feed-grid.single-card-view .feed-card>.workflow-steps,
.feed-grid.single-card-view .feed-card>.store-grid,
.feed-grid.single-card-view .feed-card>.image-widget,
.feed-grid.single-card-view .feed-card>.html-widget {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px 20px;
    box-sizing: border-box;
}

/* iframes take all space */
.feed-grid.single-card-view .feed-card>.html-widget-iframe,
.feed-grid.single-card-view .feed-card>.iframe-widget {
    flex: 1;
    height: auto;
    min-height: 0;
    border-radius: 0;
    display: block;
}

/* Override doc-content styling for full-screen — strip card chrome */
.feed-grid.single-card-view .doc-content {
    border-radius: 0;
    border: none;
    border-right: none;
    background: transparent;
}

/* task-add-row stays at bottom, not scrolled */
.feed-grid.single-card-view .feed-card>.task-add-row {
    flex-shrink: 0;
    padding: 12px 20px;
    border-top: 1px solid var(--surface-border);
    background: var(--surface-1);
}

/* Actions at bottom */
.feed-grid.single-card-view .feed-card>.card-actions {
    flex-shrink: 0;
    margin: 0;
    padding: 12px 20px;
    border-top: 1px solid var(--surface-border);
    background: var(--surface-1);
}

/* Image widget — centered */
.feed-grid.single-card-view .image-widget {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.feed-grid.single-card-view .image-widget img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* ── Feed Card Base ───────────────────────────────────────── */
.feed-card {
    background: var(--surface-3);
    border: 1px solid var(--surface-border);
    border-radius: var(--r-xl);
    padding: 20px;
    backdrop-filter: blur(12px);
    box-shadow: var(--shadow-sm);
    animation: cardPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    transition: transform 0.3s, border-color 0.3s;
    min-width: 0;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.feed-card:hover {
    border-color: var(--surface-border-hover);
    transform: translateY(-2px);
}

/* Smooth transitions for drag */
.feed-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

/* ── Expanded Overlay ─────────────────────────────────────── */
.feed-card.expanded-overlay {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    z-index: 100 !important;
    margin: 0 !important;
    border-radius: 0 !important;
    max-width: none !important;
    max-height: none !important;
    background: var(--surface-1) !important;
    overflow-y: auto !important;
}

.feed-card.expanded-overlay .html-widget-iframe,
.feed-card.expanded-overlay .iframe-widget,
.feed-card.expanded-overlay .image-widget img {
    height: calc(100vh - 120px) !important;
    max-height: none !important;
}

.feed-card.expanded-overlay .doc-content {
    max-height: none !important;
}

/* ── Card Header ──────────────────────────────────────────── */
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
    gap: 10px;
}

.card-title {
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1.3;
}

/* ── Card Badges ──────────────────────────────────────────── */
.card-badge {
    font-size: 0.7rem;
    padding: 4px 10px;
    border-radius: 12px;
    font-weight: 700;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.badge-finance {
    background: rgba(34, 197, 94, 0.15);
    color: #4ade80;
}

.badge-task {
    background: rgba(245, 158, 11, 0.15);
    color: #fbbf24;
}

.badge-doc {
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
}

.badge-default {
    background: var(--surface-border);
    color: var(--text-2);
}

.badge-app {
    background: rgba(99, 102, 241, 0.15);
    color: #818cf8;
}

.badge-flow {
    background: rgba(245, 158, 11, 0.15);
    color: #fbbf24;
}

.badge-db {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
}

/* ── Card Content: Tasks ──────────────────────────────────── */
.task-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.task-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 12px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: var(--r-md);
    transition: 0.2s;
    border: 1px solid transparent;
}

.task-item:hover {
    background: rgba(0, 0, 0, 0.3);
    border-color: var(--surface-border);
}

.task-checkbox {
    width: 20px;
    height: 20px;
    border: 2px solid var(--text-3);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
    margin-top: 2px;
    flex-shrink: 0;
}

.task-item.done .task-checkbox {
    background: var(--success);
    border-color: var(--success);
}

.task-item.done .task-checkbox::after {
    content: '✓';
    color: white;
    font-size: 12px;
    font-weight: bold;
}

.task-item.done span {
    text-decoration: line-through;
    opacity: 0.5;
}

/* Task enhancements */
.task-item:hover .remove-task-btn {
    opacity: 1 !important;
}

.task-add-row input::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
}

.task-add-row input:focus {
    border-bottom: 1px solid var(--primary-color);
    outline: none !important;
}

/* ── Card Content: Data Table ─────────────────────────────── */
.data-table-wrapper {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.data-table th,
.data-table td {
    padding: 8px 10px;
    text-align: right;
    border-bottom: 1px solid var(--surface-border);
}

.data-table th {
    color: var(--text-3);
    font-weight: 500;
    white-space: nowrap;
}

/* ── Card Content: Document ───────────────────────────────── */
.doc-content {
    font-size: 0.95rem;
    line-height: 1.6;
    background: rgba(0, 0, 0, 0.15);
    padding: 16px;
    border-radius: var(--r-md);
    border-right: 3px solid var(--accent-1);
    overflow-x: auto;
    max-width: 100%;
}

.doc-content code,
.doc-content pre {
    max-width: 100%;
    overflow-x: auto;
    word-break: break-all;
}

/* ── Card Content: HTML / Iframe ──────────────────────────── */
.html-widget {
    background: var(--surface-1);
    padding: 12px;
    border-radius: var(--r-md);
    overflow: hidden;
}

.html-widget-iframe {
    width: 100%;
    min-height: 250px;
    border: none;
    border-radius: 8px;
    background: transparent;
}

.iframe-widget {
    width: 100%;
    height: 300px;
    border: none;
    border-radius: var(--r-md);
    background: #fff;
}

/* ── Card Content: Store / Product Grid ───────────────────── */
.store-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 12px;
}

.store-product {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 14px 8px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: var(--r-md);
    border: 1px solid transparent;
    transition: 0.2s;
    text-align: center;
}

.store-product:hover {
    background: rgba(0, 0, 0, 0.3);
    border-color: var(--surface-border);
}

.product-icon {
    font-size: 1.8rem;
}

.product-name {
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.3;
}

.product-price {
    font-size: 0.8rem;
    color: #4ade80;
    font-weight: 700;
}

/* ── Card Content: Workflow Steps ─────────────────────────── */
.workflow-steps {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.workflow-step {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--r-md);
    transition: 0.2s;
    position: relative;
}

.workflow-step:not(:last-child)::after {
    content: '';
    position: absolute;
    right: 25px;
    top: 38px;
    bottom: -14px;
    width: 2px;
    background: var(--surface-border);
}

.step-indicator {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    flex-shrink: 0;
    background: var(--surface-border);
    color: var(--text-2);
    z-index: 1;
}

.step-done .step-indicator {
    background: rgba(34, 197, 94, 0.2);
    color: #4ade80;
}

.step-active .step-indicator {
    background: rgba(59, 130, 246, 0.2);
    color: #60a5fa;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.step-body {
    flex: 1;
    min-width: 0;
}

.step-title {
    font-weight: 600;
    font-size: 0.9rem;
}

.step-desc {
    font-size: 0.8rem;
    color: var(--text-3);
    margin-top: 2px;
}

.step-done .step-title {
    color: var(--text-3);
}

.step-pending .step-title {
    color: var(--text-2);
}

/* ── Card Actions ─────────────────────────────────────────── */
.card-actions {
    margin-top: 16px;
    display: flex;
    gap: 8px;
    padding-top: 16px;
    border-top: 1px solid var(--surface-border);
    flex-wrap: wrap;
}

.card-btn {
    flex: 1;
    min-width: 100px;
    padding: 8px 12px;
    border-radius: var(--r-sm);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: 0.2s;
    font-family: var(--font-hebrew);
}

.card-btn.primary {
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent-2);
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.card-btn.primary:hover {
    background: rgba(59, 130, 246, 0.25);
}

.card-btn.secondary {
    background: var(--surface-2);
    color: var(--text-1);
    border: 1px solid var(--surface-border);
}

.card-btn.secondary:hover {
    background: var(--surface-border-hover);
}

.card-btn.loading {
    opacity: 0.7;
    pointer-events: none;
    cursor: wait;
}

/* ── Mini App: Storefront / Forms ─────────────────────────── */
.store-app {
    background: #ffffff;
    color: #111;
    border-radius: 12px;
    padding: 16px;
    font-family: sans-serif;
}

.store-header {
    text-align: center;
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
}

/* Store grid (storefront variant) */
.store-app .store-grid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.product-card {
    border: 1px solid #eee;
    border-radius: 8px;
    padding: 12px;
    text-align: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.product-img {
    width: 100%;
    height: 80px;
    background: #f4f4f5;
    border-radius: 6px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
}

.product-title {
    font-weight: bold;
    font-size: 0.9rem;
    margin-bottom: 5px;
}

/* Storefront price override (blue in store context) */
.store-app .product-price {
    color: #2563eb;
    font-weight: bold;
    margin-bottom: 10px;
}

.buy-btn {
    background: #0f172a;
    color: white;
    border: none;
    padding: 8px;
    width: 100%;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    font-size: 0.8rem;
}

.buy-btn:hover {
    background: #333;
}

/* ── Mini App: Workflow Diagram ───────────────────────────── */
.workflow-diagram {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
}

.flow-node {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--btn-subtle-bg);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

.flow-icon {
    font-size: 1.5rem;
}

.flow-text h4 {
    font-size: 0.9rem;
    margin: 0;
}

.flow-text p {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 0;
}

.flow-arrow {
    text-align: center;
    color: var(--accent-gradient);
    font-size: 1.2rem;
    margin: -5px 0;
}

/* ── Database UI ──────────────────────────────────────────── */
.db-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.db-table th {
    text-align: right;
    padding: 8px;
    color: var(--text-muted);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.db-table td {
    padding: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-family: monospace;
}

.live-pulse {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
    animation: pulse 1.5s infinite;
    margin-left: 5px;
}

/* ── Agent Process Checklist ──────────────────────────────── */
.agent-process {
    margin-top: 10px;
    font-size: 0.85rem;
    color: var(--text-2);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.agent-step {
    display: flex;
    align-items: center;
    gap: 8px;
}

.agent-step.done {
    color: var(--success);
}

.agent-step.active {
    color: var(--text-1);
    font-weight: 500;
}

/* ── Feed Filters ─────────────────────────────────────────── */
.feed-filters {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    padding: 4px;
    border-radius: 12px;
}

.filter-tab {
    color: var(--text-3);
    cursor: pointer;
    font-weight: 500;
    padding: 6px 16px;
    border-radius: 8px;
    transition: 0.2s;
    font-size: 0.85rem;
}

.filter-tab:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-2);
}

.filter-tab.active {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-1);
}

/* ── Drag & Drop ──────────────────────────────────────────── */
.card-ghost {
    opacity: 0.4;
    border: 2px dashed var(--primary-color, var(--accent-1)) !important;
    background: transparent !important;
}

.card-ghost * {
    visibility: hidden;
}

.card-drag-target {
    border-top: 3px solid var(--primary-color, var(--accent-1)) !important;
    margin-top: 10px;
    transition: all 0.2s;
}

.drag-handle {
    cursor: grab;
    user-select: none;
    padding-right: 4px;
    color: var(--text-2);
}

.drag-handle:active {
    cursor: grabbing;
}

/* Editable title styles */
.card-title[contenteditable="true"] {
    cursor: text;
    border: 1px solid transparent;
}

.card-title[contenteditable="true"]:hover {
    border: 1px solid var(--border-light);
    background: rgba(255, 255, 255, 0.05);
}

.card-title[contenteditable="true"]:focus {
    border: 1px solid var(--primary-color, var(--accent-1));
    background: rgba(0, 136, 204, 0.1);
    outline: none;
}

.edit-title-icon {
    font-size: 14px;
    padding: 2px 6px;
}

.edit-title-icon:hover {
    opacity: 1 !important;
    transform: scale(1.1);
}

.card-delete-btn:hover {
    opacity: 1 !important;
    color: #ff4444 !important;
    transform: scale(1.1);
}

/* ── Animations ───────────────────────────────────────────── */
@keyframes cardPop {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(20px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-3px);
    }
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4);
    }

    70% {
        box-shadow: 0 0 0 6px rgba(16, 185, 129, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

.highlight-update {
    animation: highlight-pulse 2s ease-out;
}

@keyframes highlight-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(167, 139, 250, 0.6);
        border-color: var(--accent-1);
    }

    50% {
        box-shadow: 0 0 0 10px rgba(167, 139, 250, 0);
        border-color: var(--accent-2);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(167, 139, 250, 0);
    }
}

/* ── Mobile Overrides ─────────────────────────────────────── */
@media (max-width: 899px) {
    .workspace-canvas-scroll:not(.single-card-view-panel) {
        padding: 16px;
    }
}

/* ── Image Gallery Grid (Pure image tiles, no card wrappers) ── */
.image-gallery-grid {
    display: grid !important;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 8px;
    padding: 0;
}

.gallery-tile {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    aspect-ratio: 1 / 1;
    background: var(--surface-2, #1a1a2e);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.gallery-tile:hover {
    transform: scale(1.03);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    z-index: 2;
}

.gallery-tile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.gallery-caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px 10px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
    color: #fff;
    font-size: 0.75em;
    font-style: italic;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.gallery-tile:hover .gallery-caption {
    opacity: 1;
}

/* ── Fullscreen Image Overlay ──────────────────────────────── */
.image-fullscreen-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0, 0, 0, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeInOverlay 0.2s ease;
    backdrop-filter: blur(8px);
}

.image-fullscreen-overlay img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 8px;
    object-fit: contain;
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.5);
}

.image-fullscreen-close {
    position: absolute;
    top: 20px;
    right: 24px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    font-size: 24px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.image-fullscreen-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

@keyframes fadeInOverlay {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Responsive: larger tiles on wider screens */
@container boardPanel (min-width: 600px) {
    .image-gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
        gap: 10px;
    }
}

@container boardPanel (min-width: 900px) {
    .image-gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
        gap: 12px;
    }
}