/* variables & Apple-inspired design system */
:root {
    --bg-dark: #000000;
    --bg-surface: rgba(22, 22, 23, 0.8);
    --bg-surface-secondary: rgba(28, 28, 30, 0.7);
    --border-color: rgba(255, 255, 255, 0.08);
    
    /* Apple Blue & Accents */
    --primary: #0071e3;
    --primary-hover: #147ce5;
    --secondary: rgba(255, 255, 255, 0.08);
    --secondary-hover: rgba(255, 255, 255, 0.12);
    --success: #30d158; /* iOS Success Green */
    --danger: #ff453a; /* iOS Danger Red */
    --accent: #bf5af2;  /* iOS Purple */
    
    /* Typography */
    --text-primary: #f5f5f7;
    --text-secondary: #86868b;
    --text-muted: #48484a;
    
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    
    /* Structural tokens */
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    
    --transition-smooth: all 0.25s cubic-bezier(0.25, 1, 0.5, 1);
}

/* Reset and basic setup */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-sans);
    -webkit-font-smoothing: antialiased;
    touch-action: pan-x pan-y;
}

html, body {
    touch-action: pan-x pan-y;
    overflow-x: clip;
    max-width: 100%;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: clip;
    position: relative;
}

.page-wrapper {
    position: relative;
    width: 100%;
    overflow: hidden;
    min-height: 100vh;
}

/* Apple style subtle gradient background (SF desktop style) */
.glow-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(140px);
    z-index: -1;
    opacity: 0.55; /* Higher opacity for better backlighting */
    pointer-events: none;
}

.orb-1 {
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(0, 113, 227, 0.35) 0%, transparent 70%);
    top: -200px;
    right: -100px;
}

.orb-2 {
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, rgba(191, 90, 242, 0.3) 0%, transparent 70%);
    bottom: -150px;
    left: -100px;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

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

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Premium Transparent Card (Apple Vibrancy Glassmorphism) */
.glass {
    background: rgba(22, 22, 23, 0.42); /* Highly translucent Apple design */
    backdrop-filter: blur(35px) saturate(220%);
    -webkit-backdrop-filter: blur(35px) saturate(220%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-lg);
    /* Inset shadow creates the top highlights, outer shadow creates drop shadow */
    box-shadow: 
        inset 0 1px 1px 0 rgba(255, 255, 255, 0.15), 
        0 12px 40px 0 rgba(0, 0, 0, 0.5);
    transition: var(--transition-smooth);
}

.glass:hover {
    background: rgba(22, 22, 23, 0.5);
    border-color: rgba(255, 255, 255, 0.16);
    box-shadow: 
        inset 0 1px 1px 0 rgba(255, 255, 255, 0.25), 
        0 16px 48px 0 rgba(0, 0, 0, 0.6);
}

/* Main Container */
.app-container {
    max-width: 1140px;
    margin: 0 auto;
    padding: 32px 24px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
}

.mail-icon {
    width: 22px;
    height: 22px;
    stroke: rgba(255, 255, 255, 0.85); /* Clean white/silver glass stroke */
    fill: rgba(255, 255, 255, 0.08);   /* Frosted glass fill inside the envelope */
    stroke-width: 1.8;
    filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.15));
}

.brand h1 {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.3px;
    color: var(--text-primary);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(48, 209, 88, 0.1);
    border: 1px solid rgba(48, 209, 88, 0.15);
    padding: 5px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    color: var(--success);
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--success);
}

.status-dot.ping::after {
    content: '';
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--success);
    animation: ping 2s infinite ease-out;
}

@keyframes ping {
    0% { transform: scale(1); opacity: 1; }
    100% { transform: scale(3); opacity: 0; }
}

/* Apple style buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-weight: 500;
    font-size: 13px;
    padding: 8px 16px;
    border-radius: 980px; /* Capsule buttons */
    cursor: pointer;
    border: 1px solid transparent;
    transition: var(--transition-smooth);
    outline: none;
    user-select: none;
}

.btn i {
    width: 14px;
    height: 14px;
    stroke-width: 2px;
}

.btn-primary {
    background-color: var(--primary);
    color: #ffffff;
}

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

.btn-secondary {
    background-color: var(--secondary);
    border-color: transparent;
    color: var(--text-primary);
}

.btn-secondary:hover {
    background-color: var(--secondary-hover);
}

.btn-accent {
    background-color: rgba(255, 255, 255, 0.94);
    color: #000000;
}

.btn-accent:hover {
    background-color: #ffffff;
    transform: scale(1.02);
}

.btn-danger {
    background-color: rgba(255, 69, 58, 0.1);
    color: var(--danger);
}

