/* Settings / Ajustes — the config + account screen (bottom-nav 5th slot).
 *
 * Leans on the shared vocabulary (`.app-header` chrome, design tokens, the
 * bottom-nav padding reserve from following.css). This file owns the list-group
 * anatomy: grouped rows with a leading icon, a trailing value/chevron/switch,
 * the segmented theme control, the language disclosure and the guest CTA.
 *
 * Token-driven throughout so light and dark themes both read correctly.
 */

@layer pages {
.settings {
    padding: 12px 12px calc(72px + env(safe-area-inset-bottom));
    max-width: 640px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* JS/details toggle visibility with [hidden]; the attribute must always win. */
.settings [hidden] {
    display: none;
}

/* ── Identity: account card ───────────────────────────────────────── */

.settings-account {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border-subtle);
}

.settings-account__edit {
    flex: 0 0 auto;
    margin-left: auto;
    width: 38px;
    height: 38px;
    border-radius: var(--radius-full);
    display: grid;
    place-items: center;
    background: var(--color-surface-sunken);
    border: 1px solid var(--color-border-subtle);
    color: var(--color-text-secondary);
    cursor: pointer;
}

.settings-account__edit svg {
    width: 18px;
    height: 18px;
}

.settings-account__avatar {
    flex: 0 0 auto;
    position: relative;
    width: 52px;
    height: 52px;
    border-radius: var(--radius-full);
    overflow: hidden;
    display: grid;
    place-items: center;
    background: var(--color-accent);
    color: var(--color-on-accent);
}

.settings-account__initials {
    font-family: var(--font-title);
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: 0.5px;
}

.settings-account__photo {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.settings-account__meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.settings-account__name {
    font-family: var(--font-title);
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--color-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.settings-account__nick {
    font-family: var(--font-body);
    font-size: 0.82rem;
    color: var(--color-text-muted);
}

.settings-account__bio {
    margin-top: 3px;
    font-family: var(--font-body);
    font-size: 0.82rem;
    line-height: 1.3;
    color: var(--color-text-secondary);
    /* Two lines max, then ellipsis. */
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
}

/* ── Identity: guest CTA ──────────────────────────────────────────── */

.settings-guest {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 6px;
    padding: 22px 18px;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border-subtle);
}

.settings-guest__icon {
    width: 46px;
    height: 46px;
    border-radius: var(--radius-full);
    display: grid;
    place-items: center;
    background: var(--color-surface-sunken);
    color: var(--color-accent);
    margin-bottom: 2px;
}

.settings-guest__icon svg {
    width: 24px;
    height: 24px;
}

.settings-guest__title {
    font-family: var(--font-title);
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--color-text);
    margin: 0;
}

.settings-guest__subtitle {
    font-family: var(--font-body);
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin: 0;
    max-width: 34ch;
}

.settings-guest__actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    max-width: 280px;
    margin-top: 8px;
}

/* Ambos son <button> (abren el auth sheet en sitio, ya no navegan): reset del
   chrome nativo para que sigan leyéndose como los CTA que eran. */
.settings-guest__cta {
    padding: 11px 16px;
    border: 0;
    border-radius: var(--radius-full);
    background: var(--color-accent);
    color: var(--color-on-accent);
    font-family: var(--font-title);
    font-weight: 700;
    font-size: 0.92rem;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}

.settings-guest__login {
    padding: 9px 16px;
    border: 0;
    border-radius: var(--radius-full);
    background: transparent;
    color: var(--color-text-secondary);
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 0.88rem;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}

/* ── Section titles + groups ──────────────────────────────────────── */

.settings-section-title {
    font-family: var(--font-body);
    font-size: 0.74rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--color-text-subtle);
    margin: 14px 6px 2px;
}

.settings-group {
    display: flex;
    flex-direction: column;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border-subtle);
    overflow: hidden;
}

/* Hairline between rows, not before the first. */
.settings-group > * + *,
.settings-group > .settings-details + *,
.settings-group > * + .settings-details {
    border-top: 1px solid var(--color-border-subtle);
}

/* ── Rows ─────────────────────────────────────────────────────────── */

