/* EmailBeep — Minimal CSS */
/* System font stack, CSS custom properties, mobile-first */

:root {
    --c-primary: #2563eb;
    --c-primary-hover: #1d4ed8;
    --c-bg: #ffffff;
    --c-bg-alt: #f9fafb;
    --c-text: #111827;
    --c-text-muted: #6b7280;
    --c-border: #e5e7eb;
    --c-unread: #1e3a5f;
    --c-danger: #dc2626;
    --c-success: #16a34a;
    --c-star: #eab308;
    --sidebar-w: 260px;
    --header-h: 56px;
    --radius: 6px;
}

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

html { height: 100%; }
body { height: 100%; }
body:has(.app) { overflow: hidden; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--c-text);
    background: var(--c-bg);
}

a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

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

.sidebar {
    width: var(--sidebar-w);
    background: var(--c-bg-alt);
    border-right: 1px solid var(--c-border);
    overflow-y: auto;
    flex-shrink: 0;
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 40;
    transition: transform .2s;
}

.main {
    flex: 1;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: 100vh;
    overflow: hidden;
}

.header {
    height: var(--header-h);
    flex-shrink: 0;
    border-bottom: 1px solid var(--c-border);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 12px;
    background: var(--c-bg);
    z-index: 30;
}

.header-title { font-size: 18px; font-weight: 600; white-space: nowrap; }
.header-spacer { flex: 1; }

.content { flex: 1; overflow-y: auto; min-height: 0; display: flex; flex-direction: column; }

/* Sidebar */
.sidebar-brand { padding: 16px; font-size: 18px; font-weight: 700; color: var(--c-primary); border-bottom: 1px solid var(--c-border); }
.sidebar-nav { padding: 8px 0; }

