/* ═══════════════════════════════════════════
   MAPNA Dashboard — components.css
═══════════════════════════════════════════ */

/* ── FILTER BAR ── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.filter-label {
  font-size: 12px;
  color: var(--text3);
  margin-left: 2px;
  white-space: nowrap;
}

.chip {
  padding: 5px 15px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border2);
  background: var(--card);
  color: var(--text2);
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
  white-space: nowrap;
}
.chip:hover { border-color: var(--blue); color: var(--text); }
.chip.active { background: var(--blue); border-color: var(--blue); color: #fff; }

/* ── KPI GRID ── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.kpi-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 16px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s;
}
.kpi-card:hover { border-color: var(--border2); }

.kpi-card::before {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 2px;
}
.kpi-card.up::before   { background: var(--green); }
.kpi-card.down::before { background: var(--red); }
.kpi-card.neu::before  { background: var(--amber); }
.kpi-card.blue::before { background: var(--blue); }

.kpi-icon {
  position: absolute;
  top: 12px; left: 14px;
  opacity: 0.12;
  font-size: 32px;
  line-height: 1;
}

.kpi-label {
  font-size: 11px;
  color: var(--text3);
  margin-bottom: 7px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-value {
  font-size: 26px;
  font-weight: 600;
  color: var(--text);
  line-height: 1;
  letter-spacing: -0.5px;
}

.kpi-delta {
  font-size: 11px;
  margin-top: 7px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.kpi-delta.up   { color: var(--green); }
.kpi-delta.down { color: var(--red); }
.kpi-delta.neu  { color: var(--text3); }

/* ── CARD ── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  position: relative;
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card-title .sub {
  font-size: 11px;
  color: var(--text3);
  font-weight: 400;
}

.card-title .badge-small {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
}
.card-title .badge-small.green {
  background: var(--green-dim);
  color: var(--green);
}
.card-title .badge-small.red {
  background: var(--red-dim);
  color: var(--red);
}
.card-title .badge-small.blue {
  background: var(--blue-dim);
  color: var(--blue);
}

/* ── GRID LAYOUTS ── */
.g2   { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.g3   { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.g65  { display: grid; grid-template-columns: 1fr 310px; gap: 14px; margin-bottom: 14px; }
.g56  { display: grid; grid-template-columns: 310px 1fr; gap: 14px; margin-bottom: 14px; }
.g73  { display: grid; grid-template-columns: 1fr 280px; gap: 14px; margin-bottom: 14px; }
.mb   { margin-bottom: 14px; }

/* ── CHART WRAPPER ── */
.chart-wrap {
  position: relative;
  width: 100%;
}

/* ── LEGEND ── */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 12px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text3);
}
.legend-dot {
  width: 10px; height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}
.legend-line {
  width: 16px; height: 0;
  border-top: 2px solid;
  flex-shrink: 0;
}
.legend-dash {
  width: 16px; height: 0;
  border-top: 2px dashed;
  flex-shrink: 0;
}

/* ── TABLE ── */
.tbl-wrap {
  overflow: auto;
  max-height: 280px;
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

thead th {
  text-align: right;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text3);
  border-bottom: 1px solid var(--border2);
  position: sticky;
  top: 0;
  background: var(--card);
  white-space: nowrap;
  z-index: 1;
}

tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text2);
  white-space: nowrap;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: rgba(255,255,255,0.025); }

.pos { color: var(--green); font-weight: 500; }
.neg { color: var(--red);   font-weight: 500; }
.hi  { color: var(--text);  font-weight: 500; }

