/* ═══════════════════════════════════════════════════════════════
   HRIS SaaS Enterprise — Component Library
   Buttons, Cards, Tables, Badges, Modals, Tabs, Inputs
   ═══════════════════════════════════════════════════════════════ */

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 8px 16px;
    font-family: var(--font-family);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    line-height: 1.4;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    user-select: none;
}

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

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

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    box-shadow: var(--shadow-sm);
}

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

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-surface-hover);
    border-color: var(--slate-300);
}

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

.btn-ghost:hover:not(:disabled) {
    background: var(--bg-surface-secondary);
    color: var(--text-primary);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
    background: var(--danger-600);
}

.btn-success {
    background: var(--success);
    color: #fff;
}

.btn-success:hover:not(:disabled) {
    background: var(--success-600);
}

.btn-sm {
    padding: 5px 12px;
    font-size: var(--text-xs);
}

.btn-lg {
    padding: 10px 20px;
    font-size: var(--text-base);
}

.btn-icon {
    padding: 8px;
    width: 36px;
    height: 36px;
}

.btn-icon.btn-sm {
    width: 30px;
    height: 30px;
    padding: 5px;
}

/* ── Cards ───────────────────────────────────────────────── */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xs);
    transition: box-shadow var(--transition-base);
}

.card-hover:hover {
    box-shadow: var(--shadow-md);
}

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

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

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

/* Stat Card */
.stat-card {
    padding: var(--space-5) var(--space-6);
}

.stat-card .stat-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    margin-bottom: var(--space-3);
}

.stat-card .stat-value {
    font-size: var(--text-3xl);
    font-weight: var(--font-bold);
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.stat-card .stat-label {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    margin-top: 2px;
}

.stat-card .stat-change {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
    margin-top: var(--space-2);
    padding: 2px 8px;
    border-radius: var(--radius-full);
}

.stat-card .stat-change.up {
    color: var(--success-700);
    background: var(--success-50);
}

.stat-card .stat-change.down {
    color: var(--danger-700);
    background: var(--danger-50);
}

/* ── Badges ──────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 10px;
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
    border-radius: var(--radius-full);
    line-height: 1.6;
    white-space: nowrap;
}

.badge-primary {
    background: var(--primary-50);
    color: var(--primary-700);
}

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

.badge-danger {
    background: var(--danger-50);
    color: var(--danger-700);
}

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

.badge-neutral {
    background: var(--slate-100);
    color: var(--slate-600);
}

.badge-purple {
    background: var(--purple-50);
    color: var(--purple-600);
}

/* Dot indicator */
.badge .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* ── Avatar ──────────────────────────────────────────────── */
.avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: var(--primary-100);
    color: var(--primary-700);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    flex-shrink: 0;
    overflow: hidden;
}

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

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

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

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

.avatar-group {
    display: flex;
}

.avatar-group .avatar {
    border: 2px solid var(--bg-surface);
    margin-left: -8px;
}

.avatar-group .avatar:first-child {
    margin-left: 0;
}

/* ── Tables ──────────────────────────────────────────────── */
.table-container {
    overflow-x: auto;
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-lg);
    background: var(--bg-surface);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
}

.data-table th {
    padding: 10px 16px;
    text-align: left;
    font-weight: var(--font-medium);
    color: var(--text-secondary);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--bg-surface-hover);
    border-bottom: 1px solid var(--border-primary);
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 1;
}

.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-secondary);
    color: var(--text-primary);
    vertical-align: middle;
}

.data-table tbody tr {
    transition: background var(--transition-fast);
}

.data-table tbody tr:hover {
    background: var(--bg-surface-hover);
}

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

/* Checkbox in table */
.data-table .checkbox-cell {
    width: 44px;
    padding-left: 16px;
}

/* ── Inputs ──────────────────────────────────────────────── */
.input-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.checkbox-wrapper {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    cursor: pointer;
    font-size: var(--text-sm);
}

textarea.input {
    resize: vertical;
    min-height: 60px;
}

.input-group label {
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--text-primary);
}

