:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #818cf8;
    --primary-glow: rgba(79, 70, 229, 0.35);
    --bg-gradient-start: #eef2ff;
    --bg-gradient-end: #e0e7ff;
    --text-main: #1f2937;
    --text-secondary: #6b7280;
    --card-bg: rgba(255, 255, 255, 0.85);
    --card-border: rgba(255, 255, 255, 0.6);
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 40px -8px rgba(79, 70, 229, 0.15), 0 8px 16px -4px rgba(0, 0, 0, 0.08);
    --radius-md: 0.75rem;
    --radius-lg: 1.25rem;
    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

body {
    font-family: var(--font-sans);
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    color: var(--text-main);
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Utilities */
.container {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

/* ===== Login Page ===== */
.login-body {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    position: relative;
    overflow: hidden;
    background: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 40%, #c7d2fe 100%);
}

/* 背景装饰光球 */
.bg-decoration {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 0;
}

.bg-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.5;
    animation: orbFloat 20s ease-in-out infinite;
}

.bg-orb-1 {
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, rgba(129, 140, 248, 0.4) 0%, transparent 70%);
    top: -10%;
    right: -5%;
    animation-duration: 22s;
}

.bg-orb-2 {
    width: 350px;
    height: 350px;
    background: radial-gradient(circle, rgba(167, 139, 250, 0.35) 0%, transparent 70%);
    bottom: -8%;
    left: -5%;
    animation-duration: 18s;
    animation-delay: -5s;
}

.bg-orb-3 {
    width: 250px;
    height: 250px;
    background: radial-gradient(circle, rgba(99, 102, 241, 0.3) 0%, transparent 70%);
    top: 40%;
    left: 50%;
    animation-duration: 25s;
    animation-delay: -10s;
}

@keyframes orbFloat {
    0%, 100% {
        transform: translate(0, 0) scale(1);
    }
    25% {
        transform: translate(30px, -20px) scale(1.05);
    }
    50% {
        transform: translate(-20px, 15px) scale(0.95);
    }
    75% {
        transform: translate(15px, 25px) scale(1.02);
    }
}

/* 登录卡片 */
.login-card {
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--card-border);
    padding: 2.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 420px;
    animation: cardEntry 0.6s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    z-index: 1;
}

/* 顶部图标 */
.login-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 1rem;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-light) 100%);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.login-icon svg {
    width: 28px;
    height: 28px;
    color: white;
}

.login-card h1 {
    text-align: center;
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    color: var(--text-main);
}

.login-subtitle {
    text-align: center;
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 1.75rem;
}

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

.form-label {
    display: block;
    margin-bottom: 0.4rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-main);
    letter-spacing: 0.01em;
}

.input-wrapper {
    position: relative;
}

.input-icon {
    position: absolute;
    left: 0.875rem;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: #9ca3af;
    pointer-events: none;
    transition: color 0.2s;
    z-index: 1;
}

.input-icon-textarea {
    top: 1rem;
    transform: none;
}

.input-wrapper:focus-within .input-icon {
    color: var(--primary-color);
}

.form-input {
    width: 100%;
    padding: 0.7rem 1rem;
    border: 1.5px solid #e5e7eb;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.95);
    font-size: 0.9375rem;
    transition: all 0.25s ease;
    color: var(--text-main);
}

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

.form-input::placeholder {
    color: #c3c7ce;
}

.form-input:hover {
    border-color: #c7d2fe;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
    background: white;
}

/* 按钮 */
.btn-primary {
    width: 100%;
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, var(--primary-color) 0%, #6366f1 100%);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    position: relative;
    overflow: hidden;
    margin-top: 0.5rem;
}

.btn-primary::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent 0%, rgba(255, 255, 255, 0.1) 50%, transparent 100%);
    transform: translateX(-100%);
    transition: transform 0.5s ease;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(79, 70, 229, 0.35);
}

.btn-primary:hover::before {
    transform: translateX(100%);
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}

.btn-arrow {
    width: 18px;
    height: 18px;
    transition: transform 0.3s ease;
}

.btn-primary:hover .btn-arrow {
    transform: translateX(3px);
}

/* 错误提示 */
.error-msg {
    background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
    color: #991b1b;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.25rem;
    font-size: 0.8125rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border: 1px solid #fecaca;
    animation: shakeX 0.5s ease;
}

.error-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    color: #dc2626;
}

/* Tab 切换 */
.login-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 1.5rem;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: #f1f3f9;
    padding: 4px;
    position: relative;
}

