:root {
  --bg: #0f1215;
  --panel: #171c20;
  --panel-soft: #11161a;
  --panel-strong: #20272d;
  --ink: #edf3f0;
  --muted: #91a0a8;
  --line: rgba(170, 189, 198, 0.18);
  --blue: #5ea7ff;
  --blue-dark: #9cc9ff;
  --teal: #20c7a5;
  --gold: #d5a647;
  --red: #ff6b6b;
  --green: #36d17f;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 18% 0%, rgba(32, 199, 165, 0.16), transparent 32%),
    radial-gradient(circle at 82% 0%, rgba(213, 166, 71, 0.13), transparent 30%),
    linear-gradient(180deg, #0b0d10 0%, #13181c 42%, #101316 100%);
  color: var(--ink);
  font-family: "Segoe UI", "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: 15px;
  letter-spacing: 0;
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: 18px;
}

.topbar {
  align-items: center;
  background:
    linear-gradient(135deg, rgba(32, 199, 165, 0.16), rgba(213, 166, 71, 0.1)),
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0));
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  justify-content: space-between;
  margin: 0 auto 14px;
  max-width: 1440px;
  padding: 16px 18px;
}

.eyebrow {
  color: var(--gold);
  font-size: 12px;
  font-weight: 600;
  margin: 0 0 3px;
  text-transform: uppercase;
}

h1 {
  font-size: 30px;
  font-weight: 600;
  line-height: 1.15;
  margin: 0;
}

h2 {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 10px;
}

.top-actions {
  display: flex;
  gap: 8px;
}

.icon-button {
  align-items: center;
  background: #101418;
  border: 1px solid rgba(213, 166, 71, 0.45);
  border-radius: 8px;
  color: var(--gold);
  cursor: pointer;
  display: inline-flex;
  height: 38px;
  justify-content: center;
  min-width: 38px;
  padding: 0 10px;
  transition: background 0.16s ease, transform 0.16s ease;
}

.icon-button:hover {
  background: rgba(213, 166, 71, 0.12);
  transform: translateY(-1px);
}

.workspace-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: 340px minmax(0, 1fr);
  margin: 0 auto;
  max-width: 1440px;
}

