/* ============================================
   NarrateAI Component Library
   Reusable UI components
   ============================================ */

/* ===== Buttons ===== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-6);
    font-family: var(--font-primary);
    font-size: var(--text-base);
    font-weight: var(--font-semibold);
    line-height: 1;
    text-decoration: none;
    text-align: center;
    white-space: nowrap;
    border: 2px solid transparent;
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-base);
    user-select: none;
}

.btn:focus-visible {
    outline: 2px solid var(--primary-start);
    outline-offset: 2px;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

/* Button Variants */

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

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

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

.btn-secondary {
    background: var(--surface-card);
    color: var(--primary-start);
    border-color: var(--primary-start);
    box-shadow: var(--shadow-sm);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--surface-card-hover);
    border-color: var(--primary-dark);
    color: var(--primary-dark);
    box-shadow: var(--shadow-md);
}

.btn-ghost {
    background: transparent;
    color: var(--text-primary);
}

.btn-ghost:hover:not(:disabled) {
    background: var(--surface-muted);
}

.btn-outline {
    background: transparent;
    color: var(--primary-start);
    border-color: var(--primary-start);
}

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

.btn-success {
    background: var(--gradient-success);
    color: var(--white);
    box-shadow: var(--shadow-md);
}

.btn-success:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* Button Sizes */

.btn-sm {
    padding: var(--space-2) var(--space-4);
    font-size: var(--text-sm);
}

.btn-lg {
    padding: var(--space-4) var(--space-8);
    font-size: var(--text-lg);
}

.btn-xl {
    padding: var(--space-5) var(--space-10);
    font-size: var(--text-xl);
    border-radius: var(--radius-xl);
}

.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: var(--radius-full);
}

.btn-block {
    width: 100%;
}

/* Theme Toggle */

.theme-toggle {
    min-width: 0;
}

.theme-toggle .theme-toggle-icon {
    font-size: 1.1rem;
    line-height: 1;
}

.theme-toggle .theme-toggle-text {
    font-size: var(--text-sm);
}

/* ===== Cards ===== */

.card {
    background: var(--surface-card);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    transition: all var(--transition-base);
}

.card-hover {
    cursor: pointer;
}

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

.card-header {
    padding: var(--space-6);
    border-bottom: 1px solid var(--surface-border);
}

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

.card-footer {
    padding: var(--space-6);
    border-top: 1px solid var(--surface-border);
    background: var(--surface-muted);
}

.card-image {
    width: 100%;
    height: auto;
    display: block;
    object-fit: cover;
}

.card-elevated {
    box-shadow: var(--shadow-xl);
}

.card-bordered {
    border: 1px solid var(--surface-border);
    box-shadow: none;
}

.card-gradient {
    background: var(--gradient-primary);
    color: var(--white);
}

/* ===== Form Elements ===== */

.form-group {
    margin-bottom: var(--space-6);
}

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

.form-label-required::after {
    content: " *";
    color: var(--error);
}

.form-input,
.form-textarea,
.form-select {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    font-family: var(--font-primary);
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    color: var(--text-primary);
    background: var(--surface-card);
    border: 2px solid var(--surface-border);
    border-radius: var(--radius-lg);
    transition: all var(--transition-base);
    appearance: none;
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
    outline: none;
    border-color: var(--primary-start);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-input::placeholder,
.form-textarea::placeholder {
    color: var(--gray-400);
}

.form-input:disabled,
.form-textarea:disabled,
.form-select:disabled {
    background: var(--surface-muted);
    cursor: not-allowed;
    opacity: 0.6;
}

.form-textarea {
    min-height: 120px;
    resize: vertical;
}

.form-select {
    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='%234b5563' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-4) center;
    padding-right: var(--space-10);
}

.form-error {
    display: block;
    margin-top: var(--space-2);
    font-size: var(--text-sm);
    color: var(--error);
}

.form-help {
    display: block;
    margin-top: var(--space-2);
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.form-input.error,
.form-textarea.error,
.form-select.error {
    border-color: var(--error);
}

.form-input.success,
.form-textarea.success,
.form-select.success {
    border-color: var(--success);
}

/* Checkbox & Radio */

.form-checkbox,
.form-radio {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    cursor: pointer;
}

.form-checkbox input,
.form-radio input {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--primary-start);
}

/* ===== Badges & Tags ===== */

.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-3);
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-radius: var(--radius-full);
    line-height: 1;
}

.badge-primary {
    background: rgba(102, 126, 234, 0.1);
    color: var(--primary-dark);
}

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

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

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

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

.badge-gray {
    background: var(--surface-muted);
    color: var(--text-secondary);
}

.badge-lg {
    padding: var(--space-2) var(--space-4);
    font-size: var(--text-sm);
}

