/**
 * Components
 * Buttons, forms, cards, and reusable UI components
 */

/* ============================================
   BUTTONS
   ============================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    line-height: 1.5;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent-primary);
    color: var(--bg-primary);
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-primary-hover);
    box-shadow: var(--shadow-glow);
}

.btn-secondary {
    background: var(--surface-2);
    color: var(--text-primary);
    border-color: var(--border-primary);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-hover);
    border-color: var(--border-secondary);
}

.btn-outline {
    background: transparent;
    color: var(--accent-primary);
    border-color: var(--accent-primary);
}

.btn-outline:hover:not(:disabled) {
    background: var(--accent-primary-muted);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-danger {
    background: var(--error);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: #ff5a6a;
}

.btn-sm {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-xs);
}

.btn-lg {
    padding: var(--space-4) var(--space-6);
    font-size: var(--text-base);
}

.btn-block {
    width: 100%;
}

.btn-icon {
    padding: var(--space-2);
    width: 40px;
    height: 40px;
}

/* ============================================
   FORM ELEMENTS
   ============================================ */

.form-group {
    margin-bottom: var(--space-5);
}

.form-label {
    display: block;
    margin-bottom: var(--space-2);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--text-secondary);
}

.form-label.required::after {
    content: ' *';
    color: var(--error);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-base);
    color: var(--text-primary);
    background-color: var(--surface-1);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.form-input:hover,
.form-select:hover,
.form-textarea:hover {
    border-color: var(--border-secondary);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-primary-muted);
}

.form-input::placeholder {
    color: var(--text-muted);
}

.form-input.error,
.form-select.error,
.form-textarea.error {
    border-color: var(--error);
}

.form-textarea {
    min-height: 100px;
    resize: vertical;
}

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23707080' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-3) center;
    padding-right: var(--space-10);
}

.form-hint {
    display: block;
    margin-top: var(--space-2);
    font-size: var(--text-xs);
    color: var(--text-tertiary);
}

.form-error {
    display: block;
    margin-top: var(--space-2);
    font-size: var(--text-xs);
    color: var(--error);
}

/* Checkbox and Radio */
.form-check {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    cursor: pointer;
    user-select: none;
}

.form-check input {
    width: 20px;
    height: 20px;
    accent-color: var(--accent-primary);
    cursor: pointer;
}

.form-check-label {
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

/* Radio group */
.radio-group {
    display: flex;
    gap: var(--space-4);
    flex-wrap: wrap;
}

.radio-card {
    flex: 1;
    min-width: 120px;
    padding: var(--space-4);
    background: var(--surface-1);
    border: 2px solid var(--border-primary);
    border-radius: var(--radius-lg);
    cursor: pointer;
    text-align: center;
    transition: all var(--transition-fast);
}

.radio-card:hover {
    border-color: var(--border-secondary);
}

.radio-card.selected {
    border-color: var(--accent-primary);
    background: var(--accent-primary-muted);
}

.radio-card input {
    display: none;
}

.radio-card-icon {
    font-size: var(--text-2xl);
    margin-bottom: var(--space-2);
}

.radio-card-label {
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--text-primary);
}

/* ============================================
   CARDS
   ============================================ */

.card {
    background: var(--surface-1);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.card-header {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
}

.card-title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    margin: 0;
    color: var(--text-primary);
}

.card-body {
    padding: var(--space-5);
}

.card-footer {
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--border-primary);
    background: var(--bg-tertiary);
}

.card-clickable {
    cursor: pointer;
    transition: all var(--transition-fast);
}

.card-clickable:hover {
    border-color: var(--border-secondary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* Stat card */
.stat-card {
    padding: var(--space-5);
    background: var(--surface-1);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
}

.stat-label {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-2);
}

.stat-value {
    font-size: var(--text-2xl);
    font-weight: var(--font-bold);
    color: var(--text-primary);
    font-family: var(--font-mono);
}

.stat-change {
    font-size: var(--text-xs);
    margin-top: var(--space-2);
}

.stat-change.positive {
    color: var(--success);
}

.stat-change.negative {
    color: var(--error);
}

/* ============================================
   ALERTS & MESSAGES
   ============================================ */

.alert {
    padding: var(--space-4);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-4);
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
}

.alert-icon {
    font-size: var(--text-lg);
    flex-shrink: 0;
}

.alert-content {
    flex: 1;
}

.alert-title {
    font-weight: var(--font-semibold);
    margin-bottom: var(--space-1);
}

