:root {
  --bg: #f6f7f4;
  --ink: #1d2522;
  --muted: #65716b;
  --line: #d9ded7;
  --panel: #ffffff;
  --green: #146b43;
  --teal: #13747d;
  --gold: #b87a13;
  --red: #a64238;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Tahoma, Arial, sans-serif;
  line-height: 1.6;
  overflow-x: hidden;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  padding: 28px clamp(18px, 4vw, 56px);
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(26px, 4vw, 46px); line-height: 1.25; }
h2 { margin-bottom: 4px; font-size: 20px; }

button {
  border: 1px solid var(--green);
  background: var(--green);
  color: #fff;
  padding: 10px 14px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  font: inherit;
}

input, select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  border-radius: 6px;
  font: inherit;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

main { padding: 28px clamp(18px, 4vw, 56px) 56px; }

.answer {
  background: #123b2b;
  color: #fff;
  padding: clamp(22px, 4vw, 38px);
  border-radius: 8px;
  margin-bottom: 18px;
}

.answer span { color: #cddfd2; }
.answer h2 { font-size: clamp(24px, 4vw, 40px); line-height: 1.35; margin: 8px 0 0; }

.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.control-panel { margin-bottom: 18px; }

.controls {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr 1fr;
  gap: 12px;
}

.filter-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.secondary {
  background: #fff;
  color: var(--green);
}

.metrics article, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metrics article { padding: 18px; }
.metrics span, .panel-title span { display: block; color: var(--muted); font-size: 13px; }
.metrics strong { display: block; font-size: 32px; margin-top: 4px; }

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.panel { padding: 18px; overflow: hidden; min-width: 0; }
.wide { grid-column: 1 / -1; }
.panel-title { margin-bottom: 16px; }

.bar-row {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr) 74px;
  gap: 12px;
  align-items: center;
  margin: 10px 0;
}

.interactive-bar {
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 4px 0;
  border-radius: 6px;
  text-align: inherit;
}

.interactive-bar:hover {
  background: #f2f6ef;
}

.bar-label { font-weight: 700; }
.bar-label,
.bar-value,
.legend-row strong,
.flow-node strong,
.flow-link strong {
  min-width: 0;
  overflow-wrap: anywhere;
  white-space: normal;
}
.track {
  height: 14px;
  border-radius: 999px;
  background: #e7ebe5;
  overflow: hidden;
}

.fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--green), var(--teal));
}

.bar-value { color: var(--muted); text-align: left; direction: ltr; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: #fafbf8;
  color: var(--ink);
}

.ranked { margin: 0; padding: 0 22px 0 0; }
.ranked li { margin-bottom: 9px; }
.ranked button {
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 0;
  white-space: normal;
}

.mini-bars .bar-row {
  grid-template-columns: 95px minmax(0, 1fr) 54px;
}

.pipeline {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.pipeline-step {
  position: relative;
  display: grid;
  gap: 4px;
  min-height: 118px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  padding: 14px;
}

.pipeline-step:not(:last-child)::after {
  content: "";
  position: absolute;
  top: 50%;
  left: -10px;
  width: 10px;
  height: 2px;
  background: var(--teal);
}

.pipeline-number {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  direction: ltr;
}

.pipeline-step span {
  font-size: 24px;
  font-weight: 700;
}

.pipeline-step small {
  color: var(--muted);
}

.donut-wrap {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  gap: 18px;
  align-items: center;
}

.donut {
  width: 100%;
  max-width: 220px;
}

.donut circle {
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
}

.donut text:first-of-type {
  fill: var(--ink);
  font-size: 5px;
  font-weight: 700;
}

.donut text:last-of-type {
  fill: var(--muted);
  font-size: 2.6px;
}

.legend {
  display: grid;
  gap: 8px;
}

.legend-row {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) 44px;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  background: #fbfcfa;
  color: var(--ink);
  text-align: inherit;
}

.legend-row span {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.legend-row em {
  color: var(--muted);
  font-style: normal;
  direction: ltr;
}

.columns-chart {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  align-items: end;
  min-height: 260px;
  overflow-x: auto;
}

.column-item {
  display: grid;
  grid-template-rows: auto 160px auto;
  gap: 8px;
  align-items: end;
  justify-items: center;
  border: 1px solid var(--line);
  background: #fbfcfa;
  color: var(--ink);
  min-width: 0;
}

.column-value {
  color: var(--muted);
  font-size: 13px;
}

.column-bar {
  width: 34px;
  border-radius: 6px 6px 0 0;
  background: linear-gradient(180deg, var(--gold), var(--red));
}

.column-item strong {
  width: 100%;
  min-height: 42px;
  font-size: 12px;
  white-space: normal;
  overflow-wrap: anywhere;
}

.treemap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 260px;
}

