/* The Me page: stacked cards on a phone, one Connections list on a laptop (spec §4). */
.me-page {
    flex: 1;
    overflow: auto;
    padding: 16px 14px 24px;
}

.me-inner {
    display: flex;
    width: 100%;
    max-width: 560px;
    flex-direction: column;
    gap: 12px;
    margin: 0 auto;
}

.me-title {
    font-family: var(--font-display);
    margin: 4px 2px;
    font-size: 1.5rem;
    font-weight: 750;
    letter-spacing: -.02em;
}

.me-profile,
.me-card {
    padding: 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-raised);
}

.me-profile {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 12px;
}

.me-profile-text {
    min-width: 0;
}

.profile-name,
.profile-phone,
.me-row-desc,
.ai-app-desc {
    overflow-wrap: anywhere;
}

.profile-phone {
    margin: 2px 0 0;
    color: var(--color-text-muted);
    font-size: .85rem;
}

.profile-initials {
    font-weight: 700;
}

.profile-initials:not(:empty) + svg {
    display: none;
}

.me-label {
    margin: 8px 2px 0;
    color: var(--color-text-muted);
    font-size: .72rem;
    font-weight: 650;
    letter-spacing: .06em;
    text-transform: uppercase;
}

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

.me-row {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 12px;
}

.me-row-text,
.ai-app-text {
    display: flex;
    min-width: 0;
    flex: 1;
    flex-direction: column;
}

.me-row-name,
.ai-app-name {
    margin: 0;
    font-size: .95rem;
    font-weight: 650;
}

.me-row-desc,
.ai-app-desc {
    margin: 0;
    color: var(--color-text-muted);
    font-size: .8rem;
}

.me-moodle-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

.app-logo {
    display: grid;
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    place-items: center;
    border: 1px solid var(--color-border);
    border-radius: 9px;
    background: var(--color-surface);
}

.app-logo svg {
    width: 20px;
    height: 20px;
}

.app-logo-moodle svg {
    stroke: var(--moodle-orange);
}

.status-badge {
    display: inline-flex;
    flex: none;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--status-upcoming-bg);
    color: var(--color-text-muted);
    font-size: .75rem;
    font-weight: 650;
    white-space: nowrap;
}

.status-badge::before {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    content: "";
}

#meMoodle[data-state="connected"] #meMoodleBadge,
.ai-connect-btn[data-state="connected"] .ai-app-badge {
    background: var(--status-present-bg);
    color: var(--color-success);
}

.status-badge.is-soon {
    border: 1px dashed var(--color-border-strong);
    background: transparent;
}

.status-badge.is-soon::before {
    display: none;
}

.ai-apps {
    display: flex;
    gap: 12px;
    margin: 4px 0;
    padding: 0;
    list-style: none;
}

.ai-app-action {
    display: none;
}


@media (max-width: 720px) {
    .ai-app-text,
    .ai-app-badge,
    .ai-connect-btn .status-badge {
        display: none;
    }

    .ai-connect-btn .app-logo {
        border: 0;
        background: transparent;
    }

    .me-page {
        padding-bottom: calc(24px + var(--safe-bottom));
    }
}

