* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #14b8a6;
    --primary-dark: #0d9488;
    --bg-dark: #1a1a1a;
    --bg-darker: #0f0f0f;
    --bg-card: #252525;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --border-color: #333333;
    --hover-bg: #2a2a2a;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-darker);
    color: var(--text-primary);
    min-height: 100vh;
}

/* Login Page */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    background: var(--bg-darker);
}

.login-box {
    background: var(--bg-card);
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    width: 100%;
    max-width: 400px;
    border: 1px solid var(--border-color);
}

.login-box h1 {
    text-align: center;
    color: var(--primary-color);
    margin-bottom: 30px;
    font-size: 28px;
    font-weight: 600;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-primary);
    font-weight: 500;
    font-size: 14px;
}

.form-group label[for] {
    color: var(--text-primary);
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    background: var(--bg-dark);
    color: var(--text-primary);
    transition: all 0.3s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.1);
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    width: 100%;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(20, 184, 166, 0.3);
}

.btn-danger {
    background: #ef4444;
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-success {
    background: #10b981;
    color: white;
}

.btn-success:hover {
    background: #059669;
}

.btn-small {
    padding: 8px 16px;
    font-size: 14px;
    width: auto;
}

.error-message {
    color: #ef4444;
    margin-top: 10px;
    text-align: center;
    display: none;
    font-size: 14px;
}

.error-message.show {
    display: block;
}

/* App Container */
.app-container {
    display: flex;
    min-height: 100vh;
    background: var(--bg-darker);
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--bg-dark);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    z-index: 1000;
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-logo {
    width: 40px;
    height: 40px;
    background: var(--primary-color);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 20px;
}

.sidebar-header h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

.sidebar-menu {
    list-style: none;
    padding: 20px 0;
    flex: 1;
    overflow-y: auto;
}

.sidebar-menu li {
    margin-bottom: 4px;
}

.sidebar-menu a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s;
    font-size: 15px;
    border-left: 3px solid transparent;
}

.sidebar-menu a:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

.sidebar-menu a.active {
    background: var(--hover-bg);
    color: var(--primary-color);
    border-left-color: var(--primary-color);
}

.sidebar-menu-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 260px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.header {
    background: var(--bg-dark);
    border-bottom: 1px solid var(--border-color);
    padding: 20px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header h1 {
    color: var(--text-primary);
    font-size: 24px;
    font-weight: 600;
}

.header .btn {
    width: auto;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 20px;
}

.search-bar {
    display: flex;
    align-items: center;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 16px;
    width: 300px;
    gap: 10px;
}

.search-bar input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
}

.search-bar input::placeholder {
    color: var(--text-secondary);
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 12px;
}

.notification-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    color: var(--text-secondary);
    font-size: 18px;
}

.notification-icon:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    cursor: pointer;
}

/* Content Area */
.content-area {
    padding: 30px;
    flex: 1;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--bg-card);
    padding: 24px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 20px;
    transition: transform 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    border-color: var(--primary-color);
}

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    background: rgba(20, 184, 166, 0.1);
}

.stat-info h3 {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 8px;
    font-weight: 500;
}

.stat-value {
    font-size: 32px;
    font-weight: bold;
    color: var(--text-primary);
}

