* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: linear-gradient(135deg, #eef2f7, #e8edf3, #eef2f7);
    min-height: 100vh;
    padding: 0;
    color: #2c3e50;
}

/* ===== TOP BAR ===== */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px 24px;
    background: linear-gradient(135deg, #2c3e50, #34495e);
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

.top-bar-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.nav-row {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.nav-link-btn {
    display: inline-block;
    font-size: 0.95rem;
    color: #00ffaa;
    text-decoration: none;
    padding: 8px 28px;
    border-radius: 24px;
    font-weight: 700;
    letter-spacing: 0.5px;
    border: 2px solid #00ffaa;
    transition: all 0.2s;
}

.nav-link-btn:hover {
    background: #00ffaa;
    color: #2c3e50;
    box-shadow: 0 0 20px rgba(0, 255, 170, 0.3);
}

.top-title {
    font-size: 2.8em;
    font-weight: 900;
    letter-spacing: 3px;
    color: #ffffff;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.nav-link-btn {
    display: inline-block;
    font-size: 0.95rem;
    color: #00ffaa;
    text-decoration: none;
    padding: 8px 28px;
    border-radius: 24px;
    font-weight: 700;
    letter-spacing: 0.5px;
    border: 2px solid #00ffaa;
    transition: all 0.2s;
}

.nav-link-btn:hover {
    background: #00ffaa;
    color: #0a1628;
    box-shadow: 0 0 20px rgba(0, 255, 170, 0.3);
}

.container {
    max-width: 1000px;
    margin: 0 auto 20px;
    background: #fff;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

/* Email Setup Card */
.email-setup .card {
    background: #f7f9fc;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 20px;
    box-shadow: none;
}

.card h2 {
    color: #34495e;
    font-size: 1.5em;
    margin-bottom: 15px;
    border-bottom: 2px solid #3498db;
    padding-bottom: 5px;
}

/* Email Input Row */
.email-input-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 15px;
}

.email-group {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 3;
    /* dài nhất */
}

.domain-group {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    /* ngắn hơn email */
    max-width: 220px;
}

.email-group label,
.domain-group label {
    font-weight: 500;
    color: #34495e;
    white-space: nowrap;
}

.form-control-inline {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 1em;
    transition: border-color 0.3s;
    flex: 1;
}

.form-control-inline:focus {
    border-color: #3498db;
    outline: none;
    box-shadow: 0 0 5px rgba(52, 152, 219, 0.3);
}

.email-group .form-control-inline {
    min-width: 320px;
}

.domain-group select {
    min-width: 140px;
}

/* Online/Offline Button */
.btn-online {
    background: #2ecc71;
    color: #fff;
    padding: 8px 16px;
    /* ngắn lại */
    border: none;
    border-radius: 5px;
    font-size: 1em;
    cursor: pointer;
    transition: background 0.3s;
    font-weight: 500;
    flex: 0 0 auto;
    /* không giãn theo hàng */
}

.btn-offline {
    background: #e74c3c;
    color: #fff;
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    font-size: 1em;
    cursor: pointer;
    font-weight: 500;
}

.btn-online:hover {
    background: #27ae60;
}

.btn-offline:hover {
    background: #c0392b;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    justify-content: center;
    align-items: stretch;
    gap: 15px;
    flex-wrap: nowrap;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    font-size: 1em;
    cursor: pointer;
    transition: background 0.3s, transform 0.1s;
    font-weight: 500;
    flex: 1 1 0;
    text-align: center;
}

.btn:hover {
    transform: translateY(-2px);
}

.btn-warning {
    background: #f1c40f;
    color: #2c3e50;
}

.btn-warning:hover {
    background: #d4ac0d;
}

.btn-primary {
    background: #3498db;
    color: #fff;
}

.btn-primary:hover {
    background: #2980b9;
}

.btn-success {
    background: #2ecc71;
    color: #fff;
}

.btn-success:hover {
    background: #27ae60;
}

.btn-info {
    background: #3498db;
    color: #fff;
}

.btn-info:hover {
    background: #2980b9;
}

/* Section Header */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 20px 0 10px;
}

.section-header h2 {
    color: #34495e;
    font-size: 1.5em;
    border-bottom: 2px solid #3498db;
    padding-bottom: 5px;
}

.badge {
    background: #3498db;
    color: white;
    padding: 5px 15px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
}

/* Email Table */
.email-table {
    width: 100%;
    border: 1px solid #ddd;
    border-collapse: collapse;
    margin-top: 15px;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    min-height: 200px;
}

.email-table thead {
    background: #34495e;
    color: #fff;
    border-bottom: 2px solid #2c3e50;
}

.email-table th {
    padding: 12px 15px;
    text-align: left;
    font-weight: 500;
    text-transform: uppercase;
    font-size: 0.9em;
    border-right: 1px solid rgba(255, 255, 255, 0.3);
    border-bottom: 2px solid #2c3e50;
}

.email-table th:last-child {
    border-right: none;
}

.email-table td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid #eee;
    border-right: 1px solid #eee;
    color: #2c3e50;
}

