:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --bg-accent: #e8eef9;
  --panel: rgba(255, 255, 255, 0.9);
  --panel-strong: #ffffff;
  --line: rgba(148, 163, 184, 0.2);
  --text: #1f2937;
  --muted: #4b5563;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --good: #166534;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

* {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Noto Sans SC", sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #f8fbff 0%, var(--bg) 100%);
}

button,
input,
select {
  font: inherit;
}

.page {
  width: min(1280px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 48px;
}

.tool-nav-panel {
  margin-bottom: 20px;
  padding: 12px 16px;
}

.tool-nav {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.tool-nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 999px;
  background: #eff6ff;
  color: var(--brand-dark);
  font-weight: 700;
  text-decoration: none;
}

.tool-nav-link.active {
  background: var(--brand);
  color: #fff;
}

.gate-panel {
  padding: 28px;
}

.gate-panel p {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

code {
  padding: 2px 6px;
  border-radius: 8px;
  background: #eff6ff;
  color: var(--brand-dark);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(280px, 0.8fr);
  gap: 20px;
  align-items: stretch;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--brand);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 13px;
  font-weight: 700;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(32px, 5vw, 54px);
  line-height: 1.02;
  max-width: 10ch;
}

.intro {
  max-width: 62ch;
  margin: 16px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.panel,
.upload-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.upload-card {
  position: relative;
  display: flex;
  min-height: 190px;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  padding: 28px;
  overflow: hidden;
  cursor: pointer;
  background: linear-gradient(145deg, #eff6ff 0%, #ffffff 100%);
}

.upload-card::after {
  content: "";
  position: absolute;
  inset: auto -30px -38px auto;
  width: 140px;
  height: 140px;
  border-radius: 40px;
  background: linear-gradient(145deg, rgba(37, 99, 235, 0.18), rgba(37, 99, 235, 0));
  transform: rotate(28deg);
}

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

.upload-title {
  position: relative;
  font-size: 24px;
  font-weight: 700;
}

.upload-hint {
  position: relative;
  color: var(--muted);
}

.panel {
  margin-top: 20px;
  padding: 22px;
}

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

label span {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  color: var(--muted);
}

input[type="number"],
select,
button {
  width: 100%;
  min-height: 46px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  background: var(--panel-strong);
  color: var(--text);
  padding: 0 14px;
}

button {
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease;
}

button:hover:enabled {
  transform: translateY(-1px);
  background: var(--brand-dark);
}

button:disabled,
select:disabled,
input:disabled {
  opacity: 0.56;
  cursor: not-allowed;
}

.inline {
  display: grid;
  grid-template-columns: minmax(90px, 120px) minmax(120px, 1fr);
  gap: 10px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.status-grid article {
  padding: 18px;
  border-radius: 12px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
}

.status-grid span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.status-grid strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.status-note {
  margin: 16px 2px 0;
  color: var(--good);
}

.actions {
  display: flex;
  gap: 12px;
}

.actions button {
  max-width: 200px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 14px;
}

.section-head p {
  margin: 0;
  color: var(--muted);
}

.compare-control {
  min-width: 220px;
}

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

.table-wrap {
  overflow: auto;
  border-radius: 18px;
  border: 1px solid rgba(87, 66, 27, 0.1);
  background: rgba(255, 255, 255, 0.55);
}

.pivot-builder {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 18px;
}

.field-pane,
.layout-pane {
  min-width: 0;
}

.field-list {
  display: flex;
  max-height: 520px;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  padding-right: 4px;
}

.field-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  background: #f9fafb;
  padding: 12px 14px;
  cursor: grab;
}

.field-check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.field-check input {
  margin: 0;
}

.field-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.field-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.field-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: #eff6ff;
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 700;
}

.mini-button,
.ghost-button {
  width: auto;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
}

.mini-button {
  background: #eff6ff;
  color: var(--brand-dark);
}

.ghost-button {
  background: transparent;
  color: var(--brand-dark);
  border: 1px solid #cbd5e1;
}

.layout-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.layout-toolbar button {
  width: auto;
}

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

.drop-card {
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  background: #f9fafb;
  padding: 16px;
}

.drop-card-wide {
  grid-column: 1 / -1;
}

.drop-head {
  margin-bottom: 12px;
}

.drop-head h3 {
  margin: 0;
  font-size: 18px;
}

.drop-head p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.drop-zone {
  display: flex;
  min-height: 104px;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 10px;
  padding: 12px;
  border: 1px dashed #cbd5e1;
  border-radius: 16px;
  background: #ffffff;
}

.zone-empty {
  color: var(--muted);
  font-size: 14px;
}

.zone-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  max-width: 100%;
  padding: 6px 8px 6px 12px;
  border-radius: 12px;
  background: #ffffff;
  border: 1px solid #bfdbfe;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.08);
  cursor: grab;
}

.value-chip {
  background: #eff6ff;
}

.chip-label {
  font-weight: 600;
}

.chip-select {
  width: auto;
  min-width: 88px;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 10px;
}

.chip-remove {
  width: 28px;
  min-width: 28px;
  min-height: 28px;
  padding: 0;
  border-radius: 999px;
  background: #eff6ff;
  color: var(--text);
}

.total-row td {
  background: #f4ead7;
  font-weight: 700;
}

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

.pivot-table {
  min-width: 100%;
  table-layout: fixed;
}

.is-resizing-columns,
.is-resizing-columns * {
  cursor: col-resize !important;
  user-select: none !important;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(87, 66, 27, 0.1);
  border-right: 1px solid rgba(87, 66, 27, 0.08);
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f6ebd6;
}

.pivot-table th,
.pivot-table td {
  padding: 7px 8px;
  font-size: 12px;
  line-height: 1.25;
  white-space: normal;
  word-break: break-word;
}

.pivot-filter-head {
  min-width: 132px;
}

.pivot-resizable-head {
  padding-right: 20px !important;
}

.pivot-filter-head,
.pivot-filter-head > .pivot-filter-label {
  vertical-align: middle;
}

.pivot-filter-head {
  display: table-cell;
}

.pivot-filter-head.filtered {
  background: #eddcb9;
}

.pivot-filter-label {
  display: inline-block;
  max-width: calc(100% - 28px);
}

.pivot-table .pivot-filter-head {
  min-width: 0;
}

.pivot-table .pivot-filter-label {
  max-width: calc(100% - 40px);
}

.pivot-head-text {
  display: inline-block;
  max-width: 100%;
}

.pivot-col-resizer {
  position: absolute;
  top: 0;
  right: -6px;
  z-index: 3;
  width: 12px;
  min-width: 12px;
  height: 100%;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: transparent;
  box-shadow: none;
  transform: none !important;
}

.pivot-col-resizer:hover,
.pivot-col-resizer:focus {
  background: transparent;
  box-shadow: none;
}

.pivot-col-resizer::after {
  content: "";
  position: absolute;
  top: 6px;
  bottom: 6px;
  left: 50%;
  width: 2px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: transparent;
}

.pivot-resizable-head:hover .pivot-col-resizer::after,
.is-resizing-columns .pivot-col-resizer::after {
  background: rgba(174, 93, 31, 0.34);
}

.compare-hit-cell,
.compare-input-hit {
  background: #f7e27a !important;
}

.compare-hit-row td {
  background: #f7e27a !important;
}

.compare-duplicate-cell {
  background: rgba(79, 45, 128, 0.28) !important;
}

.compare-duplicate-row td {
  background: rgba(79, 45, 128, 0.28) !important;
}

.compare-input-cell {
  background: rgba(255, 251, 244, 0.96);
}

.compare-input-head,
.compare-input-cell {
  box-shadow: inset 6px 0 0 #ffffff;
}

.pivot-table td.compare-input-cell {
  padding: 0;
}

.compare-input {
  width: 100%;
  min-height: 34px;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 7px 8px;
  font-size: 12px;
  outline: none;
}

.compare-input:focus {
  background: rgba(174, 93, 31, 0.06);
}

.pivot-filter-button {
  display: inline-flex;
  width: 20px;
  height: 20px;
  margin-left: 8px;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid rgba(87, 66, 27, 0.18);
  border-radius: 4px;
  background: linear-gradient(180deg, #fffaf1 0%, #ead9b6 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.pivot-filter-caret {
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid #6f5a35;
}

.pivot-filter-popover {
  position: fixed;
  z-index: 30;
  width: 280px;
}

.pivot-filter-popover.hidden {
  display: none;
}

.pivot-filter-card {
  border: 1px solid rgba(87, 66, 27, 0.16);
  border-radius: 16px;
  background: #fffaf2;
  box-shadow: 0 20px 45px rgba(61, 45, 18, 0.18);
  padding: 14px;
}

.pivot-filter-toolbar,
.pivot-filter-actions,
.pivot-filter-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.pivot-filter-toolbar {
  margin-bottom: 10px;
  color: var(--muted);
}

.pivot-filter-search {
  width: 100%;
  min-height: 38px;
  margin-bottom: 10px;
  border: 1px solid rgba(87, 66, 27, 0.16);
  border-radius: 12px;
  background: white;
  padding: 0 12px;
}

.pivot-filter-actions {
  margin-bottom: 10px;
}

.pivot-filter-actions button,
.pivot-filter-footer button {
  width: auto;
}

.pivot-filter-list {
  max-height: 260px;
  overflow: auto;
  border: 1px solid rgba(87, 66, 27, 0.12);
  border-radius: 12px;
  background: white;
  padding: 8px;
}

.pivot-filter-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
  border-radius: 8px;
}

.pivot-filter-item:hover {
  background: rgba(174, 93, 31, 0.06);
}

.pivot-filter-item input {
  margin: 0;
}

.pivot-filter-footer {
  margin-top: 12px;
  justify-content: flex-end;
}

tbody tr:nth-child(even) td {
  background: rgba(255, 252, 247, 0.7);
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.empty-state {
  padding: 28px;
  color: var(--muted);
}

@media (max-width: 980px) {
  .hero,
  .control-grid,
  .status-grid,
  .pivot-builder,
  .drop-grid {
    grid-template-columns: 1fr;
  }

  .actions {
    flex-direction: column;
  }

  .actions button {
    max-width: none;
  }

  .drop-card-wide {
    grid-column: auto;
  }
}
