/* ==========================================================================
   TestFlight Hub — iOS-style design system
   Tokens follow Apple's system palette / type scale / HIG spacing so the
   site reads as "an Apple device" rather than a generic responsive web app.
   ========================================================================== */

:root {
    color-scheme: light;

    /* System colors (light) */
    --tf-blue: #007AFF;
    --tf-blue-fill: var(--tf-blue);
    --tf-green: #34C759;
    --tf-red: #FF3B30;
    --tf-orange: #FF9500;
    --tf-yellow: #FFCC00;
    --tf-purple: #AF52DE;
    --tf-teal: #30B0C7;

    --tf-gray: #8E8E93;
    --tf-gray2: #AEAEB2;
    --tf-gray3: #C7C7CC;
    --tf-gray4: #D1D1D6;
    --tf-gray5: #E5E5EA;
    --tf-gray6: #F2F2F7;

    /* Backgrounds */
    --tf-bg: #FFFFFF;
    --tf-bg-grouped: #F2F2F7;
    --tf-bg-secondary: #F2F2F7;
    --tf-bg-secondary-grouped: #FFFFFF;
    --tf-bg-tertiary-grouped: #FFFFFF;
    --tf-bg-elevated: rgba(255, 255, 255, 0.82);

    /* Labels */
    --tf-label: rgba(0, 0, 0, 0.92);
    --tf-label-secondary: rgba(60, 60, 67, 0.6);
    --tf-label-tertiary: rgba(60, 60, 67, 0.3);
    --tf-label-quaternary: rgba(60, 60, 67, 0.18);
    --tf-on-accent: #FFFFFF;

    --tf-separator: rgba(60, 60, 67, 0.29);
    --tf-separator-opaque: #C6C6C8;

    --tf-radius-sm: 10px;
    --tf-radius-md: 14px;
    --tf-radius-lg: 20px;
    --tf-safe-top: env(safe-area-inset-top, 0px);
    --tf-safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;

        --tf-blue: #0A84FF;
        --tf-blue-fill: var(--tf-blue);
        --tf-btn-secondary-text: #4DA3FF;
        --tf-green: #30D158;
        --tf-red: #FF453A;
        --tf-orange: #FF9F0A;
        --tf-yellow: #FFD60A;
        --tf-purple: #BF5AF2;
        --tf-teal: #40C8E0;

        --tf-gray: #8E8E93;
        --tf-gray2: #636366;
        --tf-gray3: #48484A;
        --tf-gray4: #3A3A3C;
        --tf-gray5: #2C2C2E;
        --tf-gray6: #1C1C1E;

        --tf-bg: #000000;
        --tf-bg-grouped: #000000;
        --tf-bg-secondary: #1C1C1E;
        --tf-bg-secondary-grouped: #1C1C1E;
        --tf-bg-tertiary-grouped: #2C2C2E;
        --tf-bg-elevated: rgba(28, 28, 30, 0.78);

        --tf-label: rgba(255, 255, 255, 0.92);
        --tf-label-secondary: rgba(235, 235, 245, 0.6);
        --tf-label-tertiary: rgba(235, 235, 245, 0.3);
        --tf-label-quaternary: rgba(235, 235, 245, 0.16);

        --tf-separator: rgba(84, 84, 88, 0.6);
        --tf-separator-opaque: #38383A;
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --tf-btn-secondary-text: #4DA3FF;

    --tf-blue: #0A84FF;
    --tf-blue-fill: var(--tf-blue);
    --tf-green: #30D158;
    --tf-red: #FF453A;
    --tf-orange: #FF9F0A;
    --tf-yellow: #FFD60A;
    --tf-purple: #BF5AF2;
    --tf-teal: #40C8E0;

    --tf-gray: #8E8E93;
    --tf-gray2: #636366;
    --tf-gray3: #48484A;
    --tf-gray4: #3A3A3C;
    --tf-gray5: #2C2C2E;
    --tf-gray6: #1C1C1E;

    --tf-bg: #000000;
    --tf-bg-grouped: #000000;
    --tf-bg-secondary: #1C1C1E;
    --tf-bg-secondary-grouped: #1C1C1E;
    --tf-bg-tertiary-grouped: #2C2C2E;
    --tf-bg-elevated: rgba(28, 28, 30, 0.78);

    --tf-label: rgba(255, 255, 255, 0.92);
    --tf-label-secondary: rgba(235, 235, 245, 0.6);
    --tf-label-tertiary: rgba(235, 235, 245, 0.3);
    --tf-label-quaternary: rgba(235, 235, 245, 0.16);

    --tf-separator: rgba(84, 84, 88, 0.6);
    --tf-separator-opaque: #38383A;
}