.tab-indicator {
    position: absolute;
    top: 4px;
    left: 4px;
    width: calc(50% - 4px);
    height: calc(100% - 8px);
    background: white;
    border-radius: calc(var(--radius-md) - 2px);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 0;
}

.tab-btn {
    flex: 1;
    padding: 0.55rem 0.75rem;
    border: none;
    background: transparent;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.25s;
    font-family: var(--font-sans);
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
}

.tab-icon {
    width: 15px;
    height: 15px;
}

.tab-btn.active {
    color: var(--primary-color);
}

.tab-btn:hover:not(.active) {
    color: var(--text-main);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: tabSlideIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

/* 卡密输入框 */
.form-textarea {
    resize: vertical;
    min-height: 5rem;
    font-family: "Cascadia Code", "Fira Code", "Consolas", "Monaco", monospace;
    font-size: 0.8125rem;
    line-height: 1.7;
    padding-top: 0.75rem;
}

.form-hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    margin-top: -0.25rem;
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.hint-icon {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    color: #a5b4fc;
}

/* Email List Page */
.app-header {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.app-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-main);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mailbox-section {
    margin-bottom: 2rem;
}

.mailbox-title {
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    font-weight: 600;
}

.email-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.email-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
    padding: 1rem;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s;
    display: block;
    color: inherit;
    position: relative;
    overflow: hidden;
}

.email-card:hover {
    box-shadow: var(--shadow-md);
    background: rgba(255, 255, 255, 0.95);
}

.email-card-content {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
}

.email-info {
    flex: 1;
    min-width: 0;
    /* Enable text truncation */
}

.email-subject {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 0.25rem;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    user-select: text;
    /* Explicitly allow selection */
    cursor: text;
}

.email-meta {
    font-size: 0.875rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.email-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.5rem;
}

.email-date {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
    margin-bottom: 0rem;
    color: var(--text-main);
}

.btn-view {
    display: inline-block;
    padding: 0.3rem 0.8rem;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: 0 1px 3px 0 rgba(59, 130, 246, 0.2);
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.btn-view:hover {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px 0 rgba(59, 130, 246, 0.3);
}

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.3);
    border-radius: var(--radius-md);
    border: 2px dashed rgba(0, 0, 0, 0.05);
}

/* Email Detail Page */
.detail-card {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    min-height: 80vh;
    display: flex;
    flex-direction: column;
}

.detail-header {
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.5);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.nav-back {
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 0.75rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.875rem;
    border-radius: 6px;
    margin-bottom: 1.5rem;
    transition: all 0.2s ease;
    background: transparent;
}

.nav-back:hover {
    color: var(--primary-color);
    background: rgba(79, 70, 229, 0.05);
    /* Very subtle primary tint */
}

.detail-subject {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 1rem;
    color: var(--text-main);
}

.detail-meta {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.meta-row {
    display: flex;
    gap: 0.5rem;
}

.meta-label {
    font-weight: 600;
    color: var(--text-main);
    min-width: 3rem;
}

.detail-body {
    padding: 2rem;
    overflow-y: auto;
    flex: 1;
    background: white;
    /* Ensure readability */
    font-size: 1rem;
    line-height: 1.6;
    color: #374151;
}

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

.detail-links {
    padding: 1.5rem;
    background: #f9fafb;
    border-top: 1px solid #e5e7eb;
}

.links-title {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-main);
}

.link-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.link-item a {
    display: block;
    padding: 0.5rem 0.75rem;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: var(--radius-md);
    color: var(--primary-color);
    text-decoration: none;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: border-color 0.2s;
}

.link-item a:hover {
    border-color: var(--primary-color);
    text-decoration: underline;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes cardEntry {
    from {
        opacity: 0;
        transform: translateY(24px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes tabSlideIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes shakeX {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

/* Mobile Responsiveness */
@media (max-width: 640px) {
    .container {
        padding: 15px;
    }

    .login-card {
        padding: 1.75rem;
        border-radius: var(--radius-md);
    }

    .login-icon {
        width: 48px;
        height: 48px;
        border-radius: 12px;
    }

    .login-icon svg {
        width: 24px;
        height: 24px;
    }

    .login-card h1 {
        font-size: 1.3rem;
    }

    .detail-subject {
        font-size: 1.25rem;
    }

    .detail-body {
        padding: 1.5rem;
    }

    .bg-orb-1 {
        width: 250px;
        height: 250px;
    }

    .bg-orb-2 {
        width: 200px;
        height: 200px;
    }

    .bg-orb-3 {
        width: 150px;
        height: 150px;
    }
}