.settings-body {
    overflow: auto;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--bg);
}

.settings-shell {
    max-width: 720px;
    margin: 0 auto;
    padding: 0 20px calc(60px + env(safe-area-inset-bottom, 0px));
}

.settings-topbar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 20px 0;
    padding-top: calc(20px + env(safe-area-inset-top, 0px));
}

.settings-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 9px;
    color: var(--text);
    text-decoration: none;
    transition: background 0.2s, color 0.2s;
}
.settings-back:hover { background: rgba(255,255,255,0.06); color: var(--white); }
.settings-back svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

@media (min-width: 701px) {
    .settings-back {
        position: fixed;
        top: calc(16px + env(safe-area-inset-top, 0px));
        left: 16px;
        z-index: 50;
        background: rgba(15, 23, 42, 0.55);
        border: 1px solid rgba(255, 255, 255, 0.1);
        backdrop-filter: blur(6px);
    }
}

.settings-topbar h1 {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--white);
}

.settings-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 24px;
    overflow-x: auto;
}

.settings-tab {
    padding: 10px 14px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--muted);
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.15s, border-color 0.15s;
}
.settings-tab:hover { color: var(--text); }
.settings-tab.active { color: var(--amber); border-bottom-color: var(--amber); }

.settings-panel.active { display: block; }

.settings-card {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px;
    margin-bottom: 16px;
}

.settings-card h2 {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    color: var(--white);
    margin-bottom: 6px;
}

.settings-card-sub {
    font-size: 0.82rem;
    color: var(--muted);
    line-height: 1.5;
    margin-bottom: 14px;
}

.settings-card-danger { border-color: rgba(239, 68, 68, 0.25); }

.settings-field-row {
    display: flex;
    gap: 10px;
}

.settings-field-row input[type="text"],
.settings-field-row input[type="password"],
.settings-field-row input[type="email"] {
    flex: 1;
    height: 42px;
    padding: 0 14px;
    border-radius: 9px;
    background: var(--bg);
    border: 1px solid rgba(255,255,255,0.1);
    color: var(--white);
    font-family: 'Inter', sans-serif;
    font-size: 16px;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.settings-field-row input:focus {
    outline: none;
    border-color: rgba(255,145,0,0.4);
    box-shadow: 0 0 0 3px rgba(255,145,0,0.1);
}
.settings-field-row input:disabled {
    color: var(--muted);
    cursor: not-allowed;
    opacity: 0.7;
}

.settings-char-counter {
    font-size: 0.72rem;
    color: var(--muted);
    text-align: right;
    margin-top: 6px;
    font-variant-numeric: tabular-nums;
}

/* (New) Username row under the display name field — same visual
   treatment as the disabled/greyed email input on the Security tab
   (var(--muted), no interactivity implied), so it reads as "this is
   informational, not editable here" at a glance. Deliberately NOT an
   <input disabled> like the email field — a username has no natural
   "field" affordance here (there's nothing to submit), so a plain
   greyed label is the honester representation. */
.settings-username-row {
    margin-top: 10px;
}
.settings-username-label {
    font-size: 0.82rem;
    color: var(--muted);
    font-family: 'Inter', sans-serif;
}

.settings-inline-link {
    color: var(--amber);
    text-decoration: underline;
    text-decoration-color: rgba(255,145,0,0.35);
    text-underline-offset: 2px;
}
.settings-inline-link:hover { text-decoration-color: var(--amber); }

.settings-toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.settings-toggle-pair {
    display: flex;
    gap: 36px;
}

.settings-toggle-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
}

.settings-toggle-label { font-size: 0.86rem; color: var(--text); }

.settings-toggle-desc {
    font-size: 0.74rem;
    color: var(--muted);
    line-height: 1.45;
    max-width: 220px;
}

.settings-switch {
    position: relative;
    width: 44px;
    height: 26px;
    border-radius: 100px;
    background: rgba(255,255,255,0.12);
    border: none;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.2s;
}
.settings-switch.is-on { background: var(--amber); }
.settings-switch:disabled { opacity: 0.4; cursor: not-allowed; }

