:root {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --bg-color: #f3f4f6;
    --sidebar-bg: #1f2937;
    --sidebar-text: #e5e7eb;
    --card-bg: #ffffff;
    --text-color: #374151;
    --text-light: #6b7280;
    --border-color: #e5e7eb;
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --success-color: #10b981;
    --warning-color: #f59e0b;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    overflow: hidden;
    line-height: 1.5;
}

/* Utilities */
.hidden { display: none !important; }
.full-width { width: 100%; }
.text-only { background: none; color: var(--text-light); border: none; padding: 0.5rem; text-decoration: underline; cursor: pointer; font-size: 0.875rem; }
.text-only:hover { color: var(--primary-color); }

/* Login View */
#login-view {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
}

.login-box {
    background: white;
    padding: 2.5rem;
    border-radius: 12px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    text-align: center;
}

.login-box h2 {
    margin-bottom: 0.5rem;
    color: #111827;
    font-size: 1.75rem;
}

.login-box h2 i {
    margin-right: 0.5rem;
    color: var(--primary-color);
}

.login-box p {
    color: var(--text-light);
    margin-bottom: 1.5rem;
}

/* Layout */
#dashboard-view {
    display: flex;
    height: 100vh;
}

.sidebar {
    width: 240px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.brand {
    padding: 1.25rem 1.5rem;
    font-size: 1.125rem;
    font-weight: 600;
    border-bottom: 1px solid #374151;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.brand i {
    color: var(--primary-color);
}

.nav-links {
    list-style: none;
    padding: 1rem 0;
    flex-grow: 1;
}

.nav-links li {
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9375rem;
}

.nav-links li i {
    width: 20px;
    text-align: center;
}

.nav-links li:hover {
    background: rgba(255,255,255,0.08);
}

.nav-links li.active {
    background: var(--primary-color);
    color: white;
}

.logout-section {
    padding: 1rem;
    border-top: 1px solid #374151;
}

#logout-btn {
    width: 100%;
    background: transparent;
    border: 1px solid #4b5563;
    color: #9ca3af;
    padding: 0.625rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

#logout-btn:hover {
    background: rgba(255,255,255,0.05);
    color: white;
    border-color: #6b7280;
}

.content-area {
    flex-grow: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: var(--bg-color);
}

.tab-content {
    padding: 2rem;
    height: 100%;
    overflow-y: auto;
    display: none;
}

.tab-content.active {
    display: block;
}

/* Page Headers */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: #111827;
}

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    border-radius: 6px;
    border: none;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

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

.btn.primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn.danger {
    background: var(--danger-color);
    color: white;
}

.btn.danger:hover:not(:disabled) {
    background: var(--danger-hover);
}

.btn.small {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn.icon {
    padding: 0.5rem;
    border-radius: 6px;
    width: 36px;
    height: 36px;
    justify-content: center;
    background: white;
    border: 1px solid var(--border-color);
    color: var(--text-color);
}

.btn.icon:hover {
    background: var(--bg-color);
}

/* Forms */
.input-group {
    margin-bottom: 1rem;
    text-align: left;
}

.input-group label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-light);
    margin-bottom: 0.375rem;
    font-weight: 500;
}

.input-group input, .input-group select {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.9375rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-group input:focus, .input-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Tables */
.table-container {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    overflow: hidden;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    background: #f9fafb;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-light);
}

tbody tr:hover {
    background: #f9fafb;
}

tr:last-child td {
    border-bottom: none;
}

.actions-col {
    text-align: right;
    width: 180px;
}

.actions-col .btn {
    margin-left: 0.5rem;
}

.empty-message {
    text-align: center;
    padding: 3rem;
    color: var(--text-light);
}

.empty-message i {
    font-size: 2rem;
    margin-bottom: 1rem;
    display: block;
}

/* Status Badge */
.status-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
}

.status-badge.active, .status-badge.online {
    background: #d1fae5;
    color: #065f46;
}

.status-badge.inactive, .status-badge.offline {
    background: #fee2e2;
    color: #991b1b;
}

.status-badge.checking {
    background: #fef3c7;
    color: #92400e;
}

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

