:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --line: #d6dde2;
  --text: #182026;
  --muted: #60717d;
  --accent: #126d8f;
  --accent-dark: #0d526c;
  --danger: #b33a3a;
  --warn: #8a6400;
  --ok: #237348;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

button,
input {
  font: inherit;
}

.topbar {
  min-height: 72px;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 1.25rem;
  font-weight: 650;
}

h2 {
  font-size: 1rem;
  font-weight: 650;
}

.topbar p,
.muted {
  color: var(--muted);
  font-size: 0.86rem;
}

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

.connection-statuses {
  flex: 1 1 520px;
  min-width: 320px;
  max-width: 760px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.connection-status {
  min-height: 44px;
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  background: #f7fafb;
  color: var(--muted);
  font-size: 0.8rem;
}

.connection-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--muted);
}

.connection-status strong,
.connection-status span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.connection-status strong {
  color: var(--text);
  font-size: 0.84rem;
}

.connection-status.ok {
  color: var(--ok);
  border-color: #a7d2bb;
  background: #eef8f2;
}

.connection-status.ok .connection-status-dot {
  background: var(--ok);
}

.connection-status.warning,
.connection-status.checking {
  color: var(--warn);
  border-color: #dfcb88;
  background: #fff8df;
}

.connection-status.warning .connection-status-dot,
.connection-status.checking .connection-status-dot {
  background: var(--warn);
}

.connection-status.error {
  color: var(--danger);
  border-color: #e1adad;
  background: #fff0f0;
}

.connection-status.error .connection-status-dot {
  background: var(--danger);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(360px, 0.75fr);
  gap: 16px;
  padding: 16px;
}

.list-pane,
.editor-pane {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.section-head {
  min-height: 54px;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}

.section-head input[type="search"] {
  width: min(420px, 52vw);
}

.operation-result {
  margin: 10px 12px 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--muted);
  background: #f7fafb;
  font-size: 0.84rem;
}

.operation-result strong {
  display: block;
  margin-bottom: 5px;
  color: var(--text);
}

.operation-result ul {
  margin: 0;
  padding-left: 18px;
}

.operation-result li + li {
  margin-top: 3px;
}

.merge-candidate {
  margin-top: 8px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  color: var(--text);
}

.merge-candidate span {
  overflow-wrap: anywhere;
}

.operation-result.success {
  color: var(--ok);
  border-color: #a7d2bb;
  background: #eef8f2;
}

.operation-result.warning,
.operation-result.notice {
  color: var(--warn);
  border-color: #dfcb88;
  background: #fff8df;
}

.operation-result.error {
  color: var(--danger);
  border-color: #e1adad;
  background: #fff0f0;
}

.udp-alert-banner {
  margin: 10px 12px 0;
  border: 1px solid #dfcb88;
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--warn);
  background: #fff8df;
  font-size: 0.84rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.udp-alert-banner[hidden] {
  display: none;
}

.udp-alert-banner button {
  flex-shrink: 0;
}

input {
  width: 100%;
  min-height: 36px;
  border: 1px solid #c4cdd3;
  border-radius: 6px;
  padding: 7px 9px;
  background: #fff;
}

input:focus {
  border-color: var(--accent);
  outline: 2px solid color-mix(in srgb, var(--accent) 22%, transparent);
}

input.hamlog-filled {
  border-color: #6da8bb;
  background: #edf8fb;
}

input.hamlog-filled:focus {
  border-color: #247d99;
  outline-color: color-mix(in srgb, #247d99 28%, transparent);
}

input.frequency-out-of-band {
  border-color: var(--danger);
  background: #fff0f0;
}

input.frequency-out-of-band:focus {
  border-color: var(--danger);
  outline-color: color-mix(in srgb, var(--danger) 26%, transparent);
}

.field-warning {
  display: none;
  color: var(--warn);
  font-size: 0.78rem;
  line-height: 1.35;
}

.field-warning.visible {
  display: block;
}

button {
  min-height: 36px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 7px 12px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
}

button:hover {
  background: var(--accent-dark);
}

button.secondary {
  color: var(--accent);
  background: #fff;
}

button.danger-outline {
  color: var(--danger);
  border-color: #dca0a0;
  background: #fff;
}

button.row-action {
  min-height: 28px;
  padding: 4px 8px;
  font-size: 0.78rem;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 160px);
}

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

