/**
 * Layout Manager CSS
 * Styles for drag/resize panel system.
 * Only active when .layout-freeform is on .custom-homepage.
 */

/* ============================================================
   FREEFORM CONTAINER
   ============================================================ */
.custom-homepage.layout-freeform {
    display: block !important;
    position: relative;
    min-height: 100vh;
}

/* ============================================================
   PANELS
   ============================================================ */
.layout-freeform .layout-panel {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    box-sizing: border-box;
    will-change: transform;
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    /* Remove grid-area so it doesn't conflict */
    grid-area: unset !important;
}

/* Active/hover state */
.layout-freeform .layout-panel:hover {
    border-color: rgba(0, 242, 254, 0.25);
}

/* Dragging */
.layout-panel.panel-dragging {
    box-shadow:
        0 0 0 1px rgba(0, 242, 254, 0.5),
        0 20px 60px rgba(0, 0, 0, 0.6),
        0 0 40px rgba(0, 242, 254, 0.1) !important;
    border-color: rgba(0, 242, 254, 0.5) !important;
    z-index: 9999 !important;
    transition: none;
}

/* Resizing */
.layout-panel.panel-resizing {
    border-color: rgba(0, 242, 254, 0.4) !important;
    z-index: 9999 !important;
    transition: none;
}

/* Resize handle — bottom-right corner indicator */
.layout-freeform .layout-panel::after {
    content: '';
    position: absolute;
    bottom: 4px;
    right: 4px;
    width: 10px;
    height: 10px;
    border-right: 2px solid rgba(0, 242, 254, 0.25);
    border-bottom: 2px solid rgba(0, 242, 254, 0.25);
    pointer-events: none;
    border-radius: 1px;
    opacity: 0;
    transition: opacity 0.2s;
}

.layout-freeform .layout-panel:hover::after {
    opacity: 1;
}

/* Scrollable inner content — panels need to fill their space */
.layout-freeform .layout-panel > *:not(.panel-drag-handle) {
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Specific inner scrollable areas */
.layout-freeform .crypto-grid,
.layout-freeform .news-list,
.layout-freeform #nostr-feed-list,
.layout-freeform .community-posts-grid,
.layout-freeform .watchlist-scroll-area {
    overflow-y: auto;
    overflow-x: hidden;
}

/* ============================================================
   DRAG HANDLE
   ============================================================ */
.panel-drag-handle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: rgba(0, 0, 0, 0.15);
    border-bottom: 1px solid rgba(0, 242, 254, 0.08);
    cursor: grab;
    user-select: none;
    flex-shrink: 0;
    transition: background 0.2s;
}

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

.panel-dragging .panel-drag-handle {
    cursor: grabbing;
}

.panel-handle-dots {
    display: grid;
    grid-template-columns: repeat(3, 4px);
    grid-template-rows: repeat(2, 4px);
    gap: 2px;
    flex-shrink: 0;
    opacity: 0.3;
    transition: opacity 0.2s;
}

.panel-drag-handle:hover .panel-handle-dots {
    opacity: 0.6;
}

.panel-handle-dots span {
    width: 3px;
    height: 3px;
    background: var(--color-accent-cyan);
    border-radius: 50%;
    display: block;
}

.panel-handle-label {
    font-size: 9px;
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    letter-spacing: 2px;
    color: rgba(0, 242, 254, 0.35);
    text-transform: uppercase;
    white-space: nowrap;
    flex-shrink: 0;
}

/* Tabs hoisted into the handle — flex-shrink:0 so spacer pushes it right */
.panel-handle-tabs {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 0;
    min-width: 0;
}

/* Strip any margin/padding/border from the hoisted tab container itself */
.panel-handle-tabs .alpha-tabs-container,
.panel-handle-tabs .news-tab-switcher {
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    border-bottom: none !important;
    display: flex;
    align-items: center;
}

.panel-handle-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

/* ============================================================
   HIDE REDUNDANT HEADERS IN FREEFORM
   ============================================================ */

/* Categories: entire header row moves into handle */
.layout-freeform #panel-categories .categories-header {
    display: none !important;
}

