:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #667085;
  --line: #d9e0ea;
  --accent: #0f766e;
  --accent-dark: #0b5f59;
  --soft: #eef7f6;
  --warn: #9a3412;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Malgun Gothic", Arial, sans-serif;
  font-size: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 28px;
  background: #162033;
  color: #fff;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  font-weight: 700;
}

h2 {
  font-size: 16px;
  font-weight: 700;
}

.topbar p {
  margin-top: 6px;
  color: #cbd5e1;
}

main {
  padding: 20px 28px 28px;
}

.upload-panel,
.workspace > *,
.stats > div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.upload-panel {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(360px, 1.1fr) auto;
  gap: 14px;
  align-items: end;
  padding: 16px;
}

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

.field label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-weight: 600;
}

input[type="file"],
input[type="search"] {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
}

button {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  padding: 0 16px;
  cursor: pointer;
}

button:hover {
  background: var(--accent-dark);
}

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

button.ghost {
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: transparent;
}

button.ghost:hover {
  background: rgba(255, 255, 255, 0.08);
}

.status {
  grid-column: 1 / -1;
  color: var(--muted);
}

.status.error {
  color: var(--warn);
  font-weight: 700;
}

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

.stats > div {
  padding: 14px 16px;
}

.stats strong {
  display: block;
  font-size: 22px;
}

.stats span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.workspace {
  display: grid;
  grid-template-columns: 430px minmax(0, 1fr);
  gap: 14px;
  min-height: calc(100vh - 250px);
}

.summary-pane,
.detail-pane {
  overflow: hidden;
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.pane-head p {
  margin-top: 4px;
  color: var(--muted);
}

.summary-list {
  height: calc(100vh - 330px);
  overflow: auto;
}

.summary-list.empty {
  padding: 22px;
  color: var(--muted);
}

.summary-item {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 12px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.summary-item:hover,
.summary-item.active {
  background: var(--soft);
}

.summary-item strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-item small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.badge {
  align-self: start;
  border-radius: 999px;
  background: #e2e8f0;
  color: #334155;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 8px;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 14px;
  padding-bottom: 8px;
}

.kpi {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.kpi span {
  display: block;
  color: var(--muted);
  margin-bottom: 5px;
}

.kpi strong {
  font-size: 18px;
}

.visual-summary {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  padding: 0 14px 14px;
}

.visual-summary.is-empty {
  display: none;
}

.chart-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.panel-title h3 {
  margin: 0;
  font-size: 14px;
}

.panel-title span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.donut-row {
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 160px;
}

.donut {
  width: 104px;
  height: 104px;
  border-radius: 50%;
  background: conic-gradient(#0f766e 0 100%);
  position: relative;
}

.donut::after {
  content: "";
  position: absolute;
  inset: 23px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--line);
}

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

.legend-item {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  gap: 7px;
  align-items: center;
  color: #475467;
  font-size: 12px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.legend-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-chart {
  display: grid;
  gap: 8px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(110px, 0.9fr) minmax(130px, 1.2fr) 86px;
  gap: 8px;
  align-items: center;
  min-height: 24px;
  font-size: 12px;
}

.bar-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #344054;
}

.bar-track {
  height: 11px;
  overflow: hidden;
  border-radius: 999px;
  background: #e9eef5;
}

.bar-fill {
  height: 100%;
  min-width: 2px;
  border-radius: inherit;
  background: linear-gradient(90deg, #0f766e, #38bdf8);
}

.bar-value {
  text-align: right;
  color: #475467;
  font-variant-numeric: tabular-nums;
}

.table-wrap {
  height: calc(100vh - 610px);
  min-height: 260px;
  overflow: auto;
  border-top: 1px solid var(--line);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
  color: #475467;
  text-align: left;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.empty-cell {
  height: 80px;
  color: var(--muted);
  text-align: center;
  vertical-align: middle;
}

@media (max-width: 980px) {
  .topbar,
  .upload-panel,
  .workspace,
  .stats {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .split,
  .kpis,
  .visual-summary {
    grid-template-columns: 1fr;
  }

  .summary-list,
  .table-wrap {
    height: auto;
    max-height: 520px;
  }
}
