/* ADEVHUB Components — Buttons, badges, cards, modals, alerts, chips
   Uses design tokens from avex-colors.css
   Consolidates button styles from legacy-bridge.css
*/

/* ============================================
   BUTTONS
   ============================================ */

/* Base button reset and styles */
.btn {
    /* Reset */
    all: unset;
    box-sizing: border-box;
    font-family: inherit;
    
    /* Layout */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5ch;
    
    /* Sizing */
    padding: var(--space-sm) var(--space-lg);
    min-height: 40px;
    
    /* Typography */
    font-size: var(--text-base);
    font-weight: var(--font-semibold);
    line-height: 1.2;
    text-decoration: none;
    
    /* Visual */
    border: 1px solid transparent;
    border-radius: var(--radius-lg);
    cursor: pointer;
    
    /* Animation */
    transition: var(--transition-all-normal);
}

.btn:focus {
    outline: none;
    box-shadow: var(--focus-ring);
}

.btn:disabled,
.btn.disabled {
    opacity: var(--button-disabled-opacity);
    cursor: not-allowed;
    pointer-events: none;
}


/* Primary Button (Blue) */
.btn-primary {
    background: var(--avex-primary);
    color: var(--text-white);
    border-color: var(--avex-primary);
}

.btn-primary:hover {
    background: var(--avex-primary-dark);
    border-color: var(--avex-primary-dark);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
}


/* Secondary Button (Light) */
.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-header);
    border-color: var(--border-medium);
}

.btn-secondary:hover {
    background: var(--table-row-hover);
    border-color: var(--border-medium);
}


/* Danger Button (Red) */
.btn-danger {
    background: var(--avex-accent);
    color: var(--text-white);
    border-color: var(--avex-accent);
}

.btn-danger:hover {
    background: var(--avex-accent-hover);
    border-color: var(--avex-accent-hover);
    transform: translateY(-1px);
}


/* Success Button (Green) */
.btn-success {
    background: var(--success);
    color: var(--text-white);
    border-color: var(--success);
}

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


/* Warning Button (Orange) */
.btn-warning {
    background: var(--warning);
    color: var(--text-white);
    border-color: var(--warning);
}

.btn-warning:hover {
    background: #d97706;
    border-color: #d97706;
    transform: translateY(-1px);
}


/* Outline Variants */
.btn-outline-primary {
    background: transparent;
    color: var(--avex-primary);
    border-color: var(--avex-primary);
}

.btn-outline-primary:hover {
    background: var(--avex-primary);
    color: var(--text-white);
}

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

.btn-outline-secondary:hover {
    background: var(--bg-secondary);
}

.btn-outline-danger {
    background: transparent;
    color: var(--avex-accent);
    border-color: var(--avex-accent);
}

.btn-outline-danger:hover {
    background: var(--avex-accent);
    color: var(--text-white);
}


/* Ghost Button (no border) */
.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: transparent;
}

.btn-ghost:hover {
    background: var(--bg-tertiary);
}


/* Link Button */
.btn-link {
    background: transparent;
    color: var(--avex-primary);
    border-color: transparent;
    padding: 0;
    min-height: auto;
}

.btn-link:hover {
    color: var(--avex-primary-dark);
    text-decoration: underline;
}


/* Button Sizes */
.btn-sm {
    padding: var(--space-xs) var(--space-sm);
    min-height: 32px;
    font-size: var(--text-sm);
}

.btn-lg {
    padding: var(--space-md) var(--space-xl);
    min-height: 48px;
    font-size: var(--text-lg);
}

.btn-xl {
    padding: var(--space-lg) var(--space-2xl);
    min-height: 56px;
    font-size: var(--text-xl);
}


/* Full Width Button */
.btn-block {
    display: flex;
    width: 100%;
}


/* Icon-only Button */
.btn-icon {
    padding: var(--space-sm);
    min-width: 40px;
    min-height: 40px;
}

.btn-icon.btn-sm {
    padding: var(--space-xs);
    min-width: 32px;
    min-height: 32px;
}

/* ============================================
   REMOVE/DELETE BUTTONS (Icon-only Red X)
   ============================================ */

.btn-remove,
.btn-delete,
.btn-remove-sm,
.btn-delete-sm,
.btn-remove-lg,
.btn-delete-lg {
    /* Layout */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex-shrink: 0;              /* Prevent shrinking */
    
    /* Visual */
    background: var(--avex-accent);
    color: var(--text-white);
    border: none;
    border-radius: var(--radius-md);  /* More rounded */
    
    /* Interaction */
    cursor: pointer;
    transition: var(--transition-fast);
}

