/* Shared app-shell layout and control sizing rules, including profile/admin surfaces. */

/* Keep the main profile card white for contrast against the sand page background */
#profile-form-container {
    background-color: rgb(var(--color-surface-2)) !important;
}

/* Dark mode contrast boosts for profile controls and action links. */
html[data-theme="dark"] #theme-mode-label,
html[data-theme="dark"] #admin-mode-label-mobile,
html[data-theme="dark"] #create-dupr-button,
html[data-theme="dark"] #profile-form-container a[href="index.html"] {
    color: rgb(var(--color-gray-800)) !important;
}

/* Keep section headings legible on dark cards without touching light mode styling. */
html[data-theme="dark"] #profile-form-container h3.text-ocean-blue,
html[data-theme="dark"] #profile-form-container h4.text-ocean-blue {
    color: rgb(var(--color-gray-800)) !important;
}

/* Lift low-contrast helper/status text in dark mode. */
html[data-theme="dark"] #profile-form-container .text-gray-500 {
    color: rgb(var(--color-gray-600)) !important;
}

html[data-theme="dark"] #profile-form-container .text-gray-400 {
    color: rgb(var(--color-gray-600)) !important;
}

/* Ensure dark-mode admin inputs/selectors have visible control surfaces. */
html[data-theme="dark"] #profile-form-container #admin-email-input {
    background-color: rgb(var(--color-gray-50)) !important;
    border-color: rgb(var(--color-border-strong)) !important;
    color: rgb(var(--color-gray-900)) !important;
}

html[data-theme="dark"] #account-management-filter-select,
html[data-theme="dark"] #account-management-user-select,
html[data-theme="dark"] #dupr-gender-filter,
html[data-theme="dark"] #dupr-gender-user-select,
html[data-theme="dark"] #dupr-gender-manual-value,
html[data-theme="dark"] #guest-account-select,
html[data-theme="dark"] #unpaid-fees-event-filter,
html[data-theme="dark"] #unpaid-fees-player-filter {
    background-color: rgb(var(--color-gray-100)) !important;
    border-color: rgb(var(--color-border-strong)) !important;
    color: rgb(var(--color-gray-900)) !important;
}

html[data-theme="dark"] #admin-email-input::placeholder {
    color: rgb(var(--color-gray-500)) !important;
    opacity: 1;
}

html[data-theme="dark"] #admin-email-input:focus,
html[data-theme="dark"] #account-management-filter-select:focus,
html[data-theme="dark"] #account-management-user-select:focus,
html[data-theme="dark"] #dupr-gender-filter:focus,
html[data-theme="dark"] #dupr-gender-user-select:focus,
html[data-theme="dark"] #dupr-gender-manual-value:focus,
html[data-theme="dark"] #guest-account-select:focus,
html[data-theme="dark"] #unpaid-fees-event-filter:focus,
html[data-theme="dark"] #unpaid-fees-player-filter:focus,
html[data-theme="dark"] #email-notifications-list:focus {
    border-color: rgb(var(--color-focus-ring)) !important;
}

/* Compact toggle-switch containers: reduce vertical padding and center the row. */
#theme-mode-section,
#email-notifications-section,
#location-filtering-section,
#calendar-sync-section-mobile,
#admin-mode-section-mobile {
    padding-top: 0.375rem;
    padding-bottom: 0.375rem;
}

#theme-mode-section .profile-section-header,
#email-notifications-section .profile-section-header,
#location-filtering-section .profile-section-header,
#calendar-sync-section-mobile .profile-section-header,
#admin-mode-section-mobile .profile-section-header {
    align-items: center;
}

/* Lift dark-mode profile toggle cards and labels above the page canvas. */
html[data-theme="dark"] #theme-mode-section,
html[data-theme="dark"] #email-notifications-section,
html[data-theme="dark"] #location-filtering-section,
html[data-theme="dark"] #calendar-sync-section-mobile,
html[data-theme="dark"] #admin-mode-section-mobile {
    background-color: rgb(var(--color-surface-2)) !important;
    border-color: rgb(var(--color-border-strong)) !important;
}

html[data-theme="dark"] #theme-mode-section p,
html[data-theme="dark"] #email-notifications-section p,
html[data-theme="dark"] #location-filtering-section p,
html[data-theme="dark"] #calendar-sync-section-mobile p,
html[data-theme="dark"] #admin-mode-section-mobile p {
    color: rgb(var(--color-gray-900)) !important;
}

