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

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary: #7c3aed;
    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;
    --info: #0284c7;
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --bg-card: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: rgba(15, 23, 42, 0.08);
    --sidebar-width: 260px;
    --logs-width: 380px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
}

.dashboard-container {
    display: flex;
    min-height: 100vh;
}

/* ============= SIDEBAR ============= */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    z-index: 100;
    box-shadow: 2px 0 10px var(--shadow);
}

.logo {
    padding: 2rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(135deg, #f8fafc 0%, #ffffff 100%);
}

.logo h1 {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo p {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-weight: 500;
}

nav {
    padding: 1rem 0;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 0.875rem 1.5rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s;
    border-left: 3px solid transparent;
    font-weight: 500;
}

.nav-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.nav-item.active {
    background: rgba(37, 99, 235, 0.08);
    color: var(--primary);
    border-left-color: var(--primary);
}

.nav-item .icon {
    margin-right: 0.75rem;
    font-size: 1.25rem;
}

.sidebar-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border);
    background: var(--bg-tertiary);
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: pulse 2s infinite;
}

.status-indicator.connected {
    background: var(--success);
}

.timestamp {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.4;
}

/* ============= MAIN CONTENT ============= */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    margin-right: var(--logs-width);
    padding: 2rem;
    max-width: calc(100vw - var(--sidebar-width) - var(--logs-width));
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 2px solid var(--border);
}

.header h2 {
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.header p {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.btn-refresh {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.2);
}

.btn-refresh:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.section {
    display: none;
}

.section.active {
    display: block;
    animation: fadeIn 0.3s ease-in;
}

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

/* ============= STATS CARDS ============= */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    border: 1px solid var(--border);
    transition: all 0.2s;
    box-shadow: 0 1px 3px var(--shadow);
}

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

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

.stat-icon.phone {
    background: linear-gradient(135deg, #dbeafe, #bfdbfe);
    color: var(--info);
}

.stat-icon.success {
    background: linear-gradient(135deg, #d1fae5, #a7f3d0);
    color: var(--success);
}

.stat-icon.warning {
    background: linear-gradient(135deg, #fed7aa, #fbbf24);
    color: var(--warning);
}

.stat-icon.danger {
    background: linear-gradient(135deg, #fecaca, #fca5a5);
    color: var(--danger);
}

.stat-content {
    flex: 1;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
    margin-bottom: 0.25rem;
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.stat-trend {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    display: inline-block;
}

.stat-trend.positive {
    background: rgba(5, 150, 105, 0.1);
    color: var(--success);
}

.stat-trend.negative {
    background: rgba(220, 38, 38, 0.1);
    color: var(--danger);
}

.stat-trend.neutral {
    background: rgba(100, 116, 139, 0.1);
    color: var(--text-muted);
}

/* ============= CHARTS ============= */
.charts-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.chart-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1.5rem;
    border: 1px solid var(--border);
    box-shadow: 0 1px 3px var(--shadow);
}

.chart-card h3 {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 1.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid var(--bg-tertiary);
}

/* ============= ACTIVITY FEED ============= */
.activity-section {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1.5rem;
    border: 1px solid var(--border);
    box-shadow: 0 1px 3px var(--shadow);
}

.activity-section h3 {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.activity-feed {
    max-height: 400px;
    overflow-y: auto;
}

.activity-item {
    padding: 1rem;
    border-radius: 8px;
    background: var(--bg-tertiary);
    margin-bottom: 0.75rem;
    border-left: 3px solid var(--primary);
}

.activity-item:last-child {
    margin-bottom: 0;
}

.activity-time {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
}

.activity-message {
    color: var(--text-primary);
    margin-top: 0.25rem;
    font-weight: 500;
}

.activity-empty {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* ============= APPOINTMENTS ============= */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.section-header h3 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.search-input {
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.875rem;
    width: 300px;
    transition: all 0.2s;
    background: var(--bg-card);
    color: var(--text-primary);
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.appointments-grid {
    display: grid;
    gap: 1rem;
}

.appointment-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1.5rem;
    border: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s;
    box-shadow: 0 1px 3px var(--shadow);
}

.appointment-card:hover {
    transform: translateX(4px);
    box-shadow: 0 4px 12px var(--shadow);
}

.appointment-info h4 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.appointment-info p {
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
}

.appointment-badge {
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary);
}

/* ============= SCHEDULE FORM ============= */
.schedule-form-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 2rem;
    border: 1px solid var(--border);
    box-shadow: 0 1px 3px var(--shadow);
}

.schedule-form-card h3 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--bg-tertiary);
}

.schedule-form {
    display: grid;
    gap: 1.5rem;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
}

.form-group label {
    display: block;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.875rem;
    transition: all 0.2s;
    background: var(--bg-card);
    color: var(--text-primary);
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.btn-primary {
    padding: 1rem 2rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 1rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.2);
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.schedule-result {
    margin-top: 1.5rem;
    padding: 1rem;
    border-radius: 8px;
    font-weight: 500;
}

.schedule-result.success {
    background: rgba(5, 150, 105, 0.1);
    color: var(--success);
    border: 1px solid var(--success);
}

.schedule-result.error {
    background: rgba(220, 38, 38, 0.1);
    color: var(--danger);
    border: 1px solid var(--danger);
}

/* ============= DOCTORS GRID ============= */
.doctors-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

.doctor-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1.5rem;
    border: 1px solid var(--border);
    text-align: center;
    transition: all 0.2s;
    box-shadow: 0 1px 3px var(--shadow);
}

.doctor-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 16px var(--shadow);
}

.doctor-avatar {
    font-size: 3.5rem;
    margin-bottom: 1rem;
}

.doctor-card h4 {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.doctor-specialty {
    color: var(--primary);
    font-weight: 600;
    font-size: 0.875rem;
    margin-bottom: 0.75rem;
}

.doctor-info {
    color: var(--text-secondary);
    font-size: 0.875rem;
    line-height: 1.6;
}

/* ============= LOGS PANEL ============= */
.logs-panel {
    position: fixed;
    right: 0;
    top: 0;
    height: 100vh;
    width: var(--logs-width);
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    box-shadow: -2px 0 10px var(--shadow);
}

.logs-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-tertiary);
}

