:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --line: #d9dee7;
  --line-strong: #b6bfcc;
  --text: #1d2430;
  --muted: #637083;
  --blue: #1f5fbf;
  --blue-dark: #16498f;
  --green: #12805c;
  --amber: #a86405;
  --red: #b42318;
  --violet: #6941c6;
  --shadow: 0 8px 24px rgba(24, 32, 48, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    "Yu Gothic UI",
    "Meiryo",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1480px, calc(100vw - 28px));
  margin: 0 auto;
}

.app-header {
  background: #252b36;
  color: #fff;
  border-bottom: 4px solid #32a58c;
}

.header-inner {
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  font-weight: 700;
}

h2 {
  font-size: 16px;
  font-weight: 700;
}

.app-header p {
  margin-top: 4px;
  color: #c8d0dd;
  font-size: 13px;
}

.header-status {
  min-width: 84px;
  min-height: 32px;
  padding: 6px 12px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  color: #dfe6ef;
  text-align: center;
  white-space: nowrap;
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  padding: 14px 0 24px;
}

.input-panel,
.summary-panel,
.results-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.input-panel {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(280px, 360px);
  grid-template-areas:
    "heading controls"
    "textarea controls";
  gap: 10px 14px;
  align-items: start;
  padding: 14px;
}

.input-panel .panel-heading {
  grid-area: heading;
  margin-bottom: 0;
}

.input-panel textarea {
  grid-area: textarea;
}

.input-panel .controls {
  grid-area: controls;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.counter {
  min-width: 64px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  text-align: center;
  white-space: nowrap;
}

textarea {
  width: 100%;
  min-height: 138px;
  resize: vertical;
  padding: 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--text);
  background: #fbfcfe;
  outline: none;
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(31, 95, 191, 0.14);
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-items: end;
  align-content: end;
  height: 100%;
  margin-top: 0;
}