/* Keep dark-mode toggle tracks/thumbs readable after utility token remaps. */
html[data-theme="dark"] #theme-mode-section label > div:first-of-type,
html[data-theme="dark"] #email-notifications-section label > div:first-of-type,
html[data-theme="dark"] #location-filtering-section label > div:first-of-type,
html[data-theme="dark"] #calendar-sync-section-mobile label > div:first-of-type,
html[data-theme="dark"] #admin-mode-section-mobile label > div:first-of-type {
    background-color: rgb(var(--color-gray-400)) !important;
    border: 1px solid rgb(var(--color-border-strong));
}

html[data-theme="dark"] #theme-mode-section input:checked + div,
html[data-theme="dark"] #email-notifications-section input:checked + div,
html[data-theme="dark"] #location-filtering-section input:checked + div,
html[data-theme="dark"] #calendar-sync-section-mobile input:checked + div,
html[data-theme="dark"] #admin-mode-section-mobile input:checked + div {
    background-color: rgb(var(--color-ocean-blue)) !important;
}

/* Profile page button system: six styles mirroring the btn-nav-* family */

.btn-profile-primary {
    padding: 0.5rem 1rem;
    border: 1px solid transparent;
    border-radius: 0.5rem;
    background-color: rgb(var(--color-ocean-blue));
    color: #fff;
    font-weight: 600;
    transition: background-color 0.15s ease;
    cursor: pointer;
}

.btn-profile-primary:hover {
    background-color: rgb(var(--color-ocean-teal));
}

.btn-profile-secondary {
    padding: 0.5rem 1rem;
    border: 1px solid rgb(var(--color-ocean-blue));
    border-radius: 0.5rem;
    background-color: #fff;
    color: rgb(var(--color-ocean-blue));
    font-weight: 600;
    transition: background-color 0.15s ease;
    cursor: pointer;
}

.btn-profile-secondary:hover {
    background-color: rgb(var(--color-seafoam-light) / 0.45);
}

html[data-theme="dark"] #profile-form-container .btn-profile-secondary:not(:disabled):hover {
    background-color: rgb(var(--color-gray-200));
}

.btn-profile-danger {
    padding: 0.5rem 1rem;
    border: 1px solid rgb(248 113 113); /* red-400 */
    border-radius: 0.5rem;
    background-color: #fff;
    color: rgb(220 38 38); /* red-600 */
    font-weight: 600;
    transition: background-color 0.15s ease;
    cursor: pointer;
}

.btn-profile-danger:hover {
    background-color: rgb(254 242 242); /* red-50 */
}

.btn-profile-primary-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    border: 1px solid transparent;
    border-radius: 0.5rem;
    background-color: rgb(var(--color-ocean-blue));
    color: #fff;
    font-weight: 600;
    white-space: nowrap;
    transition: background-color 0.15s ease;
    cursor: pointer;
}

.btn-profile-primary-sm:hover {
    background-color: rgb(var(--color-ocean-teal));
}

.btn-profile-secondary-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    border: 1px solid rgb(var(--color-ocean-blue));
    border-radius: 0.5rem;
    background-color: #fff;
    color: rgb(var(--color-ocean-blue));
    font-weight: 600;
    white-space: nowrap;
    transition: background-color 0.15s ease;
    cursor: pointer;
}

.btn-profile-secondary-sm:hover {
    background-color: rgb(var(--color-seafoam-light) / 0.45);
}

.btn-profile-danger-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    border: 1px solid rgb(252 165 165); /* red-300 */
    border-radius: 0.5rem;
    background-color: #fff;
    color: rgb(185 28 28); /* red-700 */
    font-weight: 600;
    white-space: nowrap;
    transition: background-color 0.15s ease;
    cursor: pointer;
}

.btn-profile-danger-sm:hover {
    background-color: rgb(254 242 242); /* red-50 */
}

#email-notifications-list {
    color: rgb(var(--color-gray-900));
    border-color: rgb(var(--color-border-default));
}

.btn-profile-ghost-sm {
    padding: 0.5rem 0.75rem;
    border: 1px solid rgb(var(--color-gray-300));
    border-radius: 0.5rem;
    background-color: transparent;
    color: rgb(var(--color-gray-700));
    font-weight: 600;
    transition: background-color 0.15s ease;
    cursor: pointer;
}

