/* ============ CSS Variables & Themes ============ */
:root {
    /* Light Theme (default) */
    --bg-primary: #f5f7fa;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e8ecf1;
    --text-primary: #1a1a2e;
    --text-secondary: #4a4a6a;
    --text-muted: #8a8aa3;
    --accent-primary: #6366f1;
    --accent-secondary: #818cf8;
    --accent-hover: #4f46e5;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
    
    /* Sizes */
    --sidebar-width: 280px;
    --header-height: 60px;
    --border-radius: 12px;
    --border-radius-sm: 8px;
    
    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
}

[data-theme="dark"] {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #252542;
    --text-primary: #f0f0f5;
    --text-secondary: #b0b0c5;
    --text-muted: #6a6a85;
    --accent-primary: #818cf8;
    --accent-secondary: #a5b4fc;
    --accent-hover: #6366f1;
    --border-color: #2d2d4a;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.4);
}

/* ============ Reset & Base ============ */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    transition: background-color var(--transition-normal), color var(--transition-normal);
}

/* ============ App Layout ============ */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* ============ Sidebar ============ */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    z-index: 100;
    transition: transform var(--transition-normal), background-color var(--transition-normal);
}

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

.sidebar-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.theme-toggle {
    background: var(--bg-tertiary);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: background-color var(--transition-fast), transform var(--transition-fast);
}

.theme-toggle:hover {
    background: var(--accent-primary);
    transform: rotate(15deg);
}

.saved-inboxes {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

.saved-inboxes h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 10px;
    padding: 0 10px;
}

.saved-inboxes ul {
    list-style: none;
}

.saved-inboxes li {
    margin-bottom: 4px;
}

.inbox-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: background-color var(--transition-fast);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    gap: 10px;
}

.inbox-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.inbox-item.active {
    background: var(--accent-primary);
    color: white;
}

.inbox-item .inbox-icon {
    font-size: 1rem;
}

.inbox-item .inbox-email {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.inbox-item .inbox-remove {
    opacity: 0;
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: opacity var(--transition-fast), background-color var(--transition-fast);
}

.inbox-item:hover .inbox-remove {
    opacity: 0.7;
}

.inbox-item .inbox-remove:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.2);
}

.sidebar-toggle {
    display: none;
    position: absolute;
    right: -45px;
    top: 10px;
    width: 40px;
    height: 40px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-size: 1.2rem;
    z-index: 101;
}

/* ============ Main Content ============ */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 30px;
    max-width: 900px;
    width: 100%;
}

/* ============ Email Section ============ */
.email-section {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 20px;
    margin-bottom: 25px;
    box-shadow: var(--shadow-md);
}

.email-grid {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 15px;
    align-items: end;
}

