/* Raspa UI v2 component primitives. Namespace: r2-. */

/* Buttons */
.r2-button {
    display: inline-flex;
    min-height: var(--r2-control-height);
    align-items: center;
    justify-content: center;
    gap: var(--r2-space-2);
    padding: 0.55rem var(--r2-space-4);
    border: var(--r2-border-width) solid transparent;
    border-radius: var(--r2-radius-md);
    background: transparent;
    color: var(--r2-text);
    font-size: var(--r2-font-size-sm);
    font-weight: var(--r2-weight-medium);
    line-height: 1.2;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition:
        background-color var(--r2-duration-fast) var(--r2-ease-standard),
        border-color var(--r2-duration-fast) var(--r2-ease-standard),
        color var(--r2-duration-fast) var(--r2-ease-standard);
}

.r2-button:hover {
    text-decoration: none;
}

.r2-button:active {
    transition-duration: 0ms;
}

.r2-button:disabled,
.r2-button[aria-disabled="true"] {
    cursor: not-allowed;
    opacity: 0.58;
}

.r2-button--primary {
    border-color: var(--r2-primary);
    background: var(--r2-primary);
    color: #fff;
}

.r2-button--primary:hover:not(:disabled):not([aria-disabled="true"]) {
    border-color: var(--r2-primary-hover);
    background: var(--r2-primary-hover);
    color: #fff;
}

.r2-button--primary:active:not(:disabled):not([aria-disabled="true"]) {
    border-color: var(--r2-primary-active);
    background: var(--r2-primary-active);
}

.r2-button--secondary {
    border-color: var(--r2-border-strong);
    background: var(--r2-surface);
    color: var(--r2-text);
}

.r2-button--secondary:hover:not(:disabled):not([aria-disabled="true"]) {
    border-color: var(--r2-primary-border);
    background: var(--r2-primary-soft);
    color: var(--r2-primary-hover);
}

.r2-button--quiet {
    border-color: transparent;
    color: var(--r2-primary);
}

.r2-button--quiet:hover:not(:disabled):not([aria-disabled="true"]) {
    background: var(--r2-primary-soft);
    color: var(--r2-primary-hover);
}

.r2-button--danger {
    border-color: var(--r2-danger-border);
    background: var(--r2-surface);
    color: var(--r2-danger);
}

.r2-button--danger:hover:not(:disabled):not([aria-disabled="true"]) {
    border-color: var(--r2-danger);
    background: var(--r2-danger-soft);
    color: var(--r2-danger-hover);
}

.r2-button--small {
    min-height: var(--r2-control-height-sm);
    padding: 0.35rem var(--r2-space-3);
    font-size: var(--r2-font-size-xs);
}

.r2-button--large {
    min-height: var(--r2-control-height-lg);
    padding-inline: var(--r2-space-5);
    font-size: var(--r2-font-size-base);
}

.r2-button--icon {
    width: var(--r2-control-height);
    padding: 0;
}

.r2-button__spinner {
    width: 1em;
    height: 1em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: var(--r2-radius-pill);
    animation: r2-spin 700ms linear infinite;
}

@keyframes r2-spin {
    to { transform: rotate(1turn); }
}

/* Status and save state */
.r2-status {
    display: inline-flex;
    min-height: 1.5rem;
    align-items: center;
    gap: var(--r2-space-1);
    padding: 0.15rem 0.5rem;
    border: var(--r2-border-width) solid var(--r2-border);
    border-radius: var(--r2-radius-pill);
    background: var(--r2-surface-muted);
    color: var(--r2-text-secondary);
    font-size: var(--r2-font-size-xs);
    font-weight: var(--r2-weight-medium);
    line-height: 1.2;
    white-space: nowrap;
}

.r2-status::before {
    width: 0.42rem;
    height: 0.42rem;
    border-radius: var(--r2-radius-pill);
    background: currentColor;
    content: "";
}

.r2-status--success {
    border-color: var(--r2-success-border);
    background: var(--r2-success-soft);
    color: var(--r2-success);
}

.r2-status--warning {
    border-color: var(--r2-warning-border);
    background: var(--r2-warning-soft);
    color: var(--r2-warning);
}

