/* Shared product components and page states. */
.cf-product .cf-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-width: 44px;
    min-height: 44px;
    padding: var(--space-2) 18px;
    border: 1px solid var(--cf-border-strong);
    border-radius: var(--radius-md);
    background: var(--cf-surface);
    color: var(--cf-text);
    font-family: var(--cf-font-family);
    font-size: var(--font-sm);
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}

.cf-product .cf-btn:hover,
.cf-product .cf-btn:focus {
    text-decoration: none;
}

.cf-product .cf-btn-primary {
    background: var(--cf-primary-700);
    color: var(--cf-surface);
    border-color: var(--cf-primary-700);
}

.cf-product .cf-btn-primary:not(:disabled):not([aria-disabled="true"]):hover {
    background: var(--cf-primary-800);
    border-color: var(--cf-primary-800);
}

/* Keep the existing soft class as an alias until individual pages migrate. */
.cf-product .cf-btn-secondary,
.cf-product .cf-btn-soft {
    background: var(--cf-primary-050);
    color: var(--cf-primary-800);
    border-color: var(--cf-primary-100);
}

.cf-product .cf-btn-secondary:not(:disabled):not([aria-disabled="true"]):hover,
.cf-product .cf-btn-soft:not(:disabled):not([aria-disabled="true"]):hover {
    background: var(--cf-primary-100);
}

.cf-product .cf-btn-outline {
    background: var(--cf-surface);
    color: var(--cf-text);
    border-color: var(--cf-border-strong);
}

.cf-product .cf-btn-outline:not(:disabled):not([aria-disabled="true"]):hover {
    background: var(--cf-surface-muted);
}

.cf-product .cf-btn-danger {
    background: var(--cf-danger);
    color: var(--cf-surface);
    border-color: var(--cf-danger);
}

.cf-product .cf-btn-danger:not(:disabled):not([aria-disabled="true"]):hover {
    background: var(--cf-danger-bg);
    color: var(--cf-danger);
}

/* Icon-only controls must also supply a meaningful aria-label and title. */
.cf-product .cf-btn-icon {
    width: 44px;
    height: 44px;
    padding: 0;
    flex-shrink: 0;
}

.cf-product .cf-btn:disabled,
.cf-product .cf-btn[aria-disabled="true"] {
    opacity: .55;
    cursor: not-allowed;
}

.cf-product .cf-link,
.cf-product .cf-muted-link,
.cf-product .cf-section-title a {
    color: var(--cf-primary-700);
    font-weight: 500;
    text-decoration: none;
}

.cf-product .cf-link:not([aria-disabled="true"]):hover,
.cf-product .cf-muted-link:not([aria-disabled="true"]):hover,
.cf-product .cf-section-title a:not([aria-disabled="true"]):hover {
    text-decoration: underline;
}

/* Shared navigation states only; navigation layout remains in the legacy file. */
.cf-product .cf-nav-link,
.cf-product .cf-bottom-nav a {
    color: var(--cf-text-secondary);
    background: transparent;
    text-decoration: none;
}

.cf-product .cf-nav-link.is-active,
.cf-product .cf-nav-link[aria-current="page"],
.cf-product .cf-bottom-nav a.is-active,
.cf-product .cf-bottom-nav a[aria-current="page"],
.cf-product .cf-nav-link:not([aria-disabled="true"]):hover,
.cf-product .cf-bottom-nav a:not([aria-disabled="true"]):hover {
    color: var(--cf-primary-700);
    background: var(--cf-primary-050);
}

.cf-product .cf-btn:focus-visible,
.cf-product .cf-link:focus-visible,
.cf-product .cf-muted-link:focus-visible,
.cf-product .cf-section-title a:focus-visible,
.cf-product .cf-nav-link:focus-visible,
.cf-product .cf-bottom-nav a:focus-visible {
    outline: 3px solid var(--cf-focus);
    outline-offset: 2px;
}

.cf-product .cf-link[aria-disabled="true"],
.cf-product .cf-nav-link[aria-disabled="true"] {
    opacity: .55;
    cursor: not-allowed;
}

@media (prefers-reduced-motion: reduce) {
    .cf-product .cf-btn {
        transition: none;
    }
}

/* Match existing product controls during migration, without styling hidden
   values, action inputs, or controls with their own native interaction model. */
.cf-product :is(
    .cf-input,
    .cf-select,
    .cf-textarea,
    input:not([type="hidden"], [type="checkbox"], [type="radio"], [type="submit"], [type="reset"], [type="button"], [type="image"], [type="range"], [type="color"]),
    select,
    textarea
) {
    width: 100%;
    max-width: 100%;
    min-height: 44px;
    border: 1px solid var(--cf-border);
    border-radius: var(--radius-md);
    background: var(--cf-surface);
    color: var(--cf-text);
    padding: 10px var(--space-3);
    font-family: var(--cf-font-family);
    font-size: var(--font-md);
}