.email-col-1 {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.email-input-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.email-input {
    flex: 1;
    min-width: 0;
    padding: 10px 15px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
}

.email-input:focus {
    border-color: var(--accent-primary);
}

.email-input::placeholder {
    color: var(--text-muted);
}

.at-symbol {
    color: var(--text-muted);
    font-weight: 500;
}

.domain-select {
    padding: 10px 15px;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 1rem;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    outline: none;
    min-width: 140px;
}

.domain-select:focus {
    border-color: var(--accent-primary);
}

.btn-icon-only {
    padding: 10px 12px;
}

.current-email-box {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 15px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    background: var(--bg-tertiary);
}

.current-email-box .label {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.current-email-box .email {
    font-weight: 600;
    color: var(--accent-primary);
    font-size: 1rem;
}

.email-col-2 {
    display: flex;
    align-items: stretch;
}

.btn-check {
    height: 100%;
    padding: 15px 25px;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    border-radius: var(--border-radius-sm);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

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

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-small {
    padding: 8px 12px;
    font-size: 0.85rem;
}

@media (max-width: 700px) {
    .email-grid {
        grid-template-columns: 1fr;
    }
    .email-input-row {
        flex-wrap: wrap;
    }
    .email-input {
        width: 100%;
        flex: none;
    }
    .email-input-row .btn .btn-text {
        display: none;
    }
    .email-col-2 {
        width: 100%;
    }
    .btn-check {
        width: 100%;
        justify-content: center;
    }
}

/* ============ Messages Section ============ */
.messages-section {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

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

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

.messages-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.auto-refresh-indicator {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.messages-list {
    min-height: 300px;
    max-height: 500px;
    overflow-y: auto;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state .empty-icon {
    font-size: 4rem;
    margin-bottom: 15px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 1.1rem;
    margin-bottom: 5px;
}

.empty-state small {
    font-size: 0.85rem;
}

/* Messages Table Header */
.messages-table-header {
    display: grid;
    grid-template-columns: 160px 1fr 80px;
    gap: 30px;
    padding: 10px 15px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.messages-table-header .col-date {
    text-align: right;
}

@media (max-width: 600px) {
    .messages-table-header {
        display: none;
    }
}

/* Message Item - Row style */
.message-item {
    display: grid;
    grid-template-columns: 160px 1fr 80px;
    align-items: center;
    padding: 10px 15px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background-color var(--transition-fast);
    gap: 30px;
}

.message-item:hover {
    background: var(--bg-tertiary);
}

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

.message-from {
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.9rem;
}

.message-content {
    display: flex;
    align-items: center;
    min-width: 0;
    overflow: hidden;
    width: 100%;
}

.message-subject {
    font-size: 0.9rem;
    color: var(--text-primary);
    white-space: nowrap;
    flex-shrink: 0;
}

.message-preview {
    font-size: 0.85rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
    margin-left: 6px;
}

.message-preview::before {
    content: "— ";
}

.message-date {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
    text-align: right;
}

@media (max-width: 600px) {
    .message-item {
        grid-template-columns: 1fr auto;
        grid-template-rows: auto auto;
        gap: 5px 15px;
    }
    .message-from {
        grid-column: 1;
    }
    .message-date {
        grid-column: 2;
        grid-row: 1;
    }
    .message-content {
        grid-column: 1 / -1;
        grid-row: 2;
    }
}

/* ============ Pagination ============ */
.pagination {
    display: none;
    justify-content: center;
    align-items: center;
    gap: 5px;
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
}

.pagination-btn {
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.pagination-btn:hover:not(.disabled):not(.active) {
    background: var(--bg-tertiary);
    border-color: var(--accent-primary);
}

.pagination-btn.active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

.pagination-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.pagination-dots {
    padding: 0 5px;
    color: var(--text-muted);
}

/* ============ Modal ============ */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    backdrop-filter: blur(4px);
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    width: 100%;
    max-width: 800px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: modalSlideIn 0.25s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: 15px;
}

.modal-close {
    background: var(--bg-tertiary);
    border: none;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.modal-close:hover {
    background: var(--danger);
    color: white;
}

.modal-meta {
    padding: 15px 25px;
    background: var(--bg-tertiary);
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
}

.meta-item {
    display: flex;
    gap: 8px;
    font-size: 0.9rem;
}

.meta-item .label {
    color: var(--text-muted);
}

.modal-tabs {
    display: flex;
    padding: 0 25px;
    border-bottom: 1px solid var(--border-color);
}

.tab-btn {
    padding: 12px 20px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all var(--transition-fast);
}

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

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

.modal-body {
    flex: 1;
    overflow: auto;
    min-height: 300px;
}

.tab-content {
    display: none;
    height: 100%;
}

.tab-content.active {
    display: block;
}

.tab-content iframe {
    width: 100%;
    height: 350px;
    border: none;
    background: white;
}

.tab-content pre {
    padding: 20px 25px;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.85rem;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text-secondary);
    line-height: 1.7;
}

.modal-footer {
    padding: 15px 25px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
}

/* ============ Toast Notifications ============ */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: var(--bg-secondary);
    border-radius: var(--border-radius-sm);
    padding: 15px 20px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 12px;
    animation: toastSlideIn 0.3s ease;
    border-left: 4px solid var(--accent-primary);
}

.toast.success {
    border-left-color: var(--success);
}

.toast.error {
    border-left-color: var(--danger);
}

.toast.warning {
    border-left-color: var(--warning);
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateX(100px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.toast-icon {
    font-size: 1.2rem;
}

.toast-message {
    font-size: 0.9rem;
    color: var(--text-primary);
}

/* ============ Responsive ============ */
@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
    }
    
    .sidebar.active {
        transform: translateX(0);
    }
    
    .sidebar-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .main-content {
        margin-left: 0;
        padding: 20px;
    }
}

@media (max-width: 600px) {
    .email-input-wrapper {
        flex-direction: column;
        gap: 10px;
    }
    
    .email-input-wrapper input,
    .email-input-wrapper select {
        width: 100%;
    }
    
    .at-symbol {
        display: none;
    }
    
    .email-actions {
        flex-direction: column;
    }
    
    .email-actions .btn {
        width: 100%;
        justify-content: center;
    }
    
    .message-header {
        flex-direction: column;
        gap: 5px;
    }
    
    .message-from {
        max-width: 100%;
    }
    
    .modal-content {
        max-height: 100vh;
        border-radius: 0;
    }
    
    .modal-meta {
        flex-direction: column;
        gap: 10px;
    }
}

/* ============ Scrollbar ============ */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ============ Loading Spinner ============ */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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