/* Material Design 3 - Testmail WebViewer */
:root {
    --md-sys-color-primary: #3F51B5;
    --md-sys-color-on-primary: #FFFFFF;
    --md-sys-color-primary-container: #E8EAF6;
    --md-sys-color-on-primary-container: #1A237E;
    --md-sys-color-surface: #FFFFFF;
    --md-sys-color-on-surface: #1C1B1F;
    --md-sys-color-surface-variant: #F4F4F5;
    --md-sys-color-outline: #79747E;
    --md-sys-color-outline-variant: #CAC4D0;
    --md-sys-color-background: #F0F2F5;
    --md-sys-color-error: #B3261E;
    --md-sys-color-success: #2E7D32;
    --md-sys-color-detail-bg: #FAFAFA;
    --md-sys-color-card-bg: #FFFFFF;
    --md-sys-color-card-border: #E0E0E0;
    --md-sys-color-text-primary: #202124;
    --md-sys-color-text-secondary: #3C4043;
    --md-sys-color-text-tertiary: #555;
    --font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
    --elevation-1: 0px 1px 3px rgba(0, 0, 0, 0.08), 0px 1px 2px rgba(0, 0, 0, 0.12);
    --elevation-2: 0px 4px 6px -2px rgba(0, 0, 0, 0.05), 0px 10px 15px -3px rgba(0, 0, 0, 0.1);
    --elevation-3: 0px 10px 20px rgba(0, 0, 0, 0.15);
}

/* Dark Mode */
@media (prefers-color-scheme: dark) {
    :root {
        --md-sys-color-primary: #7986CB;
        --md-sys-color-on-primary: #FFFFFF;
        --md-sys-color-primary-container: #303F9F;
        --md-sys-color-on-primary-container: #C5CAE9;
        --md-sys-color-surface: #1E1E1E;
        --md-sys-color-on-surface: #E0E0E0;
        --md-sys-color-surface-variant: #2D2D2D;
        --md-sys-color-outline: #9E9E9E;
        --md-sys-color-outline-variant: #424242;
        --md-sys-color-background: #121212;
        --md-sys-color-error: #CF6679;
        --md-sys-color-success: #81C784;
        --md-sys-color-detail-bg: #252525;
        --md-sys-color-card-bg: #2D2D2D;
        --md-sys-color-card-border: #424242;
        --md-sys-color-text-primary: #E0E0E0;
        --md-sys-color-text-secondary: #BDBDBD;
        --md-sys-color-text-tertiary: #9E9E9E;
        --elevation-1: 0px 1px 3px rgba(0, 0, 0, 0.3), 0px 1px 2px rgba(0, 0, 0, 0.4);
        --elevation-2: 0px 4px 6px -2px rgba(0, 0, 0, 0.3), 0px 10px 15px -3px rgba(0, 0, 0, 0.4);
        --elevation-3: 0px 10px 20px rgba(0, 0, 0, 0.5);
    }

    .app-bar {
        background-color: #1a1a2e;
    }

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

    .btn-primary:hover {
        background-color: #5C6BC0;
    }

    .email-summary:hover {
        background-color: rgba(121, 134, 203, 0.08);
    }

    .email-summary:active {
        background-color: rgba(121, 134, 203, 0.15);
    }

    .btn-text:hover {
        background-color: rgba(121, 134, 203, 0.15);
    }

    #snackbar {
        background-color: #424242;
    }

    iframe {
        background: var(--md-sys-color-card-bg);
    }
}

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

body {
    font-family: var(--font-family);
    background-color: var(--md-sys-color-background);
    color: var(--md-sys-color-on-surface);
    min-height: 100vh;
    padding: 20px;
}

/* Main Container */
.main-container {
    max-width: 1200px;
    margin: 0 auto;
    background: var(--md-sys-color-surface);
    border-radius: 16px;
    box-shadow: var(--elevation-2);
    overflow: hidden;
}

/* 宽屏适配 */
@media (min-width: 1400px) {
    .main-container {
        max-width: 1400px;
    }
}

@media (min-width: 1800px) {
    .main-container {
        max-width: 1600px;
    }
}

/* App Bar */
.app-bar {
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    padding: 20px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 4px 5px rgba(0, 0, 0, 0.14);
}

.app-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.app-title h1 {
    font-size: 22px;
    font-weight: 500;
    margin: 0;
}

.stats-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.help-link,
.github-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    transition: background-color 0.2s ease;
    cursor: pointer;
}

.help-link:hover,
.github-link:hover {
    background-color: rgba(255, 255, 255, 0.15);
}