/*
 * Increase Contrast support. Apple's own secondaryLabel (rgba(60,60,67,.6)
 * light / rgba(235,235,245,.6) dark) and systemBlue button fill both land a
 * little under WCAG's 4.5:1 for body-sized text against a plain white or
 * pure-black surface — true of Apple's own apps too. The HIG's mitigation
 * (accessibility.md > Vision) is to supply a higher-contrast pass for the
 * Increase Contrast setting, so we do that here rather than change the
 * default system-accurate colors.
 *
 * --tf-blue (text/icons on the page background) and --tf-blue-fill (a solid
 * button fill carrying white text) need to move in OPPOSITE directions in
 * dark mode: darker text needs to get lighter to read against black, while
 * a lighter fill needs to get darker so white text stays legible on it.
 * Verified: #0056CC white text 6.6:1 / as fill 6.6:1 (light); #4DA3FF text
 * on black 7.9:1 (dark); #0040DD white-on-fill 7.6:1 (dark).
 */
@media (prefers-contrast: more) {
    :root {
        --tf-label-secondary: rgba(60, 60, 67, 0.86);
        --tf-blue: #0056CC;
        --tf-blue-fill: #0056CC;
        --tf-separator-opaque: #8E8E93;
    }
}

@media (prefers-contrast: more) and (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --tf-label-secondary: rgba(235, 235, 245, 0.86);
        --tf-blue: #4DA3FF;
        --tf-blue-fill: #0040DD;
        --tf-separator-opaque: #8E8E93;
    }
}

@media (prefers-contrast: more) {
    :root[data-theme="dark"] {
        --tf-label-secondary: rgba(235, 235, 245, 0.86);
        --tf-blue: #4DA3FF;
        --tf-blue-fill: #0040DD;
        --tf-separator-opaque: #8E8E93;
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--tf-bg-grouped);
    color: var(--tf-label);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

body.tf-body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
    min-height: 100dvh;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
img { max-width: 100%; display: block; }

/* Type scale ------------------------------------------------------------- */
.tf-large-title { font-size: 34px; line-height: 41px; font-weight: 700; letter-spacing: 0.37px; margin: 0; }
.tf-title1 { font-size: 28px; line-height: 34px; font-weight: 700; margin: 0; }
.tf-title2 { font-size: 22px; line-height: 28px; font-weight: 700; margin: 0; }
.tf-title3 { font-size: 20px; line-height: 25px; font-weight: 600; margin: 0; }
.tf-headline { font-size: 17px; line-height: 22px; font-weight: 600; margin: 0; }
.tf-body { font-size: 17px; line-height: 22px; font-weight: 400; margin: 0; }
.tf-callout { font-size: 16px; line-height: 21px; margin: 0; }
.tf-subheadline { font-size: 15px; line-height: 20px; margin: 0; }
.tf-footnote { font-size: 13px; line-height: 18px; margin: 0; color: var(--tf-label-secondary); }
.tf-caption1 { font-size: 12px; line-height: 16px; margin: 0; color: var(--tf-label-secondary); }

.tf-eyebrow {
    display: inline-block;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.2px;
    color: var(--tf-blue);
    text-transform: uppercase;
    margin-bottom: 4px;
}

.tf-text-secondary { color: var(--tf-label-secondary); }
.tf-text-center { text-align: center; }

/* App shell / layout ------------------------------------------------------ */
.tf-app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
}

.tf-nav-bar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: calc(10px + var(--tf-safe-top)) 16px 10px;
    background: var(--tf-bg-elevated);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 0.5px solid var(--tf-separator);
}

.tf-nav-bar h1 { font-size: 17px; font-weight: 600; margin: 0; }
.tf-nav-action { color: var(--tf-blue); font-size: 17px; font-weight: 400; background: none; border: none; padding: 4px; cursor: pointer; }
.tf-nav-action.destructive { color: var(--tf-red); }