th,
td {
  padding: 9px 10px;
  border-bottom: 1px solid #edf1f3;
  text-align: left;
  vertical-align: top;
  font-size: 0.9rem;
}

th {
  position: sticky;
  top: 0;
  background: #eef3f5;
  z-index: 1;
  color: #30434f;
  font-weight: 650;
}

td {
  overflow-wrap: anywhere;
}

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

tr:hover td {
  background: #f9fbfc;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  border: 1px solid var(--line);
  color: var(--muted);
  background: #f6f8f9;
}

.status.synced {
  color: var(--ok);
  border-color: #a7d2bb;
  background: #eef8f2;
}

.status.pending,
.status.leased,
.status.unknown,
.status.message-sent {
  color: var(--warn);
  border-color: #dfcb88;
  background: #fff8df;
}

.status.failed {
  color: var(--danger);
  border-color: #e1adad;
  background: #fff0f0;
}

/* ADIF自動書き戻しの重複確認待ち。人間の確認（近似候補マージ or HAMLOGへ登録）
   が必要なことが分かるよう、warning系より一段強い配色にする。 */
.status.merge-review {
  color: #8a4b00;
  border-color: #e8bd7d;
  background: #fff3e0;
}

.qsl-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.qsl-badge {
  display: inline-flex;
  align-items: center;
  min-height: 23px;
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f6f8f9;
  color: var(--muted);
  font-size: 0.76rem;
  white-space: nowrap;
}

.qsl-badge.hqsl.eligible {
  color: var(--ok);
  border-color: #a7d2bb;
  background: #eef8f2;
}

.qsl-badge.hqsl.candidate,
.qsl-badge.hqsl.unknown {
  color: var(--warn);
  border-color: #dfcb88;
  background: #fff8df;
}

.qsl-badge.hqsl.not-registered {
  color: var(--danger);
  border-color: #e1adad;
  background: #fff0f0;
}

.lookup-status {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
  color: var(--muted);
  background: #f7fafb;
  font-size: 0.84rem;
}

.lookup-status.loading,
.lookup-status.pending,
.lookup-status.leased {
  color: var(--warn);
  border-color: #dfcb88;
  background: #fff8df;
}

.lookup-status.ready {
  color: var(--ok);
  border-color: #a7d2bb;
  background: #eef8f2;
}

.lookup-status.failed {
  color: var(--danger);
  border-color: #e1adad;
  background: #fff0f0;
}

form {
  padding: 12px;
  display: grid;
  gap: 10px;
}

label {
  display: grid;
  gap: 4px;
  color: #374b57;
  font-size: 0.84rem;
}

.two,
.three {
  display: grid;
  gap: 10px;
}

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

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

.check {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check input {
  width: 18px;
  min-height: 18px;
}

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

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 560px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .connection-statuses {
    min-width: 0;
    width: 100%;
    max-width: none;
    grid-template-columns: 1fr;
  }

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

  .section-head input[type="search"] {
    width: 100%;
  }

  .two,
  .three {
    grid-template-columns: 1fr;
  }
}

.pairing-dialog {
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  box-shadow: 0 12px 40px rgb(15 23 42 / 25%);
  max-width: 460px;
  padding: 20px 24px;
}

.pairing-dialog::backdrop {
  background: rgb(15 23 42 / 45%);
}

.pairing-dialog h2 {
  margin-top: 0;
}

.pairing-code {
  background: #0f172a;
  border-radius: 8px;
  color: #f8fafc;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 1.25rem;
  letter-spacing: 0.06em;
  margin: 12px 0;
  padding: 14px 16px;
  text-align: center;
  user-select: all;
  word-break: break-all;
}