@media (min-width: 721px) {
    .me-page {
        padding: 28px 24px;
    }

    .me-inner {
        display: grid;
        grid-template-areas: "title title" "profile logout" "label label" "connections connections"
            "appearance-label appearance-label" "appearance appearance";
        grid-template-columns: 1fr auto;
        align-items: center;
        gap: 14px 16px;
    }

    .me-title {
        grid-area: title;
    }

    .me-profile {
        grid-area: profile;
        padding: 0;
        border: 0;
        background: transparent;
    }

    .me-profile .profile-avatar {
        width: 52px;
        height: 52px;
        flex-basis: 52px;
    }

    .logout-button {
        width: auto;
        margin: 0;
        grid-area: logout;
    }

    .me-label {
        grid-area: label;
    }

    .me-connections {
        gap: 0;
        overflow: hidden;
        border: 1px solid var(--color-border);
        border-radius: var(--radius-md);
        background: var(--color-surface-raised);
        grid-area: connections;
    }

    .me-label-appearance {
        grid-area: appearance-label;
    }

    #meAppearance {
        padding: 14px;
        border: 1px solid var(--color-border);
        border-radius: var(--radius-md);
        background: var(--color-surface-raised);
        grid-area: appearance;
    }

    .me-card {
        padding: 0;
        border: 0;
        border-radius: 0;
        background: transparent;
    }

    /* The button stays inline while it fits, and drops to its own line when it does not. */
    .me-moodle {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 8px 12px;
        padding: 12px 16px;
    }

    .me-moodle .me-row {
        flex: 1 1 320px;
    }

    .me-moodle-actions {
        max-width: 100%;
        margin: 0 0 0 auto;
    }

    .me-moodle .moodle-btn {
        width: auto;
        max-width: 100%;
        min-height: 36px;
        padding: 0 14px;
        overflow-wrap: anywhere;
    }

    .ai-connect-title {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
    }

    .ai-apps {
        flex-direction: column;
        gap: 0;
        margin: 0;
    }

    .ai-apps li {
        border-top: 1px solid var(--color-border);
    }

    .ai-connect-btn {
        display: flex;
        width: 100%;
        height: auto;
        min-height: 64px;
        align-items: center;
        gap: 12px;
        padding: 12px 16px;
        border: 0;
        border-radius: 0;
        background: transparent;
        color: var(--color-text);
        text-align: left;
    }

    .ai-connect-btn:hover {
        background: var(--color-surface-hover);
    }

    .ai-connect-btn[data-state="connected"]::after {
        display: none;
    }

    .ai-connect-btn.is-disabled {
        opacity: .6;
    }

    .ai-app-action {
        display: inline-flex;
        min-height: 32px;
        align-items: center;
        padding: 0 12px;
        border-radius: 7px;
        background: var(--brand-gradient);
        color: var(--color-on-strong);
        font-size: .82rem;
        font-weight: 650;
    }

    .ai-connect-btn[data-state="connected"] .ai-app-action {
        border: 1px solid var(--color-border);
        background: var(--color-surface);
        color: var(--color-text);
    }

    .ai-apps-title,
    .ai-grants {
        margin: 0;
        padding: 10px 16px;
        border-top: 1px solid var(--color-border);
    }

    /* The link and the guides are rows of the same list. */
    .ai-link-row,
    .ai-guide {
        border: 0;
        border-top: 1px solid var(--color-border);
        border-radius: 0;
    }

    .ai-link-row {
        padding: 10px 16px;
    }

    .ai-guide summary {
        padding: 12px 16px;
    }

    .ai-steps {
        padding: 12px 16px 12px 36px;
    }

    .ai-guide-note {
        padding: 0 16px 12px;
    }
}

/* Appearance: three mini previews; the current one has a brand-red ring and a ✓. */
.theme-tiles {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.theme-tile {
    min-height: var(--touch-target);
    padding: 6px;
    border: 2px solid transparent;
    border-radius: 14px;
    background: transparent;
    color: var(--color-text-muted);
    font-size: .75rem;
    text-align: center;
}

.theme-tile[aria-pressed="true"] {
    border-color: var(--color-brand);
    color: var(--color-text);
}

.theme-swatch {
    position: relative;
    display: block;
    height: 74px;
    margin-bottom: 6px;
    overflow: hidden;
    border-radius: 10px;
}

.theme-swatch-glow {
    background: var(--swatch-glow-bg);
}

.theme-swatch-ember {
    background: var(--swatch-ember-bg);
}

.theme-swatch-paper {
    border: 1px solid var(--swatch-paper-border);
    background: var(--swatch-paper-bg);
}

.swatch-band {
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 32px;
    background: var(--swatch-glow-band);
}

.swatch-line {
    position: absolute;
    top: 14px;
    right: 8px;
    left: 8px;
    height: 6px;
    border-radius: 4px;
}

.theme-swatch-glow .swatch-line {
    top: 44px;
    background: var(--swatch-glow-line);
}

.theme-swatch-ember .swatch-line {
    background: var(--swatch-ember-line);
}

.theme-swatch-paper .swatch-line {
    background: var(--swatch-paper-line);
}

.swatch-line-short {
    top: 26px;
    right: auto;
    width: 40%;
}

.swatch-dot {
    position: absolute;
    bottom: 8px;
    left: 8px;
    width: 16px;
    height: 16px;
    border-radius: 6px;
}

.theme-swatch-glow .swatch-dot {
    background: var(--swatch-glow-dot);
}

.theme-swatch-ember .swatch-dot {
    background: var(--swatch-ember-dot);
}

.theme-swatch-paper .swatch-dot {
    background: var(--swatch-paper-dot);
}

.swatch-check {
    position: absolute;
    top: 6px;
    right: 6px;
    display: none;
    width: 16px;
    height: 16px;
    place-items: center;
    border-radius: 50%;
    background: var(--color-brand);
    color: var(--color-on-strong);
    font-size: .6rem;
}

.theme-tile[aria-pressed="true"] .swatch-check {
    display: grid;
}

.me-note {
    margin: 10px 0 0;
    color: var(--color-text-muted);
    font-size: .8rem;
}

/* Scheduling details can include several courses; keep them readable on phones. */
#moodleSyncHint {
    overflow-wrap: anywhere;
    line-height: 1.5;
}