.btn-profile-ghost-sm:hover {
    background-color: rgb(var(--color-seafoam-light) / 0.45);
}

html[data-theme="dark"] #profile-form-container .btn-profile-ghost-sm:not(:disabled):hover {
    background-color: rgb(var(--color-gray-200));
}

/* Normalize standard profile-page button copy to the shared 15px control size. */
#not-authenticated button:not(.text-xs):not(.text-sm),
#profile-form-container button:not(.text-xs):not(.text-sm),
#dupr-link-modal button:not(.text-xs):not(.text-sm) {
    font-size: 0.9375rem;
}

/* Normalize all profile-page buttons to a consistent 34px height, nav bar excluded.
   Inline text-xs action links (e.g. Revoke, Master) are exempted so list rows stay compact. */
#not-authenticated button:not(.text-xs),
#profile-form-container button:not(.text-xs),
#dupr-link-modal button:not(.text-xs) {
    height: 34px;
    min-height: 34px;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Match the admin permissions email input height to the 34px button standard. */
#admin-email-input {
    height: 34px;
    min-height: 34px;
    box-sizing: border-box;
}

html[data-theme="dark"] #theme-mode-section label > div:last-child,
html[data-theme="dark"] #email-notifications-section label > div:last-child,
html[data-theme="dark"] #location-filtering-section label > div:last-child,
html[data-theme="dark"] #calendar-sync-section-mobile label > div:last-child,
html[data-theme="dark"] #admin-mode-section-mobile label > div:last-child {
    background-color: rgb(var(--color-gray-950)) !important;
    border: 1px solid rgb(var(--color-gray-500));
}

/* Replace seafoam/green interactive states with neutral dark hover surfaces. */
html[data-theme="dark"] #calendar-sync-button {
    -webkit-text-fill-color: currentColor;
}

html[data-theme="dark"] #calendar-sync-button:not(.bg-ocean-blue) {
    background-color: rgb(var(--color-surface-2)) !important;
    border-color: rgb(var(--color-ocean-blue)) !important;
    color: rgb(var(--color-ocean-blue)) !important;
    -webkit-text-fill-color: rgb(var(--color-ocean-blue));
}

html[data-theme="dark"] #calendar-sync-button.bg-ocean-blue {
    color: rgb(var(--color-text-on-accent)) !important;
    -webkit-text-fill-color: rgb(var(--color-text-on-accent));
}

html[data-theme="dark"] #profile-form-container .hover\:bg-seafoam-light\/45:not(:disabled):hover,
html[data-theme="dark"] #profile-form-container .hover\:bg-seafoam-light\/45:not(:disabled):focus-visible,
html[data-theme="dark"] #profile-form-container .hover\:bg-seafoam-light\/45:not(:disabled):active {
    background-color: rgb(var(--color-gray-200)) !important;
    -webkit-text-fill-color: currentColor;
}

.dupr-link-modal-panel {
    width: 95%;
    max-width: 768px;
    height: calc(100dvh - 1rem);
    max-height: calc(100dvh - 1rem);
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
    display: flex;
    flex-direction: column;
}

.dupr-link-modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

@supports not (height: 100dvh) {
    .dupr-link-modal-panel {
        height: calc(100vh - 1rem);
        max-height: calc(100vh - 1rem);
    }
}

@media (min-width: 768px) {
    .dupr-link-modal-panel {
        height: calc(100dvh - 3rem);
        max-height: calc(100dvh - 3rem);
        margin-top: 1.5rem;
        margin-bottom: 1.5rem;
    }

    @supports not (height: 100dvh) {
        .dupr-link-modal-panel {
            height: calc(100vh - 3rem);
            max-height: calc(100vh - 3rem);
        }
    }
}

.dupr-link-modal-body > iframe {
    display: block;
}

/* Normalize create-event control sizing across browsers/devices */
#create-event-tools .create-event-field,
#event-management-tools .create-event-field {
    height: 42px;
    min-width: 0;
    max-width: 100%;
    background-color: rgb(var(--color-surface-2)) !important;
    box-sizing: border-box;
}

