/* === Reset & Base === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #1a73e8;
    --primary-dark: #1557b0;
    --red: #e74c3c;
    --red-dark: #c0392b;
    --green: #27ae60;
    --green-dark: #219a52;
    --blue: #2980b9;
    --purple: #8e44ad;
    --orange: #f39c12;
    --bg: #f0f4f8;
    --card-bg: #ffffff;
    --text: #1a1a2e;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --radius: 12px;
    --radius-sm: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* === Header === */
.header {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 64px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    font-size: 32px;
}

.logo h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.subtitle {
    font-size: 12px;
    opacity: 0.85;
    display: block;
}

.header-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #aaa;
    display: inline-block;
}

.status-dot.status-ok {
    background: #2ecc71;
    box-shadow: 0 0 6px rgba(46, 204, 113, 0.6);
}

.status-dot.status-error {
    background: var(--red);
    box-shadow: 0 0 6px rgba(231, 76, 60, 0.6);
}

.separator {
    opacity: 0.4;
}

/* === Container === */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

/* === Stats Grid === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow);
    border-left: 4px solid transparent;
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}

.stat-blue { border-left-color: var(--blue); }
.stat-red { border-left-color: var(--red); }
.stat-green { border-left-color: var(--green); }
.stat-purple { border-left-color: var(--purple); }
.stat-orange { border-left-color: var(--orange); }

.stat-icon {
    font-size: 28px;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    border-radius: var(--radius-sm);
}

.stat-body {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 28px;
    font-weight: 800;
    line-height: 1.2;
}

.stat-label {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
}

/* === Grid 2 Col === */
.grid-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

@media (max-width: 768px) {
    .grid-2col {
        grid-template-columns: 1fr;
    }
}

/* === Card === */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 16px;
    overflow: hidden;
}

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

.card-header h2 {
    font-size: 16px;
    font-weight: 700;
}

.card-body {
    padding: 16px 20px;
}

/* === Badge === */
.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    padding: 0 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 700;
    color: white;
}

.badge-red { background: var(--red); }
.badge-blue { background: var(--blue); }
.badge-green { background: var(--green); }
.badge-purple { background: var(--purple); }
.badge-orange { background: var(--orange); }

/* === Obat Item === */
.obat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.obat-item:last-child {
    border-bottom: none;
}

.obat-info {
    display: flex;
    flex-direction: column;
}

.obat-info strong {
    font-size: 14px;
}

.obat-detail {
    font-size: 12px;
    color: var(--text-muted);
}

.obat-status {
    display: flex;
    align-items: baseline;
    gap: 4px;
    padding: 4px 12px;
    border-radius: 20px;
    font-weight: 700;
    font-size: 14px;
}

.obat-status.stok-habis {
    background: #fde8e8;
    color: var(--red-dark);
}

.obat-status.stok-sangat-kritis {
    background: #fef3cd;
    color: #856404;
}

.obat-status.stok-kritis {
    background: #fff3e0;
    color: #e65100;
}

.obat-satuan {
    font-size: 12px;
    font-weight: 400;
    opacity: 0.7;
}

/* === Rekap Item === */
.rekap-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.rekap-item:last-child {
    border-bottom: none;
}

.rekap-date {
    font-size: 13px;
    font-weight: 600;
}

.rekap-stats {
    display: flex;
    gap: 12px;
    align-items: center;
}

.rekap-pasien {
    font-weight: 700;
    color: var(--primary);
    font-size: 14px;
}

.rekap-diag {
    font-size: 12px;
    color: var(--text-muted);
    max-width: 180px;
    text-align: right;
}

/* === Dokter Item === */
.dokter-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.dokter-item:last-child {
    border-bottom: none;
}

.dokter-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--purple));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
}

.dokter-info {
    display: flex;
    flex-direction: column;
}

.dokter-info strong {
    font-size: 14px;
}

.dokter-spesialisasi {
    font-size: 12px;
    color: var(--primary);
    font-weight: 600;
}

.dokter-jadwal {
    font-size: 12px;
    color: var(--text-muted);
}

/* === Alert Item === */
.alert-item {
    display: flex;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    align-items: flex-start;
}

.alert-item:last-child {
    border-bottom: none;
}

.alert-icon {
    font-size: 24px;
    flex-shrink: 0;
}

.alert-body strong {
    font-size: 14px;
}

.alert-body p {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}

