:root {
    --max-width: 1370px;
}

/* News Ticker */
.markets-news-ticker {
    height: 64px;
    overflow: hidden;
    position: relative;
    display: flex;
    align-items: center;
}

.ticker-wrapper {
    width: 100%;
    overflow: hidden;
    display: flex;
}

.ticker-items {
    display: flex;
    white-space: nowrap;
    animation: ticker-scroll 200s linear infinite;
    padding-left: 100%;
}

@keyframes ticker-scroll {
    0% {
        transform: translateX(0);
    }

    100% {
        transform: translateX(-100%);
    }
}

.ticker-items:hover {
    animation-play-state: paused;
}

.ticker-item {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    height: 64px;
    min-width: 160px;
    cursor: pointer;
    transition: background 0.2s;
    gap: 2px;
}

.ticker-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.ticker-company-name {
    font-family: var(--font-sans);
    font-size: 0.7rem;
    color: var(--color-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
}

.ticker-symbol {
    color: var(--color-neon-purple-bright);
    font-weight: 700;
    font-size: 0.8rem;
    font-family: var(--font-mono);
    margin-right: 0.4rem;
}

.ticker-row-price {
    display: flex;
    align-items: baseline;
    gap: 0.3rem;
}

.ticker-price {
    color: var(--color-text);
    font-weight: 700;
    font-size: 0.88rem;
    font-family: var(--font-mono);
}

.ticker-change {
    display: flex;
    align-items: center;
    font-size: 0.75rem;
    font-family: var(--font-mono);
    font-weight: 700;
    gap: 0.25rem;
}

.ticker-pct,
.ticker-abs {
    font-size: 0.73rem;
}

.ticker-change.up {
    color: var(--color-neon-green);
}

.ticker-change.down {
    color: var(--color-neon-pink);
}

.ticker-change.neutral {
    color: var(--color-text-muted);
}

.ticker-icon {
    width: 11px;
    height: 11px;
    flex-shrink: 0;
}

.markets-loader-overlay {
    height: 50vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    color: var(--color-text-muted);
}

.markets-dashboard {
    padding-bottom: var(--space-2xl);
    animation: fadeIn 0.4s ease-out;
}

/* Header & Ticker Grid */
.markets-ticker-section {
    margin-bottom: var(--space-xl);
}

.header-market-ticker {
    display: flex;
    gap: var(--space-sm);
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-lg);
}

/* Investment / Existing Issues Section */
.markets-existing-issues-section {
    padding: var(--space-xl) 0;
    border-top: 1px solid var(--color-border);
    margin-top: var(--space-xl);
}

.markets-existing-issues-section .section-heading {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    color: var(--color-text);
}

.section-source {
    font-size: 0.78rem;
    color: var(--color-text-muted);
    margin-bottom: var(--space-lg);
}

.section-source a {
    color: var(--color-neon-purple-bright);
}

.markets-section-loader {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--color-text-muted);
    padding: var(--space-lg) 0;
    font-size: 0.9rem;
}

.markets-section-loader .spinner {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.markets-error-msg {
    color: var(--color-neon-pink);
    padding: var(--space-md) 0;
    font-size: 0.9rem;
}

/* Issue Status Badges */
.issue-status {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    display: inline-block;
}

.status-opened {
    background: rgba(0, 230, 118, 0.1);
    color: var(--color-neon-green);
    border: 1px solid var(--color-neon-green);
}

.status-closed {
    background: rgba(255, 23, 68, 0.1);
    color: var(--color-neon-pink);
    border: 1px solid var(--color-neon-pink);
}

.status-coming-soon {
    background: rgba(187, 134, 252, 0.1);
    color: var(--color-neon-purple-bright);
    border: 1px solid var(--color-neon-purple-bright);
}

/* Pagination Controls */
.pagination-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) 0;
    margin-top: var(--space-sm);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.pg-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--color-white);
    padding: 6px 16px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 80px;
}