.icon-help,
.icon-github {
    width: 22px;
    height: 22px;
    fill: var(--md-sys-color-on-primary);
}

.chip {
    background: rgba(255, 255, 255, 0.2);
    padding: 6px 14px;
    border-radius: 16px;
    font-size: 13px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Icons */
.icon {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.icon-sm {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.icon-hero {
    width: 28px;
    height: 28px;
    fill: currentColor;
}

/* Config Card */
.config-card {
    padding: 20px 24px;
    border-bottom: 1px solid var(--md-sys-color-surface-variant);
}

.config-header {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--md-sys-color-on-surface);
    font-weight: 500;
    font-size: 15px;
    margin-bottom: 16px;
}

.config-header .icon {
    color: var(--md-sys-color-primary);
}

.config-form {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
}

.form-group {
    flex: 1;
    min-width: 180px;
}

.form-group label {
    display: block;
    font-size: 12px;
    color: var(--md-sys-color-outline);
    margin-bottom: 6px;
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 8px;
    font-size: 14px;
    font-family: var(--font-family);
    background: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--md-sys-color-primary);
    box-shadow: 0 0 0 2px rgba(63, 81, 181, 0.15);
}

.form-group input::placeholder {
    color: var(--md-sys-color-outline);
}

.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    border: none;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    font-family: var(--font-family);
    cursor: pointer;
    transition: background-color 0.2s, box-shadow 0.2s, transform 0.1s;
    white-space: nowrap;
}

.btn-primary:hover {
    background-color: #303F9F;
    box-shadow: var(--elevation-1);
}

.btn-primary:active {
    transform: scale(0.98);
}

/* Email List */
.email-list-container {
    background: var(--md-sys-color-surface);
}

.email-list {
    min-height: 200px;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--md-sys-color-outline);
}

.empty-icon {
    width: 64px;
    height: 64px;
    fill: var(--md-sys-color-outline-variant);
    margin-bottom: 16px;
}

.empty-state p {
    font-size: 15px;
}

/* Email Item */
.email-item {
    border-bottom: 1px solid var(--md-sys-color-surface-variant);
    transition: background-color 0.2s;
}

.email-item:last-child {
    border-bottom: none;
}

.email-summary {
    padding: 16px 24px;
    cursor: pointer;
    display: grid;
    grid-template-columns: 44px 1fr auto;
    gap: 14px;
    align-items: center;
    user-select: none;
}

.email-summary:hover {
    background-color: rgba(63, 81, 181, 0.04);
}

.email-summary:active {
    background-color: rgba(63, 81, 181, 0.08);
}

.avatar {
    width: 40px;
    height: 40px;
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 15px;
    flex-shrink: 0;
}

.content-col {
    min-width: 0;
}

.sender-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 4px;
}

.sender-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--md-sys-color-text-primary);
}

.sender-email {
    font-size: 12px;
    color: var(--md-sys-color-outline);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.subject-text {
    font-size: 14px;
    font-weight: 500;
    color: var(--md-sys-color-text-secondary);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.preview-text {
    font-size: 13px;
    color: var(--md-sys-color-outline);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.meta-col {
    text-align: right;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    flex-shrink: 0;
}

.date-badge {
    font-size: 12px;
    color: var(--md-sys-color-outline);
    font-weight: 500;
}

.tag-badge {
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
}

.chevron {
    color: var(--md-sys-color-outline);
    transition: transform 0.3s;
    width: 20px;
    height: 20px;
}

.email-item.active .chevron {
    transform: rotate(180deg);
    color: var(--md-sys-color-primary);
}

/* Email Detail */
.email-detail-container {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.35s cubic-bezier(0.4, 0.0, 0.2, 1);
    background-color: var(--md-sys-color-detail-bg);
}

.email-detail-inner {
    padding: 0 24px 24px 24px;
}

.info-card {
    background: var(--md-sys-color-card-bg);
    border: 1px solid var(--md-sys-color-card-border);
    border-radius: 8px;
    padding: 16px 20px;
    margin: 16px 0;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px 32px;
}

@media (min-width: 900px) {
    .info-card {
        grid-template-columns: repeat(4, 1fr);
    }

    .info-item.full-width {
        grid-column: span 2;
    }
}

.info-item {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.info-item.full-width {
    grid-column: 1 / -1;
}

.info-label {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--md-sys-color-outline);
    margin-bottom: 6px;
    font-weight: 500;
}

.info-value {
    font-size: 13px;
    color: var(--md-sys-color-text-secondary);
    word-break: break-word;
    overflow-wrap: break-word;
    line-height: 1.4;
}

.action-bar {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-bottom: 12px;
}

.btn-text {
    background: none;
    border: none;
    color: var(--md-sys-color-primary);
    font-family: var(--font-family);
    font-weight: 500;
    font-size: 13px;
    padding: 8px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.btn-text:hover {
    background-color: rgba(63, 81, 181, 0.08);
}

.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
    background: var(--md-sys-color-surface-variant);
    border-radius: 8px;
    padding: 4px;
}

.tab-btn {
    flex: 1;
    padding: 8px 16px;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font-family);
    color: var(--md-sys-color-outline);
    transition: all 0.2s;
}

.tab-btn:hover {
    color: var(--md-sys-color-on-surface);
}

.tab-btn.active {
    background: var(--md-sys-color-surface);
    color: var(--md-sys-color-primary);
    box-shadow: var(--elevation-1);
}

.iframe-wrapper {
    background: var(--md-sys-color-card-bg);
    border-radius: 8px;
    border: 1px solid var(--md-sys-color-card-border);
    overflow: hidden;
}

iframe {
    width: 100%;
    border: none;
    min-height: 350px;
    display: block;
}

.text-content {
    background: var(--md-sys-color-card-bg);
    border-radius: 8px;
    border: 1px solid var(--md-sys-color-card-border);
    padding: 16px;
    font-size: 14px;
    line-height: 1.6;
    color: var(--md-sys-color-text-secondary);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 400px;
    overflow-y: auto;
}

/* Attachments */
.attachments-section {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--md-sys-color-card-border);
}

.attachments-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--md-sys-color-on-surface);
    margin-bottom: 10px;
}

