/* CRM design-system primitives layered on top of Django Admin theme tokens. */

:root {
    --ds-bg: var(--body-bg);
    --ds-bg-muted: var(--darkened-bg);
    --ds-text: var(--body-fg);
    --ds-text-muted: var(--body-quiet-color);
    --ds-border: var(--border-color);
    --ds-divider: var(--hairline-color);
    --ds-primary: var(--default-button-bg);
    --ds-primary-hover: var(--default-button-hover-bg);
    --ds-secondary: var(--button-bg);
    --ds-secondary-hover: var(--button-hover-bg);
    --ds-danger: var(--delete-button-bg);
    --ds-danger-hover: var(--delete-button-hover-bg);
    --ds-focus: var(--link-fg);
    --ds-error: var(--error-fg);
    --ds-radius-control: 8px;
    --ds-radius-panel: 12px;
    --ds-radius-pill: 999px;
    --ds-control-sm: 32px;
    --ds-control-md: 40px;
    --ds-control-lg: 48px;
    --ds-touch-target: 44px;
    --ds-space-1: 4px;
    --ds-space-2: 8px;
    --ds-space-3: 12px;
    --ds-space-4: 16px;
    --ds-space-5: 20px;
    --ds-space-6: 24px;
    --ds-space-8: 32px;
    --ds-shadow-panel: 0 1px 2px color-mix(in srgb, var(--body-fg) 8%, transparent);
    --ds-shadow-modal: var(--vv-admin-shadow);
    --ds-ease-fast: 120ms ease-out;
    --ds-ease-normal: 180ms ease-out;
    --ds-z-dropdown: 1000;
    --ds-z-sticky: 1100;
    --ds-z-modal: 9000;
    --ds-z-toast: 9500;
}

.ui-button,
a.ui-button,
input.ui-button {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--ds-space-2);
    min-width: 0;
    height: var(--ds-control-md);
    min-height: var(--ds-control-md);
    margin: 0;
    padding: 0 var(--ds-space-4);
    border: 1px solid transparent;
    border-radius: var(--ds-radius-control);
    font-family: var(--font-family-primary);
    font-size: 14px;
    font-weight: 600;
    line-height: 20px;
    text-align: center;
    text-decoration: none;
    text-transform: none;
    white-space: nowrap;
    cursor: pointer;
    transition:
        background var(--ds-ease-fast),
        border-color var(--ds-ease-fast),
        color var(--ds-ease-fast),
        transform var(--ds-ease-fast);
}

.ui-button--sm {
    height: var(--ds-control-sm);
    min-height: var(--ds-control-sm);
    padding-inline: var(--ds-space-3);
    font-size: 13px;
    line-height: 18px;
}

.ui-button--lg {
    height: var(--ds-control-lg);
    min-height: var(--ds-control-lg);
    padding-inline: var(--ds-space-5);
    font-size: 15px;
    line-height: 22px;
}

.ui-button--primary,
.ui-button--primary:link,
.ui-button--primary:visited {
    background: var(--ds-primary);
    color: var(--button-fg);
}

.ui-button--primary:hover,
.ui-button--primary:active {
    background: var(--ds-primary-hover);
    color: var(--button-fg);
}

.ui-button--secondary,
.ui-button--secondary:link,
.ui-button--secondary:visited {
    border-color: var(--ds-border);
    background: var(--ds-bg);
    color: var(--ds-text);
}

.ui-button--secondary:hover,
.ui-button--secondary:active {
    border-color: var(--ds-border);
    background: var(--ds-bg-muted);
    color: var(--ds-text);
}

.ui-button--ghost,
.ui-button--ghost:link,
.ui-button--ghost:visited {
    background: transparent;
    color: var(--ds-text);
}

.ui-button--ghost:hover,
.ui-button--ghost:active {
    background: var(--ds-bg-muted);
    color: var(--ds-text);
}

.ui-button--danger,
.ui-button--danger:link,
.ui-button--danger:visited {
    background: var(--ds-danger);
    color: var(--button-fg);
}

.ui-button--danger:hover,
.ui-button--danger:active {
    background: var(--ds-danger-hover);
    color: var(--button-fg);
}

.ui-button:active {
    transform: translateY(1px);
}

.ui-button:focus-visible,
.ui-control:focus-visible,
.ui-check:focus-visible {
    outline: 2px solid var(--ds-focus);
    outline-offset: 2px;
}

.ui-button:disabled,
.ui-button[aria-disabled="true"] {
    opacity: .45;
    cursor: not-allowed;
    transform: none;
}

.ui-button--icon {
    width: var(--ds-control-md);
    padding: 0;
}

.ui-button--full {
    width: 100%;
}

.ui-button__icon {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
}

.ui-button-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--ds-space-3);
}

.ui-button-group--end {
    justify-content: flex-end;
}

/* Conservative Django Admin compatibility layer. It deliberately targets only
   established action classes and controls inside form rows. */
body:not(.login) .button,
body:not(.login) a.button,
body:not(.login) button.button,
body:not(.login) input[type="submit"],
body:not(.login) input[type="button"],
body:not(.login) .submit-row input,
body:not(.login) .submit-row a.closelink {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--ds-space-2);
    height: var(--ds-control-md);
    min-height: var(--ds-control-md);
    margin: 0;
    padding: 0 var(--ds-space-4);
    border-radius: var(--ds-radius-control);
    font-family: var(--font-family-primary);
    font-size: 14px;
    font-weight: 600;
    line-height: 20px;
    text-align: center;
    text-decoration: none;
    text-transform: none;
    white-space: nowrap;
}

body:not(.login) a.button:not(.default),
body:not(.login) button.button:not(.default),
body:not(.login) .submit-row a.closelink {
    border: 1px solid var(--ds-border);
    background: var(--ds-bg);
    color: var(--ds-text);
}

