/* Reusable UI Components */

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 0.5rem 1rem;
    font-weight: 600;
    font-size: 0.875rem;
    border-radius: var(--border-radius);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition-base);
    text-decoration: none;
    line-height: 1.5;
    white-space: nowrap;
    letter-spacing: -0.005em;
    position: relative;
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none !important;
}

.btn-primary {
    background: var(--color-primary-gradient);
    color: var(--text-inverse);
    box-shadow: var(--shadow-primary);
}

.btn-primary:hover:not(:disabled) {
    background: var(--color-primary-gradient-hover);
    box-shadow: var(--shadow-primary);
    transform: translateY(-1px);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: var(--shadow-primary);
}

.btn-outline {
    background: transparent;
    border-color: var(--border-color);
    color: var(--text-secondary);
}

.btn-outline:hover:not(:disabled) {
    border-color: var(--color-primary);
    color: var(--color-primary);
    background: var(--color-primary-light);
}

/* Pressed/selected state for outline toggles (view switchers etc.) */
.btn-outline.active {
    background: var(--color-primary-light);
    border-color: var(--color-primary);
    color: var(--color-primary);
}

/* Trail Navy secondary action */
.btn-secondary {
    background: var(--navy-800);
    color: var(--text-inverse);
    box-shadow: 0 4px 14px -2px rgba(27, 42, 65, 0.35);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--navy-700);
    transform: translateY(-1px);
}

.btn-secondary:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus-ring-color);
    outline-offset: var(--focus-ring-offset);
    box-shadow: 0 0 0 3px var(--focus-ring-soft);
}

.btn-danger {
    background: var(--color-danger-gradient);
    color: var(--text-inverse);
    box-shadow: var(--shadow-danger);
}

.btn-danger:hover:not(:disabled) {
    background: var(--color-danger-gradient-hover);
    transform: translateY(-1px);
}

.btn-success {
    background: var(--color-success);
    color: var(--text-inverse);
    box-shadow: 0 4px 14px -2px rgba(15, 157, 110, 0.35);
}

.btn-success:hover:not(:disabled) {
    background: var(--color-success-dark);
    transform: translateY(-1px);
}

.btn-sm {
    padding: 0.25rem 0.625rem;
    font-size: 0.8125rem;
    border-radius: var(--border-radius-sm);
}

.btn-lg {
    padding: 0.625rem 1.5rem;
    font-size: 1rem;
    border-radius: var(--border-radius);
}

.btn-block {
    width: 100%;
}

/* ── Forms ── */
.form {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    flex: 1;
}

.form-group label {
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    letter-spacing: 0.01em;
}

.form-row {
    display: flex;
    gap: var(--space-4);
}

.form-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.form-actions {
    display: flex;
    gap: var(--space-3);
    margin-top: var(--space-2);
}

.form-error {
    color: var(--color-danger);
    font-size: 0.8125rem;
    font-weight: 500;
    min-height: 1.25rem;
}

.form-success {
    color: var(--color-success);
    font-size: 0.8125rem;
    font-weight: 500;
    min-height: 1.25rem;
}

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

/* ── Inputs ── */
/* Every field that is a direct child of a .form-group gets the branded .input
   treatment automatically (no markup changes needed on the auth pages).
   :where() keeps specificity at (0,1,0) so page-level overrides still win. */
.input,
.form-group > :where(input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select, textarea) {
    padding: 0.5625rem 0.875rem;
    border: 1.5px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--bg-card);
    font-size: 0.9375rem;
    transition: all var(--transition-base);
    width: 100%;
    color: var(--text-primary);
}

.input:hover,
.form-group > :where(input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select, textarea):hover {
    border-color: var(--color-gray-300);
}

.input:focus,
.form-group > :where(input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select, textarea):focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--focus-ring-soft);
}

.input::placeholder,
.form-group > :where(input, textarea)::placeholder {
    color: var(--text-muted);
}

textarea.input,
.form-group > textarea {
    resize: vertical;
}

select.input,
.form-group > select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.875rem center;
    padding-right: var(--space-8);
}

/* Native tick/track controls follow the brand primary (tenant-themable). */
input[type="checkbox"],
input[type="radio"],
progress {
    accent-color: var(--color-primary);
}

/* ── Tables ── */
.table {
    width: 100%;
    text-align: left;
}

.table th {
    background: var(--color-gray-50);
    padding: var(--space-3) var(--space-4);
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-color);
}

.table td {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-color-light);
    font-size: 0.9rem;
}

.table tbody tr {
    transition: background var(--transition-fast);
}

.table tbody tr:hover {
    background: var(--color-gray-50);
}

.table-sm th,
.table-sm td {
    padding: var(--space-2) var(--space-3);
    font-size: 0.8125rem;
}