.tf-large-title-header {
    padding: 8px 16px 12px;
}

.tf-content {
    flex: 1;
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
    padding: 16px 16px calc(96px + var(--tf-safe-bottom));
}

.tf-desktop-header { display: none; }

/* Tab bar (phone widths) --------------------------------------------------- */
.tf-tab-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    display: flex;
    background: var(--tf-bg-elevated);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-top: 0.5px solid var(--tf-separator);
    padding-bottom: var(--tf-safe-bottom);
}

.tf-tab-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 4px 6px;
    color: var(--tf-gray);
    font-size: 10px;
    font-weight: 500;
}

.tf-tab-item svg { width: 26px; height: 26px; stroke: var(--tf-gray); fill: none; stroke-width: 1.6; }
.tf-tab-item.active { color: var(--tf-blue); }
.tf-tab-item.active svg { stroke: var(--tf-blue); }

/* Sidebar (iPad / desktop widths) ----------------------------------------- */
.tf-sidebar {
    display: none;
}

@media (min-width: 1024px) {
    .tf-app-shell { flex-direction: row; }

    .tf-tab-bar { display: none; }

    .tf-sidebar {
        display: flex;
        flex-direction: column;
        width: 260px;
        flex-shrink: 0;
        min-height: 100dvh;
        padding: calc(24px + var(--tf-safe-top)) 12px 24px;
        background: var(--tf-bg-secondary);
        border-right: 0.5px solid var(--tf-separator);
        gap: 2px;
    }

    .tf-sidebar-brand {
        font-size: 20px;
        font-weight: 700;
        padding: 0 12px 20px;
    }

    .tf-sidebar-item {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 10px 12px;
        border-radius: 10px;
        color: var(--tf-label);
        font-size: 15px;
        font-weight: 500;
    }

    .tf-sidebar-item svg { width: 22px; height: 22px; stroke: var(--tf-label-secondary); fill: none; stroke-width: 1.6; }
    .tf-sidebar-item.active { background: var(--tf-blue-fill); color: #fff; }
    .tf-sidebar-item.active svg { stroke: #fff; }

    .tf-nav-bar { display: none; }

    .tf-content {
        max-width: 720px;
        padding: 40px 32px 40px;
        margin: 0;
    }

    .tf-desktop-header { display: block; margin-bottom: 24px; }
}

/* Grouped inset list ------------------------------------------------------- */
.tf-list {
    background: var(--tf-bg-secondary-grouped);
    border-radius: var(--tf-radius-md);
    overflow: hidden;
    margin: 0 0 24px;
}

.tf-list-header {
    font-size: 13px;
    font-weight: 500;
    text-transform: uppercase;
    color: var(--tf-label-secondary);
    padding: 0 16px 6px;
    letter-spacing: 0.2px;
}

.tf-list-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 0.5px solid var(--tf-separator);
    background: transparent;
    width: 100%;
    text-align: left;
    cursor: pointer;
}

.tf-list-row:last-child { border-bottom: none; }
.tf-list-row-icon {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--tf-blue-fill);
    color: #fff;
    flex-shrink: 0;
}
.tf-list-row-icon svg { width: 17px; height: 17px; stroke: #fff; fill: none; stroke-width: 2; }

.tf-list-row-body { flex: 1; min-width: 0; }
.tf-list-row-title { font-size: 17px; color: var(--tf-label); }
.tf-list-row-subtitle { font-size: 13px; color: var(--tf-label-secondary); margin-top: 1px; }

.tf-list-row-value { color: var(--tf-label-secondary); font-size: 17px; }
.tf-list-row-chevron::after {
    content: "";
    width: 8px;
    height: 8px;
    border-top: 1.6px solid var(--tf-gray3);
    border-right: 1.6px solid var(--tf-gray3);
    transform: rotate(45deg);
    flex-shrink: 0;
}

/* Cards --------------------------------------------------------------------- */
.tf-card {
    background: var(--tf-bg-secondary-grouped);
    border-radius: var(--tf-radius-lg);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.tf-app-card {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--tf-bg-secondary-grouped);
    border-radius: var(--tf-radius-md);
    padding: 14px;
    margin-bottom: 12px;
}

.tf-app-icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    background: linear-gradient(160deg, var(--tf-blue-fill), var(--tf-purple));
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 20px;
    flex-shrink: 0;
    overflow: hidden;
}
.tf-app-icon img { width: 100%; height: 100%; object-fit: cover; }