.r2-status--danger {
    border-color: var(--r2-danger-border);
    background: var(--r2-danger-soft);
    color: var(--r2-danger);
}

.r2-status--info {
    border-color: var(--r2-info-border);
    background: var(--r2-info-soft);
    color: var(--r2-info);
}

.r2-save-state {
    display: inline-flex;
    align-items: center;
    gap: var(--r2-space-1);
    color: var(--r2-text-muted);
    font-size: var(--r2-font-size-xs);
    white-space: nowrap;
}

.r2-save-state::before {
    width: 0.5rem;
    height: 0.5rem;
    border: 1px solid currentColor;
    border-radius: var(--r2-radius-pill);
    content: "";
}

.r2-save-state[data-state="saved"] {
    color: var(--r2-success);
}

.r2-save-state[data-state="saving"]::before {
    border-right-color: transparent;
    animation: r2-spin 700ms linear infinite;
}

.r2-save-state[data-state="error"],
.r2-save-state[data-state="failed"],
.r2-save-state[data-state="conflict"] {
    color: var(--r2-danger);
}

.r2-save-state[data-state="dirty"] {
    color: var(--r2-warning);
}

/* Forms */
.r2-form-grid {
    container-type: inline-size;
    display: grid;
    grid-template-columns: repeat(2, minmax(15rem, 1fr));
    gap: var(--r2-space-4);
}

.r2-form-field {
    min-width: 0;
}

.r2-form-field--full {
    grid-column: 1 / -1;
}

.r2-form-label {
    display: inline-block;
    margin-block-end: var(--r2-space-2);
    color: var(--r2-text);
    font-size: var(--r2-font-size-sm);
    font-weight: var(--r2-weight-medium);
}

.r2-form-required {
    color: var(--r2-danger);
}

.r2-input,
.r2-select,
.r2-textarea {
    width: 100%;
    min-height: var(--r2-control-height);
    border: var(--r2-border-width) solid var(--r2-border-strong);
    border-radius: var(--r2-radius-md);
    background: var(--r2-surface);
    color: var(--r2-text);
    font-size: var(--r2-font-size-sm);
    line-height: 1.4;
    transition:
        border-color var(--r2-duration-fast) var(--r2-ease-standard),
        box-shadow var(--r2-duration-fast) var(--r2-ease-standard),
        background-color var(--r2-duration-fast) var(--r2-ease-standard);
}

.r2-input,
.r2-select {
    padding: 0.55rem var(--r2-space-3);
}

.r2-textarea {
    min-height: 6.5rem;
    padding: var(--r2-space-3);
    resize: vertical;
}

.r2-input:hover:not(:disabled),
.r2-select:hover:not(:disabled),
.r2-textarea:hover:not(:disabled) {
    border-color: var(--r2-primary-border);
}

.r2-input:focus,
.r2-select:focus,
.r2-textarea:focus {
    border-color: var(--r2-primary);
    outline: none;
    box-shadow: var(--r2-focus-ring);
}

.r2-input:disabled,
.r2-select:disabled,
.r2-textarea:disabled {
    border-color: var(--r2-border);
    background: var(--r2-surface-muted);
    color: var(--r2-text-disabled);
    cursor: not-allowed;
}

.r2-form-field[data-invalid="true"] .r2-input,
.r2-form-field[data-invalid="true"] .r2-select,
.r2-form-field[data-invalid="true"] .r2-textarea,
.r2-input[aria-invalid="true"],
.r2-select[aria-invalid="true"],
.r2-textarea[aria-invalid="true"] {
    border-color: var(--r2-danger);
}

.r2-form-help,
.r2-form-error {
    margin: var(--r2-space-1) 0 0;
    font-size: var(--r2-font-size-xs);
    line-height: 1.4;
}

.r2-form-help {
    color: var(--r2-text-muted);
}

.r2-form-error {
    color: var(--r2-danger);
    font-weight: var(--r2-weight-medium);
}

.r2-check-list {
    display: grid;
    gap: var(--r2-space-2);
}

