:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-strong: #fdfcf8;
  --ink: #18201e;
  --muted: #65706b;
  --line: #d9dfd8;
  --accent: #167463;
  --accent-strong: #0f5d50;
  --gold: #b77b18;
  --good: #087f5b;
  --bad: #c83f3f;
  --blue: #3465a4;
  --violet: #6d5cae;
  --radius: 8px;
  --shadow: 0 18px 40px rgba(24, 32, 30, 0.08);
  font-family:
    "Inter", "Yu Gothic UI", "Hiragino Sans", "Meiryo", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.65), transparent 320px),
    var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 32px;
}

.topbar,
.import-panel,
.panel,
.metric {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  min-height: 88px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 20px;
  border-radius: var(--radius);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
  line-height: 1.25;
}

.top-actions,
.import-actions,
.controls,
.panel-header,
.segmented,
.search-box,
.file-strip,
.chart-controls {
  display: flex;
  align-items: center;
}

.top-actions,
.import-actions {
  gap: 10px;
}

.primary-button,
.ghost-button,
.icon-button,
.segmented button,
th button {
  min-height: 40px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease,
    color 160ms ease;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.primary-button:hover,
.primary-button:focus-visible {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.ghost-button,
.icon-button {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

.ghost-button {
  padding: 0 14px;
  white-space: nowrap;
}

.icon-button {
  display: grid;
  width: 42px;
  place-items: center;
  font-weight: 800;
}

.ghost-button:hover,
.icon-button:hover,
.ghost-button:focus-visible,
.icon-button:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
}

.workspace {
  display: grid;
  gap: 18px;
  margin-top: 18px;
}

.import-section {
  display: grid;
  gap: 10px;
}

.import-panel {
  display: flex;
  min-height: 116px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 22px;
  border-radius: var(--radius);
  outline: 2px dashed transparent;
  outline-offset: -8px;
}

.import-panel.dragover {
  border-color: var(--accent);
  outline-color: rgba(22, 116, 99, 0.32);
  background: var(--surface-strong);
}

.import-copy {
  display: grid;
  gap: 6px;
}

.import-copy p,
.panel-header p {
  color: var(--muted);
  font-size: 13px;
}

#fileInput {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-strip {
  min-height: 28px;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  max-width: 100%;
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

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

.metric {
  display: grid;
  min-height: 108px;
  align-content: space-between;
  padding: 16px;
  border-radius: var(--radius);
}

.metric span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric strong {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: clamp(22px, 2.4vw, 32px);
  line-height: 1.05;
  letter-spacing: 0;
}

.metric-profit strong.positive,
.positive {
  color: var(--good);
}

.metric-profit strong.negative,
.negative {
  color: var(--bad);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(330px, 410px);
  gap: 18px;
  align-items: start;
}

.panel {
  border-radius: var(--radius);
  overflow: hidden;
}

.panel-header {
  min-height: 76px;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-header.compact {
  min-height: 62px;
}

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

.chart-controls {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.chart-controls select {
  min-height: 34px;
  max-width: 112px;
  padding-left: 10px;
}

.search-box {
  min-height: 40px;
  width: min(280px, 100%);
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--muted);
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
}

select {
  min-height: 40px;
  max-width: 220px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 0 36px 0 12px;
}

.table-wrap {
  overflow: auto;
  max-height: min(68vh, 720px);
}

table {
  width: 100%;
  min-width: 1220px;
  border-collapse: separate;
  border-spacing: 0;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef3ef;
  color: var(--muted);
  font-size: 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

th button {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: inherit;
  font-weight: 800;
  text-align: inherit;
}

th button:hover,
th button:focus-visible {
  color: var(--accent);
  background: rgba(22, 116, 99, 0.08);
}

td {
  height: 54px;
  padding: 10px 12px;
  border-bottom: 1px solid #edf0ed;
  vertical-align: middle;
  font-size: 14px;
  white-space: nowrap;
}

tbody tr:hover {
  background: #fbfaf5;
}

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

.ticker {
  display: grid;
  gap: 2px;
  font-weight: 800;
}

.ticker small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.empty-state {
  height: 220px;
  color: var(--muted);
  text-align: center;
}

.side-stack {
  display: grid;
  gap: 18px;
}

.segmented {
  min-height: 34px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f3f5f1;
}

.segmented button {
  min-height: 28px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.segmented button.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 8px rgba(24, 32, 30, 0.08);
}

.allocation-bar {
  display: flex;
  height: 18px;
  margin: 18px 16px 6px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf0ed;
}

.allocation-bar span {
  min-width: 2px;
}

.legend-list,
.mapping-list {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.legend-item,
.mapping-item {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.legend-name,
.mapping-name {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend-value,
.mapping-value {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: #eef3ef;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.status-pill.ok {
  background: rgba(8, 127, 91, 0.12);
  color: var(--good);
}

.status-pill.warn {
  background: rgba(183, 123, 24, 0.15);
  color: var(--gold);
}

.missing {
  color: var(--gold);
}

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

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

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 20px, 1480px);
    padding-top: 10px;
  }

  .topbar,
  .import-panel,
  .panel-header {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .import-actions,
  .controls {
    justify-content: stretch;
  }

  .primary-button,
  .ghost-button,
  .controls > *,
  .search-box,
  select,
  .chart-controls {
    width: 100%;
    max-width: none;
  }

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

  .metric {
    min-height: 94px;
  }
}

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