/* 共通コンポーネント: ボタン・フォーム・バッジ・カード・表・ダイアログ・タブ */

/* ── ボタン ─────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 6px 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  line-height: 1.3;
}
.btn:hover:not(:disabled):not([aria-disabled="true"]) { background: var(--surface-2); border-color: var(--text-muted); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-on); }
.btn--primary:hover:not(:disabled):not([aria-disabled="true"]) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn--danger { background: var(--danger-fg); border-color: var(--danger-fg); color: var(--surface); }
.btn--danger:hover:not(:disabled) { filter: brightness(1.1); background: var(--danger-fg); }
.btn--ghost { border-color: transparent; background: transparent; }
.btn--sm { min-height: 32px; padding: 2px 10px; font-size: 0.85rem; }
.btn:disabled, .btn[aria-disabled="true"] {
  cursor: not-allowed; opacity: 1;
  background: var(--neutral-bg); color: var(--text-muted); border-color: var(--border);
}

/* ── フォーム ─────────────────────────── */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label, .field > .label, fieldset > legend { font-weight: 700; font-size: 0.9rem; }
.field .hint, .hint { color: var(--text-muted); font-size: 0.82rem; }
.field .req { color: var(--danger-fg); margin-left: 2px; }
input[type="text"], input[type="search"], input[type="password"], input[type="date"],
input[type="datetime-local"], select, textarea {
  width: 100%;
  min-height: 40px;
  padding: 6px 10px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}
textarea { min-height: 120px; resize: vertical; line-height: 1.6; }
input:disabled, select:disabled, textarea:disabled { background: var(--neutral-bg); color: var(--text-muted); }
[aria-invalid="true"] { border-color: var(--danger-fg); box-shadow: 0 0 0 1px var(--danger-fg); }
.error-text { color: var(--danger-fg); font-weight: 600; font-size: 0.88rem; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin: 0; min-width: 0; }
fieldset > legend { padding: 0 6px; }
.filters {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr));
  align-items: end;
}
.filters--top { align-items: start; }
.filters__actions { display: flex; gap: 8px; flex-wrap: wrap; }
.counter { text-align: right; font-size: 0.82rem; color: var(--text-muted); }
.counter[data-state="warn"] { color: var(--warn-fg); font-weight: 700; }
.counter[data-state="over"] { color: var(--danger-fg); font-weight: 700; }
.choice { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; cursor: pointer; }
.choice input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }

/* ── バッジ（色だけに依存しない: 記号 + 文言） ───────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 9px; border-radius: 999px;
  border: 1px solid var(--neutral-bd);
  background: var(--neutral-bg); color: var(--neutral-fg);
  font-size: 0.8rem; font-weight: 700; line-height: 1.6; white-space: nowrap;
}
.badge__icon { font-weight: 800; }
.badge--ok { background: var(--ok-bg); color: var(--ok-fg); border-color: var(--ok-bd); }
.badge--danger { background: var(--danger-bg); color: var(--danger-fg); border-color: var(--danger-bd); }
.badge--warn { background: var(--warn-bg); color: var(--warn-fg); border-color: var(--warn-bd); }
.badge--info { background: var(--info-bg); color: var(--info-fg); border-color: var(--info-bd); }
.badge--outline { background: transparent; }
.chip {
  display: inline-flex; align-items: center; min-height: 36px; padding: 4px 12px;
  border: 1px solid var(--border-strong); border-radius: 999px;
  background: var(--surface); color: var(--text); cursor: pointer; text-align: left;
  font-size: 0.88rem;
}
.chip:hover { background: var(--accent-soft); }
.code-chip {
  display: inline-block; padding: 0 8px; border-radius: 4px;
  background: var(--neutral-bg); color: var(--neutral-fg); border: 1px solid var(--neutral-bd);
  font-family: var(--mono); font-size: 0.78rem; margin: 1px 4px 1px 0;
}

/* ── カード・通知 ─────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card--flat { box-shadow: none; background: var(--surface-2); }
.notice {
  display: flex; gap: 10px; align-items: flex-start;
  border: 1px solid var(--info-bd); background: var(--info-bg); color: var(--info-fg);
  border-radius: var(--radius); padding: 10px 14px;
}
.notice > .notice__icon { font-weight: 800; flex: none; }
.notice__body { min-width: 0; }
.notice__body p:last-child { margin-bottom: 0; }
.notice--ok { border-color: var(--ok-bd); background: var(--ok-bg); color: var(--ok-fg); }
.notice--danger { border-color: var(--danger-bd); background: var(--danger-bg); color: var(--danger-fg); }
.notice--warn { border-color: var(--warn-bd); background: var(--warn-bg); color: var(--warn-fg); }
.notice--neutral { border-color: var(--neutral-bd); background: var(--neutral-bg); color: var(--neutral-fg); }
.notice strong { color: inherit; }

.state {
  text-align: center; padding: 36px 16px; color: var(--text-muted);
  border: 1px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface);
}
.state h2, .state h3 { color: var(--text); margin-bottom: 6px; }
.state .btn { margin-top: 8px; }
.loading { display: flex; align-items: center; gap: 10px; padding: 24px 8px; color: var(--text-muted); }
.spinner {
  width: 18px; height: 18px; border-radius: 50%; flex: none;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 表（狭い画面ではカード表示） ─────────────────────────── */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.table { width: 100%; font-size: 0.88rem; }
