:root {
    --bg-main: #0f111a;
    --bg-panel: rgba(25, 28, 41, 0.6);
    --bg-panel-hover: rgba(40, 44, 62, 0.8);
    --border-color: rgba(255, 255, 255, 0.08);
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --status-active: #10b981;
    --status-connecting: #f59e0b;
    --status-error: #ef4444;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
    background-image: 
        radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(16, 185, 129, 0.1) 0px, transparent 50%);
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Navbar */
.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

.logo i {
    font-size: 1.75rem;
}

.nav-back-btn {
    display: none; /* Hidden by default on desktop */
}

.email-display {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.email-wrapper {
    display: flex;
    align-items: center;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    border-radius: 99px;
    padding: 0.35rem 0.5rem 0.35rem 1.25rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.email-wrapper:hover {
    border-color: rgba(255, 255, 255, 0.15);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.15);
}

.actions-group {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.email-text {
    font-family: monospace;
    font-size: 0.95rem;
    letter-spacing: 0.5px;
    margin-right: 1rem;
    color: #e2e8f0;
}

.copy-btn {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.copy-btn:hover {
    background: var(--primary-hover);
    transform: scale(1.05);
}

.copy-btn:active {
    transform: scale(0.95);
}

.action-btn {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.action-btn:hover {
    background: rgba(239, 68, 68, 0.2);
    color: var(--status-error);
    border-color: rgba(239, 68, 68, 0.5);
    transform: rotate(90deg);
}

.action-btn:active {
    transform: scale(0.95);
}

.status-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    box-shadow: 0 0 10px currentColor;
}

.status-indicator.active { color: var(--status-active); background-color: var(--status-active); }
.status-indicator.connecting { color: var(--status-connecting); background-color: var(--status-connecting); animation: pulse 1.5s infinite; }
.status-indicator.error { color: var(--status-error); background-color: var(--status-error); }

@keyframes pulse {
    0% { transform: scale(0.95); opacity: 0.5; }
    50% { transform: scale(1.05); opacity: 1; }
    100% { transform: scale(0.95); opacity: 0.5; }
}

/* Layout */
.main-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 350px;
    background: var(--bg-panel);
    backdrop-filter: blur(8px);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.badge {
    background: var(--primary);
    color: white;
    padding: 0.15rem 0.6rem;
    border-radius: 99px;
    font-size: 0.8rem;
    font-weight: 600;
}

.warning-alert {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(245, 158, 11, 0.15);
    color: #fcd34d;
    padding: 0.75rem 1rem;
    font-size: 0.8rem;
    border-bottom: 1px solid rgba(245, 158, 11, 0.2);
}

.warning-alert i {
    font-size: 1.1rem;
}

.email-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
    /* Custom Scrollbar for list */
    scrollbar-width: thin;
    scrollbar-color: var(--primary) transparent;
}
.email-list::-webkit-scrollbar {
    width: 6px;
}
.email-list::-webkit-scrollbar-track {
    background: transparent;
}
.email-list::-webkit-scrollbar-thumb {
    background-color: var(--primary);
    border-radius: 10px;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    gap: 1rem;
    text-align: center;
    padding: 2rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255,255,255,0.1);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 1s ease-in-out infinite;
}

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

/* Email Item */
.email-item {
    padding: 0.75rem 1rem;
    border-radius: 10px;
    margin-bottom: 0.25rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    animation: slideIn 0.3s ease-out forwards;
}

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

.email-item:hover {
    background: var(--bg-panel-hover);
    border-color: var(--border-color);
}

.email-item.active {
    background: rgba(99, 102, 241, 0.15);
    border-color: rgba(99, 102, 241, 0.3);
}

.email-item-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.25rem;
    font-size: 0.85rem;
}

.email-item-sender {
    font-weight: 600;
    color: #e2e8f0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 75%;
}

.email-item-time {
    color: var(--text-muted);
}