/* ── GAUGE BARS ── */
.gauge-list {
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.gauge-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.g-name {
  font-size: 12px;
  color: var(--text2);
  width: 140px;
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.g-track {
  flex: 1;
  height: 6px;
  background: rgba(255,255,255,0.06);
  border-radius: 3px;
  overflow: hidden;
}

.g-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.6s cubic-bezier(.4,0,.2,1);
}

.g-val {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  width: 46px;
  text-align: left;
  flex-shrink: 0;
}

/* ── STAT BOXES (Beta, etc) ── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.stat-box {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 13px 10px;
  text-align: center;
}

.stat-val { font-size: 22px; font-weight: 700; color: var(--text); line-height: 1; }
.stat-lab { font-size: 10px; color: var(--text3); margin-top: 5px; line-height: 1.3; }
.stat-val.up   { color: var(--green); }
.stat-val.down { color: var(--red); }
.stat-val.blue { color: var(--blue); }

/* ── DIVIDER ── */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

/* ── SUMMARY ROW (key metrics inline) ── */
.summary-row {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  padding: 14px 16px;
  background: rgba(255,255,255,0.025);
  border-radius: 9px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
}

.summary-item { text-align: center; }
.summary-item .val { font-size: 18px; font-weight: 600; color: var(--text); }
.summary-item .lab { font-size: 10px; color: var(--text3); margin-top: 2px; }

/* ── TAG ── */
.tag {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 5px;
  font-size: 10px; font-weight: 600;
}
.tag.green { background: var(--green-dim); color: var(--green); }
.tag.red   { background: var(--red-dim);   color: var(--red); }
.tag.blue  { background: var(--blue-dim);  color: var(--blue); }
.tag.amber { background: var(--amber-dim); color: var(--amber); }

/* ── RESPONSIVE COMPONENTS ── */
@media (max-width: 960px) {
  .g2, .g3, .g65, .g56, .g73 {
    grid-template-columns: 1fr;
  }
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .kpi-value { font-size: 20px; }
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
  .g-name { width: 110px; font-size: 11px; }
}

/* ═══════════════════════════════════════════
   اضافات v2 — symbol switcher، ratio cards
═══════════════════════════════════════════ */

/* ── SYMBOL SWITCHER (topbar) ── */
.symbol-switcher {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--card);
  border: 1px solid var(--border2);
  border-radius: 10px;
  padding: 4px 6px;
}
.sym-chip {
  padding: 5px 16px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text2);
  transition: all 0.15s;
  font-family: var(--font);
  border: none;
  background: none;
}
.sym-chip:hover { color: var(--text); background: rgba(255,255,255,0.06); }
.sym-chip.active[data-sym="ومپنا"] { background: rgba(59,130,246,0.18); color: #3b82f6; }
.sym-chip.active[data-sym="رمپنا"] { background: rgba(34,197,94,0.18);  color: #22c55e; }
.sym-chip.active[data-sym="بمپنا"] { background: rgba(245,158,11,0.18); color: #f59e0b; }

/* ── RATIO CARDS GRID ── */
.ratio-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
}
.ratio-kpi {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 12px 14px;
}
.ratio-kpi-label {
  font-size: 10px;
  color: var(--text3);
  margin-bottom: 6px;
  line-height: 1.4;
}
.ratio-kpi-val {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

/* ── SECTOR FILTER ── */
.sector-select {
  padding: 6px 14px;
  border-radius: 8px;
  background: var(--card);
  border: 1px solid var(--border2);
  color: var(--text2);
  font-family: var(--font);
  font-size: 13px;
  cursor: pointer;
  outline: none;
}
.sector-select:focus { border-color: var(--blue); }

/* ── PIVOT TABLE (بازدهی) ── */
.pivot-table-wrap { overflow-x: auto; }
.pivot-table th, .pivot-table td { white-space: nowrap; min-width: 80px; }
.pivot-table th:first-child, .pivot-table td:first-child { min-width: 110px; }

/* ── CUSTOM DATE RANGE ── */
.date-range-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 14px;
}
.date-input {
  padding: 5px 12px; border-radius: 8px;
  background: var(--card); border: 1px solid var(--border2);
  color: var(--text2); font-family: var(--font); font-size: 12px;
  width: 120px; outline: none;
}
.date-input:focus { border-color: var(--blue); }
.date-label { font-size: 12px; color: var(--text3); }

@media (max-width: 960px) {
  .ratio-card-grid { grid-template-columns: repeat(2, 1fr); }
  .symbol-switcher { padding: 3px 4px; }
  .sym-chip { padding: 4px 10px; font-size: 12px; }
}

/* ═══════════════════════════════════════════
   Mobile overflow fixes — جلوگیری از اسکرول افقی
═══════════════════════════════════════════ */

/* جلوگیری از overflow افقی کل صفحه */
html, body {
  overflow-x: hidden;
  max-width: 100vw;
}

.main {
  overflow-x: hidden;
}

/* sidebar روی موبایل نباید صفحه رو پوش بده */
@media (max-width: 960px) {
  .sidebar {
    max-width: 85vw;
  }
}

/* جداول pivot — اسکرول فقط داخل خودشون */
.pivot-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

.tbl-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

/* جداول داخل card */
.card {
  max-width: 100%;
}

/* جدول بازدهی — روی موبایل فونت کوچک‌تر */
@media (max-width: 768px) {
  .pivot-table th,
  .pivot-table td {
    padding: 6px 8px;
    font-size: 10px;
    min-width: 55px;
  }

  .pivot-table td:first-child,
  .pivot-table th:first-child {
    min-width: 70px;
    position: sticky;
    right: 0;
    background: var(--card);
    z-index: 1;
    box-shadow: -2px 0 4px rgba(0,0,0,0.2);
  }

  /* نمودارها روی موبایل ارتفاع کمتر */
  .chart-wrap[style*="height:260px"] { height: 200px !important; }
  .chart-wrap[style*="height:270px"] { height: 210px !important; }
  .chart-wrap[style*="height:250px"] { height: 190px !important; }
  .chart-wrap[style*="height:230px"] { height: 180px !important; }
}

/* صفحه در موبایل باز نشه وقتی sidebar open هست */
body.sidebar-open {
  overflow: hidden;
}

/* ═══════════════════════════════════════════
   Tooltip System
═══════════════════════════════════════════ */
.tt-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
}

.tt-icon {
  width: 15px; height: 15px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--border2);
  color: var(--text3);
  font-size: 9px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: help;
  flex-shrink: 0;
  transition: all 0.15s;
  font-style: normal;
  margin-right: 4px;
  user-select: none;
}
.tt-icon:hover {
  background: var(--blue-dim);
  border-color: var(--blue);
  color: var(--blue);
}

.tt-box {
  position: fixed;
  width: 240px;
  background: #1a2035;
  border: 1px solid var(--border2);
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 11px;
  color: var(--text2);
  line-height: 1.7;
  z-index: 9999;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s, visibility 0.15s;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  white-space: normal;
  text-align: right;
  direction: rtl;
}

.tt-wrap:hover .tt-box {
  opacity: 1;
  visibility: visible;
}

@media (max-width: 600px) {
  .tt-box { width: 200px; }
}