.status-card {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.status-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: var(--bg-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    color: var(--primary-color);
}

.status-info h3 {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.info-card {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.info-card h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: #111827;
}

.info-table {
    width: 100%;
}

.info-table td {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
}

.info-table td:first-child {
    font-weight: 500;
    color: var(--text-light);
    width: 150px;
}

/* Webmail Layout */
#tab-webmail {
    padding: 0;
    flex-direction: column;
    height: 100%;
}

#tab-webmail.active {
    display: flex;
}

.centered-panel {
    max-width: 400px;
    margin: 4rem auto;
    background: white;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    text-align: center;
}

.centered-panel h3 {
    margin-bottom: 0.5rem;
}

.centered-panel p {
    color: var(--text-light);
    margin-bottom: 1.5rem;
}

#webmail-interface {
    display: flex;
    height: 100%;
}

.mail-layout {
    display: flex;
    width: 100%;
    height: 100%;
}

.mail-sidebar {
    width: 180px;
    background: #fff;
    border-right: 1px solid var(--border-color);
    padding: 1rem;
    display: flex;
    flex-direction: column;
}

#mailbox-list {
    list-style: none;
    margin-top: 0.5rem;
    flex-grow: 1;
}

#mailbox-list li {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    border-radius: 6px;
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
}

#mailbox-list li:hover {
    background: #f3f4f6;
}

#mailbox-list li.active {
    background: #dbeafe;
    color: var(--primary-color);
    font-weight: 500;
}

.current-user-display {
    font-size: 0.8125rem;
    color: var(--text-light);
    padding: 0.5rem;
    background: var(--bg-color);
    border-radius: 6px;
    word-break: break-all;
}

.mail-list-panel {
    width: 320px;
    background: #fff;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.mail-tools {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 10px;
    background: #f9fafb;
}

.mail-tools #current-folder-name {
    font-weight: 600;
    font-size: 0.875rem;
}

.mail-count {
    font-size: 0.75rem;
    color: var(--text-light);
    margin-left: auto;
}

#email-list-container {
    overflow-y: auto;
    flex-grow: 1;
}

.email-item {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.15s;
}

.email-item:hover {
    background: #f9fafb;
}

.email-item.unread {
    background: #fefefe;
    border-left: 3px solid var(--primary-color);
}

.email-item.unread .email-subject {
    font-weight: 600;
}

.email-item.selected {
    background: #dbeafe;
}

.email-subject {
    font-size: 0.875rem;
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #111827;
}

.email-from {
    font-size: 0.75rem;
    color: var(--text-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.email-date {
    font-size: 0.6875rem;
    color: var(--text-light);
    margin-top: 0.25rem;
}

.mail-view-panel {
    flex-grow: 1;
    background: #fff;
    overflow-y: auto;
    position: relative;
}

#email-content-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #9ca3af;
}

#email-content-placeholder p {
    margin-top: 1rem;
}

#email-content-view {
    padding: 1.5rem;
}

.email-header {
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
    margin-bottom: 1rem;
}

.email-header h2 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    color: #111827;
}

.email-header .meta {
    font-size: 0.875rem;
    color: var(--text-light);
    line-height: 1.6;
}

.email-header .meta strong {
    color: var(--text-color);
}

.email-header .actions {
    margin-top: 1rem;
    display: flex;
    gap: 0.5rem;
}