.sidebar-item {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    color: var(--c-text);
    gap: 8px;
    cursor: pointer;
    font-size: 13px;
}
.sidebar-item:hover { background: var(--c-border); text-decoration: none; }
.sidebar-item.active { background: #dbeafe; color: var(--c-primary); font-weight: 600; }
.sidebar-item .badge {
    margin-left: auto;
    background: var(--c-primary);
    color: #fff;
    border-radius: 10px;
    padding: 1px 7px;
    font-size: 11px;
    font-weight: 600;
}
.sidebar-account { padding: 10px 16px 4px; font-size: 12px; font-weight: 600; text-transform: uppercase; color: var(--c-text-muted); display: flex; align-items: center; gap: 6px; }
.sidebar-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.sidebar-folder { padding-left: 38px; }

.sidebar-toggle { display: none; background: none; border: none; cursor: pointer; padding: 8px; }

/* Collapsible sidebar accounts */
.sidebar-collapsible { cursor: pointer; user-select: none; }
.sidebar-collapsible .collapse-arrow {
    margin-left: auto;
    transition: transform .2s;
    flex-shrink: 0;
}
.sidebar-collapsible.collapsed .collapse-arrow { transform: rotate(-90deg); }
.sidebar-folders { overflow: hidden; transition: max-height .2s ease; }
.sidebar-folders.collapsed { max-height: 0 !important; overflow: hidden; }
.sidebar-collapsible .badge { margin-left: 0; margin-right: 4px; }

/* Message list */
.msg-list { list-style: none; }
.msg-row {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    border-bottom: 1px solid var(--c-border);
    gap: 10px;
    cursor: pointer;
    text-decoration: none;
    color: var(--c-text);
}
.msg-row:hover { background: var(--c-bg-alt); text-decoration: none; }
.msg-row.unread { font-weight: 600; }
.msg-row.unread .msg-subject { color: var(--c-unread); }
.msg-row.active-pane { background: #dbeafe; }
.msg-row.selected { background: #eff6ff; }
.msg-row.selected:hover { background: #dbeafe; }

/* Bulk action bar */
.bulk-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: #eff6ff;
    border-bottom: 1px solid var(--c-border);
    font-size: 13px;
    font-weight: 600;
}
.bulk-bar .btn { font-size: 12px; padding: 4px 10px; }

.msg-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.msg-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 14px; color: #fff;
    flex-shrink: 0;
    text-transform: uppercase;
}
.msg-body { flex: 1; min-width: 0; }
.msg-top { display: flex; align-items: baseline; gap: 6px; }
.msg-from { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.msg-subject { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-snippet { font-size: 12px; color: var(--c-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.msg-date { font-size: 11px; color: var(--c-text-muted); white-space: nowrap; }
.msg-star { background: none; border: none; cursor: pointer; font-size: 16px; color: var(--c-border); padding: 0; line-height: 1; }
.msg-star.starred { color: var(--c-star); }

/* Message view (full page) */
.msg-view { max-width: 900px; margin: 0 auto; padding: 20px; }
.msg-view-header { margin-bottom: 16px; }
.msg-view-subject { font-size: 22px; font-weight: 600; margin-bottom: 8px; }
.msg-view-meta { font-size: 13px; color: var(--c-text-muted); }
.msg-view-meta span { margin-right: 12px; }
.msg-view-body { padding: 16px 0; line-height: 1.6; }
.msg-view-body iframe { width: 100%; border: none; min-height: 300px; }
.msg-view-actions { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.msg-attachments { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--c-border); }
.msg-attachment { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border: 1px solid var(--c-border); border-radius: var(--radius); margin: 4px 4px 4px 0; font-size: 13px; }

/* Split pane layout */
.split-pane { display: flex; flex: 1; min-height: 0; }
.split-list { flex: 1; overflow-y: auto; min-width: 0; border-right: 1px solid var(--c-border); }
.split-reading {
    flex: 1;
    overflow-y: auto;
    display: none;
    padding: 16px;
}
.reading-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: var(--c-text-muted); gap: 8px; font-size: 14px; }

/* Reading pane content */
.pane-header { margin-bottom: 12px; }
.pane-header .msg-view-subject { font-size: 18px; }
.pane-actions { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.pane-body { line-height: 1.6; }
.pane-body iframe { width: 100%; border: none; min-height: 300px; }

/* Show reading pane on desktop */
@media (min-width: 1024px) {
    .split-reading { display: block; }
    .split-list { max-width: 420px; flex: 0 0 420px; }
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--c-border);
    background: var(--c-bg);
    color: var(--c-text);
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
}
.btn:hover { background: var(--c-bg-alt); text-decoration: none; }
.btn-primary { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }
.btn-primary:hover { background: var(--c-primary-hover); }
.btn-danger { color: var(--c-danger); border-color: var(--c-danger); }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 4px; }
.form-control {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    outline: none;
}
.form-control:focus { border-color: var(--c-primary); box-shadow: 0 0 0 2px rgba(37,99,235,.15); }
select.form-control { appearance: auto; }
.form-row { display: flex; gap: 12px; }
.form-row > .form-group { flex: 1; }

/* Toggle label (checkbox inline) */
.toggle-label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; font-weight: normal; }
.toggle-label input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }

/* Search */
.search-input {
    flex: 1;
    padding: 7px 12px;
    border: 1px solid var(--c-border);
    border-radius: 20px;
    font-size: 13px;
    outline: none;
    max-width: 400px;
    font-family: inherit;
}
.search-input:focus { border-color: var(--c-primary); }
.search-results {
    position: absolute;
    top: calc(var(--header-h) - 2px);
    left: 16px;
    right: 16px;
    max-width: 600px;
    background: var(--c-bg);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0,0,0,.1);
    max-height: 400px;
    overflow-y: auto;
    display: none;
    z-index: 50;
}
.search-results.open { display: block; }
.search-result-item { padding: 8px 12px; border-bottom: 1px solid var(--c-border); cursor: pointer; display: block; color: var(--c-text); }
.search-result-item:hover { background: var(--c-bg-alt); text-decoration: none; }
.search-result-meta { display: flex; gap: 8px; align-items: center; font-size: 11px; color: var(--c-text-muted); margin-top: 2px; }
.search-result-meta .search-dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }

/* Alerts */
.alert { padding: 10px 16px; border-radius: var(--radius); margin: 12px 16px; font-size: 13px; flex-shrink: 0; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

/* Compose */
.compose-form { max-width: 800px; margin: 0 auto; padding: 20px; }
trix-editor { min-height: 250px; border: 1px solid var(--c-border); border-radius: var(--radius); padding: 8px; font-size: 14px; }
trix-toolbar { border: 1px solid var(--c-border); border-bottom: none; border-radius: var(--radius) var(--radius) 0 0; }
trix-editor { border-radius: 0 0 var(--radius) var(--radius); }

/* Accounts */
.account-list { list-style: none; }
.account-card {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--c-border);
    gap: 12px;
}
.account-card-info { flex: 1; }
.account-card-label { font-weight: 600; font-size: 14px; }
.account-card-email { font-size: 12px; color: var(--c-text-muted); }
.account-card-status { font-size: 11px; color: var(--c-text-muted); }
.account-card-actions { display: flex; gap: 6px; }

/* Color picker */
.color-input { width: 40px; height: 34px; padding: 2px; border: 1px solid var(--c-border); border-radius: var(--radius); cursor: pointer; }

/* Settings page */
.settings-page { max-width: 700px; margin: 0 auto; padding: 20px; }
.settings-header { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.settings-header h2 { font-size: 18px; margin: 0; }
fieldset { border: 1px solid var(--c-border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
legend { font-size: 13px; font-weight: 600; text-transform: uppercase; color: var(--c-text-muted); padding: 0 6px; }
.filter-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }

/* Auth pages */
.auth-page { display: flex; justify-content: center; align-items: center; min-height: 100vh; background: var(--c-bg-alt); }
.auth-card { background: var(--c-bg); border-radius: 8px; padding: 32px; width: 100%; max-width: 400px; box-shadow: 0 1px 3px rgba(0,0,0,.1); margin: 16px; }
.auth-card h1 { font-size: 22px; margin-bottom: 8px; }
.auth-card p { color: var(--c-text-muted); margin-bottom: 20px; font-size: 14px; }
.auth-link { text-align: center; margin-top: 16px; font-size: 13px; }

/* Spinner */
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
.empty-state { text-align: center; padding: 60px 20px; color: var(--c-text-muted); flex-shrink: 0; }
.empty-state svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: .5; }
.empty-state h2 { font-size: 16px; margin-bottom: 4px; color: var(--c-text); }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }

/* Filter bar */
.filter-bar {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--c-border);
    background: var(--c-bg);
    padding: 0 16px;
    flex-shrink: 0;
}
.filter-tab {
    padding: 8px 14px;
    font-size: 13px;
    color: var(--c-text-muted);
    border-bottom: 2px solid transparent;
    cursor: pointer;
    white-space: nowrap;
}
.filter-tab:hover { color: var(--c-text); text-decoration: none; }
.filter-tab.active { color: var(--c-primary); border-bottom-color: var(--c-primary); font-weight: 600; }

