/* ============================================================
   dashboard-specific styles
   ============================================================ */

.dash-main { padding-top: 22px; }

.dash-titlebar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.dash-titlebar h1 { font-size: 24px; color: var(--deep); line-height: 1.4; }
.dash-sub { color: var(--ink-2); font-size: 13.5px; max-width: 640px; }
.dash-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- main grid ---------- */
.dash-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 430px; /* map (right in RTL) | list (left) */
  gap: 16px;
  align-items: stretch;
  margin-bottom: 8px;
}

.map-card {
  position: relative;
  overflow: hidden;
  min-height: 640px;
  display: flex;
}
#map { flex: 1; min-height: 640px; z-index: 1; background: #EDF0EA; }

.map-legend {
  position: absolute;
  z-index: 500;
  bottom: 14px;
  inset-inline-end: 14px; /* RTL: bottom-left, clear of attribution */
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(4px);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 10px 14px;
  font-size: 12px;
}
.legend-title { font-weight: 700; color: var(--deep); font-size: 12.5px; margin-bottom: 6px; }
.legend-items { display: flex; flex-direction: column; gap: 4px; }
.legend-item { display: inline-flex; align-items: center; gap: 8px; color: var(--ink-2); }
.legend-item i {
  width: 14px; height: 14px;
  border-radius: 4px;
  flex: none;
  border: 1px solid rgba(8,39,24,.15);
}

/* leaflet RTL tweaks */
.leaflet-container { font-family: var(--font); font-size: 12px; }
.leaflet-control-attribution { direction: ltr; font-size: 9.5px; }
.map-tip {
  background: var(--deep);
  color: #fff;
  border: none;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 500;
  padding: 6px 12px;
  direction: rtl;
}
.map-tip::before { display: none; }
.map-tip .tip-rank { color: var(--lime); font-weight: 700; }

/* ---------- district list ---------- */
.list-card { display: flex; flex-direction: column; min-height: 640px; max-height: 78vh; overflow: hidden; }
.list-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 14px 18px 6px;
}
.list-head h2 { font-size: 16.5px; color: var(--deep); }
.list-count { font-size: 12px; color: var(--ink-3); }
.tied-note { margin: 0 18px 2px; font-size: 11px; color: var(--ink-3); line-height: 1.7; }

.search-wrap {
  margin: 6px 14px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--mint);
  border: 1px solid var(--mint-deep);
  border-radius: 10px;
  padding: 0 12px;
  color: var(--ink-3);
}
.search-wrap:focus-within { border-color: var(--lime-dark); background: #fff; }
.search-wrap input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--ink);
  padding: 9px 0;
}

.table-wrap { flex: 1; overflow: auto; border-top: 1px solid var(--line); }

.district-table { width: 100%; font-size: 13px; }
.district-table thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--mint);
  color: var(--forest);
  font-size: 12px;
  font-weight: 700;
  text-align: start;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  user-select: none;
}
/* numeric columns: center header + values (name column stays start-aligned) */
.district-table th:nth-child(1), .district-table td:nth-child(1),
.district-table th:nth-child(3), .district-table td:nth-child(3),
.district-table th:nth-child(4), .district-table td:nth-child(4),
.district-table th:nth-child(5), .district-table td:nth-child(5) { text-align: center; }
.district-table th.sortable { cursor: pointer; }
.district-table th.sortable:hover { background: var(--mint-deep); }
.sort-ind { display: inline-block; width: 12px; color: var(--lime-dark); font-size: 10px; }
th.sorted-asc .sort-ind::after { content: "▲"; }
th.sorted-desc .sort-ind::after { content: "▼"; }