.cf-product :is(
    .cf-input,
    .cf-select,
    .cf-textarea,
    input:not([type="hidden"], [type="checkbox"], [type="radio"], [type="submit"], [type="reset"], [type="button"], [type="image"], [type="range"], [type="color"]),
    select,
    textarea
):focus {
    border-color: var(--cf-primary-500);
    box-shadow: 0 0 0 3px var(--cf-focus-glow);
    outline: none;
}

.cf-product textarea {
    resize: vertical;
}

.cf-product .cf-form,
.cf-product .cf-form-row {
    display: grid;
    gap: var(--space-4);
}

.cf-product .cf-field {
    display: grid;
    gap: var(--space-2);
}

/* Fields must retain visible labels associated using for/id. Helper and error
   text belongs below its field and can be associated with aria-describedby. */
.cf-product .cf-label,
.cf-product label.cf-field,
.cf-product .cf-field label {
    margin: 0;
    color: var(--cf-text);
    font-size: var(--font-sm);
    font-weight: 500;
}

.cf-product .cf-helper {
    display: block;
    color: var(--cf-text-secondary);
    font-size: var(--font-sm);
}

.cf-product .cf-note {
    color: var(--cf-text-secondary);
    font-size: var(--font-xs);
}

/* Reuse ASP.NET validation classes; explicit errors also work in AJAX forms.
   Do not mark untouched required fields as errors with a blanket :invalid rule. */
.cf-product :is(input, select, textarea).input-validation-error,
.cf-product :is(input, select, textarea)[aria-invalid="true"],
.cf-product :is(input, select, textarea).input-validation-error:focus,
.cf-product :is(input, select, textarea)[aria-invalid="true"]:focus {
    border-color: var(--cf-danger);
}

.cf-product .cf-field-error,
.cf-product .field-validation-error,
.cf-product .validation-summary-errors {
    color: var(--cf-danger);
    font-size: var(--font-sm);
}

.cf-product .cf-field-error,
.cf-product .field-validation-error {
    display: block;
}

.cf-product .field-validation-valid,
.cf-product .validation-summary-valid {
    display: none;
}

/* Keep existing feature-specific card variants in control until their blocks. */
:where(.cf-product) .cf-card {
    background: var(--cf-surface);
    border: 1px solid var(--cf-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

:where(.cf-product .cf-card) {
    padding: var(--space-5);
}

@media (max-width: 767px) {
    :where(.cf-product .cf-card) { padding: var(--space-4); }
}

:where(.cf-product) .cf-card h2 {
    margin-top: 0;
}

/* Opt-in structure for cards migrated in later blocks:
   header, body, metadata, then actions aligned at the bottom. */
.cf-product .cf-card-structured {
    display: flex;
    flex-direction: column;
}

.cf-product .cf-card-header {
    margin-block-end: var(--space-4);
}

.cf-product .cf-card-title {
    margin: 0;
    color: var(--cf-text);
    font-size: var(--font-lg);
    font-weight: 700;
}

.cf-product .cf-card-body {
    flex: 1;
    min-width: 0;
}

.cf-product .cf-card-meta {
    margin-block-start: var(--space-3);
    color: var(--cf-text-secondary);
    font-size: var(--font-sm);
}

.cf-product .cf-card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-block-start: auto;
    padding-block-start: var(--space-4);
}

/* A badge without a semantic modifier remains neutral. Status must also be
   conveyed through visible text, never through color alone. */
.cf-product .cf-badge {
    display: inline-flex;
    align-items: center;
    border-radius: var(--radius-pill);
    padding: var(--space-1) 10px;
    background: var(--cf-surface-muted);
    color: var(--cf-text-secondary);
    font-size: var(--font-xs);
    font-weight: 600;
}

.cf-product .cf-badge-public {
    background: var(--cf-primary-050);
    color: var(--cf-primary-800);
}

.cf-product .cf-badge-unlisted,
.cf-product .cf-badge-completed {
    background: var(--cf-info-bg);
    color: var(--cf-info);
}

.cf-product .cf-badge-private {
    background: var(--cf-surface-muted);
    color: var(--cf-text-secondary);
}

.cf-product .cf-badge-active {
    background: var(--cf-success-bg);
    color: var(--cf-success);
}

.cf-product .cf-badge-cancelled {
    background: var(--cf-danger-bg);
    color: var(--cf-danger);
}

.cf-product .cf-status {
    white-space: nowrap;
}

/* Page headers keep the title, description, and primary action together. */
.cf-product .cf-page-header,
.cf-product .cf-page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: var(--space-4);
    margin-block: 0 var(--space-6);
}

