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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

body.modal-open {
    overflow: hidden;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

header {
    text-align: center;
    color: white;
    margin-bottom: 40px;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.95;
}

.search-section {
    background: white;
    border-radius: 12px;
    padding: 30px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    margin-bottom: 30px;
}

.search-box {
    display: flex;
    gap: 10px;
}

#emailInput {
    flex: 1;
    padding: 12px 16px;
    font-size: 16px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    transition: border-color 0.3s;
}

#emailInput:focus {
    outline: none;
    border-color: #667eea;
}

#searchBtn {
    padding: 12px 30px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    min-width: 120px;
    position: relative;
}

#searchBtn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

#searchBtn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #ffffff;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 0.8s linear infinite;
}

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

.error-message {
    display: none;
    color: #dc2626;
    margin-top: 10px;
    padding: 10px;
    background: #fee2e2;
    border-radius: 6px;
    font-size: 14px;
}

.emails-section {
    background: white;
    border-radius: 12px;
    padding: 30px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    min-height: 400px;
}

.emails-list h2 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.5rem;
}

.load-more-container {
    display: flex;
    justify-content: center;
    padding-top: 20px;
}

.load-more-btn {
    padding: 10px 18px;
    background: #111827;
    color: #ffffff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background 0.2s ease, transform 0.2s ease;
}

.load-more-btn:hover:not(:disabled) {
    background: #1f2937;
}

.load-more-btn:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.emails-placeholder {
    text-align: center;
    color: #6b7280;
    font-size: 16px;
    padding: 42px 20px;
    border: 1px dashed #cbd5e1;
    border-radius: 10px;
    background: #f8fafc;
}

.email-card {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 15px;
    transition: box-shadow 0.3s, transform 0.2s;
    background: #fafafa;
}

.email-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    transform: translateY(-2px);
}

.email-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 10px;
}

.email-from strong {
    color: #333;
    font-size: 16px;
}

.email-address {
    color: #666;
    font-size: 14px;
    margin-left: 5px;
}

.email-date {
    color: #666;
    font-size: 14px;
}

.email-subject {
    color: #444;
    font-size: 18px;
    font-weight: 500;
    margin: 10px 0;
}

.email-to {
    color: #666;
    font-size: 14px;
    margin-bottom: 15px;
}

.view-btn {
    padding: 8px 20px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.3s;
}

.view-btn:hover {
    background: #5a67d8;
}

.card-actions {
    display: flex;
    gap: 10px;
}

.delete-btn {
    padding: 8px 20px;
    background: #dc2626;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.3s;
}

.delete-btn:hover:not(:disabled) {
    background: #b91c1c;
}

.delete-btn:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.no-emails {
    text-align: center;
    color: #666;
    padding: 40px;
    font-size: 18px;
}

.close-btn {
    padding: 9px 14px;
    border-radius: 8px;
    border: 1px solid #111827;
    background: #111827;
    color: #ffffff;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background 0.2s ease, transform 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    background: #1f2937;
}

#emailFrame {
    width: 100%;
    border: none;
    flex: 1;
    min-height: 0;
    display: block;
    background: white;
}

.email-modal {
    position: fixed;
    inset: 0;
    background: #eef2ff;
    display: flex;
    align-items: stretch;
    justify-content: stretch;
    padding: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.12s ease;
    z-index: 1100;
}

.email-modal.is-open {
    opacity: 1;
    pointer-events: auto;
}

.email-modal-shell {
    width: 100%;
    height: 100%;
    background: white;
    display: flex;
    flex-direction: column;
}

.email-modal-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
    min-height: 58px;
}

.raw-btn {
    padding: 9px 14px;
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    color: #3730a3;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background 0.2s ease, transform 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.raw-btn:hover {
    background: #e0e7ff;
}

.direct-error-message {
    display: none;
    margin: 10px 14px 0;
    padding: 10px 12px;
    border-radius: 8px;
    background: #fee2e2;
    border: 1px solid #fecaca;
    color: #b91c1c;
    font-size: 14px;
}

body.direct-email-mode {
    margin: 0;
    padding: 0;
    background: #ffffff;
}

body.direct-email-mode .container {
    display: none;
}

body.direct-email-mode .email-modal {
    opacity: 1;
    pointer-events: auto;
    display: flex !important;
    background: #ffffff;
    z-index: 1;
}

body.direct-email-mode .email-modal-toolbar {
    display: none;
}

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

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #ffffff;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

.loading-overlay p {
    color: white;
    font-size: 18px;
}

@media (max-width: 768px) {
    header h1 {
        font-size: 2rem;
    }
    
    .search-box {
        flex-direction: column;
    }
    
    #searchBtn {
        width: 100%;
    }
    
    .email-card-header {
        flex-direction: column;
        gap: 5px;
    }
    
    .emails-section {
        padding: 20px;
    }

    .email-modal {
        padding: 0;
    }

    .card-actions {
        flex-direction: column;
    }

    .email-modal-toolbar {
        min-height: 0;
        padding: 10px;
        gap: 8px;
    }

    .close-btn,
    .raw-btn {
        flex: 1;
    }
}