.attachments {
    background: #f9fafb;
    padding: 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

.attachments ul {
    margin-top: 0.5rem;
    padding-left: 1.25rem;
}

.attachments li {
    margin-bottom: 0.25rem;
}

.email-body {
    line-height: 1.7;
    font-size: 0.9375rem;
    color: var(--text-color);
}

.email-body img {
    max-width: 100%;
    height: auto;
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    animation: fadeIn 0.2s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background-color: #fefefe;
    margin: 10% auto;
    padding: 2rem;
    border-radius: 12px;
    width: 100%;
    max-width: 440px;
    position: relative;
    animation: slideDown 0.2s;
}

@keyframes slideDown {
    from { transform: translateY(-20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-content.modal-small {
    max-width: 360px;
}

.modal-content.modal-large {
    max-width: 600px;
}

.modal-content h2 {
    margin-bottom: 0.5rem;
    font-size: 1.25rem;
}

.modal-subtitle {
    color: var(--text-light);
    font-size: 0.875rem;
    margin-bottom: 1.5rem;
}

.close {
    position: absolute;
    right: 1.5rem;
    top: 1rem;
    font-size: 1.5rem;
    cursor: pointer;
    color: #9ca3af;
    line-height: 1;
}

.close:hover {
    color: #000;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

/* Toast */
#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
}

.toast {
    background: #333;
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    margin-top: 10px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    animation: slideIn 0.3s;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.875rem;
}

.toast i {
    font-size: 1rem;
}

.toast.success {
    background: #065f46;
}

.toast.success i {
    color: #6ee7b7;
}

.toast.error {
    background: #991b1b;
}

.toast.error i {
    color: #fca5a5;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Loading Spinner */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: var(--text-light);
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 0.75rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Mobile Responsive */
@media (max-width: 1024px) {
    .mail-list-panel {
        width: 280px;
    }
}

@media (max-width: 768px) {
    #dashboard-view {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        flex-direction: row;
        align-items: center;
        height: auto;
        padding: 0.5rem;
    }

    .brand {
        border: none;
        padding: 0.5rem;
        font-size: 1rem;
    }

    .nav-links {
        display: flex;
        flex-direction: row;
        padding: 0;
        margin: 0;
        overflow-x: auto;
    }

    .nav-links li {
        padding: 0.5rem 0.75rem;
    }

    .nav-links li span {
        display: none;
    }

    .logout-section {
        padding: 0.5rem;
        border: none;
    }

    #logout-btn {
        width: auto;
        padding: 0.5rem;
    }

    #logout-btn span {
        display: none;
    }

    .content-area {
        height: calc(100vh - 56px);
    }

    .tab-content {
        padding: 1rem;
    }

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

    .mail-layout {
        flex-direction: column;
    }

    .mail-sidebar {
        width: 100%;
        height: auto;
        flex-direction: row;
        align-items: center;
        padding: 0.5rem;
        border-bottom: 1px solid var(--border-color);
        border-right: none;
    }

    #mailbox-list {
        display: flex;
        margin: 0;
        gap: 5px;
        overflow-x: auto;
    }

    .current-user-display {
        display: none;
    }

    .mail-list-panel {
        width: 100%;
        height: 40%;
        min-height: 200px;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .mail-view-panel {
        height: 60%;
    }

    .actions-col {
        width: auto;
    }

    .actions-col .btn span {
        display: none;
    }
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: white;
    border-top: 1px solid var(--border-color);
    border-radius: 0 0 8px 8px;
}

.pagination-info {
    font-size: 0.875rem;
    color: var(--text-light);
}

.pagination-controls {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.pagination-controls .btn {
    min-width: 36px;
    justify-content: center;
}

.pagination-ellipsis {
    padding: 0 0.5rem;
    color: var(--text-light);
}

/* Page Header Actions */
.page-header-actions {
    display: flex;
    gap: 0.5rem;
}

/* Batch Account Creation */
.batch-result-container {
    margin-top: 1rem;
    max-height: 300px;
    overflow-y: auto;
}

.batch-success {
    margin-bottom: 1rem;
}

.batch-success strong {
    color: var(--success-color);
    display: block;
    margin-bottom: 0.5rem;
}

.batch-failed {
    margin-top: 1rem;
}

.batch-failed strong {
    color: var(--danger-color);
    display: block;
    margin-bottom: 0.5rem;
}

.batch-failed ul {
    margin: 0;
    padding-left: 1.5rem;
    font-size: 0.875rem;
}

.batch-result-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.batch-result-table th,
.batch-result-table td {
    padding: 0.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.batch-result-table th {
    background: #f9fafb;
    font-weight: 600;
}

.batch-result-table code {
    background: #f3f4f6;
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.8125rem;
}

@media (max-width: 768px) {
    .page-header-actions {
        flex-wrap: wrap;
    }

    .pagination {
        flex-direction: column;
        gap: 0.75rem;
    }
}
