/* ==============================================
   COMPONENT STYLES — Reusable UI Components
   ============================================== */

/* ── Cards ── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    box-shadow: var(--shadow-card);
    transition: transform var(--transition-base), box-shadow var(--transition-base), border-color var(--transition-base);
}
.card:hover {
    border-color: var(--border-color-hover);
}
.card.interactive:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    border-color: var(--accent-primary);
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-lg);
    padding-bottom: var(--space-md);
    border-bottom: 1px solid var(--border-color);
}
.card-title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
}
.card-subtitle {
    font-size: var(--text-sm);
    color: var(--text-muted);
    margin-top: var(--space-xs);
}

/* ── Stat Cards ── */
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    display: flex;
    align-items: flex-start;
    gap: var(--space-md);
    transition: all var(--transition-base);
}
.stat-card:hover {
    border-color: var(--border-color-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}
.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}
.stat-icon.primary { background: var(--accent-primary-bg); color: var(--accent-primary-light); }
.stat-icon.secondary { background: var(--accent-secondary-bg); color: var(--accent-secondary); }
.stat-icon.tertiary { background: var(--accent-tertiary-bg); color: var(--accent-tertiary); }
.stat-icon.success { background: var(--success-bg); color: var(--success); }
.stat-icon.info { background: var(--info-bg); color: var(--info); }
.stat-icon.danger { background: var(--danger-bg); color: var(--danger); }
.stat-info { flex: 1; min-width: 0; }
.stat-label {
    font-size: var(--text-sm);
    color: var(--text-muted);
    margin-bottom: var(--space-xs);
}
.stat-value {
    font-size: var(--text-2xl);
    font-weight: var(--font-bold);
    color: var(--text-primary);
    line-height: 1.2;
}
.stat-change {
    font-size: var(--text-xs);
    margin-top: var(--space-xs);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: var(--radius-full);
}
.stat-change.up { background: var(--success-bg); color: var(--success); }
.stat-change.down { background: var(--danger-bg); color: var(--danger); }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: 10px 20px;
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    font-family: inherit;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
    white-space: nowrap;
    line-height: 1.4;
    position: relative;
    overflow: hidden;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
}
.btn-primary:hover {
    background: var(--accent-primary-dark);
    box-shadow: var(--shadow-glow);
}

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

.btn-success { background: var(--success); color: white; }
.btn-success:hover { filter: brightness(1.1); }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { filter: brightness(1.1); }

.btn-warning { background: var(--warning); color: var(--text-inverse); }
.btn-warning:hover { filter: brightness(1.1); }

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

.btn-outline {
    background: transparent;
    color: var(--accent-primary-light);
    border-color: var(--accent-primary);
}
.btn-outline:hover {
    background: var(--accent-primary-bg);
}

.btn-sm { padding: 6px 14px; font-size: var(--text-xs); }
.btn-lg { padding: 14px 28px; font-size: var(--text-base); }
.btn-icon { padding: 10px; width: 40px; height: 40px; }
.btn-icon.sm { padding: 6px; width: 32px; height: 32px; }

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

/* Button ripple */
.btn .ripple {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: scale(0);
    animation: ripple-effect 0.6s ease-out;
    pointer-events: none;
}
@keyframes ripple-effect {
    to { transform: scale(4); opacity: 0; }
}

/* ── Form Inputs ── */
.form-group {
    margin-bottom: var(--space-lg);
}
.form-label {
    display: block;
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
}
.form-input,
.form-select {
    width: 100%;
    padding: 10px 14px;
    font-size: var(--text-sm);
    font-family: inherit;
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    outline: none;
}
.form-input:focus,
.form-select:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-primary-bg);
}
.form-input::placeholder { color: var(--text-muted); }
.form-input.error { border-color: var(--danger); }
.form-input.success { border-color: var(--success); }

.input-group {
    position: relative;
    display: flex;
    align-items: center;
}
.input-group .input-icon {
    position: absolute;
    color: var(--text-muted);
    font-size: var(--text-base);
    transition: color var(--transition-fast);
    pointer-events: none;
    z-index: 1;
}
[dir="ltr"] .input-group .input-icon { left: 14px; }
[dir="rtl"] .input-group .input-icon { right: 14px; }
[dir="ltr"] .input-group .form-input { padding-left: 42px; }
[dir="rtl"] .input-group .form-input { padding-right: 42px; }

.input-group:focus-within .input-icon {
    color: var(--accent-primary);
}

.input-action {
    position: absolute;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    transition: color var(--transition-fast);
}
[dir="ltr"] .input-action { right: 8px; }
[dir="rtl"] .input-action { left: 8px; }
.input-action:hover { color: var(--text-primary); }