/* Size variants */
.btn-remove,
.btn-delete {
    width: 32px;
    height: 32px;
    min-width: 32px;             /* Prevent compression */
    min-height: 32px;
    aspect-ratio: 1 / 1;         /* Force square */
    font-size: var(--text-base);
}

.btn-remove-sm,
.btn-delete-sm {
    width: 24px;
    height: 24px;
    min-width: 24px;
    min-height: 24px;
    aspect-ratio: 1 / 1;
    font-size: var(--text-sm);
}

.btn-remove-lg,
.btn-delete-lg {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    aspect-ratio: 1 / 1;
    font-size: var(--text-lg);
}

/* Hover states */
.btn-remove:hover,
.btn-delete:hover,
.btn-remove-sm:hover,
.btn-delete-sm:hover,
.btn-remove-lg:hover,
.btn-delete-lg:hover {
    background: var(--avex-accent-hover);
    transform: scale(1.1);
}

/* Active states */
.btn-remove:active,
.btn-delete:active,
.btn-remove-sm:active,
.btn-delete-sm:active,
.btn-remove-lg:active,
.btn-delete-lg:active {
    transform: scale(1);
}

/* Button with Loading State */
.btn-loading {
    position: relative;
    color: transparent !important;
}

.btn-loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: btn-spin 0.75s linear infinite;
}

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


/* ============================================
   BUTTON GROUPS
   ============================================ */

.btn-group {
    display: inline-flex;
    gap: 0;
}

.btn-group .btn {
    border-radius: 0;
}

.btn-group .btn:first-child {
    border-top-left-radius: var(--radius-lg);
    border-bottom-left-radius: var(--radius-lg);
}

.btn-group .btn:last-child {
    border-top-right-radius: var(--radius-lg);
    border-bottom-right-radius: var(--radius-lg);
}

.btn-group .btn:not(:last-child) {
    border-right: none;
}


/* ============================================
   BADGES
   ============================================ */

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 8px;
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    line-height: 1.4;
    border-radius: var(--radius-round);
    white-space: nowrap;
}

.badge-primary {
    background: var(--avex-primary);
    color: var(--text-white);
}

.badge-secondary {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-light);
}

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

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

.badge-error {
    background: var(--error-light);
    color: var(--error);
}

.badge-info {
    background: var(--bg-secondary);
    color: var(--avex-primary);
}

/* Larger badge variant */
.badge-lg {
    padding: 4px 12px;
    font-size: var(--text-sm);
}


/* ============================================
   CHIPS / TAGS
   ============================================ */

.chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-sm);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
}

.chip-primary {
    background: var(--avex-primary);
    color: var(--text-white);
    border-color: var(--avex-primary);
}

.chip-success {
    background: var(--success-light);
    color: var(--success);
    border-color: var(--success-medium);
}

/* Removable chip */
.chip-removable {
    padding-right: var(--space-xs);
}

.chip-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    padding: 0;
    background: var(--avex-accent);
    color: var(--text-white);
    border: none;
    border-radius: 50%;
    font-size: 10px;
    cursor: pointer;
    transition: var(--transition-fast);
}

.chip-remove:hover {
    background: var(--avex-accent-hover);
}


/* ============================================
   CARDS
   ============================================ */

.card {
    background: var(--bg-primary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card-header {
    padding: var(--space-lg);
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-tertiary);
}

.card-header h3,
.card-header h4 {
    margin: 0;
}

.card-body {
    padding: var(--space-lg);
}

.card-footer {
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--border-light);
    background: var(--bg-tertiary);
}

/* Card variants */
.card-elevated {
    box-shadow: var(--shadow-lg);
}

.card-flat {
    box-shadow: none;
}

.card-interactive {
    cursor: pointer;
    transition: var(--transition-all);
}

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


/* ============================================
   MODALS
   ============================================ */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    padding: var(--space-lg);
}

.modal-overlay.active,
.modal-overlay[style*="display: flex"] {
    display: flex;
}

.modal {
    background: var(--bg-primary);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-modal);
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow: hidden;
    animation: modal-enter 0.2s ease-out;
}