/* ── Badges ── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.1875rem 0.5rem;
    border-radius: var(--border-radius-full);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.badge-pending {
    background: var(--color-warning-light);
    color: var(--color-warning-dark);
}

.badge-processing {
    background: var(--color-info-light);
    color: var(--color-info-dark);
}

.badge-completed {
    background: var(--color-success-light);
    color: var(--color-success-dark);
}

.badge-failed {
    background: var(--color-danger-light);
    color: var(--color-danger-dark);
}

/* ── Loading Spinner ── */
.loading-spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid var(--color-gray-200);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ── Toasts ── */
.toast-container {
    position: fixed;
    bottom: var(--space-4);
    right: var(--space-4);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

/* Trail Navy base with a semantic accent rail per type. */
.toast {
    background: var(--navy-800);
    color: var(--text-inverse);
    padding: var(--space-3) var(--space-5);
    border-left: 3px solid var(--navy-500);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-xl);
    font-size: 0.875rem;
    animation: slideIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    max-width: 360px;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-weight: 500;
    backdrop-filter: blur(8px);
}

.toast-success {
    border-left-color: var(--color-success);
}

.toast-error {
    border-left-color: var(--color-danger);
}

.toast-warning {
    border-left-color: var(--color-warning);
}

.toast-info {
    border-left-color: var(--color-info);
}

.toast-icon {
    flex-shrink: 0;
    font-weight: 700;
    line-height: 1;
}

.toast-message {
    flex: 1 1 auto;
}

.toast-success .toast-icon { color: var(--color-success-light); }
.toast-error .toast-icon { color: var(--color-danger-light); }
.toast-warning .toast-icon { color: var(--color-warning-light); }
.toast-info .toast-icon { color: var(--color-info-light); }

.toast-dismiss {
    flex-shrink: 0;
    margin-left: auto;
    background: none;
    border: none;
    color: inherit;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 var(--space-1);
    opacity: 0.7;
}

.toast-dismiss:hover {
    opacity: 1;
}

.toast-leaving {
    animation: toastLeave 0.25s ease forwards;
}

@keyframes slideIn {
    from {
        transform: translateX(100%) scale(0.9);
        opacity: 0;
    }
    to {
        transform: translateX(0) scale(1);
        opacity: 1;
    }
}

@keyframes toastLeave {
    to {
        transform: translateX(110%);
        opacity: 0;
    }
}

/* ── OCR Status Badge on image ── */
.ocr-status-badge {
    text-align: center;
    margin-top: var(--space-3);
}

/* ── Clickable table row ── */
.clickable-row {
    cursor: pointer;
}

/* ── Empty state ── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: var(--space-12) var(--space-4);
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: var(--space-3);
    opacity: 0.5;
}

/* ── Brand illustrations (mascot / neutral set) ── */
.brand-illustration {
    display: inline-block;
    max-width: 100%;
    height: auto;
}

.empty-state .brand-illustration,
.empty-state-illustration {
    display: block;
    margin: 0 auto var(--space-4);
}

/* White-label gate: theme.js sets data-show-hound="1|0" on <html>. Every
   static mascot/hound <img> on an AUTHENTICATED surface must carry
   class="hound-art" so tenant branding can hide it. */
html[data-show-hound="0"] .hound-art {
    display: none !important;
}

/* Paired neutral fallback (round-4 contract): give a `.hound-art` img an
   optional sibling carrying `.hound-art-fallback` — a neutral
   [data-illustration] hook or a plain icon. The sibling stays hidden while
   the mascot is visible and appears only when the tenant gates the hound
   off, so no state ever looks empty. */
html:not([data-show-hound="0"]) .hound-art-fallback {
    display: none !important;
}

/* Gentle idle float (round-4 contract). Apply to LARGE art moments only —
   empty states, the 404 page, auth split panels — never to small inline
   art. Fully disabled under prefers-reduced-motion below. */
.art-bob {
    animation: artBob 5s ease-in-out infinite;
}

@keyframes artBob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

@media (prefers-reduced-motion: reduce) {
    .art-bob {
        animation: none;
    }
}

/* ── Paw loader (branded full-card loading state) ─────────────────────────
   Three paw prints stepping in sequence. Mascot-adjacent, so it is gated for
   white-label tenants: pair it with a sibling `.loading-spinner
   paw-loader-fallback` that only shows when the hound is hidden. */
.paw-loader {
    display: inline-flex;
    gap: var(--space-3);
}

