/* =========================================================
   FormYar — reports & report builder
   ========================================================= */
:root {
  --rc-color-0: #047857;
  --rc-color-1: #0d9488;
  --rc-color-2: #e1903d;
  --rc-color-3: #d9534f;
  --rc-color-4: #65a30d;
  --rc-color-5: #2f9e6e;
}
[data-theme="dark"] {
  --rc-color-0: #34d399;
  --rc-color-1: #2dd4bf;
  --rc-color-2: #f3b35b;
  --rc-color-3: #f87171;
  --rc-color-4: #a3e635;
  --rc-color-5: #4ade80;
}

.report-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  padding: 14px 16px;
  margin-bottom: 18px;
}
.rt-main { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; flex: 1; min-width: 0; }
.rt-field { display: flex; flex-direction: column; gap: 5px; min-width: 132px; }
.rt-field > span { font-size: 10px; font-weight: 700; color: var(--muted-2); padding-inline-start: 3px; }
.rt-field select {
  height: 38px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  padding: 0 10px;
  font-family: inherit;
  font-size: 11.5px;
  min-width: 0;
}
.rt-actions { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }

.report-layout {
  display: grid;
  grid-template-columns: 296px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.report-side {
  position: sticky;
  top: 78px;
  max-height: calc(100dvh - 96px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.report-side .panel-head { padding-bottom: 10px; }
.report-side .panel-head h3 { font-size: 13px; }
.report-side .panel-head p { font-size: 10px; }
.report-list { overflow-y: auto; padding: 4px 10px 8px; display: flex; flex-direction: column; gap: 7px; }
.report-card {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 2px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  min-width: 0;
}
.report-card:hover { background: var(--surface-2); }
.report-card.active { background: var(--accent-soft, rgba(4, 120, 87, 0.09)); border-color: var(--accent-line, rgba(4, 120, 87, 0.22)); }
.rc-main {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 1;
  min-width: 0;
  text-align: start;
  border: 0;
  background: transparent;
  padding: 9px 8px;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
}
.rc-icon {
  width: 30px;
  height: 30px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: var(--surface-3, var(--surface-2));
  color: var(--accent);
}
.rc-icon.default { background: var(--mint-soft, #e6f7ef); color: #16794f; }
.rc-copy { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.rc-copy b { font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rc-copy small { font-size: 9.5px; color: var(--muted-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rc-actions { display: flex; align-items: center; gap: 1px; padding-inline-start: 2px; opacity: 0; transition: opacity .16s; }
.report-card:hover .rc-actions, .report-card.active .rc-actions { opacity: 1; }
.btn-xs { width: 24px; height: 24px; min-height: 24px; padding: 0; border-radius: 7px; }
.btn-xs .icon { width: 13px; height: 13px; }
.btn-icon.danger:hover { color: #c93737; background: rgba(217, 83, 79, .1); }
.report-list-empty { display: flex; align-items: center; gap: 8px; padding: 20px 10px; color: var(--muted-2); font-size: 11px; }
.report-list-empty .icon { width: 18px; height: 18px; }

.report-templates { margin-top: auto; border-top: 1px solid var(--line); padding: 10px; display: flex; flex-direction: column; gap: 5px; }
.rt-title { display: flex; align-items: center; gap: 5px; font-size: 10px; font-weight: 800; color: var(--muted-2); margin-bottom: 2px; }
.rt-title .icon { width: 13px; height: 13px; }
.rt-template {
  text-align: start;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 9px;
  padding: 7px 9px;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.rt-template b { font-size: 10.5px; }
.rt-template small { font-size: 9px; color: var(--muted-2); }
.rt-template:hover { border-color: var(--accent-line, var(--line)); background: var(--surface-3, var(--surface-2)); }

.report-canvas { min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.report-head-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  padding: 18px 20px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  box-shadow: var(--shadow-xs, none);
}
.report-head-main { min-width: 0; }
.report-head-badges { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.badge-indigo { background: rgba(4, 120, 87, .12); color: var(--accent); }
.report-head-main h2 { font-size: 21px; margin: 8px 0 3px; letter-spacing: -.4px; }
.report-head-main p { font-size: 12px; color: var(--muted-2); line-height: 1.8; }
.report-head-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 9px; color: var(--muted-2); font-size: 10px; }
.report-head-meta span { display: inline-flex; align-items: center; gap: 4px; }
.report-head-meta .icon { width: 12px; height: 12px; }
.report-head-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.report-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.report-block {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 15px 16px;
  overflow: hidden;
}
.report-block.span-2 { grid-column: span 2; }
.rb-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.rb-head h3 { font-size: 12.5px; }
.rb-type { font-size: 9px; color: var(--muted-2); background: var(--surface-2); border-radius: 20px; padding: 2px 7px; white-space: nowrap; }
.rb-body { min-width: 0; }

.rc-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 9px; }
.rc-kpi { display: flex; align-items: center; gap: 8px; padding: 9px 8px; border-radius: 11px; background: var(--surface-2); min-width: 0; }
.rc-kpi .rk-icon { width: 29px; height: 29px; border-radius: 9px; display: grid; place-items: center; flex: none; }
.rc-kpi .rk-icon .icon { width: 15px; height: 15px; }
.rc-kpi b { display: block; font-size: 17px; line-height: 1.1; }
.rc-kpi small { font-size: 9px; color: var(--muted-2); white-space: nowrap; }
.rk-icon.c1 { background: rgba(4, 120, 87, .12); color: var(--accent); }
.rk-icon.c2 { background: rgba(14, 165, 164, .13); color: #0c8a89; }
.rk-icon.c3 { background: rgba(225, 144, 61, .14); color: #b46c1f; }
.rk-icon.c4 { background: rgba(47, 158, 110, .14); color: #16794f; }

.rc-line-wrap { width: 100%; }
.rc-line-wrap svg { display: block; width: 100%; height: auto; overflow: visible; }
.rc-grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 3 4; opacity: .7; }
.rc-axis { fill: var(--muted-2); font-size: 9px; font-family: inherit; }
.rc-line { stroke: var(--accent); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.rc-line.secondary { stroke: #20b486; stroke-width: 1.8; stroke-dasharray: 5 5; opacity: .8; }
.rc-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 1.5; }
.rc-legend { display: flex; align-items: center; gap: 13px; margin-top: 4px; color: var(--muted-2); font-size: 9.5px; flex-wrap: wrap; }
.rc-legend span { display: inline-flex; align-items: center; gap: 4px; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; background: var(--muted-2); }
.dot.accent { background: var(--accent); }
.dot.mint { background: #20b486; }

.rc-bars { display: flex; flex-direction: column; gap: 10px; }
.rc-bar-row { display: grid; grid-template-columns: minmax(0, 1fr) 42px; gap: 2px 8px; align-items: center; }
.rc-bar-label { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 10.5px; }
.rc-bar-label span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rc-bar-label b { font-size: 10px; color: var(--muted-2); }
.rc-bar-track { grid-column: 1; height: 7px; border-radius: 20px; background: var(--surface-2); overflow: hidden; }
.rc-bar-track span { display: block; height: 100%; border-radius: 20px; min-width: 3px; }
.rc-bar-row small { grid-column: 1 / -1; font-size: 8.5px; color: var(--muted-2); }

.rc-donut-wrap { display: flex; align-items: center; gap: 18px; justify-content: center; flex-wrap: wrap; }
.rc-donut-wrap svg { width: 132px; height: 132px; flex: none; }
.rc-donut-bg { fill: none; stroke: var(--surface-2); stroke-width: 16; }
.rc-donut-a { fill: none; stroke: var(--accent); stroke-width: 16; stroke-linecap: round; }
.rc-donut-num { fill: var(--text); font-size: 20px; font-weight: 800; font-family: inherit; }
.rc-donut-cap { fill: var(--muted-2); font-size: 9px; font-family: inherit; }
.rc-donut-legend { display: flex; flex-direction: column; gap: 8px; font-size: 10px; color: var(--muted-2); }
.rc-donut-legend span { display: flex; align-items: center; gap: 5px; }
.rc-donut-legend b { color: var(--text); }
.rc-donut-legend small { margin-inline-start: auto; }

.rc-stacked { display: flex; flex-direction: column; gap: 11px; }
.rc-stack-row { display: flex; flex-direction: column; gap: 3px; }
.rc-stack-head { display: flex; align-items: center; justify-content: space-between; font-size: 10.5px; }
.rc-stack-head b { color: var(--muted-2); }
.rc-stack-track { display: flex; height: 9px; border-radius: 20px; overflow: hidden; background: var(--surface-2); }
.rc-stack-track span { display: block; height: 100%; min-width: 2px; }
.st-mobile { background: var(--accent); }
.st-desktop { background: #20b486; }
.rc-stack-row small { font-size: 8.5px; color: var(--muted-2); }

.rc-gauge { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.rc-gauge svg { width: 138px; height: 120px; }
.rc-gauge-bg { fill: none; stroke: var(--surface-2); stroke-width: 12; stroke-linecap: round; }
.rc-gauge-fill { fill: none; stroke: var(--accent); stroke-width: 12; stroke-linecap: round; }
.rc-gauge-num { fill: var(--text); font-size: 23px; font-weight: 800; font-family: inherit; }
.rc-gauge-cap { fill: var(--muted-2); font-size: 9px; font-family: inherit; }
.rc-gauge p { font-size: 9.5px; color: var(--muted-2); text-align: center; }

.rc-funnel { display: flex; flex-direction: column; gap: 9px; }
.rc-funnel-row { display: flex; flex-direction: column; gap: 3px; }
.rc-funnel-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 10.5px; }
.rc-funnel-label b { color: var(--muted-2); }
.rc-funnel-track { height: 9px; background: var(--surface-2); border-radius: 20px; overflow: hidden; }
.rc-funnel-track span { display: block; height: 100%; border-radius: 20px; }
.rc-funnel-track .a { background: var(--accent); }
.rc-funnel-track .b { background: #10b981; }
.rc-funnel-track .c { background: #0ea5a4; }
.rc-funnel-track .d { background: #20b486; }
.rc-funnel-row small { font-size: 8.5px; color: var(--muted-2); }

.rc-table-wrap { width: 100%; overflow-x: auto; }
.rc-table { width: 100%; border-collapse: collapse; font-size: 9.5px; min-width: 470px; }
.rc-table th { text-align: start; color: var(--muted-2); font-weight: 700; padding: 6px 7px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.rc-table td { padding: 8px 7px; border-bottom: 1px solid var(--line); vertical-align: top; }
.rc-table tr:last-child td { border-bottom: 0; }
.rc-table td b { font-size: 10px; }
.rc-table td small { display: block; color: var(--muted-2); font-size: 8.5px; margin-top: 1px; }
.rc-table .badge { font-size: 8px; padding: 1px 5px; }

.rc-insights { list-style: none; display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; }
.rc-insights li { position: relative; background: var(--surface-2); border-radius: 9px; padding: 8px 29px 8px 10px; font-size: 10.5px; line-height: 1.9; color: var(--muted); }
.rc-insights li::before { content: "✦"; position: absolute; right: 10px; top: 8px; color: var(--accent); font-size: 10px; }
.rc-insights b { color: var(--text); }
.rc-text { font-size: 11px; line-height: 2; color: var(--muted); white-space: pre-wrap; }
.rc-no-data { display: grid; place-items: center; min-height: 100px; color: var(--muted-2); font-size: 10.5px; text-align: center; background: var(--surface-2); border-radius: 10px; padding: 18px; }

.report-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: 15px;
  padding: 40px 20px;
  color: var(--muted-2);
}
.report-empty .icon { width: 32px; height: 32px; color: var(--accent); }
.report-empty b { color: var(--text); font-size: 13px; }
.report-empty p { font-size: 10.5px; margin-bottom: 6px; }
.report-foot-note { display: flex; align-items: flex-start; gap: 6px; color: var(--muted-2); font-size: 9.5px; line-height: 1.9; padding: 0 4px; }
.report-foot-note .icon { width: 13px; height: 13px; flex: none; margin-top: 3px; }
.report-tip { display: flex; align-items: flex-start; gap: 9px; margin-top: 16px; padding: 11px 14px; font-size: 10.5px; color: var(--muted-2); line-height: 1.9; }
.report-tip .icon { width: 16px; height: 16px; color: var(--accent); flex: none; margin-top: 2px; }
.report-tip b { color: var(--text); }

/* ---------- report builder modal ---------- */
.report-modal .modal-panel { width: min(920px, 100%); max-height: 94vh; }
.report-modal .modal-body { padding: 16px 20px; }
.report-form-grid { display: grid; grid-template-columns: 1.2fr 1.2fr .9fr auto; gap: 10px; align-items: end; }
.report-form-grid .field { margin: 0; }
.report-form-grid .field > span { font-size: 9.5px; }
.report-form-grid input, .report-form-grid select { height: 36px; font-size: 11px; }
.rbe-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; margin: 20px 0 9px; }
.rbe-head h4 { font-size: 12px; }
.rbe-head p { font-size: 9.5px; color: var(--muted-2); margin-top: 2px; }
.rbe-list { display: flex; flex-direction: column; gap: 6px; }
.rbe-item { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; padding: 7px 9px; min-width: 0; }
.rbe-grip { color: var(--muted-2); display: flex; }
.rbe-grip .icon { width: 14px; height: 14px; }
.rbe-icon { width: 29px; height: 29px; flex: none; display: grid; place-items: center; background: var(--surface); border-radius: 8px; color: var(--accent); }
.rbe-icon .icon { width: 14px; height: 14px; }
.rbe-copy { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 1px; }
.rbe-copy b { font-size: 10.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rbe-copy small { font-size: 8.5px; color: var(--muted-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rbe-actions { display: flex; align-items: center; gap: 2px; flex: none; }
.rbe-empty { text-align: center; color: var(--muted-2); font-size: 10.5px; padding: 20px; border: 1px dashed var(--line); border-radius: 10px; }
.rbe-empty .icon { width: 18px; height: 18px; vertical-align: -4px; }
.rbe-add { margin-top: 14px; border: 1px dashed var(--line); border-radius: 12px; padding: 12px; background: var(--surface-2); }
.rbe-add-head { display: flex; align-items: center; gap: 5px; font-size: 10.5px; font-weight: 800; margin-bottom: 9px; }
.rbe-add-head .icon { width: 14px; height: 14px; color: var(--accent); }
.rbe-add-grid { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 8px; align-items: end; }
.rbe-add-grid .field { margin: 0; }
.rbe-add-grid .field > span { font-size: 9px; }
.rbe-add-grid input, .rbe-add-grid select { height: 34px; font-size: 10.5px; }
.rbe-hint { font-size: 9px; color: var(--muted-2); margin-top: 6px; }

.export-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.export-option { display: flex; align-items: center; gap: 9px; text-align: start; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); padding: 10px; color: var(--text); cursor: pointer; font-family: inherit; }
.export-option:hover { border-color: var(--accent-line, var(--line)); background: var(--surface-3, var(--surface-2)); }
.eo-icon { width: 34px; height: 34px; flex: none; border-radius: 10px; display: grid; place-items: center; background: var(--surface); color: var(--accent); }
.eo-icon .icon { width: 16px; height: 16px; }
.export-option b { display: block; font-size: 11px; }
.export-option small { display: block; font-size: 9px; color: var(--muted-2); margin-top: 1px; }

@media (max-width: 1100px) {
  .report-layout { grid-template-columns: 1fr; }
  .report-side { position: static; max-height: none; }
  .report-list { flex-direction: row; overflow-x: auto; padding-bottom: 10px; }
  .report-card { min-width: 240px; }
  .report-templates { display: none; }
  .rc-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .report-toolbar { padding: 12px; }
  .rt-main { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
  .rt-field { min-width: 0; }
  .rt-actions { width: 100%; justify-content: flex-end; }
  .report-grid { grid-template-columns: 1fr; }
  .report-block.span-2 { grid-column: auto; }
  .report-head-card { padding: 14px; }
  .report-head-main h2 { font-size: 17px; }
  .report-head-actions { width: 100%; }
  .report-head-actions .btn { flex: 1; justify-content: center; }
  .rc-kpis { grid-template-columns: 1fr 1fr; }
  .report-form-grid { grid-template-columns: 1fr 1fr; }
  .report-form-grid .btn { grid-column: span 2; }
  .rbe-add-grid { grid-template-columns: 1fr 1fr; }
  .rbe-add-grid .btn { grid-column: span 2; }
  .report-modal .modal-body { padding: 14px; }
  .export-grid { grid-template-columns: 1fr; }
}
@media (max-width: 420px) {
  .rt-main { grid-template-columns: 1fr; }
  .report-card { min-width: 210px; }
  .rc-kpis { grid-template-columns: 1fr; }
  .report-form-grid { grid-template-columns: 1fr; }
  .report-form-grid .btn { grid-column: auto; }
  .rbe-item { flex-wrap: wrap; }
  .rbe-actions { margin-inline-start: auto; }
}

@media print {
  :root,
  [data-theme="dark"] {
    --ink: #111827;
    --ink-2: #1f2937;
    --muted: #4b5563;
    --muted-2: #6b7280;
    --bg: #ffffff;
    --bg-2: #f8fafc;
    --card: #ffffff;
    --card-2: #f8fafc;
    --line: #e5e7eb;
    --line-2: #d1d5db;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --surface-3: #ffffff;
    --text: #111827;
    --accent: #047857;
    --accent-soft: #ecfdf5;
    --accent-line: #a7f3d0;
  }
  body { background: #fff !important; color: #111827; }
  .sidebar, .topbar, .mobile-tabbar, .sidebar-backdrop, .page-head-actions,
  .report-toolbar, .report-side, .report-tip, .report-head-actions,
  .report-foot-note, .toast-wrap, .fy-ai-launcher, .fy-ai-layer, .fy-ai-panel, .fy-ai-backdrop, .ai-launcher, .ai-layer, .ai-panel, .ai-preview { display: none !important; }
  .app-layout { display: block; }
  .app-main { margin: 0 !important; }
  .content { padding: 0 !important; max-width: none !important; }
  .report-layout { display: block; }
  .report-head-card { box-shadow: none; border-color: #ddd; }
  .report-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .report-block { break-inside: avoid; border-color: #ddd; }
  .report-block.span-2 { grid-column: span 2; }
  .report-empty, .report-tip, .toast-wrap { display: none; }
  .rc-line-wrap svg { max-height: 200px; }
}