#create-event-tools input.create-event-field,
#create-event-tools select.create-event-field,
#event-management-tools input.create-event-field,
#event-management-tools select.create-event-field {
    font-size: 0.875rem;
    line-height: 1.25rem;
}

#create-event-tools input.create-event-field[type="number"],
#event-management-tools input.create-event-field[type="number"] {
    -moz-appearance: textfield;
}

#create-event-tools input.create-event-field[type="number"]::-webkit-outer-spin-button,
#create-event-tools input.create-event-field[type="number"]::-webkit-inner-spin-button,
#event-management-tools input.create-event-field[type="number"]::-webkit-outer-spin-button,
#event-management-tools input.create-event-field[type="number"]::-webkit-inner-spin-button {
    margin: 0;
}

#create-event-tools .create-event-grid-item,
#event-management-tools .create-event-grid-item {
    min-width: 0;
}

#create-event-tools .create-event-header,
#event-management-tools .create-event-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    flex-wrap: nowrap;
    gap: 0.5rem;
}

#create-event-tools .create-event-header > h4,
#event-management-tools .create-event-header > h4 {
    min-width: 0;
    flex: 1 1 auto;
}

#create-event-tools #create-event-visibility-toggle,
#event-management-tools #create-event-visibility-toggle {
    margin-left: auto;
    flex: 0 0 auto;
}

#create-event-tools .create-event-submit-row,
#event-management-tools .create-event-submit-row {
    display: flex;
    width: 100%;
    justify-content: flex-end !important;
}

/* D1 baseline header layout: keep title left-aligned and button behavior stable across breakpoints. */
#d1-baseline-tools .profile-section-header > h4 {
    text-align: left;
}

#d1-baseline-actions {
    width: 100%;
}

#d1-preview-reset-button {
    width: 100%;
    order: 3;
}

#d1-preview-reset-dry-run-button {
    order: 1;
    flex: 1 1 0;
    min-width: 0;
}

#d1-baseline-download-button {
    order: 2;
    flex: 1 1 0;
    min-width: 0;
}

@media (min-width: 768px) {
    #d1-baseline-actions {
        width: auto;
        margin-left: auto;
        justify-content: flex-end;
    }

    #d1-preview-reset-button {
        width: auto;
        order: 1;
    }

    #d1-preview-reset-dry-run-button {
        order: 2;
        flex: 0 0 auto;
    }

    #d1-baseline-download-button {
        order: 3;
        flex: 0 0 auto;
    }
}

/* Match DUPR ID input height to the existing compact account-action buttons. */
#account-management-editor input.account-management-compact-input {
    height: 34px !important;
    min-height: 34px !important;
    padding-top: 0.25rem !important;
    padding-bottom: 0.25rem !important;
    line-height: 1.1 !important;
    box-sizing: border-box;
}

#create-event-date-input.create-event-field {
    height: 42px !important;
    min-height: 42px !important;
    line-height: 1.2;
    padding-top: 0.5rem !important;
    padding-bottom: 0.5rem !important;
    background-color: rgb(var(--color-surface-2)) !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow: hidden;
}

#profile-page-nav {
    background: linear-gradient(
        135deg,
        rgb(var(--color-hero-gradient-start)) 0%,
        rgb(var(--color-hero-gradient-mid)) 52%,
        rgb(var(--color-ocean-blue)) 100%
    );
}

#profile-page-nav .profile-brand-link,
#profile-page-nav .profile-nav-link {
    color: rgb(var(--color-gray-50));
}

#profile-page-nav .btn-nav-on-dark {
    transition:
        background-color 0.2s ease,
        border-color 0.2s ease,
        box-shadow 0.2s ease,
        transform 0.2s ease;
}

#profile-page-nav .nav-dark-admin-link {
    display: none;
    min-height: 2.25rem;
    height: 2.25rem;
}

@media (min-width: 768px) {
    #profile-page-nav .nav-dark-admin-link:not(.hidden) {
        display: inline-flex;
    }
}

#profile-page-nav .profile-nav-home-button {
    min-width: 2.94rem;
}

#profile-page-nav .profile-nav-home-button-mobile {
    display: inline-flex;
}

@media (min-width: 768px) {
    #profile-page-nav .profile-nav-home-button-mobile {
        display: none !important;
    }
}

#profile-page-nav #auth-buttons-desktop {
    display: none;
    min-width: 0;
}

