/* NodeBook — buttons, inputs, selects, switches, search. */

/* ---------- buttons ---------- */

/* Buttons as on the #BEmesh tools: a hairline border on the panel; the primary one gold with dark
   text. Hover (a real pointer only) is pale gold with a gold rim; disabled is the bar colour with
   muted text. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 36px;
  padding: 0 var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: var(--text-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
  text-decoration: none;
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text);
}

.btn--danger {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--danger-ink);
}

.btn--danger-ghost {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text-2);
  cursor: not-allowed;
}

@media (hover: hover) {
  .btn:hover:not(:disabled, [aria-disabled="true"]) {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--text);
  }

  .btn--primary:hover:not(:disabled, [aria-disabled="true"]) {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: var(--accent-ink);
  }

  .btn--danger:hover:not(:disabled, [aria-disabled="true"]) {
    background: var(--danger);
    border-color: var(--danger);
    color: var(--danger-ink);
  }

  .btn--danger-ghost:hover:not(:disabled, [aria-disabled="true"]) {
    background: var(--danger-soft);
    border-color: var(--danger);
    color: var(--danger);
  }
}

.btn--sm {
  min-height: 30px;
  padding: 0 var(--space-3);
  font-size: var(--text-xs);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  flex: none;
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.icon-btn:disabled {
  color: var(--text-2);
  cursor: not-allowed;
}

@media (hover: hover) {
  .icon-btn:hover:not(:disabled) {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--text);
  }
}

.btn-row {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  align-items: center;
}

/* ---------- inputs ---------- */

input[type="text"],
input[type="search"],
input[type="number"],
input[type="password"],
input:not([type]),
select,
textarea {
  width: 100%;
  min-height: 38px;
  padding: 7px var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-md);
  transition: border-color var(--dur-fast) var(--ease);
}

::placeholder {
  color: var(--text-2);
  opacity: 1;
}

textarea {
  resize: vertical;
  line-height: 1.4;
}

select {
  appearance: none;
  padding-right: 32px;
  background: var(--surface) var(--select-arrow) no-repeat right 10px center / 12px 12px;
}

/* Firefox (and Chrome on some platforms) paint the select's background behind
   every option in the open list — give options a plain background instead. */
select option,
select optgroup {
  background: var(--surface);
  background-image: none;
  color: var(--text);
}

/* Focus: the 2 px ring, 2 px off the field, never removed. */
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

input:disabled,
select:disabled,
textarea:disabled {
  background-color: var(--surface-2);
  border-color: var(--border);
  color: var(--text-2);
  cursor: not-allowed;
}

/* An error: a 2 px red border (the inner pixel drawn inside, so nothing moves) with its sentence below. */
input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: inset 0 0 0 1px var(--danger);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field--wide {
  grid-column: 1 / -1;
}

.field-label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
}

.field-help {
  font-size: var(--text-xs);
  color: var(--text-3);
}

.field-inherit:empty {
  display: none;
}

.inherit-note {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--text-3);
}

.inherit-note.is-override {
  color: var(--text-2);
}

.inherit-note a {
  color: var(--link);
}

.field-inherit {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: var(--space-3);
  row-gap: var(--space-1);
}

/* What the device had when last read, with ↺ to use it again. */
.device-value {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: var(--text-2);
}

.device-use {
  font-size: var(--text-md);
  text-decoration: none;
  line-height: 1;
}

.device-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

.device-badge:empty {
  display: none;
}

/* A card head with the device count and the JSON badge wraps on a phone instead of overflowing. */
.settings-card .card-head {
  flex-wrap: wrap;
  row-gap: var(--space-2);
}

.link-btn {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--link);
  cursor: pointer;
  text-decoration: underline;
}

.field-error {
  font-size: var(--text-xs);
  color: var(--danger);
  min-height: 0;
}

.field-error:empty {
  display: none;
}

.field-warn {
  font-size: var(--text-xs);
  color: var(--warn);
  background: var(--warn-soft);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
}

.field-warn:empty {
  display: none;
}

.field.has-error .field-warn {
  display: none;
}

.field.is-disabled {
  opacity: 0.55;
}

.input-unit {
  position: relative;
  display: flex;
}