.control-panel,
.main-panel {
  background: rgba(23, 28, 32, 0.96);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.control-panel {
  align-self: start;
  padding: 14px;
  position: sticky;
  top: 14px;
}

.panel-section + .panel-section {
  border-top: 1px solid var(--line);
  margin-top: 14px;
  padding-top: 14px;
}

.quick-links {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr;
}

.quick-links a {
  background: var(--panel-soft);
  border: 1px solid rgba(213, 166, 71, 0.28);
  border-radius: 8px;
  color: var(--ink);
  min-width: 0;
  padding: 10px;
  text-decoration: none;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.quick-links a:hover {
  background: #151b1f;
  border-color: rgba(213, 166, 71, 0.58);
  transform: translateY(-1px);
}

.quick-links span {
  color: var(--muted);
  display: block;
  font-size: 11px;
  margin-bottom: 3px;
}

.quick-links strong {
  display: block;
  font-size: 12px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.saved-link {
  margin-top: 10px;
}

.keepa-link-card {
  background: rgba(15, 20, 24, 0.54);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.inline-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, 1fr);
  margin-top: 8px;
}

.inline-actions button,
.wide-action {
  background: linear-gradient(135deg, rgba(32, 199, 165, 0.92), rgba(31, 127, 218, 0.92));
  border: 0;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  min-height: 38px;
  padding: 0 12px;
}

.wide-action {
  margin-bottom: 10px;
  width: 100%;
}

.file-box {
  background: var(--panel-soft);
  border: 1px dashed rgba(32, 199, 165, 0.34);
  border-radius: 8px;
  cursor: pointer;
  display: block;
  margin-bottom: 10px;
  padding: 12px;
  transition: border-color 0.16s ease, background 0.16s ease, transform 0.16s ease;
}

.file-box:hover {
  background: #141c20;
  border-color: rgba(32, 199, 165, 0.62);
  transform: translateY(-1px);
}

.file-box span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-bottom: 4px;
}

.file-box strong {
  color: var(--ink);
  display: block;
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-box input {
  display: none;
}

.url-loader {
  align-items: end;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto;
  margin-bottom: 10px;
}

.url-loader button {
  background: linear-gradient(135deg, #1aa98e, #1f7fda);
  border: 0;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  min-height: 38px;
  padding: 0 14px;
}

.hint,
.status-line {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

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

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

input,
select {
  background: #0f1418;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  min-height: 38px;
  outline: none;
  padding: 8px 10px;
  width: 100%;
}

input:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(94, 167, 255, 0.14);
}

.segmented {
  background: #0f1418;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  grid-template-columns: repeat(3, 1fr);
  margin-top: 12px;
  padding: 4px;
}

.segment {
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  min-height: 34px;
}

.segment.active {
  background: rgba(32, 199, 165, 0.16);
  color: var(--teal);
  box-shadow: inset 0 0 0 1px rgba(32, 199, 165, 0.28);
}

.preset-row {
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(4, 1fr);
  margin-top: 10px;
}

.preset-row button {
  background: #11171b;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--blue-dark);
  cursor: pointer;
  min-height: 34px;
  transition: border-color 0.16s ease, color 0.16s ease, background 0.16s ease;
}

.preset-row button:hover {
  background: rgba(94, 167, 255, 0.08);
  border-color: rgba(94, 167, 255, 0.4);
}

.toggle-row {
  align-items: center;
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.toggle-row input {
  min-height: 0;
  width: auto;
}

.toggle-row span {
  color: var(--ink);
  font-size: 13px;
  margin: 0;
}

.main-panel {
  min-width: 0;
  padding: 14px;
}

.summary-strip {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
}

.metric {
  background: linear-gradient(180deg, #1c2329, #12181c);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  min-height: 82px;
}

.metric span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-bottom: 5px;
}

.metric strong {
  display: block;
  font-size: 22px;
  font-weight: 600;
}

.metric.accent {
  border-color: rgba(32, 199, 165, 0.46);
  background: linear-gradient(180deg, rgba(32, 199, 165, 0.17), #12181c);
}

.metric.accent strong {
  color: var(--teal);
}

.toolbar {
  align-items: center;
  display: flex;
  gap: 10px;
  margin: 14px 0 8px;
}

.search-wrap {
  flex: 1;
}

.toolbar select {
  max-width: 160px;
}

.status-line {
  margin-bottom: 8px;
  min-height: 20px;
}

.stockout-panel {
  background: rgba(213, 166, 71, 0.1);
  border: 1px solid rgba(213, 166, 71, 0.34);
  border-radius: 8px;
  margin-bottom: 10px;
  padding: 10px;
}

.stockout-title {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.stockout-title span,
.stockout-title strong {
  color: var(--gold);
  font-size: 13px;
  font-weight: 600;
}

.stockout-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.stockout-chip {
  align-items: center;
  background: rgba(15, 20, 24, 0.82);
  border: 1px solid rgba(213, 166, 71, 0.28);
  border-radius: 8px;
  color: var(--ink);
  display: inline-flex;
  gap: 8px;
  max-width: 100%;
  padding: 7px 9px;
  text-decoration: none;
}

.stockout-chip strong {
  font-size: 13px;
  font-weight: 600;
}

.stockout-chip span {
  color: var(--muted);
  font-size: 12px;
  margin: 0;
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  max-height: calc(100vh - 236px);
  overflow: auto;
}

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

tbody tr {
  transition: background 0.14s ease;
}

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

thead {
  background: #20272d;
  position: sticky;
  top: 0;
  z-index: 1;
}

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

th {
  color: var(--blue-dark);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

td {
  font-size: 13px;
}

.card-title {
  font-weight: 600;
  margin-bottom: 3px;
  overflow-wrap: anywhere;
}

.subtext {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.match-note {
  color: var(--blue-dark);
  font-size: 12px;
  font-weight: 600;
  margin-top: 4px;
}

.match-note.reprint {
  color: var(--gold);
}

.pill {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  justify-content: center;
  min-width: 70px;
  padding: 4px 8px;
}

.pill.buy {
  background: rgba(54, 209, 127, 0.14);
  color: var(--green);
}

.pill.watch {
  background: rgba(213, 166, 71, 0.16);
  color: var(--gold);
}

.pill.stockout {
  background: rgba(94, 167, 255, 0.14);
  color: var(--blue-dark);
}

.pill.loss {
  background: rgba(255, 107, 107, 0.14);
  color: var(--red);
}

.pill.owned {
  background: rgba(102, 117, 133, 0.14);
  color: #506070;
}

.pill.low {
  background: rgba(102, 117, 133, 0.1);
  color: var(--muted);
}

.money-positive {
  color: var(--green);
  font-weight: 600;
}

.money-negative {
  color: var(--red);
  font-weight: 600;
}

.link-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.link-row a {
  color: var(--teal);
  text-decoration: none;
}

.empty-cell {
  color: var(--muted);
  height: 160px;
  text-align: center;
  vertical-align: middle;
}

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

  .topbar {
    align-items: flex-start;
    padding: 14px;
  }

  h1 {
    font-size: 24px;
  }

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

  .control-panel {
    position: static;
  }

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

  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar select {
    max-width: none;
  }

  .table-wrap {
    max-height: none;
  }
}

@media (max-width: 720px) {
  body {
    font-size: 14px;
  }

  .app-shell {
    padding: 8px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }

  .top-actions {
    justify-content: flex-start;
    flex-shrink: 0;
  }

  .topbar,
  .control-panel,
  .main-panel,
  .workspace-grid {
    max-width: 100%;
    min-width: 0;
    width: 100%;
  }

  .url-loader {
    grid-template-columns: 1fr;
  }

  .url-loader button {
    width: 100%;
  }

  .workspace-grid {
    gap: 10px;
  }

  .control-panel,
  .main-panel {
    border-radius: 8px;
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.24);
  }

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

  .metric {
    min-height: 70px;
    padding: 10px;
  }

  .metric strong {
    font-size: 20px;
  }

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

  .preset-row {
    grid-template-columns: repeat(2, 1fr);
  }

  .stockout-list {
    display: grid;
  }

  .stockout-chip {
    justify-content: space-between;
  }

  .table-wrap {
    border: 0;
    overflow: visible;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 10px;
  }

  tbody tr {
    background: linear-gradient(180deg, #1c2329, #12181c);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
  }

  tbody tr:hover {
    background: linear-gradient(180deg, #1f282f, #131a1f);
  }

  td {
    border-bottom: 0;
    display: grid;
    gap: 6px;
    grid-template-columns: 86px minmax(0, 1fr);
    padding: 7px 0;
  }

  td::before {
    color: var(--muted);
    content: "";
    font-size: 12px;
  }

  td:nth-child(1)::before { content: "判定"; }
  td:nth-child(2)::before { content: "カード"; }
  td:nth-child(3)::before { content: "仕入先"; }
  td:nth-child(4)::before { content: "Amazon"; }
  td:nth-child(5)::before { content: "利益"; }
  td:nth-child(6)::before { content: "照合"; }
  td:nth-child(7)::before { content: "リンク"; }

  .empty-cell {
    display: block;
    height: auto;
    padding: 28px 10px;
    text-align: center;
  }

  .empty-cell::before {
    content: "";
  }

  .pill {
    justify-self: start;
  }

  .link-row {
    justify-content: flex-start;
  }
}

@media (max-width: 420px) {
  .topbar {
    flex-direction: column;
  }

  .summary-strip,
  .field-grid {
    grid-template-columns: 1fr;
  }

  td {
    grid-template-columns: 72px minmax(0, 1fr);
  }
}