/* Charts: market-header-row hidden (tabs moved to handle) */
.layout-freeform #panel-charts .market-header-row {
    display: none !important;
}

/* News: header wrapper hidden */
.layout-freeform #panel-news .news-section-header {
    display: none !important;
}

/* Remove section padding-top since handle replaces it */
.layout-freeform .layout-panel {
    padding-top: 0 !important;
}

/* Community tabs: no extra top margin, compact gaps, do NOT stretch */
.layout-freeform #panel-categories .community-tabs-bar {
    flex: 0 0 auto !important;
    margin-top: 0 !important;
    margin-bottom: 4px !important;
    padding-top: 4px !important;
    padding-bottom: 4px !important;
    gap: 4px !important;
}

/* Community category tab buttons — compact in freeform */
.layout-freeform #panel-categories .community-tab {
    padding: 3px 8px !important;
    font-size: 9px !important;
    height: auto !important;
    line-height: 1.4 !important;
    border-radius: 4px !important;
}

.layout-freeform #panel-categories .community-tab .tab-icon,
.layout-freeform #panel-categories .community-tab svg {
    width: 10px !important;
    height: 10px !important;
}

/* ============================================================
   COMMUNITY POST CARDS — compact in freeform
   ============================================================ */
.layout-freeform #panel-categories .community-post-card {
    padding: 8px 10px !important;
    border-radius: 6px !important;
}

.layout-freeform #panel-categories .community-post-card .post-card-title {
    font-size: 11px !important;
    -webkit-line-clamp: 1 !important;
    margin-bottom: 2px !important;
}

.layout-freeform #panel-categories .community-post-card .post-card-body {
    display: none !important;
}

.layout-freeform #panel-categories .community-post-card .post-card-footer {
    margin-top: 4px !important;
    font-size: 9px !important;
}

/* ============================================================
   WATCHLIST — force single line
   ============================================================ */
.layout-freeform #panel-watchlist {
    padding: 0 12px !important;
    justify-content: center;
}

.layout-freeform #panel-watchlist .watchlist-container {
    height: 100% !important;
}

/* ============================================================
   HANDLE META (local signal + search)
   ============================================================ */
.panel-handle-meta {
    display: flex;
    align-items: center;
    font-size: 9px;
    color: rgba(255,255,255,0.3);
    font-family: 'Space Mono', monospace;
    letter-spacing: 1px;
    flex-shrink: 0;
    gap: 4px;
}

.panel-handle-meta p {
    margin: 0 !important;
    font-size: 9px !important;
    color: rgba(255,255,255,0.3) !important;
}

/* ============================================================
   HANDLE EXTRA (Post Ad/Event + Ghost Protocol)
   ============================================================ */
