:root {
  --cd-blue: #002b7f;
  --cd-blue-strong: #001f5a;
  --cd-yellow: #ffd100;
  --bg: #ffffff;
  --ink: #0f2247;
  --muted: #607193;
  --line: #dde6f5;
  --line-strong: #c8d7ef;
  --surface: #ffffff;
  --surface-soft: #f7faff;
  --surface-warm: #fffef6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Manrope", sans-serif;
  line-height: 1.35;
}

.page-bg {
  position: fixed;
  inset: 0;
  background: #fff;
  z-index: -1;
}

.container {
  width: min(1320px, 94vw);
  margin: 26px auto 48px;
  display: grid;
  gap: 14px;
}

.topbar {
  position: relative;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: linear-gradient(150deg, #ffffff 60%, #fffef4 100%);
  padding: 18px;
  display: grid;
  gap: 18px;
  overflow: hidden;
}

.topbar::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 5px;
  background: linear-gradient(90deg, var(--cd-blue) 0 68%, var(--cd-yellow) 68% 100%);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  width: 96px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
  padding: 7px;
}

.brand-copy {
  display: grid;
  gap: 3px;
}

h1 {
  margin: 0;
  letter-spacing: -0.02em;
  font-size: clamp(1.2rem, 2.2vw, 1.9rem);
}

h2 {
  margin: 0 0 10px;
  letter-spacing: -0.01em;
  font-size: 1.01rem;
}

h3 {
  margin: 6px 0 8px;
  font-size: 0.94rem;
}

p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.controls-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(140px, 1fr)) repeat(2, minmax(130px, 1fr)) auto;
  align-items: end;
  gap: 10px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
}

.control-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #4f628a;
  font-weight: 700;
}

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

select:focus,
input:focus {
  outline: 2px solid #acc5ff;
  outline-offset: 1px;
}

button {
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}

button:hover {
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--cd-blue);
  color: #fff;
  border-color: var(--cd-blue);
  box-shadow: 0 10px 24px rgba(0, 43, 127, 0.2);
}

.btn-secondary {
  background: #fff;
  color: var(--cd-blue);
  border-color: #b9cbef;
}

.btn-secondary:hover {
  background: #f3f7ff;
}

.custom-range {
  display: none;
}

.status-line {
  border-radius: 13px;
  border: 1px solid #d6e4fc;
  border-left: 5px solid var(--cd-blue);
  background: #f5f9ff;
  color: #2b467c;
  padding: 11px 14px;
  font-size: 0.88rem;
}

.kpi-grid,
.charts-grid,
.insights-grid {
  display: grid;
  gap: 12px;
}

.kpi-grid {
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
}