/* ===== Loading States ===== */

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-8);
    color: var(--text-secondary);
}

.spinner {
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 4px solid var(--gray-200);
    border-top-color: var(--primary-start);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.spinner-sm {
    width: 20px;
    height: 20px;
    border-width: 2px;
}

.spinner-lg {
    width: 60px;
    height: 60px;
    border-width: 5px;
}

.skeleton {
    background: linear-gradient(
        90deg,
        var(--gray-200) 0%,
        var(--gray-300) 50%,
        var(--gray-200) 100%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: var(--radius-md);
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

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

.skeleton-heading {
    height: 2em;
    width: 60%;
}

.skeleton-circle {
    border-radius: 50%;
    width: 60px;
    height: 60px;
}

/* ===== Alerts & Messages ===== */

.alert {
    padding: var(--space-4) var(--space-5);
    border-radius: var(--radius-lg);
    border-left: 4px solid;
    margin-bottom: var(--space-4);
    display: flex;
    align-items: start;
    gap: var(--space-3);
}

.alert-success {
    background: var(--success-light);
    border-color: var(--success);
    color: var(--success-strong);
}

.alert-error {
    background: var(--error-light);
    border-color: var(--error);
    color: var(--error-strong);
}

.alert-warning {
    background: var(--warning-light);
    border-color: var(--warning);
    color: var(--warning-strong);
}

.alert-info {
    background: var(--info-light);
    border-color: var(--info);
    color: var(--info-strong);
}

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

.alert-content {
    flex: 1;
}

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

/* ===== Toast Notifications ===== */

.toast-container {
    position: fixed;
    top: var(--space-6);
    right: var(--space-6);
    z-index: var(--z-tooltip);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    min-width: 300px;
    max-width: 400px;
    padding: var(--space-4);
    background: var(--surface-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-2xl);
    display: flex;
    align-items: start;
    gap: var(--space-3);
    animation: slideInRight var(--transition-base) ease-out;
}

.toast-close {
    margin-left: auto;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    font-size: var(--text-lg);
    line-height: 1;
}

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

/* ===== Dividers ===== */

.divider {
    height: 1px;
    background: var(--surface-border);
    margin: var(--space-8) 0;
    border: none;
}

.divider-vertical {
    width: 1px;
    height: auto;
    background: var(--surface-border);
    margin: 0 var(--space-4);
}

/* ===== Icons ===== */

.icon {
    display: inline-block;
    width: 1em;
    height: 1em;
    stroke-width: 0;
    stroke: currentColor;
    fill: currentColor;
}

.icon-sm {
    width: 0.875em;
    height: 0.875em;
}

.icon-lg {
    width: 1.5em;
    height: 1.5em;
}

.icon-xl {
    width: 2em;
    height: 2em;
}

/* ===== Avatar ===== */

.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: var(--gradient-primary);
    color: var(--white);
    font-weight: var(--font-semibold);
    overflow: hidden;
}

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

.avatar-sm {
    width: 32px;
    height: 32px;
    font-size: var(--text-sm);
}

.avatar-lg {
    width: 56px;
    height: 56px;
    font-size: var(--text-lg);
}

.avatar-xl {
    width: 80px;
    height: 80px;
    font-size: var(--text-2xl);
}

/* ===== Progress Bar ===== */

.progress {
    width: 100%;
    height: 8px;
    background: var(--surface-border);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--gradient-primary);
    border-radius: var(--radius-full);
    transition: width var(--transition-base);
}

.progress-lg {
    height: 12px;
}

.progress-sm {
    height: 4px;
}

/* ===== Modal Backdrop ===== */

.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--surface-overlay);
    z-index: var(--z-modal-backdrop);
    animation: fadeIn var(--transition-base) ease-out;
}

/* ===== Back Button ===== */

.back-button {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    background: transparent;
    border: none;
    color: var(--primary-start);
    font-weight: var(--font-semibold);
    cursor: pointer;
    font-size: var(--text-base);
    padding: var(--space-2) 0;
    transition: all var(--transition-fast);
}

.back-button:hover {
    color: var(--primary-dark);
    transform: translateX(-4px);
}

/* ===== Responsive Adjustments ===== */

@media (max-width: 768px) {
    .btn {
        padding: var(--space-3) var(--space-5);
        font-size: var(--text-sm);
    }
    
    .btn-lg {
        padding: var(--space-4) var(--space-6);
        font-size: var(--text-base);
    }
    
    .card-body,
    .card-header,
    .card-footer {
        padding: var(--space-4);
    }
    
    .toast-container {
        right: var(--space-4);
        left: var(--space-4);
    }
    
    .toast {
        min-width: auto;
    }
}

@media (max-width: 640px) {
    .btn-xl {
        padding: var(--space-4) var(--space-8);
        font-size: var(--text-lg);
    }
}

