/* Bayt Al Hikmah 2.0 - Manager Analytics Dashboard */
@import url('https://fonts.googleapis.com/css2?family=Almarai:wght@300;400;700;800&display=swap');

:root {
  --ibb-navy: #191D42;
  --ibb-navy-2: #1F2857;
  --ibb-navy-3: #2A3568;
  --ibb-coral: #CC5A50;
  --ibb-red: #C93333;
  --bg: #EEF0F7;
  --bg2: #F8F9FC;
  --card: #FFFFFF;
  --text: #191D42;
  --muted: #6B7194;
  --border: #DDE1EE;
  --ok: #2E9E6B;
  --warn: #D9822B;
  --sidebar-w: 260px;
  --fb: #1877F2;
  --ig: #E1306C;
  --yt: #FF0000;
  --wiki: #3366CC;
  --shadow: 0 4px 24px rgba(25,29,66,.08);
  --shadow-lg: 0 12px 40px rgba(25,29,66,.12);
  --radius: 16px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: 'Almarai', 'Segoe UI', sans-serif; font-size: 15px;
  line-height: 1.5;
  overflow-x: hidden;
  min-width: 0;
}

/* ---------- header / nav ---------- */
header.topbar {
  background: var(--ibb-navy);
  color: #fff; padding: 0 28px;
  display: flex; align-items: center; gap: 20px;
  min-height: 64px; position: sticky; top: 0; z-index: 50;
  box-shadow: 0 2px 10px rgba(25,29,66,.25);
}
header.topbar a.brand {
  display: flex; align-items: center; gap: 14px;
  text-decoration: none; color: inherit; min-width: 0; flex: 1;
}
header.topbar img.logo { height: 38px; flex-shrink: 0; }
header.topbar .title {
  font-weight: 800; font-size: 17px; letter-spacing: .3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
header.topbar .title span { color: var(--ibb-coral); }
header.topbar .title .title-rest { color: #fff; }

nav.mainnav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
nav.mainnav a {
  color: #C9CDE4; text-decoration: none; padding: 8px 14px;
  border-radius: 8px; font-weight: 700; font-size: 14px;
}
nav.mainnav a:hover { background: rgba(255,255,255,.08); color: #fff; }
nav.mainnav a.active { background: var(--ibb-coral); color: #fff; }

.nav-toggle {
  display: none;
  width: 44px; height: 44px; margin-left: auto; flex-shrink: 0;
  padding: 0; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.14);
  border-radius: 10px; cursor: pointer; align-items: center; justify-content: center;
  flex-direction: column; gap: 5px;
}
.nav-toggle span {
  display: block; width: 18px; height: 2px; background: #fff; border-radius: 2px;
  transition: transform .2s, opacity .2s;
}
body.nav-open .nav-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
body.nav-open .nav-toggle span:nth-child(2) { opacity: 0; }
body.nav-open .nav-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
.nav-backdrop { display: none; }

main { max-width: 1320px; margin: 24px auto; padding: 0 22px 40px; }
.page-head { margin-bottom: 20px; }
.page-head h1 { font-size: 26px; font-weight: 800; margin: 0 0 6px; }
.page-head p { color: var(--muted); margin: 0; }

/* ---------- typography ---------- */
h1 { font-size: 24px; font-weight: 800; margin: 6px 0 4px; }
h2 { font-size: 17px; font-weight: 800; margin: 0 0 14px; color: var(--ibb-navy); }
h3 { font-size: 15px; font-weight: 800; margin: 0 0 10px; }
p.sub { color: var(--muted); margin: 0 0 22px; }

/* ---------- KPI cards ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px; margin-bottom: 24px;
}
@media (max-width: 1100px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .kpi-grid { grid-template-columns: 1fr; } }
.kpi {
  background: var(--card); border-radius: var(--radius); padding: 20px 22px;
  border: 1px solid var(--border); box-shadow: var(--shadow);
  position: relative; overflow: hidden; transition: transform .15s, box-shadow .15s;
}
.kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.kpi::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 4px;
  background: var(--ibb-coral);
}
.kpi.wiki::before { background: var(--wiki); }
.kpi.fb::before { background: var(--fb); }
.kpi.ig::before { background: var(--ig); }
.kpi.yt::before { background: var(--yt); }
.kpi .label { color: var(--muted); font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .5px; }
.kpi .value {
  font-size: 32px; font-weight: 800; margin: 6px 0 4px; line-height: 1.1;
  overflow-wrap: anywhere; word-break: break-word;
}
.kpi .value-unit { font-size: 0.38em; font-weight: 700; color: var(--muted); margin-left: 0.2em; }
.kpi .meta { font-size: 12px; color: var(--muted); line-height: 1.45; }
.kpi .icon { position: absolute; right: 16px; top: 16px; font-size: 28px; opacity: .15; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); gap: 14px; margin-bottom: 22px; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
}
.card .k { color: var(--muted); font-size: 13px; font-weight: 700; }
.card .v { font-size: 26px; font-weight: 800; margin-top: 4px; }
.card .v small { font-size: 13px; color: var(--muted); font-weight: 400; }
.card.accent { border-top: 4px solid var(--ibb-coral); }

.panel {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; margin-bottom: 20px; box-shadow: var(--shadow);
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px; margin-bottom: 18px;
}
.panel-head h2 { margin: 0; }
.panel-head select {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 12px; font-family: inherit; font-size: 14px; background: #fff;
  max-width: 100%;
}

/* ---------- platform cards (hub) ---------- */
.platform-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 18px; margin-bottom: 28px;
}
.platform-card {
  background: var(--card); border-radius: var(--radius); padding: 24px;
  border: 1px solid var(--border); box-shadow: var(--shadow);
  text-decoration: none; color: inherit; display: block;
  transition: transform .15s, box-shadow .15s;
  position: relative; overflow: hidden;
}
.platform-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.platform-card .plat-icon { font-size: 32px; margin-bottom: 12px; }
.platform-card h3 { font-size: 18px; margin: 0 0 6px; }
.platform-card p { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.platform-card .stat-row { display: flex; gap: 20px; font-size: 13px; }
.platform-card .stat-row b { display: block; font-size: 20px; font-weight: 800; }
.platform-card.fb { border-top: 4px solid var(--fb); }
.platform-card.ig { border-top: 4px solid var(--ig); }
.platform-card.yt { border-top: 4px solid var(--yt); }
.platform-card.wiki { border-top: 4px solid var(--wiki); }

/* ---------- filters ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 14px; }
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 700; color: var(--muted); }
.filters input, .filters select {
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 12px;
  font-family: inherit; font-size: 14px; min-width: 130px; background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.filters input:focus, .filters select:focus {
  outline: none; border-color: var(--ibb-coral);
  box-shadow: 0 0 0 3px rgba(204,90,80,.15);
}

button, .btn {
  background: var(--ibb-navy); color: #fff; border: none; border-radius: var(--radius-sm);
  padding: 10px 18px; font-family: inherit; font-weight: 700; font-size: 14px;
  cursor: pointer; text-decoration: none; display: inline-block;
  transition: background .15s, transform .1s;
}
button:hover, .btn:hover { background: var(--ibb-navy-2); }
button:active { transform: scale(.98); }
button.coral, .btn.coral { background: var(--ibb-coral); }
button.coral:hover, .btn.coral:hover { background: var(--ibb-red); }
button.ghost { background: #fff; color: var(--ibb-navy); border: 1px solid var(--border); }
button.ghost:hover { background: var(--bg2); }
button.small, .btn.small { padding: 6px 12px; font-size: 12px; }
button:disabled, .btn:disabled { opacity: .5; cursor: not-allowed; }
/* Author styles often override the HTML hidden attribute; force it */
[hidden] { display: none !important; }

/* ---------- tables ---------- */
.tablewrap { overflow-x: auto; border-radius: var(--radius-sm); border: 1px solid var(--border); }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th {
  text-align: left; background: var(--ibb-navy); color: #fff;
  padding: 11px 14px; font-size: 11px; letter-spacing: .4px;
  text-transform: uppercase; white-space: nowrap; cursor: pointer; user-select: none;
  font-weight: 700;
}
td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #F4F6FC; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td .ar { direction: rtl; unicode-bidi: plaintext; }
a.ext { color: var(--ibb-coral); font-weight: 700; text-decoration: none; }
a.ext:hover { text-decoration: underline; }
.row-actions { white-space: nowrap; }
.row-actions .del { margin-left: 10px; color: var(--ibb-red); border-color: #f0c8c8; }
.row-actions .del:hover { background: #fff5f5; }

.badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 700; background: #EEF0F8; color: var(--ibb-navy);
}
.badge.ok { background: #E2F5EC; color: var(--ok); }
.badge.warn { background: #FBEEDD; color: var(--warn); }
.badge.err { background: #FBE3E1; color: var(--ibb-red); }
.badge.fb { background: #E7F0FE; color: var(--fb); }
.badge.ig { background: #FCE8EF; color: var(--ig); }
.badge.yt { background: #FFE8E8; color: var(--yt); }
.badge.wiki { background: #E8EEFB; color: var(--wiki); }

.pager { display: flex; gap: 8px; align-items: center; margin-top: 14px; color: var(--muted); font-size: 13px; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 20px; }
.tabs .tab {
  background: var(--card); color: var(--ibb-navy);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 11px 20px; font-weight: 800; font-size: 14px; cursor: pointer;
  transition: all .15s;
}
.tabs .tab:hover { background: #EEF0F8; border-color: var(--ibb-navy-3); }
.tabs .tab.active {
  background: var(--ibb-navy); color: #fff; border-color: var(--ibb-navy);
  box-shadow: 0 4px 14px rgba(25,29,66,.25);
}
.tabs .tab.active.fb { background: var(--fb); border-color: var(--fb); }
.tabs .tab.active.ig { background: var(--ig); border-color: var(--ig); }
.tabs .tab.active.yt { background: var(--yt); border-color: var(--yt); }

/* ---------- charts ---------- */
.chart-panel { padding: 20px 24px 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
@media (max-width: 1100px) { .grid3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 900px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

/* ---------- progress / jobs ---------- */
.progress { background: #EEF0F8; border-radius: 10px; height: 14px; overflow: hidden; }
.progress > div { background: linear-gradient(90deg, var(--ibb-coral), var(--ibb-red)); height: 100%; transition: width .4s; }
.joblog {
  background: var(--ibb-navy); color: #C9CDE4; font-family: Consolas, monospace;
  font-size: 12px; border-radius: var(--radius-sm); padding: 14px; max-height: 260px;
  overflow-y: auto; white-space: pre-wrap;
}
.panel.job-running { border-color: var(--ibb-coral); box-shadow: 0 0 0 3px rgba(204,90,80,.12); }

/* ---------- modal ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(25,29,66,.55); z-index: 100;
  display: none; align-items: flex-start; justify-content: center; padding: 40px 16px;
  backdrop-filter: blur(4px);
}
.modal-bg.open { display: flex; }
.modal {
  background: #fff; border-radius: var(--radius); max-width: 920px; width: 100%;
  max-height: 85vh; overflow-y: auto; padding: 28px; box-shadow: var(--shadow-lg);
}
.modal h2 { margin-top: 0; }
.modal .close { float: right; background: transparent; color: var(--muted); font-size: 22px; padding: 0 8px; border: none; cursor: pointer; }

/* ---------- lang breakdown ---------- */
.lang-bars { display: flex; flex-direction: column; gap: 12px; }
.lang-bar { display: flex; align-items: center; gap: 12px; }
.lang-bar .name { width: 110px; font-size: 13px; font-weight: 700; flex-shrink: 0; }
.lang-bar .track { flex: 1; height: 10px; background: #EEF0F8; border-radius: 5px; overflow: hidden; }
.lang-bar .fill { height: 100%; border-radius: 5px; background: var(--ibb-coral); transition: width .5s; }
.lang-bar .val { width: 80px; text-align: right; font-size: 13px; font-weight: 800; font-variant-numeric: tabular-nums; }

/* ---------- top list ---------- */
.top-list { list-style: none; padding: 0; margin: 0; }
.top-list li {
  display: flex; align-items: flex-start; gap: 12px; padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.top-list li:last-child { border-bottom: none; }
.top-list .rank {
  width: 28px; height: 28px; border-radius: 8px; background: var(--ibb-navy);
  color: #fff; font-size: 12px; font-weight: 800; display: flex;
  align-items: center; justify-content: center; flex-shrink: 0;
}
.top-list .rank.gold { background: var(--ibb-coral); }
.top-list .body { flex: 1; min-width: 0; }
.top-list .title { font-weight: 700; font-size: 14px; }
.top-list .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.top-list .metric { font-weight: 800; font-size: 15px; white-space: nowrap; }

canvas { max-width: 100%; }

.period-modal { max-width: 480px; }
.period-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 18px; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); margin-bottom: 18px;
}
.period-bar .hint { color: var(--muted); font-size: 13px; }
footer.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 24px; }

/* ---------- comments export (BAH2 branded progress) ---------- */
.head-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.include-script {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.85rem; color: var(--muted); cursor: pointer;
  user-select: none; white-space: nowrap;
}
.include-script input { width: 16px; height: 16px; accent-color: var(--coral, #c44); cursor: pointer; }
.comments-hint {
  color: var(--muted); font-size: 13px; margin: -6px 0 14px; line-height: 1.45;
}
.sel-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  margin-bottom: 10px; font-size: 13px;
}
.sel-bar .sel-all {
  display: inline-flex; align-items: center; gap: 8px;
  font-weight: 700; color: var(--ibb-navy); cursor: pointer;
}
.sel-bar .hint { color: var(--muted); }
.checkcol { width: 36px; text-align: center; }
.checkcol input { width: 16px; height: 16px; accent-color: var(--ibb-coral); cursor: pointer; }

.bah2-progress {
  position: relative;
  margin: 0 0 18px;
  padding: 18px 20px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background:
    radial-gradient(120% 80% at 0% 0%, rgba(204,90,80,.14), transparent 55%),
    linear-gradient(135deg, #191D42 0%, #1F2857 48%, #2A3568 100%);
  color: #EEF0F7;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.bah2-progress::before {
  content: "";
  position: absolute; inset: 0;
  background: repeating-linear-gradient(
    -18deg, transparent, transparent 12px,
    rgba(255,255,255,.02) 12px, rgba(255,255,255,.02) 24px);
  pointer-events: none;
}
.bah2-progress-brand {
  position: relative; display: flex; align-items: center; gap: 12px; margin-bottom: 14px;
}
.bah2-progress-mark {
  width: 36px; height: 36px; border-radius: 10px; flex-shrink: 0;
  background: linear-gradient(145deg, var(--ibb-coral), var(--ibb-red));
  box-shadow: 0 6px 16px rgba(204,90,80,.35);
  position: relative;
}
.bah2-progress-mark::after {
  content: "";
  position: absolute; inset: 9px;
  border: 2px solid rgba(255,255,255,.9);
  border-radius: 4px;
  border-right-color: transparent;
  transform: rotate(45deg);
}
.bah2-progress-title {
  font-weight: 800; font-size: 14px; letter-spacing: .3px;
}
.bah2-progress-sub {
  font-size: 13px; color: #C9CDE4; margin-top: 2px;
}
.bah2-progress-track {
  position: relative;
  height: 14px; border-radius: 999px;
  background: rgba(255,255,255,.12);
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0,0,0,.25);
}
.bah2-progress-fill {
  height: 100%; width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #CC5A50 0%, #E07870 45%, #F0A39C 100%);
  transition: width .45s ease;
  position: relative;
  z-index: 1;
}
.bah2-progress-sheen {
  position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.25), transparent);
  transform: translateX(-100%);
  animation: bah2Sheen 1.8s ease-in-out infinite;
  pointer-events: none;
  z-index: 2;
}
.bah2-progress.is-done .bah2-progress-sheen,
.bah2-progress.is-fail .bah2-progress-sheen,
.bah2-progress.is-cancelling .bah2-progress-sheen { animation: none; opacity: 0; }
.bah2-progress.is-done .bah2-progress-fill {
  background: linear-gradient(90deg, #2E9E6B, #4CBC88);
}
.bah2-progress.is-fail .bah2-progress-fill,
.bah2-progress.is-cancelling .bah2-progress-fill {
  background: linear-gradient(90deg, #8B3030, #C93333);
}
@keyframes bah2Sheen {
  0% { transform: translateX(-100%); }
  55% { transform: translateX(100%); }
  100% { transform: translateX(100%); }
}
.bah2-progress-meta {
  position: relative;
  display: flex; flex-wrap: wrap; gap: 8px 16px;
  margin-top: 10px; font-size: 12px; font-weight: 700;
  color: #C9CDE4;
}
.bah2-progress-meta #cpPct {
  color: #fff; font-size: 15px; font-variant-numeric: tabular-nums;
}
.bah2-progress-msg {
  position: relative;
  margin: 8px 0 0; font-size: 12px; color: #A8AED0;
  min-height: 1.2em; word-break: break-word;
}
.bah2-progress-actions {
  position: relative;
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px;
  align-items: center;
}
.bah2-progress-actions .btn,
.bah2-progress-actions button {
  min-height: 40px;
  padding: 10px 16px;
  font-size: 13px;
}
.bah2-progress-actions .ghost {
  background: rgba(255,255,255,.08); color: #fff; border: 1px solid rgba(255,255,255,.22);
}
.bah2-progress-actions .ghost:hover { background: rgba(255,255,255,.14); }
.bah2-progress-actions .btn.coral {
  background: var(--ibb-coral); color: #fff; border: none;
  box-shadow: 0 4px 14px rgba(204,90,80,.35);
}
.bah2-progress-actions .btn.coral:hover { background: var(--ibb-red); }
.bah2-progress-actions .grow { margin-left: auto; }

@media (max-width: 899px) {
  .head-actions { width: 100%; }
  .head-actions button { flex: 1; min-height: 44px; }
  .bah2-progress { padding: 16px 14px; }
  .bah2-progress-actions { flex-direction: column; align-items: stretch; }
  .bah2-progress-actions .btn,
  .bah2-progress-actions button { width: 100%; margin-left: 0; }
  .bah2-progress-actions .grow { margin-left: 0; }
  .sel-bar { gap: 8px; }
  .sel-bar button { min-height: 40px; }
}

/* ============================================================
   Responsive — tablets & phones
   ============================================================ */

/* Touch-friendlier controls everywhere */
@media (hover: none) {
  button, .btn, .tabs .tab, nav.mainnav a {
    min-height: 44px;
  }
  .kpi:hover, .platform-card:hover { transform: none; box-shadow: var(--shadow); }
}

/* ---- Tablet (≤ 1024px) ---- */
@media (max-width: 1024px) {
  header.topbar { padding: 0 16px; gap: 12px; }
  header.topbar .title { font-size: 15px; }
  main { padding: 0 16px 32px; margin: 18px auto; }
  .page-head h1 { font-size: 22px; }
  .kpi .value { font-size: 28px; }
  .panel { padding: 18px; }
  .platform-grid { grid-template-columns: repeat(2, 1fr); }
  nav.mainnav a { padding: 8px 10px; font-size: 13px; }
}

/* ---- Compact tablet / large phone landscape (≤ 899px): drawer nav ---- */
@media (max-width: 899px) {
  header.topbar {
    padding: 0 12px 0 14px;
    min-height: 56px;
    position: sticky;
  }
  header.topbar a.brand { gap: 10px; flex: 1; min-width: 0; }
  header.topbar img.logo { height: 30px; }
  header.topbar .title { font-size: 14px; }
  header.topbar .title .title-rest { display: none; }

  .nav-toggle { display: inline-flex; }

  nav.mainnav {
    display: none;
    position: fixed;
    top: 56px; left: 0; right: 0;
    margin: 0;
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 4px;
    padding: 12px;
    background: var(--ibb-navy-2);
    border-bottom: 1px solid rgba(255,255,255,.08);
    box-shadow: 0 16px 32px rgba(25,29,66,.35);
    max-height: calc(100vh - 56px);
    overflow-y: auto;
    z-index: 60;
  }
  body.nav-open nav.mainnav { display: flex; }
  nav.mainnav a {
    padding: 14px 16px;
    font-size: 16px;
    border-radius: 10px;
  }

  .nav-backdrop {
    display: none;
    position: fixed; inset: 56px 0 0 0;
    background: rgba(25,29,66,.45);
    z-index: 55;
    border: none; padding: 0; margin: 0; width: auto; height: auto;
    cursor: pointer;
    appearance: none; -webkit-appearance: none;
  }
  body.nav-open .nav-backdrop:not([hidden]) { display: block; }

  main { margin: 14px auto; padding: 0 12px 28px; }
  .page-head { margin-bottom: 14px; }
  .page-head h1 { font-size: 20px; }
  .page-head p { font-size: 14px; }

  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 16px;
  }
  .kpi { padding: 14px 14px 16px; }
  .kpi .value { font-size: 24px; }
  .kpi .label { font-size: 11px; }
  .kpi .meta { font-size: 11px; }
  .kpi .icon { font-size: 22px; right: 10px; top: 10px; }

  .platform-grid { grid-template-columns: 1fr; gap: 12px; }
  .platform-card { padding: 18px; }
  .platform-card .stat-row { gap: 14px; flex-wrap: wrap; }

  .panel { padding: 16px; margin-bottom: 14px; border-radius: 14px; }
  .panel-head { gap: 8px; margin-bottom: 12px; }
  .panel-head h2 { font-size: 16px; width: 100%; }

  .filters {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .filters label { width: 100%; }
  .filters input,
  .filters select {
    width: 100%;
    min-width: 0 !important;
    min-height: 44px;
    font-size: 16px; /* prevents iOS zoom on focus */
  }
  .filters button,
  .filters .btn {
    width: 100%;
    min-height: 44px;
  }
  .filters label[style*="flex-direction:row"] {
    flex-direction: row !important;
    align-items: center !important;
    padding-bottom: 0 !important;
  }

  .period-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 14px;
  }
  .period-bar > .hint:first-child { width: 100%; }
  .period-bar button {
    min-height: 44px;
    flex: 1 1 calc(50% - 6px);
  }
  /* Put the two period buttons side-by-side; keep full-width only if alone */
  .period-bar {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }
  .period-bar .hint:not(:first-child) { flex: 1 1 100%; }

  .tabs {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    margin: 0 -12px 16px;
    padding: 0 12px 4px;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs .tab {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 12px 16px;
    font-size: 13px;
  }

  .grid2, .grid3 { grid-template-columns: 1fr; gap: 12px; }
  .chart-panel { padding: 14px 14px 10px; }
  .chart-panel canvas,
  canvas { max-height: 220px; }

  .tablewrap {
    margin: 0 -4px;
    border-radius: 10px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    position: relative;
  }
  .tablewrap::before {
    content: "";
    pointer-events: none;
    position: absolute; top: 0; right: 0; bottom: 0; width: 28px;
    background: linear-gradient(90deg, transparent, rgba(25,29,66,.08));
    border-radius: 0 10px 10px 0;
    z-index: 1;
  }
  table { font-size: 12.5px; min-width: 640px; }
  th, td { padding: 10px 10px; }
  th { font-size: 10px; }

  .pager {
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 10px;
  }
  .pager button { min-height: 40px; flex: 1; }

  .lang-bar { flex-wrap: wrap; gap: 6px 10px; }
  .lang-bar .name { width: auto; min-width: 90px; }
  .lang-bar .track { min-width: 120px; flex: 1 1 100%; order: 3; }
  .lang-bar .val { width: auto; margin-left: auto; }

  .top-list li { gap: 10px; padding: 10px 0; }
  .top-list .title { font-size: 13px; word-break: break-word; }
  .top-list .metric { font-size: 14px; }

  .modal-bg { padding: 12px 10px; align-items: flex-end; }
  .modal {
    padding: 20px 16px;
    max-height: 92vh;
    border-radius: 16px 16px 12px 12px;
  }
  .period-modal { max-width: 100%; }
  .modal .filters { flex-direction: column; }
  .modal .filters input,
  .modal .filters select { width: 100%; min-width: 0; font-size: 16px; }

  footer.foot { padding: 18px 12px 28px; font-size: 11px; line-height: 1.5; }
}

/* ---- Phone (≤ 600px) ---- */
@media (max-width: 600px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi { padding: 12px; border-radius: 12px; }
  .kpi .value { font-size: 20px; margin: 4px 0; }
  .kpi .value-unit { display: block; margin: 2px 0 0; font-size: 0.48em; }
  .kpi .meta { font-size: 10.5px; }

  /* On very narrow screens, stack the 4 overview KPIs as 2x2 still works;
     for single-kpi loading state keep readable */
  .cards { grid-template-columns: 1fr; }

  .page-head h1 { font-size: 18px; }
  h2 { font-size: 15px; }

  button, .btn { padding: 12px 14px; }
  button.small { padding: 10px 12px; font-size: 13px; min-height: 40px; }

  .badge { margin-bottom: 4px; }

  table { min-width: 560px; }
}

/* ---- Tiny phones (≤ 380px) ---- */
@media (max-width: 380px) {
  .kpi-grid { grid-template-columns: 1fr; }
  header.topbar .title { font-size: 13px; }
}

/* ---------- Audience map ---------- */
.audience-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}
.audience-stats { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.audience-map-panel { padding: 0; overflow: hidden; position: relative; }
.audience-map {
  height: min(58vh, 520px);
  width: 100%;
  background: #EEF0F7;
  border-radius: var(--radius) var(--radius) 0 0;
}
.map-legend {
  display: flex; align-items: center; gap: 6px; justify-content: center;
  padding: 10px 14px 14px; color: var(--muted); font-size: 12px; font-weight: 700;
}
.map-legend .leg-swatch {
  width: 28px; height: 12px; border-radius: 3px;
  box-shadow: inset 0 0 0 1px rgba(25,29,66,.15);
}
.map-legend .leg-label { color: var(--muted); font-size: 11px; }
.segment-box {
  margin-top: 14px; padding: 12px 14px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 14px; color: var(--ibb-navy);
}
.leaflet-tooltip.map-tip {
  background: var(--ibb-navy); color: #fff; border: none;
  border-radius: 8px; padding: 8px 10px; font-family: 'Almarai', sans-serif;
  font-size: 12px; font-weight: 700; box-shadow: var(--shadow);
}
.leaflet-tooltip.map-tip.muted { background: #6B7194; }
.leaflet-tooltip-top:before { border-top-color: var(--ibb-navy) !important; }

@media (max-width: 600px) {
  .audience-map { height: 320px; }
}
