:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-weak: #f9fafb;
  --line: #d9e0e8;
  --line-strong: #b8c4d1;
  --text: #17202a;
  --muted: #687587;
  --accent: #166b75;
  --accent-strong: #0d4e59;
  --accent-soft: #e2f3f4;
  --blue: #3568a8;
  --green: #27845f;
  --amber: #a66a12;
  --danger: #b42318;
  --shadow: 0 18px 48px rgba(30, 44, 62, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
}

.heading-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 20px;
  color: var(--accent-strong);
  font-size: 14px;
  font-weight: 700;
}

.brand-mark {
  flex: 0 0 12px;
  height: 24px;
  border-radius: 999px;
  background: #8ad3d6;
  box-shadow: 10px 0 0 #f4bc62;
}

.workspace {
  min-width: 0;
  padding: 28px;
}

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

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 7px;
  font-size: 28px;
  line-height: 1.18;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 5px;
  font-size: 17px;
  line-height: 1.3;
  letter-spacing: 0;
}

.source-summary,
.panel-header p,
.auth-panel p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.topbar-actions,
.table-actions,
.token-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.button {
  min-height: 38px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
}

.button.primary {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.button.primary:hover {
  background: var(--accent-strong);
}

.button.secondary:hover {
  border-color: var(--line-strong);
  background: var(--surface-weak);
}

.button:disabled,
input:disabled,
select:disabled {
  color: #98a3af;
  background: #eef2f5;
  cursor: not-allowed;
}

.auth-panel,
.control-panel,
.panel,
.metric-card,
.status-region:not(:empty) {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-panel {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding: 18px;
  margin-bottom: 16px;
}

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

.token-form input {
  width: min(320px, 64vw);
}

.control-panel {
  padding: 16px;
  margin-bottom: 16px;
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 12px;
}

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

input,
select {
  min-width: 0;
  width: 100%;
  min-height: 38px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  background: #fff;
}

input:focus-visible,
select:focus-visible,
.button:focus-visible,
.icon-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.toggle-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  background: var(--surface-weak);
  font-size: 13px;
  font-weight: 600;
}

.toggle input {
  width: auto;
  min-height: auto;
}

.status-region {
  margin-bottom: 16px;
  color: var(--muted);
}

.status-region:not(:empty) {
  padding: 12px 14px;
}

.status-region.error {
  color: var(--danger);
  border-color: #f3b1a9;
  background: #fff5f4;
}

.status-region.warning {
  color: #7c4a04;
  border-color: #f3d298;
  background: #fff8e8;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric-card {
  min-height: 104px;
  padding: 16px;
}

.metric-card span {
  display: block;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric-card strong {
  font-size: 26px;
  line-height: 1.1;
  letter-spacing: 0;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(300px, 0.6fr);
  gap: 16px;
  margin-bottom: 16px;
}

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

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.chart-frame {
  min-height: 280px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfcfd 100%);
  overflow: hidden;
}

.chart-frame.compact {
  min-height: 280px;
}

.chart-frame svg {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 280px;
}

.axis,
.chart-label {
  fill: #687587;
  font-size: 12px;
}

.chart-value {
  fill: #17202a;
  font-size: 12px;
  font-weight: 700;
}

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

.table-panel {
  margin-bottom: 16px;
}

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

table {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
  background: #fff;
}

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

th {
  color: var(--muted);
  background: var(--surface-weak);
  font-weight: 800;
}

td.numeric,
th.numeric {
  text-align: right;
}

tbody tr {
  cursor: default;
}

tbody tr.selectable {
  cursor: pointer;
}

tbody tr.selectable:hover,
tbody tr.selected {
  background: var(--accent-soft);
}

.link {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}

.link:hover {
  text-decoration: underline;
}

.source-dialog {
  width: min(780px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  color: var(--text);
  box-shadow: 0 28px 90px rgba(16, 31, 45, 0.24);
}

.source-dialog::backdrop {
  background: rgba(16, 31, 45, 0.42);
}

.source-dialog form {
  margin: 0;
}

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

.dialog-header h2 {
  margin: 0;
}

.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.dialog-content {
  max-height: min(70vh, 680px);
  padding: 18px 20px 22px;
  overflow: auto;
}

.definition-list {
  display: grid;
  gap: 10px;
  margin: 14px 0 0;
}

.definition-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-weak);
}

.definition-item strong {
  display: block;
  margin-bottom: 4px;
}

.definition-item span {
  color: var(--muted);
  font-size: 13px;
}

.hidden {
  display: none !important;
}

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

  .metric-grid {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
  }

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

@media (max-width: 760px) {
  .workspace {
    padding: 18px 14px;
  }

  .topbar,
  .auth-panel,
  .panel-header {
    display: grid;
  }

  .control-grid,
  .metric-grid {
    grid-template-columns: 1fr;
  }

  .topbar-actions,
  .table-actions,
  .token-form {
    align-items: stretch;
  }

  .button {
    width: 100%;
  }
}
