/* โครงสร้างหลัก — ไม่รอ Tailwind CDN */
html, body.dashboard-app {
    margin: 0;
    min-height: 100vh;
    background: #020617;
    color: #f1f5f9;
}
body.dashboard-app {
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
}
body.dashboard-app > header,
body.dashboard-app > #dashboardError {
    flex-shrink: 0;
}
body.dashboard-app > .dashboard-main {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    box-sizing: border-box;
    width: 100%;
    padding: 1rem;
    gap: 1rem;
}

.filter-input {
    width: 100%;
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 0.5rem;
    padding: 0.45rem 0.65rem;
    color: #f1f5f9;
    font-size: 0.8125rem;
}
.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.65rem;
    border-radius: 9999px;
    border: 1px solid #334155;
    background: #1e293b;
    font-size: 0.75rem;
    color: #cbd5e1;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
.filter-chip:has(input:checked) {
    border-color: #f59e0b;
    background: rgba(245, 158, 11, 0.12);
    color: #fcd34d;
}
.filter-chip input {
    accent-color: #f59e0b;
}
.filter-chip-rsi {
    gap: 0.25rem;
}
.filter-rsi-num {
    width: 3.25rem;
    padding: 0.15rem 0.35rem;
    border-radius: 0.35rem;
    border: 1px solid #475569;
    background: #0f172a;
    color: #f1f5f9;
    font-size: 0.75rem;
    text-align: center;
}
.filter-chip-num {
    gap: 0.25rem;
}
#btnSyncFundamental.hidden {
    display: none;
}
#stockFiltersRow1 {
    align-items: flex-start;
}
.filter-business-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    flex: 0 1 auto;
    order: -1;
}
.filter-business-label {
    font-size: 0.75rem;
    color: #94a3b8;
    white-space: nowrap;
}
.filter-business-input {
    width: 22ch;
    max-width: min(22ch, 100%);
    padding: 0.35rem 0.65rem;
    border-radius: 0.5rem;
    border: 1px solid #334155;
    background: #1e293b;
    color: #f1f5f9;
    font-size: 0.75rem;
}
.filter-business-input:focus {
    outline: none;
    border-color: #f59e0b;
    box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.35);
}
.business-suggest {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 0.25rem);
    z-index: 30;
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    padding: 0.5rem;
    border-radius: 0.5rem;
    border: 1px solid #334155;
    background: #0f172a;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    max-height: 9rem;
    overflow-y: auto;
}
.business-suggest.hidden {
    display: none;
}
.business-suggest-item {
    border: 1px solid #334155;
    background: #1e293b;
    color: #e2e8f0;
    font-size: 0.6875rem;
    padding: 0.2rem 0.5rem;
    border-radius: 9999px;
    cursor: pointer;
}
.business-suggest-item:hover {
    border-color: #f59e0b;
    background: rgba(245, 158, 11, 0.12);
    color: #fcd34d;
}
.dashboard-table tr.tsai-row-hidden {
    display: none;
}
.filter-chip.uptrend-chip:has(input:checked) {
    border-color: #34d399;
    background: rgba(52, 211, 153, 0.12);
    color: #6ee7b7;
}

.dashboard-lite .col-indicators {
    display: none !important;
}
.dashboard-lite #stockFiltersTech {
    opacity: 0.45;
    pointer-events: none;
}

.stocks-column {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-height: 0;
}
.stocks-filters-panel {
    flex-shrink: 0;
}
.stocks-table-panel {
    flex: 1 1 auto;
    min-height: 280px;
    display: block;
    overflow: hidden;
    border-radius: 0.75rem;
}

/* กล่องเลื่อนตารางหุ้น — ความสูงคงที่บน PC */
#stockTableScroll {
    display: block;
    width: 100%;
    height: calc(100vh - 15.5rem);
    max-height: calc(100vh - 15.5rem);
    min-height: 240px;
    overflow-x: auto;
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
    box-sizing: border-box;
}