.email-table td:last-child {
    border-right: none;
}

.email-table tbody tr:hover {
    background: #dfe6e9;
}

.email-table td.selectable {
    cursor: text;
    user-select: text;
}

.email-table td.actions-cell {
    white-space: nowrap;
}

/* Action Buttons in Table */
.btn-action {
    padding: 8px 12px;
    border: none;
    border-radius: 5px;
    font-size: 0.9em;
    cursor: pointer;
    transition: background 0.3s, transform 0.1s;
    margin-right: 5px;
    font-weight: 500;
}

.btn-view {
    background: #3498db;
    color: #fff;
}

.btn-view:hover {
    background: #2980b9;
    transform: translateY(-2px);
}

.btn-delete {
    background: #e74c3c;
    color: #fff;
}

.btn-delete:hover {
    background: #c0392b;
    transform: translateY(-2px);
}

/* Pagination */
.pagination-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 15px 0;
    padding: 10px;
    background: #f7f9fc;
    border-radius: 8px;
    gap: 15px;
    flex-wrap: wrap;
}

.pagination-left,
.pagination-center,
.pagination-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.pagination-center {
    flex: 1;
    justify-content: center;
    font-weight: 500;
    color: #2c3e50;
}

.limit-select {
    padding: 5px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    cursor: pointer;
    font-size: 0.9rem;
}

.limit-select:focus {
    outline: none;
    border-color: #3498db;
}

.page-number {
    background: #3498db;
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-weight: 600;
    min-width: 30px;
    text-align: center;
    border: 1px solid #3498db;
}

.btn-secondary {
    padding: 5px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    font-size: 0.9rem;
}

.btn-secondary:hover {
    background: #f5f5f5;
}

.btn-secondary:disabled {
    background: #f5f5f5;
    cursor: not-allowed;
    opacity: 0.6;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #6c757d;
}

.empty-state p {
    font-size: 1.1rem;
    margin-bottom: 10px;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
}

.modal-content {
    background: white;
    margin: 50px auto;
    max-width: 800px;
    border-radius: 10px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 25px;
    border-bottom: 2px solid #e0e6ed;
}

.modal-header h2 {
    color: #2c3e50;
}

.close-btn {
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: #6c757d;
    transition: color 0.3s ease;
}

.close-btn:hover {
    color: #e74c3c;
}

.modal-body {
    padding: 25px;
    max-height: 60vh;
    overflow-y: auto;
}

.email-detail {
    line-height: 1.8;
}

.detail-row {
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid #e0e6ed;
}

.detail-row strong {
    display: block;
    margin-bottom: 5px;
    color: #2c3e50;
}

.detail-content {
    margin-top: 20px;
}

.detail-content strong {
    display: block;
    margin-bottom: 10px;
    color: #2c3e50;
}

#detailBody {
    background: #f9fbfc;
    padding: 15px;
    border-radius: 5px;
    border: 1px solid #e0e6ed;
    color: #2c3e50;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.modal-footer {
    padding: 20px 25px;
    border-top: 2px solid #e0e6ed;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.btn-danger {
    background: #e74c3c;
    color: white;
}

.btn-danger:hover {
    background: #c0392b;
}

/* Loading Inline */
.loading-overlay {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    justify-content: center;
}

.loading-overlay.show {
    display: flex;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid rgba(52, 152, 219, 0.2);
    border-top: 3px solid #3498db;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.loading-overlay p {
    color: #3498db;
    font-size: 0.82rem;
    font-weight: 600;
    margin: 0;
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: #2c3e50;
    color: white;
    padding: 15px 30px;
    border-radius: 8px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
    transition: bottom 0.3s ease;
    z-index: 3000;
}

.toast.show {
    bottom: 30px;
}

.toast.success {
    background: #27ae60;
}

.toast.error {
    background: #c0392b;
}

.toast.info {
    background: #3498db;
}

/* Footer */
.footer {
    text-align: center;
    color: #2c3e50;
    margin-top: 40px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 10px;
    max-width: 1000px;
    margin-left: auto;
    margin-right: auto;
}