.input {
    padding: 8px 12px;
    font-family: var(--font-family);
    font-size: var(--text-sm);
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    outline: none;
    width: 100%;
}

.input:hover {
    border-color: var(--slate-300);
}

.input:focus {
    border-color: var(--border-focus);
    box-shadow: var(--shadow-focus);
}

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

.input-with-icon {
    position: relative;
}

.input-with-icon .input {
    padding-left: 36px;
}

.input-with-icon .input-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
    font-size: 16px;
    pointer-events: none;
}

.select {
    appearance: none;
    padding: 8px 32px 8px 12px;
    font-family: var(--font-family);
    font-size: var(--text-sm);
    color: var(--text-primary);
    background: var(--bg-input) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' 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/svg%3E") no-repeat right 12px center;
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    cursor: pointer;
    outline: none;
    transition: all var(--transition-fast);
}

.select:hover {
    border-color: var(--slate-300);
}

.select:focus {
    border-color: var(--border-focus);
    box-shadow: var(--shadow-focus);
}

/* Checkbox */
.checkbox-wrapper {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    cursor: pointer;
}

.checkbox {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
    cursor: pointer;
}

/* ── Tabs ────────────────────────────────────────────────── */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border-primary);
}

.tab {
    padding: 10px 16px;
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--text-secondary);
    background: none;
    border: none;
    cursor: pointer;
    position: relative;
    transition: color var(--transition-fast);
    white-space: nowrap;
    font-family: var(--font-family);
}

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

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

.tab.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--primary);
    border-radius: 1px 1px 0 0;
}

.tab .tab-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    font-size: 11px;
    font-weight: var(--font-semibold);
    background: var(--slate-100);
    color: var(--text-secondary);
    border-radius: var(--radius-full);
    margin-left: 6px;
}

.tab.active .tab-count {
    background: var(--primary-50);
    color: var(--primary-600);
}

/* ── Modal ───────────────────────────────────────────────── */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: var(--bg-modal-overlay);
    z-index: var(--z-modal-backdrop);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-6);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-base);
}

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

.modal {
    background: var(--bg-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    max-width: 560px;
    width: 100%;
    max-height: 85vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: scale(0.95) translateY(10px);
    transition: transform var(--transition-base);
}

.modal-backdrop.active .modal {
    transform: scale(1) translateY(0);
}

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

.modal-header h3 {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
}

.modal-body {
    padding: var(--space-6);
    overflow-y: auto;
    flex: 1;
}

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

/* Drawer (right side panel) */
.drawer-backdrop {
    position: fixed;
    inset: 0;
    background: var(--bg-modal-overlay);
    z-index: var(--z-modal-backdrop);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-base);
}

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

.drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 520px;
    max-width: 90vw;
    background: var(--bg-surface);
    box-shadow: var(--shadow-xl);
    z-index: var(--z-modal);
    transform: translateX(100%);
    transition: transform var(--transition-slow);
    display: flex;
    flex-direction: column;
}

.drawer-backdrop.active .drawer {
    transform: translateX(0);
}

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

.drawer-body {
    padding: var(--space-6);
    flex: 1;
    overflow-y: auto;
}

/* ── Pagination ──────────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--border-secondary);
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.pagination-buttons {
    display: flex;
    gap: var(--space-1);
}

.page-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    font-size: var(--text-sm);
    font-family: var(--font-family);
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.page-btn:hover {
    background: var(--bg-surface-secondary);
    color: var(--text-primary);
}

.page-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* ── Dropdown ────────────────────────────────────────────── */
.dropdown {
    position: relative;
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    min-width: 200px;
    background: var(--bg-surface);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: var(--z-dropdown);
    padding: var(--space-1);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: all var(--transition-fast);
}

.dropdown-menu.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 8px 12px;
    font-size: var(--text-sm);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition-fast);
    border: none;
    background: none;
    width: 100%;
    font-family: var(--font-family);
    text-align: left;
}

.dropdown-item:hover {
    background: var(--bg-surface-secondary);
}

