/* ============================================================
   ستوك — الشارت الاحترافي v2 — الواجهة الغامرة (prochart.css v2)
   صفحة بلا نافذة داخل نافذة: الشارت يأخذ كل مساحة الشاشة تحت شريط
   تحكم نحيف واحد، وكل الأدوات عائمة زجاجية فوق اللوحة لا تحتلها.
   الإيماءات هي طريقة التقريب والتحريك الوحيدة — لا أزرار تكبير.

   v2 — ميزة الإعادة: زر «الإعادة» بهوية كهرمانية مميزة في الشريط،
   لافتة اختيار شمعة البداية، وشريط تحكم زجاجي عائم (تشغيل/خطوة/
   سرعة/موضع/إنهاء) — كلها عناصر جديدة معزولة لا تلمس شيئاً قائماً.
   تُحمَّل بعد stock.css وict-chart.css فتغلب قواعد التخطيط القديمة
   عند تساوي الخصوصية — بلا أي إيموجي.
   ============================================================ */

/* ---------- هيكل التطبيق الغامر ---------- */
html, body.page-chart { height: 100%; }

body.page-chart {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

.pc-app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
}

/* ---------- الشريط العلوي النحيف ---------- */
.pc-top {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  padding: 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  background: rgba(7, 10, 16, 0.92);
  border-bottom: 1px solid rgba(140, 160, 200, 0.16);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  z-index: 20;
}