.cf-product :is(.cf-page-header, .cf-page-head) :is(h1, h2) {
    margin: 0 0 var(--space-2);
    color: var(--cf-text);
    font-size: var(--font-2xl);
    font-weight: 700;
}

.cf-product :is(.cf-page-header, .cf-page-head) p {
    margin: 0;
    color: var(--cf-text-secondary);
}

.cf-product .cf-page-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.cf-product .cf-section-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-4);
    margin-block-end: var(--space-3);
}

.cf-product .cf-section-title :is(h2, h3) {
    margin: 0;
    font-size: var(--font-xl);
    font-weight: 700;
}

.cf-product .cf-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    border-block-end: 1px solid var(--cf-border);
}

.cf-product .cf-tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: var(--space-2) var(--space-4);
    border: 0;
    border-block-end: 2px solid transparent;
    border-radius: 0;
    background: transparent;
    color: var(--cf-text-secondary);
    font-family: var(--cf-font-family);
    font-size: var(--font-sm);
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
}

.cf-product .cf-tab:is(.is-active, [aria-selected="true"], [aria-current="page"]),
.cf-product .cf-tab:not(:disabled):not([aria-disabled="true"]):hover {
    color: var(--cf-primary-700);
}

.cf-product .cf-tab:is(.is-active, [aria-selected="true"], [aria-current="page"]) {
    border-block-end-color: var(--cf-primary-700);
}

.cf-product .cf-tab:focus-visible {
    outline: 3px solid var(--cf-focus);
    outline-offset: 2px;
}

.cf-product .cf-tab:disabled,
.cf-product .cf-tab[aria-disabled="true"] {
    opacity: .55;
    cursor: not-allowed;
}

/* Supply a visible explanation and useful action in the page's own context. */
.cf-product .cf-empty-state,
.cf-product .cf-empty {
    padding: var(--space-8) var(--space-5);
    border: 1px solid var(--cf-border);
    border-radius: var(--radius-lg);
    background: var(--cf-surface);
    color: var(--cf-text-secondary);
    text-align: center;
}

.cf-product .cf-empty-title {
    display: block;
    margin: 0 0 var(--space-2);
    color: var(--cf-text);
    font-size: var(--font-lg);
    font-weight: 700;
}

.cf-product .cf-empty-description {
    margin: 0;
}

.cf-product .cf-empty-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-2);
    margin-block-start: var(--space-4);
}

/* Use role="status" for visible loading/save text and aria-busy on the region.
   Skeletons and spinners are decorative and should have aria-hidden="true". */
.cf-product .cf-loading,
.cf-product .cf-save-status {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--cf-text-secondary);
    font-size: var(--font-sm);
}

.cf-product .cf-skeleton {
    min-height: var(--space-4);
    border-radius: var(--radius-sm);
    background: var(--cf-surface-muted);
}

.cf-product .cf-spinner {
    display: inline-block;
    width: var(--space-4);
    height: var(--space-4);
    flex-shrink: 0;
    border: 2px solid var(--cf-border);
    border-block-start-color: currentColor;
    border-radius: var(--radius-pill);
    animation: cf-spin 1s linear infinite;
}

.cf-product .cf-save-status[data-state="saving"] {
    color: var(--cf-text-secondary);
}

.cf-product .cf-save-status[data-state="saved"] {
    color: var(--cf-success);
}

.cf-product .cf-save-status[data-state="error"] {
    color: var(--cf-danger);
}

/* Optional feedback for long editors; the existing product header is 64px. */
.cf-product .cf-save-status-sticky {
    position: sticky;
    inset-block-start: var(--space-16);
    z-index: 20;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--cf-border);
    border-radius: var(--radius-md);
    background: var(--cf-surface);
    box-shadow: var(--shadow-sm);
}

.cf-product :is(.cf-btn, .cf-tab, .cf-empty-state, .cf-empty, .cf-loading, .cf-skeleton, .cf-spinner, .cf-save-status, .cf-tab-panel)[hidden] {
    display: none;
}

@keyframes cf-spin {
    to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
    .cf-product .cf-spinner { animation: none; }
}

@media (max-width: 767px) {
    .cf-product .cf-page-header,
    .cf-product .cf-page-head {
        flex-direction: column;
        align-items: stretch;
    }

    .cf-product :is(.cf-page-header, .cf-page-head) > .cf-btn:not(.cf-btn-icon) {
        width: 100%;
    }
}

