:root {
  color-scheme: dark;
  --bg: #0a0c10;
  --panel: #14171d;
  --panel-2: #1b1f27;
  --raise: #2a313c;
  --ink: #e7eaef;
  --muted: #8b95a4;
  --line: #272d38;
  --accent: #34d3bf;
  --accent-strong: #16b8a6;
  --danger: #f87171;
  --danger-ink: #2a0a0a;
  --success: #34d399;
  --success-ink: #052e1f;
  --shadow: 0 14px 34px rgba(0, 0, 0, 0.5);
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", "Yu Gothic", Meiryo, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: var(--mono);
  font-feature-settings: "tnum" 1;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(10, 12, 16, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.topbar__inner {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand .status {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-family: var(--mono);
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.tab {
  height: 36px;
  padding: 0 16px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.tab:hover {
  color: var(--ink);
}

.tab.is-active {
  background: var(--raise);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

main {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 22px 24px 56px;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
  animation: fade 0.25s ease both;
}

.toolbar {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.filters-wrap {
  margin-bottom: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.filters-wrap > summary {
  cursor: pointer;
  padding: 14px 16px;
  font-weight: 700;
  color: var(--ink);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.filters-wrap > summary::-webkit-details-marker {
  display: none;
}

.filters-wrap > summary::before {
  content: "▸";
  color: var(--muted);
  transition: transform 0.15s;
}

.filters-wrap[open] > summary::before {
  transform: rotate(90deg);
}

.filters {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 12px;
  padding: 0 16px 16px;
}

label {
  display: grid;
  gap: 6px;
  min-width: 150px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

input,
select {
  height: 40px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--ink);
  font: inherit;
  padding: 0 12px;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(52, 211, 191, 0.15);
}

button,
.secondary {
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 16px;
  background: var(--panel-2);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}

button:active {
  transform: translateY(1px);
}

.primary {
  border-color: transparent;
  background: var(--accent);
  color: #04231e;
}

.primary:hover {
  background: var(--accent-strong);
}

.secondary {
  text-decoration: none;
}

.filter-actions {
  display: flex;
  gap: 8px;
  align-items: end;
}

.seller-admin {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 4px;
}

.register-form {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.register-msg {
  margin: 4px 0 16px;
  font-size: 13px;
  color: var(--success);
}

.register-msg.is-error {
  color: var(--danger);
}

.btn-stop,
.btn-resume {
  height: 32px;
  padding: 0 14px;
  font-size: 12px;
  font-weight: 700;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  cursor: pointer;
}

.btn-stop {
  color: var(--danger);
}

.btn-stop:hover {
  border-color: var(--danger);
}

.btn-resume {
  color: var(--success);
}

.btn-resume:hover {
  border-color: var(--success);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric {
  padding: 16px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}

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

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 30px;
  line-height: 1;
}

.table-shell {
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

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

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  position: sticky;
  top: 0;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

tbody tr {
  animation: rise 0.3s ease both;
}

tbody tr:hover td {
  background: rgba(255, 255, 255, 0.025);
}

tbody tr:last-child td {
  border-bottom: 0;
}

.status-ok {
  color: var(--success);
  font-weight: 700;
}

.status-failed {
  color: var(--danger);
  font-weight: 700;
}

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

.links {
  display: inline-flex;
  gap: 8px;
  flex-wrap: wrap;
}

.links a {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.links a:hover {
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}

.diffs-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 14px;
}

.diff-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}

.diff-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  animation: rise 0.3s ease both;
  transition: border-color 0.15s, transform 0.15s;
}

.diff-card:hover {
  border-color: var(--raise);
  transform: translateY(-2px);
}

.diff-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.diff-card__date {
  color: var(--muted);
  font-size: 12px;
}

.diff-card__seller {
  font-weight: 600;
  font-size: 14px;
  line-height: 1.4;
}

.diff-card__product {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: auto;
  padding: 8px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: zoom-in;
  font: inherit;
}

.diff-card__product:hover {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.diff-card__product img {
  max-width: 100%;
  max-height: 150px;
  width: auto;
  height: auto;
  object-fit: contain;
}

.diff-card__graph {
  display: block;
  width: 100%;
  height: auto;
  padding: 0;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #ffffff;
  cursor: zoom-in;
  font: inherit;
}

.diff-card__graph img {
  display: block;
  width: 100%;
  height: auto;
}

.diff-card__graph:hover {
  text-decoration: none;
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.diff-card__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.asin {
  font-size: 13px;
  color: var(--ink);
}

.badge {
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
}

.pill {
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
}

.pill-on {
  background: rgba(52, 211, 153, 0.16);
  color: var(--success);
}

.pill-off {
  background: rgba(139, 149, 164, 0.16);
  color: var(--muted);
}

.badge-add {
  background: var(--success);
  color: var(--success-ink);
}

.badge-rem {
  background: var(--danger);
  color: var(--danger-ink);
}

.empty {
  padding: 44px 16px;
  text-align: center;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 18px;
}

.pager[hidden] {
  display: none;
}

.pager__btn {
  height: 38px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

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

.pager__btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.pager__info {
  color: var(--muted);
  font-size: 13px;
}

body.modal-open {
  overflow: hidden;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal[hidden] {
  display: none;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.modal__panel {
  position: relative;
  z-index: 1;
  width: min(960px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  box-shadow: var(--shadow);
  animation: rise 0.2s ease both;
}

.modal__close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--ink);
  cursor: pointer;
}

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

.modal__title {
  margin: 2px 36px 12px 0;
  font-size: 14px;
  color: var(--ink);
}

.modal__graph {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.modal__graph img {
  display: block;
  max-width: 100%;
  max-height: 72vh;
  width: auto;
  height: auto;
  object-fit: contain;
}

.modal__graph img.modal__img--fill {
  width: 100%;
  max-height: none;
}

.modal__panel .secondary {
  margin-top: 12px;
}

.modal__panel--sm {
  width: min(420px, 100%);
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

@keyframes fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  .view.is-active,
  .diff-card,
  tbody tr {
    animation: none !important;
  }
}

@media (max-width: 760px) {
  .topbar__inner {
    padding: 12px 16px;
  }

  .tabs {
    width: 100%;
  }

  .tab {
    flex: 1;
    padding: 0 8px;
  }

  main {
    padding: 16px 16px 48px;
  }

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

  label {
    width: 100%;
    min-width: 0;
  }

  .filter-actions {
    width: 100%;
  }

  .filter-actions > * {
    flex: 1;
  }

  /* テーブルをカード表示に切り替え（横スクロール解消） */
  .table-shell {
    overflow: visible;
    background: transparent;
    border: 0;
    box-shadow: none;
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  table,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  tbody tr {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    margin-bottom: 12px;
    padding: 6px 2px;
  }

  td {
    border-bottom: 1px solid var(--line);
    padding: 9px 14px;
    text-align: left;
  }

  td:last-child {
    border-bottom: 0;
  }

  td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 1px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.03em;
  }

  .diff-list {
    grid-template-columns: 1fr;
  }
}