.btn-danger:hover {
    background-color: var(--danger);
    color: #ffffff;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}

.btn:active {
    transform: scale(0.97);
}

/* Generator Section */
.generator-card {
    position: relative;
    z-index: 10;
    padding: 24px;
    margin-bottom: 24px;
}

.generator-header {
    margin-bottom: 16px;
}

.generator-header h2 {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.2px;
}

.generator-header p {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.email-input-group {
    display: flex;
    gap: 12px;
    align-items: center;
}

.input-container {
    position: relative;
    flex: 1;
}

.input-wrapper {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: var(--radius-md);
    padding: 4px 16px;
    transition: var(--transition-smooth);
}

.input-wrapper:focus-within {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.2);
}

/* History button inside input wrapper */
.history-btn {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    margin-right: 8px;
    border-radius: 6px;
    transition: var(--transition-smooth);
}

.history-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.06);
}

.history-btn i {
    width: 15px;
    height: 15px;
}

/* History Dropdown Menu */
.history-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 9999;
    border-radius: var(--radius-md);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.8), inset 0 1px 0 rgba(255, 255, 255, 0.1);
    overflow: hidden;
    background: rgba(18, 18, 19, 0.97) !important;
    border: 1px solid rgba(255, 255, 255, 0.12) !important;
    backdrop-filter: blur(25px) saturate(200%);
    -webkit-backdrop-filter: blur(25px) saturate(200%);
}

.dropdown-header {
    padding: 10px 16px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.01);
}

.dropdown-items {
    max-height: 180px;
    overflow-y: auto;
}

.dropdown-item {
    padding: 12px 16px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition-smooth);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}

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

.dropdown-item:hover {
    background: rgba(255, 255, 255, 0.04);
    color: var(--primary);
}

.dropdown-item-delete {
    color: var(--text-secondary);
    border: none;
    background: transparent;
    padding: 4px;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    transition: var(--transition-smooth);
}

.dropdown-item-delete:hover {
    color: var(--danger);
    background: rgba(255, 69, 58, 0.15);
}

.dropdown-item-delete i {
    width: 12px;
    height: 12px;
}

.dropdown-footer {
    padding: 8px 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    background: rgba(255, 255, 255, 0.01);
}

.btn-clear-history {
    background: transparent;
    border: none;
    outline: none;
    color: var(--danger);
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.btn-clear-history:hover {
    text-decoration: underline;
    opacity: 0.9;
}

.input-wrapper input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 500;
    padding: 10px 0;
    letter-spacing: -0.2px;
}

.email-domain {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 50%;
    flex-shrink: 0;
}

#newDomainSuffix {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 50%;
    flex-shrink: 0;
}

.action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* Work Grid */
.workspace-grid {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 24px;
    flex: 1;
}

.inbox-panel, .detail-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 580px;
}

.panel-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.01);
}

.panel-title-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.title-icon {
    width: 16px;
    height: 16px;
    stroke: var(--text-secondary);
}

.panel-title-group h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.email-count-badge {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 500;
    padding: 3px 8px;
    border-radius: 980px;
}

/* Inbox Lists */
.email-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.list-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
    height: 100%;
}

.list-state p {
    color: var(--text-secondary);
    font-size: 13px;
}

.radar-ping {
    position: relative;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

.radar-icon {
    width: 20px;
    height: 20px;
    stroke: var(--text-secondary);
    z-index: 2;
}

.ping-circle {
    position: absolute;
    border-radius: 50%;
    border: 1.5px solid rgba(255, 255, 255, 0.1);
    animation: radar 2.5s infinite cubic-bezier(0.16, 1, 0.3, 1);
}

.circle-1 { width: 30px; height: 30px; animation-delay: 0s; }
.circle-2 { width: 50px; height: 50px; animation-delay: 0.8s; }
.circle-3 { width: 70px; height: 70px; animation-delay: 1.6s; }

@keyframes radar {
    0% { transform: scale(0.6); opacity: 1; }
    100% { transform: scale(1.6); opacity: 0; }
}

.list-state h4 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
}