.settings-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 13px 14px;
    min-height: 52px;
    background: transparent;
    border: none;
    text-align: left;
    font-family: var(--font-body);
    color: var(--color-text);
    text-decoration: none;
    box-sizing: border-box;
}

button.settings-row {
    cursor: pointer;
}

.settings-row--link:active {
    background: var(--color-surface-sunken);
}

.settings-row__icon {
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    border-radius: var(--radius-md);
    display: grid;
    place-items: center;
    background: var(--color-surface-sunken);
    color: var(--color-text-secondary);
}

.settings-row__icon svg {
    width: 18px;
    height: 18px;
}

.settings-row__label {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: 1px;
    font-size: 0.92rem;
    font-weight: 500;
    min-width: 0;
}

.settings-row__hint {
    font-size: 0.76rem;
    font-weight: 400;
    color: var(--color-text-muted);
}

.settings-row__value {
    flex: 0 0 auto;
    font-size: 0.85rem;
    color: var(--color-text-muted);
    max-width: 50%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.settings-row__chev {
    flex: 0 0 auto;
    width: 18px;
    height: 18px;
    color: var(--color-text-subtle);
}

.settings-row--static {
    cursor: default;
}

.settings-row[data-danger] {
    color: var(--color-live);
}

.settings-row[data-danger] .settings-row__icon {
    color: var(--color-live);
}

/* Stacked row (label on top, control full-width below) — the theme picker. */
.settings-row--stack {
    flex-wrap: wrap;
}

.settings-row--stack .settings-segmented {
    flex: 1 1 100%;
    margin-left: 42px;
    margin-top: 2px;
}

/* ── Segmented theme control ──────────────────────────────────────── */

.settings-segmented {
    display: flex;
    gap: 4px;
    padding: 3px;
    background: var(--color-surface-sunken);
    border-radius: var(--radius-full);
}

.settings-segmented__btn {
    flex: 1 1 0;
    padding: 7px 8px;
    border: none;
    background: transparent;
    border-radius: var(--radius-full);
    font-family: var(--font-body);
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
}

.settings-segmented__btn--active {
    background: var(--color-surface);
    color: var(--color-text);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14);
}

/* ── Language disclosure ──────────────────────────────────────────── */

.settings-details summary {
    list-style: none;
    cursor: pointer;
}

.settings-details summary::-webkit-details-marker {
    display: none;
}

.settings-details[open] summary .settings-row__chev {
    transform: rotate(180deg);
}

.settings-lang-list {
    display: flex;
    flex-direction: column;
    padding: 2px 0 6px;
    background: var(--color-surface-sunken);
}

.settings-lang {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px 10px 56px;
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--color-text);
    text-decoration: none;
}

.settings-lang--active {
    font-weight: 700;
    color: var(--color-accent);
}

.settings-lang svg {
    width: 18px;
    height: 18px;
}

.settings-lang:active {
    background: var(--color-surface);
}

/* ── Switch ───────────────────────────────────────────────────────── */

.settings-switch {
    flex: 0 0 auto;
    border: none;
    background: transparent;
    padding: 0;
    cursor: pointer;
}

.settings-switch__track {
    display: block;
    width: 44px;
    height: 26px;
    border-radius: var(--radius-full);
    background: var(--color-surface-sunken);
    border: 1px solid var(--color-border-subtle);
    position: relative;
    transition: background 0.16s ease, border-color 0.16s ease;
}

.settings-switch__thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    border-radius: var(--radius-full);
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    transition: transform 0.16s ease;
}

.settings-switch[aria-checked="true"] .settings-switch__track {
    background: var(--color-accent);
    border-color: var(--color-accent);
}

.settings-switch[aria-checked="true"] .settings-switch__thumb {
    transform: translateX(18px);
}

/* ── Logout ───────────────────────────────────────────────────────── */

.settings-logout {
    margin-top: 12px;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border-subtle);
    overflow: hidden;
}

/* ── Bottom-sheet (download chooser) ──────────────────────────────── */

.settings-sheet {
    border: none;
    padding: 0;
    background: transparent;
    max-width: 100%;
    width: 100%;
    margin: auto auto 0;
    color: var(--color-text);
}

