/*
 * Layout-only stylesheet. Color and typography come from the Homebridge UI:
 * config-ui-x injects its themed stylesheet (Bootstrap 5 plus the user's
 * config-ui-x-<theme> body class, plus `dark-mode` when active) into this
 * iframe, so anything not overridden here follows whichever theme the user
 * picked. The few greys below mirror the host's neutral palette.
 */

:root {
  --rr-muted: #6c757d;
  --rr-border: #dee2e6;
  --rr-surface: #f8f9fa;
}

/* Neutral dark surfaces matching config-ui-x's dark palette (#242424 body,
   #2b2b2b cards, #333 inputs). The --bs-* variables drive the injected
   Bootstrap form controls, including their focus state and select caret. */
body.dark-mode {
  --rr-muted: #9e9e9e;
  --rr-border: #444;
  --rr-surface: #333;
  --bs-body-bg: #333;
  --bs-body-color: #eee;
  --bs-border-color: #444;
  --bs-secondary-bg: #2b2b2b;
  --bs-form-select-bg-img: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23adb5bd' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}

* {
  box-sizing: border-box;
}

/* rr- prefix: Bootstrap's own .container would impose its breakpoint widths. */
.rr-container {
  max-width: 860px;
  margin: 0 auto;
  padding: 4px 2px 12px;
  display: grid;
  gap: 16px;
}

header h1 {
  font-size: 1.3rem;
  font-weight: 600;
  margin: 0 0 4px;
}

.subtitle {
  margin: 0;
  color: var(--rr-muted);
}

.card h2 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0 0 4px;
}

.help {
  color: var(--rr-muted);
  font-size: 0.875rem;
  margin: 8px 0 0;
}

label {
  display: block;
  margin-top: 14px;
  font-size: 0.9rem;
}

label > input,
label > select {
  margin-top: 6px;
}

.field {
  margin-top: 14px;
  font-size: 0.9rem;
}

.field-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

/* --rr-primary is sampled from the injected theme at runtime (index.js). */
input[type="checkbox"] {
  accent-color: var(--rr-primary, auto);
}

.discovered-devices {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.discovered-devices .checkbox {
  margin-top: 0;
  word-break: break-all;
}

.device-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.device-row span {
  word-break: break-all;
}

.device-row select {
  margin-top: 0;
  width: auto;
  min-width: 150px;
}

.skip-device-list {
  display: grid;
  gap: 10px;
  margin-top: 8px;
}

/* Second line inside a device row: the Matter scene-button toggle. */
.device-error {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
}

.device-error[hidden] {
  display: none;
}

.scene-toggle {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-size: 0.85rem;
  color: var(--rr-muted);
}

.scene-toggle input[type="checkbox"] {
  margin: 0;
  width: auto;
}

.pairing-panel {
  display: flex;
  gap: 16px;
  align-items: center;
  margin: 6px 0 10px;
  padding: 12px;
  border: 1px solid var(--rr-border);
  border-radius: 8px;
  background: var(--rr-surface);
}

/* QR codes keep a white quiet zone so they stay scannable in dark mode. */
.pairing-qr svg {
  display: block;
  width: 132px;
  height: 132px;
  padding: 6px;
  border-radius: 8px;
  background: #ffffff;
}

.pairing-info {
  display: grid;
  gap: 4px;
}

.pairing-info p {
  margin: 0;
}

.pairing-code {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 1.15rem;
  letter-spacing: 0.08em;
}

.skip-device-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 8px;
  align-items: center;
}

.skip-device-row input {
  margin-top: 0;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
}

.checkbox input {
  width: auto;
  margin: 0;
}

/* !important: the injected sheet loads after this one, so Bootstrap's
   .btn { display: inline-block } would otherwise win the tie. */
.hidden {
  display: none !important;
}

.readonly input,
.readonly select {
  opacity: 0.7;
  cursor: not-allowed;
}

.actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 20px;
}

/* Compact +/- buttons; the injected theme colors their hover state. */
.icon-button {
  width: 38px;
  min-width: 38px;
  height: 38px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  line-height: 1;
  border: 1px solid var(--rr-border);
  border-radius: 0.375rem;
  background-color: transparent;
  color: inherit;
  cursor: pointer;
}

.icon-button.remove {
  color: #dc3545;
}

body.dark-mode .icon-button.remove {
  color: #f28b94;
}

/* Fallback toasts, shown only when window.homebridge.toast is unavailable.
   rr- prefix keeps them clear of Bootstrap's own .toast component. */
.rr-toast-container {
  position: fixed;
  right: 24px;
  bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 9999;
}

.rr-toast {
  background: #ffffff;
  border: 1px solid var(--rr-border);
  border-left-width: 4px;
  border-radius: 8px;
  padding: 12px 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  min-width: 220px;
  animation: rr-slide-in 0.2s ease-out;
}

body.dark-mode .rr-toast {
  background: #2b2b2b;
}

.rr-toast.success {
  border-left-color: #28a745;
}

.rr-toast.error {
  border-left-color: #dc3545;
}

.rr-toast.warning {
  border-left-color: #ffc107;
}

.rr-toast.info {
  border-left-color: #17a2b8;
}

@keyframes rr-slide-in {
  from {
    transform: translateY(10px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Support: a quiet footer below the settings, never in the way of a task. */
.rr-support {
  margin-top: 4px;
  padding-top: 14px;
  border-top: 1px solid var(--rr-border);
  font-size: 0.8rem;
}
.rr-support-text {
  margin: 0 0 8px;
  color: var(--rr-muted);
  line-height: 1.5;
}
.rr-support-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.rr-tip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 3px 12px;
  border: 1px solid var(--rr-border);
  border-radius: 8px;
  color: inherit;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.rr-tip:hover,
.rr-tip:focus {
  color: inherit;
  text-decoration: none;
  border-color: var(--rr-muted);
}
.rr-tip:focus-visible {
  outline: 2px solid #0d6efd;
  outline-offset: 2px;
}
.rr-tip img {
  width: 20px;
  height: 20px;
  margin-left: -5px;
  border-radius: 5px;
}
.rr-support-note {
  margin: 8px 0 0;
  color: var(--rr-muted);
  font-size: 0.75rem;
}
