/* ============================================================
   Relict Custom UI Components
   No native browser styling — all custom controls
   ============================================================ */

/* Reset native form appearance globally within .relict-ui scope */
.relict-ui input:not([type="hidden"]),
.relict-ui textarea,
.relict-ui select,
.relict-ui button {
    font-family: var(--font);
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* Keep native checkbox/radio visible unless a custom Relict control wraps them */
.relict-ui input[type="checkbox"],
.relict-ui input[type="radio"] {
    -webkit-appearance: auto;
    -moz-appearance: auto;
    appearance: auto;
    width: 16px;
    height: 16px;
    accent-color: var(--electric);
}
.relict-ui .r-check input[type="checkbox"],
.relict-ui .ic-check input[type="checkbox"],
.relict-ui .ic-option-card input[type="checkbox"],
.relict-ui .ic-option-card input[type="radio"],
.relict-ui .ic-toggle-row input[type="checkbox"],
.relict-ui .ic-toggle-row input[type="radio"],
.relict-ui .inv-print-field input[type="checkbox"],
.relict-ui .inv-print-choice input[type="radio"],
.relict-ui .inv-print-size input[type="radio"],
.relict-ui .ic-label-content-option input[type="checkbox"],
.relict-ui .inv-table .ic-check input[type="checkbox"],
.relict-ui .inv-quick-tax .ic-check input[type="checkbox"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* ── Field wrapper ── */
.r-field { margin-bottom: 20px; }
.r-field:last-child { margin-bottom: 0; }

.r-label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: 8px;
    letter-spacing: 0.01em;
}
.r-label .r-required { color: #EF4444; margin-left: 2px; }

.r-hint {
    font-size: 0.75rem;
    color: var(--gray-400);
    margin-top: 6px;
}
.r-error {
    font-size: 0.75rem;
    color: #EF4444;
    margin-top: 6px;
    display: none;
}
.r-field.has-error .r-error { display: block; }
.r-field.has-error .r-control { border-color: #EF4444; box-shadow: 0 0 0 3px rgba(239,68,68,0.12); }

/* ── Text Input ── */
.r-control {
    display: flex;
    align-items: center;
    background: var(--surface-white);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    transition: border-color 0.15s, box-shadow 0.15s;
    position: relative;
    overflow: hidden;
}
.r-control:focus-within {
    border-color: var(--electric);
    box-shadow: 0 0 0 3px rgba(40, 184, 248, 0.15);
}
.r-control input,
.r-control textarea {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    padding: 12px 14px;
    font-size: 0.9375rem;
    color: var(--navy-900);
    width: 100%;
    min-width: 0;
}
.r-control textarea {
    resize: vertical;
    min-height: 100px;
    line-height: 1.5;
}
.r-control input::placeholder,
.r-control textarea::placeholder { color: var(--gray-400); }

.r-control-icon {
    padding: 0 12px;
    color: var(--gray-400);
    flex-shrink: 0;
    display: flex;
    align-items: center;
}
.r-control-icon .r-icon { font-size: 1.25rem; }
.r-control-action {
    padding: 0 12px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--gray-400);
    font-size: 0.8125rem;
    font-weight: 600;
    flex-shrink: 0;
    transition: color 0.15s;
}
.r-control-action:hover { color: var(--electric); }

/* ── Custom Checkbox / Toggle ── */
.r-check {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    cursor: pointer;
    user-select: none;
}
.r-check-box {
    width: 20px;
    height: 20px;
    border: 1.5px solid var(--border);
    border-radius: 6px;
    background: var(--surface-white);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
    margin-top: 1px;
}
.r-check-box svg {
    width: 12px;
    height: 12px;
    stroke: white;
    stroke-width: 3;
    fill: none;
    opacity: 0;
    transform: scale(0.5);
    transition: all 0.15s;
}
.r-check input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}
.r-check.is-checked .r-check-box {
    background: var(--gradient-primary);
    border-color: transparent;
}
.r-check.is-checked .r-check-box svg { opacity: 1; transform: scale(1); }
.r-check-label { font-size: 0.875rem; color: var(--gray-600); line-height: 1.4; }
.r-check-label a { color: var(--royal); }

/* ── Switch ── */
.r-switch-field { margin-bottom: 8px; }
.r-switch-field--compact { margin-bottom: 0; margin-top: 12px; }
.r-switch-heading {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--gray-500);
    margin-bottom: 10px;
}
.r-switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    user-select: none;
}
.r-switch input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    margin: 0;
    padding: 0;
    border: 0;
    clip: rect(0 0 0 0);
    overflow: hidden;
    pointer-events: none;
}
.r-switch-track {
    position: relative;
    width: 44px;
    height: 26px;
    background: #D5DEE8;
    border-radius: 999px;
    transition: background 0.2s, box-shadow 0.2s;
    flex-shrink: 0;
    box-shadow: inset 0 1px 2px rgba(7, 17, 31, 0.08);
}
.r-switch-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(7, 17, 31, 0.22);
    transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.r-switch input:checked + .r-switch-track,
