/**
 * 邮件系统样式表 - QQ邮箱风格
 */

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

/* 邮件查看页底部统一容器，锚定在正文容器内 */
.mail-view-footer {
    clear: both;
    position: relative;
    float: none;
    width: 100%;
    margin-left: 0;
    padding-top: 10px;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Microsoft YaHei', 'Helvetica Neue', Arial, sans-serif;
    background: #f5f5f5;
    color: #333;
    display: flex;
    flex-direction: column;
}

/* 顶部导航栏 */
.top-header {
    background: #2d2d2d;
    height: 60px;
    display: flex;
    align-items: center;
    padding: 0 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    flex-shrink: 0;
    z-index: 100;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 10px;
    color: white;
    font-size: 18px;
    font-weight: 500;
}

.logo-section .logo-text {
    font-size: 20px;
}

.logo-section .logo-subtitle {
    font-size: 12px;
    color: #aaa;
    margin-left: 5px;
}

.menu-toggle {
    display: none;
    width: 36px;
    height: 36px;
    border: 1px solid #555;
    background: #404040;
    color: #fff;
    border-radius: 4px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
}
.menu-toggle:hover { background: #4a4a4a; }
.search-bar {
    flex: 1;
    max-width: 500px;
    margin: 0 30px;
    position: relative;
}

.search-bar input {
    width: 100%;
    padding: 8px 35px 8px 12px;
    border: none;
    border-radius: 4px;
    background: #404040;
    color: white;
    font-size: 14px;
}

.search-bar input::placeholder {
    color: #999;
}

.search-bar::before {
    content: '🔍';
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: #999;
}

.user-section {
    display: flex;
    align-items: center;
    gap: 15px;
    color: white;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #555;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
}

.user-email {
    font-size: 14px;
}

.user-badge {
    background: #555;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
}

.logout-link {
    color: #fff;
    background: #ff4d4f;
    border: 1px solid #ff7875;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    text-decoration: none;
    font-weight: 600;
    transition: background 0.2s, box-shadow 0.2s;
}

.logout-link:hover {
    background: #ff7875;
    box-shadow: 0 0 0 3px rgba(255, 77, 79, 0.2);
}

/* 主容器 */
.main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    height: calc(100vh - 60px);
    min-height: 0;
}

/* 左侧边栏 */
.sidebar {
    width: 200px;
    background: #2d2d2d;
    border-right: 1px solid #1a1a1a;
    padding: 15px 0;
    overflow-y: auto;
    color: white;
    flex-shrink: 0;
}

.sidebar-backdrop { display: none; }

.compose-btn {
    margin: 0 15px 20px 15px;
    background: #4a90e2;
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    width: calc(100% - 30px);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
    transition: background 0.2s;
}

.compose-btn:hover {
    background: #5ba0f2;
}

.compose-btn::before {
    content: '✉️';
    font-size: 16px;
}

.folder-list {
    list-style: none;
}

.folder-item {
    padding: 10px 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    color: #e0e0e0;
    transition: background 0.2s;
    text-decoration: none;
    width: 100%;
    box-sizing: border-box;
}

.folder-item:hover {
    background: #3a3a3a;
}

.folder-item.active {
    background: #404040;
    color: white;
    font-weight: 500;
}

.folder-list li {
    list-style: none;
}

.folder-item .folder-name {
    display: flex;
    align-items: center;
    gap: 8px;
}

.folder-item .folder-count {
    color: #aaa;
    font-size: 12px;
}

.folder-divider {
    height: 1px;
    background: #404040;
    margin: 10px 0;
}

/* 主内容区 */
.main-content {
    flex: 1;
    background: white;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    min-width: 0;
}

/* 工具栏 */
.toolbar {
    padding: 15px 20px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    gap: 15px;
    background: #fafafa;
}

.toolbar-checkbox {
    margin-right: 10px;
}

.toolbar-title {
    font-size: 14px;
    font-weight: 500;
    margin-right: auto;
}

.toolbar-sync-btn {
    font-weight: 500;
    color: #1890ff;
    border-color: #91d5ff;
    background: #e6f7ff;
}

.toolbar-sync-btn:hover {
    border-color: #40a9ff;
    background: #bae7ff;
}

.toolbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: nowrap;
}

.toolbar-inline-form {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    white-space: nowrap;
}

.toolbar-inline-form select {
    min-width: 120px;
}

