/* ============================================================
   INDICATOR PANES - legend and settings dialog (js/indicator-panes.js)

   The legend sits over the chart at the top of each pane, the way
   TradingView's does: "RSI 14 close 60.39 62.35", the values in their
   plot's colour, hide / settings / remove on hover (on a tap on a touch
   screen). In Arabic it mirrors to the other side of the pane, clear of
   the price scale; the figures stay left-to-right (css/locale.css rule).
   ============================================================ */

.ip-legends {
    position: absolute;
    inset: 0;
    pointer-events: none;
    /* Over the chart canvas and the drawing layer (z-index 10), under the
       loading veil's spinner only in effect (it is centred). */
    z-index: 11;
    overflow: hidden;
}

.ip-row {
    position: absolute;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    padding: 1px 4px;
    border-radius: 4px;
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    font-weight: 500;
    line-height: 20px;
    color: var(--text-primary);
    white-space: nowrap;
    pointer-events: auto;
    user-select: none;
    -webkit-user-select: none;
    cursor: default;
}
.ip-row[hidden] { display: none; }
.ip-row:focus { outline: none; }
.ip-row:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.ip-row:hover,
.ip-row.ip-open,
.ip-row:focus-within { background: rgba(10, 14, 23, 0.72); }
html[data-theme="light"] .ip-row:hover,
html[data-theme="light"] .ip-row.ip-open,
html[data-theme="light"] .ip-row:focus-within { background: rgba(255, 255, 255, 0.85); }

.ip-title {
    display: inline-flex;
    gap: 6px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ip-name { color: var(--text-primary); }
.ip-inputs { color: var(--text-secondary); }
.ip-inputs[hidden] { display: none; }

.ip-vals {
    display: inline-flex;
    gap: 6px;
    font-variant-numeric: tabular-nums;
}
/* Figures stay left-to-right in an Arabic page. */
.ip-v { direction: ltr; unicode-bidi: isolate; }

/* A row longer than its pane (Ichimoku's name, inputs and five values on a
   phone) wraps: the values go under the name instead of squeezing the name
   out of sight. The rows stack by their height (Legend.layout). */
.ip-row { flex-wrap: wrap; row-gap: 0; }
.ip-vals { flex-wrap: wrap; row-gap: 0; }
/* On a touch screen a tap opens a row for its buttons: the values make room
   for them until the next tap, so an open row never grows over the row
   below it. */
@media (hover: none) {
    .ip-row.ip-open .ip-vals { display: none; }
}

.ip-btns { display: none; gap: 1px; }
.ip-row:hover .ip-btns,
.ip-row.ip-open .ip-btns,
.ip-row:focus-within .ip-btns { display: inline-flex; }

.ip-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 20px;
    padding: 0;
    border: 0;
    border-radius: 3px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
}
.ip-btn[hidden] { display: none; }
.ip-btn:hover { background: var(--hover-surface-strong); color: var(--text-bright); }
.ip-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; }
.ip-btn[aria-pressed="true"] { color: var(--accent); }

/* Hidden with the eye: the name stays, dimmed, so it can be shown again. */
.ip-row.ip-hidden .ip-name,
.ip-row.ip-hidden .ip-inputs { opacity: 0.45; }
.ip-row.ip-hidden .ip-vals { display: none; }

/* Touch: bigger targets, and the buttons come with a tap on the legend. */
@media (pointer: coarse) {
    .ip-row { font-size: 11px; line-height: 22px; }
    .ip-btn { width: 30px; height: 26px; }
}

/* ---------- Settings dialog ---------- */
.ip-dlg-wrap {
    position: fixed;
    inset: 0;
    z-index: 5000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.ip-dlg-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
}
.ip-dlg {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 400px;
    max-width: calc(100vw - 24px);
    max-height: calc(100vh - 48px);
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    line-height: 1.4;
}
.ip-dlg-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 10px 6px 16px;
}
.ip-dlg-title {
    flex: 1;
    min-width: 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-bright);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ip-dlg-x {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
}
.ip-dlg-x:hover { background: var(--hover-surface-strong); color: var(--text-bright); }

