:root {
  --bg: #160f24;
  --panel: rgba(31, 25, 54, 0.92);
  --panel-soft: rgba(55, 38, 84, 0.72);
  --line: rgba(164, 139, 224, 0.26);
  --text: #f8f5ff;
  --muted: #b9afd2;
  --coral: #ff745f;
  --blue: #18aef5;
  --green: #25dc41;
  --yellow: #ffc42d;
  --red: #f01414;
  --violet: #7b36d9;
  --shadow: 0 22px 80px rgba(0, 0, 0, 0.34);
  color-scheme: dark;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(circle at 10% 20%, rgba(255, 116, 95, 0.28), transparent 28rem),
    linear-gradient(135deg, #241235 0%, #101323 48%, #181d2b 100%);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.hero-panel {
  min-height: 126px;
  padding: 18px 32px;
  display: grid;
  grid-template-columns: auto minmax(360px, 1fr) minmax(330px, 520px) auto;
  align-items: center;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, rgba(52, 22, 66, 0.86), rgba(26, 21, 45, 0.96));
}

.brand-mark {
  width: 66px;
  height: 66px;
  display: grid;
  place-items: center;
  border: 2px solid rgba(255, 116, 95, 0.88);
  border-radius: 8px;
  color: #fff;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0;
  box-shadow: inset 0 0 28px rgba(255, 116, 95, 0.18);
}

.eyebrow,
.panel-heading p,
.upload-card span,
.filters span {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
  font-weight: 700;
}

h1 {
  margin: 5px 0 6px;
  color: var(--coral);
  font-size: clamp(28px, 3.2vw, 46px);
  line-height: 1;
  letter-spacing: 0;
}

.hero-copy {
  color: #ded8ea;
  font-size: 14px;
  line-height: 1.35;
  margin: 0;
}

.upload-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(145px, 1fr));
  gap: 12px;
}

.upload-card {
  position: relative;
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(123, 54, 217, 0.86), rgba(5, 77, 107, 0.72));
  cursor: pointer;
}

.upload-card input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-card strong {
  min-width: 0;
  overflow: hidden;
  color: white;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ghost-button {
  width: fit-content;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  padding: 11px 14px;
  background: rgba(255, 255, 255, 0.07);
  color: #fff;
  cursor: pointer;
}

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

.dashboard {
  min-width: 0;
  min-height: 0;
  height: 100%;
  padding: 14px 24px 18px;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}

.toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 12px;
}

.toolbar-right {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 14px;
}

.tabs {
  display: inline-grid;
  grid-auto-flow: column;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.18);
}