.pc-back {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid rgba(140, 160, 200, 0.22);
  background: rgba(140, 160, 200, 0.07);
  color: var(--ink2);
  text-decoration: none;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.pc-back:hover { color: var(--ink); border-color: rgba(46, 230, 200, 0.5); background: rgba(46, 230, 200, 0.08); }

.pc-brand {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  text-decoration: none;
  color: var(--ink);
  font-weight: 900;
  font-size: 0.95rem;
}
.pc-brand-name { letter-spacing: 0.02em; }

.pc-title {
  display: flex;
  align-items: baseline;
  gap: 9px;
  min-width: 0;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.pc-title .lg-sym { font-weight: 900; color: #2ee6c8; letter-spacing: 0.03em; font-size: 0.98rem; }
.pc-title .lg-name {
  color: var(--ink2);
  font-size: 0.76rem;
  font-weight: 600;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pc-title .lg-price { font-weight: 900; color: #ffffff; font-size: 1.02rem; direction: ltr; }
.pc-title .lg-chg { font-weight: 800; color: var(--ink2); font-size: 0.8rem; direction: ltr; }
.pc-title .lg-chg.is-up { color: #00c894; }
.pc-title .lg-chg.is-dn { color: #ff4d67; }

.pc-search {
  position: relative;
  flex: 1 1 200px;
  max-width: 320px;
  min-width: 130px;
  display: flex;
  align-items: center;
  margin-inline-start: auto;
}
.pc-search .search-ico {
  position: absolute;
  inset-inline-start: 11px;
  width: 15px;
  height: 15px;
  color: var(--dim);
  pointer-events: none;
}
.pc-search input {
  width: 100%;
  padding: 9px 34px 9px 12px;
  border-radius: 12px;
  border: 1px solid rgba(140, 160, 200, 0.22);
  background: rgba(140, 160, 200, 0.07);
  color: var(--ink);
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 700;
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.pc-search input:focus { border-color: rgba(46, 230, 200, 0.55); background: rgba(46, 230, 200, 0.06); }
.pc-search input::placeholder { color: var(--dim); font-weight: 600; }

/* أزرار الإطار — تورث .tf-tab من stock.css وتضيّقها للشريط النحيف */
.pc-top .pc-tf { margin: 0; display: inline-flex; gap: 4px; }
.pc-top .tf-tab { padding: 8px 13px; }
.pc-top .tf-tab .t-sub { display: none; }

.pc-ictbtn {
  flex: 0 0 auto;
  padding: 9px 13px;
  border-radius: 12px;
  border: 1px solid rgba(46, 230, 200, 0.4);
  background: rgba(46, 230, 200, 0.08);
  color: #2ee6c8;
  font: 900 12px/1 var(--font);
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.pc-ictbtn:hover { border-color: rgba(46, 230, 200, 0.75); background: rgba(46, 230, 200, 0.14); }
.pc-ictbtn[aria-expanded="true"] {
  background: rgba(46, 230, 200, 0.2);
  border-color: rgba(46, 230, 200, 0.85);
  color: #7ff5e2;
}

/* زر الإعادة — هوية كهرمانية مميزة عن ICT التركوازية */
.pc-replaybtn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 13px;
  border-radius: 12px;
  border: 1px solid rgba(245, 166, 35, 0.4);
  background: rgba(245, 166, 35, 0.08);
  color: #f5b94a;
  font: 900 12px/1 var(--font);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.pc-replaybtn:hover { border-color: rgba(245, 166, 35, 0.75); background: rgba(245, 166, 35, 0.14); }
.pc-replaybtn[aria-pressed="true"] {
  background: rgba(245, 166, 35, 0.2);
  border-color: rgba(245, 166, 35, 0.85);
  color: #ffd58a;
}

/* ---------- لوحة الشارت — كل المساحة المتبقية ---------- */
.pc-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: #05070d;
  overflow: hidden;
}

/* تغلب قاعدة الارتفاع القديمة للتخطيط القديم — اللوحة تمتد بلا حدود */
.pc-stage .chart-mount {
  position: absolute;
  inset: 0;
  height: auto;
  min-height: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}
.pc-stage .chart-mount > * { width: 100%; height: 100%; }
.pc-stage .chart-mount > canvas {
  position: absolute;
  inset: 0;
  z-index: 2;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: crosshair;
}
.pc-stage .chart-mount > canvas.is-grab { cursor: grabbing; }
.pc-stage .chart-note {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  pointer-events: none;
  margin: 0;
  color: var(--dim);
  font-weight: 700;
  font-size: 0.86rem;
}
.pc-stage .chart-note[hidden] { display: none; }

/* ---------- ليجند OHLCV العائم ---------- */
.pc-ohlc {
  position: absolute;
  top: 10px;
  left: 12px;
  z-index: 6;
  display: inline-flex;
  align-items: baseline;
  gap: 11px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(13, 18, 28, 0.78);
  border: 1px solid rgba(140, 160, 200, 0.18);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  white-space: nowrap;
}
.pc-ohlc .lg-k { color: #6b7692; font-weight: 700; }
.pc-ohlc .lg-k b { color: var(--ink); font-weight: 800; }
.pc-ohlc .lg-o.is-up, .pc-ohlc .lg-h.is-up, .pc-ohlc .lg-l.is-up, .pc-ohlc .lg-c.is-up { color: #00c894; }
.pc-ohlc .lg-o.is-dn, .pc-ohlc .lg-h.is-dn, .pc-ohlc .lg-l.is-dn, .pc-ohlc .lg-c.is-dn { color: #ff4d67; }
.pc-ohlc .lg-tf {
  font-size: 0.75rem;
  font-weight: 900;
  color: #2ee6c8;
  background: rgba(46, 230, 200, 0.1);
  border: 1px solid rgba(46, 230, 200, 0.4);
  border-radius: 7px;
  padding: 2px 8px;
}

/* ---------- تلميح الإيماءات — يظهر ثم يتلاشى ---------- */
.pc-hint {
  position: absolute;
  bottom: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  padding: 8px 15px;
  border-radius: 999px;
  background: rgba(13, 18, 28, 0.82);
  border: 1px solid rgba(140, 160, 200, 0.2);
  color: var(--ink2);
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  animation: pcHintFade 6s ease forwards;
}
@keyframes pcHintFade {
  0%, 62% { opacity: 1; }
  100% { opacity: 0; visibility: hidden; }
}
.pc-hint[hidden] { display: none; }

/* ---------- وضع الإعادة: لافتة الاختيار وشريط التحكم ---------- */
.pc-replay-pick {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 8;
  margin: 0;
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(245, 166, 35, 0.14);
  border: 1px solid rgba(245, 166, 35, 0.5);
  color: #ffd58a;
  font-size: 0.76rem;
  font-weight: 800;
  white-space: nowrap;
  pointer-events: none;
  animation: rpPickIn 0.18s ease;
}
.pc-replay-pick[hidden] { display: none; }
@keyframes rpPickIn {
  from { opacity: 0; transform: translate(-50%, -6px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.pc-replay {
  position: absolute;
  bottom: 52px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 7px;
  max-width: calc(100% - 24px);
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(140, 160, 200, 0.22);
  background: rgba(9, 13, 20, 0.92);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  animation: rpBarIn 0.2s ease;
}
.pc-replay[hidden] { display: none; }
@keyframes rpBarIn {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.rp-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid rgba(140, 160, 200, 0.22);
  background: rgba(140, 160, 200, 0.06);
  color: var(--ink2);
  cursor: pointer;
  flex: 0 0 auto;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease, transform 0.12s ease;
}
.rp-btn:hover { color: #ffd58a; border-color: rgba(245, 166, 35, 0.55); background: rgba(245, 166, 35, 0.08); }
.rp-btn:active { transform: scale(0.94); }
.rp-playbtn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border-color: rgba(245, 166, 35, 0.5);
  background: rgba(245, 166, 35, 0.12);
  color: #ffd58a;
}
.rp-playbtn[aria-pressed="true"] {
  background: rgba(245, 166, 35, 0.85);
  border-color: rgba(245, 166, 35, 0.9);
  color: #1a1205;
}
.rp-sep { flex: 0 0 auto; width: 1px; height: 20px; background: rgba(140, 160, 200, 0.2); }
.rp-speed {
  flex: 0 0 auto;
  min-width: 40px;
  padding: 7px 9px;
  border-radius: 9px;
  border: 1px solid rgba(140, 160, 200, 0.22);
  background: rgba(140, 160, 200, 0.06);
  color: var(--ink2);
  font: 800 12px/1 var(--font);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.rp-speed:hover { color: #ffd58a; border-color: rgba(245, 166, 35, 0.55); }
.rp-pos {
  flex: 0 0 auto;
  font: 800 12px/1 var(--font);
  color: var(--ink2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.rp-date {
  flex: 0 0 auto;
  font: 700 12px/1 var(--font);
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  direction: ltr;
}

/* ---------- الأزرار العائمة الدائرية ---------- */
.pc-fabs {
  position: absolute;
  left: 12px;
  bottom: 52px;
  z-index: 7;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pc-fab {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(140, 160, 200, 0.24);
  background: rgba(13, 18, 28, 0.82);
  color: var(--ink2);
  cursor: pointer;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease, transform 0.12s ease;
}
.pc-fab:hover { color: #2ee6c8; border-color: rgba(46, 230, 200, 0.55); background: rgba(13, 22, 30, 0.92); }
.pc-fab:active { transform: scale(0.94); }

/* ---------- شريط الأسفل: زر المناطق + الحاشية ---------- */
.pc-bottom {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  z-index: 7;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 12px calc(7px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, rgba(5, 7, 13, 0), rgba(5, 7, 13, 0.88) 55%);
  pointer-events: none;
}
.pc-bottom > * { pointer-events: auto; }

.pc-zchip {
  padding: 8px 15px;
  border-radius: 999px;
  border: 1px solid rgba(140, 160, 200, 0.26);
  background: rgba(13, 18, 28, 0.82);
  color: var(--ink2);
  font: 800 12px/1 var(--font);
  cursor: pointer;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.pc-zchip:hover { color: #2ee6c8; border-color: rgba(46, 230, 200, 0.55); }
.pc-zchip[aria-expanded="true"] { color: #2ee6c8; border-color: rgba(46, 230, 200, 0.7); background: rgba(46, 230, 200, 0.1); }

.pc-micro {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
  color: rgba(107, 118, 146, 0.85);
  text-align: left;
  min-width: 0;
}

/* ---------- لوحة المناطق المنزلقة ---------- */
.pc-sheet {
  position: absolute;
  inset-inline: 12px;
  bottom: 52px;
  z-index: 9;
  max-height: min(46vh, 380px);
  overflow: auto;
  border-radius: 16px;
  border: 1px solid rgba(140, 160, 200, 0.2);
  background: rgba(9, 13, 20, 0.94);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  padding: 12px 14px 14px;
  opacity: 0;
  transform: translateY(14px);
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
}
.pc-sheet.is-open { opacity: 1; transform: translateY(0); visibility: visible; pointer-events: auto; }

.pc-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  font-weight: 900;
  font-size: 0.9rem;
  color: var(--ink);
}
.pc-sheet-x {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 10px;
  border: 1px solid rgba(140, 160, 200, 0.22);
  background: transparent;
  color: var(--ink2);
  cursor: pointer;
}
.pc-sheet-x:hover { color: var(--ink); border-color: rgba(140, 160, 200, 0.45); }

/* حد المناطق داخل اللوحة — يورث .seg من stock.css */
.pc-sheet .pc-maxseg { margin-bottom: 12px; flex-wrap: wrap; }

/* بطاقات الملخص داخل اللوحة — أعمدة أضيق من القديم */
.pc-sheet .zone-strip { padding: 0; }
.pc-sheet .zone-cards { grid-template-columns: repeat(5, 1fr); gap: 8px; }
.pc-sheet .z-card { background: rgba(140, 160, 200, 0.05); border-color: rgba(140, 160, 200, 0.16); padding: 11px 12px; }
.pc-sheet .z-s { display: block; margin-top: 4px; font-size: 0.75rem; color: var(--dim); font-weight: 600; direction: ltr; text-align: right; }

/* ---------- درج طبقة ICT المنزلق ---------- */
.pc-ict {
  position: absolute;
  inset-inline: 12px;
  bottom: 52px;
  z-index: 8;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  border-radius: 16px;
  border: 1px solid rgba(140, 160, 200, 0.2);
  background: rgba(9, 13, 20, 0.94);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  padding: 12px 14px;
  margin-top: 0;
  opacity: 0;
  transform: translateY(14px);
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
}
/* تغلب قاعدتي العتامة في ict-chart.css أثناء الإغلاق */
.pc-ict.is-off .ict-chip { opacity: 0.38; pointer-events: none; }
.pc-ict.is-open { opacity: 1; transform: translateY(0); visibility: visible; pointer-events: auto; }
.pc-ict.is-off.is-open .ict-chip { opacity: 0.38; }

/* ---------- وضع التضمين داخل إطار جناح التحليل ---------- */
.embed .pc-back, .embed .pc-brand { display: none; }
.embed .pc-stage { padding-top: 0; }
.embed .pc-top { min-height: 48px; }

/* ---------- الاستجابة ---------- */
@media (max-width: 980px) {
  .pc-title .lg-name { max-width: 130px; }
  .pc-search { max-width: 240px; }
}

@media (max-width: 780px) {
  .pc-top { flex-wrap: wrap; row-gap: 8px; }
  .pc-title .lg-name { display: none; }
  .pc-search { order: 10; flex: 1 1 100%; max-width: none; }
  .pc-ohlc { top: 8px; left: 8px; gap: 8px; font-size: 0.75rem; padding: 6px 10px; }
  .pc-fabs { left: 8px; bottom: 48px; }
  .pc-fab { width: 37px; height: 37px; }
  .pc-sheet, .pc-ict { inset-inline: 8px; bottom: 48px; }
  .pc-sheet .zone-cards { grid-template-columns: repeat(2, 1fr); }
  .pc-hint { bottom: 58px; font-size: 0.75rem; max-width: calc(100% - 24px); white-space: normal; text-align: center; }
  .pc-replay-pick { top: 12px; font-size: 0.75rem; white-space: normal; text-align: center; max-width: calc(100% - 24px); }
  .pc-replay { bottom: 48px; gap: 6px; }
}

@media (max-width: 430px) {
  .pc-brand-name { display: none; }
  .pc-title .lg-sym { font-size: 0.9rem; }
  .pc-title .lg-price { font-size: 0.94rem; }
  .pc-top .tf-tab { padding: 7px 10px; font-size: 0.75rem; }
  .pc-micro { display: none; }
  .pc-bottom { justify-content: center; }
  .pc-replaybtn span { display: none; }
  .pc-replaybtn { padding: 9px 11px; }
  .pc-replay { gap: 5px; padding: 7px 9px; }
  .rp-btn { width: 31px; height: 31px; }
  .rp-playbtn { width: 35px; height: 35px; }
  .rp-date { display: none; }
  .rp-speed { min-width: 34px; padding: 6px 7px; }
}

/* تقليل الحركة — احترام تفضيل المستخدم */
@media (prefers-reduced-motion: reduce) {
  .pc-hint { animation: none; opacity: 0; visibility: hidden; }
  .pc-sheet, .pc-ict { transition: none; }
  .pc-replay, .pc-replay-pick { animation: none; }
}