.r2-check {
    display: flex;
    align-items: flex-start;
    gap: var(--r2-space-2);
    min-height: 2rem;
    padding-block: var(--r2-space-1);
    color: var(--r2-text);
    font-size: var(--r2-font-size-sm);
    cursor: pointer;
}

.r2-check input {
    width: 1rem;
    height: 1rem;
    flex: 0 0 auto;
    margin: 0.18rem 0 0;
    accent-color: var(--r2-primary);
}

.r2-check__content {
    min-width: 0;
}

.r2-check__label {
    display: block;
    font-weight: var(--r2-weight-medium);
}

.r2-check__help {
    display: block;
    margin-top: var(--r2-space-1);
    color: var(--r2-text-muted);
    font-size: var(--r2-font-size-xs);
}

.r2-switch {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--r2-space-4);
    min-height: 2.75rem;
    padding-block: var(--r2-space-2);
    border-bottom: var(--r2-border-width) solid var(--r2-divider);
    cursor: pointer;
}

.r2-switch:last-child {
    border-bottom: 0;
}

.r2-switch__text {
    min-width: 0;
}

.r2-switch__label {
    display: block;
    color: var(--r2-text);
    font-size: var(--r2-font-size-sm);
    font-weight: var(--r2-weight-medium);
}

.r2-switch__help {
    display: block;
    margin-top: var(--r2-space-1);
    color: var(--r2-text-muted);
    font-size: var(--r2-font-size-xs);
}

.r2-switch input {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
}

.r2-switch__track {
    position: relative;
    width: 2.5rem;
    height: 1.375rem;
    flex: 0 0 auto;
    border: var(--r2-border-width) solid var(--r2-border-strong);
    border-radius: var(--r2-radius-pill);
    background: var(--r2-surface-muted);
    transition:
        background-color var(--r2-duration-fast) var(--r2-ease-standard),
        border-color var(--r2-duration-fast) var(--r2-ease-standard);
}

.r2-switch__track::after {
    position: absolute;
    top: 0.1875rem;
    left: 0.1875rem;
    width: 0.875rem;
    height: 0.875rem;
    border-radius: var(--r2-radius-pill);
    background: var(--r2-text-muted);
    content: "";
    transition:
        transform var(--r2-duration-fast) var(--r2-ease-standard),
        background-color var(--r2-duration-fast) var(--r2-ease-standard);
}

.r2-switch input:checked + .r2-switch__track {
    border-color: var(--r2-primary);
    background: var(--r2-primary);
}

.r2-switch input:checked + .r2-switch__track::after {
    background: #fff;
    transform: translateX(1.125rem);
}

.r2-switch input:focus-visible + .r2-switch__track {
    outline: 2px solid var(--r2-focus-color);
    outline-offset: 2px;
    box-shadow: var(--r2-focus-ring);
}

.r2-switch input:disabled + .r2-switch__track,
.r2-switch:has(input:disabled) {
    opacity: 0.58;
    cursor: not-allowed;
}

@container (max-width: 34rem) {
    .r2-form-grid {
        grid-template-columns: 1fr;
    }
}

/* Alerts and issue rows */
.r2-alert {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--r2-space-4);
    padding: var(--r2-space-4);
    border: var(--r2-border-width) solid var(--r2-border);
    border-left-width: 3px;
    border-radius: var(--r2-radius-sm);
    background: var(--r2-surface);
}

.r2-alert--info {
    border-color: var(--r2-info-border);
    border-left-color: var(--r2-info);
    background: var(--r2-info-soft);
}

.r2-alert--success {
    border-color: var(--r2-success-border);
    border-left-color: var(--r2-success);
    background: var(--r2-success-soft);
}

.r2-alert--warning {
    border-color: var(--r2-warning-border);
    border-left-color: var(--r2-warning);
    background: var(--r2-warning-soft);
}

.r2-alert--danger {
    border-color: var(--r2-danger-border);
    border-left-color: var(--r2-danger);
    background: var(--r2-danger-soft);
}

.r2-alert__title {
    margin: 0;
    font-size: var(--r2-font-size-sm);
    font-weight: var(--r2-weight-bold);
}

.r2-alert__message {
    margin: var(--r2-space-1) 0 0;
    color: var(--r2-text-secondary);
    font-size: var(--r2-font-size-sm);
}