.paw-loader i {
    width: 20px;
    height: 20px;
    background: var(--color-accent);
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='5' cy='9' r='2.3'/%3E%3Ccircle cx='9.6' cy='5.8' r='2.5'/%3E%3Ccircle cx='14.4' cy='5.8' r='2.5'/%3E%3Ccircle cx='19' cy='9' r='2.3'/%3E%3Cellipse cx='12' cy='15.5' rx='5.6' ry='4.8'/%3E%3C/svg%3E") no-repeat center / contain;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='5' cy='9' r='2.3'/%3E%3Ccircle cx='9.6' cy='5.8' r='2.5'/%3E%3Ccircle cx='14.4' cy='5.8' r='2.5'/%3E%3Ccircle cx='19' cy='9' r='2.3'/%3E%3Cellipse cx='12' cy='15.5' rx='5.6' ry='4.8'/%3E%3C/svg%3E") no-repeat center / contain;
    opacity: 0.15;
    animation: pawStep 1.2s ease-in-out infinite;
}

.paw-loader i:nth-child(2) {
    animation-delay: 0.2s;
    transform: translateY(-5px) rotate(10deg);
}

.paw-loader i:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes pawStep {
    0%, 60%, 100% { opacity: 0.15; }
    30% { opacity: 1; }
}

html[data-show-hound="0"] .paw-loader {
    display: none;
}

/* Neutral ring shown instead of the paws for white-label tenants. */
html:not([data-show-hound="0"]) .paw-loader-fallback {
    display: none;
}

/* Navbar brand mark + white-label logo swapped in by the theme engine. */
.brand-logo-img {
    display: inline-block;
    height: 44px;
    width: auto;
    border-radius: 50%;
    vertical-align: middle;
}

/* Default-brand two-tone wordmark lockup ("TheReceiptHound"): rendered by
   theme.js applyLogo for the default product name only — "The" small + raised,
   "Receipt" in trail navy, "Hound" in hound green. Custom white-label names
   stay plain text and inherit the surrounding brand color. */
[data-brand-name] .bn-the {
    font-size: 0.55em;
    vertical-align: super;
    margin-right: 1px;
}
[data-brand-name] .bn-the,
[data-brand-name] .bn-receipt {
    color: var(--navy-800);
}
[data-brand-name] .bn-hound {
    color: var(--hound-600);
}
/* On the dark footer the navy words flip to white; the green lightens. */
.site-footer [data-brand-name] .bn-the,
.site-footer [data-brand-name] .bn-receipt {
    color: var(--color-white);
}
.site-footer [data-brand-name] .bn-hound {
    color: var(--hound-300);
}

/* ── Alert banners ── */
.alert {
    padding: var(--space-3) var(--space-5);
    border-radius: var(--border-radius-lg);
    margin-bottom: var(--space-4);
    font-size: 0.9rem;
    line-height: 1.6;
    font-weight: 500;
}

.alert a {
    font-weight: 700;
    text-decoration: underline;
}

.alert-info {
    background: var(--color-info-light);
    border: 1px solid var(--color-info);
    color: var(--color-info-dark);
}

.alert-info a { color: var(--color-info-dark); }

.alert-warning {
    background: var(--color-warning-light);
    border: 1px solid var(--color-warning);
    color: var(--color-warning-dark);
}

.alert-warning a { color: var(--color-warning-dark); }

.alert-danger {
    background: var(--color-danger-light);
    border: 1px solid var(--color-danger);
    color: var(--color-danger-dark);
}

.alert-danger a { color: var(--color-danger-dark); }

/* ── Settings card ── */
.settings-card {
    max-width: 600px;
    margin-bottom: var(--space-6);
}

/* ── Settings sections ── */
.settings-section {
    margin-bottom: var(--space-8);
}

/* Navy heading with a short green trail rail — the admin-surface signature. */
.section-title {
    font-size: 1.125rem;
    font-weight: 700;
    margin-bottom: var(--space-2);
    color: var(--color-accent-text);
    border-left: 3px solid var(--color-primary);
    padding-left: var(--space-3);
}

.section-subtitle {
    color: var(--text-secondary);
    margin-bottom: var(--space-4);
    max-width: 600px;
    line-height: 1.7;
    font-size: 0.9375rem;
}

/* ── Profile avatar ── */
.profile-avatar-area {
    display: flex;
    align-items: center;
    gap: var(--space-5);
    margin-bottom: var(--space-6);
    padding-bottom: var(--space-6);
    border-bottom: 1px solid var(--border-color);
}

.profile-avatar {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: var(--border-radius-full);
    background: var(--color-primary-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

.avatar-letter {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-inverse);
    user-select: none;
}

.avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-avatar-actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.profile-avatar-actions .form-hint {
    margin-top: 0;
}

.page-subtitle {
    color: var(--text-secondary);
    margin-bottom: var(--space-6);
    max-width: 600px;
    line-height: 1.7;
}

.input-group {
    display: flex;
    gap: var(--space-2);
    align-items: center;
}

.input-group .input {
    flex: 1;
}

.form-hint {
    display: block;
    margin-top: var(--space-1);
    font-size: 0.8125rem;
    color: var(--text-muted);
}

/* ── Legal Pages ── */
.legal-page {
    max-width: 800px;
}

.legal-effective {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: var(--space-6);
}

.legal-content {
    padding: var(--space-8);
    line-height: 1.8;
}

.legal-content section {
    margin-bottom: var(--space-6);
}

.legal-content section:last-child {
    margin-bottom: 0;
}

.legal-content h3 {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--color-accent-text);
    border-bottom: 1px solid var(--navy-100);
    padding-bottom: var(--space-2);
    margin-bottom: var(--space-3);
}

