/* ============================================================
   stockshow-base.css — استایل‌های مشترک دسکتاپ + موبایل
   شامل: متغیرها، table، mini-chart، tooltips، chip، reset
   ============================================================ */

/* ---------- CSS Variables ---------- */
:root {
    --primary: #2459a9;
    --primary-dark: #173f7a;
    --primary-light: #eaf2ff;
    --success: #238653;
    --danger: #c62828;
    --warning: #ff9800;
    --bg: #f4f6fa;
    --card-bg: #ffffff;
    --border: #e1e8f0;
    --text: #172b4d;
    --text-muted: #63748b;
    --shadow-sm: 0 1px 3px rgba(23,43,77,0.08);
    --shadow-md: 0 4px 12px rgba(23,43,77,0.12);
    --shadow-lg: 0 12px 32px rgba(23,43,77,0.18);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 20px;
    --transition: cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
    font-family: 'VazirmatnUI', Vazir, Tahoma, sans-serif;
    direction: rtl;
    text-align: right;
    color: var(--text);
    background: var(--bg);
    margin: 0;
    padding: 0;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior-y: contain;
}

/* ---------- Base Table ---------- */
#market-table { width: 100% !important; }
table.dataTable {
    width: 100% !important;
    table-layout: fixed !important;
    max-width: 100%;
    border-collapse: separate !important;
    border-spacing: 0 !important;
}
table.dataTable thead th {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 100;
    padding: 8px 4px;
    font-size: 12px;
    font-weight: 600;
    text-align: center;
    border: none !important;
    white-space: normal;
    word-wrap: break-word;
    line-height: 1.2;
    vertical-align: middle;
}
table.dataTable tbody td {
    min-height: 0 !important;
    border: none !important;
    border-bottom: 1px solid var(--border) !important;
    padding: 4px 6px !important;
    line-height: 1.2 !important;
    text-align: center;
    white-space: nowrap !important;
    font-size: 11px !important;
    overflow: visible !important;
    transition: background-color 0.2s ease;
    text-overflow: ellipsis !important;
}
table.dataTable tbody tr:last-child td { border-bottom: none !important; }
table.dataTable tbody tr,
table.dataTable tbody tr.odd,
table.dataTable tbody tr.even { height: auto !important; min-height: 32px !important; }
table.dataTable tbody tr:nth-child(even) { background: #fafbfc; }
table.dataTable tbody tr:nth-child(odd) { background: #FFFFFF; }
table.dataTable tbody tr:hover { background-color: #E8F4FD !important; }

/* ---------- Column Search ---------- */
.search-input-wrapper { position: relative; width: 90%; margin: 2px auto; }
.search-input-wrapper input.column-search {
    width: 100%;
    padding: 4px 8px 4px 22px;
    box-sizing: border-box;
    direction: rtl;
    text-align: right;
    font-family: inherit;
    font-size: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.search-input-wrapper input.column-search:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(36,89,169,0.15);
}
.search-input-wrapper .clear-search-btn {
    position: absolute;
    left: 6px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 18px;
    font-weight: bold;
    color: #999;
    cursor: pointer;
    display: none;
    line-height: 1;
    user-select: none;
}
.search-input-wrapper .clear-search-btn:hover { color: var(--danger); }

/* ---------- DataTables controls ---------- */
.dataTables_wrapper { direction: rtl; text-align: right; }
.dataTables_filter { float: right; text-align: right; margin-bottom: 10px; }
.dataTables_filter input { margin-right: 5px; direction: ltr; text-align: left; }
.dataTables_paginate { float: left; margin-top: 5px; }
.dataTables_info { float: right; margin-top: 10px; }

/* ---------- Loading ---------- */
.loading-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255,255,255,0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(3px);
}
.loading-spinner {
    display: inline-block;
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid var(--primary);
    border-radius: 50%;
    animation: mwSpin 1s linear infinite;
}
@keyframes mwSpin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
.loading-text {
    margin-top: 15px;
    font-size: 16px;
    color: var(--primary);
    text-align: center;
}
.loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: white;
    padding: 20px;
    border-radius: var(--radius);
    box-shadow: 0 12px 35px rgba(23,43,77,0.13);
}

/* ---------- Error ---------- */
.error-message {
    color: #a61b1b;
    text-align: center;
    padding: 20px;
    background: #fff5f5;
    border: 1px solid #f2c6c6;
    border-radius: var(--radius);
    margin: 20px;
}

/* ---------- Highlight ---------- */
.highlight-change { animation: highlight 2s ease-in-out; }
@keyframes highlight {
    0% { background-color: #ffff99; }
    50% { background-color: #ffff99; }
    100% { background-color: transparent; }
}
.highlight-negative { animation: highlight-red 2s ease-in-out; }
@keyframes highlight-red {
    0% { background-color: #ffcccc; }
    50% { background-color: #ffcccc; }
    100% { background-color: transparent; }
}

/* ---------- Update Status ---------- */
#simple-update-status {
    position: fixed;
    top: 78px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: var(--primary-dark);
    color: white;
    padding: 10px 20px;
    border-radius: 999px;
    font-size: 13px;
    z-index: 2100;
    display: none;
    box-shadow: var(--shadow-md);
    opacity: 0;
    transition: all 0.3s var(--transition);
    white-space: nowrap;
    max-width: 90vw;
    overflow: hidden;
    text-overflow: ellipsis;
}
#simple-update-status.visible {
    display: block;
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ---------- Mini Chart ---------- */
.chart-cell {
    padding: 0 !important;
    vertical-align: middle !important;
    text-align: center !important;
    overflow: visible !important;
}
table.dataTable tbody td.chart-cell {
    overflow: visible !important;
    padding: 0 !important;
}
.mini-chart {
    width: 100% !important;
    min-width: 60px;
    max-width: 100%;
    height: 26px;
    position: relative;
    margin: 0 auto;
    direction: ltr;
    font-family: Tahoma, Arial, sans-serif;
    overflow: visible !important;
    z-index: 1;
    transition: z-index 0.1s ease;
}
.mini-chart:hover { z-index: 1000 !important; }
.mini-chart .full-range {
    position: absolute;
    top: 11px; height: 4px;
    background: #ccc;
    left: 0; right: 0;
    z-index: 0;
    cursor: default;
}
.mini-chart .trade-range {
    position: absolute;
    top: 11px; height: 4px;
    z-index: 1;
    pointer-events: none;
}
.mini-chart .marker-open {
    position: absolute;
    top: 9px;
    width: 3px; height: 8px;
    background: #ffa07a;
    z-index: 2;
}
.mini-chart .triangle-last {
    position: absolute;
    top: 2px;
    width: 0; height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 6px solid #44808b;
    transform: translateX(-50%);
    z-index: 3;
}
.mini-chart .triangle-close {
    position: absolute;
    top: 18px;
    width: 0; height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-bottom: 6px solid #44808b;
    transform: translateX(-50%);
    z-index: 3;
}
.mini-chart .dashed-yesterday {
    position: absolute;
    top: 8px;
    height: 10px;
    width: 2px;
    border-left: 2px dashed #ff4500;
    z-index: 1;
}
.mini-chart .dashed-yesterday::before {
    content: '';
    position: absolute;
    left: -6px; top: 0;
    width: 14px; height: 100%;
}
.mini-chart .static-tooltip {
    position: absolute;
    background: #222;
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 10px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    z-index: 1000000 !important;
    box-shadow: 0 2px 6px rgba(0,0,0,0.4);
    transform: translateX(-50%);
}
.mini-chart .triangle-last:hover .static-tooltip,
.mini-chart .triangle-close:hover .static-tooltip,
.mini-chart .marker-open:hover .static-tooltip,
.mini-chart .dashed-yesterday:hover .static-tooltip { opacity: 1; }
.mini-chart .triangle-last .static-tooltip { top: -24px; left: 50%; }
.mini-chart .triangle-close .static-tooltip { top: 14px; left: 50%; }
.mini-chart .marker-open .static-tooltip { top: -24px; left: 50%; }
.mini-chart .dashed-yesterday .static-tooltip { top: -24px; left: 50%; }

/* ---------- Inline Queue ---------- */
.inline-queue {
    display: grid;
    grid-template-columns: 1fr 2.5fr 1.5fr 2px 1.5fr 2.5fr 1fr;
    align-items: center;
    justify-content: stretch;
    font-size: 10.5px;
    font-family: inherit;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    overflow: hidden;
    height: 26px;
    margin: 0;
    direction: rtl;
    width: 100%;
    max-width: 100%;
    background-color: #fff;
    box-sizing: border-box;
}
.inline-queue .q-item {
    padding: 0;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 26px;
    font-weight: 600;
}
.inline-queue .q-buy { background-color: #f0fdf4; color: #166534; }
.inline-queue .q-sell { background-color: #fef2f2; color: #991b1b; }
.inline-queue .q-divider { background-color: #9ca3af; height: 100%; width: 100%; }
.inline-queue .q-item:hover { filter: brightness(0.95); cursor: help; }
.inline-queue .q-price { font-weight: 700; font-size: 12px; }

/* ---------- Tooltips ---------- */
.bestLimitsTooltip {
    position: absolute;
    background: white;
    border: 1px solid #d9e2ee;
    border-radius: 12px;
    box-shadow: 0 16px 42px rgba(23,43,77,0.18);
    z-index: 3000;
    max-width: 400px;
    width: max-content;
    padding: 0;
    font-family: inherit;
    font-size: 0.9rem;
    color: #333;
}
.bestLimitsTooltip table {
    border-collapse: collapse;
    width: 100%;
    margin: 0;
    box-shadow: none;
    overflow: hidden;
    border-radius: 12px;
}
.bestLimitsTooltip table th,
.bestLimitsTooltip table td {
    border: 1px solid #e1e8f0;
    padding: 8px;
    text-align: center;
}
.bestLimitsTooltip th.buygrp {
    background: linear-gradient(to bottom, #e0f2f1, #b2dfdb);
    color: #00695c;
}
.bestLimitsTooltip th.sellgrp {
    background: linear-gradient(to bottom, #ffe6e6, #ffd1d1);
    color: #c62828;
}
.bestLimitsTooltip tbody td { color: #333 !important; }
.bestLimitsTooltip td.buygrp { background-color: #f1f8e9; }
.bestLimitsTooltip td.sellgrp { background-color: #fff7f7; }
.bestLimitsTooltip .loader {
    display: block;
    margin: 15px auto;
    width: 20px; height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #00796b;
    border-radius: 50%;
    animation: mwSpin 1s linear infinite;
}
.bestLimitsTooltip .error { color: #d32f2f; text-align: center; padding: 10px; font-size: 0.9rem; }
.bestLimitsTooltip tbody td.outOfRangeBuyRow { opacity: 0.6; background-color: #e8f5e8 !important; color: #555 !important; }
.bestLimitsTooltip tbody td.outOfRangeSellRow { opacity: 0.6; background-color: #ffe6e6 !important; color: #555 !important; }

.historicalPriceTooltip {
    position: absolute;
    background-color: white;
    border: 1px solid #d9e2ee;
    border-radius: 12px;
    box-shadow: 0 16px 42px rgba(23,43,77,0.18);
    z-index: 1000;
    padding: 10px;
    font-family: inherit;
    font-size: 12px;
    max-width: 650px;
    max-height: 450px;
    overflow: hidden;
}
.historicalPriceTooltip .loading-container { padding: 10px; }
.historicalPriceTooltip .error-message { padding: 10px; color: red; }

.shareholder-tooltip {
    position: absolute;
    background-color: #ffffff;
    border: 1px solid #d9e2ee;
    border-radius: 12px;
    box-shadow: 0 16px 42px rgba(23,43,77,0.18);
    z-index: 1000;
    padding: 8px;
    font-family: inherit;
    font-size: 13px;
    color: #333;
    max-width: 580px;
    min-width: 500px;
    overflow: hidden;
}
.shareholder-tooltip table.shareholder-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    table-layout: fixed;
}
.shareholder-tooltip table.shareholder-table th {
    background-color: #f8f9fa;
    color: #495057;
    font-weight: bold;
    border: 1px solid #e1e8f0;
    padding: 6px 4px;
    text-align: center;
    vertical-align: middle;
}
.shareholder-tooltip table.shareholder-table td {
    border: 1px solid #e1e8f0;
    padding: 6px 4px;
    text-align: center;
    vertical-align: middle;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.shareholder-tooltip .shareholder-summary {
    margin-top: 10px;
    padding: 8px;
    border-top: 1px solid #ccc;
    font-size: 12px;
    background-color: #f8f9fa;
    border-radius: 4px;
}
.shareholder-tooltip .shareholder-summary p { margin: 4px 0; line-height: 1.4; }
.shareholder-tooltip .shareholder-symbol-title {
    margin: 0 0 7px;
    padding: 7px 9px;
    border: 1px solid #d8e5f8;
    border-radius: 8px;
    background: #edf4ff;
    color: #173f7a;
    font-size: 12px;
    font-weight: 800;
    text-align: right;
}

.fixed-pos-tl { position: fixed; top: 120px; left: 20px; z-index: 3000; min-width: 500px; max-width: 95vw; }
.fixed-pos-br { position: fixed; bottom: 25px; left: 20px; z-index: 3000; max-width: 650px; }
.fixed-pos-bl { position: fixed; bottom: 25px; left: 650px; z-index: 3000; max-width: 600px; }

/* ---------- Keyboard Row ---------- */
.keyboard-selected-row { background-color: #b3d9ff !important; }
#market-table_wrapper table.dataTable tbody tr.keyboard-selected-row td:not(.chart-cell) {
    background: #dceaff !important;
    box-shadow: inset 0 1px 0 #c4d9fb, inset 0 -1px 0 #c4d9fb;
}
#market-table_wrapper table.dataTable tbody tr.keyboard-selected-row td .clickable-symbol {
    color: #123b77 !important;
    font-weight: 800 !important;
    text-decoration: underline !important;
    text-underline-offset: 3px;
}

/* ---------- Symbol Cell ---------- */
.clickable-symbol {
    cursor: pointer;
    user-select: none;
    color: var(--primary) !important;
    font-weight: 700;
    text-decoration: none !important;
}
.clickable-symbol:hover {
    color: var(--primary-dark) !important;
    text-decoration: underline !important;
    text-underline-offset: 3px;
}

/* ---------- Negative Numbers ---------- */
.negative-number {
    color: var(--danger) !important;
    font-weight: 700 !important;
    direction: ltr;
    unicode-bidi: isolate;
}

/* ---------- Queue Chips (مشترک) ---------- */
#queue-filter-container,
#queue-filter-secondary-container {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 4px 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    min-width: 0;
}
#queue-filter-container::-webkit-scrollbar,
#queue-filter-secondary-container::-webkit-scrollbar { display: none; }

.queue-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: white;
    border: 1.5px solid var(--border);
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s var(--transition);
    user-select: none;
    flex-shrink: 0;
    animation: chipIn 0.25s cubic-bezier(0.4, 0, 0.2, 1) both;
}
@keyframes chipIn {
    from { opacity: 0; transform: translateY(6px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.queue-chip:hover:not(.active) {
    background: rgba(36,89,169,0.06);
    border-color: var(--primary) !important;
}
.queue-chip.active {
    color: white;
    border-color: transparent;
    box-shadow: 0 2px 8px rgba(0,0,0,0.18);
}
.queue-chip input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 0; height: 0;
}
.queue-chip:focus-within {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* ---------- Header actions (shared baseline) ---------- */
.header-container {
    position: sticky;
    top: 0;
    background: rgba(255,255,255,0.96);
    z-index: 1000;
    padding: 12px clamp(14px, 2vw, 28px);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 4px 20px rgba(23,43,77,0.07);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}
.header-container h2 { margin: 0; color: var(--text); font-size: clamp(17px, 1.35vw, 21px); font-weight: 700; }
#update-time { color: var(--text-muted); font-size: 11px; margin-top: 3px; }
.header-actions { display: flex; align-items: center; gap: 8px; min-width: max-content; }
.home-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 8px 13px;
    border: 1px solid #cbd8e8;
    border-radius: 10px;
    background: #f7faff;
    color: var(--primary) !important;
    font-size: 12px;
    font-weight: 700;
    text-decoration: none !important;
    white-space: nowrap;
    transition: background-color .18s ease, border-color .18s ease, transform .18s ease;
}
.home-btn:hover { background: var(--primary-light); border-color: #a8c4ee; transform: translateY(-1px); }
.export-btn {
    justify-self: end;
    min-height: 40px;
    padding: 8px 16px !important;
    border: 1px solid #1e8449 !important;
    border-radius: 10px !important;
    background: linear-gradient(135deg, #238653, #176b43) !important;
    box-shadow: 0 4px 10px rgba(35,134,83,0.16);
    color: white;
    font-weight: 600 !important;
    white-space: nowrap;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s var(--transition);
}
.export-btn:hover { transform: translateY(-1px); box-shadow: 0 7px 15px rgba(35,134,83,0.22); }

/* ---------- Main layout base ---------- */
.main-layout {
    display: flex;
    flex-direction: column;
    padding: 16px clamp(10px, 1.6vw, 24px) 28px;
    gap: 12px;
}

/* ---------- Filter Overlay (base) — برای هر دو حالت ---------- */
.filter-overlay {
    display: none;
    box-sizing: border-box;
}
.filter-overlay[style*="display: flex"],
.filter-overlay[style*="display:flex"] {
    display: flex !important;
    flex-direction: column;
}

.content-area { position: relative; display: flex; gap: 14px; justify-content: flex-end; align-items: flex-start; }
.table-wrapper {
    flex: 1;
    min-width: 0;
    position: relative;
    padding: 8px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

/* ---------- Scrollbars ---------- */
@media (hover: hover) {
    ::-webkit-scrollbar { width: 8px; height: 8px; }
    ::-webkit-scrollbar-track { background: transparent; }
    ::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
    ::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
}

/* ---------- Focus ring ---------- */
button:focus-visible,
a:focus-visible,
input:focus-visible,
.bs-chip:focus-visible,
.industry-item:focus-visible,
.queue-chip:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
/* ---------- Filter Overlay — تعریف پایه با اولویت پایین ---------- */
.filter-overlay {
    display: none;
    box-sizing: border-box;
    z-index: 2000;
}

/* وقتی از JavaScript نمایش داده می‌شود */
.filter-overlay.mw-open,
.filter-overlay[style*="display: flex"],
.filter-overlay[style*="display:flex"] {
    display: flex !important;
    flex-direction: column;
}