/* ============================================
   Stock Screener Feature Styles
   ============================================ */

/* Screener container - hidden by default, shown when ScreenerBtn is clicked */
.screener-container {
    display: none;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    position: relative; /* For positioning floating arrows */
    min-height: 600px; /* Ensure minimum height when displayed */
}

.screener-container.active {
    display: block;
    min-height: 600px;
}

/* Header for screener mode */
.screener-header {
    text-align: center;
    margin-bottom: 30px;
}

.screener-header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.screener-header h2 {
    font-size: 1.5rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.screener-header .subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-top: 12px;
    line-height: 1.5;
}

/* Horizontal scrollable columns wrapper */
.screener-columns-wrapper {
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    padding: 10px 0;
    margin: 0 -10px;
}

/* Hide scrollbar but keep functionality */
.screener-columns-wrapper::-webkit-scrollbar {
    height: 6px;
}

.screener-columns-wrapper::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 10px;
}

.screener-columns-wrapper::-webkit-scrollbar-thumb {
    background: var(--text-tertiary);
    border-radius: 10px;
}

.screener-columns-wrapper::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Columns container - flexbox for horizontal layout */
.screener-columns {
    display: flex;
    gap: 16px;
    min-width: min-content;
    padding: 0 10px;
}

/* Individual column */
.screener-column {
    flex: 0 0 300px;
    min-width: 300px;
    max-width: 300px;
    height: 600px; /* Fixed height for consistent layout */
    scroll-snap-align: start;
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 0; /* Remove padding to allow header to stick */
    border: 1px solid rgba(124, 58, 237, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Prevent content overflow */
}

/* Column header - sticky at top */
.screener-column-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px;
    margin-bottom: 0;
    background: var(--bg-secondary);
    border-bottom: 2px solid var(--gradient-start);
    border-radius: 12px 12px 0 0; /* Round only top corners */
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.screener-column-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--gradient-start), var(--gradient-end));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 18px;
}


.screener-column-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    flex: 1;
}

/* Scrollable cards area within each column */
.screener-cards-wrapper {
    flex: 1; /* Take remaining space */
    max-height: 480px; /* Limit height to show content below on mobile */
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
}
/* The message container inserted into the main chat area */
.screener-conditions-container {
    margin: 16px 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.screener-conditions-strip {
    display: flex;
    gap: 80px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 12px 50px 20px;
    margin: 0;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}
@media (max-width: 599px) and (orientation: portrait) {
  .screener-conditions-strip {
    gap: 40px;
    padding: 12px 20px 20px;
  }
}

.screener-conditions-strip::-webkit-scrollbar-thumb{ background:transparent; }
.screener-conditions-strip:hover::-webkit-scrollbar-thumb{ background:rgba(0,0,0,.15); }
.screener-conditions-strip{
  scrollbar-gutter: stable both-edges; /* Chrome/Edge/Safari ใหม่ ๆ */
}

.main-content .chat-messages .screener-conditions-container {
    position: sticky;
    top: calc(var(--topbar-height, 48px) + 16px);
    z-index: 0;
    align-self: stretch;
    width: calc(100% + (var(--chat-messages-padding-x, 20px) * 2));
    margin: 0 calc(-1 * var(--chat-messages-padding-x, 20px));
    margin-bottom: 24px;
    padding: 0 var(--chat-messages-padding-x, 20px);
    box-sizing: border-box;
    pointer-events: auto;
    filter: drop-shadow(0 14px 32px rgba(124, 58, 237, 0.18));
}

.main-content .chat-messages .screener-conditions-container > .screener-conditions-note,
.main-content .chat-messages .screener-conditions-container > .screener-conditions-strip {
    pointer-events: auto;
}

@media (max-width: 599px) and (orientation: portrait) {
    .main-content .chat-messages .screener-conditions-container {
        top: calc(var(--topbar-height, 48px) + 12px);
        filter: drop-shadow(0 10px 25px rgba(124, 58, 237, 0.15));
    }
}

.screener-conditions-strip::-webkit-scrollbar {
    height: 0px;
}

.screener-conditions-strip::-webkit-scrollbar-thumb {
    background: linear-gradient(90deg, rgba(124,58,237,0.45), rgba(56,189,248,0.45));
    border-radius: 999px;
}

.screener-conditions-strip::-webkit-scrollbar-track {
    background: rgba(124,58,237,0.12);
    border-radius: 999px;
}

.screener-conditions-strip .screener-conditions-message {
    flex: 0 0 100%;
    width: 100%;
    max-width: 60%;
    min-height: 180px;
    scroll-snap-align: center;
}

@media (max-width: 1024px){
  .screener-conditions-strip .screener-conditions-message {
      max-width: 70%;
  }
}


.screener-conditions-message {
    position: relative;
    margin: 16px 0;
    padding: 18px;
    border-radius: 12px;
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.18), rgba(56, 189, 248, 0.12));
    border: 1px solid rgba(124, 58, 237, 0.35);
    box-shadow: 0 18px 42px rgba(124, 58, 237, 0.28), 0 10px 26px rgba(14, 165, 233, 0.18);
    backdrop-filter: blur(14px);
    overflow: hidden;
    animation: slideInFromBottom 420ms ease both, pulseGlow 6800ms ease-in-out infinite;
    transition: transform 240ms ease, box-shadow 240ms ease;
    z-index: 0;
    display: flex;
    flex-direction: column;
}

