/* ============================================
   Mail Viewer - Modern Glassmorphism UI
   ============================================ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-base: #0a0e27;
    --bg-deep: #050816;
    --surface: rgba(255, 255, 255, 0.04);
    --surface-hover: rgba(255, 255, 255, 0.07);
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.16);

    --text-primary: rgba(255, 255, 255, 0.95);
    --text-secondary: rgba(255, 255, 255, 0.65);
    --text-tertiary: rgba(255, 255, 255, 0.42);

    --accent: #7c3aed;
    --accent-bright: #a78bfa;
    --accent-glow: rgba(124, 58, 237, 0.5);
    --accent-soft: rgba(124, 58, 237, 0.12);

    --pink: #ec4899;
    --blue: #3b82f6;
    --cyan: #06b6d4;

    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 24px 48px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 40px var(--accent-glow);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-xl: 24px;

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', Menlo, Consolas, monospace;
}

html, body {
    height: 100%;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ============ 动态背景 ============ */
.bg-wrapper {
    position: fixed;
    inset: 0;
    z-index: -1;
    overflow: hidden;
    background:
        radial-gradient(ellipse at top, #1a1a3e 0%, var(--bg-base) 50%, var(--bg-deep) 100%);
}

.bg-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.5;
    animation: float 20s ease-in-out infinite;
}

.orb-1 {
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, var(--accent) 0%, transparent 70%);
    top: -10%;
    left: -10%;
}

.orb-2 {
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, var(--pink) 0%, transparent 70%);
    bottom: -10%;
    right: -10%;
    animation-delay: -7s;
}

.orb-3 {
    width: 350px;
    height: 350px;
    background: radial-gradient(circle, var(--cyan) 0%, transparent 70%);
    top: 50%;
    left: 60%;
    animation-delay: -14s;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(50px, -30px) scale(1.05); }
    66% { transform: translate(-30px, 40px) scale(0.95); }
}

.bg-grid {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
    background-size: 60px 60px;
    mask-image: radial-gradient(ellipse at center, black 30%, transparent 70%);
}

.bg-noise {
    position: absolute;
    inset: 0;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ============ 玻璃拟态 ============ */
.glass {
    background: rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

/* ============ 主布局 ============ */
.app {
    max-width: 920px;
    margin: 0 auto;
    padding: 32px 20px 60px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ============ 顶部品牌 ============ */
.brand {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 36px;
    padding: 4px;
}

.brand-logo {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--accent) 0%, var(--pink) 100%);
    border-radius: 12px;
    color: white;
    box-shadow: 0 8px 24px var(--accent-glow);
    flex-shrink: 0;
}

.brand-text {
    flex: 1;
    min-width: 0;
}

.brand-text h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #fff 0%, rgba(255, 255, 255, 0.6) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.brand-text p {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.brand-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 100px;
    font-size: 12px;
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
    animation: pulse 2s ease-in-out infinite;
}

.brand-status.loading .status-dot { background: var(--warning); box-shadow: 0 0 8px var(--warning); }
.brand-status.error .status-dot { background: var(--error); box-shadow: 0 0 8px var(--error); }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ============ 搜索区 ============ */
.search-section {
    margin-bottom: 24px;
}

.search-card {
    padding: 28px;
    position: relative;
    overflow: hidden;
}

.search-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent-bright), transparent);
    opacity: 0.5;
}

.search-header {
    margin-bottom: 20px;
}

.search-header h2 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 4px;
}

.search-hint {
    font-size: 13px;
    color: var(--text-secondary);
}

.search-form {
    display: flex;
    gap: 12px;
    align-items: stretch;
}

.input-wrapper {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon {
    position: absolute;
    left: 16px;
    color: var(--text-tertiary);
    pointer-events: none;
    transition: color 0.2s;
}

.input-wrapper:focus-within .input-icon {
    color: var(--accent-bright);
}

.search-form input {
    width: 100%;
    padding: 14px 44px 14px 46px;
    background: rgba(0, 0, 0, 0.3);
    border: 1.5px solid var(--border);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 15px;
    font-family: var(--font-mono);
    outline: none;
    transition: all 0.2s;
}

.search-form input::placeholder {
    color: var(--text-tertiary);
}

.search-form input:focus {
    border-color: var(--accent-bright);
    background: rgba(0, 0, 0, 0.4);
    box-shadow: 0 0 0 4px var(--accent-soft);
}

.clear-btn {
    position: absolute;
    right: 12px;
    width: 24px;
    height: 24px;
    display: none;
    align-items: center;
    justify-content: center;
    background: var(--surface-hover);
    border: none;
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}

.clear-btn.visible {
    display: flex;
}

.clear-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: var(--text-primary);
}

.search-btn {
    position: relative;
    padding: 0 24px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--pink) 100%);
    border: none;
    border-radius: 12px;
    color: white;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    overflow: hidden;
    transition: transform 0.15s, box-shadow 0.2s;
    box-shadow: 0 4px 16px var(--accent-glow);
    min-width: 120px;
}

.search-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 8px 24px var(--accent-glow);
}

.search-btn:active:not(:disabled) {
    transform: translateY(0);
}

.search-btn:disabled {
    cursor: not-allowed;
    opacity: 0.7;
}

.btn-content {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: opacity 0.2s;
}

