html {
  box-sizing: border-box;
}

*,
*::before,
*::after {
  box-sizing: inherit;
}

:root {
  --bg-page: #eef2f7;
  --bg-card: #ffffff;
  --accent: #1565a3;
  --accent-hover: #0d4d7d;
  --accent-soft: #e3eef6;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #c5d0dc;
  --border-light: #e2e8f0;
  --success: #166534;
  --error: #b91c1c;
  --radius: 10px;
  --shadow-soft: 0 2px 12px rgba(21, 101, 163, 0.08);
}

body {
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--text);
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 16px 24px 32px;
  min-height: 100vh;
  background: var(--bg-page);
  background-image: linear-gradient(180deg, #f8fafc 0%, var(--bg-page) 48%, #e8eef5 100%);
}

.page-intro {
  text-align: center;
  max-width: 56rem;
  margin: 0 auto 8px;
  padding: 20px 32px 24px;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  border: 1px solid var(--border-light);
}

.page-intro h1 {
  margin: 0;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: -0.02em;
  font-size: 1.5rem;
}

.page-intro-logo {
  display: block;
  height: 3.5rem;
  width: auto;
  max-width: 10rem;
  object-fit: contain;
  justify-self: start;
}

.page-intro .form-row {
  justify-content: center;
}

.page-intro-header-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  column-gap: 16px;
  row-gap: 12px;
  margin-bottom: 8px;
  text-align: left;
}

.page-intro-header-row h1 {
  justify-self: center;
  text-align: center;
}

.page-intro-header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  justify-self: end;
  flex-wrap: wrap;
}

.lang-select {
  padding: 6px 10px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-hover);
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  cursor: pointer;
  max-width: 9rem;
}

.lang-select:hover,
.lang-select:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.login-lang-row {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.btn-logout {
  flex-shrink: 0;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-hover);
  background: var(--accent-soft);
  border: 1px solid var(--border-light);
}

.btn-logout:hover {
  background: #dbeafe;
  color: var(--accent);
}

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.login-card {
  width: 100%;
  max-width: 22rem;
  padding: 28px 24px 32px;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  border: 1px solid var(--border-light);
  text-align: center;
}

.login-title {
  margin: 0 0 8px;
  font-size: 1.35rem;
  color: var(--accent);
  font-weight: 700;
}

.login-hint {
  margin: 0 0 20px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.login-form {
  text-align: left;
}

.login-field {
  flex-direction: column;
  align-items: stretch;
  margin: 12px 0;
}

.login-field label {
  margin-bottom: 4px;
}

.login-field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
}

.login-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.login-msg {
  margin: 8px 0 12px;
  min-height: 1.25em;
}

.login-submit {
  width: 100%;
  margin-top: 8px;
}

.hidden {
  display: none !important;
}

.login-mfa-hint {
  margin-bottom: 12px;
  text-align: center;
}

.login-back {
  width: 100%;
  margin-top: 10px;
  color: var(--accent-hover);
  background: var(--accent-soft);
  border: 1px solid var(--border-light);
}

.login-back:hover {
  background: #dbeafe;
  color: var(--accent);
}

h1 {
  font-size: 1.25rem;
}

.hint {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 16px 0;
}

label {
  font-weight: 600;
  color: var(--text);
}

.bridge-mac-combobox {
  position: relative;
  flex: 1 1 220px;
  min-width: 220px;
  max-width: 28rem;
}

#bridgeMac {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  box-sizing: border-box;
}

.bridge-mac-suggestions {
  position: absolute;
  z-index: 20;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  margin: 0;
  padding: 4px 0;
  list-style: none;
  max-height: 240px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow-soft);
}

.bridge-mac-suggestions li {
  margin: 0;
  padding: 0;
}

.bridge-mac-suggestion-btn {
  display: block;
  width: 100%;
  padding: 8px 12px;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  box-sizing: border-box;
}

.bridge-mac-suggestion-btn:hover,
.bridge-mac-suggestion-btn.is-active {
  background: var(--accent-soft);
  color: var(--accent-hover);
}

#bridgeMac:hover {
  border-color: #94a3b8;
}

#bridgeMac:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

button {
  padding: 10px 20px;
  cursor: pointer;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 6px;
  transition: background 0.15s ease, transform 0.05s ease;
}

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

button:active {
  transform: translateY(1px);
}

.msg {
  min-height: 1.5em;
  text-align: center;
}

.msg.error {
  color: var(--error);
  font-weight: 500;
}

.msg.ok {
  color: var(--success);
  font-weight: 500;
}

.results.hidden {
  display: none;
}

section {
  margin-top: 24px;
}

section h2 {
  font-size: 1.05rem;
  color: var(--accent);
  font-weight: 700;
  border-bottom: 2px solid var(--accent-soft);
  padding-bottom: 6px;
}

dl {
  display: grid;
  grid-template-columns: minmax(140px, 260px) minmax(0, 1fr);
  gap: 6px 16px;
  margin: 12px 0;
  width: 100%;
}