.charts-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.insights-grid {
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

.whatsapp-insights-grid {
  margin-top: 2px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.whatsapp-insights-grid .wa-report-human {
  grid-column: 1 / -1;
}

.whatsapp-insights-grid .card {
  padding: 18px;
  border-radius: 18px;
  border: 1px solid #d7e3f8;
  background: linear-gradient(180deg, #ffffff 0%, #f9fbff 100%);
}

.whatsapp-insights-grid h2 {
  margin-bottom: 12px;
  line-height: 1.2;
}

.card,
.kpi {
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(16, 34, 71, 0.04);
}

.card {
  padding: 15px;
}

.kpi {
  padding: 13px;
  border-top: 4px solid var(--cd-blue);
}

.kpi.warning {
  border-top-color: #e39a00;
}

.kpi .label {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #5a6f95;
  font-weight: 700;
}

.kpi .value {
  margin-top: 5px;
  font-size: 1.75rem;
  letter-spacing: -0.02em;
  font-weight: 800;
}

.kpi .sub {
  margin-top: 3px;
  font-size: 0.8rem;
  color: #3a5686;
}

.card-chart {
  min-height: 350px;
}

.chart-wrap {
  height: 285px;
}

.chart-wrap-line {
  height: 295px;
}

.donut-layout {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(170px, 0.65fr);
  gap: 12px;
  align-items: center;
  min-height: 285px;
}

.chart-wrap-donut {
  height: 250px;
}

.donut-breakdown {
  display: grid;
  gap: 8px;
}

.donut-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
  background: #fbfdff;
}

.donut-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.donut-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-block;
  margin-right: 6px;
}

.donut-label {
  color: #436192;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.donut-value {
  font-size: 1.2rem;
  font-weight: 800;
  color: #0f2c63;
}

.donut-sub {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.78rem;
}

.metric-highlight {
  border-radius: 12px;
  border: 1px dashed #ffd86d;
  background: var(--surface-warm);
  padding: 10px;
  display: grid;
  gap: 4px;
  font-size: 0.95rem;
}

.wa-kpi-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.wa-kpi-value {
  font-size: 2rem;
  letter-spacing: -0.02em;
  font-weight: 800;
  color: #0f2c63;
}

.wa-kpi-label {
  font-size: 0.92rem;
  color: #3e5988;
  font-weight: 700;
}

.wa-progress {
  margin-top: 8px;
  height: 9px;
  border-radius: 999px;
  background: #f0f5ff;
  border: 1px solid #d9e5fb;
  overflow: hidden;
}

.wa-progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #1f4ea6 0%, #0d3b90 50%, #f0b800 100%);
}

.wa-split-metrics {
  margin-top: 9px;
  display: grid;
  gap: 5px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  font-size: 0.85rem;
  color: #3b5582;
}

.wa-split-metrics span {
  padding: 7px 9px;
  border-radius: 10px;
  border: 1px solid #d9e6fc;
  background: #f8fbff;
}

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

.tag {
  border: 1px solid #d4e1fc;
  border-radius: 14px;
  padding: 9px 10px;
  color: #1c3f84;
  background: #f4f8ff;
  display: grid;
  gap: 3px;
}

.tone-chip-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
}

.tone-chip-value {
  font-size: 1.02rem;
  font-weight: 800;
}

.tag.tone-anger {
  border-color: #f6c7c7;
  color: #9f1f1f;
  background: #fff1f1;
}

.tag.tone-urgent {
  border-color: #f7d4aa;
  color: #9a4a00;
  background: #fff5e8;
}

.tag.tone-neutral {
  border-color: #ccd8ee;
  color: #365a92;
  background: #f4f7fc;
}

.tag.tone-positive {
  border-color: #bfe5c9;
  color: #196b3b;
  background: #ecfbf1;
}

.search-row,
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.search-row input {
  flex: 1;
  min-width: 220px;
}

.timeline {
  margin: 10px 0 0;
  padding-left: 17px;
  display: grid;
  gap: 8px;
}

.intervention-list {
  max-height: 340px;
  overflow-y: auto;
  padding-right: 4px;
  margin-top: 10px;
  padding-left: 0;
  list-style: none;
}

.intervention-item {
  border: 1px solid #d8e5fb;
  background: #f9fbff;
  border-radius: 12px;
  padding: 10px 11px;
}

.intervention-item + .intervention-item {
  margin-top: 8px;
}

.intervention-item.empty {
  color: #4d648e;
  font-size: 0.86rem;
}

.intervention-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.intervention-head strong {
  font-size: 0.95rem;
  line-height: 1.3;
}

.intervention-meta {
  margin-top: 4px;
  color: #3f5f94;
  font-size: 0.82rem;
}

.intervention-reason {
  margin-top: 6px;
  color: #2f4f86;
  font-size: 0.8rem;
}

.pill {
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.72rem;
  border: 1px solid;
}

.pill.open {
  color: #8e6000;
  background: #fff8dd;
  border-color: #ffd86e;
}

.pill.closed {
  color: #1f458f;
  background: #edf3ff;
  border-color: #b8cefb;
}

.small-note {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.82rem;
}