/* Floating action buttons that sit at the top-right of each screener message */
.screener-message-actions {
    position: absolute;
    top: 12px;
    right: 12px;
    display: flex;
    gap: 8px;
    z-index: 1400; /* above the message decoration */
}

.screener-action-btn {
    width: 36px;
    height: 36px;
    border-radius: 9px;
    border: 1px solid rgba(255,255,255,0.12);
    background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02));
    color: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 160ms ease, background 180ms ease, box-shadow 180ms ease;
}

.screener-action-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 18px rgba(0,0,0,0.18);
}

.screener-action-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

.screener-action-btn .fas { font-size: 14px; }

.screener-action-btn.fav-btn.is-favorite,
.screener-action-btn.fav-btn.is-favorite .fas {
    color: #ffd54a; /* gold star */
    text-shadow: 0 1px 0 rgba(0,0,0,0.25);
}

.screener-conditions-message::before {
    content: '';
    position: absolute;
    inset: -40% -35% auto;
    height: 120px;
    background: radial-gradient(circle at center, rgba(244, 114, 182, 0.35), rgba(244, 114, 182, 0));
    opacity: 0.85;
    filter: blur(12px);
    animation: shimmerSweep 5.2s ease-in-out infinite;
    z-index: -1;
}

.screener-conditions-message > * {
    position: relative;
    z-index: 1;
}

.screener-conditions-message:hover {
    transform: translateY(-2px) scale(1.01);
    box-shadow: 0 22px 60px rgba(124, 58, 237, 0.34), 0 16px 34px rgba(14, 165, 233, 0.2);
}

.screener-conditions-message[data-role="stream"] {
    margin: 18px 0;
    width: 100%;
    flex: 1 1 auto;
}

.screener-conditions-message[data-role="stream"] .screener-conditions-wrapper {
    margin: 0;
}

/* Inline bottom-left actions (smaller icons, 20% smaller) */
.screener-inline-actions {
    position: absolute;
    left: 12px;
    bottom: 12px;
    display: flex;
    gap: 8px;
    z-index: 1400;
}

.screener-inline-btn {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.08);
    background: rgba(255,255,255,0.03);
    color: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 120ms ease, box-shadow 120ms ease;
}

.screener-inline-btn .fas { font-size: 11px; /* ~20% smaller */ }

.screener-inline-btn.is-favorite,
.screener-inline-btn.is-favorite .fas { color: #ffd54a; }

.screener-message-actions .collapse-btn .fas { font-size: 13px; }

/* Make sure the list inside the message has some spacing from edges */
.screener-conditions-message .screener-conditions-wrapper {
    margin: 0;
}

.screener-condition-stream {
    margin-top: 18px;
    padding: 16px;
    border-radius: 12px;
    border: 1px solid rgba(124, 58, 237, 0.18);
    background: var(--glow-color-soft);
    backdrop-filter: blur(10px);
    transition: border-color 180ms ease, box-shadow 180ms ease, background 180ms ease, opacity 180ms ease;
    position: relative;
}

.screener-condition-stream.is-pending {
    opacity: 0.75;
}

.screener-condition-stream.is-streaming {
    border-color: rgba(124, 58, 237, 0.42);
    box-shadow: 0 12px 32px rgba(124, 58, 237, 0.28);
}

.screener-condition-stream.has-error {
    border-color: rgba(248, 113, 113, 0.65);
    background: rgba(248, 113, 113, 0.12);
    box-shadow: 0 12px 28px rgba(248, 113, 113, 0.25);
}

.screener-condition-stream-header {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.screener-condition-stream-header::before {
    content: '\f201';
    font-family: 'Font Awesome 5 Free';
    font-weight: 900;
    font-size: 0.85rem;
    color: var(--gradient-start);
}

.screener-condition-stream-content {
    margin-top: 12px;
    padding: 12px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    line-height: 1.55;
    max-height: 420px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    word-break: break-word;
    position: relative;
}

.screener-condition-stream .token-usage-meta {
    text-align: end;
    margin: 14px 0 0;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.45;
}

.screener-condition-stream-content.is-streaming::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.18), rgba(14, 165, 233, 0));
    opacity: 0.35;
    animation: pulseGlow 4800ms ease-in-out infinite;
}

