:root {
  --brand: #204893;
  --green: #0daa63;
  --ice: #d2edfb;
  --navy: #204893;
  --navy-2: #183672;
  --navy-3: #142c5c;
  --surface: #ffffff;
  --surface-solid: #ffffff;
  --line: rgba(32, 72, 147, 0.12);
  --line-strong: rgba(32, 72, 147, 0.28);
  --cyan: #204893;
  --cyan-2: #3a6bc0;
  --teal: #0daa63;
  --gold: #0daa63;
  --mint: #0daa63;
  --rose: #d64545;
  --amber: #d39b00;
  --text: #204893;
  --muted: #5d7399;
  --soft: #3d5a80;
  --shadow: 0 14px 36px rgba(32, 72, 147, 0.08);
  --radius: 22px;
  --sidebar: 280px;
  --header: 84px;
  --good: #0daa63;
  --warn: #d39b00;
  --critical: #d64545;
  --font: "Cairo", "Segoe UI", Tahoma, sans-serif;
  --display: "Cairo", "Segoe UI", Tahoma, sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body.app-body {
  margin: 0;
  display: flex;
  align-items: stretch;
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  color: var(--text);
  color-scheme: light;
  --bs-body-color: #204893;
  --bs-body-bg: #d2edfb;
  --bs-secondary-color: #5d7399;
  --bs-heading-color: #204893;
  --bs-card-color: #204893;
  --bs-card-title-color: #204893;
  --bs-card-cap-color: #204893;
  --bs-card-bg: #ffffff;
  --bs-table-color: #204893;
  --bs-table-bg: transparent;
  --bs-table-striped-color: #204893;
  --bs-table-hover-color: #204893;
  --bs-border-color: rgba(32, 72, 147, 0.12);
  --bs-emphasis-color: #204893;
  background:
    radial-gradient(900px 420px at 100% 0%, rgba(13, 170, 99, 0.10), transparent 46%),
    linear-gradient(180deg, #d2edfb 0%, #eef8fd 42%, #f7fcff 100%);
}

a { color: var(--brand); text-decoration: none; }
button, input, select, textarea, table { font-family: inherit; }

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar);
  flex: 0 0 var(--sidebar);
  background: linear-gradient(180deg, #204893 0%, #183672 100%);
  border-right: 0;
  padding: 24px 18px 20px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  z-index: 20;
  color: #fff;
}
.brand-logo-wrap {
  background: #fff;
  border-radius: 16px;
  padding: 10px 12px;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
}
.brand-logo {
  display: block;
  width: 100%;
  height: 46px;
  object-fit: contain;
}
.brand-kicker { font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase; color: #d2edfb; margin-top: 14px; }
.brand-title { font-family: var(--display); font-size: 22px; line-height: 1.1; color: #fff; }
.brand-tag { font-size: 12px; color: #d2edfb; margin-top: 8px; }

.side-nav { display: flex; flex-direction: column; gap: 6px; margin-top: 22px; }
.side-link {
  border: 0; background: transparent; color: #d2edfb;
  text-align: start; border-radius: 14px; padding: 11px 12px;
  display: flex; align-items: center; gap: 10px;
  flex-direction: row;
  transition: 0.2s ease;
}
.side-link:hover, .side-link.active {
  background: rgba(210, 237, 251, 0.16);
  color: #fff;
}
.side-link.active { box-shadow: inset 0 0 0 1px rgba(210, 237, 251, 0.35); }
.side-foot {
  margin-top: auto; padding-top: 16px;
  border-top: 1px solid rgba(210, 237, 251, 0.2);
  color: #d2edfb; font-size: 12px;
}
.side-foot strong { color: #fff; }

.main {
  flex: 1;
  min-width: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 22px 28px 48px;
}

.topbar {
  min-height: var(--header);
  display: flex; align-items: flex-start; justify-content: space-between; gap: 20px;
  margin-bottom: 22px;
}
.topbar-lead { display: flex; align-items: flex-start; gap: 12px; min-width: 0; }
.topbar-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; }
.menu-toggle {
  display: none;
  width: 42px; height: 42px; flex: 0 0 42px;
  border: 1px solid var(--line); border-radius: 12px;
  background: #fff; color: var(--brand);
  place-items: center; font-size: 22px;
}
.nav-backdrop {
  display: none;
}
.page-kicker { color: var(--green); letter-spacing: 0.16em; text-transform: uppercase; font-size: 11px; font-weight: 700; }
.page-title { font-family: var(--display); font-size: 40px; margin: 4px 0 0; letter-spacing: -0.03em; color: var(--brand); }
.page-sub { color: var(--muted); margin-top: 6px; }

.btn-cyan, .btn-ghost, .btn-gold {
  border-radius: 14px; padding: 10px 16px; font-weight: 700; font-size: 13px;
  border: 1px solid transparent; transition: 0.2s ease;
}
.btn-cyan {
  background: #0daa63;
  color: #fff;
  box-shadow: 0 10px 24px rgba(13, 170, 99, 0.22);
}
.btn-gold { background: #204893; color: #fff; }
.btn-ghost { background: #fff; color: var(--brand); border-color: var(--line); }
.btn-cyan:hover, .btn-gold:hover, .btn-ghost:hover { transform: translateY(-1px); }

h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6,
p, li, td, th, label, strong, span, small {
  color: inherit;
}
.text-secondary { color: var(--muted) !important; }
.card, .kpi, .panel, .chart-card, .insight, .quad {
  color: var(--text);
  --bs-card-color: var(--text);
  --bs-heading-color: var(--text);
}

.card, .kpi, .panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.kpi {
  padding: 20px 22px;
  position: relative;
  overflow: hidden;
  transition: 0.25s ease;
}
.kpi:hover { transform: translateY(-3px); border-color: var(--line-strong); }
.kpi::after {
  content: ""; position: absolute; right: -30px; top: -30px;
  width: 110px; height: 110px; border-radius: 50%;
  background: radial-gradient(circle, rgba(13, 170, 99, 0.16), transparent 70%);
}
.kpi-label { color: var(--muted); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; }
.kpi-value { font-family: var(--display); font-size: 34px; margin: 8px 0 4px; color: var(--brand); }
.kpi-help { color: var(--soft); font-size: 12px; }
.kpi-tip {
  position: absolute; top: 16px; right: 16px; width: 22px; height: 22px;
  border-radius: 50%; border: 1px solid var(--line); color: var(--muted);
  font-size: 11px; display: grid; place-items: center; cursor: help;
}

.filters {
  padding: 16px; margin-bottom: 22px;
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)) auto;
  gap: 12px; align-items: end;
}
.field label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 6px; letter-spacing: 0.06em; text-transform: uppercase; }
.field input, .field select, .form-control, .form-select, textarea {
  width: 100%;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--brand);
  border-radius: 12px;
  padding: 10px 12px;
  color-scheme: light;
}
.form-control::placeholder, textarea::placeholder { color: #7a90b3; opacity: 1; }
.form-select option { background: #fff; color: #204893; }
input[type="date"], input[type="date"]::-webkit-datetime-edit,
input[type="date"]::-webkit-datetime-edit-fields-wrapper,
input[type="date"]::-webkit-datetime-edit-text,
input[type="date"]::-webkit-datetime-edit-month-field,
input[type="date"]::-webkit-datetime-edit-day-field,
input[type="date"]::-webkit-datetime-edit-year-field {
  color: #204893;
}
input[type="date"]::-webkit-calendar-picker-indicator { filter: none; opacity: 0.7; }
.form-control:focus, .form-select:focus, textarea:focus {
  background: #fff;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(13, 170, 99, 0.14);
  color: var(--brand);
}

.section-title { font-family: var(--display); font-size: 26px; margin-bottom: 6px; color: var(--brand); }
.section-help { color: var(--muted); margin-bottom: 16px; }
.chart-card { padding: 20px; height: 100%; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.chart-wrap { position: relative; height: 340px; }
.chart-wrap-reason { height: 380px; }
.reason-charts {
  background: linear-gradient(180deg, #ffffff 0%, #d2edfb 140%);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 24px 22px 20px;
  box-shadow: var(--shadow);
}
.reason-charts-head { margin-bottom: 18px; }
.reason-line-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 22px;
  transition: border-color 0.2s ease, transform 0.2s ease;
}
.reason-line-card:hover { border-color: var(--line-strong); transform: translateY(-2px); }
.mini-stat { color: var(--soft); font-size: 13px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  background: #d2edfb; color: var(--brand); font-size: 12px;
}
.chip-gold { background: rgba(13, 170, 99, 0.12); color: var(--green); }
.chip-rose { background: rgba(214, 69, 69, 0.1); color: #d64545; }

.table {
  color: var(--text);
  --bs-table-color: var(--text);
  --bs-table-bg: transparent;
  --bs-table-border-color: var(--line);
  --bs-table-hover-color: var(--brand);
  --bs-table-hover-bg: rgba(210, 237, 251, 0.7);
}
.table thead th { color: var(--muted); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; }
.table tbody td { color: var(--text); }
.table tbody tr:hover { background: rgba(210, 237, 251, 0.7); color: var(--brand); }
.reason-cell { max-width: 420px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; direction: auto; }

.heatmap { display: grid; gap: 6px; }
.heat-head, .heat-row { display: grid; gap: 6px; align-items: center; }
.heat-cell {
  min-height: 42px; border-radius: 10px;
  display: grid; place-items: center;
  font-size: 11px; color: #204893; font-weight: 700;
  cursor: pointer; transition: 0.15s ease;
}
.heat-label { font-size: 12px; color: var(--muted); }
.heat-cell:hover { transform: scale(1.04); }

.matrix { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.quad { padding: 18px; min-height: 220px; }
.quad h5 { font-size: 14px; }
.quad ul { margin: 10px 0 0; padding-left: 16px; color: var(--soft); }
.q-hh { border-color: rgba(214, 69, 69, 0.35); }
.q-hl { border-color: rgba(211, 155, 0, 0.35); }
.q-lh { border-color: rgba(13, 170, 99, 0.35); }
.q-ll { border-color: var(--line); }

.insights-wrap {
  background: linear-gradient(180deg, #ffffff 0%, #d2edfb 120%);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 28px 26px 24px;
  box-shadow: var(--shadow);
}
.insights-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 18px;
  margin-bottom: 22px;
}
.insights-legend { display: flex; flex-wrap: wrap; gap: 8px; }
.legend-pill {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.legend-fact { background: #d2edfb; color: var(--brand); }
.legend-int { background: rgba(32, 72, 147, 0.08); color: var(--brand); }
.legend-rec { background: rgba(13, 170, 99, 0.12); color: var(--green); }

.insight {
  height: 100%;
  padding: 22px;
  border-radius: 22px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  transition: transform 0.2s ease, border-color 0.2s ease;
}
.insight:hover { transform: translateY(-3px); border-color: var(--line-strong); }
.insight-featured {
  background: linear-gradient(135deg, #ffffff, #d2edfb 90%);
  border-color: rgba(32, 72, 147, 0.2);
}
.insight-top { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 16px; }
.insight-index {
  min-width: 46px; height: 46px;
  border-radius: 14px;
  display: grid; place-items: center;
  background: #d2edfb;
  color: var(--brand);
  font-weight: 800;
  letter-spacing: 0.04em;
}
.insight-kicker {
  color: var(--green);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 700;
  margin-bottom: 4px;
}
.insight h5 {
  margin: 0;
  font-family: var(--display);
  font-size: 20px;
  line-height: 1.35;
  color: var(--brand);
}
.insight-rail { display: grid; gap: 10px; }
.insight-row {
  display: grid;
  grid-template-columns: 138px 1fr;
  gap: 14px;
  align-items: start;
  padding: 12px 14px;
  border-radius: 14px;
  background: #f7fcff;
}
.insight-row span {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding-top: 2px;
}
.insight-row p { margin: 0; color: var(--soft); line-height: 1.55; }
.insight-fact { border-left: 3px solid var(--brand); }
.insight-fact span { color: var(--brand); }
.insight-int { border-left: 3px solid #7aa3d4; }
.insight-int span { color: #3a6bc0; }
.insight-rec { border-left: 3px solid var(--green); }
.insight-rec span { color: var(--green); }

@media (max-width: 760px) {
  .insights-head { flex-direction: column; align-items: flex-start; }
  .insight-row { grid-template-columns: 1fr; gap: 6px; }
}

.dq-pill { padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.dq-good { background: rgba(13, 170, 99, 0.12); color: var(--good); }
.dq-warning { background: rgba(211, 155, 0, 0.14); color: var(--warn); }
.dq-critical { background: rgba(214, 69, 69, 0.12); color: var(--critical); }

.q-nav { display: flex; gap: 8px; margin-bottom: 18px; }
.q-btn { border-radius: 12px; border: 1px solid var(--line); background: #fff; color: var(--soft); padding: 8px 14px; }
.q-btn.active { background: #204893; color: #fff; border-color: #204893; }

.empty-hero {
  min-height: 62vh; display: grid; place-items: center; text-align: center; padding: 40px 20px;
}
.empty-hero h1 { font-family: var(--display); font-size: 48px; }
.dropzone {
  margin: 24px auto 0; max-width: 560px; padding: 36px;
  border: 1px dashed var(--line-strong); border-radius: 24px;
  background: rgba(210, 237, 251, 0.55);
}

.overlay {
  position: fixed; inset: 0; background: rgba(32, 72, 147, 0.45);
  backdrop-filter: blur(10px); z-index: 50;
  display: none; place-items: center;
}
.overlay.show { display: grid; }
.loader-card { width: min(460px, 92vw); padding: 32px; text-align: center; }
.loader-bar { height: 6px; background: #d2edfb; border-radius: 99px; overflow: hidden; }
.loader-bar span {
  display: block; height: 100%; width: 30%;
  background: linear-gradient(90deg, #204893, #0daa63);
  animation: load 1.4s ease infinite;
}
@keyframes load { 0% { transform: translateX(-120%); } 100% { transform: translateX(400%); } }

.toast-wrap { position: fixed; right: 24px; bottom: 24px; z-index: 60; }

.lang-switch {
  display: inline-flex;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.lang-btn {
  border: 0;
  background: transparent;
  color: var(--brand);
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 0.06em;
  padding: 8px 12px;
  min-width: 46px;
}
.lang-btn.active {
  background: #204893;
  color: #fff;
}

html[dir="rtl"] body.app-body {
  flex-direction: row;
  direction: rtl;
}
html[dir="rtl"] .sidebar {
  text-align: right;
  border-left: 0;
}
html[dir="rtl"] .brand-kicker,
html[dir="rtl"] .brand-title,
html[dir="rtl"] .brand-tag,
html[dir="rtl"] .side-foot {
  text-align: right;
}
html[dir="rtl"] .side-nav {
  align-items: stretch;
}
html[dir="rtl"] .side-link {
  flex-direction: row;
  justify-content: flex-start;
  text-align: right;
  direction: rtl;
}
html[dir="rtl"] .side-link i {
  margin-inline-end: 0;
}
html[dir="rtl"] .kpi-tip { right: auto; left: 16px; }
html[dir="rtl"] .kpi::after { right: auto; left: -30px; }
html[dir="rtl"] .insight-fact,
html[dir="rtl"] .insight-int,
html[dir="rtl"] .insight-rec { border-left: 0; }
html[dir="rtl"] .insight-fact { border-right: 3px solid var(--brand); }
html[dir="rtl"] .insight-int { border-right: 3px solid #7aa3d4; }
html[dir="rtl"] .insight-rec { border-right: 3px solid var(--green); }
html[dir="rtl"] .quad ul { padding-left: 0; padding-right: 16px; }
html[dir="rtl"] .toast-wrap { right: auto; left: 24px; }
html[dir="rtl"] .heat-label,
html[dir="rtl"] .reason-cell { text-align: right; }
html[dir="rtl"] .page-kicker,
html[dir="rtl"] .kpi-label,
html[dir="rtl"] .field label,
html[dir="rtl"] .insight-kicker,
html[dir="rtl"] .insight-row span,
html[dir="rtl"] .legend-pill { letter-spacing: 0.02em; }

.view { display: none; }
.view.active { display: block; }

.wa-box textarea { min-height: 180px; }

@media (max-width: 1200px) {
  .filters { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .page-title { font-size: 32px; }
  .chart-wrap { height: 300px; }
}

@media (max-width: 980px) {
  html, body.app-body { overflow-x: hidden; }
  body.app-body, .app-shell { display: block; }
  .menu-toggle { display: grid; }
  .nav-backdrop {
    display: block;
    position: fixed; inset: 0;
    background: rgba(32, 72, 147, 0.35);
    z-index: 35;
    opacity: 0; pointer-events: none;
    transition: opacity 0.2s ease;
  }
  body.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }
  .sidebar {
    position: fixed;
    top: 0; bottom: 0;
    left: 0; right: auto;
    width: min(300px, 88vw);
    height: 100vh;
    z-index: 40;
    transform: translateX(-110%);
    visibility: hidden;
    transition: transform 0.22s ease, visibility 0.22s ease;
    box-shadow: 0 20px 50px rgba(20, 44, 92, 0.28);
  }
  html[dir="rtl"] .sidebar {
    left: auto !important;
    right: 0;
    transform: translateX(110%);
  }
  body.nav-open .sidebar,
  html[dir="rtl"] body.nav-open .sidebar {
    transform: translateX(0);
    visibility: visible;
  }
  .side-nav { flex-direction: column; flex-wrap: nowrap; }
  .main { height: auto; min-height: 100vh; padding: 16px 14px 36px; overflow: visible; }
  .topbar { flex-direction: column; align-items: stretch; gap: 14px; }
  .topbar-actions { justify-content: flex-start; }
  .page-title { font-size: 26px; }
  .page-sub { font-size: 13px; }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .display-4 { font-size: 2rem !important; }
  .kpi-value { font-size: 26px; }
  .chart-wrap { height: 260px; }
  .chart-wrap-reason { height: 280px; }
  .matrix { grid-template-columns: 1fr; }
  .heatmap { overflow-x: auto; }
  .table-responsive { overflow-x: auto; }
  .empty-hero { min-height: 52vh; padding: 28px 14px; }
  .empty-hero h1 { font-size: 32px; }
  .insights-head { flex-direction: column; align-items: flex-start; }
  .reason-charts { padding: 16px 12px; }
}

@media (max-width: 640px) {
  .filters { grid-template-columns: 1fr; }
  .page-title { font-size: 22px; }
  .section-title { font-size: 22px; }
  .topbar-actions .btn-ghost,
  .topbar-actions .btn-gold,
  .topbar-actions .btn-cyan { width: 100%; }
  .empty-hero h1 { font-size: 26px; }
  .dropzone { padding: 22px 14px; }
  .insight-row { grid-template-columns: 1fr; }
  .loader-card { padding: 22px 16px; }
}

@media print {
  .sidebar, .topbar, .filters, .no-print, .overlay, .toast-wrap { display: none !important; }
  .main { padding: 0; }
  .view { display: block !important; page-break-after: always; }
  body.app-body { background: #fff; color: #204893; }
  .card, .kpi, .panel, .insight, .quad { break-inside: avoid; box-shadow: none; background: #fff; color: #204893; border-color: #ddd; }
  .page-title, .section-title, .kpi-value { color: #204893; }
}
