:root {
  color-scheme: light;
  --color-text: #1a1a1a;
  --color-text-secondary: #4d4d4d;
  --color-text-placeholder: #767676;
  --color-border: #949494;
  --color-border-light: #d8d8d8;
  --color-surface-subtle: #f7f7f7;
  --color-primary: #0017c1;
  --color-primary-hover: #000082;
  --color-primary-active: #000060;
  --color-success: #197a4b;
  --color-error: #b4000f;
  --focus-ring: #000;
  --radius-small: 4px;
  --radius-medium: 8px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--color-text);
  background: #fff;
  font-family: "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { cursor: pointer; }

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  padding: 8px 12px;
  color: #fff;
  background: var(--color-primary);
  transform: translateY(-150%);
}

.skip-link:focus { transform: translateY(0); }

:where(button, input, a):focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 3px;
}

main {
  width: min(1200px, calc(100% - 48px));
  margin: 0 auto;
  padding: 32px 0 64px;
}

.search-panel {
  padding: 24px;
}

.panel-heading,
.form-footer,
.results-heading,
.result-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  padding: 2px 10px;
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border-light);
  border-radius: 999px;
  font-size: 14px;
  line-height: 1.5;
}

.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #767676;
}

.status.online .status-dot { background: var(--color-success); }
.status.offline .status-dot { background: var(--color-error); }

.text-button,
.sheet-link {
  color: var(--color-primary);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.text-button {
  min-height: 44px;
  padding: 8px;
  border: 0;
  background: transparent;
}

.text-button:hover,
.sheet-link:hover { text-decoration-thickness: 3px; }

.field-grid { display: grid; gap: 20px; }
.primary-fields { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 24px; }
.detail-fields { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-top: 24px; }
.field { display: grid; gap: 8px; min-width: 0; }

.field-label {
  color: var(--color-text);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.5;
}

input {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  color: var(--color-text);
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-small);
  outline: none;
}

input:hover { border-color: var(--color-text); }
input:focus { border-color: var(--color-text); box-shadow: inset 0 0 0 1px var(--color-text); }
input::placeholder { color: var(--color-text-placeholder); opacity: 1; }
.form-footer { margin-top: 28px; }

.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  color: var(--color-text);
  cursor: pointer;
}

.toggle-label input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.toggle {
  position: relative;
  width: 44px;
  height: 26px;
  flex: 0 0 auto;
  border: 2px solid var(--color-border);
  border-radius: 999px;
  background: #fff;
  transition: background-color .15s, border-color .15s;
}

.toggle::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--color-text-secondary);
  transition: transform .15s, background-color .15s;
}

.toggle-label input:checked + .toggle { border-color: var(--color-primary); background: var(--color-primary); }
.toggle-label input:checked + .toggle::after { background: #fff; transform: translateX(18px); }
.toggle-label input:focus-visible + .toggle { outline: 3px solid var(--focus-ring); outline-offset: 3px; }

.primary-button,
.secondary-button {
  min-height: 48px;
  padding: 10px 20px;
  border-radius: var(--radius-small);
  font-weight: 700;
  line-height: 1.4;
  transition: background-color .15s, border-color .15s;
}

.primary-button {
  min-width: 160px;
  color: #fff;
  border: 2px solid var(--color-primary);
  background: var(--color-primary);
}

.primary-button:hover { border-color: var(--color-primary-hover); background: var(--color-primary-hover); }
.primary-button:active { border-color: var(--color-primary-active); background: var(--color-primary-active); }

.secondary-button {
  color: var(--color-primary);
  border: 1px solid var(--color-primary);
  background: #fff;
}

.secondary-button:hover { color: #fff; background: var(--color-primary-hover); }
.primary-button:disabled,
.secondary-button:disabled { color: #767676; border-color: #b3b3b3; background: #e6e6e6; cursor: not-allowed; }

.results-section { padding-top: 32px; }
.results-heading { min-height: 48px; margin-bottom: 12px; }
#result-count { color: var(--color-text); font-weight: 700; }
.sheet-link { display: inline-flex; align-items: center; min-height: 44px; }

.message {
  padding: 16px;
  margin-bottom: 16px;
  color: var(--color-error);
  border-left: 6px solid var(--color-error);
  background: #fff2f3;
}

.message.success { color: #0a5c36; border-left-color: var(--color-success); background: #edf8f2; }

.table-shell {
  border-top: 1px solid var(--color-border-light);
  border-bottom: 1px solid var(--color-border-light);
  overflow: hidden;
}

.empty-state {
  min-height: 240px;
  display: grid;
  place-content: center;
  gap: 4px;
  padding: 32px;
  text-align: center;
}

.empty-state p { margin: 0; }
.empty-title { color: var(--color-text); font-weight: 700; }
.empty-hint { color: var(--color-text-secondary); font-size: 14px; }
.table-scroll { overflow-x: auto; }

table {
  width: 100%;
  min-width: 960px;
  border-collapse: separate;
  border-spacing: 0;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  height: 56px;
  padding: 20px 16px 8px;
  color: #000060;
  background: #fff;
  border-right: 0;
  border-bottom: 3px double var(--color-border-light);
  border-left: 0;
  text-align: left;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.5;
  vertical-align: bottom;
  white-space: nowrap;
}

td {
  padding: 16px;
  border-right: 0;
  border-bottom: 1px solid var(--color-border-light);
  border-left: 0;
  font-size: 14px;
  line-height: 1.6;
  vertical-align: top;
}

tbody tr:hover { background: #f5f8ff; }
tbody tr:last-child td { border-bottom: 0; }
td:first-child { width: 20%; font-weight: 700; }
td:nth-child(2) { width: 35%; }
td:nth-child(3) { width: 21%; }
td:nth-child(4),
td:nth-child(5) { white-space: nowrap; font-variant-numeric: tabular-nums; }
th:nth-child(4),
td:nth-child(4) { text-align: right; }
.load-more-wrap { display: flex; justify-content: center; margin-top: 20px; }

@media (max-width: 900px) {
  main { width: min(100% - 32px, 1200px); padding-top: 24px; }
  .primary-fields { grid-template-columns: 1fr 1fr; }
  .detail-fields { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 600px) {
  main { width: 100%; padding: 0 0 40px; }
  .search-panel { padding: 20px 16px 24px; }
  .primary-fields,
  .detail-fields { grid-template-columns: 1fr; gap: 16px; margin-top: 20px; }
  .form-footer { align-items: stretch; flex-direction: column; }
  .primary-button { width: 100%; }
  .results-section { padding: 24px 16px 0; }
  .results-heading { align-items: flex-start; flex-direction: column; }
  .result-actions { width: 100%; align-items: stretch; }
  .result-actions .secondary-button { flex: 1; }
  .empty-state { min-height: 200px; padding: 24px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