.tf-app-card-body { flex: 1; min-width: 0; }
.tf-app-card-title { font-size: 17px; font-weight: 600; }
.tf-app-card-meta { font-size: 13px; color: var(--tf-label-secondary); margin-top: 2px; }

/* Buttons --------------------------------------------------------------------- */
.tf-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 20px;
    border-radius: 980px;
    font-size: 17px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: opacity 0.15s ease, transform 0.1s ease;
}
.tf-btn:active { transform: scale(0.97); opacity: 0.85; }

.tf-btn-primary { background: var(--tf-blue-fill); color: #fff; }
.tf-btn-secondary { background: var(--tf-gray5); color: var(--tf-btn-secondary-text, var(--tf-blue)); }
.tf-btn-destructive { background: transparent; color: var(--tf-red); }
.tf-btn-plain { background: none; color: var(--tf-blue); padding: 8px 4px; font-weight: 400; }
.tf-btn-block { display: flex; width: 100%; }
.tf-btn-sm { padding: 8px 14px; font-size: 14px; }

/* Forms --------------------------------------------------------------------- */
.tf-form-group { margin-bottom: 16px; }
.tf-form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--tf-label-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.2px;
}

.tf-form-group input[type="text"],
.tf-form-group input[type="email"],
.tf-form-group input[type="password"],
.tf-form-group input[type="url"],
.tf-form-group input[type="number"],
.tf-form-group input[type="date"],
.tf-form-group select,
.tf-form-group textarea {
    width: 100%;
    padding: 12px 14px;
    font-size: 17px;
    border-radius: var(--tf-radius-sm);
    border: none;
    background: var(--tf-gray5);
    color: var(--tf-label);
    font-family: inherit;
    appearance: none;
}

.tf-form-group textarea { resize: vertical; min-height: 90px; }
.tf-form-group input:focus,
.tf-form-group select:focus,
.tf-form-group textarea:focus {
    outline: 2px solid var(--tf-blue);
    outline-offset: 1px;
}

.tf-form-row { display: flex; gap: 12px; }
.tf-form-row > .tf-form-group { flex: 1; }

/* iOS switch ------------------------------------------------------------------ */
.tf-switch { position: relative; display: inline-block; width: 51px; height: 31px; flex-shrink: 0; }
.tf-switch input { opacity: 0; width: 0; height: 0; }
.tf-switch-track {
    position: absolute; inset: 0; border-radius: 999px;
    background: var(--tf-gray4); transition: background 0.2s ease; cursor: pointer;
}
.tf-switch-track::before {
    content: "";
    position: absolute; top: 2px; left: 2px;
    width: 27px; height: 27px; border-radius: 50%;
    background: #fff; box-shadow: 0 3px 8px rgba(0,0,0,0.18);
    transition: transform 0.2s ease;
}
.tf-switch input:checked + .tf-switch-track { background: var(--tf-green); }
.tf-switch input:checked + .tf-switch-track::before { transform: translateX(20px); }

/* Segmented control ------------------------------------------------------------ */
.tf-segmented {
    display: flex;
    background: var(--tf-gray5);
    border-radius: 9px;
    padding: 2px;
    margin-bottom: 16px;
}
.tf-segmented a, .tf-segmented button {
    flex: 1;
    text-align: center;
    padding: 6px 10px;
    font-size: 13px;
    font-weight: 500;
    border-radius: 7px;
    color: var(--tf-label);
    background: none;
    border: none;
    cursor: pointer;
}
.tf-segmented .active { background: var(--tf-bg-secondary-grouped); box-shadow: 0 1px 3px rgba(0,0,0,0.15); }

/* Badges ------------------------------------------------------------------------ */
.tf-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}
.tf-badge-success { background: color-mix(in srgb, var(--tf-green) 16%, transparent); color: var(--tf-green); }
.tf-badge-warning { background: color-mix(in srgb, var(--tf-orange) 16%, transparent); color: var(--tf-orange); }
.tf-badge-danger { background: color-mix(in srgb, var(--tf-red) 16%, transparent); color: var(--tf-red); }
.tf-badge-info { background: color-mix(in srgb, var(--tf-blue) 16%, transparent); color: var(--tf-blue); }
.tf-badge-neutral { background: var(--tf-gray5); color: var(--tf-label-secondary); }