textarea.form-input {
    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='12' height='12' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-size: 12px;
}
[dir="ltr"] .form-select { background-position: right 14px center; padding-right: 38px; }
[dir="rtl"] .form-select { background-position: left 14px center; padding-left: 38px; }

/* ── Checkbox ── */
.form-check {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    cursor: pointer;
}
.form-check input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent-primary);
    cursor: pointer;
}
.form-check label {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    cursor: pointer;
}

/* ── Tables ── */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
}
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
}
.data-table th {
    padding: 12px 16px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-weight: var(--font-semibold);
    text-align: start;
    white-space: nowrap;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 1;
}
.data-table td {
    padding: 12px 16px;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}
.data-table tbody tr {
    transition: background var(--transition-fast);
}
.data-table tbody tr:hover {
    background: var(--sidebar-hover);
}
.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* ── Badges ── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    border-radius: var(--radius-full);
    white-space: nowrap;
}
.badge-primary { background: var(--accent-primary-bg); color: var(--accent-primary-light); }
.badge-secondary { background: var(--accent-secondary-bg); color: var(--accent-secondary); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }

/* ── Tabs ── */
.tabs {
    display: flex;
    gap: var(--space-xs);
    background: var(--bg-tertiary);
    padding: 4px;
    border-radius: var(--radius-md);
    margin-bottom: var(--space-lg);
    overflow-x: auto;
}
.tab-btn {
    padding: 10px 20px;
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    font-family: inherit;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}
.tab-btn:hover { color: var(--text-primary); background: var(--sidebar-hover); }
.tab-btn.active {
    color: var(--text-primary);
    background: var(--bg-card);
    box-shadow: var(--shadow-sm);
}
.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn 0.3s ease; }

/* ── Alerts ── */
.alert {
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    display: flex;
    align-items: center;
    gap: var(--space-md);
    margin-bottom: var(--space-md);
    border: 1px solid;
    animation: fadeInUp 0.3s ease both;
}
.alert-success { background: var(--success-bg); color: var(--success); border-color: rgba(34, 197, 94, 0.2); }
.alert-danger { background: var(--danger-bg); color: var(--danger); border-color: rgba(239, 68, 68, 0.2); }
.alert-warning { background: var(--warning-bg); color: var(--warning); border-color: rgba(245, 158, 11, 0.2); }
.alert-info { background: var(--info-bg); color: var(--info); border-color: rgba(59, 130, 246, 0.2); }
.alert i { font-size: var(--text-lg); }
.alert-close {
    margin-inline-start: auto;
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    opacity: 0.7;
    font-size: var(--text-lg);
}
.alert-close:hover { opacity: 1; }

/* ── Modal ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    padding: var(--space-lg);
    backdrop-filter: blur(4px);
}
.modal-overlay.active {
    display: flex;
    animation: fadeIn 0.2s ease;
}
.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    animation: scaleIn 0.3s ease;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-lg);
    border-bottom: 1px solid var(--border-color);
}
.modal-header h3 {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
}
.modal-body {
    padding: var(--space-lg);
}
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--border-color);
}

/* ── Loading Spinner ── */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    display: inline-block;
}
.spinner-lg { width: 40px; height: 40px; border-width: 3px; }

/* ── Empty State ── */
.empty-state {
    text-align: center;
    padding: var(--space-2xl);
    color: var(--text-muted);
}
.empty-state i {
    font-size: 3rem;
    margin-bottom: var(--space-md);
    opacity: 0.5;
}
.empty-state p {
    font-size: var(--text-base);
    color: var(--text-muted);
}

/* ── Tooltip ── */
[data-tooltip] {
    position: relative;
}
[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%) scale(0.9);
    padding: 6px 12px;
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: all var(--transition-fast);
    z-index: var(--z-dropdown);
}
[data-tooltip]:hover::after {
    opacity: 1;
    transform: translateX(-50%) scale(1);
}

/* ── Filter Bar ── */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-md);
    padding: var(--space-lg);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-lg);
    align-items: flex-end;
}
.filter-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    flex: 1;
    min-width: 160px;
}
.filter-group label {
    font-size: var(--text-xs);
    color: var(--text-muted);
    font-weight: var(--font-medium);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.filter-actions {
    display: flex;
    gap: var(--space-sm);
    align-items: center;
}

/* ── Stats Grid ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

/* ── Chart Container ── */
.chart-container {
    position: relative;
    padding: var(--space-md);
    height: 300px;
}
.chart-container canvas {
    max-height: 100%;
}

/* ── Grid Layouts ── */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-lg);
}
.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-lg);
}

@media (max-width: 992px) {
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .filter-bar { flex-direction: column; }
    .filter-group { min-width: 100%; }
    .tabs { flex-wrap: nowrap; overflow-x: auto; }
}
@media (max-width: 576px) {
    .stats-grid { grid-template-columns: 1fr; }
    .modal { margin: var(--space-md); }
}
