@import url("./card-foundation.css");
@import url("./market-card-shared.css");

:root {
  /* фон/текст совпадают с основным сайтом (globals.css theme-b: rgb(13,20,33)) */
  --bg: #0d1421;
  --panel: #161b22;
  --panel-2: #1c232c;
  --border: #2a313c;
  --text: #f8fafc;
  --muted: #8b97a7;
  --grid: rgba(139,151,167,.16);
  --oi: #2ea043;
  --oi-soft: rgba(46,160,67,.85);
  --price: #e0a82e;
  --accent: #388bfd;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
}
html.light, body.light {
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-2: #f0f3f6;
  --border: #d8dee4;
  --text: #111827;
  --muted: #656d76;
  --grid: rgba(101,109,118,.16);
  --oi: #1a7f37;
  --oi-soft: rgba(26,127,55,.8);
  --price: #bf8700;
  --accent: #0969da;
  --shadow: 0 1px 3px rgba(140,149,159,.25);
}

body.embedded { background: var(--bg); min-height: 100vh; }

/* ───── Toolbar ───── */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 14px; }
/* кастомный дропдаун монет (макс. 15 видимых, дальше скролл) */
.coin-dd { position: relative; }
.coin-dd-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  min-width: 190px; max-width: 240px; padding: 7px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  font: inherit; cursor: pointer;
}
.coin-dd-btn:hover { border-color: var(--accent); }
.coin-dd.open .coin-dd-btn, .coin-dd-btn:focus { outline: none; border-color: var(--accent); }
.coin-dd-caret {
  flex: 0 0 auto; width: 0; height: 0; border-left: 5px solid transparent;
  border-right: 5px solid transparent; border-top: 6px solid var(--muted); transition: transform .15s;
}
.coin-dd.open .coin-dd-caret { transform: rotate(180deg); }
.coin-dd-list {
  position: absolute; z-index: 40; top: calc(100% + 4px); left: 0; min-width: 100%;
  margin: 0; padding: 4px; list-style: none; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow);
}
.coin-dd-list[hidden] { display: none; }
.coin-dd-list li {
  padding: 7px 10px; border-radius: 6px; cursor: pointer; white-space: nowrap; color: var(--text);
}
.coin-dd-list li:hover { background: var(--panel-2); }
.coin-dd-list li.active { background: var(--accent); color: #fff; }
.coin-dd-list::-webkit-scrollbar { width: 9px; }
.coin-dd-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }
.periods { display: flex; gap: 4px; flex-wrap: wrap; }
.periods button {
  padding: 7px 11px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel); color: var(--muted); font: inherit; cursor: pointer;
}
.periods button:hover { color: var(--text); }
.periods button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.meta { margin-left: auto; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.stale-badge { background: rgba(229,83,75,.14); color: #e5534b; border: 1px solid #e5534b; border-radius: 6px; padding: 1px 6px; font-size: 11px; }
.errbox { margin-bottom: 14px; padding: 10px 12px; border-radius: 8px; background: rgba(229,83,75,.14); border: 1px solid #e5534b; color: #e5534b; font-size: 13px; }

/* ───── Chart card ───── */
/* у обёртки общего фона НЕТ — карточки отдельные у графика и у панели */
.oichart { margin-bottom: 16px; }
.oichart-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 6px; }
.oichart-title { font-size: 16px; margin: 0; font-weight: 700; }
.oichart-keys { display: flex; gap: 14px; color: var(--muted); font-size: 12px; }
.oichart-keys .key { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.sw.oi { background: var(--oi); }
.sw.price { background: var(--price); }
.oichart-empty { padding: 40px; text-align: center; color: var(--muted); }

/* график+навигатор слева (своя карточка), панель-легенда — своя карточка справа */
.oichart-body { display: flex; gap: 14px; align-items: flex-start; }
.oichart-left {
  flex: 1 1 auto; min-width: 0; padding: 14px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.oichart-side { flex: 0 0 200px; }
.oichart-plot { position: relative; width: 100%; }
.oichart-svg { width: 100%; height: 340px; display: block; touch-action: pan-y; }

/* ───── Навигатор (мини-график + окно-браш под основным) ───── */
.oichart-nav { width: 100%; margin-top: 6px; }
.oichart-navsvg { width: 100%; height: 52px; display: block; touch-action: none; }
.oichart-navsvg .navarea { fill: var(--oi-soft); opacity: .35; stroke: none; }
.oichart-navsvg .navdim { fill: var(--bg); opacity: .55; pointer-events: none; }
.oichart-navsvg .navwin { fill: rgba(56,139,253,.10); stroke: var(--accent); stroke-width: 1; vector-effect: non-scaling-stroke; cursor: grab; }
.oichart-navsvg .navwin:active { cursor: grabbing; }
.oichart-navsvg .navh { fill: var(--accent); opacity: .9; cursor: ew-resize; rx: 1.5; }
.oichart-navsvg .navh:hover { opacity: 1; }
.oichart-svg .barea { fill: var(--oi-soft); stroke: none; }

/* элементы svg */
.oichart-svg .grid { stroke: var(--grid); stroke-width: 1; vector-effect: non-scaling-stroke; }
.oichart-svg .bar { fill: var(--oi-soft); }
.oichart-svg .pline { fill: none; stroke: var(--price); stroke-width: 1.6; vector-effect: non-scaling-stroke; }
.oichart-svg .cross { stroke: var(--accent); stroke-width: 1; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
.oichart-svg .barhi { fill: rgba(56,139,253,.14); }
.oichart-svg .axl { fill: var(--muted); font-size: 12px; text-anchor: start; }
.oichart-svg .axr { fill: var(--muted); font-size: 12px; text-anchor: end; }
.oichart-svg .axx { fill: var(--muted); font-size: 12px; text-anchor: middle; }

/* ───── Tip / легенда по биржам ───── */
.oichart-tip {
  width: 100%;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 11px 13px; font-size: 12px; pointer-events: none;
}
.tip-date { font-weight: 700; margin-bottom: 6px; font-size: 12.5px; }
.tip-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 2px 0; }
.tip-ex { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); white-space: nowrap; }
.tip-v { font-variant-numeric: tabular-nums; font-weight: 600; }
.tip-row.off .tip-v { color: var(--muted); font-weight: 400; }
.tip-row.tip-price .tip-v { color: var(--price); }
.tip-total { margin-top: 5px; padding-top: 6px; border-top: 1px solid var(--border); }
.tip-total .tip-ex { color: var(--text); font-weight: 700; }
.tip-total .tip-v { color: var(--oi); font-weight: 800; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: 0 0 8px; }
.dot-price { background: var(--price); }
.dot-binance { background: #f3ba2f; }
.dot-bybit { background: #ff8a65; }
.dot-okx { background: #4fc3f7; }
.dot-bitget { background: #26d9c7; }
.dot-deribit { background: #b388ff; }
.dot-cme { background: #4e8cff; }

/* ───── Объяснение ───── */
.explain { margin-top: 18px; padding: 14px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--border); }
.explain h3 { margin: 0 0 8px; font-size: 14px; }
.explain p { margin: 0 0 8px; color: var(--text); }
.explain .disclaimer { color: var(--muted); font-size: 12px; margin-bottom: 0; }

@media (max-width: 760px) {
  .oichart-body { flex-direction: column; gap: 10px; }
  .oichart-side { flex-basis: auto; }
}
@media (max-width: 560px) {
  .oichart-svg { height: 280px; }
  .oichart-tip { font-size: 11px; padding: 8px 10px; }
  .coin-dd, .coin-dd-btn { width: 100%; max-width: none; }
  .meta { margin-left: 0; }
}

/* ───── Card-режим виджета главной (?layout=card) — точь-в-точь Tlap-Longshort-Ratio ───── */
/* Card-режим главной: держим цепочку height:100% (иначе строки-flex схлопываются)
   и даём панельный фон как у всех виджетов грида (1:1 с Tlap-Longshort-Ratio). */
html:has(body.card-layout), body.card-layout { height: 100%; }
body.card-layout { overflow: hidden; min-height: 0; background: #222531; }
html.light body.card-layout, body.card-layout.light { background: #ffffff; }
body.card-layout .wrap { display: block; padding: 0; margin: 0; max-width: none; height: 100%; }
.oicard { display: flex; flex-direction: column; height: 100%; padding: 10px 13px; box-sizing: border-box; gap: 6px; }
.oicard-head { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.oicard-name { font-size: 13px; font-weight: 800; color: var(--text); white-space: nowrap; letter-spacing: -0.01em; }
.oic-coin { font-size: 12px; font-weight: 700; color: var(--accent); white-space: nowrap; background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 1px 7px; }
.oicard-ctrls { display: flex; align-items: center; gap: 6px; flex-shrink: 0; margin-left: auto; }
.oic-arrow { display: inline-flex; flex-shrink: 0; align-items: center; justify-content: center; width: 22px; height: 22px; padding: 0; cursor: pointer; color: #ffffff; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1); border-radius: 50%; transition: all 0.2s; }
.oic-arrow:hover { background: rgba(255,255,255,0.1); }
html.light .oic-arrow, body.light .oic-arrow { color: #000000; background: rgba(0,0,0,0.04); border-color: rgba(0,0,0,0.1); }
html.light .oic-arrow:hover, body.light .oic-arrow:hover { background: rgba(0,0,0,0.08); }
.oic-page { display: inline-flex; align-items: center; justify-content: center; height: 26px; padding: 0 11px; color: #94a3b8; font-family: inherit; font-size: 11px; font-weight: 600; line-height: 1; text-decoration: none; white-space: nowrap; background: rgba(255,255,255,0.08); border: 1px solid transparent; border-radius: 7px; transition: background .2s, color .2s; }
.oic-page:hover { color: #f1f5f9; background: rgba(255,255,255,0.16); }
html.light .oic-page, body.light .oic-page { color: #000000; background: rgba(0,0,0,0.06); }
html.light .oic-page:hover, body.light .oic-page:hover { color: #000000; background: rgba(0,0,0,0.1); }
.oicard-rows { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.oic-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; flex: 1 1 0; min-height: 0; border-bottom: 1px solid var(--border); font-size: 12px; }
.oic-row:last-child { border-bottom: 0; }
.oic-lab { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.oic-rv { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text); }
.oic-rv.strong { color: var(--accent); }
.oicard-dots { display: flex; justify-content: center; gap: 5px; flex: 0 0 auto; padding-top: 2px; }
.oic-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--border); }
.oic-dot.on { background: var(--accent); }
.oic-empty { color: var(--muted); text-align: center; padding: 14px; }
.oicard-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.oic-coin { flex-shrink: 0; }

/* ───── Стек по биржам на графике + легенда ───── */
.oichart-svg .exarea { stroke: none; }
.oichart-svg .exbar { stroke: none; }
.oi-legend { display: flex; flex-wrap: wrap; gap: 5px 14px; align-items: center; padding: 2px 2px 8px; }
.oi-leg { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.oi-leg-sw { width: 11px; height: 11px; border-radius: 3px; flex-shrink: 0; }
.oi-leg-line { height: 3px; border-radius: 2px; background: var(--price); }
