/* Styles for the interactive web tools (/tools/profiles/ and /tools/flash/).
   Loaded after site.css, which provides tokens, type, .btn and .card.
   Class names here are the ones profiles.js and flasher.js toggle; rename
   them in both places or not at all. */

.tool {
  /* Aliases for the inline styles that remain in the profile generator markup. */
  --text-main: var(--text);
  --text-dark: var(--text-2);
  --text-muted: var(--text-3);
  --border-light: var(--line);
  padding-bottom: clamp(3.5rem, 8vw, 6rem);
}

.hidden {
  display: none !important;
}
.content-hidden {
  display: none;
}

.tool-head {
  padding-block: clamp(2.5rem, 6vw, 4rem) 2rem;
}
.tool-head h1 {
  font-size: clamp(2.1rem, 5vw, 3.1rem);
  letter-spacing: -0.03em;
}
.tool-head .lede {
  margin-top: 1rem;
  max-width: 46rem;
  font-size: 1.15rem;
  color: var(--text-2);
}

.tool-main {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 56rem;
}

.tool .card {
  padding: clamp(1.1rem, 3vw, 1.75rem);
}

/* ---------- Mode tabs ---------- */

.mode-tabs {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 1.75rem;
  padding: 0.25rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg-raised);
}
.tab-btn {
  background: transparent;
  border: 0;
  padding: 0.6rem 1.1rem;
  color: var(--text-2);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  border-radius: var(--radius);
  cursor: pointer;
}
.tab-btn:hover {
  color: var(--text);
}
.tab-btn.active {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.mode-container {
  display: none;
}
.mode-container.active-mode {
  display: block;
}

/* ---------- Step header ---------- */

.section-header {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}
.section-header h2 {
  font-size: 1.2rem;
}
.step-number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  flex: none;
  border: 1px solid var(--accent-line);
  border-radius: 50%;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.82rem;
}
.section-header .signal-counter {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
}

/* ---------- Upload ---------- */

.file-upload {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-inset);
  transition: border-color 0.15s, background-color 0.15s;
}
.file-upload:hover,
.file-upload.dragover {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.upload-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  padding: 2.5rem 1.5rem;
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
}
.upload-icon-wrapper {
  color: var(--accent);
  line-height: 0;
}
.upload-text {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text);
  text-align: center;
}

.status-message {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.95rem;
}
.success-message {
  border: 1px solid rgba(95, 209, 154, 0.3);
  background: rgba(95, 209, 154, 0.08);
  color: var(--ok);
}

/* ---------- Forms ---------- */

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.flex-1 {
  flex: 1;
  min-width: 200px;
}
.flex-2 {
  flex: 2;
  min-width: 280px;
}

.tool label:not(.btn):not(.upload-label):not(.toggle-switch) {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
}

.premium-input,
.premium-select {
  width: 100%;
  padding: 0.65rem 0.85rem;
  background: var(--bg-inset);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.premium-input::placeholder {
  color: var(--text-3);
}
.premium-input:focus,
.premium-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.premium-input:disabled,
.premium-select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.custom-select-wrapper {
  position: relative;
}
.custom-select-wrapper::after {
  content: "";
  position: absolute;
  right: 0.9rem;
  top: 50%;
  width: 0.45rem;
  height: 0.45rem;
  border-right: 1.5px solid var(--text-3);
  border-bottom: 1.5px solid var(--text-3);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}
.premium-select {
  appearance: none;
  padding-right: 2.25rem;
}

.input-hint {
  font-size: 0.8rem;
  color: var(--text-3);
}

.highlight {
  color: var(--accent);
}

/* ---------- Searchable dropdown ---------- */

.searchable-dropdown {
  position: relative;
  width: 100%;
}
.sd-list {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 40;
  width: 100%;
  max-height: 260px;
  margin-top: 4px;
  overflow-y: auto;
  background: var(--bg-raised);
  border: 1px solid var(--accent-line);
  border-radius: var(--radius);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
}
.sd-item {
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.95rem;
  cursor: pointer;
}
.sd-item:last-child {
  border-bottom: 0;
}
.sd-item:hover {
  background: var(--accent-dim);
}
.sd-empty {
  color: var(--text-3);
  font-style: italic;
  cursor: default;
}
.sd-empty:hover {
  background: none;
}

/* ---------- Slots ---------- */

.accordion {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.slot-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg);
}
.slot-item.expanded {
  border-color: var(--line-strong);
}
.slot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1.1rem;
  cursor: pointer;
}
.slot-item.expanded .slot-header {
  border-bottom: 1px solid var(--line);
}
.slot-header-left {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem 0.9rem;
}
.slot-title {
  font-size: 1.02rem;
  font-weight: 500;
}
.slot-status-badge {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--text-3);
}
.slot-status-badge.active {
  border-color: rgba(95, 209, 154, 0.35);
  color: var(--ok);
}
.expand-btn {
  display: flex;
  background: none;
  border: 0;
  padding: 0.35rem;
  color: var(--text-3);
  cursor: pointer;
  transition: transform 0.2s;
}
.slot-item.expanded .expand-btn {
  transform: rotate(180deg);
  color: var(--accent);
}
.slot-body-inner {
  padding: 1.25rem 1.1rem;
}
.slot-body.disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* ---------- Toggle ---------- */