.legal-content h4 {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-top: var(--space-4);
    margin-bottom: var(--space-2);
}

.legal-content p {
    margin-bottom: var(--space-3);
    color: var(--text-secondary);
    max-width: 70ch;
}

/* reset.css strips list markers globally; restore them for content lists. */
.legal-content ul,
.legal-content ol {
    margin: var(--space-2) 0 var(--space-4);
    padding-left: var(--space-6);
}

.legal-content ul {
    list-style: disc;
}

.legal-content ol {
    list-style: decimal;
}

.legal-content li {
    margin-bottom: var(--space-2);
    color: var(--text-secondary);
    max-width: 70ch;
}

.legal-content li::marker {
    color: var(--hound-600);
}

.form-hint a {
    color: var(--color-primary);
    text-decoration: underline;
}

.form-message {
    color: var(--color-success);
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: var(--space-3);
}

/* ── Provider info section ── */
.provider-info {
    margin-top: var(--space-8);
}

.provider-info h3 {
    margin-bottom: var(--space-4);
    font-weight: 700;
}

.provider-info .feature-card {
    text-align: center;
}

.provider-info .feature-card h4 {
    margin-bottom: var(--space-2);
    font-weight: 600;
}

.provider-info .feature-card p {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-3);
}

/* ---- Confidence Indicators ---- */
.confidence-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.6875rem;
    font-weight: 500;
    padding: 2px 6px;
    border-radius: 4px;
    vertical-align: middle;
    margin-left: 4px;
}

.confidence-high {
    background: var(--color-success-light);
    color: var(--color-success-dark);
}

.confidence-medium {
    background: var(--color-warning-light);
    color: var(--color-warning-dark);
}

.confidence-low {
    background: var(--color-danger-light);
    color: var(--color-danger-dark);
}

.confidence-unknown {
    background: var(--color-gray-100);
    color: var(--text-muted);
}

.confidence-bar {
    display: inline-block;
    width: 40px;
    height: 6px;
    background: var(--color-gray-200);
    border-radius: 3px;
    overflow: hidden;
    vertical-align: middle;
}

.confidence-bar-fill {
    display: block;
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s ease;
}

.confidence-bar-fill.high { background: var(--color-success); }
.confidence-bar-fill.medium { background: var(--color-warning); }
.confidence-bar-fill.low { background: var(--color-danger); }

/* ---- Extraction Summary ---- */
.extraction-summary {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: var(--space-4);
    margin-bottom: var(--space-4);
}

.extraction-summary h4 {
    margin-bottom: var(--space-3);
    font-size: 0.9375rem;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.extraction-meta {
    display: flex;
    gap: var(--space-4);
    flex-wrap: wrap;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-3);
}

.extraction-meta span {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ---- Categorization Info ---- */
.categorization-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 4px;
}

.categorization-info .cat-method {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.categorization-info .cat-ai-hint {
    color: var(--color-primary);
    font-size: 0.75rem;
    font-style: italic;
}

/* ---- Validation Warnings ---- */
.validation-warnings {
    margin-top: var(--space-3);
    padding: var(--space-3);
    background: var(--color-warning-light);
    border: 1px solid var(--color-warning);
    border-radius: var(--border-radius-sm);
    font-size: 0.8125rem;
}

.validation-warnings h5 {
    margin-bottom: var(--space-2);
    color: var(--color-warning-dark);
    font-size: 0.8125rem;
}

.validation-warnings ul {
    margin: 0;
    padding-left: var(--space-4);
    color: var(--color-warning-dark);
}

.validation-warnings li {
    margin-bottom: 2px;
}

/* ---- Extraction Error ---- */
.extraction-error {
    padding: var(--space-3) var(--space-4);
    background: var(--color-danger-light);
    border: 1px solid var(--color-danger);
    border-radius: var(--border-radius);
    color: var(--color-danger-dark);
    font-size: 0.875rem;
    margin-bottom: var(--space-4);
}

/* ---- Add Line Item Form ---- */
.add-line-item-form {
    display: flex;
    gap: var(--space-2);
    margin-top: var(--space-3);
    padding-top: var(--space-3);
    border-top: 1px solid var(--border-color);
    flex-wrap: wrap;
    align-items: flex-end;
}

.add-line-item-form .form-group {
    flex: 1;
    min-width: 80px;
    gap: 2px;
}

.add-line-item-form .form-group.desc-group {
    flex: 3;
    min-width: 150px;
}

.add-line-item-form label {
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.add-line-item-form .input {
    padding: var(--space-1) var(--space-2);
    font-size: 0.8125rem;
}

.add-line-item-form .btn {
    white-space: nowrap;
    align-self: flex-end;
}

/* ---- Overall Confidence Meter ---- */
.overall-confidence {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--border-radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
}

.overall-confidence .meter {
    flex: 1;
    max-width: 120px;
    height: 8px;
    background: var(--color-gray-200);
    border-radius: 4px;
    overflow: hidden;
}

.overall-confidence .meter-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.4s ease;
}

/* Semantic level classes so JS never has to inject raw hex colors. */
.meter-fill.high { background: var(--color-success); }
.meter-fill.medium { background: var(--color-warning); }
.meter-fill.low { background: var(--color-danger); }

/* Auto-processing spinner + status */
.processing-overlay {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-8);
    color: var(--text-secondary);
    text-align: center;
}