.btn-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 18px;
    height: 18px;
    margin: -9px 0 0 -9px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    opacity: 0;
    animation: spin 0.8s linear infinite;
}

.search-btn.loading .btn-content {
    opacity: 0;
}

.search-btn.loading .btn-loader {
    opacity: 1;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.quick-tags {
    margin-top: 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.quick-tag {
    padding: 6px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 100px;
    color: var(--text-secondary);
    font-size: 12px;
    font-family: var(--font-mono);
    cursor: pointer;
    transition: all 0.15s;
}

.quick-tag:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent-bright);
}

.quick-tag .tag-remove {
    margin-left: 6px;
    opacity: 0.5;
}

.quick-tag:hover .tag-remove {
    opacity: 1;
}

/* ============ 状态提示 ============ */
.status-message {
    display: none;
    padding: 14px 20px;
    margin-bottom: 20px;
    border-radius: var(--radius-md);
    font-size: 14px;
    align-items: center;
    gap: 10px;
}

.status-message.show {
    display: flex;
}

.status-message.error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #fca5a5;
}

.status-message.info {
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.3);
    color: #93c5fd;
}

.status-message.success {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: #6ee7b7;
}

/* ============ 结果区 ============ */
.results {
    flex: 1;
    margin-bottom: 32px;
}

.results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding: 0 4px;
}

.results-info h3 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.results-info p {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 2px;
    font-family: var(--font-mono);
}

.refresh-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 100px;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.refresh-btn:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.refresh-btn.spinning svg {
    animation: spin 1s linear infinite;
}

/* ============ 邮件列表 ============ */
.email-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.email-card {
    padding: 18px 20px;
    background: var(--surface);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    animation: slideIn 0.3s ease both;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.email-card:hover {
    background: var(--surface-hover);
    border-color: var(--border-strong);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.email-card::after {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: linear-gradient(180deg, var(--accent) 0%, var(--pink) 100%);
    opacity: 0;
    transition: opacity 0.2s;
}

.email-card:hover::after {
    opacity: 1;
}

.email-card-row {
    display: flex;
    align-items: center;
    gap: 14px;
}

.email-avatar {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
    text-transform: uppercase;
}

.email-content {
    flex: 1;
    min-width: 0;
}

.email-top {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 4px;
}

.email-from {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.email-date {
    font-size: 12px;
    color: var(--text-tertiary);
    font-family: var(--font-mono);
    flex-shrink: 0;
}

.email-subject {
    font-size: 14px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

.email-card-arrow {
    flex-shrink: 0;
    color: var(--text-tertiary);
    transition: transform 0.2s, color 0.2s;
}

.email-card:hover .email-card-arrow {
    color: var(--accent-bright);
    transform: translateX(2px);
}

/* ============ 空状态 ============ */
.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
}

.empty-state.hidden {
    display: none;
}

.empty-icon {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    margin-bottom: 20px;
    position: relative;
}

.empty-icon::before {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--pink));
    opacity: 0.2;
    z-index: -1;
    filter: blur(20px);
}

.empty-state h3 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 14px;
    color: var(--text-secondary);
    max-width: 320px;
}

/* ============ 底部 ============ */
.footer {
    margin-top: auto;
    padding-top: 32px;
    text-align: center;
    font-size: 12px;
    color: var(--text-tertiary);
    font-family: var(--font-mono);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
}

.footer-dot {
    opacity: 0.5;
}

/* ============ 模态框 ============ */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
}

.modal-content {
    position: relative;
    width: 100%;
    max-width: 760px;
    max-height: 88vh;
    background: rgba(15, 18, 40, 0.92);
    backdrop-filter: blur(40px) saturate(180%);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-xl);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: scaleIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.96) translateY(8px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-header {
    padding: 24px 28px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.modal-title-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 16px;
}

.modal-header h2 {
    font-size: 19px;
    font-weight: 700;
    line-height: 1.4;
    letter-spacing: -0.01em;
    word-break: break-word;
}

.modal-close {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}

.modal-close:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
    transform: rotate(90deg);
}

.modal-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.meta-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.meta-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-tertiary);
}

.meta-value {
    font-size: 13px;
    color: var(--text-primary);
    font-family: var(--font-mono);
    word-break: break-all;
}

.modal-body {
    flex: 1;
    overflow: hidden;
    background: white;
    margin: 0;
}

.modal-body iframe {
    width: 100%;
    height: 100%;
    min-height: 400px;
    border: none;
    background: white;
}

/* ============ 响应式 ============ */
@media (max-width: 640px) {
    .app {
        padding: 20px 16px 40px;
    }

    .brand {
        margin-bottom: 24px;
    }

    .brand-status {
        display: none;
    }

    .search-card {
        padding: 20px;
    }

    .search-form {
        flex-direction: column;
    }

    .search-btn {
        padding: 14px 24px;
    }

    .modal {
        padding: 0;
    }

    .modal-content {
        max-height: 100vh;
        height: 100vh;
        border-radius: 0;
    }

    .email-card-row {
        gap: 12px;
    }

    .email-avatar {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }

    .email-top {
        gap: 8px;
    }

    .email-date {
        font-size: 11px;
    }
}

/* 隐藏滚动条但保持功能 */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* 隐藏属性 */
[hidden] {
    display: none !important;
}
