* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #4F46E5;
    --primary-dark: #4338CA;
    --secondary: #10B981;
    --background: #F9FAFB;
    --surface: #FFFFFF;
    --text-primary: #111827;
    --text-secondary: #6B7280;
    --border: #E5E7EB;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
}

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

.container {
    max-width: 1400px;
    margin: 0 auto;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    background: var(--surface);
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
}

.logo {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-img {
    width: 180px;
    height: 180px;
    object-fit: contain;
    border-radius: 8px;
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: #F0FDF4;
    border-radius: 20px;
    font-size: 0.875rem;
    color: var(--secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    background: var(--secondary);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

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

/* Chat Wrapper */
.chat-wrapper {
    flex: 1;
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 0;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 2rem 1.5rem;
    overflow-y: auto;
}

.sidebar h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.quick-queries {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 2rem;
}

.query-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    font-size: 0.875rem;
    color: var(--text-primary);
}

.query-btn:hover {
    background: #EEF2FF;
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.query-btn svg {
    color: var(--primary);
    flex-shrink: 0;
}

.stats-preview {
    background: var(--background);
    padding: 1rem;
    border-radius: 8px;
    margin-top: 2rem;
}

.stats-preview h4 {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
}

.stat-item {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    font-size: 0.875rem;
}

.stat-item span:first-child {
    color: var(--text-secondary);
}

.stat-item span:last-child {
    color: var(--text-primary);
    font-weight: 500;
}

/* Chat Container */
.chat-container {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    height: 100%;
    overflow: hidden;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    max-height: calc(100vh - 300px);
    min-height: 400px;
}

.message {
    display: flex;
    gap: 1rem;
    animation: slideIn 0.3s ease-out;
}

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

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.bot-avatar {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
}

.user-avatar {
    background: linear-gradient(135deg, #F59E0B, #D97706);
    color: white;
}

.message-content {
    flex: 1;
    max-width: 70%;
}

.user-message {
    flex-direction: row-reverse;
}

.user-message .message-content {
    background: var(--primary);
    color: white;
    padding: 1rem 1.25rem;
    border-radius: 18px 18px 4px 18px;
}

.bot-message .message-content {
    background: var(--background);
    padding: 1rem 1.25rem;
    border-radius: 18px 18px 18px 4px;
    border: 1px solid var(--border);
}

.message-content p {
    margin-bottom: 0.5rem;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-text {
    margin-bottom: 0.75rem !important;
    line-height: 1.6;
}

.hint {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-style: italic;
}

.collection-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    background: #EEF2FF;
    color: var(--primary);
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    margin-top: 0.5rem;
}

.loading {
    display: flex;
    gap: 0.5rem;
    padding: 1rem;
}

.loading-dot {
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.loading-dot:nth-child(1) { animation-delay: -0.32s; }
.loading-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Input Area */
.input-area {
    padding: 1.5rem 2rem 2rem;
    background: var(--surface);
    border-top: 1px solid var(--border);
}

.input-wrapper {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

#userInput {
    flex: 1;
    padding: 1rem 1.5rem;
    border: 2px solid var(--border);
    border-radius: 24px;
    font-size: 1rem;
    outline: none;
    transition: all 0.2s;
}

#userInput:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.send-btn {
    width: 48px;
    height: 48px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    box-shadow: var(--shadow);
}

.send-btn:hover {
    background: var(--primary-dark);
    transform: scale(1.05);
    box-shadow: var(--shadow-lg);
}

.send-btn:active {
    transform: scale(0.95);
}

.send-btn:disabled {
    background: var(--border);
    cursor: not-allowed;
}

.suggestions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.suggestion-label {
    font-size: 0.813rem;
    color: var(--text-secondary);
}

.suggestion-chip {
    padding: 0.5rem 1rem;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 16px;
    font-size: 0.813rem;
    cursor: pointer;
    transition: all 0.2s;
}

.suggestion-chip:hover {
    background: #EEF2FF;
    border-color: var(--primary);
    color: var(--primary);
}

/* Scrollbar */
.messages::-webkit-scrollbar,
.sidebar::-webkit-scrollbar {
    width: 6px;
}

.messages::-webkit-scrollbar-track,
.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.messages::-webkit-scrollbar-thumb,
.sidebar::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.messages::-webkit-scrollbar-thumb:hover,
.sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Data Visualization */
.data-visualization {
    margin-top: 1rem;
}

/* Procedure Section */
.procedure-section {
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: #FFFFFF;
    border-radius: 16px;
    border: 2px solid #E5E7EB;
}

.procedure-section-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: #111827;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid #E5E7EB;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Metrics Grid */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin: 1rem 0;
}

.metrics-grid-secondary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.metric-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem;
    background: linear-gradient(135deg, #FFFFFF 0%, #F9FAFB 100%);
    border: 2px solid #E5E7EB;
    border-radius: 16px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.metric-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.1);
    border-color: var(--primary);
}

.metric-card.card-revenue {
    background: linear-gradient(135deg, #ECFDF5 0%, #D1FAE5 100%);
    border-color: #10B981;
}

.metric-card.card-expense {
    background: linear-gradient(135deg, #FEF2F2 0%, #FEE2E2 100%);
    border-color: #EF4444;
}

.metric-card.card-profit {
    background: linear-gradient(135deg, #EFF6FF 0%, #DBEAFE 100%);
    border-color: #3B82F6;
}

.metric-card.card-new {
    background: linear-gradient(135deg, #F0FDF4 0%, #DCFCE7 100%);
    border-color: #22C55E;
}

.metric-card.card-repeat {
    background: linear-gradient(135deg, #EEF2FF 0%, #E0E7FF 100%);
    border-color: #6366F1;
}

.metric-card.card-unique {
    background: linear-gradient(135deg, #FEF3C7 0%, #FDE68A 100%);
    border-color: #F59E0B;
}

.metric-icon {
    font-size: 2.5rem;
    line-height: 1;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.metric-details {
    flex: 1;
}

.metric-label {
    font-size: 0.813rem;
    color: #6B7280;
    margin-bottom: 0.375rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.metric-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: #111827;
    line-height: 1.2;
}

/* Date Range Badge */
.date-range-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    background: linear-gradient(135deg, #EFF6FF 0%, #DBEAFE 100%);
    border: 2px solid #3B82F6;
    border-radius: 24px;
    font-size: 0.875rem;
    color: #1E40AF;
    font-weight: 600;
    margin-top: 1rem;
}

.date-range-badge svg {
    flex-shrink: 0;
}

/* Inventory Grid */
.inventory-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
    margin: 1rem 0;
}

.inventory-card {
    padding: 1.5rem;
    background: white;
    border: 2px solid #E5E7EB;
    border-radius: 16px;
    transition: all 0.3s;
    position: relative;
    overflow: hidden;
}

.inventory-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: #10B981;
    transition: width 0.3s;
}

.inventory-card.status-critical::before {
    background: #EF4444;
}

.inventory-card.status-warning::before {
    background: #F59E0B;
}

.inventory-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.1);
}

.inventory-card:hover::before {
    width: 8px;
}

.inventory-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.inventory-name {
    font-weight: 700;
    font-size: 1rem;
    color: #111827;
}

.inventory-status-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    background: #F3F4F6;
    color: #6B7280;
}

.status-good .inventory-status-badge {
    background: #ECFDF5;
    color: #059669;
}

.status-warning .inventory-status-badge {
    background: #FFFBEB;
    color: #D97706;
}

.status-critical .inventory-status-badge {
    background: #FEF2F2;
    color: #DC2626;
}

.inventory-stock-level {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.stock-value {
    font-size: 2.5rem;
    font-weight: 800;
    color: #111827;
    line-height: 1;
}

.stock-unit {
    font-size: 1rem;
    color: #6B7280;
    font-weight: 500;
}

.inventory-details-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.detail-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.detail-label {
    font-size: 0.75rem;
    color: #9CA3AF;
    font-weight: 500;
}

.detail-value {
    font-size: 1rem;
    color: #111827;
    font-weight: 700;
}

.stock-progress-bar {
    width: 100%;
    height: 8px;
    background: #F3F4F6;
    border-radius: 4px;
    overflow: hidden;
}

.stock-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #10B981 0%, #059669 100%);
    border-radius: 4px;
    transition: width 0.5s ease;
}

.status-warning .stock-progress-fill {
    background: linear-gradient(90deg, #F59E0B 0%, #D97706 100%);
}

.status-critical .stock-progress-fill {
    background: linear-gradient(90deg, #EF4444 0%, #DC2626 100%);
}

/* Doctors Grid */
.doctors-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
    margin: 1rem 0;
}

.doctor-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem;
    background: linear-gradient(135deg, #FFFFFF 0%, #F9FAFB 100%);
    border: 2px solid #E5E7EB;
    border-radius: 16px;
    transition: all 0.3s;
}

.doctor-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.1);
    border-color: var(--primary);
}

.doctor-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
}

.doctor-info {
    flex: 1;
}

.doctor-name {
    font-weight: 700;
    font-size: 1rem;
    color: #111827;
    margin-bottom: 0.25rem;
}

.doctor-role {
    font-size: 0.875rem;
    color: var(--primary);
    font-weight: 500;
}

.doctor-badge {
    padding: 0.375rem 0.75rem;
    background: #ECFDF5;
    color: #059669;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

/* Procedures Grid */
.procedures-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem;
    margin: 1rem 0;
}

.procedure-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem;
    background: linear-gradient(135deg, #FFFFFF 0%, #F9FAFB 100%);
    border: 2px solid #E5E7EB;
    border-radius: 16px;
    transition: all 0.3s;
}

.procedure-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.1);
    border-color: var(--primary);
}

