:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-strong: #eef3f6;
  --ink: #151923;
  --muted: #5f6b78;
  --line: #d8e1ea;
  --accent: #007f73;
  --accent-soft: #dff4ef;
  --coral: #d86f45;
  --shadow: 0 18px 50px rgba(17, 24, 39, 0.1);
  --radius: 8px;
  --max-width: 1220px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111419;
  --surface: #1a1f27;
  --surface-strong: #232a35;
  --ink: #f5f7fb;
  --muted: #b5bfcb;
  --line: #323b48;
  --accent: #45c7b5;
  --accent-soft: #143a36;
  --coral: #ff9b70;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(90deg, rgba(0, 127, 115, 0.07), transparent 34%),
    linear-gradient(180deg, rgba(216, 111, 69, 0.07), transparent 36%),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.55;
}

a {
  color: inherit;
}

button,
input,
select {
  font: inherit;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem max(1rem, calc((100vw - var(--max-width)) / 2));
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface), transparent 8%);
  backdrop-filter: blur(16px);
}

.brand,
.app-header nav {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.brand,
.app-header a {
  text-decoration: none;
}

.brand span {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--surface);
  font-weight: 900;
}

.app-header nav a,
.theme-toggle,
.toolbar button,
.pagination button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
  min-height: 38px;
  padding: 0.55rem 0.75rem;
  text-decoration: none;
}

.app-shell {
  width: min(var(--max-width), calc(100% - 2rem));
  margin: 0 auto;
  padding: 4rem 0 5rem;
}

.intro {
  max-width: 820px;
  margin-bottom: 1.5rem;
}

.eyebrow {
  margin: 0 0 0.7rem;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 1rem;
  font-size: clamp(2.2rem, 5vw, 4rem);
  line-height: 1;
}

h2 {
  margin-bottom: 0.5rem;
  font-size: 1.35rem;
}

h3 {
  margin-bottom: 0.35rem;
}

.intro p,
.upload-panel p,
.panel-heading p,
.section-detail p,
.chart-panel p,
.table-meta,
.pagination {
  color: var(--muted);
}

.upload-panel,
.status-panel,
.viewer-layout,
.summary-grid article,
.chart-panel,
.table-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface), transparent 2%);
  box-shadow: var(--shadow);
}

.upload-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 420px);
  gap: 1rem;
  align-items: center;
  padding: 1rem;
}

.drop-zone {
  display: grid;
  place-items: center;
  min-height: 150px;
  border: 1px dashed color-mix(in srgb, var(--accent), var(--line) 45%);
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent);
  cursor: pointer;
  text-align: center;
}

.drop-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.drop-zone span {
  border-radius: var(--radius);
  background: var(--accent);
  color: #ffffff;
  font-weight: 900;
  padding: 0.7rem 1rem;
}

.drop-zone strong {
  display: block;
  margin-top: 0.65rem;
}

.drop-zone.is-dragging {
  outline: 3px solid color-mix(in srgb, var(--accent), transparent 45%);
}

.status-panel {
  margin-top: 1rem;
  padding: 1rem;
}

.status-panel.is-error {
  border-color: #d86f45;
  color: #d86f45;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.8rem;
  margin-top: 1rem;
}

.summary-grid article {
  padding: 1rem;
  box-shadow: none;
}

.summary-grid span {
  display: block;
  color: var(--coral);
  font-size: 1.7rem;
  font-weight: 900;
  line-height: 1;
}

.summary-grid p {
  margin: 0.4rem 0 0;
}

.viewer-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 1rem;
  margin-top: 1rem;
  padding: 1rem;
}

.section-nav {
  border-right: 1px solid var(--line);
  padding-right: 1rem;
}

.section-list {
  display: grid;
  gap: 0.45rem;
  max-height: 68vh;
  overflow: auto;
  padding-right: 0.3rem;
}

.section-button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  gap: 0.15rem;
  padding: 0.65rem;
  text-align: left;
}

.section-button span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.section-button.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.data-workspace {
  min-width: 0;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(180px, 260px) minmax(240px, 1fr) auto;
  gap: 0.8rem;
  align-items: end;
  margin-bottom: 1rem;
}

.toolbar label {
  display: grid;
  gap: 0.35rem;
}

.toolbar label span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.toolbar input,
.toolbar select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  min-height: 42px;
  padding: 0.6rem 0.75rem;
}

.section-detail {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.section-detail p:last-child {
  max-width: 46ch;
}

.key-values {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
  margin-bottom: 1rem;
}

.key-value {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  padding: 0.65rem;
}

.key-value span {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
}

.key-value strong {
  display: block;
  overflow-wrap: anywhere;
}

.chart-panel {
  margin-bottom: 1rem;
  padding: 1rem;
}

.chart-panel canvas {
  width: 100%;
  height: 260px;
  margin-top: 0.7rem;
}

.table-panel {
  overflow: hidden;
}

.table-meta,
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
}

.table-wrap {
  max-height: 66vh;
  overflow: auto;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 0.52rem 0.65rem;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--ink);
  color: var(--surface);
  font-size: 0.78rem;
}

td {
  color: var(--muted);
}

tbody tr:nth-child(even) td {
  background: color-mix(in srgb, var(--surface-strong), transparent 45%);
}

.is-hidden {
  display: none !important;
}

@media (max-width: 980px) {
  .upload-panel,
  .viewer-layout,
  .toolbar,
  .section-detail {
    grid-template-columns: 1fr;
  }

  .viewer-layout {
    display: block;
  }

  .section-nav {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    margin-bottom: 1rem;
    padding: 0 0 1rem;
  }

  .section-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-height: 280px;
  }

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

@media (max-width: 640px) {
  .app-header,
  .app-header nav {
    align-items: stretch;
    flex-direction: column;
  }

  .app-shell {
    padding-top: 2.5rem;
  }

  .summary-grid,
  .key-values,
  .section-list {
    grid-template-columns: 1fr;
  }

  th,
  td {
    white-space: normal;
  }
}