.dropdown-divider {
    height: 1px;
    background: var(--border-secondary);
    margin: var(--space-1) 0;
}

/* ── Breadcrumb ──────────────────────────────────────────── */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
    color: var(--text-tertiary);
}

.breadcrumb a {
    color: var(--text-secondary);
}

.breadcrumb a:hover {
    color: var(--primary);
}

.breadcrumb-sep {
    font-size: 10px;
}

/* ── Loading Skeleton ────────────────────────────────────── */
.skeleton {
    background: linear-gradient(90deg, var(--slate-100) 25%, var(--slate-200) 50%, var(--slate-100) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-md);
}

[data-theme="dark"] .skeleton {
    background: linear-gradient(90deg, var(--slate-800) 25%, var(--slate-700) 50%, var(--slate-800) 75%);
    background-size: 200% 100%;
}

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

    100% {
        background-position: -200% 0;
    }
}

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

.empty-state .empty-icon {
    width: 80px;
    height: 80px;
    background: var(--slate-100);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    margin-bottom: var(--space-4);
    color: var(--text-tertiary);
}

.empty-state h3 {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

.empty-state p {
    color: var(--text-secondary);
    font-size: var(--text-sm);
    max-width: 360px;
}

/* ── Toast / Notification ────────────────────────────────── */
.toast-container {
    position: fixed;
    top: var(--space-4);
    right: var(--space-4);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-4);
    background: var(--bg-surface);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    min-width: 320px;
    max-width: 420px;
    animation: toast-slide-in 0.3s ease-out;
}

@keyframes toast-slide-in {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ── Tooltip ─────────────────────────────────────────────── */
[data-tooltip] {
    position: relative;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 10px;
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
    color: #fff;
    background: var(--slate-800);
    border-radius: var(--radius-sm);
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-fast);
    pointer-events: none;
}

[data-tooltip]:hover::after {
    opacity: 1;
    visibility: visible;
}

/* ── Progress Bar ────────────────────────────────────────── */
.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--slate-100);
    border-radius: var(--radius-full);
    overflow: hidden;
}

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

/* ── Timeline ────────────────────────────────────────────── */
.timeline {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.timeline-item {
    display: flex;
    gap: var(--space-4);
    padding-bottom: var(--space-6);
    position: relative;
}

.timeline-item:last-child {
    padding-bottom: 0;
}

.timeline-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    margin-top: 6px;
    flex-shrink: 0;
    position: relative;
}

.timeline-item:not(:last-child) .timeline-dot::after {
    content: '';
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    width: 1px;
    height: calc(100% + var(--space-6) - 4px);
    background: var(--border-primary);
}

.timeline-content {
    flex: 1;
}

.timeline-content .timeline-title {
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--text-primary);
}

.timeline-content .timeline-time {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    margin-top: 2px;
}

.timeline-content .timeline-desc {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    margin-top: var(--space-1);
}

/* ── Utility ─────────────────────────────────────────────── */
.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.justify-end {
    justify-content: flex-end;
}

.gap-1 {
    gap: var(--space-1);
}

.gap-2 {
    gap: var(--space-2);
}

.gap-3 {
    gap: var(--space-3);
}

.gap-4 {
    gap: var(--space-4);
}

.gap-6 {
    gap: var(--space-6);
}

.flex-1 {
    flex: 1;
}

.flex-wrap {
    flex-wrap: wrap;
}

.grid {
    display: grid;
}

.grid-2 {
    grid-template-columns: repeat(2, 1fr);
}

.grid-3 {
    grid-template-columns: repeat(3, 1fr);
}

.grid-4 {
    grid-template-columns: repeat(4, 1fr);
}

.w-full {
    width: 100%;
}

.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}

.hidden {
    display: none !important;
}

.relative {
    position: relative;
}

/* ── Modal Animations (used by MPP approval modal etc.) ── */
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(16px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0)    scale(1);    }
}

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

.modal-fade {
    animation: fadeIn 0.15s ease;
}

.modal-slide-up {
    animation: slideUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}