/* ============================================
   CBT Master - Reusable Components
   ============================================ */

/* ========== Container ========== */
.container {
    width: 100%;
    max-width: var(--container-xl);
    margin: 0 auto;
    padding: 0 var(--space-4);
}

.container-sm {
    max-width: var(--container-sm);
}

.container-md {
    max-width: var(--container-md);
}

.container-lg {
    max-width: var(--container-lg);
}

.container-xl {
    max-width: var(--container-xl);
}

/* ========== Cards ========== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-xl);
    padding: var(--space-6);
    backdrop-filter: blur(10px);
    transition: all var(--transition-base);
}

.card:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-light);
    transform: translateY(-2px);
    box-shadow: var(--shadow-card);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--border-primary);
}

.card-title {
    font-size: var(--text-xl);
    font-weight: var(--font-semibold);
    margin: 0;
}

.card-body {
    flex: 1;
}

.card-footer {
    margin-top: var(--space-4);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border-primary);
}

/* Glass Card Variant */
.card-glass {
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* ========== 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-sm);
    font-weight: var(--font-medium);
    line-height: 1;
    text-decoration: none;
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn:hover {
    transform: translateY(-1px);
    text-decoration: none;
}

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

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Button Sizes */
.btn-sm {
    padding: var(--space-2) var(--space-4);
    font-size: var(--text-xs);
}

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

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

/* Button Variants */
.btn-primary {
    background: var(--gradient-primary);
    color: var(--text-primary);
    box-shadow: 0 4px 15px var(--primary-glow);
}

.btn-primary:hover {
    box-shadow: 0 6px 20px var(--primary-glow);
}

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

.btn-secondary:hover {
    background: var(--bg-card-hover);
    border-color: var(--primary);
}

.btn-outline {
    background: transparent;
    color: var(--primary-light);
    border: 2px solid var(--primary);
}

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

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

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

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

.btn-success:hover {
    background: #16a34a;
}

.btn-danger {
    background: var(--error);
    color: var(--text-primary);
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-warning {
    background: var(--warning);
    color: var(--bg-primary);
}

.btn-warning:hover {
    background: var(--accent-dark);
}

/* Icon Button */
.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: var(--radius-lg);
}

.btn-icon-sm {
    width: 32px;
    height: 32px;
}

.btn-icon-lg {
    width: 48px;
    height: 48px;
}

/* Button Group */
.btn-group {
    display: inline-flex;
    gap: var(--space-2);
}

/* ========== 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);
    margin-left: var(--space-1);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    font-family: var(--font-primary);
    font-size: var(--text-base);
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    transition: all var(--transition-fast);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
    outline: none;
}

.form-input::placeholder {
    color: var(--text-dark);
}

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

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

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-3) center;
    background-size: 18px;
    padding-right: var(--space-10);
    cursor: pointer;
}

.form-select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.form-hint {
    margin-top: var(--space-2);
    font-size: var(--text-sm);
    color: var(--text-muted);
}

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

/* Checkbox & Radio */
.form-check {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    cursor: pointer;
}

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

.form-check-label {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    cursor: pointer;
}

/* File Input */
.form-file {
    position: relative;
}

.form-file-input {
    position: absolute;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.form-file-label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    padding: var(--space-8);
    background: var(--bg-tertiary);
    border: 2px dashed var(--border-primary);
    border-radius: var(--radius-xl);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.form-file-label:hover {
    border-color: var(--primary);
    background: var(--bg-card);
}

/* ========== Badges ========== */
.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-medium);
    border-radius: var(--radius-full);
}

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

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

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

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

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

/* ========== Alerts ========== */
.alert {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-4);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-4);
}

.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);
}

.alert-message {
    font-size: var(--text-sm);
    margin: 0;
}

.alert-success {
    background: var(--success-bg);
    border: 1px solid var(--success);
    color: var(--success);
}

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

.alert-error {
    background: var(--error-bg);
    border: 1px solid var(--error);
    color: var(--error);
}

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

