:root {
  color-scheme: light dark;

  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #dfe3e8;
  --border-strong: #c4cad2;
  --text: #1d2330;
  --text-muted: #616b7a;
  --accent: #2f5fd0;
  --accent-text: #ffffff;
  --accent-soft: #e8effc;
  --danger: #b4293a;
  --danger-soft: #fdecee;
  --ok: #1f7a4d;
  --ok-soft: #e6f4ec;
  --warn: #8a6100;
  --warn-soft: #fdf3dc;
  --neutral: #4f5765;
  --neutral-soft: #eceff3;
  --shadow: 0 1px 2px rgba(20, 26, 38, .06), 0 8px 20px rgba(20, 26, 38, .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --surface: #1c2027;
    --border: #2c323c;
    --border-strong: #3d4552;
    --text: #e7eaef;
    --text-muted: #9aa4b2;
    --accent: #6f9bff;
    --accent-text: #10151f;
    --accent-soft: #223250;
    --danger: #ff9098;
    --danger-soft: #3a2126;
    --ok: #6fd39c;
    --ok-soft: #1c3229;
    --warn: #e8c169;
    --warn-soft: #352d18;
    --neutral: #aab3c0;
    --neutral-soft: #262c35;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans",
    "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 15px;
  line-height: 1.7;
  overflow-x: hidden;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .9em;
  background: var(--neutral-soft);
  border-radius: 4px;
  padding: .1em .35em;
}

.wrap {
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 20px;
}

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding-top: 18px;
  padding-bottom: 18px;
}

.site-title {
  margin: 0;
  font-size: 18px;
  font-weight: 650;
  letter-spacing: .02em;
}

.site-sub {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
}

main { padding: 24px 0 40px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

.card h2 {
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 650;
}

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

.section-head h2 { margin: 0; }

.section-tools {
  display: flex;
  align-items: center;
  gap: 10px;
}

.field-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.field-row label {
  font-size: 13px;
  color: var(--text-muted);
  min-width: 78px;
}

input[type="text"] {
  flex: 1 1 200px;
  min-width: 0;
  padding: 8px 10px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
}

input[type="text"]:focus-visible,
.dropzone:focus-visible,
.btn:focus-visible,
.invoice-row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.hint {
  margin: 10px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

.btn {
  font: inherit;
  font-size: 13.5px;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.btn:hover:not(:disabled) { border-color: var(--accent); }

.btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
  padding: 6px 10px;
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--border-strong);
}

.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: 10px;
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
  background: var(--bg);
  transition: background .12s ease, border-color .12s ease;
}

.dropzone:hover { border-color: var(--accent); }

.dropzone.is-dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone-main {
  margin: 0;
  font-size: 14.5px;
  font-weight: 600;
}

.dropzone-sub {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

.selected-file {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding: 10px 12px;
  background: var(--neutral-soft);
  border-radius: 6px;
  font-size: 13.5px;
}

.selected-name {
  font-weight: 600;
  word-break: break-all;
}

.selected-size { color: var(--text-muted); }

.selected-file .btn-ghost { margin-left: auto; }

.actions { margin-top: 14px; }

.progress-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}

.progress-track {
  flex: 1 1 auto;
  height: 8px;
  border-radius: 999px;
  background: var(--neutral-soft);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width .15s ease;
}

.progress-label {
  font-size: 12.5px;
  color: var(--text-muted);
  min-width: 4ch;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.message {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13.5px;
  border: 1px solid transparent;
}

.message.is-error {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}

.message.is-ok {
  background: var(--ok-soft);
  border-color: var(--ok);
  color: var(--ok);
}

.message.is-info {
  background: var(--neutral-soft);
  border-color: var(--border);
  color: var(--text-muted);
}

.poll-indicator {
  font-size: 12px;
  color: var(--text-muted);
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--neutral-soft);
}

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

.invoice-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 13.5px;
}

.invoice-table th,
.invoice-table td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.invoice-table th {
  font-size: 12px;
  font-weight: 650;
  color: var(--text-muted);
  white-space: nowrap;
}

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

.invoice-row { cursor: pointer; }

.invoice-row:hover { background: var(--accent-soft); }

.invoice-row.is-open { background: var(--accent-soft); }

.cell-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  white-space: nowrap;
}

.cell-filename {
  max-width: 260px;
  word-break: break-all;
}

.cell-date { white-space: nowrap; }

.badge {
  display: inline-block;
  padding: 1px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: .03em;
  white-space: nowrap;
  border: 1px solid transparent;
}

.badge-pending    { background: var(--neutral-soft); color: var(--neutral); border-color: var(--border-strong); }
.badge-queued     { background: var(--accent-soft);  color: var(--accent); border-color: var(--accent); }
.badge-processing { background: var(--warn-soft);    color: var(--warn);   border-color: var(--warn); }
.badge-processed  { background: var(--ok-soft);      color: var(--ok);     border-color: var(--ok); }
.badge-failed     { background: var(--danger-soft);  color: var(--danger); border-color: var(--danger); }
.badge-unknown    { background: var(--neutral-soft); color: var(--neutral); border-color: var(--border-strong); }

.detail-row > td {
  background: var(--bg);
  padding: 14px 16px;
}

.detail-title {
  margin: 0 0 8px;
  font-size: 12.5px;
  font-weight: 650;
  color: var(--text-muted);
}

.detail-error {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  color: var(--danger);
  font-size: 13px;
  word-break: break-word;
}

.detail-meta {
  margin: 0 0 12px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 4px 16px;
  font-size: 12.5px;
}

.detail-meta div {
  display: flex;
  gap: 8px;
}

.detail-meta dt {
  margin: 0;
  color: var(--text-muted);
  min-width: 90px;
}

.detail-meta dd {
  margin: 0;
  word-break: break-all;
}

.items-table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  font-size: 12.5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.items-table th,
.items-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.items-table tr:last-child td { border-bottom: none; }

.items-table th {
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
}

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

.empty,
.detail-empty {
  margin: 14px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

.detail-empty { margin: 0; }

.site-footer {
  border-top: 1px solid var(--border);
  padding: 16px 0 28px;
}

.site-footer .hint { margin: 0; }

@media (max-width: 600px) {
  .wrap { padding: 0 14px; }
  .card { padding: 16px; }
  .field-row label { min-width: 100%; }
}
