/* ── Multi-profile UI ────────────────────────────────────────────────── */

/* Settings note injected section */
.profile-controls {
  padding: 8px 0 12px;
}

.profile-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

/* ── Row (horizontal layout, wraps gracefully) ───────────────────────── */
.profile-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  flex-wrap: wrap;
}

.profile-row.active {
  background: var(--surface, #2e2e2e);
  border-color: var(--border, #444);
}

/* Avatar + name share a fixed-spacing sub-flex so their relationship is
   never affected by row-level gap or wrap behaviour. */
.profile-row-identity {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 auto;
  min-width: 0;
}

/* Name takes the remaining horizontal slack so chips align to the right */
.profile-row-label {
  flex: 1 1 auto;
  min-width: 80px;
  font-size: 14px;
  color: var(--text, #e8dcf4);
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.4;
  display: inline-flex;
  align-items: center;
}

.profile-row-label:hover {
  text-decoration: underline;
}

/* Active pill */
.profile-active-pill {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent, #a272b0);
  color: var(--text-on-accent, #fff);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1;
  height: 22px;
  box-sizing: border-box;
}

/* ── Chips (Sync / Encryption / Switch / Remove) ─────────────────────── */
.profile-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  padding: 0 10px;
  height: 22px;
  border-radius: 999px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1;
  margin: 0;
  background: var(--surface, #2e2e2e);
  color: var(--muted, #888);
  border: 1px solid var(--border, #444);
  white-space: nowrap;
  flex-shrink: 0;
  font-family: inherit;
  box-sizing: border-box;
}

.profile-chip:disabled,
.profile-chip-disabled {
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
}

.profile-chip-on {
  background: rgba(76, 175, 114, 0.15);
  color: var(--success, #4caf72);
  border-color: rgba(76, 175, 114, 0.4);
}

.profile-chip-off {
  /* default surface look, no extra colour */
}

.profile-chip-warn {
  background: rgba(212, 162, 74, 0.15);
  color: var(--warning, #d4a24a);
  border-color: rgba(212, 162, 74, 0.4);
}

.profile-chip-active {
  outline: 2px solid var(--accent, #a272b0);
  outline-offset: 1px;
}

.profile-chip-switch {
  background: transparent;
  color: var(--accent, #a272b0);
  border-color: var(--accent, #a272b0);
}

/* Delete profile — borderless ✕ glyph. Drops the chip's uppercase +
   letter-spacing so the icon reads cleanly, and removes the circle border. */
.profile-chip-remove {
  margin-left: auto;
  color: var(--error, #e05c5c);
  border: none;
  background: transparent;
  width: 22px;
  padding: 0;
  font-size: 14px;
  text-transform: none;
  letter-spacing: 0;
}

.profile-chip-busy {
  opacity: 0.5;
  pointer-events: none;
}

@media (hover: hover) {
  .profile-chip:not(:disabled):not(.profile-chip-disabled):hover {
    filter: brightness(1.15);
  }
}

/* ── Inline panel that drops below an active row ─────────────────────── */
.profile-row-panel {
  position: relative;
  margin: -2px 0 6px 0;
  padding: 10px 36px 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--border, #444);
  background: var(--surface, #2e2e2e);
  font-size: 13px;
}

.profile-row-panel .sync-btn {
  margin-bottom: 6px;
  margin-right: 6px;
}

.profile-row-panel .sync-btn:last-child {
  margin-bottom: 0;
}

/* Close (X) button — anchored top-right of the panel so the user can dismiss
   any flow at any time. Matches the toggle behaviour of the chip itself. */
.profile-row-panel-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--muted, #888);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.profile-row-panel-close:hover {
  background: var(--hover-overlay, rgba(255,255,255,0.08));
  color: var(--text, #e8dcf4);
}

/* ── Inline rename input — replaces the .profile-row-label span on click */
.profile-row-name-input {
  flex: 1 1 auto;
  min-width: 80px;
  font-size: 14px;
  padding: 2px 6px;
  margin: 0;
  border: 1px solid var(--accent, #a272b0);
  border-radius: 4px;
  background: var(--bg, #1e1e1e);
  color: var(--text, #e8dcf4);
  font-family: inherit;
  outline: none;
  box-sizing: border-box;
  height: 24px;
  line-height: 1.2;
}

/* ── Avatar (shared: row + dropdown + toolbar) ───────────────────────── */
.profile-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: 600;
  border: none;
  background-color: var(--accent, #a272b0);
  color: var(--text-on-accent, #fff);
  user-select: none;
  flex-shrink: 0;
  line-height: 1;
}

.profile-avatar-mini {
  width: 26px;
  height: 26px;
  font-size: 12px;
}

/* Avatar in the row that doubles as a colour picker */
.profile-avatar-pick {
  position: relative;
  cursor: pointer;
}

.profile-avatar-pick:hover {
  filter: brightness(1.1);
}

/* Hide the native colour input visually but keep it interactive over the
   avatar. Sized to cover the full avatar so any click triggers the picker. */
.profile-avatar-color-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  padding: 0;
  margin: 0;
  background: transparent;
  opacity: 0;
  cursor: pointer;
}
.profile-avatar-color-input::-webkit-color-swatch-wrapper { padding: 0; }
.profile-avatar-color-input::-webkit-color-swatch { border: none; }

/* ── Avatar group — anchored to the bottom-right of the sidebar panel.
   #panel-lists is position:fixed so absolute children are relative to it. ── */
#profile-avatar-group {
  position: absolute;
  right: var(--gap);
  bottom: calc(var(--gap) + env(safe-area-inset-bottom));
  z-index: 6;
}

#profile-avatar-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* background-color is set inline by JS to the active profile's colour */
  border: none;
  line-height: 1;
}

#profile-avatar-btn:hover {
  filter: brightness(1.15);
}

/* ── Dropdown ────────────────────────────────────────────────────────── */
/* Anchored to the bottom-right of the avatar group; opens upward since the
   avatar sits at the bottom of the viewport. */
.profile-dropdown {
  position: absolute;
  bottom: 100%;
  right: 0;
  margin-bottom: 6px;
  background: var(--bg, #1e1e1e);
  border: 1px solid var(--border, #444);
  border-radius: 8px;
  box-shadow: 0 2px 6px var(--shadow, rgba(0,0,0,0.3)),
              0 8px 20px var(--shadow-light, rgba(0,0,0,0.2));
  z-index: 200;
  min-width: 200px;
  padding: 4px 0;
}

.profile-dropdown[hidden] { display: none; }

.profile-dropdown .profile-row {
  border-radius: 0;
  padding: 6px 12px;
  cursor: pointer;
  border: none;
  background: transparent;
  flex-wrap: nowrap;
}

.profile-dropdown .profile-row:hover {
  background: var(--hover-overlay, rgba(255,255,255,0.05));
}

.profile-dropdown .profile-row.active,
.profile-dropdown .profile-row.active:hover {
  background: var(--surface, #2e2e2e);
}

.profile-dropdown-sep {
  height: 1px;
  background: var(--border, #444);
  margin: 4px 0;
}

.profile-manage-row {
  font-size: 12px;
  color: var(--muted, #888);
  justify-content: flex-start;
}

.profile-manage-row:hover {
  color: var(--text, #e8dcf4);
}

.profile-row-tag {
  font-size: 11px;
  color: var(--muted, #888);
  margin-left: 4px;
}

/* ── Narrow viewports ─────────────────────────────────────────────────
   Avatar + name stay on the first line (their identity sub-flex is set
   to flex: 1 1 auto with min-width: 0 so it always takes its natural
   spot). Chips that don't fit wrap to a second line beneath the row,
   left-aligned. We never stack the whole row vertically. */
@media (max-width: 600px) {
  .profile-row {
    flex-wrap: wrap;
    gap: 6px 8px;
    padding: 10px 12px;
    border: 1px solid var(--border, #444);
  }
  .profile-row.active {
    border-color: var(--accent, #a272b0);
  }

  /* Identity stays on the first line and consumes the full width so the
     wrap break happens between identity and the chip cluster. */
  .profile-row-identity {
    flex: 1 0 100%;
    min-width: 0;
  }

  .profile-row-label {
    font-size: 15px;
  }

  /* Remove icon sits at the right end of the wrapped chip row. */
  .profile-chip-remove {
    margin-left: auto;
  }
}

@media (max-width: 400px) {
  #profile-avatar-btn {
    width: 24px;
    height: 24px;
    font-size: 11px;
  }
  .profile-dropdown {
    min-width: 180px;
  }
}