.footer p {
    margin: 5px 0;
}

.footer a {
    color: #3498db;
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
}

.footer .warning {
    font-size: 0.9rem;
    color: #6c757d;
}

/* Bulk Email Reader */
.bulk-mail-section {
    margin-top: 25px;
}

.bulk-mail-card {
    background: #f7f9fc;
    border-radius: 8px;
    padding: 15px;
    border: 1px solid #e0e6ed;
}

.bulk-textarea {
    width: 100%;
    min-height: 120px;
    padding: 12px;
    border-radius: 6px;
    border: 1px solid #ddd;
    font-family: 'Inter', monospace;
    font-size: 0.9rem;
    resize: vertical;
    line-height: 1.6;
}

.bulk-textarea:focus {
    border-color: #3498db;
    outline: none;
    box-shadow: 0 0 5px rgba(52, 152, 219, 0.3);
}

.bulk-mail-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.bulk-status {
    font-size: 0.85rem;
    font-weight: 600;
    color: #3498db;
}

.bulk-results {
    margin-top: 15px;
}

.bulk-email-group {
    margin-bottom: 15px;
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
}

.bulk-email-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: #34495e;
    color: #fff;
    font-weight: 600;
    font-size: 0.9rem;
}

.bulk-email-group-header .bulk-count {
    background: #3498db;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
}

.bulk-email-group-header .bulk-error {
    background: #e74c3c;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
}

.bulk-email-group .email-table {
    margin-top: 0;
    border: none;
    border-radius: 0;
}

/* Responsive */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .main-title h1 {
        font-size: 2em;
        letter-spacing: 2px;
    }

    .container {
        padding: 20px;
        margin: 0 auto 10px;
    }

    .email-input-row {
        flex-direction: column;
        align-items: stretch;
    }

    .email-group,
    .domain-group {
        flex-direction: column;
        align-items: flex-start;
        width: 100%;
    }

    .form-control-inline {
        width: 100%;
        min-width: auto;
    }

    .btn-online,
    .btn-offline {
        width: 100%;
    }

    .action-buttons {
        flex-direction: column;
    }

    .action-buttons .btn {
        width: 100%;
    }

    .email-table {
        font-size: 0.85rem;
    }

    .email-table th,
    .email-table td {
        padding: 8px;
    }

    .pagination-wrapper {
        flex-direction: column;
        gap: 10px;
    }

    .pagination-left,
    .pagination-center,
    .pagination-right {
        width: 100%;
        justify-content: center;
    }

    .modal-content {
        margin: 20px;
        max-width: calc(100% - 40px);
    }

    .modal-footer {
        flex-direction: column;
    }

    .modal-footer .btn {
        width: 100%;
    }

    .domain-filter-row {
        flex-direction: column;
        align-items: stretch;
    }
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #f7f9fc;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb {
    background: #3498db;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: #2980b9;
}

/* ===== THEME TOGGLE SWITCH ===== */
.theme-toggle-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 12px 0;
}

.theme-label {
    font-size: 1.3rem;
    user-select: none;
    display: inline-block;
    width: 28px;
    text-align: center;
}

.switch {
    position: relative;
    display: inline-block;
    width: 56px;
    height: 28px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch .slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #ccd5de;
    border-radius: 28px;
    transition: background 0.3s;
}

