/* ── Reset & Base ─────────────────────────────────────────────────────── */

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

:root {
    --bg-dark: #0f1117;
    --bg-sidebar: #161822;
    --bg-card: #1c1f2e;
    --bg-card-hover: #242840;
    --bg-input: #1c1f2e;
    --border: #2a2d3e;
    --text-primary: #e4e6f0;
    --text-secondary: #8b8fa3;
    --text-muted: #5c6078;
    --accent: #6c63ff;
    --accent-glow: rgba(108, 99, 255, .25);
    --accent-hover: #7b73ff;
    --danger: #ff4d6a;
    --danger-hover: #ff6680;
    --success: #2dd4a8;
    --radius: 12px;
    --radius-sm: 8px;
    --transition: .2s ease;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

html,
body {
    height: 100%;
    font-family: var(--font);
    background: var(--bg-dark);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

/* ── Layout ───────────────────────────────────────────────────────────── */

.app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────────────────── */

.sidebar {
    width: 300px;
    min-width: 300px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

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

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 16px;
    color: var(--accent);
}

.btn-add {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.btn-add:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    box-shadow: 0 0 16px var(--accent-glow);
}

.account-list {
    list-style: none;
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.account-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    margin-bottom: 2px;
}

.account-item:hover {
    background: var(--bg-card-hover);
}

.account-item.active {
    background: var(--accent);
    color: #fff;
}

.account-item.active .account-email {
    color: #fff;
}

.account-item.active .btn-delete {
    color: rgba(255, 255, 255, .6);
}

.account-item.active .btn-delete:hover {
    color: #fff;
}

.account-info {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.account-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--bg-card);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    color: var(--accent);
    flex-shrink: 0;
}

.account-item.active .account-avatar {
    background: rgba(255, 255, 255, .15);
    color: #fff;
}

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

.btn-delete {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: all var(--transition);
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.btn-delete:hover {
    color: var(--danger);
    background: rgba(255, 77, 106, .1);
}

/* ── Main ─────────────────────────────────────────────────────────────── */

.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.main-header {
    padding: 22px 28px;
    border-bottom: 1px solid var(--border);
}

.main-header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.main-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.main-header p {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 3px;
}

.time-picker {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.time-picker label {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .5px;
}

.time-picker select {
    padding: 7px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 13px;
    cursor: pointer;
    outline: none;
    transition: border-color var(--transition);
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238b8fa3' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
}

.time-picker select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.time-picker select option {
    background: var(--bg-sidebar);
    color: var(--text-primary);
}

.email-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

/* ── Empty / Loading states ───────────────────────────────────────────── */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 12px;
    color: var(--text-muted);
    font-size: 14px;
}

.loading-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

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

/* ── Email cards ──────────────────────────────────────────────────────── */

.email-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
    transition: all var(--transition);
    animation: fadeIn .25s ease;
    overflow: hidden;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.email-card.expanded {
    border-color: var(--accent);
    box-shadow: 0 0 20px var(--accent-glow);
}

/* Subject row */
.email-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    cursor: pointer;
    transition: background var(--transition);
}

.email-row:hover {
    background: var(--bg-card-hover);
}

.email-subject {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.email-date {
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
    white-space: nowrap;
}

.btn-delete-email {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: all var(--transition);
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.btn-delete-email:hover {
    color: var(--danger);
    background: rgba(255, 77, 106, .1);
}

/* Expanded body area */
.email-body {
    display: none;
    border-top: 1px solid var(--border);
    padding: 16px 18px;
    animation: fadeIn .2s ease;
}

.email-card.expanded .email-body {
    display: block;
}

.email-body-meta {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    line-height: 1.6;
}

.email-body-meta strong {
    color: var(--text-primary);
    font-weight: 600;
}

.email-body-content {
    font-size: 13px;
    color: var(--text-primary);
    line-height: 1.7;
    max-height: 400px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.email-body-content iframe {
    width: 100%;
    min-height: 300px;
    border: none;
    border-radius: var(--radius-sm);
    background: #fff;
}

.email-body-loading {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-muted);
    font-size: 13px;
}

.email-body-loading .spinner {
    width: 18px;
    height: 18px;
    border-width: 2px;
}

/* ── Error banner ─────────────────────────────────────────────────────── */

.error-banner {
    background: rgba(255, 77, 106, .1);
    border: 1px solid var(--danger);
    border-radius: var(--radius-sm);
    padding: 14px 18px;
    color: var(--danger);
    font-size: 13px;
    margin: 20px;
    animation: fadeIn .3s ease;
}

/* ── Modal ────────────────────────────────────────────────────────────── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .6);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease;
}

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

.modal {
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 420px;
    max-width: 92vw;
    padding: 28px;
    transform: translateY(20px) scale(.97);
    transition: transform .25s ease;
}

.modal-overlay.open .modal {
    transform: translateY(0) scale(1);
}

.modal h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 20px;
}

.field {
    margin-bottom: 16px;
}

.field label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: .5px;
}

.field input {
    width: 100%;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 14px;
    outline: none;
    transition: border-color var(--transition);
}

.field input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

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

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 24px;
}

.btn {
    padding: 9px 20px;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-cancel {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.btn-cancel:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

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

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 0 20px var(--accent-glow);
}

.btn-primary:disabled {
    opacity: .5;
    cursor: not-allowed;
}

/* ── Scrollbar ────────────────────────────────────────────────────────── */

::-webkit-scrollbar {
    width: 6px;
}

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

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

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

/* ── Responsive ───────────────────────────────────────────────────────── */

@media (max-width: 700px) {
    .sidebar {
        width: 64px;
        min-width: 64px;
    }

    .logo span,
    .account-email {
        display: none;
    }

    .sidebar-header {
        justify-content: center;
        padding: 16px 8px;
    }

    .account-item {
        justify-content: center;
        padding: 10px 0;
    }

    .account-info {
        justify-content: center;
    }

    .btn-delete {
        display: none;
    }
}