.r-switch.is-on .r-switch-track {
    background: linear-gradient(135deg, #28B8F8, #3978FF);
    box-shadow: inset 0 1px 2px rgba(7, 17, 31, 0.12);
}
.r-switch input:checked + .r-switch-track .r-switch-thumb,
.r-switch.is-on .r-switch-thumb {
    transform: translateX(18px);
}
.r-switch input:focus-visible + .r-switch-track {
    outline: 2px solid rgba(40, 184, 248, 0.55);
    outline-offset: 2px;
    box-shadow: inset 0 1px 2px rgba(7, 17, 31, 0.12);
}
.r-switch-caption {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--gray-600);
    line-height: 1.3;
}
.r-switch input:checked ~ .r-switch-caption,
.r-switch.is-on .r-switch-caption {
    color: var(--navy-900);
}
.r-switch-text {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    font-weight: 600;
}
.r-switch-off { color: var(--navy-900); }
.r-switch-on { color: var(--gray-400); }
.r-switch input:checked ~ .r-switch-text .r-switch-off { color: var(--gray-400); }
.r-switch input:checked ~ .r-switch-text .r-switch-on { color: var(--navy-900); }

/* Compact primary / current toggles in forms */
.r-switch--compact {
    gap: 10px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    transition: border-color 0.15s, background 0.15s;
}
.r-switch--compact:hover {
    border-color: #B8C9DC;
}
.r-switch--compact.is-on,
.r-switch--compact:has(input:checked) {
    border-color: rgba(40, 184, 248, 0.45);
    background: rgba(40, 184, 248, 0.06);
}
.r-switch--compact .r-switch-track {
    width: 40px;
    height: 22px;
}
.r-switch--compact .r-switch-thumb {
    width: 16px;
    height: 16px;
    top: 3px;
    left: 3px;
}
.r-switch--compact input:checked + .r-switch-track .r-switch-thumb,
.r-switch--compact.is-on .r-switch-thumb {
    transform: translateX(18px);
}
.r-switch--compact .r-switch-caption {
    font-size: 0.8125rem;
}