dt {
  font-weight: 600;
  color: var(--text-muted);
}

dd {
  margin: 0;
  word-break: break-word;
  color: var(--text);
}

.actuator-block {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}

.empty-note {
  color: var(--text-muted);
  font-style: italic;
}

.support-extra-section {
  margin-top: 28px;
  padding-top: 16px;
  border-top: 2px solid var(--accent-soft);
}

.commands-section {
  margin-top: 28px;
  padding-top: 16px;
  border-top: 2px solid var(--accent-soft);
}

.commands-section-banner {
  margin: 0 0 12px;
  font-size: 1.125rem;
  font-weight: 600;
}

.section-title-row {
  margin: 0 0 12px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--accent-soft);
}

.section-title-group {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.section-title-row h2 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--accent);
  font-weight: 700;
}

.commands-section-title-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.section-info-btn {
  -webkit-appearance: none;
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 1.35rem;
  height: 1.35rem;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg-card);
  color: var(--accent);
  cursor: pointer;
  box-shadow: none;
  line-height: 0;
}

.section-info-btn .section-info-icon-svg {
  width: 0.8rem;
  height: 0.8rem;
}

.section-info-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-hover);
}

.section-info-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.commands-section-toggle {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 8px;
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  box-sizing: border-box;
}

.commands-section-toggle:hover {
  border-color: var(--accent-soft);
  background: linear-gradient(180deg, var(--accent-soft) 0%, var(--bg-card) 140%);
}

.commands-section-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.commands-section-toggle-label {
  font-weight: 600;
}

.commands-section-toggle-meta {
  flex: 0 0 auto;
  font-weight: normal;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.commands-section-chevron {
  margin-left: auto;
  flex-shrink: 0;
  font-size: 0.75rem;
  line-height: 1;
  color: var(--text-muted);
  width: 1.25rem;
  text-align: center;
}

.commands-section-is-collapsed .commands-section-toggle {
  opacity: 0.98;
}

.commands-section-body[hidden] {
  display: none !important;
}

.commands-section-body-empty {
  min-height: 0;
}

.commands-section-empty-msg {
  margin: 12px 0 0;
}

.commands-cap {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin: 8px 0 16px;
}

.commands-pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  margin-bottom: 16px;
}

.commands-page-btn {
  -webkit-appearance: none;
  appearance: none;
  padding: 0.45rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  font: inherit;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.commands-page-btn:hover:not(:disabled) {
  border-color: var(--accent-hover);
  background: var(--accent-soft);
}

.commands-page-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.commands-page-numbers {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.commands-page-num {
  min-width: 2.25rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border-light);
  border-radius: 4px;
  background: var(--bg-card);
  font: inherit;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text);
  cursor: pointer;
  line-height: 1.2;
}

.commands-page-num:hover:not(.is-current) {
  border-color: var(--accent-hover);
}

.commands-page-num.is-current {
  font-weight: 700;
  border-color: var(--accent-hover);
  background: linear-gradient(180deg, var(--accent-soft) 0%, #dbeafe 100%);
  color: var(--accent-hover);
  cursor: default;
}

.commands-page-summary {
  font-size: 0.88rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.commands-table-mount {
  min-width: 0;
}

.commands-table-wrap {
  overflow-x: auto;
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  box-shadow: var(--shadow-soft);
}

.commands-table {
  width: max(100%, max-content);
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  table-layout: auto;
}

.commands-table th,
.commands-table td {
  border: 1px solid var(--border-light);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

.commands-table thead th {
  background: linear-gradient(180deg, var(--accent-soft) 0%, #dbeafe 100%);
  color: var(--accent-hover);
  font-weight: 600;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}

.commands-table tbody tr:nth-child(even) {
  background: #f8fafc;
}

.commands-table tbody tr:hover {
  background: #f0f7fc;
}

.commands-table td {
  word-break: break-word;
}

/* Matter-only bridge info (no row in bridge table) */
.matter-only-bridge {
  margin-top: 16px;
}

.matter-only-payload-dd {
  word-break: break-word;
  font-size: 0.9rem;
}

.matter-only-qr-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  margin-top: 4px;
}

.matter-only-qr-item {
  text-align: center;
}

.matter-only-qr-graphic {
  line-height: 0;
}

.matter-only-qr-graphic img,
.matter-only-qr-graphic canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Bridge section — QR row (last): graphic + download beside it */
.bridge-qr-dd {
  min-width: 0;
}

.bridge-qr-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.bridge-qr-toolbar {
  display: flex;
  align-items: flex-start;
  flex-shrink: 0;
}

.bridge-qr-download-btn {
  -webkit-appearance: none;
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0.4rem 0.55rem;
  border: 1px solid #f59e0b;
  border-radius: 6px;
  background: #fffbeb;
  color: #b45309;
  cursor: pointer;
  line-height: 0;
  box-sizing: border-box;
  font: inherit;
}

.bridge-qr-download-btn:hover:not(:disabled) {
  background: #fef3c7;
  border-color: #d97706;
}

.bridge-qr-download-btn:active:not(:disabled) {
  background: #fde68a;
}

.bridge-qr-download-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.bridge-qr-download-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.bridge-qr-download-icon {
  flex-shrink: 0;
  display: block;
  color: inherit;
}

.bridge-qr-graphic {
  line-height: 0;
}

.bridge-qr-graphic img,
.bridge-qr-graphic canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Section info modal */
body.section-info-modal-open {
  overflow: hidden;
}

.section-info-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.45);
}

.section-info-modal.hidden {
  display: none !important;
}

.section-info-modal-dialog {
  width: min(100%, 72rem);
  max-height: min(90vh, 40rem);
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.2);
}

