:root {
  --r-primary: var(--auh-primary, #01529d);
  --r-secondary: var(--auh-secondary, #179ec9);
  --r-accent: var(--auh-accent, #11aae2);
  --r-success: var(--auh-success, #008e54);
  --r-bg: var(--auh-bg, #f4f8fb);
  --r-card: var(--auh-surface, #fff);
  --r-text: var(--auh-text, #152335);
  --r-muted: var(--auh-muted, #69788a);
  --r-border: var(--auh-border, #dbe6ee);
  --r-radius: 18px;
  --r-shadow: 0 16px 42px rgba(1, 82, 157, .08);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--r-bg); color: var(--r-text); }
.auh-reports-body {
  padding: 0;
  overflow-x: hidden;
  font-family: var(--auh-font-ar, "Almarai", Arial, sans-serif) !important;
}
html[dir="ltr"] .auh-reports-body {
  font-family: var(--auh-font-en, "Gill Sans", Arial, sans-serif) !important;
}
.auh-reports-app,
.auh-reports-app button,
.auh-reports-app input,
.auh-reports-app select,
.auh-reports-app textarea,
.auh-reports-app table,
.auh-reports-app dialog {
  font-family: var(--auh-font-ar, "Almarai", Arial, sans-serif) !important;
}
html[dir="ltr"] .auh-reports-app,
html[dir="ltr"] .auh-reports-app button,
html[dir="ltr"] .auh-reports-app input,
html[dir="ltr"] .auh-reports-app select,
html[dir="ltr"] .auh-reports-app textarea,
html[dir="ltr"] .auh-reports-app table,
html[dir="ltr"] .auh-reports-app dialog {
  font-family: var(--auh-font-en, "Gill Sans", Arial, sans-serif) !important;
}
.auh-reports-app { width: 100%; min-height: 100vh; font-size: 15px; line-height: 1.55; }
.r-standalone-layout { min-height: 100vh; display: grid; grid-template-columns: 250px minmax(0, 1fr); }
.r-standalone-sidebar {
  min-height: 100vh; padding: 22px 14px; display: flex; flex-direction: column; color: #fff;
  background: linear-gradient(180deg, var(--auh-sidebar-start, #016aa8), var(--auh-sidebar-mid, #01529d) 55%, var(--auh-sidebar-end, #013f78));
}
.r-standalone-brand { padding: 8px; display: grid; justify-items: center; gap: 8px; color: #fff; text-align: center; text-decoration: none; }
.r-standalone-brand img { width: min(150px, 100%); height: 82px; object-fit: contain; }
.r-standalone-sidebar nav { margin-top: 24px; display: grid; gap: 6px; }
.r-standalone-sidebar nav a, .r-standalone-footer a { min-height: 43px; padding: 10px 13px; border: 1px solid transparent; border-radius: 11px; display: flex; align-items: center; color: #fff; font-weight: 800; text-decoration: none; }
.r-standalone-sidebar nav a:hover, .r-standalone-sidebar nav a:focus { background: color-mix(in srgb, var(--r-accent) 75%, transparent); }
.r-standalone-footer { margin-top: auto; padding-top: 20px; display: grid; gap: 7px; }
.r-standalone-footer a { justify-content: center; border-color: rgba(255,255,255,.28); font-size: 13px; }
.r-standalone-main { min-width: 0; }
.r-shell { width: 100%; padding: clamp(16px, 2.5vw, 36px); }
.r-icon { width: 20px; height: 20px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
button { cursor: pointer; }
button:disabled { opacity: .5; cursor: not-allowed; }

.r-page-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin: 0 0 24px; }
.r-page-heading h1 { margin: 2px 0 3px; color: var(--r-primary); font-size: clamp(27px, 3vw, 40px); line-height: 1.15; }
.r-page-heading p { margin: 0; max-width: 780px; color: var(--r-muted); }
.r-eyebrow { color: var(--r-secondary); font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.r-heading-actions, .r-preview-actions, .r-card-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; }
.r-btn { min-height: 42px; padding: 9px 16px; border: 1px solid transparent; border-radius: 11px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; color: var(--r-primary); background: var(--r-card); font-weight: 800; line-height: 1.2; text-decoration: none; transition: transform .15s ease, box-shadow .15s ease, background .15s ease; }
.r-btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 7px 20px rgba(1,82,157,.13); }
.r-btn.primary { color: #fff; background: linear-gradient(135deg, var(--r-primary), var(--r-secondary)); }
.r-btn.secondary { border-color: color-mix(in srgb, var(--r-primary) 24%, var(--r-border)); color: var(--r-primary); }
.r-btn.ghost { min-height: 36px; padding: 7px 11px; border-color: var(--r-border); background: transparent; font-size: 13px; }
.r-link { border: 0; padding: 4px; display: inline-flex; align-items: center; gap: 5px; background: transparent; color: var(--r-primary); font-weight: 800; }
.r-link .r-icon { width: 16px; height: 16px; }
[dir="rtl"] .r-link .r-icon, [dir="rtl"] .r-source-card > .r-btn .r-icon { transform: scaleX(-1); }
.r-icon-btn { width: 38px; height: 38px; padding: 0; border: 1px solid var(--r-border); border-radius: 10px; display: inline-grid; place-items: center; color: var(--r-primary); background: var(--r-card); }
.r-icon-btn.danger { color: #c24135; }

.r-kpi-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-bottom: 20px; }
.r-metric-card { min-height: 132px; padding: 22px; border: 1px solid var(--r-border); border-radius: var(--r-radius); display: flex; align-items: center; gap: 18px; background: var(--r-card); box-shadow: var(--r-shadow); overflow: hidden; position: relative; }
.r-metric-card::after { content: ""; position: absolute; inset-inline-end: -34px; top: -42px; width: 120px; height: 120px; border-radius: 50%; background: color-mix(in srgb, var(--r-accent) 8%, transparent); }
.r-icon-box, .r-source-icon { width: 54px; height: 54px; border-radius: 15px; display: grid; place-items: center; color: var(--r-primary); background: color-mix(in srgb, var(--r-accent) 12%, #fff); }
.r-metric-card > div:last-child { display: grid; position: relative; z-index: 1; }
.r-metric-card small, .r-metric-card span { color: var(--r-muted); }
.r-metric-card strong { color: var(--r-primary); font-size: 30px; line-height: 1.15; }
.r-security { margin-bottom: 26px; padding: 18px 22px; border: 1px solid color-mix(in srgb, var(--r-success) 25%, var(--r-border)); border-radius: 15px; display: flex; align-items: flex-start; gap: 14px; color: color-mix(in srgb, var(--r-success) 80%, #102a43); background: color-mix(in srgb, var(--r-success) 7%, #fff); }
.r-security > .r-icon { width: 28px; height: 28px; margin-top: 2px; }
.r-security h2, .r-security p { margin: 0; }
.r-security h2 { font-size: 17px; }
.r-security p { margin-top: 3px; color: var(--r-muted); }

.r-section { margin-top: 24px; }
.r-section-title { margin-bottom: 14px; display: flex; align-items: end; justify-content: space-between; gap: 16px; }
.r-section-title h2, .r-section-title p { margin: 0; }
.r-section-title h2 { color: var(--r-primary); font-size: 22px; }
.r-section-title p { color: var(--r-muted); }
.r-source-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.r-source-card { min-width: 0; padding: 20px; border: 1px solid var(--r-border); border-radius: var(--r-radius); display: grid; grid-template-columns: auto 1fr; gap: 14px; background: var(--r-card); box-shadow: var(--r-shadow); }
.r-source-copy { min-width: 0; }
.r-source-copy small { color: var(--r-secondary); font-size: 11px; font-weight: 800; letter-spacing: .08em; }
.r-source-copy h3 { margin: 2px 0 4px; color: var(--r-primary); font-size: 18px; }
.r-source-copy p { min-height: 46px; margin: 0 0 8px; color: var(--r-muted); }
.r-source-copy span { color: var(--r-muted); font-size: 12px; }
.r-source-card > .r-btn { grid-column: 1 / -1; width: 100%; }

.r-report-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.r-report-card { min-width: 0; padding: 20px; border: 1px solid var(--r-border); border-radius: var(--r-radius); display: flex; flex-direction: column; background: var(--r-card); box-shadow: var(--r-shadow); }
.r-report-top { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; }
.r-report-top .r-icon-box { width: 46px; height: 46px; border-radius: 13px; }
.r-report-top small { color: var(--r-secondary); font-size: 11px; font-weight: 800; }
.r-report-top h3 { margin: 0; color: var(--r-primary); font-size: 17px; }
.r-report-card > p { min-height: 44px; margin: 14px 0; color: var(--r-muted); }
.r-report-meta { margin-bottom: 14px; color: var(--r-muted); font-size: 12px; }
.r-card-actions { margin-top: auto; }
.r-card-actions .r-btn { flex: 1; }
.r-badge { padding: 4px 8px; border-radius: 999px; color: var(--r-primary); background: color-mix(in srgb, var(--r-accent) 12%, #fff); font-size: 11px; font-weight: 800; }

.r-builder { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); align-items: start; gap: 20px; }
.r-builder-controls { display: grid; gap: 14px; }
.r-panel, .r-preview-card { border: 1px solid var(--r-border); border-radius: var(--r-radius); background: var(--r-card); box-shadow: var(--r-shadow); overflow: hidden; }
.r-panel { padding: 17px; }
.r-panel-head, .r-panel-title { margin-bottom: 14px; display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.r-panel-head > span { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; color: var(--r-primary); background: color-mix(in srgb, var(--r-accent) 12%, #fff); }
.r-panel-head > div { flex: 1; }
.r-panel h2, .r-panel p { margin: 0; }
.r-panel h2 { color: var(--r-primary); font-size: 16px; }
.r-panel p { color: var(--r-muted); font-size: 12px; }
.r-source-note { margin-top: 11px; padding: 11px; border-radius: 11px; display: grid; background: var(--r-bg); }
.r-source-note small { color: var(--r-muted); }
.r-field { display: grid; gap: 6px; min-width: 0; }
.r-field > span { color: var(--r-text); font-size: 12px; font-weight: 800; }
.r-field input, .r-field select, .r-field textarea,
.r-search, .r-filter input, .r-filter select {
  width: 100%; min-width: 0; min-height: 42px; padding: 9px 11px; border: 1px solid var(--r-border); border-radius: 10px; outline: 0; color: var(--r-text); background: #fff;
}
.r-field textarea { min-height: 82px; resize: vertical; }
.r-field input:focus, .r-field select:focus, .r-field textarea:focus,
.r-search:focus, .r-filter input:focus, .r-filter select:focus { border-color: var(--r-accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--r-accent) 15%, transparent); }
.r-search { margin-bottom: 10px; }
.r-check-list { max-height: 250px; overflow: auto; padding-inline-end: 4px; display: grid; gap: 3px; scrollbar-width: thin; }
.r-check { min-width: 0; padding: 7px 8px; border-radius: 8px; display: flex; align-items: flex-start; gap: 9px; cursor: pointer; }
.r-check:hover { background: var(--r-bg); }
.r-check input { width: 17px; height: 17px; margin: 2px 0 0; accent-color: var(--r-primary); }
.r-check span { min-width: 0; display: grid; color: var(--r-text); font-weight: 700; }
.r-check small { color: var(--r-muted); font-size: 10px; font-weight: 400; }
.r-check.wide { grid-column: 1 / -1; }
.r-filter-list { display: grid; gap: 9px; }
.r-filter { padding: 10px; border: 1px solid var(--r-border); border-radius: 12px; display: grid; grid-template-columns: 1fr 1fr auto; gap: 7px; background: var(--r-bg); }
.r-filter input { grid-column: 1 / span 2; }
.r-filter input + input { grid-column: 1 / span 2; }
.r-filter .r-icon-btn { grid-column: 3; grid-row: 1; }
.r-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; }
.r-muted { margin: 0; padding: 8px 0; color: var(--r-muted); font-size: 12px; }

.r-preview-wrap { min-width: 0; position: sticky; top: 12px; }
.r-preview-card { min-height: 660px; }
.r-preview-head { min-height: 80px; padding: 16px 20px; border-bottom: 1px solid var(--r-border); display: flex; align-items: center; justify-content: space-between; gap: 16px; background: linear-gradient(135deg, color-mix(in srgb, var(--r-primary) 5%, #fff), #fff); }
.r-preview-head span { color: var(--r-secondary); font-size: 11px; font-weight: 800; }
.r-preview-head h2 { margin: 0; color: var(--r-primary); font-size: 20px; }
.r-preview-body { min-height: 570px; padding: 18px; }
.r-empty-preview, .r-empty { min-height: 300px; padding: 30px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: var(--r-muted); }
.r-empty-preview .r-icon, .r-empty .r-icon { width: 48px; height: 48px; margin-bottom: 10px; color: color-mix(in srgb, var(--r-primary) 45%, #fff); }
.r-empty-preview h3, .r-empty-preview p, .r-empty p { margin: 3px 0; }
.r-table-wrap { width: 100%; overflow: auto; border: 1px solid var(--r-border); border-radius: 12px; }
.r-table-wrap table { width: 100%; border-collapse: collapse; white-space: nowrap; font-size: 13px; }
.r-table-wrap th, .r-table-wrap td { padding: 11px 12px; border-bottom: 1px solid var(--r-border); text-align: start; }
.r-table-wrap th { position: sticky; top: 0; z-index: 1; color: var(--r-primary); background: color-mix(in srgb, var(--r-accent) 8%, #fff); }
.r-table-wrap tbody tr:last-child td { border-bottom: 0; }
.r-table-wrap tbody tr:hover { background: var(--r-bg); }
.r-result-footer { margin-top: 14px; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; color: var(--r-muted); font-size: 12px; }
.r-result-footer > div { display: flex; align-items: center; gap: 8px; }
.r-chart { min-height: 420px; }
.r-bars { padding: 14px 4px; display: grid; align-content: center; gap: 13px; }
.r-bar-row { display: grid; grid-template-columns: minmax(90px, 160px) 1fr 70px; align-items: center; gap: 12px; }
.r-bar-row > span { overflow: hidden; color: var(--r-text); text-overflow: ellipsis; white-space: nowrap; }
.r-bar-row > div { height: 28px; border-radius: 7px; overflow: hidden; background: var(--r-bg); }
.r-bar-row i { display: block; width: var(--bar); height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--r-primary), var(--r-accent)); }
.r-bar-row strong { color: var(--r-primary); text-align: end; }
.r-line { display: grid; grid-template-rows: 330px auto; }
.r-line svg { width: 100%; height: 100%; overflow: visible; }
.r-line line { stroke: var(--r-border); stroke-width: 1; vector-effect: non-scaling-stroke; }
.r-line polyline { fill: none; stroke: var(--r-primary); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.r-line-labels { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(85px, 1fr); overflow: auto; gap: 8px; }
.r-line-labels span { display: grid; text-align: center; }
.r-line-labels b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.r-line-labels small { color: var(--r-primary); }
.r-donut-wrap { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(240px, 1fr); align-items: center; gap: 30px; }
.r-donut { width: min(320px, 78vw); aspect-ratio: 1; margin: auto; border-radius: 50%; display: grid; place-items: center; position: relative; }
.r-donut::after { content: ""; width: 58%; height: 58%; border-radius: 50%; background: var(--r-card); box-shadow: inset 0 0 0 1px var(--r-border); }
.r-donut > span { z-index: 1; position: absolute; display: grid; text-align: center; }
.r-donut strong { color: var(--r-primary); font-size: 30px; }
.r-donut small { color: var(--r-muted); }
.r-legend { display: grid; gap: 10px; }
.r-legend > div { padding: 9px 11px; border-bottom: 1px solid var(--r-border); display: grid; grid-template-columns: 12px 1fr auto; align-items: center; gap: 9px; }
.r-legend i { width: 10px; height: 10px; border-radius: 3px; }
.r-legend span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.r-big-kpi { min-height: 420px; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.r-big-kpi small { color: var(--r-muted); font-size: 16px; }
.r-big-kpi strong { color: var(--r-primary); font-size: clamp(60px, 10vw, 120px); line-height: 1; }

.r-alert { margin-bottom: 16px; padding: 14px 16px; border: 1px solid; border-radius: 12px; display: flex; align-items: center; gap: 9px; }
.r-alert.error { border-color: #f5b7af; color: #a52d21; background: #fff4f2; }
.r-loading { min-height: 260px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--r-muted); }
.r-loading > span { width: 42px; height: 42px; border: 4px solid var(--r-border); border-top-color: var(--r-primary); border-radius: 50%; animation: r-spin .8s linear infinite; }
@keyframes r-spin { to { transform: rotate(360deg); } }

.r-dialog { width: min(760px, calc(100vw - 30px)); max-height: calc(100vh - 40px); padding: 0; border: 0; border-radius: var(--r-radius); color: var(--r-text); background: var(--r-card); box-shadow: 0 28px 100px rgba(0,31,69,.28); }
.r-dialog::backdrop { background: rgba(10, 35, 61, .58); backdrop-filter: blur(3px); }
.r-dialog form { padding: 22px; }
.r-dialog-head { margin-bottom: 18px; display: flex; align-items: start; justify-content: space-between; }
.r-dialog-head h2 { margin: 0; color: var(--r-primary); font-size: 24px; }
.r-form-grid.two { grid-template-columns: repeat(2, minmax(0,1fr)); }
.r-role-list { margin: 16px 0 0; padding: 13px; border: 1px solid var(--r-border); border-radius: 12px; display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); max-height: 190px; overflow: auto; }
.r-role-list legend { padding: 0 5px; color: var(--r-primary); font-weight: 800; }
.r-dialog-actions { margin-top: 18px; display: flex; justify-content: flex-end; gap: 9px; }
.r-form-error { min-height: 20px; margin: 10px 0 0; color: #b42318; }
.auh-reports-toast-region { position: fixed; inset-inline-end: 20px; bottom: 20px; z-index: 100000; display: grid; gap: 9px; pointer-events: none; }
.r-toast { min-width: min(360px, calc(100vw - 40px)); padding: 13px 16px; border: 1px solid var(--r-border); border-radius: 12px; display: flex; align-items: center; gap: 10px; color: var(--r-text); background: #fff; box-shadow: 0 18px 45px rgba(0,31,69,.18); animation: r-toast-in .2s ease-out; }
.r-toast.success { border-inline-start: 4px solid var(--r-success); }
.r-toast.error { border-inline-start: 4px solid #d13f31; }
.r-toast.info { border-inline-start: 4px solid var(--r-primary); }
@keyframes r-toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 1100px) {
  .r-source-grid, .r-report-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .r-builder { grid-template-columns: minmax(280px, 340px) minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .r-standalone-layout { display: block; }
  .r-standalone-sidebar { min-height: 0; padding: 10px; display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 10px; }
  .r-standalone-brand { grid-template-columns: auto auto; justify-content: start; text-align: start; }
  .r-standalone-brand img { width: 76px; height: 48px; }
  .r-standalone-sidebar nav { grid-column: 1 / -1; margin: 0; display: flex; overflow-x: auto; padding-bottom: 3px; }
  .r-standalone-sidebar nav a { flex: 0 0 auto; }
  .r-standalone-footer { grid-column: 1 / -1; margin: 0; padding: 0; grid-template-columns: repeat(2, minmax(0,1fr)); }
  .r-shell { padding: 16px; }
  .r-page-heading { align-items: flex-start; flex-direction: column; }
  .r-heading-actions { width: 100%; }
  .r-heading-actions .r-btn { flex: 1; }
  .r-kpi-grid { grid-template-columns: repeat(3, minmax(150px, 1fr)); overflow-x: auto; scroll-snap-type: x proximity; padding-bottom: 7px; }
  .r-metric-card { scroll-snap-align: start; }
  .r-builder { grid-template-columns: 1fr; }
  .r-preview-wrap { position: static; }
  .r-preview-card { min-height: 520px; }
  .r-preview-body { min-height: 430px; }
  .r-donut-wrap { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
  .r-page-heading h1 { font-size: 28px; }
  .r-source-grid, .r-report-grid { grid-template-columns: 1fr; }
  .r-source-copy p, .r-report-card > p { min-height: 0; }
  .r-form-grid, .r-form-grid.two, .r-role-list { grid-template-columns: 1fr; }
  .r-filter { grid-template-columns: 1fr auto; }
  .r-filter select, .r-filter input, .r-filter input + input { grid-column: 1; }
  .r-filter .r-icon-btn { grid-column: 2; grid-row: 1; }
  .r-preview-head { align-items: flex-start; flex-direction: column; }
  .r-preview-actions { width: 100%; }
  .r-preview-actions .r-btn { flex: 1; }
  .r-preview-body { padding: 10px; }
  .r-bar-row { grid-template-columns: minmax(85px, 110px) 1fr 52px; gap: 7px; font-size: 12px; }
  .r-report-top { grid-template-columns: auto 1fr; }
  .r-report-top .r-badge { grid-column: 2; width: fit-content; }
  .r-card-actions .r-btn { min-width: 150px; }
  .r-result-footer { align-items: flex-start; flex-direction: column; }
}

@media print {
  body { background: #fff !important; }
  .r-standalone-sidebar, .r-page-heading, .r-builder-controls, .r-preview-head, .r-result-footer, .auh-reports-toast-region { display: none !important; }
  .r-standalone-layout, .r-standalone-main { display: block !important; width: 100% !important; }
  .r-shell, .r-builder, .r-preview-wrap, .r-preview-card, .r-preview-body { width: 100% !important; min-height: 0 !important; padding: 0 !important; margin: 0 !important; border: 0 !important; box-shadow: none !important; display: block !important; }
  .r-table-wrap { overflow: visible; }
  .r-table-wrap table { white-space: normal; font-size: 9pt; }
}
