/* ── Reset ──────────────────────────────────────────────────────── */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg-app: #f6f8fc;
    --bg-card: #ffffff;
    --bg-hover: #f2f6fc;
    --bg-selected: #d3e3fd;
    --bg-unread: #ffffff;
    --bg-read: #f9f9f9;
    --border: #dadce0;
    --border-light: #e8eaed;
    --text-primary: #202124;
    --text-secondary: #5f6368;
    --text-muted: #80868b;
    --accent: #1a73e8;
    --accent-hover: #1765cc;
    --accent-dim: #e8f0fe;
    --success: #1e8e3e;
    --error: #d93025;
    --warning: #f9ab00;
    --shadow-sm: 0 1px 2px 0 rgba(60, 64, 67, 0.1);
    --shadow: 0 1px 3px 0 rgba(60, 64, 67, 0.15), 0 4px 8px 3px rgba(60, 64, 67, 0.1);
    --shadow-lg: 0 4px 16px rgba(60, 64, 67, 0.2);
    --transition: 0.15s ease;
}

html {
    font-size: 14px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Google Sans', 'Roboto', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-app);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    line-height: 1.5;
}

/* ── Top Bar ─────────────────────────────────────────────────────── */
#top-bar {
    height: 64px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    padding: 0 16px;
    position: relative;
    z-index: 100;
}

.topbar-left,
.topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 200px;
}

.topbar-right {
    justify-content: flex-end;
}

.topbar-center {
    flex: 1;
    padding: 0 32px;
    display: flex;
    justify-content: center;
}

.menu-btn {
    width: 40px;
    height: 40px;
    background: transparent;
    border: none;
    border-radius: 50%;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    transition: background var(--transition);
}
.menu-btn:hover { background: var(--bg-hover); }

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
}
.logo-text {
    font-size: 22px;
    font-weight: 500;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.search-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-app);
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 10px 16px;
    width: 100%;
    max-width: 720px;
    height: 48px;
    transition: all var(--transition);
}
.search-wrap:focus-within {
    background: var(--bg-card);
    border-color: var(--accent);
    box-shadow: var(--shadow);
}
.search-wrap svg { color: var(--text-secondary); flex-shrink: 0; }
#search-input {
    border: none;
    background: transparent;
    outline: none;
    flex: 1;
    font-size: 16px;
    color: var(--text-primary);
    font-family: inherit;
}
#search-input::placeholder { color: var(--text-muted); }

.icon-btn {
    width: 40px;
    height: 40px;
    background: transparent;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
}
.icon-btn:hover { background: rgba(60, 64, 67, 0.08); }

.icon-btn-sm {
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px 10px;
    font-size: 16px;
    transition: background var(--transition);
    font-family: inherit;
}
.icon-btn-sm:hover { background: var(--bg-hover); }

/* ── App Layout ─────────────────────────────────────────────────── */
#app-layout {
    display: grid;
    grid-template-columns: 256px 480px 1fr;
    height: calc(100vh - 64px);
    background: var(--bg-app);
}

/* ── Sidebar ────────────────────────────────────────────────────── */
#sidebar {
    background: var(--bg-app);
    border-right: 1px solid var(--border-light);
    overflow-y: auto;
    padding: 8px 0;
}

.compose-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 8px 0 16px 16px;
    padding: 12px 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: all var(--transition);
    font-family: inherit;
    max-width: 160px;
}
.compose-btn:hover {
    background: var(--bg-hover);
    box-shadow: var(--shadow);
    color: var(--text-primary);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 16px;
    height: 32px;
    border-radius: 0 16px 16px 0;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition);
}
.nav-item svg { color: var(--text-secondary); flex-shrink: 0; }
.nav-item:hover { background: var(--bg-hover); }
.nav-item.active {
    background: var(--accent-dim);
    color: var(--accent);
}
.nav-item.active svg { color: var(--accent); }

.nav-badge {
    margin-left: auto;
    background: var(--text-secondary);
    color: white;
    font-size: 12px;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 12px;
    min-width: 24px;
    text-align: center;
}
.nav-item.active .nav-badge {
    background: var(--accent);
}