.treemap-cell {
  flex-basis: 31%;
  min-height: 74px;
  display: grid;
  align-content: end;
  gap: 3px;
  border: 0;
  color: #fff;
  text-align: inherit;
  white-space: normal;
}

.treemap-cell strong,
.treemap-cell span {
  text-shadow: 0 1px 2px rgba(0,0,0,.22);
}

.treemap-cell span {
  font-size: 12px;
}

.word-cloud {
  min-height: 260px;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: 8px 12px;
  padding: 10px;
}

.cloud-word {
  border: 0;
  background: transparent;
  padding: 2px 4px;
  color: var(--green);
}

.cloud-word:hover {
  background: #eef5ef;
}

.tone-1 { color: var(--teal); }
.tone-2 { color: var(--gold); }
.tone-3 { color: var(--red); }

.sankey {
  display: grid;
  grid-template-columns: 1fr .7fr 1fr 1.2fr 1fr 1.2fr 1fr;
  gap: 10px;
  align-items: center;
  overflow-x: auto;
  padding-bottom: 4px;
}

.insight-types {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.insight-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  padding: 14px;
  min-width: 0;
}

.insight-card span {
  color: var(--teal);
  font-size: 28px;
  font-weight: 700;
}

.insight-card strong {
  display: block;
  margin: 4px 0;
}

.insight-card p {
  margin: 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.flow-node,
.flow-link {
  border: 1px solid var(--line);
  background: #fbfcfa;
  color: var(--ink);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 4px;
  min-width: 130px;
  text-align: inherit;
}

.flow-node strong,
.flow-link strong {
  font-size: 20px;
}

.flow-node span,
.flow-link span {
  color: var(--muted);
  white-space: normal;
}

.flow-lane {
  height: 86px;
  display: flex;
  align-items: center;
}

.flow-band {
  height: 28px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--green), var(--teal));
}

.flow-column {
  display: grid;
  gap: 8px;
  min-width: 180px;
}

.flow-link {
  position: relative;
  overflow: hidden;
}

.flow-link::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--w);
  opacity: .18;
  background: var(--teal);
}

.flow-link > * {
  position: relative;
}

.quran-link::before {
  background: var(--gold);
}

.result-node {
  border-color: #9cc9ad;
  background: #e8f3ec;
}

.examples { margin-top: 14px; }
.examples-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.topic-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfa;
}

.topic-card h3 { margin: 0 0 8px; font-size: 17px; }
.topic-card p { margin: 0 0 8px; color: #2f3a35; }
.topic-card small { color: var(--muted); }

.comment-list {
  display: grid;
  gap: 10px;
  max-height: 720px;
  overflow: auto;
  padding-inline-end: 4px;
}

.comment-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  padding: 14px;
}

.comment-card p {
  margin: 10px 0;
  color: #26312d;
}

.comment-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
}

.topic-badge {
  background: #e8f3ec;
  color: var(--green);
}

.quran-badge {
  background: #fff2da;
  color: #7c4b00;
}

.empty {
  margin: 0;
  color: var(--muted);
}

@media (max-width: 1100px) {
  .controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pipeline { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sankey { grid-template-columns: repeat(4, minmax(160px, 1fr)); }
  .insight-types { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  main { padding-inline: 12px; }
  .topbar { padding-inline: 12px; }
  .metrics, .grid, .examples-grid, .controls, .insight-types { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 1fr; gap: 5px; }
  .bar-value { text-align: right; }
  .filter-actions { align-items: stretch; flex-direction: column; }
  .pipeline, .donut-wrap, .columns-chart { grid-template-columns: 1fr; }
  .sankey { grid-template-columns: 1fr; }
  .pipeline-step:not(:last-child)::after { display: none; }
  .column-item { grid-template-rows: auto 120px auto; }
  .treemap-cell { flex-basis: 100%; }
  .comment-list { max-height: none; }
  button, input, select { max-width: 100%; }
}

@media (max-width: 420px) {
  h1 { font-size: 24px; }
  h2 { font-size: 18px; }
  .answer h2 { font-size: 22px; }
  .metrics strong { font-size: 26px; }
  .panel { padding: 14px; }
  .columns-chart { grid-template-columns: repeat(2, minmax(120px, 1fr)); }
  .donut { max-width: 190px; margin-inline: auto; }
}
