/**
 * GSignalX — shared responsive layout (desk, grid, admin).
 * Loaded after page-specific styles; uses existing IDs/classes.
 */

/* —— Safe areas (notched phones, home indicator) —— */
@supports (padding: env(safe-area-inset-bottom)) {
    body {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }

    #header {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
        padding-top: max(10px, env(safe-area-inset-top));
    }

    .site-footer {
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }

    main {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
}

/* —— Touch targets —— */
@media (pointer: coarse) {
    .btn-nav,
    .filter-chip,
    #toolbar .btn,
    .btn,
    .btn-primary,
    .btn-icon {
        min-height: 44px;
    }
}

/* —— Header: tablet —— */
@media (max-width: 1100px) {
    .header-metrics {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        max-width: 100%;
        padding-bottom: 2px;
        mask-image: linear-gradient(90deg, #000 92%, transparent);
        -webkit-mask-image: linear-gradient(90deg, #000 92%, transparent);
    }

    .header-metrics .item,
    #header .item {
        flex-shrink: 0;
    }
}

/* —— Header: mobile stack —— */
@media (max-width: 768px) {
    #header {
        gap: 10px;
        padding-top: 10px;
        padding-bottom: 10px;
    }

    .header-brand {
        flex: 1 1 100%;
        width: 100%;
        max-width: 100%;
        border-right: none !important;
        border-bottom: 1px solid var(--color-border);
        padding-bottom: 10px;
        margin-right: 0 !important;
        margin-bottom: 2px;
    }

    .header-metrics,
    .header-middle {
        flex: 1 1 100%;
        width: 100%;
        min-width: 0;
    }

    .header-actions {
        flex: 1 1 100%;
        width: 100%;
        margin-left: 0 !important;
        justify-content: flex-end;
        flex-wrap: wrap;
        gap: 8px;
    }

    #status {
        max-width: 100%;
    }

    #status-text {
        max-width: 9rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

@media (max-width: 480px) {
    .brand-tagline,
    .brand-parent {
        display: none;
    }

    .theme-label {
        display: none;
    }

    .btn-nav {
        padding: 8px 10px;
        font-size: 11px;
    }

    #header .value {
        font-size: 11px;
    }

    .footer-products {
        max-width: 100%;
    }
}

/* —— Scrollable data tables —— */
.scanner-scroll,
.vpof-table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}

.scanner-table {
    min-width: min(100%, 640px);
}

.vpof-table-scroll table {
    min-width: min(100%, 560px);
}

@media (max-width: 640px) {
    .scanner-table {
        min-width: 520px;
    }

    .scanner-scroll {
        max-height: min(42vh, 220px);
    }
}

/* —— Admin dashboard —— */
@media (max-width: 900px) {
    main .grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    main {
        padding: 12px !important;
    }

    main .stat-grid {
        grid-template-columns: 1fr;
    }

    main .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    main .toolbar input {
        width: 100%;
        min-width: 0;
    }

    main table {
        font-size: 0.78rem;
    }

    main th,
    main td {
        padding: 6px 8px;
    }
}

/* —— Multi-symbol grid —— */
@media (max-width: 900px) {
    #symbolGrid {
        grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr));
    }
}

@media (max-width: 640px) {
    #symbolGrid {
        grid-template-columns: 1fr;
    }

    .symbol-card .card-body {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto;
    }

    .symbol-card {
        min-height: 160px;
    }

    #toolbar {
        padding: 8px 12px;
        gap: 6px;
    }

    #toolbar .btn {
        flex: 1 1 auto;
        min-width: calc(50% - 6px);
        text-align: center;
        justify-content: center;
    }

    #sidebar {
        width: min(100vw, 280px);
        top: 0;
        padding-top: env(safe-area-inset-top, 0);
    }

    #detailModal .modal-content {
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100dvh;
        border-radius: 0;
        margin: 0;
    }
}

/* —— Desk dashboard (single-symbol) —— */
@media (max-width: 900px) {
    .header-actions {
        flex-wrap: wrap;
        justify-content: flex-end;
        width: 100%;
    }

    .mode-wrap {
        order: 3;
        flex: 1 1 100%;
        align-items: stretch;
    }

    .mode-selector {
        width: 100%;
        justify-content: stretch;
    }

    .mode-selector .mode-btn {
        flex: 1 1 33%;
        text-align: center;
    }

    .mode-subtitle {
        max-width: none;
    }

    #scanner {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
    }

    #main {
        margin-bottom: max(12px, env(safe-area-inset-bottom));
    }

    #vpContainer,
    #cvdContainer {
        min-height: min(240px, 38vh);
    }

    #domContainer {
        min-height: min(200px, 32vh);
    }

    .insights-grid {
        gap: 10px;
    }

    .signal-card,
    .struct-panel {
        min-width: 0;
    }
}

@media (max-width: 640px) {
    .scanner-toolbar {
        gap: 6px;
    }

    .filter-chip {
        padding: 6px 12px;
        font-size: 10px;
    }

    #header .item {
        padding: 6px 10px;
    }

    .panel-header,
    .section-header {
        padding: 9px 12px;
        flex-wrap: wrap;
        gap: 8px;
    }

    #vpStats {
        margin-left: 0;
        width: 100%;
    }
}

/* —— Reduced motion —— */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