.processing-overlay .loading-spinner {
    width: 40px;
    height: 40px;
}

/* ===================== Duplicate Warning Banner ===================== */
.duplicate-warning-banner {
    background: var(--color-warning-light);
    border: 2px solid var(--color-warning);
    border-radius: var(--border-radius);
    padding: var(--space-4);
    margin-bottom: var(--space-4);
}

.duplicate-warning-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
    font-size: 1.05rem;
    color: var(--color-warning-dark);
}

.duplicate-icon {
    font-size: 1.3rem;
}

.duplicate-message {
    color: var(--color-warning-dark);
    margin-bottom: var(--space-3);
    font-size: 0.9rem;
}

.duplicate-matches {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
}

.duplicate-match-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: var(--space-3);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-4);
}

.duplicate-match-card .match-type {
    font-weight: 600;
    font-size: 0.85rem;
    min-width: 120px;
}

.duplicate-match-card .match-details {
    display: flex;
    gap: var(--space-3);
    font-size: 0.85rem;
    color: var(--text-secondary);
    flex: 1;
    min-width: 200px;
}

.duplicate-match-card .match-confidence {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.duplicate-match-card .match-info {
    font-size: 0.8rem;
    color: var(--text-muted);
    width: 100%;
}

.duplicate-actions {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
}

/* Inline duplicate/deleted flags — same pill geometry as the status badges. */
.badge-warning {
    display: inline-flex;
    align-items: center;
    background: var(--color-warning-light);
    color: var(--color-warning-dark);
    font-size: 0.6875rem;
    padding: 0.1875rem 0.5rem;
    border-radius: var(--border-radius-full);
    font-weight: 600;
    letter-spacing: 0.02em;
    margin-left: 4px;
    white-space: nowrap;
}

.badge-danger {
    display: inline-flex;
    align-items: center;
    background: var(--color-danger-light);
    color: var(--color-danger-dark);
    font-size: 0.6875rem;
    padding: 0.1875rem 0.5rem;
    border-radius: var(--border-radius-full);
    font-weight: 600;
    letter-spacing: 0.02em;
    margin-left: 4px;
    white-space: nowrap;
}

.row-deleted {
    opacity: 0.55;
}

/* ============================================================================
   Premium design-system additions (epic 04 T1)
   Accessible focus, loading / empty / error states, skeletons, brand footer.
   WCAG 2.2 AA: 2.4.13 (>=2px high-contrast focus ring), 2.5.8 (>=44px targets),
   prefers-reduced-motion support.
   ============================================================================ */

/* ── Accessible focus ring (2.4.13) ──────────────────────────────────────── */
/* Keyboard users get a clearly visible, high-contrast ring; pointer users do
   not (focus-visible). Applied broadly so every interactive control complies. */
:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus-ring-color);
    outline-offset: var(--focus-ring-offset);
    border-radius: var(--border-radius-sm);
}

.btn:focus-visible,
.input:focus-visible,
a:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus-ring-color);
    outline-offset: var(--focus-ring-offset);
}

/* ── Minimum tap targets (2.5.8) ─────────────────────────────────────────── */
.btn,
.icon-btn {
    min-height: var(--tap-target-min);
}

.btn-sm {
    /* Compact controls keep a usable target via padding/line-height. */
    min-height: 36px;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: var(--tap-target-min);
    padding: var(--space-2);
    border: 1px solid transparent;
    border-radius: var(--border-radius);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-base);
}

.icon-btn:hover:not(:disabled) {
    background: var(--color-gray-100);
    color: var(--text-primary);
}

/* ── Button loading state ────────────────────────────────────────────────── */
/* Disable interaction and show an inline spinner while a request is in flight.
   The label stays in the DOM (hidden) so the button keeps its width and any
   aria-label remains meaningful to assistive tech. */
.btn.is-loading {
    color: transparent !important;
    pointer-events: none;
    position: relative;
}