@media (min-width: 768px) {
    #profile-page-nav #auth-buttons-desktop {
        display: flex;
    }
}

#profile-page-nav .profile-nav-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.42rem 0.78rem;
    border: 1px solid currentColor;
    border-radius: 0.58rem;
    background: transparent;
    line-height: 1;
}

#profile-page-nav .profile-brand-link:hover,
#profile-page-nav .profile-brand-link:focus-visible,
#profile-page-nav .profile-nav-link:hover,
#profile-page-nav .profile-nav-link:focus-visible {
    color: rgb(var(--color-gray-100));
}

#profile-page-nav .btn-nav-on-dark:hover,
#profile-page-nav .btn-nav-on-dark:focus-visible {
    box-shadow: 0 8px 22px rgb(8 28 44 / 0.24);
    transform: translateY(-1px);
}

html[data-theme="dark"] #profile-page-nav {
    background: linear-gradient(
        135deg,
        rgb(var(--color-hero-gradient-start)) 0%,
        rgb(var(--color-hero-gradient-mid)) 52%,
        rgb(var(--color-ocean-blue)) 100%
    );
}

html[data-theme="dark"] #profile-page-nav .profile-brand-link,
html[data-theme="dark"] #profile-page-nav .profile-nav-link {
    color: rgb(var(--color-gray-50));
}

html[data-theme="dark"] #profile-page-nav .btn-nav-on-dark {
    border-color: rgb(255 255 255 / 0.34);
    background: rgb(255 255 255 / 0.1);
    box-shadow: 0 8px 24px rgb(0 0 0 / 0.26);
}

html[data-theme="dark"] #profile-page-nav .profile-brand-link:hover,
html[data-theme="dark"] #profile-page-nav .profile-brand-link:focus-visible,
html[data-theme="dark"] #profile-page-nav .profile-nav-link:hover,
html[data-theme="dark"] #profile-page-nav .profile-nav-link:focus-visible {
    color: rgb(var(--color-gray-100));
}

html[data-theme="dark"] #profile-page-nav .btn-nav-on-dark:hover,
html[data-theme="dark"] #profile-page-nav .btn-nav-on-dark:focus-visible {
    background: rgb(255 255 255 / 0.16);
    border-color: rgb(255 255 255 / 0.5);
}

body[data-page="profile"] #profile-nav-shell {
    max-width: 52.75rem;
}

body[data-page="profile"] #profile-page-content-shell {
    max-width: 52.75rem;
}

#profile-nav-row {
    min-height: 52px;
    gap: 0.5rem;
    padding-top: 0.25rem;
    padding-bottom: 0.25rem;
}

.profile-brand-link {
    min-width: 0;
    flex: 1 1 auto;
}

.profile-brand-text {
    display: flex;
    align-items: center;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1;
    transform: translateY(0.04em);
}

@media (max-width: 767px) {
    body.nav-mobile-unauthenticated .profile-brand-text {
        font-size: 1.3rem;
        line-height: 1.1;
    }
}

@media (max-width: 767px) {
    .profile-header-row,
    .profile-section-header {
        flex-wrap: wrap;
        align-items: flex-start;
    }

    .profile-header-row > :first-child,
    .profile-section-header > :first-child {
        min-width: 0;
        flex: 1 1 auto;
    }

    .profile-header-actions {
        flex: 0 0 auto;
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    #create-event-tools .create-event-header,
    #event-management-tools .create-event-header {
        width: 100%;
        justify-content: space-between;
        align-items: center;
        flex-wrap: nowrap !important;
    }
}

.profile-dupr-account-button:not(.hidden) {
    display: inline-flex;
}

.profile-settings-heading {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    gap: 0.28rem;
}

.profile-settings-icon {
    display: block;
    width: 1.22rem;
    height: 1.22rem;
    flex: 0 0 auto;
    opacity: 0.86;
    transform: translateY(-0.5px);
}

#profile-identity-header {
    margin-top: 0.15rem;
}

.rating-label-mobile {
    display: inline;
}

.rating-label-desktop {
    display: none;
}

@media (min-width: 780px) {
    #profile-nav-row {
        min-height: var(--homepage-desktop-nav-height, 60px);
        padding-top: 0;
        padding-bottom: 0;
    }

    .rating-label-mobile {
        display: none;
    }

    .rating-label-desktop {
        display: inline;
    }
}
