/**
 * VINAmail — Custom Styles
 * Built on top of Bootstrap 5 CDN.
 * Provides styling for login, inbox, email view, compose,
 * user settings, admin dashboard, and activity log pages.
 */

/* ===================================================================
   1. CSS Custom Properties (Theme)
   =================================================================== */
:root {
    --sidebar-width: 240px;
    --sidebar-bg: #f8f9fa;
    --sidebar-active-bg: #e9ecef;
    --sidebar-hover-bg: #dee2e6;
    --unread-dot-color: #0d6efd;
    --quota-normal: #198754;
    --quota-warning: #ffc107;
    --quota-full: #dc3545;
    --email-hover-bg: #f0f4ff;
    --admin-card-border: #dee2e6;
}

/* ===================================================================
   2. Global / Layout
   =================================================================== */
html, body {
    height: 100%;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background-color: #f5f6fa;
}

.page-wrapper {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

/* ===================================================================
   3. Login Page
   =================================================================== */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-card {
    width: 100%;
    max-width: 420px;
    border: none;
    border-radius: 0.75rem;
    box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.2);
}

.login-card .card-body {
    padding: 2.5rem;
}

.login-card .card-title {
    font-weight: 700;
    margin-bottom: 1.5rem;
    text-align: center;
}

.login-card .btn-primary {
    width: 100%;
    padding: 0.625rem;
    font-weight: 600;
}

.login-logo {
    text-align: center;
    margin-bottom: 1rem;
}

.login-logo i {
    font-size: 3rem;
    color: #667eea;
}


/* ===================================================================
   4. Sidebar — Gmail-like Folder Navigation
   =================================================================== */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    border-right: 1px solid #dee2e6;
    overflow-y: auto;
    padding: 1rem 0;
    display: flex;
    flex-direction: column;
}

.sidebar .nav-link {
    color: #333;
    padding: 0.5rem 1.25rem;
    border-radius: 0 1.5rem 1.5rem 0;
    margin-right: 0.75rem;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: background-color 0.15s ease;
}

.sidebar .nav-link:hover {
    background-color: var(--sidebar-hover-bg);
}

.sidebar .nav-link.active {
    background-color: #d3e3fd;
    color: #001d35;
    font-weight: 600;
}

.sidebar .nav-link .badge {
    margin-left: auto;
    font-size: 0.75rem;
}

.sidebar .compose-btn {
    margin: 0 1rem 1rem;
    border-radius: 1.5rem;
    padding: 0.75rem 1.5rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.sidebar-quota {
    margin-top: auto;
    padding: 1rem 1.25rem;
    border-top: 1px solid #dee2e6;
    font-size: 0.8rem;
    color: #6c757d;
}

/* ===================================================================
   5. Inbox / Email List
   =================================================================== */
.email-list-table {
    margin-bottom: 0;
}

.email-list-table thead th {
    border-bottom: 2px solid #dee2e6;
    font-size: 0.8rem;
    text-transform: uppercase;
    color: #6c757d;
    font-weight: 600;
    padding: 0.5rem 0.75rem;
}

.email-list-table tbody tr {
    cursor: pointer;
    transition: background-color 0.1s ease;
}

.email-list-table tbody tr:hover {
    background-color: var(--email-hover-bg);
}

/* Unread email — bold text + indicator dot */
.email-list-table tbody tr.email-unread td {
    font-weight: 700;
}

.email-list-table tbody tr.email-unread .email-sender,
.email-list-table tbody tr.email-unread .email-subject {
    font-weight: 700;
}

.email-unread-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--unread-dot-color);
    margin-right: 0.5rem;
    flex-shrink: 0;
}

.email-read-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 0.5rem;
    flex-shrink: 0;
}

.email-list-table td {
    padding: 0.625rem 0.75rem;
    vertical-align: middle;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px;
}

.email-sender {
    font-size: 0.9rem;
}

.email-subject {
    font-size: 0.9rem;
    color: #333;
}

.email-subject .email-snippet {
    color: #6c757d;
    font-weight: 400;
}

.email-date {
    font-size: 0.8rem;
    color: #6c757d;
    text-align: right;
    white-space: nowrap;
}

/* Bulk action toolbar */
.bulk-actions-bar {
    display: none;
    padding: 0.5rem 0.75rem;
    background-color: #e9ecef;
    border-radius: 0.375rem;
    margin-bottom: 0.75rem;
    align-items: center;
    gap: 0.5rem;
}

.bulk-actions-bar.show {
    display: flex;
}

/* Pagination */
.email-pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    font-size: 0.85rem;
    color: #6c757d;
}


/* ===================================================================
   6. Email View
   =================================================================== */