.panel-handle-extra {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.panel-handle-extra .btn,
.panel-handle-extra button {
    font-size: 8px !important;
    padding: 3px 8px !important;
    height: auto !important;
    border-radius: 4px !important;
    line-height: 1.4 !important;
}

/* Spacer pushes tabs + collapse to the right */
.panel-handle-spacer {
    flex: 1;
}

/* Tabs inner sizing */
.panel-handle-tabs .segmented-control {
    background: rgba(255,255,255,0.04);
    border-radius: 5px;
    padding: 2px;
    gap: 2px;
}

.panel-handle-tabs .alpha-tab-btn,
.panel-handle-tabs .news-tab-btn {
    font-size: 8px !important;
    padding: 3px 8px !important;
    letter-spacing: 1px;
    height: auto !important;
    gap: 4px !important;
}

.panel-handle-tabs .alpha-tab-btn.active,
.panel-handle-tabs .news-tab-btn.active {
    box-shadow: none !important;
}

.panel-handle-tabs .alpha-tab-btn.active .tab-icon,
.panel-handle-tabs .news-tab-btn.active .tab-icon {
    filter: none !important;
}

.panel-handle-tabs .tab-icon {
    width: 9px !important;
    height: 9px !important;
}

.panel-collapse-btn {
    width: 18px;
    height: 18px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    color: rgba(255, 255, 255, 0.5);
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    font-family: 'Space Mono', monospace;
    padding: 0;
}

.panel-collapse-btn:hover {
    background: rgba(0, 242, 254, 0.1);
    color: var(--color-accent-cyan);
    border-color: rgba(0, 242, 254, 0.3);
}

/* ============================================================
   COLLAPSED STATE
   ============================================================ */
.layout-panel.panel-collapsed {
    overflow: hidden;
}

.layout-panel.panel-collapsed > *:not(.panel-drag-handle) {
    display: none !important;
}

.layout-panel.panel-collapsed .panel-drag-handle {
    border-bottom: none;
}

/* ============================================================
   LOCKED STATE
   ============================================================ */
.layout-locked .panel-drag-handle {
    cursor: default;
    opacity: 0.7;
}

.layout-locked .panel-drag-handle .panel-handle-dots {
    display: none;
}

.layout-locked .layout-panel::after {
    display: none;
}

/* ============================================================
   TOOLBAR
   ============================================================ */
#layout-toolbar {
    position: fixed;
    bottom: 52px; /* above footer bar */
    right: 16px;
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(6, 12, 20, 0.92);
    border: 1px solid rgba(0, 242, 254, 0.2);
    border-radius: 8px;
    padding: 6px 10px;
    z-index: 888888;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.layout-toolbar-label {
    font-size: 8px;
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    letter-spacing: 2px;
    color: rgba(0, 242, 254, 0.4);
    text-transform: uppercase;
    padding-right: 4px;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    margin-right: 2px;
}

#layout-toolbar button {
    font-size: 8px;
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    padding: 4px 10px;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 4px;
    color: rgba(255, 255, 255, 0.45);
    cursor: pointer;
    transition: all 0.15s;
}

#layout-toolbar button:hover {
    background: rgba(0, 242, 254, 0.08);
    border-color: rgba(0, 242, 254, 0.35);
    color: var(--color-accent-cyan);
}

#layout-toolbar button.active {
    background: rgba(0, 242, 254, 0.1);
    border-color: rgba(0, 242, 254, 0.4);
    color: var(--color-accent-cyan);
}

/* ============================================================
   INNER CONTENT FILL — panels must stretch their content
   ============================================================ */

/* Charts: grid starts immediately, no gap */
.layout-freeform #panel-charts .crypto-grid,
.layout-freeform #panel-charts #crypto-heatmap {
    padding-top: 0 !important;
    margin-top: 0 !important;
}

/* Market chart grid scrolls inside its panel */
.layout-freeform #panel-charts {
    display: flex;
    flex-direction: column;
}

.layout-freeform #panel-charts .market-header-row {
    flex-shrink: 0;
}

.layout-freeform #panel-charts .crypto-grid,
.layout-freeform #panel-charts #crypto-heatmap {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

/* News panel inner scroll */
.layout-freeform #panel-news {
    display: flex;
    flex-direction: column;
}

.layout-freeform #panel-news .news-section-header {
    flex-shrink: 0;
}

.layout-freeform #panel-news .news-list,
.layout-freeform #panel-news #nostr-feed-list {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

/* Community posts panel */
.layout-freeform #panel-categories {
    display: flex;
    flex-direction: column;
}

.layout-freeform #panel-categories .categories-header,
.layout-freeform #panel-categories .community-tabs-bar {
    flex-shrink: 0;
}

.layout-freeform #panel-categories .community-posts-grid {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

/* Watchlist panel — keeps its single-row layout */
.layout-freeform #panel-watchlist {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* ============================================================
   MOBILE — disable everything, restore stacked layout
   ============================================================ */
@media (max-width: 899px) {
    .custom-homepage.layout-freeform {
        display: grid !important;
        position: static !important;
        height: auto !important;
    }

    .layout-freeform .layout-panel {
        position: static !important;
        transform: none !important;
        width: 100% !important;
        height: auto !important;
    }

    .panel-drag-handle {
        display: none !important;
    }

    #layout-toolbar {
        display: none !important;
    }
}