@keyframes modal-enter {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(-10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-lg {
    max-width: 700px;
}

.modal-xl {
    max-width: 900px;
}

.modal-header {
    padding: var(--space-lg);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    margin: 0;
    color: var(--text-header);
}

.modal-close {
    background: none;
    border: none;
    padding: var(--space-xs);
    cursor: pointer;
    color: var(--text-muted);
    font-size: var(--text-xl);
    line-height: 1;
    transition: var(--transition-fast);
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: var(--space-lg);
    overflow-y: auto;
    max-height: 60vh;
}

.modal-footer {
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--border-light);
    background: var(--bg-tertiary);
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
}

/* Simple modal variant (from templates) */
.modal h3 {
    margin: 0 0 var(--space-md);
    color: var(--text-header);
}

.modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
    margin-top: var(--space-lg);
}


/* ============================================
   ALERTS / MESSAGES
   ============================================ */

.alert {
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-lg);
    font-size: var(--text-base);
}

.alert-icon {
    flex-shrink: 0;
    font-size: var(--text-lg);
}

.alert-content {
    flex: 1;
}

.alert-title {
    font-weight: var(--font-semibold);
    margin-bottom: var(--space-xs);
}

.alert-close {
    flex-shrink: 0;
    background: none;
    border: none;
    padding: var(--space-xs);
    cursor: pointer;
    opacity: 0.5;
    transition: var(--transition-fast);
}

.alert-close:hover {
    opacity: 1;
}

/* Alert variants */
.alert-info {
    background: var(--bg-secondary);
    color: var(--avex-primary-dark);
    border: 1px solid var(--avex-secondary);
}

.alert-success {
    background: var(--success-light);
    color: #065f46;
    border: 1px solid var(--success-medium);
}

.alert-warning {
    background: var(--warning-light);
    color: #92400e;
    border: 1px solid #fcd34d;
}

.alert-error {
    background: var(--error-light);
    color: #991b1b;
    border: 1px solid var(--error-border);
}

/* Inline alert (compact) */
.alert-inline {
    padding: var(--space-sm) var(--space-md);
    font-size: var(--text-sm);
}


/* ============================================
   TOAST NOTIFICATIONS
   ============================================ */

.toast-container {
    position: fixed;
    top: var(--space-lg);
    right: var(--space-lg);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    max-width: 400px;
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md);
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    animation: toast-enter 0.3s ease-out;
}

@keyframes toast-enter {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.toast-success {
    border-left: 4px solid var(--success);
}

.toast-error {
    border-left: 4px solid var(--error);
}

.toast-warning {
    border-left: 4px solid var(--warning);
}

.toast-info {
    border-left: 4px solid var(--avex-primary);
}


/* ============================================
   LOADING STATES
   ============================================ */

.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-light);
    border-top-color: var(--avex-primary);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

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

.spinner-sm {
    width: 14px;
    height: 14px;
    border-width: 1.5px;
}

.spinner-lg {
    width: 32px;
    height: 32px;
    border-width: 3px;
}

/* Loading overlay */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-dropdown);
}


/* ============================================
   DIVIDERS
   ============================================ */

.divider {
    display: flex;
    align-items: center;
    margin: var(--space-lg) 0;
    color: var(--text-muted);
    font-size: var(--text-sm);
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--border-light);
}

.divider:not(:empty)::before {
    margin-right: var(--space-md);
}

.divider:not(:empty)::after {
    margin-left: var(--space-md);
}


/* ============================================
   EMPTY STATES
   ============================================ */

.empty-state {
    text-align: center;
    padding: var(--space-2xl);
    color: var(--text-muted);
}

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

.empty-state-title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
}

.empty-state-description {
    font-size: var(--text-sm);
    margin-bottom: var(--space-lg);
}


/* ============================================
   TABS
   ============================================ */

.tabs {
    display: flex;
    gap: var(--space-sm);
    border-bottom: 2px solid var(--border-light);
    margin-bottom: var(--space-lg);
}

.tab-button {
    padding: var(--space-sm) var(--space-lg);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    font-size: var(--text-base);
    font-weight: var(--font-medium);
    color: var(--text-muted);
    transition: var(--transition-fast);
}

.tab-button:hover {
    color: var(--text-secondary);
}

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

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}


/* ============================================
   UTILITY: HIDDEN CLASS
   Used by JavaScript for toggling visibility
   ============================================ */

.hidden {
    display: none !important;
}

.invisible {
    visibility: hidden;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