.email-view-header {
    border-bottom: 1px solid #dee2e6;
    padding-bottom: 1rem;
    margin-bottom: 1rem;
}

.email-view-header h4 {
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.email-view-meta {
    font-size: 0.85rem;
    color: #6c757d;
}

.email-view-meta .email-from {
    font-weight: 600;
    color: #333;
}

.email-view-body {
    padding: 1rem 0;
    line-height: 1.7;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.email-view-body img {
    max-width: 100%;
    height: auto;
}

.email-attachments {
    border-top: 1px solid #dee2e6;
    padding-top: 1rem;
    margin-top: 1rem;
}

.email-attachments .attachment-item {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    margin-right: 0.5rem;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    color: #333;
    text-decoration: none;
    transition: background-color 0.15s ease;
}

.email-attachments .attachment-item:hover {
    background-color: #f8f9fa;
}

.email-view-actions {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

/* ===================================================================
   7. Compose Form
   =================================================================== */
.compose-form .form-label {
    font-weight: 600;
    font-size: 0.85rem;
}

.compose-form .recipient-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.compose-form .recipient-row label {
    min-width: 40px;
    font-weight: 600;
    font-size: 0.85rem;
    color: #6c757d;
}

.compose-form .recipient-row input {
    flex: 1;
}

.compose-form .compose-body {
    min-height: 300px;
}

.compose-form .attachment-list {
    list-style: none;
    padding: 0;
    margin: 0.5rem 0;
}

.compose-form .attachment-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.375rem 0.5rem;
    background-color: #f8f9fa;
    border-radius: 0.25rem;
    margin-bottom: 0.25rem;
    font-size: 0.85rem;
}

.compose-form .attachment-size-warning {
    color: var(--quota-full);
    font-size: 0.8rem;
    font-weight: 600;
}

/* ===================================================================
   8. Quota Usage Bar
   =================================================================== */
.quota-bar-wrapper {
    margin-top: 0.5rem;
}

.quota-bar {
    height: 6px;
    border-radius: 3px;
    background-color: #e9ecef;
    overflow: hidden;
}

.quota-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s ease, background-color 0.3s ease;
}

/* Normal — green (< 90%) */
.quota-bar-fill.quota-normal {
    background-color: var(--quota-normal);
}

/* Warning — yellow (>= 90%) */
.quota-bar-fill.quota-warning {
    background-color: var(--quota-warning);
}

/* Full — red (>= 100%) */
.quota-bar-fill.quota-full {
    background-color: var(--quota-full);
}

.quota-text {
    font-size: 0.75rem;
    color: #6c757d;
    margin-top: 0.25rem;
}

.quota-text.quota-text-warning {
    color: #856404;
    font-weight: 600;
}

.quota-text.quota-text-full {
    color: var(--quota-full);
    font-weight: 700;
}

/* Quota warning banner (shown at top of page) */
.quota-warning-banner {
    display: none;
    padding: 0.75rem 1rem;
    border-radius: 0.375rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.quota-warning-banner.show {
    display: block;
}

.quota-warning-banner.quota-banner-warning {
    background-color: #fff3cd;
    border: 1px solid #ffc107;
    color: #856404;
}

.quota-warning-banner.quota-banner-full {
    background-color: #f8d7da;
    border: 1px solid #dc3545;
    color: #842029;
}


/* ===================================================================
   9. Admin Dashboard Cards
   =================================================================== */
.admin-stat-card {
    border: 1px solid var(--admin-card-border);
    border-radius: 0.75rem;
    padding: 1.25rem;
    text-align: center;
    background-color: #fff;
    transition: box-shadow 0.15s ease;
}

.admin-stat-card:hover {
    box-shadow: 0 0.25rem 0.75rem rgba(0, 0, 0, 0.08);
}

.admin-stat-card .stat-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.admin-stat-card .stat-icon.text-primary { color: #0d6efd; }
.admin-stat-card .stat-icon.text-success { color: #198754; }
.admin-stat-card .stat-icon.text-warning { color: #ffc107; }
.admin-stat-card .stat-icon.text-danger  { color: #dc3545; }

.admin-stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.2;
}

.admin-stat-card .stat-label {
    font-size: 0.8rem;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 0.25rem;
}

/* Admin sidebar */
.admin-sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background-color: #212529;
    color: #fff;
    overflow-y: auto;
    padding: 1rem 0;
}

.admin-sidebar .sidebar-brand {
    padding: 0.5rem 1.25rem 1.25rem;
    font-weight: 700;
    font-size: 1.1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 0.5rem;
}

.admin-sidebar .nav-link {
    color: rgba(255, 255, 255, 0.7);
    padding: 0.5rem 1.25rem;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: color 0.15s ease, background-color 0.15s ease;
}

.admin-sidebar .nav-link:hover {
    color: #fff;
    background-color: rgba(255, 255, 255, 0.1);
}

.admin-sidebar .nav-link.active {
    color: #fff;
    background-color: rgba(255, 255, 255, 0.15);
    font-weight: 600;
}

.admin-sidebar .nav-divider {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    margin: 0.5rem 0;
}

/* ===================================================================
   10. Activity Log Table
   =================================================================== */
.activity-log-table {
    font-size: 0.85rem;
}

.activity-log-table thead th {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: #6c757d;
    font-weight: 600;
    border-bottom: 2px solid #dee2e6;
    white-space: nowrap;
}

.activity-log-table td {
    vertical-align: middle;
    padding: 0.5rem 0.75rem;
}

.activity-log-table .log-action {
    font-weight: 600;
}

.activity-log-table .log-action.log-action-login       { color: #198754; }
.activity-log-table .log-action.log-action-logout       { color: #6c757d; }
.activity-log-table .log-action.log-action-login_failed { color: #dc3545; }
.activity-log-table .log-action.log-action-account_created   { color: #0d6efd; }
.activity-log-table .log-action.log-action-account_deleted   { color: #dc3545; }
.activity-log-table .log-action.log-action-password_reset    { color: #ffc107; }
.activity-log-table .log-action.log-action-bulk_create       { color: #0d6efd; }

.activity-log-table .log-details {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.activity-log-table .log-ip {
    font-family: monospace;
    font-size: 0.8rem;
    color: #6c757d;
}

/* Log filter bar */
.log-filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
    align-items: flex-end;
}

.log-filter-bar .form-group {
    display: flex;
    flex-direction: column;
}

.log-filter-bar .form-group label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #6c757d;
    margin-bottom: 0.25rem;
}

/* ===================================================================
   11. Notification Toast
   =================================================================== */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1080;
}

/* ===================================================================
   12. Miscellaneous
   =================================================================== */

/* Search bar in navbar */
.navbar-search {
    max-width: 400px;
}

/* Account management action buttons */
.account-actions .btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
}

/* Bulk create dynamic rows */
.bulk-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.5rem;
}

.bulk-row .form-control {
    flex: 1;
}

/* Settings tabs */
.settings-tabs .nav-link {
    font-weight: 600;
    font-size: 0.9rem;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #6c757d;
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    display: block;
}

.empty-state p {
    font-size: 1rem;
}

/* Loading spinner overlay */
.loading-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background-color: rgba(255, 255, 255, 0.7);
    z-index: 1070;
    align-items: center;
    justify-content: center;
}

.loading-overlay.show {
    display: flex;
}

/* ===================================================================
   13. Responsive Adjustments
   =================================================================== */

/* Tablet (< 992px) */
@media (max-width: 991.98px) {
    :root {
        --sidebar-width: 200px;
    }

    .main-content {
        padding: 1rem;
    }

    .email-list-table td {
        max-width: 200px;
    }

    .login-card {
        max-width: 380px;
    }
}

/* Mobile (< 768px) */
@media (max-width: 767.98px) {
    .page-wrapper {
        flex-direction: column;
    }

    .sidebar,
    .admin-sidebar {
        width: 100%;
        min-width: 100%;
        border-right: none;
        border-bottom: 1px solid #dee2e6;
        padding: 0.5rem 0;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
    }

    .sidebar .nav-link,
    .admin-sidebar .nav-link {
        white-space: nowrap;
        border-radius: 1.5rem;
        margin-right: 0;
        padding: 0.375rem 0.75rem;
        font-size: 0.8rem;
    }

    .sidebar .compose-btn {
        margin: 0 0.5rem;
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }

    .sidebar-quota {
        display: none;
    }

    .admin-sidebar .sidebar-brand {
        padding: 0.5rem 1rem;
        border-bottom: none;
        margin-bottom: 0;
    }

    .main-content {
        padding: 0.75rem;
    }

    .email-list-table td {
        max-width: 150px;
        font-size: 0.85rem;
    }

    .email-date {
        display: none;
    }

    .email-view-actions {
        flex-wrap: wrap;
    }

    .compose-form .compose-body {
        min-height: 200px;
    }

    .log-filter-bar {
        flex-direction: column;
    }

    .navbar-search {
        max-width: 100%;
    }

    .admin-stat-card {
        margin-bottom: 0.75rem;
    }

    .admin-stat-card .stat-value {
        font-size: 1.5rem;
    }

    .bulk-actions-bar {
        flex-wrap: wrap;
    }
}

/* Small mobile (< 576px) */
@media (max-width: 575.98px) {
    .login-card .card-body {
        padding: 1.5rem;
    }

    .email-list-table .email-checkbox-col {
        display: none;
    }
}