.input-unit input {
  padding-right: 46px;
}

.input-unit .unit {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  font-size: var(--text-sm);
  pointer-events: none;
}

.input-with-action {
  display: flex;
  gap: var(--space-1);
  align-items: stretch;
}

.input-with-action > input,
.input-with-action > textarea {
  flex: 1;
  min-width: 0;
}

.input-with-action .icon-btn {
  height: auto;
  min-height: 38px;
  border: 1px solid var(--border-strong);
}

.field-locked {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  min-height: 38px;
  color: var(--text-2);
}

.field-locked > span {
  display: inline-flex;
  gap: var(--space-1);
  align-items: center;
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* Workspace → Files and backup: one row per file action. */
.file-actions {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
  gap: 0 var(--space-5);
}

.file-action {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-top: 1px solid var(--border);
}

.file-action > .icon {
  flex: none;
  color: var(--text-3);
}

.file-action-text {
  flex: 1 1 12rem;
  min-width: 0;
}

.file-action-text h4 {
  font-size: var(--text-sm);
}

.file-action-text p {
  font-size: var(--text-xs);
}

.file-action > .btn {
  flex: none;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-4) var(--space-5);
}

.field--toggle {
  justify-content: center;
}

/* switch */
.switch {
  position: relative; /* keeps the visually hidden checkbox inside the label */
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
  min-height: 38px;
  user-select: none;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.switch-track {
  position: relative;
  width: 38px;
  height: 22px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
  flex: none;
}

.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-2);
}

.switch input:checked + .switch-track {
  background: var(--accent);
  border-color: var(--accent);
}

.switch input:checked + .switch-track .switch-thumb {
  transform: translateX(16px);
  background: var(--accent-ink);
}

.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.switch-label {
  font-size: var(--text-md);
}

/* search */
.search {
  position: relative;
}

.search .icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  pointer-events: none;
}

.search input {
  padding-left: 36px;
}

/* The "?" after a label or a card title (ui/info.js): a 22 px circle, the button around it 24 px
   (44 px on a touch screen, without taking more room in the line). */
.field-label-row { display: flex; align-items: center; gap: 2px; }
.field-label-row .field-label { margin-bottom: 0; }
.info, .info-label { display: inline-flex; align-items: center; gap: 2px; }
.info-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  margin: 0 2px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text-2);
  font: 600 13px/1 inherit;
  cursor: pointer;
  flex: none;
}
.info-btn::before {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  background: var(--surface);
  z-index: -1;
}
.info-btn { isolation: isolate; }
@media (pointer: coarse), (max-width: 640px) {
  .info-btn { width: 44px; height: 44px; margin: -10px -8px; }
}
.info-btn[aria-expanded="true"] { color: var(--text); }
.info-btn[aria-expanded="true"]::before { background: var(--accent-soft); border-color: var(--accent); }
@media (hover: hover) {
  .info-btn:hover { color: var(--text); }
  .info-btn:hover::before { background: var(--accent-soft); border-color: var(--accent); }
}
.info-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; border-radius: 50%; }
.info-bubble {
  position: fixed;
  inset: auto;
  margin: 0;
  max-width: min(320px, calc(100vw - 32px));
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-2);
  font-size: var(--text-md);
  line-height: var(--leading);
  overflow-wrap: anywhere;
}
.info-bubble { max-height: calc(100dvh - 32px); overflow-y: auto; }
/* Hidden unless open; a browser without the Popover API drops the :popover-open rule and keeps them hidden. */
.info-bubble { display: none; }
.info-bubble:popover-open { display: block; }
.info-bubble:popover-open:not([data-placed]) { visibility: hidden; }
.info-bubble--inline { position: static; flex-basis: 100%; margin-top: 4px; box-shadow: none; }
.info-bubble--inline:not([hidden]) { display: block; }
.info:has(.info-bubble--inline:not([hidden])) { flex-wrap: wrap; }
.info-bubble p { margin: 0; }
.info-bubble p + p { margin-top: 6px; }

/* Settings → Data in this browser: badge, its "?", the space used, on one line. */
.data-status { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; margin: 0; }
.info-text { display: inline; }
.info-text .info { display: inline-flex; vertical-align: middle; }