/* Email Item card */
.list-items {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.email-item {
    padding: 14px;
    border-radius: var(--radius-md);
    background: transparent;
    border: 1px solid transparent;
    cursor: pointer;
    transition: var(--transition-smooth);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.email-item:hover {
    background: rgba(255, 255, 255, 0.04);
}

.email-item.active {
    background: rgba(0, 113, 227, 0.15);
    border-color: rgba(0, 113, 227, 0.25);
}

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

.item-sender {
    font-weight: 500;
    font-size: 13px;
    color: var(--text-primary);
    max-width: 70%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-time {
    font-size: 10px;
    color: var(--text-secondary);
}

.item-subject {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.email-item.active .item-subject {
    color: #ffffff;
}

.item-snippet {
    font-size: 11px;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.4;
}

/* Detail Panel Placeholders */
.detail-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 40px;
    text-align: center;
}

.placeholder-icon {
    width: 32px;
    height: 32px;
    stroke: var(--text-muted);
    margin-bottom: 12px;
}

.detail-placeholder h3 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 4px;
}

.detail-placeholder p {
    font-size: 12px;
    color: var(--text-secondary);
    max-width: 280px;
}

/* Detail display */
.detail-content {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.detail-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.subject-line {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 14px;
}

.subject-line h2 {
    font-size: 18px;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: -0.2px;
}

.metadata-grid {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.meta-row {
    display: flex;
    font-size: 12px;
}

.meta-label {
    width: 50px;
    color: var(--text-secondary);
}

.meta-value {
    color: var(--text-primary);
    word-break: break-all;
}

/* Tabs */
.detail-tabs {
    display: flex;
    gap: 4px;
    padding: 10px 24px;
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid var(--border-color);
}

.tab-btn {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-secondary);
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.tab-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.04);
}

.tab-btn.active {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.08);
}

/* Body Rendering */
.body-container {
    flex: 1;
    overflow: hidden;
    background: #000000;
}

.tab-panel {
    width: 100%;
    height: 100%;
    overflow: auto;
    padding: 20px;
}

#emailFrame {
    width: 100%;
    height: 100%;
    border: none;
    background: #ffffff;
    border-radius: var(--radius-sm);
}

pre {
    font-family: 'SFMono-Regular', Consolas, Menlo, monospace;
    font-size: 12px;
    line-height: 1.6;
    color: #e5e5ea;
    white-space: pre-wrap;
    word-break: break-all;
}

/* Modal configuration */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(16px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal {
    width: 90%;
    max-width: 440px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.close-modal-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
}

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group input {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    color: var(--text-primary);
    font-size: 16px;
    outline: none;
    transition: var(--transition-smooth);
}

.form-group input:focus {
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.06);
}

.form-help {
    font-size: 10px;
    color: var(--text-secondary);
    line-height: 1.4;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(30, 30, 30, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #ffffff;
    backdrop-filter: blur(20px);
    padding: 10px 18px;
    border-radius: 980px; /* Capsule toast */
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 500;
    z-index: 200;
    animation: toast-in 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes toast-in {
    from { transform: translate(-50%, 20px); opacity: 0; }
    to { transform: translate(-50%, 0); opacity: 1; }
}

.hidden {
    display: none !important;
}

/* Back button in detail panel (hidden by default on desktop) */
.back-btn {
    display: none;
    align-items: center;
    gap: 4px;
    background: transparent;
    border: none;
    color: var(--primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    padding: 0 0 12px 0;
    outline: none;
    transition: var(--transition-smooth);
}

.back-btn:hover {
    color: var(--primary-hover);
}

.back-btn i {
    width: 18px;
    height: 18px;
}

/* Responsive adjustment */
@media (max-width: 820px) {
    .workspace-grid {
        grid-template-columns: 1fr;
        height: auto;
    }
    
    .inbox-panel {
        display: flex;
        height: 550px;
    }
    
    .detail-panel {
        display: none;
        height: 550px;
    }
    
    /* Toggle view for mobile devices */
    .workspace-grid.show-detail .inbox-panel {
        display: none;
    }
    
    .workspace-grid.show-detail .detail-panel {
        display: flex;
    }
    
    .back-btn {
        display: inline-flex;
    }
}

@media (max-width: 992px) {
    .email-input-group {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
    
    .action-buttons {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        width: 100%;
        margin-top: 4px;
    }
    
    .action-buttons .btn {
        width: 100%;
        padding: 10px 16px;
    }
}

@media (max-width: 580px) {
    .app-container {
        padding: 20px 16px;
    }
    
    .email-domain {
        font-size: 13px;
        max-width: 45%;
    }
    
    .input-wrapper input {
        font-size: 14px;
        padding: 8px 0;
    }
}

@media (max-width: 480px) {
    .app-header {
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
        margin-bottom: 24px;
    }
    
    .header-actions {
        width: 100%;
        justify-content: space-between;
    }
    
    .generator-card {
        padding: 16px;
    }
    
    .input-wrapper {
        padding: 4px 12px;
    }
    
    .subject-line {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    
    .subject-line h2 {
        font-size: 16px;
    }
    
    .detail-header {
        padding: 16px;
    }
    
    .detail-tabs {
        padding: 8px 12px;
        gap: 2px;
        justify-content: space-between;
    }
    
    .tab-btn {
        font-size: 11px;
        padding: 4px 6px;
        flex: 1;
        text-align: center;
    }
    
    .modal {
        padding: 16px;
        gap: 12px;
    }
}