.alert-body small {
    font-size: 11px;
    color: var(--text-muted);
    opacity: 0.7;
}

.stok-bahaya {
    color: var(--red);
    font-weight: 700;
}

/* === Automation Info === */
.automation-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

@media (max-width: 768px) {
    .automation-grid {
        grid-template-columns: 1fr;
    }
}

.auto-card {
    display: flex;
    gap: 16px;
    padding: 16px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.auto-icon {
    font-size: 32px;
    flex-shrink: 0;
}

.auto-info h3 {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 4px;
}

.auto-info p {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.auto-desc {
    margin-top: 4px !important;
    font-style: italic;
    opacity: 0.8;
}

.auto-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    background: var(--primary);
    color: white;
    margin-top: 6px;
}

/* === Loading & Empty === */
.loading, .empty {
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

/* === Footer === */
.footer {
    text-align: center;
    padding: 24px;
    color: var(--text-muted);
    font-size: 13px;
    border-top: 1px solid var(--border);
    margin-top: 8px;
}

/* === WebSocket Status === */
.ws-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 4px;
}
.ws-dot.connected {
    background: #2ecc71;
    box-shadow: 0 0 6px rgba(46, 204, 113, 0.6);
}
.ws-dot.disconnected {
    background: #e74c3c;
    box-shadow: 0 0 6px rgba(231, 76, 60, 0.6);
}
.ws-dot.connecting {
    background: #f39c12;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* === Chart Container === */
.chart-wrapper {
    position: relative;
    width: 100%;
    min-height: 280px;
}

.chart-wrapper canvas {
    width: 100% !important;
    height: 100% !important;
}

/* === Timeline / Activity Feed === */
.timeline {
    max-height: 400px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.timeline::-webkit-scrollbar {
    width: 6px;
}
.timeline::-webkit-scrollbar-track {
    background: transparent;
}
.timeline::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.timeline-item {
    display: flex;
    gap: 14px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    animation: slideIn 0.3s ease-out;
    align-items: flex-start;
}

.timeline-item:last-child {
    border-bottom: none;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.timeline-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.timeline-icon.success {
    background: #e8f5e9;
    color: #2e7d32;
}

.timeline-icon.failed {
    background: #fde8e8;
    color: #c62828;
}

.timeline-icon.running {
    background: #fff3e0;
    color: #e65100;
    animation: pulse 1s infinite;
}

.timeline-body {
    flex: 1;
    min-width: 0;
}

.timeline-title {
    font-size: 14px;
    font-weight: 600;
}

.timeline-body p {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.timeline-time {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
    opacity: 0.7;
    margin-top: 3px;
}

/* === Status Badge (Automation) === */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
}

.status-badge.success {
    background: #e8f5e9;
    color: #2e7d32;
}

.status-badge.failed {
    background: #fde8e8;
    color: #c62828;
}

.status-badge.running {
    background: #fff3e0;
    color: #e65100;
}

/* === Automation Detail Card === */
.auto-detail-card {
    padding: 16px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.auto-detail-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.auto-detail-header h3 {
    font-size: 14px;
    font-weight: 700;
}

.auto-detail-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.auto-detail-stat {
    display: flex;
    flex-direction: column;
}

.auto-detail-stat .label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
}

.auto-detail-stat .value {
    font-size: 13px;
    font-weight: 600;
}

/* === Chart Row === */
.chart-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

@media (max-width: 900px) {
    .chart-grid {
        grid-template-columns: 1fr;
    }
}

/* === Obat Mini Status === */
.obat-mini {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.obat-mini:last-child {
    border-bottom: none;
}

.obat-mini .stok-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
}

.obat-mini .stok-indicator.habis { background: #c62828; }
.obat-mini .stok-indicator.kritis { background: #e65100; }
.obat-mini .stok-indicator.waspada { background: #f9a825; }

/* === Pulse for running state === */
@keyframes running-pulse {
    0% { box-shadow: 0 0 0 0 rgba(230, 81, 0, 0.4); }
    70% { box-shadow: 0 0 0 8px rgba(230, 81, 0, 0); }
    100% { box-shadow: 0 0 0 0 rgba(230, 81, 0, 0); }
}

.running-pulse {
    animation: running-pulse 1.5s infinite;
}

/* === Last Update === */
.last-update {
    font-size: 12px;
    color: var(--text-muted);
    opacity: 0.8;
}