.alert-success {
    background: var(--success-muted);
    border: 1px solid var(--success);
    color: var(--success);
}

.alert-warning {
    background: var(--warning-muted);
    border: 1px solid var(--warning);
    color: var(--warning);
}

.alert-error {
    background: var(--error-muted);
    border: 1px solid var(--error);
    color: var(--error);
}

.alert-info {
    background: var(--info-muted);
    border: 1px solid var(--info);
    color: var(--info);
}

/* ============================================
   TOAST NOTIFICATIONS
   ============================================ */

.toast-container {
    position: fixed;
    bottom: var(--space-6);
    right: var(--space-4);
    left: var(--space-4);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    pointer-events: none;
}

@media (min-width: 640px) {
    .toast-container {
        left: auto;
        width: 320px;
    }
}

.toast {
    padding: var(--space-4);
    background: var(--surface-2);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    pointer-events: auto;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast.hiding {
    animation: slideOut 0.3s ease forwards;
}

@keyframes slideOut {
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

.toast-icon {
    font-size: var(--text-lg);
}

.toast-message {
    flex: 1;
    font-size: var(--text-sm);
}

.toast-close {
    padding: var(--space-1);
    color: var(--text-muted);
    cursor: pointer;
}

.toast-close:hover {
    color: var(--text-primary);
}

.toast-success .toast-icon { color: var(--success); }
.toast-error .toast-icon { color: var(--error); }
.toast-warning .toast-icon { color: var(--warning); }
.toast-info .toast-icon { color: var(--info); }

/* ============================================
   BADGES
   ============================================ */

.badge {
    display: inline-flex;
    align-items: center;
    padding: var(--space-1) var(--space-2);
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
    border-radius: var(--radius-full);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.badge-primary {
    background: var(--accent-primary-muted);
    color: var(--accent-primary);
}

.badge-secondary {
    background: var(--surface-3);
    color: var(--text-secondary);
}

.badge-success {
    background: var(--success-muted);
    color: var(--success);
}

.badge-warning {
    background: var(--warning-muted);
    color: var(--warning);
}

.badge-error {
    background: var(--error-muted);
    color: var(--error);
}

/* ============================================
   LISTS
   ============================================ */

.list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.list-item {
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.list-item:last-child {
    border-bottom: none;
}

.list-item-clickable {
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

.list-item-clickable:hover {
    background-color: var(--bg-hover);
}

.list-item-content {
    flex: 1;
    min-width: 0;
}

.list-item-title {
    font-weight: var(--font-medium);
    color: var(--text-primary);
    margin-bottom: var(--space-1);
}

.list-item-subtitle {
    font-size: var(--text-sm);
    color: var(--text-tertiary);
}

.list-item-actions {
    display: flex;
    gap: var(--space-2);
}

/* ============================================
   EMPTY STATES
   ============================================ */

.empty-state {
    text-align: center;
    padding: var(--space-12) var(--space-6);
}

.empty-state-icon {
    font-size: 4rem;
    margin-bottom: var(--space-4);
    opacity: 0.5;
}

.empty-state-title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

.empty-state-description {
    color: var(--text-tertiary);
    margin-bottom: var(--space-6);
    max-width: 300px;
    margin-left: auto;
    margin-right: auto;
}

/* ============================================
   MODAL
   ============================================ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--surface-1);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: scale(0.95);
    transition: transform var(--transition-normal);
}

.modal-overlay.active .modal {
    transform: scale(1);
}

.modal-header {
    padding: var(--space-5);
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    margin: 0;
}

.modal-close {
    font-size: var(--text-xl);
    color: var(--text-muted);
    cursor: pointer;
    padding: var(--space-2);
    margin: calc(var(--space-2) * -1);
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: var(--space-5);
    overflow-y: auto;
}

.modal-footer {
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--border-primary);
    display: flex;
    gap: var(--space-3);
    justify-content: flex-end;
}

/* ============================================
   LOADING
   ============================================ */

.spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border-primary);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.spinner-sm {
    width: 16px;
    height: 16px;
}

.spinner-lg {
    width: 40px;
    height: 40px;
    border-width: 3px;
}

.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(10, 10, 15, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

/* ============================================
   DIVIDER
   ============================================ */

.divider {
    height: 1px;
    background: var(--border-primary);
    margin: var(--space-6) 0;
}

.divider-text {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    color: var(--text-muted);
    font-size: var(--text-sm);
}

.divider-text::before,
.divider-text::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-primary);
}