.pairing-steps {
  margin: 12px 0;
  padding-left: 20px;
}

.pairing-steps li {
  margin-bottom: 6px;
}

.pairing-dialog .actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

.conflict-dialog {
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  box-shadow: 0 12px 40px rgb(15 23 42 / 25%);
  max-width: 720px;
  padding: 20px 24px;
}

.conflict-dialog::backdrop {
  background: rgb(15 23 42 / 45%);
}

.conflict-dialog h2 {
  margin-top: 0;
}

.conflict-table-wrap {
  max-height: 52vh;
  overflow: auto;
}

.conflict-table {
  border-collapse: collapse;
  font-size: 0.9rem;
  width: 100%;
}

.conflict-table th,
.conflict-table td {
  border: 0.5px solid #e2e8f0;
  padding: 4px 8px;
  text-align: left;
  vertical-align: top;
  word-break: break-word;
}

.conflict-table thead th {
  background: #f1f5f9;
  position: sticky;
  top: 0;
}

.conflict-field {
  font-weight: 500;
  white-space: nowrap;
}

.conflict-table tr.conflict-diff td {
  background: #fef3c7;
}

/* 再照合比較ダイアログ: 行の薄い強調に加え、クラウド側と実際に異なる
   候補セルだけを濃く強調して、どの欄が違うか一目で分かるようにする。 */
.conflict-table td.reconcile-diff-cell {
  background: #fde68a;
  font-weight: 600;
}

.reconcile-merge-note {
  margin: 6px 0 0;
  font-size: 0.8rem;
  max-width: 240px;
}

.settings-section-title {
  font-size: 0.95rem;
  font-weight: 650;
  margin: 0 0 6px;
}

#settingsDatabases select,
#settingsDatabases input[type="checkbox"] {
  cursor: pointer;
}

/* マージ方式のselectはネイティブ表示幅が最長の選択肢に合わせて広がり、
   ダイアログ幅（.conflict-dialogのmax-width: 720px）を超えて隣の保存ボタンを
   押し出してしまう。閉じた状態の表示幅を抑え、はみ出す分は省略表示にする。
   フルテキストはtitle属性のツールチップで確認できる。 */
#settingsDatabases select {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* HDBのlocalDatabaseKeyはハッシュ由来の長い連続文字列で、空白を含まないため
   通常のword-breakでは折り返せない。break-allで強制的に折り返し、列幅も
   抑えて他の列（件数・最終確認・設定）と重ならないようにする。 */
.settings-db-key {
  font-weight: 500;
  word-break: break-all;
  max-width: 160px;
}

/* 一覧見出しの「？」ヘルプ。操作ボタンの使い分けダイアログを開く。 */
.help-button {
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 650;
  line-height: 1;
  cursor: pointer;
  vertical-align: middle;
}

.help-button:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--panel);
}

.conflict-radio {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-right: 8px;
}

.conflict-dialog .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

.login-gate {
  align-items: center;
  background: #f8fafc;
  display: flex;
  inset: 0;
  justify-content: center;
  min-height: 100vh;
  position: fixed;
}

/* [hidden]の詳細度は.login-gate単体と同点のためCSS適用順で負ける。
   .login-gate[hidden]で詳細度を上げてdisplay:noneを確実に勝たせる。 */
.login-gate[hidden] {
  display: none;
}

.login-gate-card {
  background: #fff;
  border: 0.5px solid #cbd5e1;
  border-radius: 12px;
  box-shadow: 0 12px 40px rgb(15 23 42 / 15%);
  max-width: 360px;
  padding: 32px;
  text-align: center;
}

.login-gate-card h1 {
  margin-top: 0;
}

.login-button {
  background: #1d4ed8;
  border-radius: 8px;
  color: #fff;
  display: inline-block;
  font-weight: 500;
  margin: 16px 0;
  padding: 10px 20px;
  text-decoration: none;
}

.login-button:hover {
  background: #1e40af;
}

.session-email {
  align-self: center;
  color: #475569;
  font-size: 0.85rem;
  margin-right: 8px;
}