.screener-condition-stream-content pre {
    background: rgba(15, 23, 42, 0.55);
    border-radius: 8px;
    padding: 12px;
    overflow-x: auto;
}

.screener-stream-placeholder {
    display: flex;
    align-items: center;
    gap: 10px;
    font-style: italic;
    color: var(--text-secondary);
}

.screener-stream-placeholder::before {
    content: '';
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid rgba(124, 58, 237, 0.2);
    border-top-color: rgba(124, 58, 237, 0.85);
    animation: screenerSpinner 860ms linear infinite;
}

.screener-stream-error {
    color: rgba(248, 113, 113, 0.95);
    font-weight: 600;
    line-height: 1.5;
}

/* Small screens: stack single column and make cards full width */
@media (max-width: 640px) {
    .screener-conditions-list {
        grid-template-columns: 1fr;
    }
    .screener-condition-card {
        padding: 12px;
    }
    .screener-conditions-message {
        padding: 14px;
        margin: 12px auto;
        border-radius: 14px;
        width: min(100%, calc(100vw - 24px)) !important;
        max-width: 100% !important;
        max-height: calc(100vh - 140px) !important;;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        box-sizing: border-box;
    }
    .screener-condition-stream {
        padding: 12px;
    }
    .screener-condition-stream-content {
        max-height: min(360px, 60vh);
    }
}

/* Ensure streaming message area expands properly on narrow portrait phones
   Many devices report the stream placeholder as a small area until content
   arrives. Make the stream wrapper and content allow expansion and use
   viewport-relative limits so the area grows while loading. */
@media (max-width: 640px) and (orientation: portrait) {
    .screener-conditions-message[data-role="stream"] {
        /* Give an initial minimum height so users see the loading area */
        /* Allow it to use most of the viewport height while loading */
        max-height: calc(100vh - 120px);
        overflow: visible; /* let inner streaming element expand */
        box-sizing: border-box;
    }

    .screener-condition-stream {
        /* Don't force a small fixed max-height on the container */
        max-height: none;
    }

    .screener-condition-stream-content {
        /* Allow the content to grow up to a sensible fraction of viewport */
        max-height: calc(60vh);
        overflow-y: auto;
    }
}

/* Subtle float animation for the entire conditions block */
@keyframes conditionsFloat {
    0% { transform: translateY(6px); opacity: 0; }
    100% { transform: translateY(0); opacity: 1; }
}

.screener-conditions-list .screener-condition-card {
    animation-name: cardFadeUp, conditionsFloat;
    animation-duration: 420ms, 1200ms;
    animation-timing-function: ease-out, ease-in-out;
    animation-fill-mode: both;
}

@keyframes pulseGlow {
    0%, 100% {
        box-shadow: 0 18px 42px rgba(124, 58, 237, 0.28), 0 10px 26px rgba(14, 165, 233, 0.18);
    }
    45% {
        box-shadow: 0 26px 66px rgba(124, 58, 237, 0.4), 0 18px 40px rgba(14, 165, 233, 0.22);
    }
}

@keyframes shimmerSweep {
    0% {
        transform: translateX(-30%) rotate(6deg);
        opacity: 0.55;
    }
    50% {
        transform: translateX(30%) rotate(0deg);
        opacity: 0.9;
    }
    100% {
        transform: translateX(-30%) rotate(-4deg);
        opacity: 0.55;
    }
}

/* Custom scrollbar for cards wrapper */
.screener-cards-wrapper::-webkit-scrollbar {
    width: 6px;
}

.screener-cards-wrapper::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 10px;
}

.screener-cards-wrapper::-webkit-scrollbar-thumb {
    background: var(--text-tertiary);
    border-radius: 10px;
}

.screener-cards-wrapper::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Cards container */
.screener-cards {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Individual screener card */
.screener-card {
    background: var(--card-bg);
    border: 1px solid rgba(124, 58, 237, 0.15);
    border-radius: 10px;
    padding: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08),
                0 1px 2px rgba(124, 58, 237, 0.1);
}

.screener-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(124, 58, 237, 0.25),
                0 3px 8px rgba(0, 0, 0, 0.15);
    border-color: var(--gradient-start);
}

.screener-card:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(124, 58, 237, 0.2),
                0 1px 3px rgba(0, 0, 0, 0.1);
}

.screener-card-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.screener-card-title i {
    color: var(--gradient-start);
    font-size: 0.85rem;
}