.controls label {
  grid-column: 1 / -1;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

select,
input[type="search"] {
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

select {
  padding: 0 34px 0 10px;
}

input[type="search"] {
  width: 220px;
  padding: 0 10px;
}

.primary-button,
.secondary-button {
  min-height: 40px;
  padding: 0 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 700;
  white-space: nowrap;
}

.primary-button {
  background: var(--blue);
  color: #fff;
}

.primary-button:hover {
  background: var(--blue-dark);
}

.secondary-button {
  background: #fff;
  border-color: var(--line-strong);
  color: var(--text);
}

.secondary-button:hover {
  border-color: var(--blue);
  color: var(--blue);
}

button:disabled {
  cursor: wait;
  opacity: 0.64;
}

.summary-panel {
  grid-column: 1;
  display: grid;
  grid-template-columns: repeat(7, minmax(96px, 1fr));
  gap: 0;
  overflow: hidden;
}

.summary-item {
  display: grid;
  min-height: 64px;
  align-content: center;
  gap: 2px;
  padding: 12px;
  border: 0;
  border-right: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  text-align: left;
}

.summary-item:last-child {
  border-right: 0;
}

.summary-label {
  color: var(--muted);
  font-size: 12px;
}

.summary-item strong {
  font-size: 22px;
  line-height: 1.1;
}

.filter-button.active {
  background: #eef5ff;
  box-shadow: inset 0 -3px 0 var(--blue);
}

.filter-button:hover {
  background: #f7f9fc;
}

.results-panel {
  grid-column: 1;
  min-width: 0;
  overflow: hidden;
}

.results-heading {
  min-height: 56px;
  margin: 0;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.result-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.progress {
  height: 4px;
  background: #e7ecf4;
  overflow: hidden;
}

.progress div {
  width: 38%;
  height: 100%;
  background: var(--blue);
  animation: loading 1s ease-in-out infinite;
}

@keyframes loading {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(280%);
  }
}

.table-wrap {
  width: 100%;
  max-height: max(420px, calc(100vh - 330px));
  min-height: 420px;
  overflow: auto;
}

table {
  width: 100%;
  min-width: 1160px;
  border-collapse: collapse;
  table-layout: fixed;
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f9fafc;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.sort-button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  min-height: 26px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: inherit;
  font-weight: inherit;
  text-align: left;
}

.sort-button:hover,
.sort-button.active {
  color: var(--blue);
}

.sort-indicator {
  min-width: 12px;
  color: var(--blue);
  font-size: 10px;
  line-height: 1;
}

tbody tr:hover {
  background: #fbfcff;
}

.row-index {
  width: 56px;
  color: var(--muted);
}

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

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

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

th:nth-child(4),
td:nth-child(4) {
  width: 104px;
}

th:nth-child(5),
td:nth-child(5) {
  width: 164px;
}

th:nth-child(6),
td:nth-child(6) {
  width: 118px;
}

th:nth-child(8),
td:nth-child(8) {
  width: 72px;
}

.tracking-number {
  font-family: "Cascadia Mono", Consolas, monospace;
  font-weight: 700;
}

.carrier {
  white-space: nowrap;
}

.detail {
  color: var(--text);
  overflow-wrap: anywhere;
}

.detail-stack {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 6px;
}

.detail-line {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
}

.detail-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 20px;
  padding: 0 5px;
  border: 1px solid #d7dde8;
  border-radius: 4px;
  background: #f5f7fa;
  color: #667085;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

.detail-value {
  min-width: 0;
  color: #344054;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.detail-primary .detail-value {
  color: var(--muted);
}

.history-toggle {
  margin-top: 1px;
}

.history-toggle summary {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid #cbd7ef;
  border-radius: 5px;
  background: #f6f9ff;
  color: var(--blue);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  list-style: none;
}

.history-toggle summary::-webkit-details-marker {
  display: none;
}

.history-toggle summary::before {
  content: "+";
  width: 12px;
  margin-right: 4px;
  font-weight: 800;
}

.history-toggle[open] summary::before {
  content: "-";
}

.history-list {
  margin: 7px 0 0;
  padding-left: 22px;
  color: var(--muted);
}

.history-list li {
  margin: 4px 0;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  max-width: 100%;
  padding: 4px 9px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-weight: 700;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.status-normal {
  background: #eaf7f1;
  border-color: #a7dfc7;
  color: var(--green);
}

.status-hold {
  background: #fff4df;
  border-color: #e7c178;
  color: var(--amber);
}

.status-not_found {
  background: #f3f5f8;
  border-color: #c9d1dc;
  color: #4a5568;
}

.status-error,
.status-unknown {
  background: #fff1f0;
  border-color: #f1aaa4;
  color: var(--red);
}

.official a,
.official button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--blue);
  text-decoration: none;
  font-weight: 700;
  white-space: nowrap;
}

.official a:hover,
.official button:hover {
  border-color: var(--blue);
}

.empty-row td {
  height: 140px;
  color: var(--muted);
  text-align: center;
  vertical-align: middle;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  max-width: min(420px, calc(100vw - 36px));
  padding: 10px 14px;
  border-radius: 8px;
  background: #252b36;
  color: #fff;
  box-shadow: var(--shadow);
}

@media (max-width: 980px) {
  .input-panel {
    grid-template-columns: 1fr;
    grid-template-areas:
      "heading"
      "textarea"
      "controls";
  }

  .summary-panel {
    grid-template-columns: repeat(3, minmax(86px, 1fr));
  }
}

@media (max-width: 680px) {
  .app-shell {
    width: min(100vw - 20px, 1480px);
  }

  .header-inner {
    align-items: flex-start;
    flex-direction: column;
    padding: 12px 0;
  }

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

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

  .table-wrap {
    max-height: none;
    min-height: 320px;
  }

  .summary-item {
    border-bottom: 1px solid var(--line);
  }

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

  .result-actions {
    justify-content: stretch;
  }

  input[type="search"] {
    width: 100%;
    flex: 1 1 100%;
  }

  .result-actions .secondary-button {
    flex: 1;
  }
}