.r2-issue-list {
    border-top: var(--r2-border-width) solid var(--r2-divider);
}

.r2-issue-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--r2-space-4);
    align-items: center;
    padding: var(--r2-space-4) 0;
    border-bottom: var(--r2-border-width) solid var(--r2-divider);
}

.r2-issue-row__title {
    margin: 0;
    font-size: var(--r2-font-size-sm);
    font-weight: var(--r2-weight-medium);
}

.r2-issue-row__message {
    margin: var(--r2-space-1) 0 0;
    color: var(--r2-text-secondary);
    font-size: var(--r2-font-size-sm);
}

/* Summary strip */
.r2-summary-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
    border: var(--r2-border-width) solid var(--r2-border);
    border-radius: var(--r2-radius-sm);
    background: var(--r2-surface);
}

.r2-summary-item {
    min-width: 0;
    padding: var(--r2-space-4);
    border-right: var(--r2-border-width) solid var(--r2-divider);
}

.r2-summary-item:last-child {
    border-right: 0;
}

.r2-summary-item__value {
    display: block;
    color: var(--r2-text);
    font-size: var(--r2-font-size-xl);
    font-weight: var(--r2-weight-bold);
    line-height: var(--r2-line-tight);
}

.r2-summary-item__label {
    display: block;
    margin-top: var(--r2-space-1);
    color: var(--r2-text-muted);
    font-size: var(--r2-font-size-xs);
}

/* Tables */
.r2-table-wrap {
    width: 100%;
    overflow-x: auto;
    border-top: var(--r2-border-width) solid var(--r2-border);
    border-bottom: var(--r2-border-width) solid var(--r2-border);
    background: var(--r2-surface);
}

.r2-table {
    width: 100%;
    border-collapse: collapse;
    color: var(--r2-text);
    font-size: var(--r2-font-size-sm);
    text-align: left;
}

.r2-table th,
.r2-table td {
    min-height: var(--r2-table-row-min);
    padding: var(--r2-space-3) var(--r2-space-4);
    border-bottom: var(--r2-border-width) solid var(--r2-divider);
    vertical-align: middle;
}

.r2-table th {
    background: var(--r2-surface-subtle);
    color: var(--r2-text-secondary);
    font-size: var(--r2-font-size-xs);
    font-weight: var(--r2-weight-bold);
    letter-spacing: 0.015em;
}

.r2-table tbody tr:last-child td {
    border-bottom: 0;
}

.r2-table tbody tr:hover {
    background: var(--r2-surface-subtle);
}

.r2-table tbody tr[aria-selected="true"] {
    background: var(--r2-surface-selected);
}

.r2-table__primary {
    display: block;
    color: var(--r2-text);
    font-weight: var(--r2-weight-medium);
}

.r2-table__secondary {
    display: block;
    margin-top: var(--r2-space-1);
    color: var(--r2-text-muted);
    font-size: var(--r2-font-size-xs);
}

.r2-table__actions {
    width: 1%;
    white-space: nowrap;
    text-align: right;
}

/* Menus */
.r2-menu {
    position: relative;
    display: inline-block;
}

.r2-menu__panel {
    position: absolute;
    z-index: 30;
    top: calc(100% + var(--r2-space-1));
    right: 0;
    width: max-content;
    min-width: 12rem;
    padding: var(--r2-space-1);
    border: var(--r2-border-width) solid var(--r2-border);
    border-radius: var(--r2-radius-overlay);
    background: var(--r2-surface);
    box-shadow: var(--r2-shadow-menu);
}

