:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-alt: #eef2f7;
  --text: #172033;
  --muted: #637086;
  --line: #d8dde7;
  --primary: #6d3fd1;
  --primary-dark: #5430a9;
  --green: #198754;
  --yellow: #b7791f;
  --red: #c73535;
  --gray: #758195;
  --blue: #2764a8;
  --shadow: 0 12px 30px rgba(30, 39, 66, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #111827;
  color: #f8fafc;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

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

.brand-mark {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  background: var(--primary);
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: #b9c2d3;
  font-size: 13px;
}

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

.nav button {
  color: #dce3ef;
  background: transparent;
  padding: 11px 12px;
  border-radius: 7px;
  text-align: left;
  min-height: 42px;
}

.nav button:hover,
.nav button.active {
  background: #263246;
  color: #ffffff;
}

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

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}

h1 {
  font-size: 26px;
  line-height: 1.2;
  margin: 0 0 4px;
}

p {
  margin: 0;
}

#view-subtitle,
.muted {
  color: var(--muted);
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.primary,
.ghost,
.filters button,
.table-actions button,
.pager button,
.settings-actions button {
  min-height: 38px;
  border-radius: 7px;
  padding: 0 13px;
  white-space: nowrap;
}

.primary {
  background: var(--primary);
  color: #ffffff;
}

.primary:hover {
  background: var(--primary-dark);
}

.primary.soft {
  background: #2764a8;
}

.ghost {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
}

.filters {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 10px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

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

input,
select,
textarea {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  color: var(--text);
  background: #ffffff;
}

textarea {
  min-height: 94px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

.filters button {
  align-self: end;
  background: #172033;
  color: #ffffff;
}

.status-line {
  min-height: 26px;
  padding: 8px 2px;
  color: var(--muted);
  font-size: 13px;
}

.view-root {
  display: grid;
  gap: 16px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(130px, 1fr));
  gap: 10px;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  min-height: 86px;
}

.kpi span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.kpi strong {
  display: block;
  font-size: 19px;
  line-height: 1.2;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

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

.panel-header h2 {
  margin: 0;
  font-size: 16px;
}

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

.chart-wrap {
  padding: 12px;
  height: 280px;
}

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

.table-wrap {
  overflow: auto;
}

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

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

th {
  color: var(--muted);
  background: #f9fafc;
  font-weight: 700;
  position: sticky;
  top: 0;
  z-index: 1;
}

tr:hover td {
  background: #fbfcff;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 700;
}

.tag.POSITIVE {
  color: #0f5132;
  background: #d8f3e6;
}

.tag.ATTENTION {
  color: #7c4b00;
  background: #fff1cc;
}

.tag.LOSS {
  color: #842029;
  background: #f8d7da;
}

.tag.NO_DATA {
  color: #475569;
  background: #e9edf3;
}

.empty {
  display: grid;
  place-items: center;
  min-height: 180px;
  color: var(--muted);
  text-align: center;
  padding: 28px;
}

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

.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}

.settings-section {
  padding: 14px;
}

.settings-section h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

.settings-actions,
.table-actions,
.pager {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.pager {
  justify-content: flex-end;
  padding: 12px 14px;
}

.pager button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

.detail-grid {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 16px;
}

.summary-list {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.summary-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.summary-list span {
  color: var(--muted);
}

@media (max-width: 1180px) {
  .kpi-grid {
    grid-template-columns: repeat(3, minmax(130px, 1fr));
  }

  .filters {
    grid-template-columns: repeat(3, minmax(130px, 1fr));
  }
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

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

  .topbar,
  .chart-grid,
  .two-col,
  .settings-grid,
  .detail-grid {
    grid-template-columns: 1fr;
    display: grid;
  }

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