.settings-sheet::backdrop {
    background: rgba(0, 0, 0, 0.5);
}

.settings-sheet__inner {
    background: var(--color-surface);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 10px 18px calc(20px + env(safe-area-inset-bottom));
    max-width: 520px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.settings-sheet__handle {
    width: 40px;
    height: 4px;
    border-radius: var(--radius-full);
    background: var(--color-border-subtle);
    margin: 2px auto 6px;
}

.settings-sheet__title {
    font-family: var(--font-title);
    font-weight: 700;
    font-size: 1.15rem;
    margin: 0;
    text-align: center;
}

.settings-sheet__subtitle {
    font-family: var(--font-body);
    font-size: 0.85rem;
    color: var(--color-text-muted);
    text-align: center;
    margin: 0 0 4px;
}

.settings-sheet__options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.settings-store {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border-subtle);
    background: var(--color-surface-sunken);
    color: var(--color-text);
    text-decoration: none;
}

.settings-store:active {
    opacity: 0.85;
}

.settings-store__text {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    font-family: var(--font-title);
    font-weight: 700;
    font-size: 1rem;
    line-height: 1.2;
}

.settings-store__text small {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: 0.72rem;
    color: var(--color-text-muted);
}

.settings-sheet__close {
    margin-top: 4px;
    padding: 11px;
    border: none;
    background: transparent;
    color: var(--color-text-secondary);
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
}

/* Confirm CTA inside a sheet (e.g. the logout confirmation). */
.settings-sheet__confirm {
    width: 100%;
    padding: 13px 16px;
    border: none;
    border-radius: var(--radius-full);
    font-family: var(--font-title);
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
    background: var(--color-accent);
    color: var(--color-on-accent);
}

.settings-sheet__confirm--danger {
    background: var(--color-live);
    color: #fff;
}

/* ── Edit-profile modal + cropper ─────────────────────────────────── */

.pe-modal {
    border: none;
    padding: 0;
    background: transparent;
    width: 100%;
    max-width: 100%;
    max-height: 92vh;
    margin: auto auto 0; /* bottom-sheet, like the download + install modals */
    color: var(--color-text);
}

.pe-modal::backdrop {
    background: rgba(0, 0, 0, 0.55);
}

.pe-modal__inner {
    background: var(--color-surface);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 0 18px calc(18px + env(safe-area-inset-bottom));
    max-width: 520px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-height: 92vh;
    overflow-y: auto;
}

.pe-modal__head {
    position: sticky;
    top: 0;
    display: grid;
    grid-template-columns: 40px 1fr auto;
    align-items: center;
    gap: 8px;
    padding: 12px 0;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border-subtle);
    z-index: 1;
}

.pe-modal__close {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border: none;
    background: transparent;
    color: var(--color-text-secondary);
    cursor: pointer;
}

.pe-modal__close svg {
    width: 20px;
    height: 20px;
}

.pe-modal__title {
    font-family: var(--font-title);
    font-weight: 700;
    font-size: 1.05rem;
    text-align: center;
    margin: 0;
}

.pe-modal__save {
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-full);
    background: var(--color-accent);
    color: var(--color-on-accent);
    font-family: var(--font-title);
    font-weight: 700;
    font-size: 0.86rem;
    cursor: pointer;
}

.pe-modal__save:disabled {
    opacity: 0.55;
    cursor: default;
}

.pe-crop-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.pe-crop {
    position: relative;
    width: 200px;
    height: 200px;
    border-radius: var(--radius-full);
    overflow: hidden;
    background: var(--color-accent);
    color: var(--color-on-accent);
    display: grid;
    place-items: center;
    cursor: grab;
    touch-action: none;
    user-select: none;
}

.pe-crop:active {
    cursor: grabbing;
}

.pe-crop__initials {
    font-family: var(--font-title);
    font-weight: 700;
    font-size: 3rem;
    letter-spacing: 1px;
}

.pe-crop__img {
    position: absolute;
    max-width: none;
    pointer-events: none;
}