.r2-menu__item {
    display: flex;
    width: 100%;
    min-height: 2.25rem;
    align-items: center;
    padding: var(--r2-space-2) var(--r2-space-3);
    border: 0;
    border-radius: var(--r2-radius-sm);
    background: transparent;
    color: var(--r2-text);
    font-size: var(--r2-font-size-sm);
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.r2-menu__item:hover,
.r2-menu__item:focus-visible {
    background: var(--r2-primary-soft);
    color: var(--r2-primary-hover);
}

.r2-menu__item--danger {
    color: var(--r2-danger);
}

.r2-menu__separator {
    height: 1px;
    margin: var(--r2-space-1) 0;
    background: var(--r2-divider);
}

/* Empty state */
.r2-empty-state {
    max-width: 38rem;
    padding: var(--r2-space-8) 0;
    text-align: left;
}

.r2-empty-state__title {
    margin-bottom: var(--r2-space-2);
    font-size: var(--r2-font-size-lg);
}

.r2-empty-state__message {
    margin-bottom: var(--r2-space-4);
    color: var(--r2-text-secondary);
    font-size: var(--r2-font-size-sm);
}

/* Disclosure */
.r2-disclosure {
    border-top: var(--r2-border-width) solid var(--r2-divider);
    border-bottom: var(--r2-border-width) solid var(--r2-divider);
}

.r2-disclosure__button {
    display: flex;
    width: 100%;
    min-height: 2.75rem;
    align-items: center;
    justify-content: space-between;
    gap: var(--r2-space-3);
    padding: var(--r2-space-2) 0;
    border: 0;
    background: transparent;
    color: var(--r2-primary);
    font-size: var(--r2-font-size-sm);
    font-weight: var(--r2-weight-medium);
    text-align: left;
    cursor: pointer;
}

.r2-disclosure__icon {
    transition: transform var(--r2-duration-fast) var(--r2-ease-standard);
}

.r2-disclosure__button[aria-expanded="true"] .r2-disclosure__icon {
    transform: rotate(180deg);
}

.r2-disclosure__panel {
    padding: 0 0 var(--r2-space-4);
    color: var(--r2-text-secondary);
    font-size: var(--r2-font-size-sm);
}

/* Dialog */
.r2-dialog {
    width: min(34rem, calc(100vw - 2rem));
    max-height: calc(100vh - 2rem);
    padding: 0;
    overflow: auto;
    border: var(--r2-border-width) solid var(--r2-border);
    border-radius: var(--r2-radius-overlay);
    background: var(--r2-surface);
    color: var(--r2-text);
    box-shadow: var(--r2-shadow-dialog);
}

.r2-dialog::backdrop {
    background: rgba(16, 29, 54, 0.54);
}

.r2-dialog__header,
.r2-dialog__body,
.r2-dialog__footer {
    padding: var(--r2-space-4) var(--r2-space-5);
}

.r2-dialog__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--r2-space-4);
    border-bottom: var(--r2-border-width) solid var(--r2-divider);
}

.r2-dialog__title {
    margin: 0;
    font-size: var(--r2-font-size-xl);
}

.r2-dialog__body p:last-child {
    margin-bottom: 0;
}

.r2-dialog__footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--r2-space-2);
    border-top: var(--r2-border-width) solid var(--r2-divider);
}

/* Skeleton */
.r2-skeleton {
    display: block;
    min-height: 1rem;
    border-radius: var(--r2-radius-sm);
    background:
        linear-gradient(90deg, var(--r2-surface-muted) 25%, #f7f8fa 45%, var(--r2-surface-muted) 65%);
    background-size: 240% 100%;
    animation: r2-skeleton 1.3s ease-in-out infinite;
}

@keyframes r2-skeleton {
    from { background-position: 100% 0; }
    to { background-position: -100% 0; }
}

@media (max-width: 44rem) {
    .r2-alert,
    .r2-issue-row {
        grid-template-columns: 1fr;
    }

    .r2-summary-strip {
        grid-template-columns: 1fr 1fr;
    }

    .r2-summary-item:nth-child(2n) {
        border-right: 0;
    }

    .r2-summary-item:nth-child(n + 3) {
        border-top: var(--r2-border-width) solid var(--r2-divider);
    }

    .r2-dialog__footer {
        flex-direction: column-reverse;
    }

    .r2-dialog__footer .r2-button {
        width: 100%;
    }
}

/* Native dialog surfaces must never inherit translucent page styles. */
.r2-dialog[open],
.r2-dialog[open] > .r2-dialog__header,
.r2-dialog[open] > .r2-dialog__body,
.r2-dialog[open] > .r2-dialog__footer {
    opacity: 1;
    background-color: var(--r2-surface);
}
