:root {
  --bg-0: #070b12;
  --bg-1: #0d1421;
  --bg-2: #101a2b;
  --line: #1b2a40;
  --line-soft: #223552;
  --text: #d6e0f1;
  --muted: #8fa5c8;
  --accent: #4da3ff;
  --accent-2: #1c79e6;
  --success: #1cc37c;
  --danger: #f15b66;
  --glow: rgba(77, 163, 255, 0.25);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(circle at 20% -10%, #183768 0%, var(--bg-0) 35%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0));
  color: var(--text);
  font-family: "Manrope", sans-serif;
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(rgba(128, 158, 205, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(128, 158, 205, 0.07) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(circle at 50% 20%, black 20%, transparent 70%);
  z-index: 0;
}

.app-header,
.app-main {
  position: relative;
  z-index: 1;
  width: min(1600px, 96vw);
  margin: 0 auto;
}

.app-header {
  padding: 24px 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.title-wrap {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

h1 {
  margin: 0;
  font-size: clamp(1.25rem, 1.6vw, 1.75rem);
  font-weight: 800;
  letter-spacing: 0.02em;
}

.badge {
  display: inline-block;
  font-size: 0.75rem;
  padding: 6px 10px;
  border-radius: 999px;
  color: #a6ceff;
  border: 1px solid #2b4f78;
  background: rgba(13, 56, 106, 0.38);
}

.controls-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stat {
  border: 1px solid var(--line);
  background: rgba(12, 24, 40, 0.7);
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.82rem;
}

.search-wrap input {
  width: min(340px, 68vw);
  background: #07101c;
  border: 1px solid var(--line-soft);
  color: var(--text);
  border-radius: 9px;
  padding: 11px 14px;
  outline: none;
}

.search-wrap input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--glow);
}

.app-main {
  padding-bottom: 30px;
}

.sheet-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  scrollbar-width: thin;
  margin-bottom: 16px;
}

.tab-btn {
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  padding: 12px 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 180ms ease;
}

.tab-btn:hover {
  color: #b8d0f5;
}

.tab-btn.active {
  color: #d7e7ff;
  border-bottom-color: var(--accent);
}

.dataset-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

h2 {
  margin: 0;
  font-size: clamp(1rem, 1.5vw, 1.35rem);
}

#sheetSubtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.toolbar {
  display: flex;
  gap: 8px;
}

.btn {
  border: 1px solid #2f5f93;
  background: linear-gradient(180deg, #144173, #0e2f53);
  color: #d5e7ff;
  border-radius: 8px;
  font-weight: 600;
  padding: 9px 12px;
  cursor: pointer;
}

.btn:hover {
  filter: brightness(1.05);
}

.btn.btn-subtle {
  border-color: var(--line-soft);
  background: #0d1929;
  color: var(--muted);
}

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

.kpi-card {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(22, 37, 58, 0.9), rgba(12, 22, 36, 0.9));
  border-radius: 12px;
  padding: 12px 14px;
}

.kpi-label {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.kpi-value {
  margin-top: 8px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 1.2rem;
  font-weight: 600;
}

.table-shell {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(6, 13, 22, 0.78);
  overflow: hidden;
}

.status {
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 0.86rem;
}

.table-scroll {
  overflow: auto;
  max-height: 70vh;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}

thead th {
  position: sticky;
  top: 0;
  background: #14253a;
  color: #a8c1e6;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-align: left;
  border-bottom: 1px solid var(--line-soft);
  padding: 10px 12px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

thead th.sort-asc::after,
thead th.sort-desc::after {
  content: "";
  margin-left: 7px;
  border: 5px solid transparent;
  display: inline-block;
}

thead th.sort-asc::after {
  border-bottom-color: var(--accent);
  transform: translateY(-2px);
}

thead th.sort-desc::after {
  border-top-color: var(--accent);
  transform: translateY(2px);
}

tbody td {
  border-bottom: 1px solid rgba(43, 67, 99, 0.4);
  color: #d8e4f7;
  font-size: 0.9rem;
  padding: 9px 12px;
  white-space: nowrap;
}

tbody tr:hover td {
  background: rgba(18, 34, 54, 0.65);
}

.value-pos {
  color: var(--success);
  font-weight: 600;
}

.value-neg {
  color: var(--danger);
  font-weight: 600;
}

.pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
  flex-wrap: wrap;
}

.pager-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pager-btn {
  border: 1px solid var(--line-soft);
  background: #0f1b2c;
  color: #c5d9f5;
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
}

.pager-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@media (max-width: 920px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .table-scroll {
    max-height: 62vh;
  }
}
