:root {
  --navy: #263047;
  --navy-2: #1f293d;
  --line: #d9e0ea;
  --surface: #ffffff;
  --page: #f3f6fa;
  --text: #172033;
  --muted: #667085;
  --blue: #3860a8;
  --amber: #b07a00;
  --green: #438834;
  --sky: #3a7ec1;
  --violet: #6e5ad2;
  --red: #c0544e;
  --slate: #58668c;
  --teal: #358480;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Malgun Gothic", Arial, sans-serif;
  color: var(--text);
  background: var(--page);
}

button, input, select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 232px 1fr;
}

.sidebar {
  background: var(--navy-2);
  color: #fff;
  padding: 20px 14px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 6px 8px 22px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: #4b8ad8;
  font-weight: 800;
}

.brand span {
  display: block;
  margin-top: 2px;
  color: #aeb8cc;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 4px;
}

.nav-item {
  border: 0;
  width: 100%;
  text-align: left;
  color: #d7deeb;
  background: transparent;
  padding: 11px 12px;
  border-radius: 6px;
  cursor: pointer;
}

.nav-item.active,
.nav-item:hover {
  color: #fff;
  background: rgba(255,255,255,0.12);
}

.main {
  min-width: 0;
  padding: 18px;
}

.topbar {
  min-height: 66px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--navy);
  color: #fff;
  border-radius: 8px 8px 0 0;
  padding: 12px 18px;
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0;
}

.topbar p {
  margin: 4px 0 0;
  color: #c6cfdf;
  font-size: 13px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #4ade80;
}

.primary-button,
.chat-input button {
  border: 0;
  color: #fff;
  background: #2f6fcb;
  border-radius: 6px;
  padding: 9px 14px;
  cursor: pointer;
}

.filterbar {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
  background: #fff;
  border: 1px solid var(--line);
  border-top: 0;
  padding: 12px 14px;
}

.filterbar label {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.filterbar input,
.filterbar select {
  height: 34px;
  border: 1px solid #cfd7e4;
  border-radius: 6px;
  padding: 0 10px;
  color: var(--text);
  background: #fff;
}

.segmented {
  display: inline-flex;
  border: 1px solid #cfd7e4;
  border-radius: 6px;
  overflow: hidden;
}

.segmented button {
  height: 34px;
  min-width: 54px;
  border: 0;
  border-right: 1px solid #cfd7e4;
  background: #fff;
  color: #475467;
  cursor: pointer;
}

.segmented button:last-child {
  border-right: 0;
}

.segmented .selected {
  color: #fff;
  background: #315a9f;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 14px;
  margin-top: 14px;
}

.dashboard {
  min-width: 0;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(156px, 1fr));
  gap: 12px;
}

.kpi-card {
  color: #fff;
  border-radius: 8px;
  padding: 14px;
  min-height: 124px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.12);
}

.kpi-card.selected {
  outline: 3px solid #4ade80;
  outline-offset: -3px;
}

.kpi-card h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.kpi-value {
  font-size: 30px;
  line-height: 1;
  font-weight: 800;
}

.kpi-meta {
  margin-top: 11px;
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: rgba(255,255,255,0.88);
}

.chart-band,
.data-band,
.ai-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 14px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.section-header h2,
.ai-header h2,
.ai-panel h3 {
  margin: 0;
  letter-spacing: 0;
}

.section-header h2 {
  font-size: 17px;
}

.section-header p,
.ai-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.chart-wrap {
  padding: 14px 16px 18px;
}

canvas {
  width: 100%;
  height: 270px;
  display: block;
}

.tabs {
  display: flex;
  gap: 2px;
  padding: 10px 10px 0;
  border-bottom: 1px solid var(--line);
}

.tab {
  border: 0;
  background: transparent;
  color: #475467;
  padding: 10px 12px;
  border-radius: 6px 6px 0 0;
  cursor: pointer;
}

.tab.active {
  color: #173b78;
  background: #e9f1ff;
  font-weight: 700;
}

.table-wrap {
  max-height: 310px;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  border-bottom: 1px solid #e6ebf2;
  padding: 9px 10px;
  text-align: right;
  white-space: nowrap;
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: #24436f;
  background: #eef4fb;
}

.ai-panel {
  margin-top: 0;
  padding: 16px;
  align-self: start;
  position: sticky;
  top: 14px;
}

.ai-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 18px;
}

.ai-badge {
  color: #176b56;
  background: #dff8ef;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 700;
}

.ai-panel section {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 14px;
}

.ai-panel h3 {
  font-size: 14px;
  margin-bottom: 10px;
}

.insight-list {
  padding-left: 18px;
  margin: 0;
  color: #344054;
  line-height: 1.55;
  font-size: 13px;
}

.insight-cards {
  display: grid;
  gap: 8px;
}

.insight-card {
  border: 1px solid #dce4ee;
  border-radius: 8px;
  padding: 10px;
  background: #f8fafc;
}

.insight-card strong {
  display: block;
  margin-bottom: 3px;
}

.insight-card span {
  color: var(--muted);
  font-size: 12px;
}

.prompt-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.prompt-chips button {
  border: 1px solid #ccd6e4;
  background: #fff;
  border-radius: 999px;
  padding: 7px 10px;
  color: #344054;
  cursor: pointer;
}

.ai-answer {
  min-height: 88px;
  border: 1px solid #dce4ee;
  border-radius: 8px;
  background: #f8fafc;
  padding: 11px;
  color: #344054;
  font-size: 13px;
  line-height: 1.55;
}

.chat-input {
  display: grid;
  grid-template-columns: 1fr 58px;
  gap: 8px;
  margin-top: 10px;
}

.chat-input input {
  min-width: 0;
  border: 1px solid #cfd7e4;
  border-radius: 6px;
  padding: 0 10px;
}

@media (max-width: 1280px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .content-grid { grid-template-columns: 1fr; }
  .ai-panel { position: static; }
}

@media (max-width: 760px) {
  .main { padding: 10px; }
  .topbar { align-items: flex-start; gap: 12px; flex-direction: column; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tabs { overflow-x: auto; }
}