/* Shared, opt-in feedback for program share/copy actions. */
.cf-product .cf-share-feedback {
    position: fixed;
    inset-inline-start: var(--space-6);
    inset-block-end: var(--cf-primary-nav-reserve);
    z-index: 25;
    max-width: calc(100% - var(--space-12));
    padding: var(--space-3);
    border: 1px solid var(--cf-border);
    border-radius: var(--radius-md);
    background: var(--cf-surface);
    box-shadow: var(--shadow-sm);
    overflow-wrap: anywhere;
}

@media (min-width: 1024px) {
    .cf-product.cf-has-primary-nav .cf-share-feedback {
        inset-inline-start: calc(var(--cf-primary-nav-width) + var(--space-6));
    }
}

/* Opt-in native dialogs: data-cf-dialog, an accessible name, and a clearly
   labelled data-cf-dialog-close button. Native modality supplies focus trapping. */
.cf-product dialog:is(.cf-modal, .cf-drawer) {
    padding: 0;
    border: 1px solid var(--cf-border);
    background: var(--cf-surface);
    color: var(--cf-text);
    font-family: var(--cf-font-family);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.cf-product dialog:is(.cf-modal, .cf-drawer)[open] {
    display: flex;
    flex-direction: column;
}

.cf-product dialog:is(.cf-modal, .cf-drawer):not([open]) {
    display: none;
}

.cf-product dialog.cf-modal {
    width: calc(100% - var(--space-8));
    max-width: 520px;
    max-height: calc(100dvh - var(--space-8));
    border-radius: var(--radius-xl);
}

.cf-product dialog.cf-drawer {
    inset-block: 0;
    inset-inline-start: 0;
    inset-inline-end: auto;
    margin: 0;
    width: 100%;
    max-width: 520px;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
}

.cf-product dialog:is(.cf-modal, .cf-drawer)::backdrop {
    background: color-mix(in srgb, var(--cf-text) 40%, transparent);
}

.cf-product .cf-dialog-header,
.cf-product .cf-dialog-footer {
    position: sticky;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-5);
    background: var(--cf-surface);
}

.cf-product .cf-dialog-header {
    inset-block-start: 0;
    justify-content: space-between;
    border-block-end: 1px solid var(--cf-border);
}

.cf-product .cf-dialog-title {
    margin: 0;
    font-size: var(--font-xl);
    font-weight: 700;
}

.cf-product .cf-dialog-body {
    flex: 1;
    min-height: 0;
    padding: var(--space-5);
    overflow-y: auto;
}

.cf-product .cf-dialog-footer {
    inset-block-end: 0;
    justify-content: flex-end;
    flex-wrap: wrap;
    border-block-start: 1px solid var(--cf-border);
}

.cf-product.cf-dialog-open {
    overflow: hidden;
}

/* Reuse the existing Font Awesome family. Decorative icons need aria-hidden;
   icon-only buttons retain their own Persian aria-label and title. */
.cf-product .cf-icon,
.cf-product .cf-btn-icon .fa,
.cf-product .cf-bottom-nav .fa {
    display: inline-block;
    width: 1em;
    height: 1em;
    font-size: 20px;
    line-height: 1;
    text-align: center;
    flex-shrink: 0;
}

.cf-product .cf-btn:not(.cf-btn-icon) .fa,
.cf-product .cf-icon-sm,
.cf-product .cf-btn .cf-icon-sm {
    font-size: 16px;
}

.cf-product .cf-icon-lg,
.cf-product .cf-btn .cf-icon-lg {
    font-size: 24px;
}

/* Shared controls remain usable when labels wrap at small viewport widths. */
.cf-product .cf-btn,
.cf-product .cf-tab {
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
}

/* A checkbox/radio keeps its native visual size; its associated label supplies
   the touch target when a later page migration opts into this shared wrapper. */
.cf-product .cf-choice {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 44px;
}

/* Optional mobile table cards require visible data-label values on cells.
   Existing tables retain their markup and locally scrollable wrappers. */
@media (max-width: 767px) {
    .cf-product .cf-table-cards,
    .cf-product .cf-table-cards tbody,
    .cf-product .cf-table-cards tr,
    .cf-product .cf-table-cards td {
        display: block;
        width: 100%;
    }

    .cf-product .cf-table-cards thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }

    .cf-product .cf-table-cards tr {
        margin-block-end: var(--space-4);
        border: 1px solid var(--cf-border);
        border-radius: var(--radius-lg);
        padding: var(--space-4);
        background: var(--cf-surface);
    }

    .cf-product .cf-table-cards td {
        border: 0;
        padding-block: var(--space-2);
        overflow-wrap: anywhere;
    }

    .cf-product .cf-table-cards td[data-label]::before {
        content: attr(data-label);
        display: block;
        color: var(--cf-text-secondary);
        font-size: var(--font-sm);
        font-weight: 500;
    }
}
