/* start of styles.css file */

/* ── base ── */
html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(160deg, #e8edf5 0%, #f0f2f5 40%, #e3ecf7 100%);
    background-attachment: fixed;
    direction: rtl;
    color: #2c3e50;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

/* ── global controls ── */
.global-controls {
    flex-shrink: 0;
    padding: 10px 24px;
    background: #fff;
    border-radius: 0;
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.07), 0 1px 3px rgba(0, 0, 0, 0.04);
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: flex-start;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-bottom: 1px solid rgba(25, 118, 210, 0.08);
    position: sticky;
    top: 0;
    z-index: 50;
}

.global-controls .control-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.global-controls label {
    font-weight: 700;
    color: #607d8b;
    white-space: nowrap;
    font-size: 0.9rem;
    letter-spacing: 0.01em;
}

.global-controls input[type="number"] {
    padding: 8px 12px;
    border: 1.5px solid #dce3eb;
    border-radius: 8px;
    font-size: 0.9rem;
    width: 72px;
    text-align: center;
    font-weight: 600;
    color: #37474f;
    background: #fafbfc;
    transition: border-color 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
}

.global-controls input[type="number"]:focus {
    border-color: #1976d2;
    box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.18);
    background: #fff;
    outline: none;
}

/* ── charts grid ── */
.charts-container-grid {
    flex-grow: 1;
    display: grid;
    gap: 8px;
    padding: 10px 0;
    background: transparent;
    border-radius: 0;
    box-shadow: none;
    min-height: 0;
    align-content: start;
}

/* ── individual chart section ── */
.chart-section {
    display: flex;
    flex-direction: column;
    padding: 0;
    margin: 0;
    box-sizing: border-box;
    background: #fff;
    border: 1px solid #dce3eb;
    border-radius: 14px;
    justify-content: center;
    align-items: center;
    font-size: 1.3rem;
    font-weight: 600;
    color: #1976d2;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.03);
    overflow: hidden;
    transition: box-shadow 0.3s ease, transform 0.2s ease;
}

.chart-section:hover {
    box-shadow: 0 6px 24px rgba(25, 118, 210, 0.1), 0 2px 6px rgba(0, 0, 0, 0.04);
    transform: translateY(-1px);
}

/* ── chart header row ── */
.chart-header-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    background: linear-gradient(180deg, #f6f8fb 0%, #eef1f5 100%);
    padding: 10px 14px;
    flex-shrink: 0;
    width: 100%;
    box-sizing: border-box;
    border-bottom: 1px solid #e4e9f0;
    border-radius: 14px 14px 0 0;
}

.chart-header-actions {
    display: contents;
}

.chart-header-row h3 {
    margin: 0 10px 0 0;
    white-space: nowrap;
    flex-shrink: 0;
    font-size: 15px;
    text-align: right;
    color: #263238;
    font-weight: 700;
    letter-spacing: -0.1px;
}

/* ── drag handle ── */
.drag-handle {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 10px;
    border: 1px solid #cfd8dc;
    border-radius: 7px;
    background: linear-gradient(180deg, #fff 0%, #f5f7f9 100%);
    cursor: grab;
    user-select: none;
    touch-action: none;
    flex-shrink: 0;
    font-size: 14px;
    line-height: 1;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), inset 0 1px 0 rgba(255, 255, 255, 0.9);
    transition: background 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
}