.sidebar-accounts {
    border-top: 1px solid var(--border-light);
    margin-top: 16px;
    padding: 16px 0 0 0;
}

.sidebar-label {
    padding: 8px 16px 8px 24px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#sidebar-accounts-list {
    padding: 0 8px;
}

.sidebar-account {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 16px 6px 16px;
    border-radius: 0 16px 16px 0;
    cursor: pointer;
    transition: background var(--transition);
    font-size: 13px;
    color: var(--text-primary);
}
.sidebar-account:hover { background: var(--bg-hover); }
.sidebar-account.active { background: var(--accent-dim); color: var(--accent); }

.account-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.account-dot.online { background: var(--success); }
.account-dot.error { background: var(--error); }
.account-dot.syncing { background: var(--warning); animation: pulse 1.5s infinite; }

.sidebar-account-email {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-account-count {
    background: var(--bg-hover);
    color: var(--text-secondary);
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 8px;
    font-weight: 500;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ── Email List Pane ────────────────────────────────────────────── */
#mail-list-pane {
    background: var(--bg-card);
    border-right: 1px solid var(--border-light);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.list-header {
    height: 48px;
    padding: 0 16px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-app);
    flex-shrink: 0;
}

.list-title {
    display: flex;
    align-items: center;
    gap: 12px;
}
.list-title h2 {
    font-size: 18px;
    font-weight: 500;
    color: var(--text-primary);
}
#list-count {
    background: var(--bg-hover);
    color: var(--text-secondary);
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.list-tools {
    display: flex;
    align-items: center;
    gap: 8px;
}
#account-filter {
    padding: 6px 10px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    max-width: 200px;
}

.email-list {
    flex: 1;
    overflow-y: auto;
}

.email-item {
    display: grid;
    grid-template-columns: 40px 200px 1fr 120px;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
    cursor: pointer;
    transition: background var(--transition);
    align-items: center;
}
.email-item:hover { background: var(--bg-hover); box-shadow: inset 1px 0 0 var(--border), inset -1px 0 0 var(--border), 0 1px 2px 0 rgba(60,64,67,.09), 0 1px 3px 1px rgba(60,64,67,.06); }
.email-item.selected { background: var(--bg-selected); }
.email-item.unread .email-from,
.email-item.unread .email-subject {
    font-weight: 700;
}

.email-checkbox {
    width: 16px;
    height: 16px;
    border: 2px solid var(--text-muted);
    border-radius: 2px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.email-from {
    font-size: 14px;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.email-content {
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.email-subject {
    font-size: 14px;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
}

.email-snippet {
    font-size: 12px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.code-badge {
    display: inline-flex;
    align-items: center;
    background: #fef7e0;
    color: #b06000;
    font-size: 11px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 4px;
    font-family: 'Roboto Mono', monospace;
    border: 1px solid #fdd663;
}

.email-date {
    font-size: 12px;
    color: var(--text-secondary);
    text-align: right;
    white-space: nowrap;
}

/* Empty state */
.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    text-align: center;
    padding: 40px;
}
.empty-state h3 {
    font-size: 18px;
    color: var(--text-secondary);
    margin-top: 16px;
    font-weight: 400;
}
.empty-state p {
    margin-top: 8px;
    font-size: 14px;
}

/* ── Detail Pane ────────────────────────────────────────────────── */
#mail-detail-pane {
    background: var(--bg-card);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.detail-header {
    height: 48px;
    padding: 0 16px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-app);
    flex-shrink: 0;
}

.detail-content {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
}

.detail-empty {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    text-align: center;
}
.detail-empty h3 {
    margin-top: 16px;
    font-size: 16px;
    color: var(--text-secondary);
    font-weight: 400;
}
.detail-empty p {
    margin-top: 8px;
    font-size: 14px;
}

.email-detail-meta {
    border-bottom: 1px solid var(--border-light);
    padding-bottom: 16px;
    margin-bottom: 16px;
}

.email-detail-subject {
    font-size: 22px;
    font-weight: 400;
    color: var(--text-primary);
    margin-bottom: 16px;
    line-height: 1.3;
}

.sender-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 500;
    font-size: 16px;
    flex-shrink: 0;
}

.sender-info { flex: 1; }
.sender-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}
.sender-email {
    font-size: 12px;
    color: var(--text-secondary);
}