.pg-btn:hover:not(:disabled) {
    background: var(--gradient-primary);
    border-color: transparent;
    box-shadow: 0 0 15px rgba(187, 134, 252, 0.3);
}

.pg-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.pg-info {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    font-weight: 500;
}

.market-status {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.badge-open {
    background-color: rgba(0, 230, 118, 0.1);
    color: var(--color-neon-green);
    border: 1px solid var(--color-neon-green);
}

.badge-closed {
    background-color: rgba(255, 23, 68, 0.1);
    color: var(--color-neon-pink);
    border: 1px solid var(--color-neon-pink);
}

.header-market-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-md);
}

.market-metrics-box {
    padding: var(--space-md);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    justify-content: center;
    border-radius: 8px;
}

.market-metrics-box.primary-index {
    border-left: 4px solid var(--color-neon-green);
}

.market-metric-label {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}

.market-metric-value {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.ticker-current {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text);
}

.ticker-change {
    font-size: 1rem;
    font-weight: 700;
    font-family: var(--font-mono);
}

/* Chart Area */
.markets-chart-section {
    margin-bottom: var(--space-xl);
}

.chart-container {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    padding: var(--space-lg);
    border-radius: 8px;
    position: relative;
    height: 450px;
    /* Constrain height to prevent infinite resize loop */
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: var(--space-md);
    border-bottom: 1px solid var(--color-border);
    padding-bottom: var(--space-sm);
}

.chart-header h2 {
    font-size: 1.5rem;
    margin: 0;
}

.last-updated {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

#nepseChart {
    display: block;
    width: 100% !important;
    height: calc(100% - 60px) !important;
    /* Account for header space */
}

/* Data Grids & Tabs */
.markets-data-section {
    margin-bottom: var(--space-xl);
}

.markets-grid-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 350px;
    gap: var(--space-xl);
    align-items: start;
}

/* --- Fear and Greed Index (Market Pulse) --- */
.fear-greed-widget {
    background: #111;
    border: 1.5px solid #222;
    border-radius: 12px;
    padding: 20px;
    margin-top: 15px;
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
}

.fear-greed-widget:hover {
    border-color: #00ff8888;
    box-shadow: 0 0 20px rgba(0, 255, 136, 0.1);
}

.pulse-gauge-container {
    text-align: center;
    position: relative;
    margin-bottom: 20px;
}

.pulse-gauge {
    width: 100%;
    max-width: 180px;
    height: auto;
}

.gauge-bg {
    stroke: #222;
}

.gauge-fill {
    transition: stroke-dashoffset 1s ease-out;
}

.gauge-value {
    font-size: 24px;
    font-weight: 700;
    fill: #fff;
    font-family: 'Inter', sans-serif;
}

.pulse-status {
    font-size: 1.2rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: -5px;
    color: #00ff88;
}

.pulse-history-mini {
    border-top: 1px solid #222;
    padding-top: 15px;
    margin-bottom: 15px;
}

.history-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.h-label {
    color: #666;
}

.h-val {
    color: #aaa;
    font-weight: 600;
}

.pulse-footer {
    text-align: right;
    border-top: 1px solid #222;
    padding-top: 10px;
}

.pulse-link {
    color: #00ff88;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    transition: color 0.2s;
}

.pulse-link:hover {
    color: #fff;
    text-decoration: underline;
}

/* Animations for Status */
.pulse-status.fear {
    color: #ff3333;
}

.pulse-status.neutral {
    color: #ffcc00;
}

.pulse-status.greed {
    color: #00ff88;
}

@media (max-width: 900px) {
    .markets-grid-layout {
        grid-template-columns: 1fr;
    }
}

.markets-tabs {
    display: flex;
    gap: var(--space-md);
    border-bottom: 1px solid var(--color-border);
    margin-bottom: var(--space-md);
}

.markets-tabs::-webkit-scrollbar {
    display: none;
}

