:root {
  color-scheme: dark;
  --settings-nav-width: 168px;
  --settings-header-border: rgba(255, 255, 255, 0.10);
  --settings-nav-bg: rgba(0, 0, 0, 0.28);
  --settings-tab-active-bg: rgba(255, 255, 255, 0.12);
  --settings-tab-hover-bg: rgba(255, 255, 255, 0.06);
  /* Cool selection chrome — not KeyPilot text-mode orange / left-edge pulse */
  --settings-tab-active-border: rgba(120, 180, 255, 0.45);
  --settings-tab-active-accent: rgba(120, 180, 255, 0.95);
  --settings-tab-focus-ring: rgba(120, 180, 255, 0.75);
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: linear-gradient(rgb(18, 18, 18) 0%, rgb(11, 11, 11) 100%);
  color: rgba(255, 255, 255, 0.92);
}

/* Full-height master–detail shell (popover iframe + standalone) */
.settings-app {
  box-sizing: border-box;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--settings-header-border);
  background: linear-gradient(180deg, rgba(35, 35, 35, 0.55) 0%, rgba(18, 18, 18, 0.2) 100%);
}

/* Outer KeyPilot popover titlebar owns title + close when embedded. */
.kp-popover-embed .settings-app > .header,
.header[hidden] {
  display: none !important;
}

.header-text {
  min-width: 0;
}

h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0.2px;
}

.sub {
  margin: 4px 0 0 0;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.68);
}

.header-actions {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}

.settings-shell {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--settings-nav-width) minmax(0, 1fr);
}

/* Left master list */
.settings-nav {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 8px;
  overflow-y: auto;
  border-right: 1px solid var(--settings-header-border);
  background: var(--settings-nav-bg);
}

.settings-tab {
  appearance: none;
  box-sizing: border-box;
  width: 100%;
  margin: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: rgba(255, 255, 255, 0.82);
  text-align: left;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.15px;
  padding: 9px 10px;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.settings-tab:hover {
  background: var(--settings-tab-hover-bg);
  color: rgba(255, 255, 255, 0.95);
}

.settings-tab:focus-visible {
  outline: 2px solid var(--settings-tab-focus-ring);
  outline-offset: 1px;
}

/* Selected master-list item. Avoid orange inset left-edge (same visual language as
   text-mode field focus) so selecting a category never looks like typing mode. */
.settings-tab[aria-selected="true"] {
  background: var(--settings-tab-active-bg);
  border-color: var(--settings-tab-active-border);
  color: rgba(255, 255, 255, 0.98);
  box-shadow: inset 3px 0 0 var(--settings-tab-active-accent);
}

/* Right detail pane */
.settings-detail {
  box-sizing: border-box;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 18px 28px;
}

.settings-panel {
  display: none;
  max-width: 720px;
}

.settings-panel.is-active {
  display: block;
}

.panel-header {
  margin-bottom: 14px;
}

.panel-header h2 {
  margin: 0 0 6px 0;
  font-size: 16px;
  letter-spacing: 0.15px;
}

.panel-lead {
  margin: 0;
  font-size: 12px;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.68);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.btn {
  background: linear-gradient(180deg, rgba(255,255,255,0.15) 0%, rgba(255,255,255,0.08) 100%);
  border: 1px solid rgba(255,255,255,0.25);
  color: rgba(255,255,255,0.95);
  border-radius: 5px;
  padding: 10px 12px;
  font-size: 13px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.1);
}

.btn:hover {
  border-color: rgba(255,255,255,0.28);
}

.btn-secondary {
  border-color: rgba(255,140,0,0.35);
}

.radio-group {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
}

.radio {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 7px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(0,0,0,0.35);
  box-shadow: 0 2px 6px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.03);
}

.radio input {
  transform: scale(1.1);
  flex-shrink: 0;
}

.radio-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.radio-title {
  display: block;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.1px;
}

.radio-sub {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.62);
  line-height: 1.35;
}

.settings-app kbd {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.08);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  line-height: 1.3;
}

.toggle {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 10px;
  border-radius: 7px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(0,0,0,0.35);
  cursor: pointer;
  user-select: none;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.03);
}

.toggle:hover {
  border-color: rgba(255,255,255,0.22);
}

.toggle input[type="checkbox"] {
  margin-top: 2px;
  transform: scale(1.1);
}

.toggle-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.toggle-title {
  font-size: 13px;
  font-weight: 600;
}

.toggle-sub {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.72);
}

.hint {
  margin: 10px 0 0 0;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.70);
}

.subhead {
  margin: 0 0 10px 0;
  font-size: 12px;
  color: rgba(235, 235, 235, 0.78);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  align-items: start;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 10px;
  border-radius: 7px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(0,0,0,0.35);
  box-shadow: 0 2px 6px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.03);
}

.field-label {
  font-size: 11px;
  font-weight: 700;
  color: rgba(235, 235, 235, 0.78);
}

.field-hint {
  font-size: 11px;
  color: rgba(235, 235, 235, 0.60);
}

.select {
  background: rgba(0,0,0,0.35);
  color: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 5px;
  padding: 10px 10px;
  font-size: 13px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.05);
}

.range-row {
  display: grid;
  grid-template-columns: 1fr 90px;
  gap: 10px;
  align-items: center;
}

.number {
  background: rgba(0,0,0,0.35);
  color: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 5px;
  padding: 10px 10px;
  font-size: 13px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.05);
}

.preview {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 10px;
  border-radius: 7px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(0,0,0,0.35);
  box-shadow: 0 2px 6px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.03);
}

.preview-title {
  font-size: 12px;
  font-weight: 700;
}

.preview-box {
  height: 72px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(0,0,0,0.45);
  display: grid;
  place-items: center;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.02);
}

.preview-box img {
  width: 60px;
  height: 60px;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 2px;
}

.btn-small {
  padding: 8px 10px;
}

.divider {
  height: 1px;
  background: rgba(255,255,255,0.10);
  margin: 4px 0 2px;
}

.about-card {
  padding: 14px 12px;
  border-radius: 7px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(0,0,0,0.35);
  box-shadow: 0 2px 6px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.03);
}

.about-brand {
  margin: 0 0 8px 0;
  font-size: 14px;
  font-weight: 600;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
}

/* Narrow popover / window: stack nav above detail */
@media (max-width: 640px) {
  .settings-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .settings-nav {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    border-right: none;
    border-bottom: 1px solid var(--settings-header-border);
    padding: 8px;
    gap: 6px;
  }

  .settings-tab {
    width: auto;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .settings-tab[aria-selected="true"] {
    box-shadow: inset 0 -3px 0 var(--settings-tab-active-accent);
  }
}