.cf-toggle-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 20px;
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid rgba(148, 163, 184, 0.22);
}
.cf-toggle-row .r-switch-field--compact {
    margin-top: 0;
}
.r-field.is-disabled {
    opacity: 0.55;
    pointer-events: none;
}
.r-field.is-disabled .r-control input {
    background: var(--surface, #f1f5f9);
    color: var(--gray-400);
    cursor: not-allowed;
}


.r-prompt-copy {
    margin: 0 0 12px;
    color: var(--gray-600);
    font-size: .9rem;
    line-height: 1.45;
}

/* ── Custom Select ── */
.r-select { position: relative; }
.r-select.is-disabled {
    opacity: .55;
    pointer-events: none;
}
.r-select.is-disabled .r-select-trigger {
    cursor: not-allowed;
    background: var(--surface);
}
.r-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    background: var(--surface-white);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 0.9375rem;
    color: var(--navy-900);
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s, border-radius 0.15s;
    user-select: none;
    position: relative;
    z-index: 1;
}
.r-select-trigger:hover { border-color: #B8C9DC; }
.r-select.is-open .r-select-trigger {
    border-color: var(--electric);
    box-shadow: none;
    z-index: 10001;
}
.r-select.is-open:not(.is-open-up) .r-select-trigger {
    border-radius: 10px 10px 0 0;
    border-bottom-color: transparent;
}
.r-select.is-open-up .r-select-trigger {
    border-radius: 0 0 10px 10px;
    border-top-color: transparent;
}
.r-select-value {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.r-select-placeholder { color: var(--gray-400); }
.r-select-chevron {
    width: 16px;
    height: 16px;
    color: var(--gray-400);
    transition: transform 0.2s;
    flex-shrink: 0;
}
.r-select.is-open .r-select-chevron { transform: rotate(180deg); }
.r-select input[type="hidden"] { display: none; }

.r-select-menu {
    position: absolute;
    top: calc(100% - 1.5px);
    left: 0;
    right: 0;
    background: var(--surface-white);
    border: 1.5px solid var(--electric);
    border-top: none;
    border-radius: 0 0 10px 10px;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
    z-index: 10000;
    max-height: 220px;
    overflow-y: auto;
    display: none;
}
.r-select.is-open .r-select-menu { display: block; }
.r-select.is-open-up .r-select-menu {
    top: auto;
    bottom: calc(100% - 1.5px);
    border-top: 1.5px solid var(--electric);
    border-bottom: none;
    border-radius: 10px 10px 0 0;
    box-shadow: 0 -10px 28px rgba(15, 23, 42, 0.10);
}
/* Teleported menus (body) keep seamless join via JS positioning */
.r-select-menu.is-teleported {
    margin: 0;
}
.r-select-option {
    padding: 10px 14px;
    font-size: 0.9375rem;
    color: var(--navy-900);
    cursor: pointer;
    transition: background 0.1s;
}
.r-select-option:hover { background: rgba(40, 184, 248, 0.06); }
.r-select-option:first-child {
    border-radius: inherit;
}
.r-select-option.is-selected {
    background: rgba(40, 184, 248, 0.1);
    color: var(--electric);
    font-weight: 600;
}
.r-select-option.is-selected::after {
    content: 'check';
    font-family: 'Material Symbols Outlined';
    font-size: 1.125rem;
    float: right;
    color: var(--electric);
    font-variation-settings: 'FILL' 0, 'wght' 500, 'GRAD' 0, 'opsz' 24;
}

.contact-editor .cf-entry { overflow: visible; }
.contact-editor .cf-section { overflow: visible; }



/* ── Custom Buttons ── */
.r-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 22px;
    border-radius: 10px;
    font-size: 0.9375rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    white-space: nowrap;
    line-height: 1;
    font-family: var(--font);
}
.r-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.r-btn-primary {
    background: var(--gradient-primary);
    color: white;
    box-shadow: 0 2px 8px rgba(40, 184, 248, 0.3);
}
.r-btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(40, 184, 248, 0.4); }
.r-btn-secondary {
    background: var(--surface-white);
    color: var(--navy-900);
    border: 1.5px solid var(--border);
}
.r-btn-secondary:hover:not(:disabled) { border-color: var(--electric); color: var(--electric); }
.r-btn-ghost {
    background: transparent;
    color: var(--gray-600);
}
.r-btn-ghost:hover:not(:disabled) { background: rgba(40, 184, 248, 0.06); color: var(--electric); }
.r-btn-danger { background: #EF4444; color: white; }
.r-btn-danger:hover:not(:disabled) { background: #DC2626; }
.r-btn-sm { padding: 8px 16px; font-size: 0.8125rem; border-radius: 8px; }
.r-btn-lg { padding: 14px 28px; font-size: 1rem; }
.r-btn-block { width: 100%; }
.r-btn-icon { padding: 10px; border-radius: 8px; }

/* ── Password Strength ── */
.r-strength { margin-top: 8px; }
.r-strength-bar {
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    overflow: hidden;
}
.r-strength-fill {
    height: 100%;
    border-radius: 2px;
    width: 0;
    transition: width 0.3s, background 0.3s;
}
.r-strength-fill.weak { width: 33%; background: #EF4444; }
.r-strength-fill.fair { width: 66%; background: #F59E0B; }
.r-strength-fill.strong { width: 100%; background: #10B981; }
.r-strength-label {
    font-size: 0.6875rem;
    color: var(--gray-400);
    margin-top: 4px;
}

/* ── Modal ── */
.r-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(7, 17, 31, 0.55);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s, visibility 0.2s;
}
.r-modal-backdrop.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}
.r-modal-backdrop.r-confirm-backdrop {
    z-index: 2200;
}
.r-modal {
    background: var(--surface-white);
    border-radius: 14px;
    box-shadow: 0 24px 64px rgba(7, 17, 31, 0.2);
    width: 100%;
    max-width: 440px;
    transform: translateY(12px) scale(0.97);
    transition: transform 0.2s;
    overflow: hidden;
}
/* Inventory check modals need room for multi-section forms */
.r-modal.ic-modal,
.r-modal.ic-modal--start {
    width: min(1180px, calc(100vw - 24px)) !important;
    max-width: min(1180px, calc(100vw - 24px)) !important;
}
.r-modal.ic-modal--review {
    width: min(780px, calc(100vw - 24px)) !important;
    max-width: min(780px, calc(100vw - 24px)) !important;
}
.r-modal.ic-modal--req {
    width: min(720px, calc(100vw - 24px)) !important;
    max-width: min(720px, calc(100vw - 24px)) !important;
}
.r-modal-backdrop.is-open .r-modal { transform: translateY(0) scale(1); }
.r-modal-header {
    padding: 24px 24px 0;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}
.r-modal-title { font-size: 1.125rem; font-weight: 700; color: var(--navy-900); }
.r-modal-close {
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 8px;
    border: none;
    background: var(--surface);
    color: var(--gray-500);
    cursor: pointer;
    display: grid;
    place-items: center;
    line-height: 1;
    flex-shrink: 0;
    transition: background 0.15s;
}
.r-modal-close .r-icon,
.r-modal-close .material-symbols-outlined {
    display: block;
    margin: 0;
    font-size: 1.125rem;
    line-height: 1;
}
.r-modal-close:hover { background: var(--border); color: var(--navy-900); }
.r-modal-body { padding: 16px 24px 24px; color: var(--gray-600); font-size: 0.9375rem; line-height: 1.6; }
.r-modal-footer {
    padding: 16px 24px 24px;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* ── Alert / Toast (custom) ── */
.r-alert {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    border-radius: 10px;
    font-size: 0.875rem;
    margin-bottom: 20px;
    border: 1px solid;
}
.r-alert-icon {
    flex-shrink: 0;
    margin-top: 1px;
    display: inline-flex;
    align-items: center;
}
.r-alert-icon .r-icon { font-size: 1.25rem; }
.r-alert-success { background: rgba(16,185,129,0.08); border-color: rgba(16,185,129,0.25); color: #059669; }
.r-alert-error { background: rgba(239,68,68,0.08); border-color: rgba(239,68,68,0.25); color: #DC2626; }
.r-alert-info { background: rgba(40,184,248,0.08); border-color: rgba(40,184,248,0.25); color: #0E8EC4; }

.r-toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}
.r-toast {
    background: var(--surface-white);
    border-radius: 10px;
    padding: 14px 18px;
    box-shadow: var(--shadow-lg);
    border-left: 4px solid var(--electric);
    font-size: 0.875rem;
    color: var(--navy-900);
    pointer-events: auto;
    animation: rToastIn 0.3s ease;
    min-width: 280px;
    max-width: 400px;
}
.r-toast.success { border-left-color: #10B981; }
.r-toast.error { border-left-color: #EF4444; }
@keyframes rToastIn {
    from { transform: translateX(110%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ── Auth layout (ensure styled even if app.css load order varies) ── */
.auth-layout {
    min-height: 100vh;
    min-height: 100dvh;
    width: 100%;
    display: grid;
    place-items: center;
    background: var(--gradient-hero);
    padding:
        max(16px, env(safe-area-inset-top))
        max(16px, env(safe-area-inset-right))
        max(16px, env(safe-area-inset-bottom))
        max(16px, env(safe-area-inset-left));
    box-sizing: border-box;
}
.auth-card {
    background: var(--surface-white);
    border-radius: 14px;
    padding: clamp(24px, 4vw, 40px);
    width: min(100%, 32rem);
    max-width: 100%;
    box-shadow: 0 24px 64px rgba(0,0,0,0.25);
    box-sizing: border-box;
}
.auth-card > form,
.auth-card .r-field,
.auth-card .r-alert,
.auth-card .r-btn-block {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}
.auth-card form {
    display: flex;
    flex-direction: column;
    width: 100%;
}
.auth-logo { text-align: center; margin-bottom: clamp(20px, 3vw, 32px); width: 100%; }
.auth-logo img { height: 56px; width: 56px; border-radius: 50%; margin-bottom: 12px; }
.auth-logo h1 { font-size: clamp(1.25rem, 2.5vw, 1.5rem); margin-bottom: 4px; }
.auth-logo p {
    color: var(--gray-500);
    font-size: 0.875rem;
    margin: 0 auto;
    max-width: 36ch;
    line-height: 1.45;
    overflow-wrap: anywhere;
}
.auth-footer {
    text-align: center;
    margin-top: 24px;
    font-size: 0.875rem;
    color: var(--gray-500);
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}
.auth-footer a { color: var(--royal); font-weight: 500; }
.auth-code-input .r-control input {
    text-align: center;
    letter-spacing: 0.28em;
    font-size: 1.25rem;
    font-weight: 700;
}

/* MFA verify — spacing tuned for alerts + single code field */
.auth-card--mfa-verify > .r-alert {
    margin-bottom: 12px;
}
.auth-card--mfa-verify > .r-alert:last-of-type {
    margin-bottom: 20px;
}
.auth-card--mfa-verify .auth-dev-code__value {
    display: inline-block;
    margin-left: 0.35em;
    letter-spacing: 0.12em;
    font-weight: 700;
}
.auth-verify-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
}
.auth-code-input .r-field {
    margin-bottom: 0;
}
.auth-code-input .r-control input {
    padding: 14px 16px;
    font-variant-numeric: tabular-nums;
}
.auth-footer--mfa {
    margin-top: 20px;
    gap: 12px;
}
.auth-footer--mfa .auth-resend-form {
    width: 100%;
    margin: 0;
}

.mfa-choose { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.mfa-method-card {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    text-align: left;
    padding: 16px;
    border-radius: 12px;
    border: 1.5px solid var(--border);
    background: var(--surface);
    cursor: pointer;
    font-family: var(--font);
    color: var(--navy-900);
    transition: border-color 0.15s, background 0.15s;
    box-sizing: border-box;
}
.mfa-method-card:hover {
    border-color: var(--electric);
    background: rgba(40, 184, 248, 0.06);
}
.mfa-method-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.mfa-method-text strong { font-size: 0.9375rem; }
.mfa-method-text small {
    font-size: 0.8125rem;
    color: var(--gray-500);
    overflow-wrap: anywhere;
}

/* ── App body baseline (fix unstyled dashboard) ── */
body.app-body {
    background: var(--surface);
    color: var(--navy-900);
    margin: 0;
    min-height: 100vh;
}

/* ── Drop zone (custom) ── */
.r-dropzone {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--surface);
}
.r-dropzone:hover,
.r-dropzone.is-dragover {
    border-color: var(--electric);
    background: rgba(40, 184, 248, 0.04);
}
.r-dropzone-icon {
    margin-bottom: 12px;
    opacity: 0.45;
    color: var(--gray-500);
    display: inline-flex;
}
.r-dropzone-icon .r-icon { font-size: 2.5rem; }
.r-dropzone input[type="file"] { display: none; }
.r-dropzone-name {
    color: var(--electric);
    margin-top: 8px;
    font-weight: 600;
    word-break: break-word;
}
.r-dropzone--compact {
    padding: 18px 16px;
}
.r-dropzone--compact .r-dropzone-icon {
    margin-bottom: 6px;
}
.r-dropzone--compact .r-dropzone-icon .r-icon { font-size: 1.75rem; }
.r-dropzone--compact p {
    margin: 0;
    font-size: 0.8125rem;
    color: var(--navy-900);
}
.r-dropzone--compact p.text-muted,
.r-dropzone--compact .text-muted {
    margin-top: 4px;
    color: var(--gray-500);
    font-size: 0.75rem;
}

/* ── Grid helpers ── */
.r-grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    width: 100%;
}
@media (max-width: 560px) {
    .r-grid-2 { grid-template-columns: 1fr; }
}

/* ── Color picker ── */
.r-field:has(> .r-color) {
    margin-bottom: 14px;
    position: relative;
    z-index: 1;
}
.r-field:has(> .r-color.is-open) {
    z-index: 1200;
}
.r-color {
    position: relative;
    width: 100%;
    margin: 0;
    z-index: 1;
    --r-color: #28B8F8;
    --r-color-h: 199;
    --r-color-s: 93%;
    --r-color-l: 56%;
}
.r-color.is-open {
    z-index: 1200;
}
.r-color-control {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 3px 4px 3px 3px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-white);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.r-color.is-open .r-color-control,
.r-color-control:focus-within {
    border-color: var(--electric);
    box-shadow: 0 0 0 3px rgba(40, 184, 248, 0.18);
}
.r-color-swatch {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: 1px solid rgba(15, 23, 42, 0.12);
    background: var(--r-color);
    cursor: pointer;
    flex-shrink: 0;
    padding: 0;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
}
.r-color-hex {
    flex: 1;
    min-width: 0;
    border: none;
    outline: none;
    background: transparent;
    font: inherit;
    font-size: 0.875rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--navy-900);
}
.r-color-caret {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--gray-500);
    cursor: pointer;
}
.r-color-caret:hover { background: rgba(148, 163, 184, 0.16); color: var(--navy-900); }
.r-color.is-open .r-color-caret .r-icon { transform: rotate(180deg); }
.r-color-caret .r-icon { transition: transform 0.15s; }

.r-color-panel {
    position: absolute;
    z-index: 1210;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    min-width: 260px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface-white);
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.14);
}
.r-color-panel[hidden] { display: none !important; }
.r-color-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}
.r-color-panel-head strong {
    font-size: 0.8125rem;
    color: var(--navy-900);
}
.r-color-panel-preview {
    width: 24px;
    height: 24px;
    border-radius: 999px;
    border: 1px solid rgba(15, 23, 42, 0.12);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}
.r-color-presets {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: 8px;
}
.r-color-preset {
    aspect-ratio: 1;
    border-radius: 8px;
    border: 1px solid rgba(15, 23, 42, 0.1);
    cursor: pointer;
    padding: 0;
    position: relative;
}
.r-color-preset.is-selected {
    outline: 2px solid var(--electric);
    outline-offset: 1px;
}
.r-color-preset[data-r-color-preset="#FFFFFF"],
.r-color-preset[data-r-color-preset="#F8FAFC"] {
    box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.12);
}
.r-color-sliders {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.r-color-slider {
    display: grid;
    grid-template-columns: 70px minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    min-height: 18px;
    font-size: 0.6875rem;
    font-weight: 700;
    color: var(--gray-500);
    line-height: 1;
}
.r-color-slider input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 18px;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 999px;
    background-color: transparent;
    background-image: none;
    background-repeat: no-repeat;
    background-position: center;
    background-size: 100% 8px;
    cursor: pointer;
}
.r-color-slider input[type="range"]::-webkit-slider-runnable-track {
    height: 8px;
    border-radius: 999px;
    border: 1px solid rgba(15, 23, 42, 0.1);
    background: #e2e8f0;
}
.r-color-slider input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    margin-top: -4px;
    border-radius: 50%;
    border: 2px solid #fff;
    background: var(--r-color);
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.35);
}
.r-color-slider input[type="range"]::-moz-range-track {
    height: 8px;
    border-radius: 999px;
    border: 1px solid rgba(15, 23, 42, 0.1);
    background: #e2e8f0;
}
.r-color-slider input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border: 2px solid #fff;
    border-radius: 50%;
    background: var(--r-color);
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.35);
}