.toggle-switch {
  position: relative;
  display: inline-block;
  flex: none;
  width: 40px;
  height: 22px;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  inset: 0;
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  background: var(--bg-inset);
  cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s;
}
.slider::before {
  content: "";
  position: absolute;
  left: 2px;
  bottom: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-2);
  transition: transform 0.2s, background-color 0.2s;
}
input:checked + .slider {
  background: var(--accent);
  border-color: var(--accent);
}
input:checked + .slider::before {
  transform: translateX(18px);
  background: var(--accent-ink);
}
input:focus-visible + .slider {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Warning ---------- */

.warning-alert {
  display: flex;
  align-items: flex-start;
  gap: 0.9rem;
  margin-bottom: 1.25rem;
  padding: 0.9rem 1.1rem;
  border: 1px solid rgba(240, 115, 106, 0.35);
  border-radius: var(--radius);
  background: rgba(240, 115, 106, 0.07);
}
.warning-icon {
  flex: none;
  color: var(--danger);
}
.warning-content h4 {
  font-size: 0.95rem;
  color: var(--text);
}
.warning-text {
  margin-top: 0.2rem;
  font-size: 0.88rem;
  color: var(--text-2);
}

/* ---------- Info pills ---------- */

.advanced-info {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.25rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--line);
}
.info-pill,
.dcfg-pill {
  font-size: 0.8rem;
  padding: 0.18rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text-2);
}
.info-label {
  margin-right: 0.25rem;
  color: var(--text-3);
}
.info-value {
  font-family: var(--font-mono);
}
.info-value.highlight,
.id-pill {
  font-family: var(--font-mono);
  color: var(--accent);
}

/* ---------- DBC decoding profile builder ---------- */

.signal-selector-panel {
  margin-bottom: 1.5rem;
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg);
}
.signal-selector-panel .btn {
  margin-top: 0.25rem;
}
.signal-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.empty-state {
  padding: 2rem 1.5rem;
  border: 1px dashed var(--line);
  border-radius: var(--radius-lg);
  text-align: center;
  color: var(--text-3);
}
.dcfg-signal-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg);
}
.dcfg-signal-item:hover {
  border-color: var(--line-strong);
}
.dcfg-content {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
}
.dcfg-names {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
}
.dcfg-name-input {
  width: 100%;
  max-width: 260px;
  margin-left: -0.3rem;
  padding: 0.1rem 0.3rem;
  background: transparent;
  border: 1px dashed transparent;
  border-radius: 4px;
  color: var(--text);
  font: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  outline: none;
}
.dcfg-name-input:hover {
  border-color: var(--line-strong);
}
.dcfg-name-input:focus {
  border-style: solid;
  border-color: var(--accent);
  background: var(--bg-inset);
}
.dcfg-msg-name {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-3);
}
.dcfg-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.remove-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 2.1rem;
  height: 2.1rem;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: none;
  color: var(--text-3);
  cursor: pointer;
}
.remove-btn:hover {
  border-color: var(--danger);
  color: var(--danger);
}

/* ---------- Export ---------- */

.export-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem 2rem;
}
.export-text-group {
  flex: 1;
  min-width: 240px;
}
.tool .export-desc {
  margin: 0;
  color: var(--text);
}
.tool .export-path {
  margin-top: 0.4rem;
  font-size: 0.9rem;
  color: var(--text-2);
}

/* ---------- Flasher ---------- */

.flash-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  max-width: 62rem;
}
.flash-option h2 {
  font-size: 1.25rem;
}
.flash-option .build-meta {
  margin-top: 0.7rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--accent);
}
.flash-option .card-foot {
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
}
.flash-option .btn {
  width: 100%;
}
esp-web-install-button {
  display: block;
}
esp-web-install-button[active] .btn {
  opacity: 0.6;
}

.flasher-custom-panel {
  display: none;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.9rem;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
}
.flasher-custom-panel.is-active {
  display: flex;
}
.flasher-custom-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}
.custom-file-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.88rem;
  color: var(--text-3);
}
.custom-file-name.has-file {
  font-family: var(--font-mono);
  color: var(--ok);
}
.custom-chip-select .premium-select {
  max-width: 170px;
  padding-block: 0.4rem;
  font-size: 0.88rem;
}

.flasher-unsupported {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.8rem;
  border: 1px solid rgba(240, 115, 106, 0.35);
  border-radius: var(--radius);
  background: rgba(240, 115, 106, 0.07);
  font-size: 0.88rem;
  color: var(--danger);
}

.tool .tool-after {
  margin-top: clamp(2.5rem, 5vw, 3.5rem);
}

@media (max-width: 760px) {
  .flash-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .form-row {
    flex-direction: column;
    gap: 1rem;
  }
  .flex-1,
  .flex-2 {
    min-width: 0;
    width: 100%;
  }
  .mode-tabs {
    display: flex;
    flex-direction: column;
  }
  .export-actions .btn {
    width: 100%;
  }
  .advanced-info {
    flex-direction: column;
    align-items: stretch;
  }
  .info-pill {
    display: flex;
    justify-content: space-between;
  }
}