/* ========== Progress Bar ========== */
.progress {
    width: 100%;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
    overflow: hidden;
}

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

.progress-success .progress-bar {
    background: var(--success);
}

.progress-warning .progress-bar {
    background: var(--warning);
}

.progress-error .progress-bar {
    background: var(--error);
}

/* ========== Avatar ========== */
.avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    object-fit: cover;
    background: var(--bg-tertiary);
}

.avatar-sm {
    width: 32px;
    height: 32px;
}

.avatar-lg {
    width: 56px;
    height: 56px;
}

.avatar-xl {
    width: 80px;
    height: 80px;
}

.avatar-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gradient-primary);
    color: var(--text-primary);
    font-weight: var(--font-bold);
}

/* ========== Tables ========== */
.table-container {
    width: 100%;
    overflow-x: auto;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-primary);
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: var(--space-4);
    text-align: left;
    border-bottom: 1px solid var(--border-primary);
}

.table th {
    background: var(--bg-secondary);
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.table td {
    background: var(--bg-card);
    color: var(--text-secondary);
}

.table tr:last-child td {
    border-bottom: none;
}

.table tr:hover td {
    background: var(--bg-tertiary);
}

/* ========== Tabs ========== */
.tabs {
    display: flex;
    gap: var(--space-1);
    background: var(--bg-secondary);
    padding: var(--space-1);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-6);
}

.tab {
    flex: 1;
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.tab:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.tab.active {
    color: var(--text-primary);
    background: var(--primary);
}

/* ========== Modal ========== */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: var(--z-modal-backdrop);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-base);
}

.modal-backdrop.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.95);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-xl);
    z-index: var(--z-modal);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-base);
    overflow: hidden;
}

.modal.active {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
}

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

.modal-title {
    font-size: var(--text-xl);
    font-weight: var(--font-semibold);
    margin: 0;
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: var(--text-xl);
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

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

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

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--border-primary);
}

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

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

/* ========== Toast ========== */
.toast-container {
    position: fixed;
    top: var(--space-6);
    right: var(--space-6);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    animation: slideInRight var(--transition-base) ease forwards;
}

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

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

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

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

.toast-icon {
    font-size: var(--text-xl);
}

.toast-content {
    flex: 1;
}

.toast-title {
    font-weight: var(--font-semibold);
    font-size: var(--text-sm);
}

.toast-message {
    font-size: var(--text-sm);
    color: var(--text-muted);
}

.toast-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: var(--space-1);
}

/* ========== Tooltip ========== */
.tooltip {
    position: relative;
}

.tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: var(--space-2) var(--space-3);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: var(--text-xs);
    white-space: nowrap;
    border-radius: var(--radius-md);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-fast);
    margin-bottom: var(--space-2);
    z-index: var(--z-tooltip);
}

.tooltip:hover::after {
    opacity: 1;
    visibility: visible;
}

/* ========== Loader ========== */
.loader {
    width: 40px;
    height: 40px;
    border: 3px solid var(--bg-tertiary);
    border-top-color: var(--primary);
    border-radius: var(--radius-full);
    animation: spin 1s linear infinite;
}

.loader-sm {
    width: 24px;
    height: 24px;
    border-width: 2px;
}

.loader-lg {
    width: 56px;
    height: 56px;
    border-width: 4px;
}

/* Full Page Loader */
.page-loader {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    z-index: var(--z-modal);
}

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

.empty-state-icon {
    font-size: 4rem;
    color: var(--text-dark);
    margin-bottom: var(--space-4);
}

.empty-state-title {
    font-size: var(--text-xl);
    font-weight: var(--font-semibold);
    margin-bottom: var(--space-2);
}

.empty-state-message {
    color: var(--text-muted);
    margin-bottom: var(--space-6);
}

/* ========== Skeleton Loader ========== */
.skeleton {
    background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-card) 50%, var(--bg-tertiary) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-md);
}

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

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

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

/* ========== Divider ========== */
.divider {
    width: 100%;
    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);
}