/* Hue — keep vendor rules separate (combined ::-webkit/::-moz selectors get dropped) */
.r-color-slider input[data-r-color-h] {
    background-image: linear-gradient(90deg,
        #ff0000 0%, #ffff00 17%, #00ff00 33%, #00ffff 50%,
        #0000ff 67%, #ff00ff 83%, #ff0000 100%);
}
.r-color-slider input[data-r-color-h]::-webkit-slider-runnable-track {
    background: linear-gradient(90deg,
        #ff0000 0%, #ffff00 17%, #00ff00 33%, #00ffff 50%,
        #0000ff 67%, #ff00ff 83%, #ff0000 100%);
}
.r-color-slider input[data-r-color-h]::-moz-range-track {
    background: linear-gradient(90deg,
        #ff0000 0%, #ffff00 17%, #00ff00 33%, #00ffff 50%,
        #0000ff 67%, #ff00ff 83%, #ff0000 100%);
}

/* Saturation */
.r-color-slider input[data-r-color-s] {
    background-image: linear-gradient(90deg,
        hsl(var(--r-color-h), 0%, var(--r-color-l)),
        hsl(var(--r-color-h), 100%, var(--r-color-l)));
}
.r-color-slider input[data-r-color-s]::-webkit-slider-runnable-track {
    background: linear-gradient(90deg,
        hsl(var(--r-color-h), 0%, var(--r-color-l)),
        hsl(var(--r-color-h), 100%, var(--r-color-l)));
}
.r-color-slider input[data-r-color-s]::-moz-range-track {
    background: linear-gradient(90deg,
        hsl(var(--r-color-h), 0%, var(--r-color-l)),
        hsl(var(--r-color-h), 100%, var(--r-color-l)));
}

/* Brightness */
.r-color-slider input[data-r-color-l] {
    background-image: linear-gradient(90deg,
        #000000 0%,
        hsl(var(--r-color-h), var(--r-color-s), 50%) 50%,
        #ffffff 100%);
}
.r-color-slider input[data-r-color-l]::-webkit-slider-runnable-track {
    background: linear-gradient(90deg,
        #000000 0%,
        hsl(var(--r-color-h), var(--r-color-s), 50%) 50%,
        #ffffff 100%);
}
.r-color-slider input[data-r-color-l]::-moz-range-track {
    background: linear-gradient(90deg,
        #000000 0%,
        hsl(var(--r-color-h), var(--r-color-s), 50%) 50%,
        #ffffff 100%);
}
.r-color-tip {
    margin: 6px 0 0;
    font-size: 0.6875rem;
    color: var(--gray-400);
    line-height: 1.35;
}

.fb-color-field {
    position: relative;
    z-index: 1;
}
.fb-color-field:has(.r-color.is-open) {
    z-index: 1200;
}
.fb-color-field .r-color { margin-top: 2px; }
.fb-color-field .r-field { margin: 0; }
