/* ============================================
   E-ERP B2B Portal — Components CSS
   Button, Card, Table, Form, Modal, Toast, Badge
   ============================================ */

/* === BUTTONS === */
.btn {
    padding: 9px 18px;
    border: none;
    border-radius: var(--border-radius);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-normal);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-decoration: none;
    line-height: 1.4;
    white-space: nowrap;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); box-shadow: 0 4px 12px rgba(14,165,233,0.3); }
.btn-secondary { background: var(--gray-200); color: var(--gray-700); }
.btn-secondary:hover:not(:disabled) { background: var(--gray-300); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover:not(:disabled) { opacity: 0.9; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover:not(:disabled) { opacity: 0.9; }
.btn-warning { background: var(--warning); color: var(--dark); }
.btn-warning:hover:not(:disabled) { opacity: 0.9; }
.btn-info { background: var(--info); color: white; }
.btn-info:hover:not(:disabled) { opacity: 0.9; }

.btn-outline {
    background: transparent;
    border: 1.5px solid var(--gray-300);
    color: var(--gray-700);
}
.btn-outline:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); background: var(--primary-50); }

.btn-ghost { background: transparent; color: var(--gray-600); }
.btn-ghost:hover:not(:disabled) { background: var(--gray-100); color: var(--dark); }

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-icon { width: 36px; height: 36px; padding: 0; }
.btn-block { width: 100%; }

/* === CARDS === */
.card {
    background: var(--white);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--card-shadow);
    overflow: hidden;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h3 {
    font-size: 15px;
    font-weight: 700;
    color: var(--dark);
}

.card-body {
    padding: 20px;
}

.card-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--gray-200);
    background: var(--gray-50);
}

/* Stat Card */
.stat-card {
    background: var(--white);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--card-shadow);
    padding: 20px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    transition: transform var(--transition-normal), box-shadow var(--transition-normal);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.stat-card .stat-icon.blue { background: var(--primary-light); color: var(--primary); }
.stat-card .stat-icon.green { background: var(--success-light); color: var(--success); }
.stat-card .stat-icon.orange { background: var(--warning-light); color: var(--warning); }
.stat-card .stat-icon.red { background: var(--danger-light); color: var(--danger); }
.stat-card .stat-icon.purple { background: var(--purple-light); color: var(--purple); }

.stat-card .stat-info { flex: 1; min-width: 0; }
.stat-card .stat-label { font-size: 12px; color: var(--gray-500); font-weight: 500; margin-bottom: 4px; }
.stat-card .stat-value { font-size: 22px; font-weight: 700; color: var(--dark); line-height: 1.2; }
.stat-card .stat-sub { font-size: 11px; color: var(--gray-400); margin-top: 4px; }

/* === TABLES === */
.table-container {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table thead th {
    background: var(--gray-50);
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    color: var(--gray-600);
    border-bottom: 2px solid var(--gray-200);
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    user-select: none;
}

.data-table thead th.sortable {
    cursor: pointer;
}

.data-table thead th.sortable:hover {
    color: var(--primary);
}

.data-table thead th .sort-icon {
    margin-left: 4px;
    opacity: 0.3;
}

.data-table thead th.sort-asc .sort-icon,
.data-table thead th.sort-desc .sort-icon {
    opacity: 1;
    color: var(--primary);
}

.data-table tbody tr {
    border-bottom: 1px solid var(--gray-100);
    transition: background var(--transition-fast);
}

.data-table tbody tr:hover {
    background: var(--gray-50);
}

.data-table tbody tr.active {
    background: var(--primary-light);
}

.data-table tbody td {
    padding: 10px 12px;
    color: var(--gray-700);
    vertical-align: middle;
}

.data-table tbody td.number {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.data-table tbody td.center {
    text-align: center;
}

.data-table .clickable-row {
    cursor: pointer;
}

/* === FORMS === */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.form-control {
    width: 100%;
    padding: 9px 12px;
    border: 1.5px solid var(--gray-300);
    border-radius: var(--border-radius);
    font-size: 13px;
    font-family: inherit;
    color: var(--gray-700);
    background: var(--white);
    transition: all var(--transition-normal);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-control:disabled {
    background: var(--gray-100);
    color: var(--gray-500);
    cursor: not-allowed;
}

.form-control::placeholder {
    color: var(--gray-400);
}

select.form-control {
    appearance: none;
    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='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

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

.form-row {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
}

.form-row .form-group {
    flex: 1;
    margin-bottom: 0;
}

.input-group {
    display: flex;
    align-items: stretch;
}

.input-group .form-control {
    border-radius: var(--border-radius) 0 0 var(--border-radius);
}

.input-group .input-group-btn {
    border-radius: 0 var(--border-radius) var(--border-radius) 0;
    border-left: none;
}

.form-error {
    font-size: 11px;
    color: var(--danger);
    margin-top: 4px;
}

.form-hint {
    font-size: 11px;
    color: var(--gray-400);
    margin-top: 4px;
}

/* === BADGES === */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-primary { background: var(--primary-light); color: var(--primary-dark); }
.badge-success { background: var(--success-light); color: var(--success-dark); }
.badge-warning { background: var(--warning-light); color: var(--warning-dark); }
.badge-danger { background: var(--danger-light); color: var(--danger-dark); }
.badge-info { background: var(--info-light); color: var(--info-dark); }
.badge-purple { background: var(--purple-light); color: var(--purple-dark); }
.badge-secondary { background: var(--gray-200); color: var(--gray-600); }

/* === MODAL === */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: var(--z-modal-backdrop);
    align-items: center;
    justify-content: center;
}

.modal-overlay.show { display: flex; }

.modal-dialog {
    background: var(--white);
    border-radius: var(--border-radius-xl);
    box-shadow: var(--shadow-xl);
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 { font-size: 16px; font-weight: 700; }

.modal-close {
    width: 32px; height: 32px;
    border: none;
    background: var(--gray-100);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--gray-500);
    transition: all var(--transition-fast);
    font-size: 16px;
}
.modal-close:hover { background: var(--gray-200); color: var(--dark); }

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--gray-200);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    background: var(--gray-50);
}

/* === TOAST === */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--border-radius);
    color: white;
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s ease;
    min-width: 260px;
    max-width: 400px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.toast i { font-size: 16px; flex-shrink: 0; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); color: var(--dark); }