.settings-switch-knob {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--white);
    transition: transform 0.2s;
}
.settings-switch.is-on .settings-switch-knob { transform: translateX(18px); }

.settings-btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }

.settings-hint {
    font-size: 0.76rem;
    color: var(--muted);
    line-height: 1.5;
    margin-top: 10px;
}

.settings-warning {
    font-size: 0.78rem;
    color: #fca5a5;
    line-height: 1.5;
}
.settings-warning strong { color: var(--red); }

.settings-pin-status {
    font-size: 0.82rem;
    color: var(--text);
    margin-bottom: 12px;
}

.settings-error {
    font-size: 0.8rem;
    color: var(--red);
    margin-top: 10px;
}

.settings-future-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.settings-future-list li {
    font-size: 0.85rem;
    color: var(--text);
    line-height: 1.5;
    padding-left: 18px;
    position: relative;
}
.settings-future-list li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 8px;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--amber);
}

/* ── DEVICES LIST ── */
.settings-devices-box {
    max-height: 320px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    padding: 4px;
    margin-top: 14px;
}

.settings-devices-placeholder {
    padding: 32px 16px;
    text-align: center;
    color: var(--muted);
    font-size: 0.82rem;
}

.device-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 10px;
    border-bottom: 1px solid var(--border);
    transition: background 1.2s ease;
}
.device-row:last-child { border-bottom: none; }

/* (New) Brief highlight flash for a device row that just appeared or
   just had its timestamps bumped by a live socket push — gives the
   "instant update" a visible confirmation instead of it just silently
   changing underneath the person's cursor. Added/removed by settings.js;
   fades out over the transition above rather than cutting off sharply. */
.device-row.just-updated {
    background: rgba(255, 145, 0, 0.08);
}

.device-icon {
    width: 36px;
    height: 36px;
    border-radius: 9px;
    background: var(--amber-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.device-icon svg {
    width: 17px;
    height: 17px;
    stroke: var(--amber);
    fill: none;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.device-icon svg.icon-solid {
    fill: var(--amber);
    stroke: none;
}

.device-info { flex: 1; min-width: 0; }

.device-info-primary {
    font-size: 0.86rem;
    font-weight: 500;
    color: var(--white);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.device-info-secondary {
    font-size: 0.74rem;
    color: var(--muted);
    margin-top: 2px;
    font-variant-numeric: tabular-nums;
}

.device-current-badge {
    font-size: 0.63rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--green);
    background: var(--green-dim);
    padding: 2px 7px;
    border-radius: 100px;
}

.device-logout-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 9px;
    flex-shrink: 0;
    color: var(--muted);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}
.device-logout-btn:hover:not(:disabled) { background: rgba(239,68,68,0.1); color: var(--red); }
.device-logout-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.device-logout-btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ── Toast ── */
.profile-toast {
    position: fixed;
    left: 50%;
    bottom: calc(28px + env(safe-area-inset-bottom, 0px));
    transform: translate(-50%, 12px);
    opacity: 0;
    pointer-events: none;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: calc(100vw - 40px);
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 11px;
    padding: 13px 18px;
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--white);
    box-shadow: 0 16px 40px rgba(0,0,0,0.4);
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 999;
}

.profile-toast::before {
    content: '';
    width: 7px;
    height: 7px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--muted);
}

.profile-toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
    pointer-events: auto;
}

.profile-toast.success { border-color: rgba(74, 222, 128, 0.3); }
.profile-toast.success::before { background: #4ade80; box-shadow: 0 0 8px rgba(74,222,128,0.6); }

.profile-toast.error { border-color: rgba(239, 68, 68, 0.3); }
.profile-toast.error::before { background: #ef4444; box-shadow: 0 0 8px rgba(239,68,68,0.6); }

@media (max-width: 560px) {
    .settings-shell { padding: 0 14px calc(50px + env(safe-area-inset-bottom, 0px)); }
    .settings-card { padding: 16px; }
    .profile-toast { bottom: calc(20px + env(safe-area-inset-bottom, 0px)); }
}