.attachment-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--md-sys-color-surface-variant);
    border-radius: 6px;
    margin-right: 8px;
    margin-bottom: 8px;
    font-size: 13px;
    color: var(--md-sys-color-text-tertiary);
}

/* Footer */
.app-footer {
    padding: 16px 24px;
    text-align: center;
    font-size: 13px;
    color: var(--md-sys-color-outline);
    border-top: 1px solid var(--md-sys-color-outline-variant);
    background: var(--md-sys-color-surface-variant);
}

.app-footer a {
    color: var(--md-sys-color-primary);
    text-decoration: none;
    font-weight: 500;
    margin-left: 4px;
}

.app-footer a:hover {
    text-decoration: underline;
}

/* Loading */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading.hidden {
    display: none;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: var(--md-sys-color-on-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading p {
    color: white;
    margin-top: 16px;
    font-size: 15px;
}

/* Snackbar */
#snackbar {
    visibility: hidden;
    min-width: 280px;
    background-color: #323232;
    color: #fff;
    text-align: center;
    border-radius: 8px;
    padding: 14px 24px;
    position: fixed;
    z-index: 1001;
    left: 50%;
    bottom: 30px;
    transform: translateX(-50%);
    font-size: 14px;
    opacity: 0;
    transition: opacity 0.3s, bottom 0.3s;
    box-shadow: var(--elevation-3);
}

#snackbar.show {
    visibility: visible;
    opacity: 1;
    bottom: 40px;
}

#snackbar.error {
    background-color: var(--md-sys-color-error);
}

#snackbar.success {
    background-color: var(--md-sys-color-success);
}

/* Error State */
.error-state {
    padding: 40px 24px;
    text-align: center;
    color: var(--md-sys-color-error);
}

.error-state p {
    font-size: 14px;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--md-sys-color-outline-variant);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--md-sys-color-outline);
}

/* Responsive */
@media (max-width: 600px) {
    body {
        padding: 0;
    }

    .main-container {
        border-radius: 0;
    }

    .app-bar {
        padding: 16px;
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .app-title h1 {
        font-size: 18px;
    }

    .config-card {
        padding: 16px;
    }

    .config-form {
        flex-direction: column;
    }

    .form-group {
        width: 100%;
    }

    .btn-primary {
        width: 100%;
        justify-content: center;
    }

    .email-summary {
        grid-template-columns: 1fr auto;
        padding: 14px 16px;
    }

    .avatar {
        display: none;
    }

    .sender-email {
        display: none;
    }

    .email-detail-inner {
        padding: 0 16px 16px 16px;
    }

    .info-card {
        grid-template-columns: 1fr;
    }

    /* Allow text wrapping on mobile */
    .subject-text, .preview-text {
        white-space: normal;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }
    
    .app-title h1 {
        white-space: normal;
        overflow-wrap: break-word;
    }
}
