/* messenger/account-settings.css — 8 of 9. Needs base.css and message-actions.css (the
   shared .modal shell) and conversation-settings.css (.modal-confirm.danger).
   The Settings dialog (KAN-63) behind the gear under the chat list, driven by
   account-settings.js. Its open/close and tab-switch animations are in motion.css.
   Sections, in order:
     - Shell: .account-modal (wider than the other dialogs), .account-layout
     - Tabs: .account-tabs and .account-tab
     - Panels and their shared pieces: .account-panel, .account-form, .account-field,
       .account-hint, .account-note, .account-error / -success, .account-actions, buttons
     - Profile: .profile-photo and its avatar and actions
     - Preferences: .account-row, the .account-switch toggle, .appearance-choices
     - Account: .account-row--danger, .delete-account-form
     - @media (max-width: 720px): tabs across the top, the dialog fills the screen */

/* Shell */

.account-modal {
  --surface: var(--surface-pop);
  display: flex;
  flex-direction: column;
  max-width: 720px;
  max-height: min(640px, calc(100dvh - 2rem));
  overflow: hidden;
}

.account-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 190px 1fr;
}

/* Tabs */

.account-tabs {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.75rem;
  border-right: 1px solid var(--border);
}

.account-tab {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.75rem;
  border: none;
  border-radius: var(--radius-md);
  background: none;
  color: var(--text);
  font: inherit;
  font-size: var(--text-md);
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.account-tab .icon {
  font-size: 1.2rem;
  color: var(--muted);
  transition: color 0.15s ease;
}

.account-tab:hover {
  background: var(--hover-tint);
}

.account-tab[aria-selected="true"] {
  background: var(--accent-soft);
  color: var(--heading);
  font-weight: 600;
}

.account-tab[aria-selected="true"] .icon {
  color: var(--accent-ink);
}

.account-tab:focus-visible {
  outline-offset: -2px;
}

/* Panels */

.account-panels {
  min-width: 0;
  overflow-y: auto;
  padding: 1.25rem 1.5rem 1.5rem;
}

.account-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.account-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.account-field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.account-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--heading);
}

.account-field input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font: inherit;
  font-size: var(--text-md);
  font-weight: 400;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.account-field input:focus {
  outline: none;
  border-color: var(--accent-ink);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.account-field input[readonly] {
  background: var(--bg);
  color: var(--muted);
}

/* A hint sits right under the field it explains. */
.account-hint {
  margin: -0.5rem 0 0;
  font-size: var(--text-xs);
  color: var(--muted);
}

.account-panel-intro {
  margin: 0;
}

.account-note {
  margin: 0;
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius-md);
  background: var(--bg);
  font-size: var(--text-sm);
  line-height: 1.45;
  color: var(--text);
}

.account-error,
.account-success {
  margin: 0;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
}

.account-error {
  background: var(--error-bg);
  color: var(--error);
}

.account-success {
  background: var(--online-soft);
  color: var(--online-ink);
}

.account-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.account-actions button,
.account-secondary-btn,
.account-danger-btn {
  border: none;
  border-radius: var(--radius-md);
  padding: 0.55rem 1.1rem;
  font: inherit;
  font-size: var(--text-md);
  font-weight: 600;
  cursor: pointer;
}

.account-actions button:disabled {
  opacity: 0.6;
  cursor: default;
}

.account-secondary-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
  background: var(--bg);
  color: var(--heading);
  transition: background-color 0.15s ease;
}

.account-secondary-btn:hover {
  background: var(--hover-tint);
}

.account-secondary-btn .icon {
  font-size: 1.1rem;
}

.account-text-btn {
  border: none;
  background: none;
  padding: 0.55rem 0.4rem;
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--error);
  cursor: pointer;
}

