:root {
  color-scheme: light dark;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --panel-strong: #eef6f2;
  --text: #18221f;
  --muted: #68736f;
  --line: #d9e1dd;
  --brand: #1f7a6d;
  --brand-strong: #145f55;
  --accent: #d7992d;
  --danger-soft: #f3ece8;
  --shadow: 0 12px 30px rgba(30, 52, 47, 0.12);
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Segoe UI", sans-serif;
}

body.dark {
  --bg: #101513;
  --panel: #18201d;
  --panel-strong: #1e2a25;
  --text: #eef4f1;
  --muted: #a8b5af;
  --line: #31403b;
  --brand: #55b8a8;
  --brand-strong: #76d6c5;
  --accent: #e1b24d;
  --danger-soft: #2b2422;
  --shadow: none;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button,
select,
.primary-file-button {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
}

button,
.primary-file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

button:active,
.primary-file-button:active {
  transform: translateY(1px);
}

.app-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 14px calc(94px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0 14px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.7rem, 8vw, 2.35rem);
  line-height: 1.05;
}

h2 {
  font-size: 1.05rem;
}

.icon-button {
  width: 48px;
  flex: 0 0 48px;
  padding: 0;
  font-size: 1.3rem;
}

.import-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
  min-height: 118px;
  padding: 18px;
  border: 2px dashed color-mix(in srgb, var(--brand) 55%, var(--line));
  border-radius: var(--radius);
  background: var(--panel-strong);
}

.import-panel.dragging {
  border-style: solid;
  background: color-mix(in srgb, var(--brand) 14%, var(--panel));
}

.import-panel p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.92rem;
}

.primary-file-button {
  border-color: var(--brand);
  background: var(--brand);
  color: white;
}

.primary-file-button input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

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

.summary-grid article {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.summary-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.summary-grid strong {
  display: block;
  margin-top: 6px;
  font-size: clamp(1.05rem, 4vw, 1.45rem);
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.toolbar {
  display: grid;
  grid-template-columns: 0.8fr 1fr 1fr minmax(140px, 0.9fr);
  gap: 8px;
}

.toolbar button[aria-pressed="true"] {
  border-color: var(--brand);
  background: var(--brand);
  color: white;
}

.danger-button {
  border-color: #d2b3a8;
  background: var(--danger-soft);
}

select {
  width: 100%;
  padding: 0 12px;
  font-weight: 700;
}

.search-box {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
  margin: 10px 0;
  min-height: 52px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.search-box span {
  color: var(--muted);
  font-weight: 700;
}

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

.status-line {
  min-height: 28px;
  color: var(--muted);
  font-size: 0.9rem;
}

.status-line.error {
  color: #b84b32;
  font-weight: 700;
}

.output-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  margin: 8px 0 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
}

.output-panel[hidden] {
  display: none;
}

.output-panel strong,
.output-panel span {
  display: block;
}

.output-panel span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.86rem;
  overflow-wrap: anywhere;
}

.output-panel a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--radius);
  background: var(--brand);
  color: white;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.history-panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.table-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.table-head span {
  color: var(--muted);
  font-weight: 700;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

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

th,
td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel-strong);
  color: var(--muted);
  font-size: 0.82rem;
}

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

tr.excluded {
  background: var(--danger-soft);
  color: color-mix(in srgb, var(--text) 56%, var(--muted));
}

tr.excluded td:not(:first-child) {
  opacity: 0.58;
}

.exclude-check {
  width: 24px;
  height: 24px;
  accent-color: var(--brand);
}

.mobile-exclude {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.empty-cell {
  padding: 28px 10px;
  color: var(--muted);
  text-align: center;
}

.action-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 12px max(14px, env(safe-area-inset-left)) calc(12px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-right));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  backdrop-filter: blur(16px);
}

.action-bar button {
  min-height: 54px;
  font-size: 1.02rem;
}

.primary-action {
  border-color: var(--brand);
  background: var(--brand);
  color: white;
}

@media (max-width: 720px) {
  .app-shell {
    padding-inline: 10px;
  }

  .import-panel,
  .toolbar {
    grid-template-columns: 1fr;
  }

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

  .primary-file-button {
    width: 100%;
  }

  .import-panel {
    padding: 16px;
  }

  .import-panel h2 {
    font-size: 1.18rem;
  }

  .import-panel p {
    line-height: 1.55;
  }

  .table-wrap {
    overflow-x: auto;
  }

  table {
    min-width: 0;
    table-layout: fixed;
  }

  th,
  td {
    padding: 9px 6px;
    font-size: 0.88rem;
    white-space: nowrap;
  }

  th:nth-child(7),
  td:nth-child(5),
  td:nth-child(7),
  th:nth-child(8),
  td:nth-child(8) {
    display: none;
  }

  th:nth-child(1),
  td:nth-child(1) {
    width: 58px;
  }

  th:nth-child(2),
  td:nth-child(2) {
    width: 58px;
  }

  th:nth-child(3),
  td:nth-child(3) {
    width: 64px;
  }

  th:nth-child(4),
  td:nth-child(4) {
    width: auto;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  th:nth-child(6),
  td:nth-child(6) {
    width: auto;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .exclude-check {
    width: 28px;
    height: 28px;
  }

  .mobile-exclude span {
    display: none;
  }

  .mobile-exclude {
    justify-content: center;
  }

  .output-panel {
    grid-template-columns: 1fr;
  }

  .output-panel a {
    width: 100%;
  }
}

@media (prefers-color-scheme: dark) {
  body:not(.light) {
    --bg: #101513;
    --panel: #18201d;
    --panel-strong: #1e2a25;
    --text: #eef4f1;
    --muted: #a8b5af;
    --line: #31403b;
    --brand: #55b8a8;
    --brand-strong: #76d6c5;
    --accent: #e1b24d;
    --danger-soft: #2b2422;
    --shadow: none;
  }
}