.screener-card-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
    .screener-column {
        flex: 0 0 280px;
        min-width: 280px;
        max-width: 280px;
        height: 350px; /* Shorter to show input section */
    }
    
    .screener-cards-wrapper {
        max-height: 250px; /* Limit cards height on tablet */
    }
    
    .screener-header h1 {
        font-size: 1.6rem;
    }
    
    .screener-header h2 {
        font-size: 1.2rem;
    }
}

@media (max-width: 480px) {
    .screener-column {
        flex: 0 0 260px;
        min-width: 260px;
        max-width: 260px;
        height: 380px; /* Much shorter on small phones */
    }
    
    .screener-cards-wrapper {
        max-height: 280px; /* Show only 2-3 cards, force scrolling */
        padding: 12px;
    }
    
    .screener-container {
        padding: 10px 0;
    }
}

/* Landscape mobile orientation */
@media (max-width: 768px) and (orientation: landscape) {
    .screener-column {
        height: 320px; /* Very short in landscape to show input */
    }
    
    .screener-cards-wrapper {
        max-height: 220px; /* Minimal cards in landscape */
    }
    
    .screener-header {
        margin-bottom: 20px;
    }
    
    .screener-header h1 {
        font-size: 1.4rem;
    }
    
    .screener-header h2 {
        font-size: 1.1rem;
    }
}

/* Animation for showing screener */
@keyframes slideInFromBottom {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.screener-container.active {
    animation: slideInFromBottom 0.3s ease-out;
}

/* Scroll to top button for mobile */
.screener-scroll-top {
    position: fixed;
    bottom: 80px;
    right: 16px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border: none;
    color: white;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    transform: translateY(20px);
}

.screener-scroll-top.visible {
    opacity: 1;
    transform: translateY(0);
}

.screener-scroll-top:hover {
    transform: scale(1.1) translateY(0);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.screener-scroll-top:active {
    transform: scale(0.95);
}

@media (max-width: 768px) {
    .screener-scroll-top {
        display: flex;
    }
}

/* Conditions list (rendered after screener response) */
.screener-conditions-wrapper {
    margin: 18px 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.screener-conditions-note {
    color: var(--text-secondary);
    font-size: 0.95rem;
    padding: 8px 12px;
    background: rgba(124,58,237,0.03);
    border-radius: 8px;
    border: 1px solid rgba(124,58,237,0.06);
}

.screener-conditions-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 12px;
}

@keyframes cardFadeUp {
    from {
        opacity: 0;
        transform: translateY(18px);
        filter: blur(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
        filter: blur(0);
    }
}

.screener-condition-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 14px;
    background: var(--card-bg);
    border-radius: 12px;
    border: 1px solid rgba(0,0,0,0.06);
    box-shadow: 0 8px 20px rgba(12,12,12,0.06), inset 0 1px 0 rgba(255,255,255,0.02);
    cursor: pointer;
    transition: transform 0.22s ease, box-shadow 0.22s ease;
    animation: cardFadeUp 420ms ease forwards;
    transform: translateY(0);
    position: relative;
}

.screener-condition-card:hover {
    transform: translateY(-6px);
    box-shadow: 0 18px 40px rgba(12,12,12,0.12);
    border-color: rgba(124,58,237,0.15);
}

.screener-condition-card.is-sending {
    opacity: 0.7;
    transform: translateY(0) scale(0.998);
    box-shadow: 0 10px 26px rgba(12,12,12,0.08);
    border-color: rgba(124,58,237,0.2);
    cursor: progress;
    pointer-events: none;
}



.screener-condition-card.is-submitted {
    border-color: rgba(34,197,94,0.6);
    box-shadow: 0 18px 38px rgba(34,197,94,0.18);
    background: linear-gradient(135deg, rgba(34,197,94,0.14), rgba(20,184,166,0.1));
}

.screener-condition-card.is-submit-error {
    border-color: rgba(248,113,113,0.6);
    box-shadow: 0 18px 38px rgba(248,113,113,0.2);
    background: linear-gradient(135deg, rgba(248,113,113,0.14), rgba(244,114,182,0.1));
}

.screener-condition-name {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 1.5rem;
}

.screener-condition-meta {
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.screener-condition-desc {
    color: var(--text-secondary);
    font-size: 1.1rem;
    line-height: 1.4;
}

.screener-condition-footer {
    margin-top: 8px;
    font-size: 0.78rem;
    color: var(--text-primary);
    display: flex;
    gap: 8px;
    width: 100%;
    justify-content: space-between;
}

@media (max-width: 480px) {
    .screener-conditions-list {
        grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    }
}

@keyframes screenerSpinner {
    from { transform: translateY(-50%) rotate(0deg); }
    to { transform: translateY(-50%) rotate(360deg); }
}

/* debug button removed */