.tab {
  border: 0;
  border-radius: 6px;
  padding: 9px 15px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.tab.active {
  background: linear-gradient(135deg, var(--violet), #075e85);
  color: #fff;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.action-buttons,
.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filters label {
  display: grid;
  gap: 5px;
}

.filters select,
.filters input {
  min-width: 145px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 11px;
  background: rgba(28, 22, 45, 0.94);
  color: #fff;
}

.saving-filter input {
  min-width: 82px;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.kpi-card {
  min-height: 104px;
  display: grid;
  align-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.kpi-card h3 {
  margin: 0;
  color: #e7e1f4;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.kpi-value {
  font-size: clamp(24px, 2.5vw, 38px);
  font-weight: 900;
  line-height: 1;
}

.kpi-note {
  color: var(--muted);
  font-size: 13px;
}

.blue {
  color: var(--blue);
}

.green {
  color: var(--green);
}

.yellow {
  color: var(--yellow);
}

.red {
  color: var(--red);
}

.chart-area {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(320px, 0.65fr);
  grid-template-rows: minmax(330px, 1.45fr) minmax(210px, 0.9fr);
  gap: 12px;
  min-height: 0;
}

.panel {
  min-width: 0;
  min-height: 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.main-chart {
  grid-column: 1;
}

.side-panel {
  grid-column: 2;
  grid-row: 1 / span 2;
}

.trend-panel {
  grid-column: 1;
}

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

.panel-heading h2 {
  margin: 0 0 5px;
  font-size: 18px;
  letter-spacing: 0;
}

.bar-chart {
  height: calc(100% - 48px);
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(90px, 1fr);
  align-items: end;
  gap: clamp(18px, 4vw, 46px);
  padding: 10px 16px 6px;
  overflow-x: auto;
}

.bar-group {
  min-width: 90px;
  height: 100%;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 12px;
}

.bars {
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 0;
}

.bar {
  width: min(72px, 42%);
  min-height: 3px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
}

.bar.red-bar {
  background: linear-gradient(180deg, #ff2a1f, #c90000);
}

.bar.blue-bar {
  background: linear-gradient(180deg, #18c4ff, #5c47ca);
}

.bar-label {
  color: #efe9ff;
  font-weight: 800;
  text-align: center;
}

.trend-chart {
  height: calc(100% - 48px);
}

.main-chart,
.trend-panel {
  position: relative;
  overflow: hidden;
}

.main-chart::before,
.trend-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  border-left: 4px solid rgba(255, 116, 95, 0.9);
  pointer-events: none;
}

.main-chart .panel-heading h2,
.trend-panel .panel-heading h2 {
  font-size: 22px;
}

.trend-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.ranking-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.ranking-list li {
  display: grid;
  gap: 4px;
  padding-bottom: 9px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.rank-name {
  color: #fff;
  font-weight: 800;
  line-height: 1.25;
  font-size: 14px;
}

.rank-meta {
  color: var(--muted);
  font-size: 13px;
}

.table-heading {
  align-items: center;
}

.compact {
  padding: 8px 11px;
}

.primary-action {
  border-color: rgba(255, 196, 45, 0.62);
  background: rgba(255, 196, 45, 0.16);
  color: #ffe8a5;
}

.guide-button {
  border-color: rgba(24, 174, 245, 0.56);
  background: rgba(24, 174, 245, 0.12);
  color: #d9f3ff;
}

.table-wrap {
  height: calc(100% - 58px);
  max-height: none;
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
}

.detail-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  padding: 28px;
}

.detail-modal.open,
.guide-modal.open {
  display: grid;
  place-items: center;
}

.guide-modal {
  position: fixed;
  inset: 0;
  z-index: 22;
  display: none;
  padding: 28px;
}

.detail-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(7, 5, 14, 0.72);
  backdrop-filter: blur(6px);
}

.detail-dialog {
  position: relative;
  z-index: 1;
  width: min(1420px, 94vw);
  height: min(720px, 86vh);
}

.guide-dialog {
  position: relative;
  z-index: 1;
  width: min(1280px, 94vw);
  height: min(820px, 88vh);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.guide-content {
  min-height: 0;
  overflow: auto;
  display: grid;
  gap: 14px;
  padding-right: 4px;
}

.guide-step {
  display: grid;
  grid-template-columns: 42px minmax(220px, 0.9fr) minmax(280px, 1.4fr);
  gap: 14px;
  align-items: start;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
}

.guide-step span {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--violet), #075e85);
  color: white;
  font-weight: 900;
}

.guide-step h3 {
  margin: 1px 0 6px;
  color: #fff;
  font-size: 17px;
}

.guide-step p {
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

.guide-step img {
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  border-radius: 8px;
  background: #f4f4f4;
}

.guide-step img + img {
  margin-top: 10px;
}

.final-step {
  grid-template-columns: 42px 1fr;
}

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

th,
td {
  padding: 9px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  text-align: left;
  font-size: 13px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #251a3c;
  color: #fff;
}

td {
  color: #ded8ea;
}

.empty-state {
  display: grid;
  place-items: center;
  height: 100%;
  min-height: 170px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1120px) {
  body {
    overflow: auto;
  }

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

  .hero-panel {
    grid-template-columns: auto 1fr;
    min-height: auto;
    padding: 34px 24px;
  }

  .upload-grid,
  .hero-panel .ghost-button {
    grid-column: 1 / -1;
  }

  .dashboard {
    height: auto;
    padding: 24px;
    overflow: visible;
  }

  .chart-area {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }

  .main-chart,
  .side-panel,
  .trend-panel {
    grid-column: 1;
    grid-row: auto;
  }

  .main-chart {
    min-height: 380px;
  }

  .trend-panel {
    min-height: 235px;
  }
}

@media (max-width: 760px) {
  .hero-panel {
    grid-template-columns: 1fr;
  }

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

  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-right {
    align-items: stretch;
    flex-direction: column;
  }

  .tabs,
  .filters,
  .action-buttons,
  .filters label {
    width: 100%;
  }

  .action-buttons {
    justify-content: stretch;
  }

  .action-buttons .ghost-button {
    width: 100%;
  }

  .filters select,
  .filters input {
    width: 100%;
  }

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

  .panel {
    padding: 14px;
  }

  .guide-step,
  .final-step {
    grid-template-columns: 42px 1fr;
  }

  .guide-step img {
    grid-column: 1 / -1;
  }
}

@media print {
  @page {
    size: landscape;
    margin: 8mm;
  }

  body {
    height: auto;
    overflow: visible;
    background: #160f24;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  .app-shell {
    height: auto;
  }

  .hero-panel,
  .dashboard {
    padding: 10px;
  }

  .upload-grid,
  .ghost-button,
  .detail-modal,
  .guide-modal {
    display: none !important;
  }

  .chart-area {
    grid-template-rows: 310px 190px;
  }

  .panel,
  .kpi-card {
    box-shadow: none;
  }
}