/* Table */
.table-container {
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.devices-table {
    width: 100%;
    border-collapse: collapse;
}

.devices-table thead {
    background: var(--bg-dark);
}

.devices-table th {
    padding: 16px;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 14px;
    border-bottom: 1px solid var(--border-color);
}

.devices-table td {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 14px;
}

.devices-table tbody tr:hover {
    background: var(--hover-bg);
}

.devices-table tbody tr:last-child td {
    border-bottom: none;
}

.status-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.status-connected {
    background: rgba(16, 185, 129, 0.2);
    color: #10b981;
}

.status-disconnected {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.status-initializing {
    background: rgba(251, 191, 36, 0.2);
    color: #fbbf24;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.action-buttons {
    display: flex;
    gap: 8px;
}

/* Device Selector */
.device-selector {
    background: var(--bg-card);
    padding: 20px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    margin-bottom: 20px;
}

.device-selector label {
    display: block;
    margin-bottom: 10px;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 14px;
}

.form-select {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    background: var(--bg-dark);
    color: var(--text-primary);
    cursor: pointer;
    transition: border-color 0.3s;
}

.form-select:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Chats Container */
.chats-container {
    display: flex;
    gap: 20px;
    height: calc(100vh - 200px);
    min-height: 500px;
}

.chats-list-panel {
    flex: 0 0 350px;
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chats-list-panel h2 {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 18px;
    margin: 0;
    font-weight: 600;
}

.chats-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.chat-item {
    display: flex;
    gap: 15px;
    padding: 15px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    margin-bottom: 5px;
}

.chat-item:hover {
    background: var(--hover-bg);
}

.chat-item.selected {
    background: rgba(20, 184, 166, 0.1);
    border-left: 3px solid var(--primary-color);
}

.chat-icon {
    font-size: 32px;
    flex-shrink: 0;
}

.chat-info {
    flex: 1;
    min-width: 0;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}

.chat-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.unread-badge {
    background: var(--primary-color);
    color: white;
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 12px;
    font-weight: 600;
    min-width: 20px;
    text-align: center;
}

.chat-preview {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 5px 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-time {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Messages Panel */
.messages-panel {
    flex: 1;
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.messages-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-dark);
}

.messages-header h2 {
    color: var(--text-primary);
    font-size: 18px;
    margin: 0;
    font-weight: 600;
}

.messages-list {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--bg-darker);
}

.message-item {
    margin-bottom: 15px;
    padding: 12px 15px;
    border-radius: 10px;
    max-width: 70%;
    word-wrap: break-word;
}

.message-sent {
    background: rgba(20, 184, 166, 0.2);
    margin-left: auto;
    margin-right: 0;
    border: 1px solid rgba(20, 184, 166, 0.3);
}

.message-received {
    background: var(--bg-card);
    margin-left: 0;
    margin-right: auto;
    border: 1px solid var(--border-color);
}

.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}

.message-sender {
    font-weight: 600;
    font-size: 13px;
    color: var(--primary-color);
}

.message-time {
    font-size: 11px;
    color: var(--text-secondary);
}

.message-body {
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.5;
}

.message-body p {
    margin: 0;
}

.message-media {
    margin-top: 5px;
}

.message-image {
    display: block;
    max-width: 100%;
    border-radius: 8px;
    transition: transform 0.2s;
}

.message-image:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Image Modal */
.image-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.3s;
}

.image-modal-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.image-modal-content img {
    max-width: 100%;
    max-height: 90vh;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.image-modal-close {
    position: absolute;
    top: -40px;
    right: 0;
    color: white;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.3s;
    background: var(--bg-card);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.image-modal-close:hover {
    color: var(--primary-color);
    background: var(--bg-dark);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Message animation for new messages */
.message-item.message-new {
    animation: messageSlideIn 0.3s ease-out;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Message Input */
.message-input-container {
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-dark);
}

.send-message-form {
    display: flex;
    gap: 10px;
    align-items: center;
}

.message-input {
    flex: 2;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 25px;
    font-size: 14px;
    background: var(--bg-card);
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.3s;
}

.message-input:focus {
    border-color: var(--primary-color);
}

.message-input::placeholder {
    color: var(--text-secondary);
}

.btn-send {
    padding: 12px 24px;
    border-radius: 25px;
    white-space: nowrap;
    min-width: 80px;
    width: auto;
}

.btn-send:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px);
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--bg-card);
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border-color);
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    color: var(--text-primary);
    font-size: 20px;
    font-weight: 600;
}

.close-modal {
    font-size: 28px;
    font-weight: bold;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.close-modal:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
}

.qr-container {
    margin-top: 20px;
    text-align: center;
    padding: 20px;
    background: var(--bg-dark);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.qr-container h3 {
    margin-bottom: 15px;
    color: var(--text-primary);
    font-size: 16px;
}

#qrCodeDisplay {
    display: flex;
    justify-content: center;
    margin: 20px 0;
}