.table caption { text-align: left; padding: 10px 12px; font-weight: 700; color: var(--text-muted); caption-side: top; }
.table th, .table td { padding: 8px 12px; text-align: left; vertical-align: top; border-top: 1px solid var(--border); }
.table thead th { background: var(--surface-2); font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; border-top: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table .q-cell { max-width: 34ch; }
.table .mono-cell { font-family: var(--mono); font-size: 0.8rem; }

@media (min-width: 761px) {
  .table td.nowrap { white-space: nowrap; }
}

@media (max-width: 760px) {
  .table--cards, .table--cards tbody, .table--cards tr, .table--cards td { display: block; width: 100%; }
  .table--cards thead {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
  .table--cards caption { display: block; }
  .table--cards tr { border-top: 1px solid var(--border); padding: 10px 12px; }
  .table--cards tbody tr:first-child { border-top: 0; }
  .table--cards td { border: 0; padding: 3px 0; display: grid; grid-template-columns: 7.5em minmax(0, 1fr); gap: 8px; }
  .table--cards td::before { content: attr(data-label); color: var(--text-muted); font-size: 0.78rem; font-weight: 700; }
  .table--cards td.num { text-align: left; }
  .table--cards .q-cell { max-width: none; }
  .table-wrap { overflow-x: visible; }
}

.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; padding: 10px 2px; }
.pager__btns { display: flex; gap: 8px; }

/* ── ダイアログ（<dialog>） ─────────────────────────── */
dialog {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  padding: 0; width: min(560px, calc(100vw - 32px));
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}
dialog::backdrop { background: rgba(10, 14, 20, 0.6); }
.dialog__inner { padding: 20px; }
.dialog__inner h2 { margin-top: 0; }
.dialog__inner > * + * { margin-top: 12px; }
.dialog__inner > .dialog__actions { margin-top: 16px; }
.dialog__summary dd { margin: 0 0 8px; }
.dialog__actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.dialog__summary { margin: 12px 0; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }

/* ── タブ ─────────────────────────── */
.tablist { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 2px solid var(--border); margin-bottom: 16px; }
.tab {
  min-height: 44px; padding: 6px 14px; background: transparent; border: 0;
  border-bottom: 3px solid transparent; margin-bottom: -2px;
  cursor: pointer; color: var(--text-muted); font-weight: 600;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); background: var(--accent-soft); }
[role="tabpanel"]:focus { outline: none; }
@media (max-width: 600px) { .tablist { overflow-x: auto; flex-wrap: nowrap; } .tab { white-space: nowrap; } }

/* ── 説明リスト（key/value） ─────────────────────────── */
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 10px 20px; }
.kv > div { min-width: 0; }
.kv dt { margin-bottom: 1px; }
.kv dd { margin: 0; font-weight: 500; }
.kv--wide { grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }

details > summary { cursor: pointer; font-weight: 600; padding: 4px 0; min-height: 32px; }
details > summary::marker { color: var(--text-muted); }
.details-pre { margin-top: 6px; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); max-height: 260px; overflow: auto; }

/* ── 動作モード（Preview 読取専用）バナー ─────────────────────── */
.mode-banner {
  background: var(--warn-bg); color: var(--warn-fg); border-bottom: 2px solid var(--warn-bd);
  padding: 8px 16px; text-align: center; font-size: 0.9rem;
}
.readonly-reason { margin: 0; padding: 8px 12px; border: 1px dashed var(--warn-bd); border-radius: var(--radius-sm); background: var(--warn-bg); color: var(--warn-fg); font-size: 0.88rem; }