.logs-header h3 {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-primary);
}

.btn-icon {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: color 0.2s;
    padding: 0.25rem;
}

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

.logs-filters {
    display: flex;
    gap: 0.5rem;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    background: var(--bg-card);
}

.filter-btn {
    padding: 0.5rem 0.875rem;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 600;
    transition: all 0.2s;
}

.filter-btn:hover {
    background: var(--bg-tertiary);
}

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

.logs-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.log-entry {
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    border-radius: 6px;
    font-size: 0.8125rem;
    font-family: 'Monaco', 'Courier New', monospace;
    border-left: 3px solid;
    background: var(--bg-tertiary);
}

.log-entry.call {
    border-left-color: var(--info);
}

.log-entry.speech {
    border-left-color: var(--success);
}

.log-entry.function {
    border-left-color: var(--secondary);
}

.log-entry.error {
    border-left-color: var(--danger);
    background: rgba(220, 38, 38, 0.05);
}

.log-time {
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
}

.log-message {
    color: var(--text-primary);
    margin-top: 0.25rem;
    word-break: break-word;
}

.log-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
    font-weight: 500;
}

.logs-toggle {
    display: none;
}

/* ============= LOADING & EMPTY STATES ============= */
.loading {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* ============= ANIMATIONS ============= */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ============= RESPONSIVE ============= */
@media (max-width: 1024px) {
    :root {
        --logs-width: 320px;
        --sidebar-width: 220px;
    }
}

@media (max-width: 768px) {
    .main-content {
        margin-left: 0;
        margin-right: 0;
        max-width: 100vw;
        padding: 1rem;
    }

    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .logs-panel {
        transform: translateX(100%);
        transition: transform 0.3s;
    }

    .logs-panel.open {
        transform: translateX(0);
    }

    .logs-toggle {
        display: flex;
        position: fixed;
        bottom: 1rem;
        right: 1rem;
        padding: 1rem;
        background: var(--primary);
        color: white;
        border: none;
        border-radius: 50%;
        cursor: pointer;
        box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
        z-index: 99;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .charts-row {
        grid-template-columns: 1fr;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .doctors-grid {
        grid-template-columns: 1fr;
    }

    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .section-header {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .search-input {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .logo {
        padding: 1.5rem 1rem;
    }

    .logo h1 {
        font-size: 1.25rem;
    }

    .header h2 {
        font-size: 1.5rem;
    }

    .stat-card {
        flex-direction: column;
        text-align: center;
    }

    .stat-icon {
        width: 56px;
        height: 56px;
        font-size: 1.75rem;
    }
}