.procedure-icon {
    font-size: 2rem;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.procedure-info {
    flex: 1;
}

.procedure-name {
    font-weight: 600;
    font-size: 0.938rem;
    color: #111827;
    margin-bottom: 0.375rem;
}

.procedure-price {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--primary);
}

/* Procedure Stats Grid (for fallback ranking) */
.procedures-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
    margin: 1rem 0;
}

.procedure-stat-card {
    padding: 1.5rem;
    background: white;
    border: 2px solid #E5E7EB;
    border-radius: 16px;
    transition: all 0.3s;
    position: relative;
    overflow: hidden;
}

.procedure-stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: #6B7280;
}

.procedure-stat-card.rank-1::before {
    background: linear-gradient(180deg, #FFD700 0%, #FFA500 100%);
}

.procedure-stat-card.rank-2::before {
    background: linear-gradient(180deg, #C0C0C0 0%, #A8A8A8 100%);
}

.procedure-stat-card.rank-3::before {
    background: linear-gradient(180deg, #CD7F32 0%, #B87333 100%);
}

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

.procedure-rank-badge {
    display: inline-block;
    padding: 0.375rem 0.875rem;
    background: #F3F4F6;
    border-radius: 12px;
    font-size: 0.813rem;
    font-weight: 700;
    color: #6B7280;
    margin-bottom: 1rem;
}

.rank-1 .procedure-rank-badge {
    background: linear-gradient(135deg, #FEF3C7 0%, #FDE68A 100%);
    color: #92400E;
}

.rank-2 .procedure-rank-badge {
    background: linear-gradient(135deg, #F3F4F6 0%, #E5E7EB 100%);
    color: #374151;
}

.rank-3 .procedure-rank-badge {
    background: linear-gradient(135deg, #FED7AA 0%, #FDBA74 100%);
    color: #7C2D12;
}

.procedure-stat-name {
    font-size: 1.125rem;
    font-weight: 700;
    color: #111827;
    margin-bottom: 1rem;
}

.procedure-stat-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.stat-box {
    padding: 0.875rem;
    border-radius: 0.5rem;
    background: #F9FAFB;
    transition: all 0.2s ease;
    text-align: center;
}

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

.stat-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #6B7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 1.25rem;
    font-weight: 800;
    color: #111827;
}

/* Responsive Design */
@media (max-width: 768px) {
    .chat-wrapper {
        grid-template-columns: 1fr;
    }
    
    .sidebar {
        display: none;
    }
    
    .metrics-grid {
        grid-template-columns: 1fr 1fr;
    }
    
    .inventory-grid,
    .doctors-grid,
    .procedures-grid,
    .procedures-stats-grid {
        grid-template-columns: 1fr;
    }
}

/* Add these at the end of your CSS file */

/* 2x2 Grid Layout for Procedure Stats */
.procedure-stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-top: 1rem;
}

/* Color-coded stat boxes */
.stat-box {
    padding: 1rem;
    border-radius: 0.5rem;
    background: #F9FAFB;
    transition: all 0.2s ease;
}

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

.stat-box-revenue {
    background: linear-gradient(135deg, #ECFDF5 0%, #D1FAE5 100%);
    border-left: 3px solid #10B981;
}

.stat-box-cost {
    background: linear-gradient(135deg, #FEF2F2 0%, #FEE2E2 100%);
    border-left: 3px solid #EF4444;
}

.stat-box-profit {
    background: linear-gradient(135deg, #EFF6FF 0%, #DBEAFE 100%);
    border-left: 3px solid #3B82F6;
}

.stat-box-revenue .stat-value {
    color: #059669;
    font-weight: 700;
}

.stat-box-cost .stat-value {
    color: #DC2626;
    font-weight: 700;
}

.stat-box-profit .stat-value {
    color: #2563EB;
    font-weight: 700;
}

.stat-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #6B7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #111827;
}