:root {
  color-scheme: light;
  --ink: #172027;
  --muted: #66727c;
  --line: #d9e1e7;
  --panel: #ffffff;
  --page: #f4f7f9;
  --blue: #2457a6;
  --green: #23815f;
  --gold: #b47a1f;
  --red: #b64a3b;
  --shadow: 0 8px 22px rgba(30, 45, 60, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 26px 32px 18px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.15;
}

h2 {
  font-size: 17px;
  line-height: 1.2;
}

.periodBadge {
  min-width: 176px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  background: #f8fafb;
}

main {
  padding: 18px 32px 36px;
}

.controls {
  display: grid;
  grid-template-columns: 1.1fr 1.2fr 1.8fr 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

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

select {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: #ffffff;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
}

button,
input {
  font: inherit;
}

.kpiGrid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

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

.kpiGrid article {
  min-height: 104px;
  padding: 15px;
  display: grid;
  align-content: space-between;
}

.kpiGrid span,
.kpiGrid small,
.panelHead p {
  color: var(--muted);
  font-size: 12px;
}

.kpiGrid strong {
  display: block;
  margin-top: 7px;
  font-size: 27px;
  line-height: 1.05;
}

.dashboardGrid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
}

.panel {
  min-width: 0;
  padding: 16px;
}

.panel.wide {
  grid-column: span 2;
}

.panelHead {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.chart {
  min-height: 286px;
}

.trendChart svg {
  display: block;
  width: 100%;
  height: 286px;
}

.axisText {
  fill: var(--muted);
  font-size: 11px;
}

.barList {
  display: grid;
  gap: 9px;
}

.barItem {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.barLabel {
  min-width: 0;
  color: var(--ink);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.barValue {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.barTrack {
  grid-column: 1 / -1;
  height: 8px;
  background: #edf2f5;
  border-radius: 999px;
  overflow: hidden;
}

.barFill {
  height: 100%;
  background: var(--blue);
}

.barFill.green {
  background: var(--green);
}

.barFill.gold {
  background: var(--gold);
}

.tableWrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

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

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

th:first-child,
td:first-child {
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 12px;
  background: #f8fafb;
}

tr:last-child td {
  border-bottom: 0;
}

.positive {
  color: var(--green);
}

.negative {
  color: var(--red);
}

.empty {
  padding: 22px;
  color: var(--muted);
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 6px;
}

.assistantPanel {
  display: grid;
  gap: 10px;
}

.chatMessages {
  display: grid;
  align-content: start;
  gap: 8px;
  min-height: 132px;
  max-height: 220px;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafb;
}

.chatMessage {
  max-width: 86%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  font-size: 13px;
  line-height: 1.4;
  white-space: pre-line;
}

.chatMessage.user {
  justify-self: end;
  border-color: #bdd0df;
  background: #eef5fb;
}

.chatMessage.assistant {
  justify-self: start;
}

.chatMessage.refusal {
  border-color: #e1c2bb;
  background: #fff7f5;
}

.chatForm {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 84px;
  gap: 8px;
}

.chatForm input {
  min-width: 0;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 11px;
  background: #ffffff;
  color: var(--ink);
  font-size: 14px;
}

.chatForm button {
  height: 40px;
  border: 0;
  border-radius: 6px;
  background: var(--blue);
  color: #ffffff;
  font-weight: 700;
  cursor: pointer;
}

.chatForm button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

@media (max-width: 980px) {
  .topbar {
    align-items: start;
    flex-direction: column;
  }

  main {
    padding: 16px;
  }

  .controls,
  .kpiGrid,
  .dashboardGrid {
    grid-template-columns: 1fr;
  }

  .panel.wide {
    grid-column: auto;
  }

  .chatMessage {
    max-width: 100%;
  }
}