.drag-handle:hover {
    background: linear-gradient(180deg, #f5f7f9 0%, #eceff1 100%);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.drag-handle:active {
    cursor: grabbing;
    background: #e8ebee;
    transform: scale(0.95);
}

/* ── action buttons (duplicate, close) ── */
.chart-action-btn,
.duplicate-chart-btn,
.close-duplicate-btn {
    width: 28px;
    height: 28px;
    margin-left: 8px;
    border: 1px solid #cfd8dc;
    border-radius: 7px;
    background: #fff;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #546e7a;
    transition: all 0.2s ease;
}

.duplicate-chart-btn:hover {
    background: #e3f2fd;
    border-color: #90caf9;
    color: #1565c0;
    box-shadow: 0 2px 6px rgba(25, 118, 210, 0.15);
}

.close-duplicate-btn {
    background: #fff;
    color: #c62828;
    border-color: #ef9a9a;
}

.close-duplicate-btn:hover {
    background: #ffebee;
    border-color: #e57373;
    color: #b71c1c;
    box-shadow: 0 2px 6px rgba(198, 40, 40, 0.15);
}

/* ── duplicate badge ── */
.duplicate-badge {
    margin-right: auto;
    background: linear-gradient(135deg, #fff8e1, #fff3cd);
    color: #8c6d1f;
    font-size: 11px;
    padding: 2px 10px;
    border-radius: 999px;
    border: 1px solid #f7d985;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.chart-section.duplicate-chart {
    opacity: 0.96;
    border-style: dashed;
    border-color: #b3d4f5;
}

.chart-section.dragging {
    opacity: 0.92;
    box-shadow: 0 14px 32px rgba(25, 118, 210, 0.22), 0 4px 10px rgba(0, 0, 0, 0.08);
    cursor: grabbing;
    transform: scale(1.015) rotate(0.5deg);
    z-index: 1000;
    border-color: #90caf9;
}

/* ── category selector ── */
.chart-header-row .category-selector {
    padding: 0;
    background-color: transparent;
    flex-grow: 1;
    justify-content: center;
    width: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.category-btn {
    padding: 3px 9px;
    font-size: 10.5px;
    font-weight: 600;
    border-radius: 14px;
    border: 1.5px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    letter-spacing: 0.01em;
}

.category-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.15);
}

.category-btn.active {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    border-color: rgba(0, 0, 0, 0.08);
}

/* ── chart wrapper ── */
.chart-wrapper {
    flex: 1;
    padding: 12px 14px;
    min-height: 0;
    display: flex;
    flex-direction: column;
    width: 100%;
    box-sizing: border-box;
    background: #fff;
    border-radius: 0 0 14px 14px;
}

/* ── chart.js canvases ── */
#trendChart,
#changeChart,
#changeFromPclChart,
#volChangeChart {
    width: 100%;
    height: auto;
    flex-grow: 1;
    min-height: 0;
}

/* ── slider (volChange) ── */
.slider-container {
    padding: 10px 16px;
    text-align: center;
    flex-shrink: 0;
    width: 100%;
    box-sizing: border-box;
    height: 40px;
}

.slider-container label {
    margin-left: 10px;
    white-space: nowrap;
}