.btn.is-loading::after {
    content: '';
    position: absolute;
    width: 1em;
    height: 1em;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    color: var(--text-inverse);
    animation: spin 0.7s linear infinite;
}

.btn-outline.is-loading::after {
    color: var(--color-primary);
}

/* ── Input states (error / success / disabled) ───────────────────────────── */
.input.is-error,
.input[aria-invalid='true'],
.form-group > :where(input, select, textarea)[aria-invalid='true'] {
    border-color: var(--color-danger);
}

.input.is-error:focus,
.input[aria-invalid='true']:focus,
.form-group > :where(input, select, textarea)[aria-invalid='true']:focus {
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.14);
}

.input.is-success {
    border-color: var(--color-success);
}

.input:disabled,
.input[readonly],
.form-group > :where(input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select, textarea):disabled,
.form-group > :where(input, textarea)[readonly] {
    background: var(--color-gray-100);
    color: var(--text-muted);
    cursor: not-allowed;
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-card);
    padding: var(--space-6);
}

.card-interactive {
    cursor: pointer;
    transition: box-shadow var(--transition-base), transform var(--transition-base);
}

.card-interactive:hover {
    box-shadow: var(--shadow-card-hover);
    transform: translateY(-2px);
}

/* ── Skeleton loaders (aria-busy shimmer) ────────────────────────────────── */
.skeleton {
    display: block;
    background: linear-gradient(
        90deg,
        var(--color-gray-100) 25%,
        var(--color-gray-200) 37%,
        var(--color-gray-100) 63%
    );
    background-size: 400% 100%;
    border-radius: var(--border-radius-sm);
    animation: skeleton-shimmer 1.4s ease infinite;
}

.skeleton-text {
    height: 0.85em;
    margin-bottom: var(--space-2);
}

.skeleton-text:last-child {
    width: 60%;
    margin-bottom: 0;
}

.skeleton-title {
    height: 1.4em;
    width: 45%;
    margin-bottom: var(--space-3);
}

.skeleton-avatar {
    width: 48px;
    height: 48px;
    border-radius: var(--border-radius-full);
}

.skeleton-block {
    height: 120px;
    border-radius: var(--border-radius);
}

@keyframes skeleton-shimmer {
    0% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0 50%;
    }
}

/* ── Card-level state regions (loading / empty / error) ──────────────────── */
.state-region {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: var(--space-3);
    padding: var(--space-12) var(--space-4);
    color: var(--text-secondary);
}

.state-region .state-icon {
    font-size: 2.5rem;
    line-height: 1;
}

.state-region .state-title {
    font-size: var(--text-lg);
    font-weight: var(--weight-bold);
    color: var(--text-primary);
}

.state-region .state-message {
    max-width: 36ch;
    line-height: var(--leading-normal);
    color: var(--text-secondary);
}

.state-region--error .state-icon {
    color: var(--color-danger);
}

.state-region--error .state-title {
    color: var(--color-danger-dark);
}

/* Brand art inside a state region (error-recovery pattern, round 4):
   a static PNG tile carrying .hound-art, paired with a neutral
   [data-illustration] hook carrying .hound-art-fallback. Rendered by
   Utils.renderErrorState(); the cream art tile gets soft corners so it
   reads as a framed illustration on white cards. */
.state-region .state-art {
    display: block;
}

.state-region img.state-art {
    width: 160px;
    max-width: 100%;
    height: auto;
    border-radius: var(--border-radius-lg);
}

/* ── Brand / powered-by footer ───────────────────────────────────────────── */
/* The entity name is platform-fixed and never tenant-overridable. The whole
   line is removed (not dimmed) when an Enterprise tenant disables it. */
.powered-by {
    text-align: center;
    font-size: var(--text-xs);
    color: var(--text-muted);
    letter-spacing: var(--tracking-wide);
    padding: var(--space-4) 0;
}

.powered-by[hidden] {
    display: none;
}

/* Tenant gate: theme.js mirrors branding.show_powered_by onto
   <html data-show-powered-by="1|0"> (same pattern as the .hound-art gate), so
   the injected site footer's credit line disappears for Enterprise tenants
   that disable it. The branding-page live preview keeps managing its own
   #preview-powered-by node via the [hidden] attribute. */
html[data-show-powered-by="0"] .site-footer .powered-by {
    display: none !important;
}

/* ── Reduced motion (respect prefers-reduced-motion) ─────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }

    .skeleton {
        animation: none;
        background: var(--color-gray-100);
    }

    .loading-spinner,
    .btn.is-loading::after {
        animation: spin 1.2s linear infinite; /* keep a slow, non-flashing spin */
    }

    .paw-loader i {
        animation: pawStep 2.4s ease-in-out infinite; /* slow, non-flashing fade */
    }
}