.switch .slider::before {
    content: '';
    position: absolute;
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.3s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.switch input:checked+.slider {
    background: #1e3a5f;
}

.switch input:checked+.slider::before {
    transform: translateX(28px);
}

/* ===== DARK THEME ===== */
[data-theme="dark"] {
    background: linear-gradient(135deg, #0a1628, #0d1f3c, #0a1628);
    color: #e0e6ed;
}

[data-theme="dark"] .top-bar {
    background: linear-gradient(135deg, #0a1628, #0d1f3c);
    border-bottom-color: rgba(0, 255, 170, 0.15);
}

[data-theme="dark"] .top-title {
    color: #fff;
}

[data-theme="dark"] .nav-link-btn {
    color: #00ffaa;
    border-color: #00ffaa;
}

[data-theme="dark"] .nav-link-btn:hover {
    background: #00ffaa;
    color: #0a1628;
}

[data-theme="dark"] .container {
    background: #0d1b30;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
    border: 1px solid #2a5a8f;
}

[data-theme="dark"] .email-setup .card {
    background: #122240;
    border: 1px solid #2a5a8f;
}

[data-theme="dark"] .card h2,
[data-theme="dark"] .section-header h2 {
    color: #e0e6ed;
    border-bottom-color: #2a5a8f;
}

[data-theme="dark"] .email-group label,
[data-theme="dark"] .domain-group label,
[data-theme="dark"] .domain-filter-row label {
    color: #8899aa;
}

[data-theme="dark"] .form-control-inline {
    background: #0d1f3c;
    border-color: #2a5a8f;
    color: #e0e6ed;
}

[data-theme="dark"] .form-control-inline:focus {
    border-color: #00ffaa;
    box-shadow: 0 0 5px rgba(0, 255, 170, 0.2);
}

[data-theme="dark"] .email-table {
    background: #0d1b30;
    border: 1px solid #2a5a8f;
}

[data-theme="dark"] .email-table thead {
    background: #1a3355;
    border-bottom: 2px solid #3a7abf;
}

[data-theme="dark"] .email-table th {
    color: #ffffff;
    border-right: 1px solid #3a7abf;
    border-bottom: 2px solid #3a7abf;
}

[data-theme="dark"] .email-table th:last-child {
    border-right: none;
}

[data-theme="dark"] .email-table td {
    color: #e0e6ed;
    border-bottom: 1px solid #305a85;
    border-right: 1px solid #2a4d75;
}

[data-theme="dark"] .email-table td:last-child {
    border-right: none;
}

[data-theme="dark"] .email-table tbody tr:hover {
    background: #142d50;
}

[data-theme="dark"] .pagination-wrapper {
    background: #122240;
    border: 1px solid #2a5a8f;
    color: #e0e6ed;
}

[data-theme="dark"] .pagination-center {
    color: #ffffff;
}

[data-theme="dark"] .pagination-left,
[data-theme="dark"] .pagination-right {
    color: #e0e6ed;
}

[data-theme="dark"] .limit-select {
    background: #0d1f3c;
    border-color: #2a5a8f;
    color: #e0e6ed;
}

[data-theme="dark"] .btn-secondary {
    background: #122240;
    border-color: #2a5a8f;
    color: #e0e6ed;
}

[data-theme="dark"] .btn-secondary:hover {
    background: #1a3352;
}

[data-theme="dark"] .bulk-mail-card {
    background: #122240;
    border: 1px solid #2a5a8f;
}

[data-theme="dark"] .bulk-textarea {
    background: #0d1f3c;
    border-color: #2a5a8f;
    color: #e0e6ed;
}

[data-theme="dark"] .bulk-textarea:focus {
    border-color: #00ffaa;
    box-shadow: 0 0 5px rgba(0, 255, 170, 0.2);
}

[data-theme="dark"] .bulk-status {
    color: #00ffaa;
}

[data-theme="dark"] .bulk-email-group {
    border-color: #2a5a8f;
}

[data-theme="dark"] .bulk-email-group-header {
    background: #1a3355;
}

[data-theme="dark"] .modal-content {
    background: #0d1b30;
}

[data-theme="dark"] .modal-header {
    border-bottom-color: #1e4a6f;
}

[data-theme="dark"] .modal-header h2 {
    color: #00ffaa;
    border-bottom: none;
}

[data-theme="dark"] .close-btn {
    color: #8899aa;
}

[data-theme="dark"] .close-btn:hover {
    color: #ff6b6b;
}

[data-theme="dark"] .detail-row {
    border-bottom-color: #1e3a5f;
}

[data-theme="dark"] .detail-row strong,
[data-theme="dark"] .detail-content strong {
    color: #8899aa;
}

[data-theme="dark"] .detail-row span {
    color: #e0e6ed;
}

[data-theme="dark"] #detailBody {
    background: #0a1628;
    border-color: #1e3a5f;
    color: #e0e6ed;
}

[data-theme="dark"] .modal-footer {
    border-top-color: #1e4a6f;
}

[data-theme="dark"] .footer {
    background: rgba(13, 27, 48, 0.8);
    color: #8899aa;
}

[data-theme="dark"] .footer a {
    color: #00d4ff;
}

[data-theme="dark"] .footer .warning {
    color: #6b8299;
}

[data-theme="dark"] .empty-state {
    color: #6b8299;
}

[data-theme="dark"] .toast {
    background: #1e3a5f;
}

[data-theme="dark"] .loading-overlay p {
    color: #00ffaa;
}

[data-theme="dark"] .spinner {
    border-color: rgba(0, 255, 170, 0.2);
    border-top-color: #00ffaa;
}

[data-theme="dark"] ::-webkit-scrollbar-track {
    background: #0d1b30;
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
    background: #1e4a6f;
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
    background: #2a5a8f;
}