.district-table tbody td {
  padding: 7px 10px;
  border-bottom: 1px solid #EDF1EC;
  white-space: nowrap;
  vertical-align: middle;
}
.district-table tbody tr { cursor: pointer; transition: background .12s; }
.district-table tbody tr:hover { background: var(--mint); }
.district-table tbody tr.selected { background: #F2F7DE; box-shadow: inset 3px 0 0 var(--lime-dark); }
.district-table .d-name { font-weight: 500; color: var(--deep); white-space: normal; min-width: 110px; line-height: 1.4; }
.district-table .d-score { font-weight: 700; color: var(--forest); }

.empty-msg { padding: 30px; text-align: center; color: var(--ink-3); font-size: 13.5px; }

/* ---------- detail panel ---------- */
.panel-scrim {
  position: fixed;
  inset: 0;
  background: rgba(8, 39, 24, .35);
  z-index: 1200;
  opacity: 0;
  transition: opacity .25s;
}
.panel-scrim.show { opacity: 1; }

.detail-panel {
  position: fixed;
  z-index: 1300;
  top: 0;
  bottom: 0;
  inset-inline-end: 0; /* RTL: left edge */
  width: min(430px, 96vw);
  background: #fff;
  box-shadow: var(--shadow-lg);
  transform: translateX(-105%); /* off-screen to the left */
  transition: transform .3s cubic-bezier(.3,.8,.3,1);
  display: flex;
  flex-direction: column;
}
.detail-panel.open { transform: translateX(0); }
.panel-grab { display: none; }

.panel-close {
  position: absolute;
  top: 12px;
  inset-inline-start: 12px;
  z-index: 10;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,.22);
  color: #fff;
  font-size: 15px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.panel-close:hover { background: rgba(255,255,255,.36); }

.panel-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; }