/* ── Branding editor (epic-04 T8 admin UI) ───────────────────────────────── */
.branding-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 360px);
    gap: var(--space-6);
    align-items: start;
}

.branding-controls .settings-section {
    margin-bottom: var(--space-4);
}

.branding-preview-sticky {
    position: sticky;
    top: var(--space-4);
}

/* Toggle rows (mascot / trail language / powered-by) */
.toggle-row {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-2) 0;
    cursor: pointer;
}
.toggle-row + .toggle-row {
    border-top: 1px solid var(--border-color-light);
    margin-top: var(--space-2);
}
.toggle-row input[type="checkbox"] {
    margin-top: 3px;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}
.toggle-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.toggle-text .form-hint {
    margin: 0;
}

/* Compact inline checkbox label (dashboard / branding filter bars) */
.toggle-label {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    font-size: 0.875rem;
    color: var(--text-secondary);
    white-space: nowrap;
    cursor: pointer;
}

/* Primary-color picker row */
.color-input-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}
.color-input-row input[type="color"] {
    width: 44px;
    height: 44px;
    padding: 2px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    background: none;
    cursor: pointer;
    flex-shrink: 0;
}
.color-input-row .input {
    flex: 1;
    min-width: 0;
    font-family: var(--font-mono, monospace);
    text-transform: uppercase;
}

/* AA contrast status line */
.brand-aa-status {
    margin-top: var(--space-2);
    font-size: var(--text-sm);
    color: var(--text-secondary);
}
.brand-aa-status.is-ok {
    color: var(--color-success-dark);
}
.brand-aa-status.is-error {
    color: var(--color-danger);
    font-weight: 600;
}

/* Derived 50-900 ramp */
.brand-ramp {
    display: flex;
    gap: 2px;
    margin-top: var(--space-3);
    border-radius: var(--border-radius-sm);
    overflow: hidden;
}
.brand-ramp-chip {
    flex: 1;
    min-width: 0;
    height: 40px;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 3px;
    font-size: 10px;
    font-weight: 600;
}

/* Live preview card */
.preview-card {
    text-align: center;
}
.preview-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--color-primary);
    margin-bottom: var(--space-3);
}
.preview-logo .brand-logo-img,
#preview-logo img {
    max-height: 28px;
    width: auto;
    vertical-align: middle;
}
.preview-illustration {
    display: flex;
    justify-content: center;
    margin: var(--space-3) 0;
}
.preview-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}
.preview-greeting {
    color: var(--text-secondary);
    font-size: var(--text-sm);
    margin-bottom: var(--space-3);
}
.preview-actions {
    display: flex;
    gap: var(--space-2);
    justify-content: center;
    margin-bottom: var(--space-3);
}

@media (max-width: 768px) {
    .branding-layout {
        grid-template-columns: 1fr;
    }
    .branding-preview-sticky {
        position: static;
    }
}

/* ── Org switcher (navbar) — epic-04 T3 ─────────────────────────── */
.org-switcher {
    display: flex;
    align-items: center;
}
.org-switcher.hidden {
    display: none;
}
.org-select {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
    padding: var(--space-1) var(--space-6) var(--space-1) var(--space-2);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--bg-card);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    max-width: 12rem;
    cursor: pointer;
}
.org-select:hover {
    border-color: var(--color-primary);
}
.org-select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--focus-ring-soft);
}

/* ── Team page — epic-04 T3 ─────────────────────────────────────── */
.team-org-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    flex-wrap: wrap;
}
.team-org-summary > div:first-child {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}
.team-seats {
    color: var(--text-secondary);
    font-size: 0.875rem;
}
.team-subhead {
    margin: var(--space-4) 0 var(--space-2);
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
}
.table-wrap {
    overflow-x: auto;
}
.team-member-name strong {
    display: block;
}
.team-member-email {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}
.team-actions-col {
    white-space: nowrap;
    text-align: right;
}
.team-actions-col .btn + .btn {
    margin-left: var(--space-2);
}
.input-sm {
    padding: var(--space-1) var(--space-2);
    font-size: 0.8125rem;
}
.role-select {
    max-width: 8rem;
}
.invite-form {
    margin-bottom: var(--space-2);
}