.dashboard-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    text-align: left;
}
.dashboard-table th,
.dashboard-table td {
    white-space: nowrap;
    padding: 0.5rem 0.75rem;
}
.dashboard-table thead {
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(30, 41, 59, 0.95);
}
.dashboard-table th.sortable {
    cursor: pointer;
}
.dashboard-table th.sortable:hover {
    color: #fbbf24;
}
.dashboard-table th .sort-ind {
    opacity: 0.35;
    font-size: 0.65rem;
    margin-left: 0.15rem;
}
.dashboard-table th.sort-asc .sort-ind,
.dashboard-table th.sort-desc .sort-ind {
    opacity: 1;
    color: #fbbf24;
}

.sidebar-feed-column {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-height: 0;
}
.feed-panel {
    display: flex;
    flex-direction: column;
    min-height: 140px;
    max-height: 38vh;
    overflow: hidden;
}
.feed-scroll {
    flex: 1 1 auto;
    min-height: 80px;
    max-height: 32vh;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

@media (min-width: 1280px) {
    body.dashboard-app > .dashboard-main {
        flex-direction: row;
        align-items: stretch;
    }
    .sidebar-feed-column {
        width: 20rem;
        flex-shrink: 0;
        max-height: calc(100vh - 5rem);
    }
    .feed-panel {
        flex: 1 1 0;
        max-height: none;
    }
    .feed-scroll {
        max-height: none;
    }
    .stocks-column {
        flex: 1 1 0;
        min-height: 0;
    }
    #stockTableScroll {
        height: calc(100vh - 12.5rem);
        max-height: calc(100vh - 12.5rem);
    }
}

@media (max-width: 1279px) {
    #stockTableScroll {
        height: min(65vh, calc(100vh - 14rem));
        max-height: min(65vh, calc(100vh - 14rem));
    }
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.5);
    border-radius: 8px;
}
::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.5);
}

.symbol-cell {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
}
.dashboard-table th.col-draggable {
    cursor: grab;
    user-select: none;
}
.dashboard-table th.col-draggable:active {
    cursor: grabbing;
}
.dashboard-table th.col-dragging {
    opacity: 0.45;
}
.dashboard-table th.col-drag-over {
    box-shadow: inset 0 -2px 0 #f59e0b;
}
.dashboard-table th .col-grip {
    opacity: 0.35;
    margin-right: 0.2rem;
    font-size: 0.55rem;
    letter-spacing: -0.12em;
}
.tv-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    padding: 0.2rem 0.45rem;
    font-size: 0.625rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    border-radius: 0.35rem;
    background: #2962ff;
    color: #fff;
    text-decoration: none;
    border: 1px solid rgba(41, 98, 255, 0.5);
}
.tv-btn:hover {
    background: #1e4fd6;
    color: #fff;
}
.info-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.25rem;
    padding: 0.2rem 0.45rem;
    font-size: 0.625rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    border-radius: 0.35rem;
    background: #0f766e;
    color: #fff;
    border: 1px solid rgba(45, 212, 191, 0.45);
    cursor: pointer;
}
.info-btn:hover {
    background: #0d9488;
}
.info-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* Modal ข้อมูลธุรกิจ */
body.tsai-info-modal-open {
    overflow: hidden;
}
.tsai-info-modal {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.tsai-info-modal.hidden {
    display: none;
}
.tsai-info-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(2, 6, 23, 0.78);
    backdrop-filter: blur(2px);
}
.tsai-info-modal-panel {
    position: relative;
    z-index: 1;
    width: min(42rem, 100%);
    max-height: min(88vh, 720px);
    display: flex;
    flex-direction: column;
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 0.75rem;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}
.tsai-info-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid #1e293b;
    flex-shrink: 0;
}
.tsai-info-modal-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: #fcd34d;
}
.tsai-info-modal-close {
    border: none;
    background: #1e293b;
    color: #cbd5e1;
    width: 2rem;
    height: 2rem;
    border-radius: 0.5rem;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
}
.tsai-info-modal-close:hover {
    background: #334155;
    color: #fff;
}
.tsai-info-modal-body {
    padding: 1rem;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}