.email-date-full {
    font-size: 12px;
    color: var(--text-secondary);
}

.email-detail-body {
    line-height: 1.6;
    color: var(--text-primary);
    word-wrap: break-word;
}
.email-detail-body iframe {
    width: 100%;
    min-height: 400px;
    border: none;
    background: white;
}

.code-display {
    background: #e6f4ea;
    border: 2px dashed #1e8e3e;
    border-radius: 8px;
    padding: 16px;
    margin: 16px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}
.code-display-text {
    font-family: 'Roboto Mono', monospace;
    font-size: 24px;
    font-weight: 700;
    color: #137333;
    letter-spacing: 2px;
}
.code-display-copy {
    background: var(--accent);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    font-family: inherit;
    transition: background var(--transition);
}
.code-display-copy:hover { background: var(--accent-hover); }

/* ── Modal ──────────────────────────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.modal-overlay.active { display: flex; }

.modal {
    background: var(--bg-card);
    border-radius: 8px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.2s ease;
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-header h3 { font-size: 18px; font-weight: 500; }
.modal-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    padding: 0 8px;
    line-height: 1;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-hint {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 12px;
}
.modal-hint code {
    background: var(--bg-app);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Roboto Mono', monospace;
    font-size: 12px;
    color: var(--accent);
}

#import-textarea {
    width: 100%;
    min-height: 200px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: 'Roboto Mono', monospace;
    font-size: 13px;
    resize: vertical;
}
#import-textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.import-actions {
    margin-top: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.btn-primary {
    background: var(--accent);
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 4px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: background var(--transition);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--border);
    padding: 10px 16px;
    border-radius: 4px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: background var(--transition);
}
.btn-secondary:hover { background: var(--bg-hover); }

.btn-danger {
    background: transparent;
    color: var(--error);
    border: 1px solid var(--error);
    padding: 10px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    transition: background var(--transition);
}
.btn-danger:hover { background: rgba(217, 48, 37, 0.08); }

.setting-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-light);
}
.setting-row label {
    min-width: 200px;
    color: var(--text-secondary);
}
.setting-row input[type="number"] {
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    width: 100px;
    font-family: inherit;
}

/* ── Toast ──────────────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast-item {
    pointer-events: auto;
    background: #323232;
    color: white;
    padding: 14px 24px;
    border-radius: 4px;
    box-shadow: var(--shadow-lg);
    font-size: 14px;
    max-width: 500px;
    animation: toastSlideUp 0.2s ease;
}
.toast-item.success { background: var(--success); }
.toast-item.error { background: var(--error); }
.toast-item.warning { background: var(--warning); color: #202124; }

@keyframes toastSlideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ── Sync indicator ─────────────────────────────────────────────── */
.sync-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    background: var(--bg-hover);
    border-radius: 12px;
    font-size: 12px;
    color: var(--text-secondary);
    margin-left: 12px;
}
.sync-indicator.syncing {
    color: var(--warning);
}
.sync-indicator .spinner {
    width: 12px;
    height: 12px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 1200px) {
    #app-layout {
        grid-template-columns: 256px 380px 1fr;
    }
}

@media (max-width: 900px) {
    #app-layout {
        grid-template-columns: 64px 1fr;
    }
    #mail-detail-pane { display: none; }
    #mail-detail-pane.active { display: flex; grid-column: 1 / -1; }
    .compose-btn span { display: none; }
    .nav-item span { display: none; }
    .nav-item { justify-content: center; padding: 0; }
    .nav-badge { display: none; }
    .topbar-center { padding: 0 16px; }
    .search-wrap { max-width: 100%; }
}
