/**
 * Webmail Client - Main Stylesheet
 */

/* CSS Variables (defaults, overridden by branding) */
:root {
    --primary-color: #2563eb;
    --secondary-color: #3b82f6;
    --header-bg-color: #1e40af;
    --footer-bg-color: #1e3a8a;
    --font-color: #ffffff;
    --body-bg-color: #f1f5f9;

    /* Additional variables */
    --text-color: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --card-bg: #ffffff;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;

    --sidebar-width: 240px;
    --header-height: 60px;
    --message-list-width: 380px;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    --radius-sm: 4px;
    --radius: 8px;
    --radius-lg: 12px;

    --transition: 150ms ease;
}

/* Reset */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 0.9375rem;
    line-height: 1.5;
    color: var(--text-color);
    background-color: var(--body-bg-color);
}

a {
    color: var(--primary-color);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

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

button, input, select, textarea {
    font-family: inherit;
    font-size: inherit;
}

/* Icons */
.icon {
    width: 1.25rem;
    height: 1.25rem;
    flex-shrink: 0;
}

.icon-large {
    width: 4rem;
    height: 4rem;
    stroke: var(--text-muted);
}

.hidden {
    display: none !important;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn:hover {
    text-decoration: none;
}

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

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

.btn-secondary {
    background-color: var(--border-color);
    color: var(--text-color);
}

.btn-secondary:hover {
    background-color: #cbd5e1;
}

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

.btn-danger:hover {
    background-color: #dc2626;
}

.btn-block {
    width: 100%;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--radius);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
}

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

/* Forms */
.form-group {
    margin-bottom: 1.25rem;
}

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

.form-group small {
    display: block;
    margin-top: 0.25rem;
    color: var(--text-muted);
    font-size: 0.8125rem;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="file"],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background-color: #fff;
    transition: all var(--transition);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgb(37 99 235 / 0.1);
}

.form-group textarea {
    resize: vertical;
    min-height: 100px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

@media (max-width: 640px) {
    .form-row {
        grid-template-columns: 1fr;
    }
}

.input-with-icon {
    position: relative;
}

.input-with-icon .icon {
    position: absolute;
    left: 0.875rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.input-with-icon input {
    padding-left: 2.75rem;
}

.input-with-icon .toggle-password {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    width: 2rem;
    height: 2rem;
    padding: 0;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
}

.input-with-icon .toggle-password:hover {
    color: var(--text-color);
}

/* Checkbox */
.checkbox-group {
    margin-bottom: 1.25rem;
}

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
}

.checkbox-label input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.checkbox-label .checkmark {
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: #fff;
    position: relative;
    transition: all var(--transition);
}

.checkbox-label input:checked + .checkmark {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

.checkbox-label .checkmark::after {
    content: '';
    position: absolute;
    left: 5px;
    top: 2px;
    width: 5px;
    height: 9px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    opacity: 0;
    transition: opacity var(--transition);
}

.checkbox-label input:checked + .checkmark::after {
    opacity: 1;
}

/* Alerts */
.alert {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    margin-bottom: 1.25rem;
    border-radius: var(--radius);
}

.alert-error {
    background-color: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert-success {
    background-color: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

/* =====================================================
   LOGIN PAGE
   ===================================================== */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: linear-gradient(135deg, var(--header-bg-color) 0%, var(--primary-color) 100%);
}

.login-container {
    width: 100%;
    max-width: 420px;
}

.login-box {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem;
}

.login-logo-container {
    text-align: center;
    margin-bottom: 1.5rem;
}

.login-logo-container .login-logo {
    max-height: 80px;
    width: auto;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.login-instructions {
    text-align: center;
    margin-bottom: 1.5rem;
}

.login-instructions h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 0.5rem;
}

.login-instructions p {
    color: var(--text-muted);
    font-size: 0.9375rem;
}

.remember-group {
    margin-bottom: 1.25rem;
}

.remember-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.9375rem;
    color: var(--text-color);
}

.remember-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary-color);
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-logo {
    max-height: 60px;
    width: auto;
}

.login-title {
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--text-color);
}

.login-subtitle {
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.login-form .btn {
    margin-top: 0.5rem;
}

.login-footer {
    text-align: center;
    margin-top: 2rem;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.875rem;
}

/* =====================================================
   WEBMAIL INTERFACE
   ===================================================== */

.webmail-page {
    height: 100vh;
    overflow: hidden;
}

.webmail-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Header */
.webmail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 1rem;
    background-color: var(--header-bg-color);
    color: var(--font-color);
    box-shadow: var(--shadow);
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-logo {
    height: 32px;
    width: auto;
}

.header-title {
    font-size: 1.25rem;
    font-weight: 600;
}

.mobile-menu-toggle {
    display: none;
    color: var(--font-color);
}

.header-center {
    flex: 1;
    max-width: 480px;
    margin: 0 1.5rem;
}

.search-box {
    position: relative;
}

.search-box .icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.search-box input {
    width: 100%;
    padding: 0.5rem 1rem 0.5rem 2.5rem;
    border: none;
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.1);
    color: var(--font-color);
    transition: all var(--transition);
}

.search-box input::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

.search-box input:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.2);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-right .btn-icon {
    color: var(--font-color);
}

.header-right .btn-icon:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--font-color);
}

.user-email {
    font-size: 0.875rem;
    opacity: 0.9;
    margin-right: 0.5rem;
}

/* Main Content */
.webmail-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--card-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 1rem;
    overflow-y: auto;
}

.btn-compose {
    margin-bottom: 1rem;
}

.folder-list {
    flex: 1;
}