/* Thread view */
.thread-count { font-size: 12px; color: var(--c-text-muted); }
.thread-message { border-bottom: 1px solid var(--c-border); padding: 12px 0; }
.thread-message:last-child { border-bottom: none; }
.thread-message-header { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; }
.thread-message-header strong { font-size: 13px; }
.thread-date { font-size: 11px; color: var(--c-text-muted); }
.thread-current { background: #f0f9ff; padding: 12px; border-radius: var(--radius); margin: 4px -12px; }
.thread-collapsed .thread-message-header { cursor: pointer; }
.thread-collapsed .thread-message-header:hover { color: var(--c-primary); }
.thread-toggle { font-size: 12px; }
.thread-toggle.active { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }

/* Resize handles */
.resize-handle {
    width: 4px;
    cursor: col-resize;
    background: transparent;
    flex-shrink: 0;
    z-index: 41;
}
.resize-handle:hover,
.resize-handle.dragging { background: var(--c-primary); opacity: .4; }
#sidebar-resize {
    position: fixed;
    top: 0;
    bottom: 0;
    left: var(--sidebar-w);
}
.resize-handle-v { position: relative; z-index: 31; }
body.resizing { cursor: col-resize; user-select: none; }

/* Loading sentinel for infinite scroll */
#scroll-sentinel { height: 1px; }

/* Mobile */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); width: 280px; }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; }
    .sidebar-toggle { display: block; }
    .header { padding: 0 8px; gap: 6px; }
    .header-title { font-size: 15px; }
    .header-spacer { display: none; }
    .search-wrapper { flex: 1; min-width: 0; }
    .search-input { max-width: none; padding: 6px 10px; font-size: 12px; }
    .header .btn-sm { padding: 4px 8px; font-size: 11px; }
    .msg-from { max-width: 120px; }
    .form-row { flex-direction: column; gap: 0; }
    .msg-view { padding: 12px; }
    .compose-form { padding: 12px; }
    .content { overflow-y: auto; }
    .split-pane { flex-direction: column; flex: none; }
    .split-list { border-right: none; max-width: none; flex: none; overflow-y: visible; }
    .split-reading { display: none; }
    .resize-handle { display: none; }
    .filter-row { flex-wrap: wrap; }
}

/* Overlay for mobile sidebar */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.3);
    z-index: 35;
}
.sidebar-overlay.open { display: block; }

/* Landing page */
.landing { max-width: 960px; margin: 0 auto; padding: 20px; }
.landing-hero { text-align: center; padding: 60px 20px 40px; }
.landing-hero h1 { font-size: 36px; font-weight: 800; margin-bottom: 12px; letter-spacing: -.5px; }
.landing-hero p { font-size: 18px; color: var(--c-text-muted); max-width: 520px; margin: 0 auto 24px; line-height: 1.6; }
.landing-cta { display: flex; gap: 12px; justify-content: center; }
.btn-lg { padding: 12px 28px; font-size: 15px; }
.landing-features { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; padding: 20px 0 40px; }
.feature-card { background: var(--c-bg-alt); border: 1px solid var(--c-border); border-radius: 8px; padding: 20px; }
.feature-card svg { color: var(--c-primary); margin-bottom: 10px; }
.feature-card h3 { font-size: 15px; margin-bottom: 6px; }
.feature-card p { font-size: 13px; color: var(--c-text-muted); line-height: 1.5; }
.landing-footer { text-align: center; padding: 20px; font-size: 13px; color: var(--c-text-muted); border-top: 1px solid var(--c-border); }

/* Landing nav bar */
.landing-nav { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--c-border); }
.landing-nav-brand { font-size: 18px; font-weight: 700; color: var(--c-primary); }
.landing-nav-spacer { flex: 1; }
.landing-nav a.btn { margin-left: 8px; }

/* Test connection result */
.test-result { padding: 8px 12px; border-radius: var(--radius); margin-top: 8px; font-size: 13px; display: none; }
.test-result.success { display: block; background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.test-result.error { display: block; background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.test-result.loading { display: block; background: var(--c-bg-alt); color: var(--c-text-muted); border: 1px solid var(--c-border); }

/* Refresh indicator */
.refresh-indicator { font-size: 11px; color: var(--c-text-muted); padding: 2px 8px; }

@media (max-width: 768px) {
    .landing-hero h1 { font-size: 26px; }
    .landing-hero p { font-size: 15px; }
    .landing-cta { flex-direction: column; align-items: center; }
}