.account-danger-btn {
  flex-shrink: 0;
  background: var(--error-bg);
  color: var(--error);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.account-danger-btn:hover {
  background: var(--error);
  color: #fff;
}

/* Profile */

.profile-photo {
  display: flex;
  align-items: center;
  gap: 1.1rem;
}

.profile-avatar {
  width: 84px;
  height: 84px;
  min-width: 84px;
  font-size: 1.6rem;
}

.profile-photo-actions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.profile-photo-actions .account-hint {
  margin: 0;
}

.profile-photo-buttons {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
}

/* The file input inside is visually hidden, so the label shows its focus instead. */
.profile-photo-pick:focus-within {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Preferences and Account rows */

.account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.account-switch-row {
  cursor: pointer;
}

.account-row-text {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.account-row-text strong {
  font-size: var(--text-md);
  color: var(--heading);
}

.account-row-text span {
  font-size: var(--text-sm);
  line-height: 1.4;
  color: var(--muted);
}

/* A toggle switch drawn on the checkbox itself; the knob slides (motion.css keeps it
   still under reduced motion). */
.account-switch {
  appearance: none;
  position: relative;
  flex-shrink: 0;
  width: 44px;
  height: 26px;
  margin: 0;
  border-radius: 999px;
  background: var(--border);
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.account-switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.account-switch:checked {
  background: var(--orange);
}

.account-switch:checked::after {
  transform: translateX(18px);
}

.appearance-choices {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin: 0;
  padding: 0;
  border: none;
}

.appearance-choices legend {
  margin-bottom: 0.6rem;
  padding: 0;
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--heading);
}

.appearance-choice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  padding: 0.6rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.appearance-choice:hover {
  background: var(--hover-tint);
}

.appearance-choice:has(input:checked) {
  border-color: var(--orange);
  background: var(--accent-soft);
  font-weight: 600;
}

.appearance-choice:has(input:focus-visible) {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.appearance-choice input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

/* A tiny window in each look: a bar and two bubbles. */
.appearance-swatch {
  width: 100%;
  height: 48px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(127, 127, 127, 0.25);
}

.appearance-swatch--light {
  background:
    linear-gradient(#f2994a, #f2994a) 70% 62% / 34% 16% no-repeat,
    linear-gradient(#d8dce3, #d8dce3) 22% 34% / 40% 16% no-repeat,
    #fff;
}

.appearance-swatch--dark {
  background:
    linear-gradient(#f2994a, #f2994a) 70% 62% / 34% 16% no-repeat,
    linear-gradient(#2f3442, #2f3442) 22% 34% / 40% 16% no-repeat,
    #1b1e27;
}

.appearance-swatch--system {
  background:
    linear-gradient(#f2994a, #f2994a) 70% 62% / 34% 16% no-repeat,
    linear-gradient(#8a909c, #8a909c) 22% 34% / 40% 16% no-repeat,
    linear-gradient(135deg, #fff 50%, #1b1e27 50%);
}

/* Account */

.account-row--danger {
  border-color: color-mix(in srgb, var(--error) 35%, var(--border));
}

.delete-account-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 1rem;
  border: 1px solid color-mix(in srgb, var(--error) 35%, var(--border));
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--error-bg) 50%, transparent);
}

/* Narrow screens: tabs scroll across the top and the dialog takes the whole screen. */
@media (max-width: 720px) {
  #account-dialog {
    padding: 0;
  }

  .account-modal {
    max-width: none;
    max-height: none;
    height: 100%;
    border-radius: 0;
  }

  .account-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .account-tabs {
    flex-direction: row;
    overflow-x: auto;
    padding: 0.5rem 0.75rem;
    border-right: none;
    border-bottom: 1px solid var(--border);
    scrollbar-width: none;
  }

  .account-tab {
    flex-shrink: 0;
    padding: 0.5rem 0.7rem;
  }

  /* Text only, so all four tabs fit across a phone. */
  .account-tab .icon {
    display: none;
  }

  .account-panels {
    padding: 1rem 1rem calc(1.5rem + env(safe-area-inset-bottom));
  }

  .account-field-row {
    grid-template-columns: 1fr;
  }

  .account-row {
    flex-wrap: wrap;
  }
}