.folder-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.875rem;
    border-radius: var(--radius);
    color: var(--text-color);
    cursor: pointer;
    transition: all var(--transition);
}

.folder-item:hover {
    background-color: var(--border-color);
    text-decoration: none;
}

.folder-item.active {
    background-color: var(--primary-color);
    color: #fff;
}

.folder-item .icon {
    color: var(--text-muted);
}

.folder-item.active .icon {
    color: #fff;
}

.folder-name {
    flex: 1;
    font-weight: 500;
}

.folder-count {
    font-size: 0.75rem;
    background: var(--border-color);
    padding: 0.125rem 0.5rem;
    border-radius: 999px;
}

.folder-item.active .folder-count {
    background: rgba(255, 255, 255, 0.2);
}

/* Message List */
.message-list-container {
    width: var(--message-list-width);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    background: var(--card-bg);
}

.message-list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

.message-list-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.message-list-actions .select-all {
    margin-right: 0.5rem;
}

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

.message-list-info {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.message-list {
    flex: 1;
    overflow-y: auto;
}

.message-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background-color var(--transition);
}

.message-item:hover {
    background-color: #f8fafc;
}

.message-item.active {
    background-color: #eff6ff;
}

.message-item.unread {
    background-color: #fefce8;
}

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

.message-checkbox {
    flex-shrink: 0;
    margin-top: 0.125rem;
}

.message-content {
    flex: 1;
    min-width: 0;
}

.message-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.message-from {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-date {
    font-size: 0.75rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

.message-subject {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.25rem;
}

.message-preview {
    font-size: 0.8125rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-indicators {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    margin-left: auto;
}

.message-indicators .icon {
    width: 1rem;
    height: 1rem;
    color: var(--text-muted);
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    padding: 0.75rem;
    border-top: 1px solid var(--border-color);
}

.pagination button {
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--border-color);
    background: #fff;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}

.pagination button:hover:not(:disabled) {
    background: var(--border-color);
}

.pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination button.active {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}

/* Message View */
.message-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--card-bg);
    overflow: hidden;
}

.message-view-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

.message-view-empty p {
    margin-top: 1rem;
}

.message-view-header {
    padding: 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.message-view-subject {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.message-view-meta {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
}

.message-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--primary-color);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.message-view-info {
    flex: 1;
}

.message-view-from {
    font-weight: 600;
}

.message-view-to {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.message-view-date {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.message-view-actions {
    display: flex;
    gap: 0.5rem;
}

.message-view-body {
    flex: 1;
    padding: 1.25rem;
    overflow-y: auto;
}

.message-view-body iframe {
    width: 100%;
    border: none;
    min-height: 300px;
}

.message-attachments {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-color);
    background: #f8fafc;
}

.message-attachments h4 {
    font-size: 0.875rem;
    margin-bottom: 0.75rem;
    color: var(--text-muted);
}

.attachment-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.attachment-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 0.875rem;
    text-decoration: none;
    color: var(--text-color);
    transition: all var(--transition);
}

.attachment-item:hover {
    border-color: var(--primary-color);
    text-decoration: none;
}

.attachment-item .icon {
    color: var(--primary-color);
}

.attachment-size {
    color: var(--text-muted);
    font-size: 0.75rem;
}

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

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

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

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition);
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-small {
    width: 100%;
    max-width: 400px;
}

.modal-large {
    width: 100%;
    max-width: 700px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
}

.modal-body {
    padding: 1.25rem;
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-color);
}

/* File Upload */
.file-upload {
    position: relative;
}

.file-upload input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.file-upload-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    color: var(--text-muted);
    transition: all var(--transition);
}

.file-upload:hover .file-upload-label {
    border-color: var(--primary-color);
    background: #eff6ff;
}

.file-upload-label .icon {
    margin-bottom: 0.5rem;
}

.file-list {
    margin-top: 0.75rem;
}

.file-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    background: #f8fafc;
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
}

.file-list-item .file-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-list-item .file-size {
    color: var(--text-muted);
    font-size: 0.8125rem;
    margin: 0 0.5rem;
}

.file-list-item .remove-file {
    color: var(--danger-color);
    cursor: pointer;
}

/* Toast */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
}

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

.toast-success {
    border-left: 4px solid var(--success-color);
}

.toast-error {
    border-left: 4px solid var(--danger-color);
}

.toast-success .icon {
    color: var(--success-color);
}

.toast-error .icon {
    color: var(--danger-color);
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    text-align: center;
    color: var(--text-muted);
}

.empty-state h3 {
    margin: 1rem 0 0.5rem;
    color: var(--text-color);
}

.empty-state p {
    margin-bottom: 1.5rem;
}

/* Badge */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 999px;
}

.badge-success {
    background: #dcfce7;
    color: #166534;
}

.badge-secondary {
    background: var(--border-color);
    color: var(--text-muted);
}

/* Responsive */
@media (max-width: 1024px) {
    .user-email {
        display: none;
    }

    .message-list-container {
        width: 320px;
    }
}

@media (max-width: 768px) {
    :root {
        --sidebar-width: 100%;
        --message-list-width: 100%;
    }

    .mobile-menu-toggle {
        display: flex;
    }

    .header-center {
        display: none;
    }

    .sidebar {
        position: fixed;
        top: var(--header-height);
        left: 0;
        bottom: 0;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform var(--transition);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .webmail-content {
        flex-direction: column;
    }

    .message-list-container {
        flex: 1;
        border-right: none;
    }

    .message-view {
        position: fixed;
        inset: 0;
        top: var(--header-height);
        z-index: 40;
        transform: translateX(100%);
        transition: transform var(--transition);
    }

    .message-view.open {
        transform: translateX(0);
    }
}