.tsai-info-section {
    margin-bottom: 1rem;
}
.tsai-info-section h4 {
    margin: 0 0 0.45rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #94a3b8;
}
.tsai-info-names {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: #f8fafc;
}
.tsai-info-sector {
    margin: 0.35rem 0 0;
    font-size: 0.8125rem;
    color: #94a3b8;
}
.tsai-info-summary {
    margin: 0;
    font-size: 0.875rem;
    line-height: 1.55;
    color: #e2e8f0;
    white-space: pre-wrap;
}
.tsai-info-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}
.tsai-info-table th,
.tsai-info-table td {
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid #1e293b;
    text-align: left;
}
.tsai-info-table th {
    width: 42%;
    color: #94a3b8;
    font-weight: 500;
}
.tsai-info-table td {
    color: #f1f5f9;
    text-align: right;
}
.tsai-info-meta {
    font-size: 0.8125rem;
    color: #cbd5e1;
}
.tsai-info-refresh-ok {
    margin: 0.5rem 0 0;
    font-size: 0.75rem;
    font-weight: 600;
    color: #6ee7b7;
}
.tsai-info-refresh-warn {
    margin: 0.5rem 0 0;
    font-size: 0.75rem;
    color: #fcd34d;
}
.dashboard-table td .bb-score-badge {
    display: inline-block;
    min-width: 2.25rem;
}

/* แถบสถานะโหลด / อัปเดต */
.tsai-status-bar {
    display: block;
    font-size: 0.8125rem;
    font-weight: 700;
    line-height: 1.35;
    padding: 0.45rem 0.75rem;
    border-radius: 0.5rem;
    margin: 0;
    letter-spacing: 0.02em;
    transition: color 0.2s, background 0.2s, box-shadow 0.2s;
}
.tsai-status-feed {
    margin: 0;
    border-top: 1px solid #1e293b;
}
.tsai-status-wait {
    color: #cbd5e1;
    background: rgba(51, 65, 85, 0.5);
    border: 1px solid #475569;
}
.tsai-status-updating {
    color: #0f172a;
    background: linear-gradient(90deg, #fde047 0%, #fbbf24 45%, #f59e0b 100%);
    border: 1px solid #f59e0b;
    box-shadow: 0 0 14px rgba(251, 191, 36, 0.65);
    animation: tsai-status-blink 0.75s ease-in-out infinite;
}
.tsai-status-feed.tsai-status-updating {
    color: #fff;
    background: linear-gradient(90deg, #fda4af 0%, #fb7185 50%, #f43f5e 100%);
    border-color: #fb7185;
    box-shadow: 0 0 14px rgba(251, 113, 133, 0.55);
}
.tsai-status-ok {
    color: #6ee7b7;
    background: rgba(6, 95, 70, 0.55);
    border: 1px solid rgba(52, 211, 153, 0.55);
    box-shadow: 0 0 8px rgba(52, 211, 153, 0.25);
    animation: none;
}
.tsai-status-error {
    color: #fecaca;
    background: rgba(127, 29, 29, 0.65);
    border: 1px solid #f87171;
    box-shadow: 0 0 10px rgba(248, 113, 113, 0.35);
    animation: tsai-status-blink 1s ease-in-out infinite;
}

@keyframes tsai-status-blink {
    0%, 100% {
        opacity: 1;
        filter: brightness(1);
    }
    50% {
        opacity: 0.55;
        filter: brightness(1.15);
    }
}

@media (prefers-reduced-motion: reduce) {
    .tsai-status-updating,
    .tsai-status-error {
        animation: none;
        opacity: 1;
    }
}
