* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #3B82F6;
    --primary-dark: #2563EB;
    --secondary-color: #6B7280;
    --success-color: #10B981;
    --danger-color: #EF4444;
    --warning-color: #F59E0B;
    --bg-color: #F9FAFB;
    --sidebar-bg: #1F2937;
    --sidebar-hover: #374151;
    --text-primary: #111827;
    --text-secondary: #6B7280;
    --border-color: #E5E7EB;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
}

/* Screen Management */
.screen {
    display: none;
}

.screen.active {
    display: flex;
}

/* Login Screen */
#loginScreen {
    min-height: 100vh;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 20px;
}

.login-box {
    background: white;
    padding: 40px;
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
}

.login-box h1 {
    font-size: 28px;
    margin-bottom: 10px;
    text-align: center;
}

.subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 30px;
}

.default-credentials {
    text-align: center;
    margin-top: 20px;
    padding: 10px;
    background: var(--bg-color);
    border-radius: 5px;
}

/* Dashboard Layout */
#dashboardScreen {
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    color: white;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header h2 {
    font-size: 20px;
}

.sidebar-subtitle {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.6);
    margin-top: 5px;
}

.sidebar-nav {
    flex: 1;
    padding: 20px 0;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    transition: all 0.2s;
}

.nav-item:hover {
    background: var(--sidebar-hover);
    color: white;
}

.nav-item.active {
    background: var(--primary-color);
    color: white;
}

.nav-item .icon {
    margin-right: 12px;
    font-size: 20px;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.user-info {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 10px;
}

.user-details {
    flex: 1;
}

.user-name {
    font-weight: 600;
    font-size: 14px;
}

.user-role {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.6);
}

/* Main Content */
.main-content {
    margin-left: 260px;
    padding: 30px;
    min-height: 100vh;
}

.page {
    display: none;
}

.page.active {
    display: block;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

.page-header h1 {
    font-size: 28px;
}

.filters {
    display: flex;
    gap: 10px;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
}

.stat-icon {
    font-size: 40px;
    margin-right: 15px;
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--primary-color);
}

.stat-label {
    color: var(--text-secondary);
    font-size: 14px;
}

.stat-meta {
    color: var(--success-color);
    font-size: 12px;
    font-weight: 500;
    margin-top: 4px;
}

/* Page Section */
.page-section {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.page-section h2 {
    margin-bottom: 15px;
}

/* Tables */
.table-container {
    background: white;
    border-radius: 10px;
    box-shadow: var(--shadow);
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background: var(--bg-color);
}

th {
    text-align: left;
    padding: 15px;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 12px;
    text-transform: uppercase;
}

td {
    padding: 15px;
    border-top: 1px solid var(--border-color);
}

tr:hover {
    background: var(--bg-color);
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-block;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background: #4B5563;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
    padding: 8px 16px;
    font-size: 12px;
}

.btn-success {
    background: var(--success-color);
    color: white;
    padding: 8px 16px;
    font-size: 12px;
}

.btn-block {
    width: 100%;
    display: block;
}

.btn-small {
    padding: 5px 10px;
    font-size: 12px;
}

/* Form Elements */
.form-group {
    margin-bottom: 20px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    font-size: 14px;
}

input, select, textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-control {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
}

.badge-success {
    background: #D1FAE5;
    color: #065F46;
}

.badge-danger {
    background: #FEE2E2;
    color: #991B1B;
}

.badge-warning {
    background: #FEF3C7;
    color: #92400E;
}

.badge-info {
    background: #DBEAFE;
    color: #1E40AF;
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 10px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 20px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal form {
    padding: 20px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* Messages */
.error-message {
    color: var(--danger-color);
    font-size: 14px;
    margin-top: 10px;
}

.loading {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
}

.message {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
}

/* Responsive */
@media (max-width: 768px) {
    /* Sidebar - Hidden by default on mobile */
    .sidebar {
        position: fixed;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 1000;
        height: 100vh;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    /* Main content takes full width on mobile */
    .main-content {
        margin-left: 0;
        padding: 15px;
    }

    /* Page header - stack elements */
    .page-header {
        flex-direction: column;
        gap: 15px;
        align-items: stretch !important;
    }

    .page-header h1 {
        font-size: 24px;
    }

    .page-header .btn {
        width: 100%;
    }

    /* Stats grid - single column */
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    /* Form rows - single column */
    .form-row {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    /* Tables - horizontal scroll */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -15px;
        padding: 0 15px;
    }

    table {
        min-width: 600px;
        font-size: 13px;
    }

    table th,
    table td {
        padding: 10px 8px;
        white-space: nowrap;
    }

    /* Buttons - stack vertically */
    table .btn {
        display: block;
        width: 100%;
        margin: 4px 0;
        font-size: 12px;
        padding: 6px 10px;
    }

    /* Action buttons in table cells */
    table td:last-child {
        min-width: 120px;
    }

    /* Modals - full screen on mobile */
    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        height: 100vh;
        max-height: 100vh;
        margin: 0;
        border-radius: 0;
    }

    .modal-body {
        max-height: calc(100vh - 140px);
        overflow-y: auto;
    }

    /* Agent Details Modal */
    #agentDetailsModal .modal-content {
        padding: 15px;
    }

    #agentDetailsModal h3,
    #agentDetailsModal h4 {
        font-size: 18px;
    }

    /* Conversation cards */
    #conversationsContent > div {
        gap: 12px;
    }

    #conversationsContent > div > div {
        padding: 12px;
        font-size: 13px;
    }

    /* Conversation grid - single column on mobile */
    #conversationsContent > div > div > div[style*="grid"] {
        grid-template-columns: 1fr !important;
        gap: 8px !important;
    }

    /* Conversation transcript */
    #conversationsContent  div[style*="transcript"] div {
        max-height: 120px !important;
        font-size: 12px !important;
    }

    /* Sync log table */
    #syncLogContent table {
        font-size: 11px;
    }

    #syncLogContent th,
    #syncLogContent td {
        padding: 6px 4px;
    }

    /* Badges */
    .badge {
        font-size: 11px;
        padding: 3px 8px;
    }

    /* Code blocks */
    code {
        font-size: 11px;
        word-break: break-all;
    }

    /* Forms */
    .form-group label {
        font-size: 13px;
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 14px;
    }

    /* Login container */
    .login-container {
        padding: 20px;
        margin: 15px;
    }

    /* Hide text in navigation on very small screens */
    @media (max-width: 480px) {
        .sidebar {
            width: 70px;
        }

        .nav-item span:not(.icon) {
            display: none;
        }

        .logo-text {
            display: none;
        }
    }
}

/* Tablet adjustments */
@media (min-width: 769px) and (max-width: 1024px) {
    .sidebar {
        width: 200px;
    }

    .main-content {
        margin-left: 200px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    table {
        font-size: 14px;
    }

    .modal-content {
        width: 90% !important;
        max-width: 90% !important;
    }
}