.email-item-subject {
    font-weight: 500;
    font-size: 0.95rem;
    margin-bottom: 0.2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.email-item-snippet {
    font-size: 0.85rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Main Content */
.email-view {
    flex: 1;
    position: relative;
    background: rgba(10, 11, 16, 0.4);
    display: flex;
    flex-direction: column;
}

.no-email-selected {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    gap: 1rem;
}

.no-email-selected i {
    font-size: 4rem;
    opacity: 0.5;
}

.no-email-selected.hidden {
    display: none;
}

.email-content {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.email-content.hidden {
    display: none;
}

.email-header {
    padding: 2rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-panel);
    backdrop-filter: blur(10px);
}

.email-header h1 {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    font-weight: 600;
}

.mail-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sender-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.avatar {
    width: 48px;
    height: 48px;
    min-width: 48px;
    flex-shrink: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: bold;
    color: white;
}

.sender-details {
    display: flex;
    flex-direction: column;
}

.sender-name {
    font-weight: 600;
    font-size: 1.1rem;
}

.sender-email {
    font-size: 0.95rem;
    color: var(--text-main);
}

.recipient {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

.mail-datetime {
    text-align: right;
}

.mail-time {
    font-weight: 600;
    color: var(--text-main);
    font-size: 0.95rem;
    margin-bottom: 0.2rem;
}

.mail-date {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.email-body {
    flex: 1;
    padding: 0;
    background: white; /* Email bodies are best read on white */
    overflow: hidden;
    position: relative;
    border-top-left-radius: 12px;
    margin: 1rem;
    border-radius: 8px;
}

#mail-body-frame {
    width: 100%;
    height: 100%;
    border: none;
}

#mail-body-text {
    padding: 2rem;
    color: #1a1a1a;
    white-space: pre-wrap;
    font-family: inherit;
    overflow-y: auto;
    height: 100%;
}

.hidden {
    display: none !important;
}

/* Toast */
.toast {
    position: fixed;
    bottom: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--status-active);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 99px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
    box-shadow: 0 10px 25px rgba(16, 185, 129, 0.3);
    transition: bottom 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 1000;
}

.toast.show {
    bottom: 30px;
}

@media (max-width: 768px) {
    .navbar {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
        transition: padding 0.3s ease;
    }
    
    .logo {
        width: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        margin-bottom: 0.25rem;
        gap: 0.75rem;
    }

    .nav-back-btn {
        display: none;
        background: transparent;
        border: none;
        color: var(--text-main);
        font-size: 1.5rem;
        cursor: pointer;
        padding: 0.25rem;
    }

    .app-container.show-email .nav-back-btn {
        display: flex;
    }
    .app-container.show-email .logo-icon {
        display: none;
    }
    .app-container.show-email .logo {
        justify-content: flex-start;
        margin-bottom: 0;
    }

    .email-display {
        flex-direction: column;
        width: 100%;
        gap: 0.75rem;
        overflow: hidden;
        max-height: 500px;
        opacity: 1;
        transition: max-height 0.4s ease, opacity 0.3s ease, margin 0.3s ease, padding 0.3s ease;
    }
    
    .app-container.nav-hidden .email-display {
        max-height: 0;
        opacity: 0;
        margin: 0;
        padding: 0;
        gap: 0;
    }
    
    .app-container.nav-hidden .navbar {
        padding: 0.75rem 1rem;
        gap: 0;
    }

    .email-wrapper {
        width: 100%;
        max-width: 100%;
        flex-direction: column;
        align-items: stretch;
        padding: 1.25rem;
        border-radius: 12px;
        gap: 1.25rem;
        background: rgba(0, 0, 0, 0.2);
    }
    
    .email-text {
        font-size: 1.05rem;
        white-space: normal;
        word-break: break-all;
        margin: 0;
        text-align: center;
        line-height: 1.4;
    }

    .copy-btn {
        width: 100%;
        height: 48px;
        border-radius: 8px;
        gap: 0.5rem;
    }
    .copy-btn::after {
        content: "Copy Address";
        font-family: 'Inter', sans-serif;
        font-size: 1rem;
        font-weight: 600;
    }

    .actions-group {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
        width: 100%;
    }

    .action-btn {
        width: auto;
        flex: 1;
        height: 48px;
        border-radius: 8px;
        gap: 0.5rem;
        background: rgba(255, 255, 255, 0.05);
    }
    .action-btn::after {
        content: "New Email";
        font-family: 'Inter', sans-serif;
        font-size: 1rem;
        font-weight: 600;
    }
    
    #connection-status {
        margin: 0 1rem;
        transform: scale(1.2);
    }

    .main-layout {
        position: relative;
    }
    
    .sidebar {
        width: 100%;
        position: absolute;
        top: 0; bottom: 0; left: 0; right: 0;
        z-index: 5;
        transition: transform 0.3s ease;
    }
    
    .email-view {
        width: 100%;
        position: absolute;
        top: 0; bottom: 0; left: 0; right: 0;
        z-index: 10;
        transform: translateX(100%);
        transition: transform 0.3s ease;
    }
    
    .app-container.show-email .sidebar {
        transform: translateX(-100%);
    }
    
    .app-container.show-email .email-view {
        transform: translateX(0);
    }
    
    .email-header {
        padding: 1rem 1rem 0.5rem 1rem;
    }
    
    .email-header h1 {
        font-size: 1.2rem;
        margin-bottom: 0.75rem;
        line-height: 1.3;
    }
    
    .mail-meta {
        flex-direction: column;
        align-items: stretch;
        gap: 1.25rem;
    }
    
    .sender-info {
        width: 100%;
        gap: 0.75rem;
    }
    
    .sender-details {
        flex: 1;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        gap: 0.1rem;
    }
    
    .sender-name {
        font-size: 1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        display: block;
    }

    .sender-email {
        font-size: 0.9rem;
        color: var(--text-muted);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        display: block;
    }
    
    .recipient {
        font-size: 0.75rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        display: block;
        line-height: 1.2;
    }

    .mail-datetime {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        background: rgba(255, 255, 255, 0.05);
        padding: 0.6rem 0.75rem;
        border-radius: 8px;
    }
    
    .mail-time {
        margin: 0;
        font-size: 0.85rem;
    }
    
    .mail-date {
        font-size: 0.85rem;
    }

    .email-body {
        margin: 0;
        border-radius: 0;
    }

    #mail-body-text {
        padding: 1rem;
    }
}