/* ── Pricing / upgrade surface — epic-04 T4 ─────────────────────── */
.plans-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: var(--space-5);
    margin-top: var(--space-6);
    align-items: stretch;
}
.plans-grid.hidden {
    display: none;
}
.plan-card {
    position: relative;
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-card);
    padding: var(--space-6);
}
.plan-card-featured {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-md);
}
.plan-card-current {
    border-color: var(--color-success);
}
.plan-ribbon {
    position: absolute;
    top: 0;
    right: var(--space-5);
    transform: translateY(-50%);
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-inverse);
    padding: var(--space-1) var(--space-3);
    border-radius: 999px;
}
.plan-ribbon-popular {
    background: var(--color-primary);
}
.plan-ribbon-current {
    background: var(--color-success);
}
.plan-name {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 var(--space-2);
}
.plan-price {
    display: flex;
    align-items: baseline;
    gap: var(--space-1);
    margin-bottom: var(--space-4);
    min-height: 2.5rem;
}
.plan-price-amount {
    font-size: 2rem;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1;
}
.plan-price-period {
    font-size: 0.875rem;
    color: var(--text-muted);
}
.plan-meta {
    list-style: none;
    margin: 0 0 var(--space-4);
    padding: 0 0 var(--space-4);
    border-bottom: 1px solid var(--border-color-light);
}
.plan-meta li {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    padding: var(--space-1) 0;
}
.plan-features {
    list-style: none;
    margin: 0 0 var(--space-6);
    padding: 0;
    flex: 1 1 auto;
}
.plan-features li {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 0.875rem;
    padding: var(--space-1) 0;
    color: var(--text-secondary);
}
.plan-features li.feature-off {
    color: var(--text-muted);
}
.feature-mark {
    flex: 0 0 1.1rem;
    text-align: center;
    font-weight: 700;
}
.feature-on .feature-mark {
    color: var(--hound-600);
}
.feature-off .feature-mark {
    color: var(--text-muted);
}
.plan-card .btn-block {
    margin-top: auto;
}
.pricing-manage {
    margin-top: var(--space-6);
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9375rem;
}
.pricing-manage.hidden {
    display: none;
}

/* ── Billing management (epic-04 T5) ── */
.billing-plan-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    flex-wrap: wrap;
}
.billing-plan-name {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-right: var(--space-2);
}
.billing-reset-note {
    margin-top: var(--space-2);
    font-size: 0.875rem;
    color: var(--text-muted);
}
.billing-meters {
    margin-top: var(--space-5);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}
.billing-meter-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
}
.billing-meter-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
}
.billing-meter-value {
    font-size: 0.875rem;
    color: var(--text-muted);
}
.billing-meter .meter {
    height: 8px;
    background: var(--color-gray-200);
    border-radius: 4px;
    overflow: hidden;
}
.billing-meter .meter-fill {
    height: 100%;
    width: 0;
    border-radius: 4px;
    background: var(--color-success);
    transition: width 0.4s ease;
}
.billing-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    margin-top: var(--space-4);
}
.billing-cancel-note {
    margin-top: var(--space-3);
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* ── Trial banner + quota upgrade prompt (epic-04 T6) ── */
.trial-banner {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--color-warning-light);
    border-bottom: 1px solid var(--color-warning);
    color: var(--color-warning-dark);
}
.trial-banner-icon {
    font-size: 1.25rem;
    line-height: 1;
}
.trial-banner-text {
    flex: 1;
    min-width: 0;
    font-size: 0.9rem;
}
.trial-banner-text strong {
    font-weight: 700;
}
.trial-banner-sub {
    display: block;
    font-size: 0.8rem;
    opacity: 0.85;
}
.trial-banner-cta {
    flex-shrink: 0;
}
.trial-banner-dismiss {
    flex-shrink: 0;
    background: none;
    border: none;
    color: inherit;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 var(--space-2);
    opacity: 0.7;
}
.trial-banner-dismiss:hover {
    opacity: 1;
}

.upgrade-modal {
    max-width: 440px;
    text-align: center;
}
.upgrade-modal .modal-actions {
    justify-content: center;
}

@media (max-width: 600px) {
    .trial-banner {
        flex-wrap: wrap;
    }
    .trial-banner-text {
        flex-basis: 100%;
    }
}

/* ── Tabs (canonical underline-tab component) ────────────────────────────
   Shared pattern for queue/help/report tab rows — page classes may alias
   these rules instead of redefining the geometry. */
.tabs {
    display: flex;
    gap: var(--space-1);
    border-bottom: 2px solid var(--border-color-light);
    margin-bottom: var(--space-6);
    overflow-x: auto;
}

.tab {
    padding: var(--space-2) var(--space-4);
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    white-space: nowrap;
    transition: color var(--transition-fast), background var(--transition-fast),
        border-color var(--transition-fast);
}

.tab:hover {
    color: var(--text-primary);
    background: var(--color-gray-50);
}

.tab.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

/* ── Utilities ───────────────────────────────────────────────────────────── */
/* Screen-reader-only content (e.g. off-screen form labels, honeypots). */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* ── Brand polish: selection + scrollbars ────────────────────────────────── */
::selection {
    background: var(--hound-100);
    color: var(--hound-900);
}

html {
    scrollbar-width: thin;
    scrollbar-color: var(--color-gray-300) transparent;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--color-gray-300);
    border-radius: var(--border-radius-full);
    border: 2px solid transparent;
    background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
    background-color: var(--hound-300);
}