.ip-dlg-tabs {
    display: flex;
    gap: 18px;
    padding: 0 16px;
    border-bottom: 1px solid var(--border-primary);
}
.ip-dlg-tab {
    padding: 8px 0 7px;
    border: 0;
    border-bottom: 2px solid transparent;
    background: none;
    color: var(--text-secondary);
    font: inherit;
    font-weight: 500;
    cursor: pointer;
}
.ip-dlg-tab[hidden] { display: none; }
.ip-dlg-tab[aria-selected="true"] { color: var(--text-bright); border-bottom-color: var(--accent); }
.ip-dlg-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.ip-dlg-body {
    flex: 1;
    min-height: 120px;
    overflow: auto;
    padding: 6px 16px 12px;
}
.ip-dlg-group {
    margin: 12px 0 4px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* Inputs: label, then the control at the end of the row. */
.ip-f {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 12px;
    padding: 5px 0;
}
.ip-f[hidden] { display: none; }
.ip-f label { color: var(--text-secondary); }

/* Style: on/off, name, then colour / width / value. */
.ip-s {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 5px 0;
}
.ip-s label { color: var(--text-primary); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ip-c { display: inline-flex; align-items: center; gap: 6px; }

.ip-dlg input[type="number"],
.ip-dlg select {
    height: 30px;
    padding: 0 8px;
    border: 1px solid var(--border-secondary);
    border-radius: 4px;
    background: var(--bg-input);
    color: var(--text-primary);
    font: inherit;
}
.ip-dlg input[type="number"] { width: 96px; font-variant-numeric: tabular-nums; }
.ip-dlg .ip-f select { min-width: 150px; max-width: 200px; }
.ip-dlg .ip-s select { width: 64px; }
.ip-dlg input[type="number"]:focus,
.ip-dlg select:focus { outline: none; border-color: var(--accent); }
.ip-dlg input[type="color"] {
    width: 32px;
    height: 30px;
    padding: 2px;
    border: 1px solid var(--border-secondary);
    border-radius: 4px;
    background: var(--bg-input);
    cursor: pointer;
}
.ip-dlg input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--accent-fill);
    cursor: pointer;
}

.ip-dlg-foot {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-top: 1px solid var(--border-primary);
}
.ip-dlg-gap { flex: 1; }
.ip-dlg-btn {
    height: 32px;
    padding: 0 14px;
    border: 1px solid var(--border-secondary);
    border-radius: 6px;
    background: transparent;
    color: var(--text-primary);
    font: inherit;
    font-weight: 500;
    cursor: pointer;
}
.ip-dlg-btn:hover { background: var(--hover-surface-strong); }
.ip-dlg-ok { background: var(--accent-fill); border-color: var(--accent-fill); color: #fff; }
.ip-dlg-ok:hover { background: var(--accent-fill-hover); }
.ip-dlg-btn:focus-visible,
.ip-dlg-x:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Phone: a sheet from the bottom edge. */
@media (max-width: 767px), (pointer: coarse) and (orientation: landscape) and (max-height: 500px) {
    .ip-dlg-wrap { align-items: flex-end; }
    .ip-dlg {
        width: 100%;
        max-width: 100%;
        max-height: 85vh;
        border-radius: 14px 14px 0 0;
        border-bottom: 0;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    .ip-dlg input[type="number"],
    .ip-dlg select { height: 36px; font-size: 16px; }   /* 16px: no zoom on focus (iOS) */
    .ip-dlg-btn { height: 40px; }
}

/* Arabic: the dialog mirrors with the page (grid and flex follow dir);
   the head's padding is the one physical offset. */
html[dir="rtl"] .ip-dlg-head { padding: 12px 16px 6px 10px; }