.toolbar-btn {
    padding: 6px 12px;
    border: 1px solid #d9d9d9;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: all 0.2s;
}

.toolbar-btn:hover {
    background: #f5f5f5;
    border-color: #40a9ff;
}

.toolbar-btn::before {
    font-size: 14px;
}

.toolbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
}

.toolbar-info {
    font-size: 13px;
    color: #666;
}

.toolbar-select {
    padding: 4px 8px;
    border: 1px solid #d9d9d9;
    border-radius: 4px;
    font-size: 13px;
    background: white;
    cursor: pointer;
}

.toolbar-select:hover {
    border-color: #40a9ff;
}

.pagination {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.pagination-btn {
    padding: 4px 10px;
    border: 1px solid #d9d9d9;
    border-radius: 4px;
    background: white;
    color: #333;
    text-decoration: none;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.pagination-btn:hover {
    background: #f5f5f5;
    border-color: #40a9ff;
    color: #1890ff;
}

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

.toolbar-btn:disabled:hover {
    background: white;
    border-color: #d9d9d9;
}

.sync-status {
    min-height: 24px;
    padding: 0 20px 10px 20px;
    font-size: 13px;
    color: #666;
}

.sync-status.success {
    color: #389e0d;
}

.sync-status.error {
    color: #cf1322;
}

/* 邮件列表 */
.mail-list-container {
    flex: 1;
    overflow-y: auto;
}

.mail-list-table {
    width: 100%;
    border-collapse: collapse;
}

.mail-list-table thead {
    background: #fafafa;
    position: sticky;
    top: 0;
    z-index: 10;
}

.mail-list-table th {
    padding: 12px 20px;
    text-align: left;
    font-weight: 500;
    font-size: 13px;
    color: #666;
    border-bottom: 1px solid #e0e0e0;
}

.mail-list-table td {
    padding: 12px 20px;
    border-bottom: 1px solid #f0f0f0;
    font-size: 14px;
}

.mail-list-table tbody tr {
    cursor: pointer;
    transition: background 0.2s;
}

.mail-list-table tbody tr:hover {
    background: #f5f5f5;
}

.mail-list-table tbody tr.unread {
    background: #f0f7ff;
    font-weight: 500;
}

.mail-list-table tbody tr.unread:hover {
    background: #e6f4ff;
}

.mail-list-table .mail-checkbox {
    width: 40px;
    text-align: center;
}

.mail-list-table .mail-from {
    width: 200px;
    color: #333;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mail-list-table .mail-subject {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mail-list-table .mail-subject a {
    color: #333;
    text-decoration: none;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mail-list-table .mail-subject a:hover {
    color: #1890ff;
}

.mail-list-table .mail-date {
    width: 150px;
    color: #999;
    font-size: 13px;
    text-align: right;
}

.mail-list-table .mail-size {
    width: 80px;
    color: #999;
    font-size: 13px;
    text-align: right;
}

/* 空状态 */
.empty-state {
    text-align: center;
    padding: 100px 20px;
    color: #999;
}

.empty-state-icon {
    font-size: 64px;
    margin-bottom: 20px;
    opacity: 0.3;
}

.empty-state-title {
    font-size: 16px;
    color: #333;
    margin-bottom: 8px;
}

.empty-state-desc {
    font-size: 13px;
    color: #999;
    margin-bottom: 20px;
}

.folder-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    background: white;
}

.primary-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 20px;
    border-radius: 4px;
    background: #40a9ff;
    color: white;
    text-decoration: none;
    font-size: 14px;
    border: none;
    transition: background 0.2s;
}

.primary-btn:hover {
    background: #1890ff;
}

/* 邮件查看页面 */
.mail-view-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: visible;
    padding: 0;
}

.mail-view-header {
    border-bottom: 1px solid #e0e0e0;
    padding: 20px 30px;
    margin: 0;
    flex-shrink: 0;
    background: white;
}

.mail-view-title {
    font-size: 20px;
    font-weight: 500;
    margin-bottom: 15px;
    color: #333;
}

.mail-view-meta {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 14px;
    color: #666;
}

.mail-view-body {
    flex: 1;
    overflow: visible;
    padding: 30px;
    line-height: 1.8;
    font-size: 14px;
    color: #333;
    background: white;
    min-height: 0;
    display: flow-root;
    position: relative;
    isolation: isolate;
}

.mail-attachments {
    border-top: none;
    padding: 10px 0 0 0;
    background: transparent;
    clear: both;
    position: relative;
    float: none;
    width: 100%;
    margin-left: 0;
}