/* Alerts -------------------------------------------------------------------------- */
.tf-alert { padding: 14px 16px; border-radius: var(--tf-radius-sm); margin-bottom: 16px; font-size: 15px; }
.tf-alert-success { background: color-mix(in srgb, var(--tf-green) 14%, transparent); color: var(--tf-green); }
.tf-alert-error { background: color-mix(in srgb, var(--tf-red) 14%, transparent); color: var(--tf-red); }

/* Empty states --------------------------------------------------------------------- */
.tf-empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--tf-label-secondary);
}
.tf-empty-state svg { width: 44px; height: 44px; stroke: var(--tf-gray3); fill: none; stroke-width: 1.4; margin-bottom: 10px; }

/* Avatar ------------------------------------------------------------------------------ */
.tf-avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--tf-blue-fill); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 15px; flex-shrink: 0;
}

/* Bottom sheet / modal ------------------------------------------------------------------ */
.tf-sheet-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,0.4);
    display: flex; align-items: flex-end; justify-content: center;
    z-index: 60; opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
}
.tf-sheet-backdrop.active { opacity: 1; pointer-events: auto; }

.tf-sheet {
    background: var(--tf-bg-secondary-grouped);
    width: 100%; max-width: 560px;
    border-radius: 20px 20px 0 0;
    padding: 10px 20px calc(24px + var(--tf-safe-bottom));
    transform: translateY(100%);
    transition: transform 0.25s cubic-bezier(0.32, 0.72, 0, 1);
    max-height: 86vh;
    overflow-y: auto;
}
.tf-sheet-backdrop.active .tf-sheet { transform: translateY(0); }

@media (min-width: 640px) {
    .tf-sheet-backdrop { align-items: center; }
    .tf-sheet { border-radius: 20px; transform: translateY(16px) scale(0.96); opacity: 0; }
    .tf-sheet-backdrop.active .tf-sheet { transform: translateY(0) scale(1); opacity: 1; }
}

.tf-sheet-grabber {
    width: 36px; height: 5px; border-radius: 999px;
    background: var(--tf-gray3); margin: 6px auto 14px;
}

.tf-sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.tf-sheet-close { background: var(--tf-gray5); color: var(--tf-label-secondary); width: 28px; height: 28px; border-radius: 50%; border: none; font-size: 15px; cursor: pointer; }

/* Login / auth screens ---------------------------------------------------------------------- */
.tf-shell { display: flex; align-items: center; justify-content: center; min-height: 100dvh; padding: 24px; }
.tf-shell-narrow .tf-card, .tf-auth-card { max-width: 380px; width: 100%; }

.tf-auth-card {
    background: var(--tf-bg-secondary-grouped);
    border-radius: var(--tf-radius-lg);
    padding: 32px 28px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.08);
}
.tf-auth-icon {
    width: 64px; height: 64px; border-radius: 16px; margin: 0 auto 18px;
    background: linear-gradient(160deg, var(--tf-blue-fill), var(--tf-purple));
    display: flex; align-items: center; justify-content: center;
}
.tf-auth-icon svg { width: 32px; height: 32px; stroke: #fff; fill: none; stroke-width: 1.8; }

.tf-setup-log { padding-left: 18px; color: var(--tf-label-secondary); font-size: 14px; }
.tf-success { color: var(--tf-green); font-weight: 600; }
.tf-error { color: var(--tf-red); font-weight: 600; }

/* Toolbar for panels (staff pages) -------------------------------------------------------------- */
.tf-panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.tf-panel-head h2 { font-size: 20px; margin: 0; }

.tf-divider { height: 0.5px; background: var(--tf-separator); margin: 16px 0; border: none; }

.tf-stack { display: flex; flex-direction: column; gap: 10px; }
.tf-row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.tf-fab {
    position: fixed;
    right: 20px;
    bottom: calc(84px + var(--tf-safe-bottom));
    width: 56px; height: 56px; border-radius: 50%;
    background: var(--tf-blue-fill); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 28px; box-shadow: 0 6px 20px rgba(0,122,255,0.4);
    z-index: 35;
}

@media (min-width: 1024px) {
    .tf-fab { bottom: 32px; }
}