body:not(.login) a.button:not(.default):hover,
body:not(.login) button.button:not(.default):hover,
body:not(.login) .submit-row a.closelink:hover {
    background: var(--ds-bg-muted);
    color: var(--ds-text);
}

body:not(.login) .button.default,
body:not(.login) input[type="submit"].default,
body:not(.login) .submit-row input.default {
    background: var(--ds-primary);
    color: var(--button-fg);
}

body:not(.login) .submit-row {
    gap: var(--ds-space-3);
    border-color: var(--ds-divider);
    border-radius: var(--ds-radius-panel);
}

body:not(.login) .form-row input:not([type]),
body:not(.login) .form-row input[type="text"],
body:not(.login) .form-row input[type="password"],
body:not(.login) .form-row input[type="email"],
body:not(.login) .form-row input[type="url"],
body:not(.login) .form-row input[type="number"],
body:not(.login) .form-row input[type="tel"],
body:not(.login) .form-row input[type="date"],
body:not(.login) .form-row input[type="time"],
body:not(.login) .form-row select:not([multiple]) {
    box-sizing: border-box;
    height: var(--ds-control-md);
    min-height: var(--ds-control-md);
    padding: 0 var(--ds-space-3);
    border-radius: var(--ds-radius-control);
    font-size: 14px;
    line-height: 20px;
}

body:not(.login) .form-row textarea {
    box-sizing: border-box;
    min-height: 96px;
    padding: 10px var(--ds-space-3);
    border-radius: var(--ds-radius-control);
    font-size: 14px;
    line-height: 20px;
}

.ui-control {
    box-sizing: border-box;
    width: 100%;
    min-height: var(--ds-control-md);
    margin: 0;
    padding: 0 var(--ds-space-3);
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-control);
    background: var(--ds-bg);
    color: var(--ds-text);
    font-family: var(--font-family-primary);
    font-size: 14px;
    font-weight: 400;
    line-height: 20px;
    transition: border-color var(--ds-ease-fast), outline-color var(--ds-ease-fast);
}

textarea.ui-control {
    min-height: 96px;
    padding-block: 10px;
    resize: vertical;
}

.ui-control:disabled {
    background: var(--ds-bg-muted);
    color: var(--ds-text-muted);
    cursor: not-allowed;
}

.ui-control[readonly] {
    background: var(--ds-bg-muted);
    color: var(--ds-text);
}

.ui-field {
    display: grid;
    gap: 6px;
}

.ui-field + .ui-field {
    margin-top: var(--ds-space-4);
}

.ui-field > label {
    color: var(--ds-text);
    font-size: 14px;
    font-weight: 600;
    line-height: 20px;
}

.ui-field__help,
.ui-field__error {
    margin: 0;
    font-size: 13px;
    line-height: 18px;
}

.ui-field__help {
    color: var(--ds-text-muted);
}

.ui-field__error {
    color: var(--ds-error);
}

.ui-modal {
    z-index: var(--ds-z-modal);
    box-sizing: border-box;
    width: min(560px, calc(100vw - 32px));
    max-height: calc(100dvh - 32px);
    padding: 0;
    overflow: auto;
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-panel);
    background: var(--ds-bg);
    color: var(--ds-text);
    box-shadow: var(--ds-shadow-modal);
}

.ui-modal::backdrop {
    background: color-mix(in srgb, var(--body-fg) 55%, transparent);
}

.ui-modal__header {
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--ds-space-3);
    min-height: 64px;
    padding: 18px var(--ds-space-6);
    border-bottom: 1px solid var(--ds-divider);
}

.ui-modal__header h1,
.ui-modal__header h2,
.ui-modal__header h3 {
    margin: 0;
    color: var(--ds-text);
    font-size: 20px;
    font-weight: 600;
    line-height: 28px;
    text-transform: none;
}

.ui-modal__body {
    padding: var(--ds-space-6);
}

.ui-modal__footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: var(--ds-space-3);
    padding: var(--ds-space-4) var(--ds-space-6);
    border-top: 1px solid var(--ds-divider);
    background: var(--ds-bg-muted);
}

.ui-modal__status {
    min-height: 18px;
    margin: var(--ds-space-3) 0 0;
    font-size: 13px;
    line-height: 18px;
}

.ui-modal__status:empty {
    min-height: 0;
    margin: 0;
}

.ui-spinner {
    box-sizing: border-box;
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: ui-spin 700ms linear infinite;
}

@keyframes ui-spin {
    to { transform: rotate(360deg); }
}

@media (max-width: 575px) {
    .ui-button--sm {
        min-height: var(--ds-touch-target);
    }

    .ui-modal {
        width: calc(100vw - 16px);
        max-height: calc(100dvh - 16px);
    }

    .ui-modal__header,
    .ui-modal__body,
    .ui-modal__footer {
        padding: var(--ds-space-4);
    }

    .ui-modal__footer {
        flex-direction: column-reverse;
    }

    .ui-modal__footer .ui-button,
    .ui-modal__footer .button,
    .ui-modal__footer input[type="submit"] {
        width: 100%;
        min-height: var(--ds-touch-target);
    }

    body:not(.login) .button,
    body:not(.login) a.button,
    body:not(.login) button.button,
    body:not(.login) input[type="submit"],
    body:not(.login) input[type="button"],
    body:not(.login) .submit-row input,
    body:not(.login) .submit-row a.closelink {
        min-height: var(--ds-touch-target);
    }
}

@media (prefers-reduced-motion: reduce) {
    .ui-button,
    .ui-control {
        transition: none;
    }

    .ui-spinner {
        animation-duration: 1400ms;
    }
}