.toast.info { background: var(--info); }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(100px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(100px); }
}

/* === CONFIRM DIALOG === */
.confirm-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 10000;
    align-items: center;
    justify-content: center;
}
.confirm-overlay.show { display: flex; }

.confirm-dialog {
    background: white;
    border-radius: var(--border-radius-xl);
    padding: 28px;
    width: 400px;
    max-width: 90vw;
    box-shadow: var(--shadow-xl);
    text-align: center;
}

.confirm-icon { font-size: 48px; margin-bottom: 12px; }
.confirm-icon.warning { color: var(--warning); }
.confirm-icon.danger { color: var(--danger); }
.confirm-icon.info { color: var(--primary); }
.confirm-title { font-size: 18px; font-weight: 700; color: var(--gray-700); margin-bottom: 8px; }
.confirm-message { font-size: 14px; color: var(--gray-500); margin-bottom: 24px; line-height: 1.5; }
.confirm-buttons { display: flex; gap: 10px; justify-content: center; }
.confirm-buttons .btn { min-width: 110px; }

/* === LOADING OVERLAY === */
.loading-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255,255,255,0.7);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 16px;
}

.loading-overlay.show { display: flex; }

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

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

.loading-text {
    color: var(--gray-600);
    font-size: 14px;
    font-weight: 500;
}

/* === EMPTY STATE === */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    color: var(--gray-400);
    text-align: center;
}

.empty-state i {
    font-size: 56px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state h4 {
    font-size: 16px;
    color: var(--gray-500);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 13px;
    color: var(--gray-400);
    max-width: 300px;
}

/* === PAGINATION === */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    font-size: 13px;
}

.pagination-info {
    color: var(--gray-500);
}

.pagination-buttons {
    display: flex;
    gap: 4px;
}

.pagination-btn {
    width: 34px;
    height: 34px;
    border: 1px solid var(--gray-200);
    background: var(--white);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--gray-600);
    transition: all var(--transition-fast);
    font-size: 13px;
}

.pagination-btn:hover:not(:disabled) {
    border-color: var(--primary);
    color: var(--primary);
}

.pagination-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

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

/* === TABS === */
.tab-list {
    display: flex;
    gap: 4px;
    border-bottom: 2px solid var(--gray-200);
    margin-bottom: 16px;
}

.tab-item {
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-500);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all var(--transition-fast);
}

.tab-item:hover { color: var(--primary); }
.tab-item.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* === FILTER BAR === */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    margin-bottom: 16px;
}

.filter-chip {
    padding: 6px 14px;
    border: 1.5px solid var(--gray-200);
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    color: var(--gray-600);
    cursor: pointer;
    transition: all var(--transition-fast);
    background: var(--white);
}

.filter-chip:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.filter-chip.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* === SEARCH INPUT === */
.search-input-wrapper {
    position: relative;
    flex: 1;
    max-width: 360px;
}

.search-input-wrapper i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-400);
    font-size: 14px;
}

.search-input-wrapper .form-control {
    padding-left: 36px;
}

/* === PROGRESS BAR === */
.progress-bar {
    height: 8px;
    background: var(--gray-200);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar .progress-fill {
    height: 100%;
    border-radius: 4px;
    transition: width var(--transition-slow);
}

.progress-fill.blue { background: var(--primary); }
.progress-fill.green { background: var(--success); }
.progress-fill.orange { background: var(--warning); }
.progress-fill.red { background: var(--danger); }

/* === AVATAR === */
.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    color: white;
    flex-shrink: 0;
}

.avatar-sm { width: 32px; height: 32px; font-size: 12px; }
.avatar-lg { width: 56px; height: 56px; font-size: 20px; }

/* === TIMELINE === */
.timeline {
    position: relative;
    padding-left: 24px;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 8px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--gray-200);
}

.timeline-item {
    position: relative;
    padding-bottom: 20px;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -20px;
    top: 4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--gray-300);
    border: 2px solid var(--white);
}

.timeline-item.active::before { background: var(--primary); }
.timeline-item.completed::before { background: var(--success); }

.timeline-item .timeline-date {
    font-size: 11px;
    color: var(--gray-400);
    margin-bottom: 4px;
}

.timeline-item .timeline-text {
    font-size: 13px;
    color: var(--gray-700);
}

/* === TOOLTIP === */
[data-tooltip] {
    position: relative;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 6px 10px;
    background: var(--dark);
    color: white;
    font-size: 11px;
    border-radius: 6px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-fast);
    margin-bottom: 6px;
}

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