.panel-hero {
  background: linear-gradient(160deg, var(--deep), var(--forest));
  color: #fff;
  padding: 26px 22px 20px;
}
.panel-hero .p-name { font-size: 21px; font-weight: 700; line-height: 1.4; }
.panel-hero .p-name-en { font-size: 12px; color: #A9BCAE; direction: ltr; text-align: end; display: block; margin-top: 1px; text-align: start; }
.panel-hero-stats { display: flex; gap: 12px; margin-top: 16px; }
.hero-stat {
  flex: 1;
  background: rgba(255,255,255,.09);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 12px;
  padding: 10px 14px;
}
.hero-stat .hs-label { font-size: 11.5px; color: #B9C9BD; }
.hero-stat .hs-value { font-size: 24px; font-weight: 700; line-height: 1.3; }
.hero-stat .hs-value .hs-of { font-size: 12px; font-weight: 400; color: #B9C9BD; }
.hero-stat.accent .hs-value { color: var(--lime); }
.prio-tag {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  border-radius: 99px;
  padding: 3px 14px;
  color: #fff;
  border: 1px solid rgba(255,255,255,.25);
}
.tag-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; align-items: center; }

/* Monte Carlo certainty lines (muted, small — matches «آخر رصد» note style) */
.cert-block { margin-top: 10px; }
.cert-block .cert-line { font-size: 11px; color: #A9BCAE; line-height: 1.8; }
.cert-block .cert-line .num { color: #D5E2D8; font-weight: 700; }

/* «آخر رصد» live-monitor section */
.monitor-block { padding: 8px 0 2px; }
.monitor-headline { font-size: 15px; font-weight: 700; color: var(--deep); }
.monitor-headline.delta-up { color: var(--up); }
.monitor-headline.delta-down { color: var(--down); }
.monitor-sub { font-size: 12.5px; color: var(--ink-2); margin-top: 3px; }
.monitor-note { font-size: 11px; color: var(--ink-3); line-height: 1.7; margin-top: 7px; }
.monitor-degraded { color: var(--ink-3); font-weight: 700; }
.monitor-badge {
  margin-top: 8px;
  font-size: 11.5px;
  line-height: 1.7;
  color: #7A5B00;
  background: #FFF7DB;
  border: 1px solid #EAD98F;
  border-radius: var(--radius-sm);
  padding: 7px 11px;
}

.panel-metrics { padding: 18px 22px 26px; }
.panel-metrics h3 {
  font-size: 13px;
  color: var(--ink-3);
  font-weight: 700;
  margin: 14px 0 4px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--line);
}
.metric-row { padding: 9px 0 4px; }
.metric-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.metric-label { font-size: 13px; color: var(--ink-2); }
.metric-value { font-size: 14.5px; font-weight: 700; color: var(--deep); white-space: nowrap; }
.metric-value .mv-sub { font-size: 11.5px; font-weight: 400; color: var(--ink-3); }
.metric-value .delta-up { color: var(--up); }
.metric-value .delta-down { color: var(--down); }

.bar-track {
  position: relative;
  height: 8px;
  background: var(--mint-deep);
  border-radius: 99px;
  margin-top: 6px;
  overflow: visible;
}
.bar-fill {
  position: absolute;
  inset-inline-start: 0;
  top: 0; bottom: 0;
  border-radius: 99px;
  background: var(--forest);
  min-width: 3px;
  transition: width .5s ease;
}
.bar-mean {
  position: absolute;
  top: -3px; bottom: -3px;
  width: 2px;
  background: var(--ink-3);
  border-radius: 2px;
}
.bar-note { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--ink-3); margin-top: 3px; }

/* «محاكاة الأثر» impact simulator */
.sim-block {
  background: #F4F7F2;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px 10px;
  margin-top: 10px;
}
.sim-lead { font-size: 13px; color: var(--ink-2); }
.sim-lead .num { font-weight: 700; color: var(--deep); }
.sim-slider {
  display: block;
  width: 100%;
  margin: 10px 0 10px;
  accent-color: var(--lime-dark);
  cursor: pointer;
}
.sim-stats { display: flex; gap: 8px; flex-wrap: wrap; }
.sim-stat {
  flex: 1 1 30%;
  min-width: 96px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 8px 6px;
  text-align: center;
}
.sim-stat .ss-label { font-size: 10.5px; color: var(--ink-3); line-height: 1.5; }
.sim-stat .ss-value { font-size: 15.5px; font-weight: 700; color: var(--deep); margin-top: 2px; }
.sim-stat .ss-value .ss-unit { font-size: 10px; font-weight: 400; color: var(--ink-3); }
.sim-note { font-size: 10.5px; color: var(--ink-3); line-height: 1.7; margin-top: 8px; }
.sim-goal-line { font-size: 13px; color: var(--ink-2); padding: 10px 2px 4px; }

/* ============================================================
   responsive
   ============================================================ */

/* tablet */
@media (max-width: 1024px) {
  .dash-grid { grid-template-columns: 1fr; }
  .map-card, #map { min-height: 480px; }
  .list-card { min-height: 0; max-height: 560px; }
  .kpi-row { grid-template-columns: repeat(3, 1fr); }
  .kpi:nth-child(4), .kpi:nth-child(5) { grid-column: span 1; }
  .kpi-row { grid-template-columns: repeat(6, 1fr); }
  .kpi { grid-column: span 2; }
  .kpi:nth-child(4) { grid-column: 1 / span 3; }
  .kpi:nth-child(5) { grid-column: 4 / span 3; }
}

/* mobile */
@media (max-width: 640px) {
  .dash-titlebar h1 { font-size: 20px; }
  .kpi-row { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi, .kpi:nth-child(4) { grid-column: span 1; }
  .kpi:nth-child(5) { grid-column: 1 / -1; }
  .kpi .kpi-value { font-size: 21px; }
  .map-card, #map { min-height: 380px; }
  .map-legend { padding: 8px 10px; bottom: 10px; inset-inline-end: 10px; }
  .legend-items { gap: 3px; }
  .legend-item { font-size: 11px; }

  /* bottom sheet */
  .detail-panel {
    top: auto;
    inset-inline: 0;
    width: 100%;
    max-height: 82vh;
    height: 82vh;
    border-radius: 18px 18px 0 0;
    transform: translateY(105%);
  }
  .detail-panel.open { transform: translateY(0); }
  .panel-grab {
    display: block;
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 44px; height: 5px;
    border-radius: 99px;
    background: rgba(255,255,255,.4);
    z-index: 11;
  }
  .panel-hero { padding-top: 30px; }
}
