/* ============================================
   OnshoreHSE Components
   Cards, Badges, Buttons, Tables, Modals
   ============================================ */

/* --- Cards --- */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow-card);
    transition: all var(--transition-base);
    overflow: hidden;
}

.card:hover {
    box-shadow: var(--shadow-card-hover);
    border-color: var(--emerald-200);
}

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

.card-header h3 {
    font-size: var(--text-md);
    font-weight: var(--weight-semibold);
    color: var(--gray-800);
}

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

.card-footer {
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--gray-100);
    background: var(--gray-50);
}

/* Metric Card */
.metric-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--gray-200);
    padding: var(--space-5);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    transition: all var(--transition-base);
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-card);
}

.metric-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--emerald-400), var(--emerald-600));
    opacity: 0;
    transition: opacity var(--transition-base);
}

.metric-card:hover {
    box-shadow: var(--shadow-card-hover);
    border-color: var(--emerald-200);
    transform: translateY(-2px);
}

.metric-card:hover::before {
    opacity: 1;
}

.metric-card .metric-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.metric-card .metric-icon {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.metric-card .metric-icon.emerald {
    background: linear-gradient(135deg, var(--emerald-100), var(--emerald-50));
    color: var(--emerald-600);
}

.metric-card .metric-icon.blue {
    background: linear-gradient(135deg, #dbeafe, #eff6ff);
    color: #2563eb;
}

.metric-card .metric-icon.amber {
    background: linear-gradient(135deg, #fef3c7, #fffbeb);
    color: #d97706;
}

.metric-card .metric-icon.red {
    background: linear-gradient(135deg, #fee2e2, #fef2f2);
    color: #dc2626;
}

.metric-card .metric-icon.purple {
    background: linear-gradient(135deg, #ede9fe, #f5f3ff);
    color: #7c3aed;
}

.metric-card .metric-icon.teal {
    background: linear-gradient(135deg, #ccfbf1, #f0fdfa);
    color: #0d9488;
}

.metric-card .metric-trend {
    display: flex;
    align-items: center;
    gap: 3px;
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    padding: 2px 8px;
    border-radius: var(--radius-full);
}

.metric-card .metric-trend.up {
    color: var(--color-success);
    background: var(--color-success-light);
}

.metric-card .metric-trend.down {
    color: var(--color-danger);
    background: var(--color-danger-light);
}

.metric-card .metric-trend.neutral {
    color: var(--gray-500);
    background: var(--gray-100);
}

.metric-card .metric-value {
    font-size: var(--text-3xl);
    font-weight: var(--weight-extrabold);
    color: var(--gray-900);
    letter-spacing: -0.02em;
    line-height: 1;
}

.metric-card .metric-label {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    font-weight: var(--weight-medium);
}

/* Glass Card */
.glass-card {
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

/* --- Badges --- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 10px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: var(--weight-semibold);
    letter-spacing: 0.02em;
    white-space: nowrap;
    line-height: 1.6;
}

.badge-emerald { background: var(--emerald-100); color: var(--emerald-800); }
.badge-green { background: var(--color-success-light); color: #065f46; }
.badge-yellow { background: var(--color-warning-light); color: #92400e; }
.badge-red { background: var(--color-danger-light); color: #991b1b; }
.badge-blue { background: var(--color-info-light); color: #1e40af; }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }
.badge-purple { background: #ede9fe; color: #5b21b6; }
.badge-orange { background: #ffedd5; color: #9a3412; }
.badge-teal { background: #ccfbf1; color: #115e59; }

.badge-outline {
    background: transparent;
    border: 1px solid currentColor;
}

.badge-dot::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* Risk badges */
.badge-risk-low { background: var(--risk-low-bg); color: var(--risk-low); }
.badge-risk-medium { background: var(--risk-medium-bg); color: #b45309; }
.badge-risk-high { background: var(--risk-high-bg); color: var(--risk-high); }
.badge-risk-extreme { background: var(--risk-extreme-bg); color: var(--risk-extreme); }

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    line-height: 1.5;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all var(--transition-base);
    white-space: nowrap;
    user-select: none;
    position: relative;
    overflow: hidden;
}

.btn:active {
    transform: scale(0.98);
}

.btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* Primary Button */
.btn-primary {
    background: linear-gradient(135deg, var(--emerald-600), var(--emerald-700));
    color: #fff;
    box-shadow: 0 2px 4px rgba(4, 120, 87, 0.2);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--emerald-700), var(--emerald-800));
    box-shadow: var(--shadow-emerald);
    transform: translateY(-1px);
}

/* Secondary Button */
.btn-secondary {
    background: #fff;
    color: var(--gray-700);
    border-color: var(--gray-300);
}

.btn-secondary:hover {
    background: var(--gray-50);
    border-color: var(--gray-400);
}

/* Ghost Button */
.btn-ghost {
    background: transparent;
    color: var(--gray-600);
}

.btn-ghost:hover {
    background: var(--gray-100);
    color: var(--gray-800);
}

/* Danger Button */
.btn-danger {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    color: #fff;
}

.btn-danger:hover {
    background: linear-gradient(135deg, #b91c1c, #991b1b);
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3);
}

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

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

.btn-icon {
    padding: var(--space-2);
    width: 36px;
    height: 36px;
}

/* --- Tables --- */
.table-container {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--gray-200);
}

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

.data-table thead {
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
}

.data-table thead th {
    padding: var(--space-3) var(--space-4);
    text-align: left;
    font-weight: var(--weight-semibold);
    color: var(--gray-600);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

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

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

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

.data-table tbody td {
    padding: var(--space-3) var(--space-4);
    color: var(--text-primary);
    vertical-align: middle;
}

.data-table .td-id {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    color: var(--emerald-700);
}

/* --- Modals --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: var(--z-modal);
    display: none;
    align-items: center;
    justify-content: center;
    padding: var(--space-6);
    animation: fadeIn 0.2s ease;
}

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

.modal {
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-2xl);
    width: 100%;
    max-width: 640px;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}

.modal-lg { max-width: 820px; }
.modal-xl { max-width: 1024px; }

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

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

.modal-close {
    background: none;
    border: none;
    color: var(--gray-400);
    cursor: pointer;
    padding: var(--space-1);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    background: var(--gray-100);
    color: var(--gray-700);
}

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

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--gray-200);
    background: var(--gray-50);
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

/* --- Slide Panel --- */
.slide-panel {
    position: fixed;
    top: 0;
    right: -480px;
    width: 480px;
    height: 100vh;
    background: var(--bg-card);
    box-shadow: var(--shadow-2xl);
    z-index: var(--z-modal);
    transition: right var(--transition-slow);
    display: flex;
    flex-direction: column;
}

.slide-panel.open {
    right: 0;
}

.slide-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-5) var(--space-5);
    border-bottom: 1px solid var(--gray-200);
    flex-shrink: 0;
}

.slide-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-5);
}

/* --- Tabs --- */
.tabs {
    display: flex;
    gap: var(--space-1);
    border-bottom: 1px solid var(--gray-200);
    margin-bottom: var(--space-5);
}

.tab-btn {
    padding: var(--space-2) var(--space-4);
    border: none;
    background: none;
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all var(--transition-base);
    margin-bottom: -1px;
}

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

.tab-btn.active {
    color: var(--emerald-700);
    border-bottom-color: var(--emerald-600);
    font-weight: var(--weight-semibold);
}

/* --- Progress Bar --- */
.progress-bar {
    height: 6px;
    background: var(--gray-200);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress-bar .progress-fill {
    height: 100%;
    border-radius: var(--radius-full);
    background: linear-gradient(90deg, var(--emerald-500), var(--emerald-400));
    transition: width 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* --- Timeline --- */
.timeline {
    position: relative;
    padding-left: var(--space-8);
}

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

.timeline-item {
    position: relative;
    padding-bottom: var(--space-5);
}

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

.timeline-item .timeline-dot {
    position: absolute;
    left: calc(-1 * var(--space-8) + 4px);
    top: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--emerald-500);
    border: 3px solid var(--emerald-100);
    z-index: 1;
}

.timeline-item .timeline-dot.pending {
    background: var(--gray-300);
    border-color: var(--gray-100);
}

.timeline-item .timeline-content {
    font-size: var(--text-sm);
}

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

/* --- Divider --- */
.divider {
    height: 1px;
    background: var(--gray-200);
    margin: var(--space-5) 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 svg {
    width: 64px;
    height: 64px;
    color: var(--gray-300);
    margin-bottom: var(--space-4);
}

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

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

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

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-4px);
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    background: var(--gray-900);
    color: #fff;
    font-size: 11px;
    font-weight: var(--weight-medium);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: all var(--transition-fast);
    z-index: var(--z-tooltip);
}

[data-tooltip]:hover::after {
    opacity: 1;
    transform: translateX(-50%) translateY(-8px);
}

/* --- Filter bar --- */
.filter-bar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
}

.filter-bar .filter-group {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.filter-bar select {
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    border: 1px solid var(--gray-300);
    background: #fff;
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
    outline: none;
}

.filter-bar select:focus {
    border-color: var(--emerald-400);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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