#qrCodeDisplay img {
    max-width: 100%;
    border: 5px solid var(--bg-card);
    border-radius: 8px;
}

.qr-instruction {
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 15px;
}

.loading-text {
    color: var(--primary-color);
    font-weight: 600;
    padding: 20px;
    text-align: center;
}

/* Charts */
.chart-container {
    position: relative;
    height: 300px;
    width: 100%;
}

/* Analytics specific */
.broadcast-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
}

.contacts-grid,
.groups-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 15px;
}

.contact-card,
.group-card {
    transition: transform 0.2s, border-color 0.2s;
}

.contact-card:hover,
.group-card:hover {
    transform: translateY(-2px);
    border-color: var(--primary-color);
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
    }

    .main-content {
        margin-left: 0;
    }

    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }

    .search-bar {
        width: 100%;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .chats-container {
        flex-direction: column;
        height: auto;
    }

    .chats-list-panel {
        flex: 1;
        max-height: 300px;
    }
}

/* Dataset Page Styles */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-card);
    border-radius: 8px;
    overflow: hidden;
}

.data-table thead {
    background: var(--bg-dark);
    position: sticky;
    top: 0;
    z-index: 10;
}

.data-table th {
    padding: 14px 16px;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 13px;
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
}

.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 13px;
    vertical-align: middle;
}

.data-table tbody tr {
    transition: background-color 0.2s;
}

.data-table tbody tr:hover {
    background: var(--hover-bg);
    cursor: pointer;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table .btn-small {
    padding: 6px 12px;
    font-size: 12px;
    margin: 0 2px;
}

/* Card Styles */
.card {
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    margin-bottom: 20px;
    overflow: hidden;
    margin-right: 30px;
    margin-left: 30px;
}

.card-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-dark);
}

.card-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.card-body {
    padding: 24px;
}

/* Page Header */
.page-header {
    margin-bottom: 30px;
    padding: 30px 30px 0;
}

.page-header h1 {
    font-size: 28px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.page-header p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* Form Text */
.form-text {
    display: block;
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

/* Modal Styles for Dataset */
.modal.show {
    display: flex;
}

.modal-content {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    background: var(--bg-dark);
}

.modal-body {
    overflow-y: auto;
    flex: 1;
}

.close {
    color: var(--text-secondary);
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.close:hover {
    color: var(--text-primary);
}

/* Table Pagination */
#tablePagination {
    padding: 16px;
    background: var(--bg-dark);
    border-radius: 8px;
    margin-bottom: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

#tablePagination label {
    color: var(--text-secondary);
    font-size: 13px;
    margin-right: 8px;
}

#tablePagination select {
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
}

#tablePagination select:focus {
    outline: none;
    border-color: var(--primary-color);
}

#pageInfo {
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
}

/* Responsive Table */
@media (max-width: 768px) {
    .data-table {
        font-size: 12px;
    }
    
    .data-table th,
    .data-table td {
        padding: 10px 12px;
    }
    
    .modal-content {
        margin: 2% auto;
        max-width: 95vw;
        max-height: 96vh;
    }
    
    .page-header {
        padding: 20px 20px 0;
    }
}

/* Form Control Styles */
.form-control {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    background: var(--bg-dark);
    color: var(--text-primary);
    transition: all 0.3s;
    font-family: inherit;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.1);
}

.form-control::placeholder {
    color: var(--text-secondary);
}

.form-control option {
    background: var(--bg-dark);
    color: var(--text-primary);
}

/* Checkbox Styles */
input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary-color);
    margin-right: 8px;
}

input[type="checkbox"] + label {
    cursor: pointer;
    color: var(--text-primary);
    font-size: 14px;
    user-select: none;
}

label {
    display: flex;
    align-items: center;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
}

/* Code Styles */
code {
    font-family: 'Courier New', monospace;
    font-size: 13px;
    background: var(--bg-dark);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--primary-color);
}

/* Badge Styles (if not already defined) */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-success {
    background: rgba(16, 185, 129, 0.2);
    color: #10b981;
}

.badge-danger {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}