/* Static preview of the current avatar shown when the modal opens — fills the
   circle (cover) without the cropper's inline positioning. Picking a new file
   removes this class and hands the <img> back to the cropper geometry. */
.pe-crop__img--preview {
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.pe-crop__ring {
    position: absolute;
    inset: 0;
    border-radius: var(--radius-full);
    box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.7);
    pointer-events: none;
}

.pe-crop__zoom {
    width: 200px;
    accent-color: var(--color-accent);
}

.pe-crop__pick {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 16px;
    border-radius: var(--radius-full);
    border: 1px solid var(--color-border-subtle);
    background: var(--color-surface-sunken);
    color: var(--color-text);
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 0.86rem;
    cursor: pointer;
}

.pe-crop__pick svg {
    width: 16px;
    height: 16px;
}

.pe-field {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.pe-field__label {
    font-family: var(--font-body);
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--color-text-subtle);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.pe-field__input {
    width: 100%;
    box-sizing: border-box;
    padding: 11px 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border-subtle);
    background: var(--color-surface-sunken);
    color: var(--color-text);
    font-family: var(--font-body);
    font-size: 0.95rem;
}

.pe-field__input:focus {
    outline: none;
    border-color: var(--color-accent);
}

.pe-field__textarea {
    resize: vertical;
    min-height: 64px;
}

.pe-handle {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 0;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    background: var(--color-surface-sunken);
}

.pe-handle__at {
    font-family: var(--font-title);
    font-weight: 700;
    font-size: 0.95rem;
}

.pe-handle__note {
    font-family: var(--font-body);
    font-size: 0.76rem;
    color: var(--color-text-muted);
}

.pe-error {
    margin: 0;
    color: var(--color-live);
    font-family: var(--font-body);
    font-size: 0.85rem;
    text-align: center;
}

/* Save button loading spinner — the sheet must never look frozen mid-save. */
.pe-modal__save.is-loading {
    color: transparent;
    position: relative;
    pointer-events: none;
}

.pe-modal__save.is-loading::after {
    content: "";
    position: absolute;
    inset: 0;
    margin: auto;
    width: 15px;
    height: 15px;
    border: 2px solid var(--color-on-accent);
    border-top-color: transparent;
    border-radius: 50%;
    animation: pe-spin 0.6s linear infinite;
}

@keyframes pe-spin {
    to { transform: rotate(360deg); }
}

/* ── Timezone picker (bottom-sheet with client search) ────────────────── */

/* Timezone search — reuses the shared in-modal search atoms
   (.select-modal-search-input + .select-modal-search-icon, select-modal.css)
   so it matches every other modal searchbox in the app. Only the wrapper is
   re-scoped for the settings bottom-sheet: no divider and no extra inset (the
   sheet already pads via .settings-sheet__inner + gap), and the icon slides
   left to compensate for the removed wrapper padding. */
.settings-tz-search.select-modal-search {
    padding: 0;
    border-bottom: none;
}

.settings-tz-search .select-modal-search-icon {
    left: 12px;
}

.settings-tz-list {
    /* Fixed height (not max-height) so the sheet keeps its initial size when
       the search narrows the list to a few rows or none — no springing /
       collapse. The empty-state message lives inside and centers via margin. */
    height: 46vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    margin: 0 -6px;
}

.settings-tz-row {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 11px 8px;
    border: none;
    background: transparent;
    text-align: left;
    color: var(--color-text);
    font-family: var(--font-body);
    font-size: 0.92rem;
    cursor: pointer;
    border-radius: var(--radius-md);
}

.settings-tz-row:hover {
    background: var(--color-surface-sunken);
}

.settings-tz-row__name {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.settings-tz-row__off {
    flex: 0 0 auto;
    font-size: 0.8rem;
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
}

.settings-tz-row--active {
    color: var(--color-accent);
    font-weight: 700;
}

.settings-tz-row--active .settings-tz-row__off {
    color: var(--color-accent);
}

.settings-tz-empty {
    margin: auto;
    padding: 20px 8px;
    text-align: center;
    color: var(--color-text-muted);
    font-family: var(--font-body);
    font-size: 0.88rem;
}
}