#sentimentSummary {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.wa-summary-pill {
  border-radius: 999px;
  border: 1px solid #d2e0fa;
  background: #f5f9ff;
  color: #304f83;
  padding: 5px 10px;
  font-size: 0.78rem;
}

.wa-meta-note {
  margin-top: 6px;
  color: #3c5888;
  font-size: 0.84rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.prompt-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 86px;
  overflow-y: auto;
  padding-right: 2px;
}

.prompt-chip {
  border: 1px solid #c4d7f8;
  background: linear-gradient(180deg, #f7faff 0%, #eef4ff 100%);
  color: #1b3f83;
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 0.79rem;
  font-weight: 700;
  line-height: 1.2;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.14s ease;
}

.prompt-chip:hover {
  background: #e9f0ff;
  border-color: #a7c2f6;
  transform: translateY(-1px);
}

.chat-thread {
  border: 1px solid #d7e4fb;
  background: linear-gradient(180deg, #fbfdff 0%, #f7faff 100%);
  border-radius: 12px;
  padding: 12px;
  min-height: 220px;
  max-height: 380px;
  overflow-y: auto;
  display: grid;
  gap: 9px;
}

.chat-msg {
  max-width: 92%;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 9px 11px;
  font-size: 0.86rem;
  line-height: 1.42;
  white-space: pre-wrap;
  box-shadow: 0 4px 10px rgba(15, 34, 71, 0.05);
}

.chat-msg p {
  margin: 0;
}

.chat-msg p + p {
  margin-top: 7px;
}

.chat-msg ul,
.chat-msg ol {
  margin: 6px 0 0;
  padding-left: 18px;
}

.chat-msg li + li {
  margin-top: 4px;
}

.chat-msg strong {
  color: #102c63;
}

.chat-msg code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  background: rgba(16, 44, 99, 0.08);
  border: 1px solid rgba(16, 44, 99, 0.12);
  border-radius: 6px;
  padding: 1px 5px;
  font-size: 0.82em;
}

.chat-msg.user {
  margin-left: auto;
  background: linear-gradient(180deg, #eef5ff 0%, #e7f0ff 100%);
  border-color: #bfd3fb;
}

.chat-msg.assistant {
  margin-right: auto;
  background: linear-gradient(180deg, #fffef8 0%, #fff9e6 100%);
  border-color: #f0dd95;
}

.chat-input-wrap {
  display: grid;
  gap: 7px;
}

.chat-input-wrap textarea {
  width: 100%;
  resize: none;
  min-height: 70px;
  max-height: 140px;
  border-radius: 12px;
  border: 1px solid #cdddf8;
  background: #ffffff;
  padding: 10px 12px;
}

.chat-fab {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 1300;
  border-radius: 999px;
  border: 1px solid #0d3f9d;
  background: linear-gradient(180deg, #1b57c8 0%, #0a3f9f 42%, #002b7f 100%);
  color: #fff;
  width: 56px;
  height: 56px;
  padding: 0;
  display: grid;
  place-items: center;
  box-shadow: 0 16px 34px rgba(0, 43, 127, 0.36);
  transition: transform 0.16s ease, box-shadow 0.22s ease;
}

.chat-fab svg {
  width: 25px;
  height: 25px;
  fill: currentColor;
}

.chat-fab:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 20px 40px rgba(0, 43, 127, 0.42);
}

.chat-widget {
  position: fixed;
  right: 16px;
  bottom: 82px;
  width: min(398px, calc(100vw - 24px));
  max-height: min(78vh, 640px);
  z-index: 1301;
  border: 1px solid #d4e2fb;
  border-radius: 18px;
  background: linear-gradient(180deg, #ffffff 0%, #fcfdff 100%);
  box-shadow: 0 22px 44px rgba(15, 34, 71, 0.24);
  padding: 12px 12px 10px;
  display: none;
  gap: 9px;
  transform-origin: bottom right;
  overflow: hidden;
}

.chat-widget.is-open {
  display: grid;
  animation: chatPopIn 180ms ease-out;
}

@keyframes chatPopIn {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.chat-widget-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid #e5edfb;
  padding-bottom: 8px;
}

.chat-title-wrap {
  display: flex;
  align-items: center;
  gap: 9px;
}

.chat-title-wrap h3 {
  margin: 0;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
}

.chat-title-wrap .small-note {
  margin-top: 1px;
  font-size: 0.74rem;
}

.chat-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.66rem;
  font-weight: 800;
  color: #0b3a95;
  border: 1px solid #bdd2f8;
  background: linear-gradient(180deg, #f4f8ff 0%, #eaf2ff 100%);
}

.chat-close {
  border-radius: 10px;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid #d8e4fb;
  background: #f6faff;
  color: #1a3f84;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1;
}

.chat-widget .chat-thread {
  min-height: 170px;
  max-height: 300px;
}

.chat-widget .chat-input-wrap textarea {
  min-height: 74px;
}

#dashboardChatSendBtn {
  width: 100%;
  border-radius: 12px;
  font-weight: 800;
}

.schedule-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(130px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.full-width {
  grid-column: 1 / -1;
}

hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 13px 0;
}

.card-table {
  padding-bottom: 6px;
}

.table-wrap {
  overflow-x: auto;
  border-radius: 12px;
  border: 1px solid var(--line);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  text-align: left;
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}

th {
  background: #f6f9ff;
  color: #37578f;
  font-size: 0.79rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 800;
}

tbody tr:nth-child(even) {
  background: #fcfdff;
}

.badge-open {
  display: inline-block;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 0.74rem;
  border: 1px solid #ffd86c;
  color: #8e6100;
  background: #fff8de;
}

@media (max-width: 1080px) {
  .controls-row {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
  }

  .charts-grid {
    grid-template-columns: 1fr;
  }

  .donut-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 920px) {
  .container {
    width: min(1320px, 96vw);
    margin-top: 12px;
  }

  .controls-row {
    grid-template-columns: 1fr;
  }

  .controls-row .btn-primary {
    width: 100%;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .card-chart {
    min-height: 300px;
  }

  .chart-wrap {
    height: 235px;
  }

  .chart-wrap-line {
    height: 250px;
  }

  .chart-wrap-donut {
    height: 225px;
  }
}

@media (max-width: 760px) {
  .container {
    width: min(1320px, 96vw);
    margin-top: 10px;
    gap: 10px;
  }

  .topbar {
    padding: 14px;
  }

  .brand {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .brand-logo {
    width: 74px;
  }

  .controls-row {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .controls-row .btn-primary {
    width: 100%;
  }

  .card {
    padding: 12px;
  }

  .kpi {
    padding: 11px;
  }

  .kpi .value {
    font-size: 1.55rem;
  }

  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .card-chart {
    min-height: 285px;
  }

  .chart-wrap {
    height: 210px;
  }

  .chart-wrap-line {
    height: 220px;
  }

  .chart-wrap-donut {
    height: 220px;
  }

  .donut-layout {
    min-height: auto;
  }

  .insights-grid {
    grid-template-columns: 1fr;
  }

  .tag-cloud,
  .wa-split-metrics {
    grid-template-columns: 1fr;
  }

  .wa-kpi-value {
    font-size: 1.7rem;
  }

  .search-row input {
    min-width: 0;
    width: 100%;
  }

  .search-row button,
  .actions button,
  #saveScheduleBtn,
  #dashboardChatSendBtn {
    width: 100%;
  }

  th,
  td {
    padding: 9px 8px;
    font-size: 0.84rem;
  }

  .schedule-grid {
    grid-template-columns: 1fr;
  }

  .chat-fab {
    right: 12px;
    bottom: 12px;
    width: 54px;
    height: 54px;
  }

  .chat-widget {
    right: 12px;
    bottom: 64px;
    width: calc(100vw - 24px);
    max-height: 72vh;
    padding: 10px;
  }

  .chat-widget .chat-thread {
    min-height: 150px;
    max-height: 240px;
  }
}