.section-info-modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-light);
}

.section-info-modal-title {
  margin: 0;
  flex: 1;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
}

.section-info-modal-close {
  -webkit-appearance: none;
  appearance: none;
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.section-info-modal-close:hover {
  background: var(--accent-soft);
  color: var(--accent-hover);
}

.section-info-modal-body {
  padding: 0;
  overflow: auto;
}

.section-info-table-wrap {
  overflow-x: auto;
}

.section-info-table {
  width: 100%;
  min-width: 52rem;
  border-collapse: collapse;
  font-size: 0.85rem;
  line-height: 1.45;
}

.section-info-table th,
.section-info-table td {
  border: 1px solid var(--border-light);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

.section-info-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--accent-soft);
  color: var(--accent-hover);
  font-weight: 600;
  font-size: 0.8rem;
  white-space: nowrap;
}

.section-info-table tbody tr:nth-child(even) {
  background: #f8fafc;
}

.section-info-table .section-info-th-category,
.section-info-table .section-info-td-category {
  min-width: 9rem;
  max-width: 11rem;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.section-info-table .section-info-th-code,
.section-info-table .section-info-td-code {
  min-width: 10rem;
  white-space: nowrap;
  font-weight: 600;
  color: var(--accent-hover);
}

.section-info-table .section-info-td-meaning {
  min-width: 11rem;
}

.section-info-table .section-info-td-symptom,
.section-info-table .section-info-td-actions {
  min-width: 10rem;
}

/* --- Responsive --- */

@media (max-width: 720px) {
  body {
    padding: 12px 12px 24px;
  }

  .page-intro {
    width: 100%;
    padding: 16px 16px 20px;
  }

  .page-intro-header-row {
    grid-template-columns: auto 1fr;
    grid-template-areas:
      'logo logout'
      'title title';
    column-gap: 12px;
  }

  .page-intro-header-row .page-intro-logo {
    grid-area: logo;
    height: 2.75rem;
    max-width: 8rem;
  }

  .page-intro-header-row h1 {
    grid-area: title;
    justify-self: stretch;
    text-align: center;
    font-size: 1.2rem;
    margin-top: 4px;
  }

  .page-intro-header-row .page-intro-header-actions {
    grid-area: logout;
    justify-self: end;
    align-self: center;
  }

  .page-intro .form-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-top: 12px;
  }

  .page-intro .form-row label {
    text-align: left;
  }

  .bridge-mac-combobox {
    flex: 1 1 auto;
    min-width: 0;
    max-width: none;
    width: 100%;
  }

  .page-intro .form-row button {
    width: 100%;
  }

  dl {
    grid-template-columns: 1fr;
    gap: 2px 0;
  }

  dl dt {
    margin-top: 8px;
  }

  dl dt:first-of-type {
    margin-top: 0;
  }

  .commands-page-summary {
    white-space: normal;
  }
}

@media (max-width: 480px) {
  body {
    padding: 10px 10px 20px;
  }

  .page-intro {
    padding: 14px 12px 18px;
    border-radius: 8px;
  }

  .page-intro-header-row h1 {
    font-size: 1.05rem;
    line-height: 1.3;
  }

  .page-intro-header-row .page-intro-logo {
    height: 2.35rem;
    max-width: 6.5rem;
  }

  .page-intro-header-row .btn-logout {
    padding: 6px 10px;
    font-size: 0.78rem;
  }

  #bridgeMac {
    font-size: 16px;
  }

  .commands-section-toggle {
    padding: 8px 10px;
    gap: 6px;
  }

  .commands-section-toggle-meta {
    flex: 1 1 100%;
  }

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

  .commands-page-numbers {
    justify-content: center;
  }

  .commands-page-summary {
    text-align: center;
  }

  .bridge-qr-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .section-info-modal {
    padding: 10px;
    align-items: flex-end;
  }

  .section-info-modal-dialog {
    width: 100%;
    max-height: 92vh;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
  }

  .section-info-table {
    min-width: 40rem;
    font-size: 0.8rem;
  }

  .section-info-table thead th {
    white-space: normal;
  }
}