.mail-attachments h3 {
    font-size: 14px;
    margin-bottom: 15px;
    color: #333;
}

.attachment-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.attachment-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 10px 15px;
    background: #fafafa;
}

.attachment-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.attachment-name {
    font-weight: 500;
    color: #333;
}

.attachment-size {
    font-size: 12px;
    color: #999;
}

.attachment-download {
    border: 1px solid #40a9ff;
    color: #1890ff;
    padding: 6px 12px;
    border-radius: 4px;
    text-decoration: none;
    font-size: 13px;
    transition: all 0.2s;
}

.attachment-download:hover {
    background: #40a9ff;
    color: #fff;
}

.mail-content-html-wrapper {
    width: 100%;
    height: auto;
    display: block;
    overflow: visible;
    background: transparent;
    padding: 0;
}

.mail-content-html-wrapper * {
    max-width: 100%;
    box-sizing: border-box;
}

.mail-content-html-wrapper table {
    max-width: 100% !important;
    width: auto !important;
}

.mail-content-html-wrapper img {
    max-width: 100% !important;
    height: auto !important;
}

.mail-content-iframe {
    display: block;
    width: 100%;
    border: none;
    background: transparent;
    min-height: 200px;
}

.mail-content-html {
    max-width: 100%;
    overflow-x: auto;
    word-wrap: break-word;
    background: transparent;
    padding: 0;
}

.mail-content-html img {
    max-width: 100%;
    height: auto;
}

.mail-content-text {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: inherit;
}

.mail-content-text pre {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: inherit;
    margin: 0;
}

.mail-view-actions {
    flex-shrink: 0;
    padding: 10px 0 0 0;
    border-top: none;
    display: flex;
    gap: 10px;
    background: transparent;
    clear: both;
    position: relative;
    float: none;
    width: 100%;
    margin-left: 0;
}

/* 写邮件页面 */
.compose-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    padding: 0;
    overflow: hidden;
    flex: 1;
    min-height: 0;
}

.compose-form {
    display: flex;
    flex-direction: column;
    height: 100%;
    flex: 1;
    min-height: 0;
}

.compose-topbar {
    padding: 10px 12px;
    background: #e9ecef;
    border-bottom: 1px solid #d9d9d9;
    display: flex;
    align-items: center;
    gap: 10px;
}

.compose-attachments-bar {
    padding: 10px 12px;
    background: #f0f2f5;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.compose-footerbar {
    padding: 10px 12px;
    background: #f3f4f5;
    border-top: 1px solid #d9d9d9;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.compose-fields {
    padding: 12px;
    background: #f7f7f7;
    border-bottom: 1px solid #e0e0e0;
}

.compose-field {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.compose-field label {
    width: 60px;
    color: #666;
}

.compose-field input {
    flex: 1;
}

.compose-editor-wrapper {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: #fff;
    overflow: hidden;
}

.compose-editor-label {
    padding: 10px 12px;
    color: #666;
    background: #f7f7f7;
    border-bottom: 1px solid #e0e0e0;
}

.compose-editor {
    flex: 1;
    min-height: 0;
    padding: 0 12px 12px;
    display: flex;
    flex-direction: column;
    --toolbar-gap: 44px;
}

.editor-toolbar {
    margin: 12px 0;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.editor-toolbar button {
    padding: 6px 10px;
    border: 1px solid #d9d9d9;
    background: #fff;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
}
.editor-toolbar button:hover { background: #f5f5f5; border-color: #40a9ff; }

#html-wrapper { display: flex; flex-direction: column; flex: 1; min-height: 300px; min-width: 0; }
#html-editor {
    flex: 1;
    min-height: 0;
    border: 1px solid #ccc;
    padding: 10px;
    border-radius: 6px;
    overflow: auto;
    word-break: break-word;
    overflow-wrap: anywhere;
    contain: content;
    min-width: 0;
    position: relative;
    isolation: isolate;
}

#plain-wrapper { height: 100%; }
#plain-wrapper textarea {
    height: calc(100% - var(--toolbar-gap)) !important;
    min-height: 300px;
}

.compose-editor-wrapper,
.compose-editor,
#html-wrapper { min-width: 0; }

#html-editor * {
    max-width: 100%;
    box-sizing: border-box;
}

#html-editor table {
    max-width: 100% !important;
    width: auto !important;
    display: block;
    overflow-x: auto;
}