.slider-container input[type="number"] {
    width: calc(100% - 120px);
    vertical-align: middle;
    -webkit-appearance: none;
    appearance: none;
    background: linear-gradient(90deg, #bbdefb, #e3f2fd);
    outline: none;
    height: 8px;
    border-radius: 5px;
    transition: opacity 0.2s;
    opacity: 0.8;
}

.slider-container input[type="number"]:hover {
    opacity: 1;
}

.slider-container input[type="number"]::-webkit-slider-thumb,
.slider-container input[type="number"]::-moz-range-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1976d2, #2196f3);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(25, 118, 210, 0.35);
    border: 2px solid #fff;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.slider-container input[type="number"]::-webkit-slider-thumb:hover,
.slider-container input[type="number"]::-moz-range-thumb:hover {
    transform: scale(1.15);
    box-shadow: 0 3px 12px rgba(25, 118, 210, 0.45);
}

/* ── power filter buttons ── */
.power-filter-container {
    display: flex;
    margin: 0 10px;
    border: 1px solid #cfd8dc;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.power-filter-btn {
    padding: 5px 14px;
    font-size: 12px;
    background-color: #f5f7f9;
    color: #546e7a;
    border: none;
    border-left: 1px solid #cfd8dc;
    cursor: pointer;
    transition: all 0.25s ease;
    font-weight: 500;
}

.power-filter-container .power-filter-btn:first-child {
    border-right: none;
}

.power-filter-btn:hover {
    background-color: #e3f2fd;
    color: #1565c0;
}

.power-filter-btn.active {
    background: linear-gradient(135deg, #1565c0, #1976d2);
    color: white;
    font-weight: 700;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.power-filter-btn:last-child {
    border-left: none;
}

/* ── help button (question mark) ── */
.help-btn {
    margin: 0 0 0 10px;
    padding: 0;
    width: 38px;
    height: 38px;
    border: 1.5px solid #cfd8dc;
    border-radius: 50%;
    background: linear-gradient(180deg, #fff 0%, #f8f9fa 100%);
    cursor: help;
    font-size: 18px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #607d8b;
    flex-shrink: 0;
    box-sizing: border-box;
    line-height: 1;
    transition: all 0.25s ease;
}

.help-btn:hover {
    background: #e3f2fd;
    border-color: #90caf9;
    color: #1565c0;
    box-shadow: 0 2px 8px rgba(25, 118, 210, 0.15);
    transform: scale(1.05);
}

.help-btn.active {
    background: #1976d2;
    border-color: #1565c0;
    color: #fff;
    box-shadow: 0 2px 10px rgba(25, 118, 210, 0.3);
}

.help-btn-wrapper {
    position: relative;
    display: inline-block;
}

/* ── help tooltip ── */
.help-tooltip {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 10px;
    width: 300px;
    background: #fff;
    border: 1px solid #dce3eb;
    border-radius: 12px;
    padding: 14px 16px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.12), 0 2px 6px rgba(0, 0, 0, 0.06);
    font-size: 13px;
    line-height: 1.7;
    z-index: 100;
    color: #37474f;
    white-space: normal;
}

.help-tooltip::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 20px;
    width: 12px;
    height: 12px;
    background: #fff;
    border-top: 1px solid #dce3eb;
    border-right: 1px solid #dce3eb;
    transform: rotate(-45deg);
}

.help-tooltip.visible {
    display: block;
    animation: tooltipFadeIn 0.2s ease forwards;
}

.help-tooltip.tooltip-flip {
    left: auto;
    right: 0;
}

.help-tooltip.tooltip-flip::before {
    left: auto;
    right: 20px;
}

@keyframes tooltipFadeIn {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── help link (top right) ── */
.help {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-right: auto;
    padding: 7px 16px;
    background: linear-gradient(135deg, #00838f, #0097a7);
    color: #fff;
    border-radius: 8px;
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 600;
    letter-spacing: 0.01em;
    box-shadow: 0 2px 8px rgba(0, 151, 167, 0.25);
    transition: all 0.25s ease;
}

.help:hover {
    background: linear-gradient(135deg, #006064, #00838f);
    box-shadow: 0 4px 14px rgba(0, 151, 167, 0.35);
    transform: translateY(-1px);
}

/* ══════════════════════════════════════════════ */
/*  RESPONSIVE                                   */
/* ══════════════════════════════════════════════ */

/* ── mobile ── */
@media (max-width: 768px) {
    #width-control {
        display: none;
    }

    .global-controls input[type="number"] {
        direction: rtl;
        font-family: 'Vazirmatn', 'Segoe UI', sans-serif;
        text-align: right;
    }

    .global-controls {
        padding: 10px 14px;
        gap: 12px;
        flex-wrap: wrap;
        justify-content: center;
    }

    .global-controls .control-group {
        gap: 6px;
    }

    .global-controls label {
        font-size: 0.8rem;
    }

    .global-controls input[type="number"] {
        width: 56px;
        padding: 6px 8px;
        font-size: 0.8rem;
    }

    .charts-container-grid {
        gap: 10px;
        padding: 10px;
        grid-template-columns: 1fr !important;
    }

    .chart-section {
        border-radius: 12px;
    }

    .chart-header-row {
        flex-direction: column;
        align-items: stretch;
        padding: 10px 12px;
        gap: 8px;
        border-radius: 12px 12px 0 0;
    }

    .chart-header-row h3 {
        margin: 0;
        width: 100%;
        text-align: center;
        font-size: 14px;
        order: 1;
    }

    .chart-header-actions {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        order: 3;
        width: 100%;
    }

    .drag-handle {
        width: 24px;
        height: 24px;
        margin-left: 6px;
        font-size: 12px;
        border-radius: 6px;
    }

    .chart-header-row .category-selector {
        justify-content: center;
        width: 100%;
        gap: 4px;
        order: 2;
    }

    .category-btn {
        padding: 4px 10px;
        font-size: 11px;
        border-radius: 12px;
    }

    .power-filter-container {
        margin: 0;
        justify-content: center;
        width: 100%;
    }

    .power-filter-btn {
        padding: 6px 14px;
        font-size: 12px;
        flex: 1;
        text-align: center;
    }

    .help-btn {
        width: 32px;
        height: 32px;
        font-size: 15px;
        margin: 0 6px;
    }

    .help-btn-wrapper {
        position: static;
    }

    .help-tooltip {
        position: fixed;
        top: 50%;
        left: 50%;
        right: auto;
        transform: translate(-50%, -50%);
        width: calc(100vw - 40px);
        max-width: 340px;
        max-height: 60vh;
        overflow-y: auto;
        z-index: 200;
        border-radius: 16px;
    }

    .help-tooltip::before {
        display: none;
    }

    .duplicate-chart-btn {
        width: 24px;
        height: 24px;
        font-size: 14px;
        margin-left: 6px;
    }

    .close-duplicate-btn {
        width: 24px;
        height: 24px;
        font-size: 14px;
        margin-left: 6px;
    }

    .chart-wrapper {
        padding: 8px 10px;
        border-radius: 0 0 12px 12px;
    }

    .slider-container {
        padding: 8px 12px;
        height: 36px;
    }

    .slider-container input[type="number"] {
        width: 100%;
    }

    .duplicate-badge {
        font-size: 10px;
        padding: 2px 8px;
    }

    .help {
        font-size: 12px;
        padding: 6px 12px;
    }
}