.markets-tab {
    background: transparent;
    border-color: transparent;
    border-style: solid;
    border-width: 0 0 2px 0;
    padding: 0.75rem 0;
    font-weight: 700;
    font-size: 1rem;
    color: var(--color-text-muted);
    cursor: pointer;
    margin-bottom: -1px;
    white-space: nowrap;
    transition: all 0.2s;
}

.markets-tab:hover {
    color: var(--color-text);
}

.markets-tab.active {
    color: var(--color-neon-purple-bright);
    border-bottom-color: var(--color-neon-purple-bright);
}

.tab-pane {
    display: none;
    animation: fadeIn 0.3s ease-in-out;
}

.tab-pane.active {
    display: block;
}

/* Tables */
.markets-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

.markets-table th,
.markets-table td {
    padding: 0.75rem 0.5rem;
    border-bottom: 1px solid var(--color-border);
    text-align: left;
}

.markets-table th {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.markets-table tbody tr:hover {
    background-color: var(--color-surface);
}

.text-right {
    text-align: right !important;
}

.text-green {
    color: var(--color-neon-green) !important;
}

.text-red {
    color: var(--color-neon-pink) !important;
}

.font-mono {
    font-family: var(--font-mono);
}

/* Sub-indices Table Styling */
.section-heading {
    font-size: 1.5rem;
    padding-bottom: 0.75rem;
    margin-bottom: 0;
    margin-top: 0;
}

.sub-indices-container {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 2rem;
}

.sub-indices-table td {
    font-size: 0.85rem;
}

/* Company Modal */
.company-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    display: none;
    /* Controlled by JS */
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--color-surface);
    width: 95%;
    max-width: 1000px;
    max-height: 90vh;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    overflow-y: auto;
    padding: var(--space-xl);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    z-index: 10001;
}

.close-modal {
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    background: none;
    border: none;
    font-size: 2.5rem;
    color: var(--color-text-muted);
    cursor: pointer;
    line-height: 1;
}

.close-modal:hover {
    color: var(--color-text);
}

.modal-loader {
    text-align: center;
    padding: 5rem;
    color: var(--color-text-muted);
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--color-neon-purple-bright);
    border-radius: 50%;
    margin: 0 auto 1.5rem;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Company Detail Content Styles */
.view-company {
    color: var(--color-neon-purple-bright);
    text-decoration: none;
    font-weight: 700;
    border-bottom: 1px solid transparent;
    transition: all 0.2s;
    cursor: pointer;
}

.view-company:hover {
    border-bottom-color: var(--color-neon-purple-bright);
}

.company-header {
    border-bottom: 1px solid var(--color-border);
    padding-bottom: var(--space-lg);
    margin-bottom: var(--space-lg);
    padding-right: 3rem;
}

.company-title-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 1rem;
}

.company-title-row h2 {
    font-size: 2.5rem;
    margin: 0;
    line-height: 1.1;
}

.company-symbol-badge {
    background: var(--color-bg);
    border: 1px solid var(--color-neon-purple-bright);
    color: var(--color-neon-purple-bright);
    padding: 0.3rem 0.8rem;
    border-radius: 4px;
    font-size: 1rem;
    font-family: var(--font-mono);
    font-weight: 700;
}

.company-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-md);
    margin-bottom: var(--space-xl);
}

.stat-item {
    background: var(--color-bg);
    padding: var(--space-md);
    border: 1px solid var(--color-border);
    border-radius: 8px;
}

.stat-label {
    font-size: 0.7rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    margin-bottom: 0.5rem;
    font-family: var(--font-mono);
    letter-spacing: 1px;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--color-text);
}

.history-chart-outer {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: var(--space-lg);
    margin-bottom: var(--space-xl);
}

.history-chart-container {
    height: 400px;
    width: 100%;
    position: relative;
}

.chart-legend-custom {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
    font-size: 0.8rem;
    color: var(--color-text-muted);
}