#html-editor img {
    max-width: 100% !important;
    height: auto !important;
}

#html-editor pre {
    white-space: pre-wrap;
    word-wrap: break-word;
}

blockquote.quoted-mail {
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.attachments-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 12px;
}

.attachments-list .file-chip {
    background: #f0f0f0;
    border: 1px solid #d9d9d9;
    border-radius: 12px;
    padding: 4px 10px;
    font-size: 12px;
}

.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    background: #fff;
    border: 1px solid #d9d9d9;
    border-radius: 4px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.08);
    display: none;
    min-width: 150px;
    z-index: 20;
}
.dropdown-menu.show { display: block; }
.dropdown-menu button {
    width: 100%;
    text-align: left;
    padding: 8px 12px;
    border: none;
    background: #fff;
    cursor: pointer;
    font-size: 13px;
}
.dropdown-menu button:hover { background: #f5f5f5; }

.schedule-panel { margin-left: 12px; display: flex; align-items: center; gap: 8px; }
.compose-actions { display: flex; gap: 8px; }

.compose-form h2 {
    margin-bottom: 25px;
    font-size: 18px;
    color: #333;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    color: #666;
    font-weight: 500;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d9d9d9;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #40a9ff;
    box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.1);
}

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

.form-actions {
    margin-top: 25px;
    display: flex;
    gap: 10px;
}

/* 按钮 */
.btn {
    padding: 8px 20px;
    border: 1px solid #d9d9d9;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-primary {
    background: #1890ff;
    color: white;
    border-color: #1890ff;
}

.btn-primary:hover {
    background: #40a9ff;
    border-color: #40a9ff;
}

.btn-secondary {
    background: white;
    color: #333;
}

.btn-secondary:hover {
    background: #f5f5f5;
    border-color: #40a9ff;
}

/* 消息提示 */
.error-message {
    background: #fff2f0;
    color: #ff4d4f;
    padding: 12px 16px;
    border-radius: 4px;
    margin-bottom: 20px;
    border: 1px solid #ffccc7;
}

.success-message {
    background: #f6ffed;
    color: #52c41a;
    padding: 12px 16px;
    border-radius: 4px;
    margin-bottom: 20px;
    border: 1px solid #b7eb8f;
}

/* 登录页面 */
.login-page {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-box {
    background: white;
    border-radius: 8px;
    padding: 40px;
    max-width: 400px;
    width: 100%;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.login-box h1 {
    text-align: center;
    margin-bottom: 30px;
    color: #333;
    font-size: 24px;
}

.server-info {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #e0e0e0;
    font-size: 12px;
    color: #999;
    text-align: center;
}

/* 响应式设计 */
@media (max-width: 1024px) {
    .menu-toggle { display: inline-flex; }
    .search-bar { display: none; }
    .user-email, .user-badge { display: none; }
    .sidebar {
        position: fixed;
        left: 0;
        top: 60px;
        height: calc(100vh - 60px);
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        z-index: 100;
        width: 240px;
        max-width: 85vw;
    }
    body.sidebar-open .sidebar { transform: translateX(0); box-shadow: 2px 0 10px rgba(0,0,0,0.3); }
    .sidebar-backdrop { display: none; }
    body.sidebar-open .sidebar-backdrop {
        display: block;
        position: fixed;
        left: 0;
        top: 60px;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.35);
        z-index: 90;
    }
    .toolbar { flex-wrap: wrap; }
    .mail-list-table { font-size: 13px; }
    .mail-list-table th, .mail-list-table td { padding: 10px 12px; }
    .mail-view-header, .mail-attachments { padding: 16px; }
    .mail-view-body { padding: 16px; }
    .mail-content-html-wrapper { padding: 12px; }
    .compose-topbar, .compose-attachments-bar, .compose-footerbar { padding: 10px 12px; }
    .compose-fields { padding: 10px 12px; }
    .compose-field { flex-direction: column; align-items: stretch; }
    .compose-field label { width: auto; margin-bottom: 6px; }
}

@media (max-width: 768px) {
    .logo-section .logo-subtitle { display: none; }
    .mail-list-table { font-size: 12px; }
    .mail-list-table th, .mail-list-table td { padding: 8px 10px; }
    .mail-view-header, .mail-attachments { padding: 12px; }
    .mail-view-body { padding: 12px; }
    .mail-content-html-wrapper { padding: 10px; }
    .sidebar { width: 220px; }
}
