/* ============================================================
   Amral Mail - Clean unified inbox UI
   ============================================================ */

:root {
    --primary: #673de6;
    --primary-dark: #5527d6;
    --primary-light: #f1ecff;
    --text-main: #1a1a2e;
    --text-muted: #6b7280;
    --text-faint: #9ca3af;
    --border: #e5e7eb;
    --bg-app: #f7f7fb;
    --bg-panel: #ffffff;
    --bg-hover: #f3f1fd;
    --success: #16a34a;
    --error: #dc2626;
    --warning: #d97706;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
    --shadow-md: 0 4px 16px rgba(16, 24, 40, 0.12);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: var(--text-main);
    background: var(--bg-app);
    -webkit-font-smoothing: antialiased;
}

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

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 16px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 600;
    border: 1px solid transparent; cursor: pointer; transition: all .15s ease;
    background: #fff; color: var(--text-main);
}
.btn:hover { filter: brightness(0.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: #fff; border-color: var(--border); color: var(--text-main); }
.btn-outline:hover { background: var(--bg-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-main); }
.btn-danger { background: #fff; color: var(--error); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.login-body {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #f7f7fb 0%, #eee9ff 100%);
}
.login-card {
    width: 380px; background: #fff; border-radius: 16px; padding: 40px 36px;
    box-shadow: var(--shadow-md);
}
.login-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.logo-mark {
    width: 36px; height: 36px; border-radius: 9px; background: var(--primary);
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 18px;
}
.logo-text { font-size: 19px; font-weight: 700; }
.login-subtitle { color: var(--text-muted); font-size: 14px; margin: 0 0 24px; }
.login-form label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 6px; color: var(--text-muted); }
.login-form input {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-size: 14px; font-family: inherit;
}
.login-form input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.login-form .btn { margin-top: 22px; }
.alert { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 4px; }
.alert-error { background: #fef2f2; color: var(--error); border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: var(--success); border: 1px solid #bbf7d0; }

.app-shell { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.topbar {
    height: 58px; flex: 0 0 auto; display: flex; align-items: center; gap: 14px;
    padding: 0 18px; background: #fff; border-bottom: 1px solid var(--border);
}
.topbar .logo-mark { width: 30px; height: 30px; font-size: 15px; border-radius: 8px; }
.topbar .logo-text { font-size: 16px; font-weight: 700; }
.topbar-search { flex: 1; max-width: 480px; position: relative; }
.topbar-search input {
    width: 100%; padding: 9px 14px 9px 36px; border-radius: 20px; border: 1px solid var(--border);
    background: var(--bg-app); font-size: 14px; font-family: inherit;
}
.topbar-search input:focus { outline: none; border-color: var(--primary); background: #fff; }
.topbar-search .search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-faint); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.sync-status { font-size: 12.5px; color: var(--text-faint); margin-right: 6px; white-space: nowrap; }
.user-chip {
    display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 20px;
    cursor: pointer; border: 1px solid var(--border);
}
.avatar {
    width: 26px; height: 26px; border-radius: 50%; background: var(--primary-light); color: var(--primary);
    display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px;
}

.app-body { flex: 1; display: flex; overflow: hidden; }

.sidebar {
    width: 260px; flex: 0 0 auto; background: #fff; border-right: 1px solid var(--border);
    display: flex; flex-direction: column; overflow-y: auto; padding: 14px 10px;
}
.compose-btn { margin: 4px 6px 16px; }
.nav-item {
    display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius-sm);
    font-size: 14px; font-weight: 500; color: var(--text-main); cursor: pointer; margin-bottom: 2px;
}
.nav-item:hover { background: var(--bg-hover); }
.nav-item.active { background: var(--primary-light); color: var(--primary-dark); font-weight: 600; }
.nav-item .badge {
    margin-left: auto; background: var(--primary); color: #fff; font-size: 11px; font-weight: 700;
    padding: 1px 7px; border-radius: 10px; min-width: 18px; text-align: center;
}
.nav-item.active .badge { background: var(--primary-dark); }
.nav-icon { width: 18px; text-align: center; flex: 0 0 auto; }

.sidebar-section-title {
    font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint);
    font-weight: 700; margin: 18px 12px 6px;
}
.account-group { margin-bottom: 2px; }
.account-header {
    display: flex; align-items: center; gap: 9px; padding: 8px 12px; border-radius: var(--radius-sm);
    cursor: pointer; font-size: 13.5px; font-weight: 600;
}
.account-header:hover { background: var(--bg-hover); }
.account-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.account-header .account-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-header .chevron { transition: transform .15s ease; color: var(--text-faint); font-size: 11px; }
.account-header.collapsed .chevron { transform: rotate(-90deg); }
.account-folders { padding-left: 24px; }
.account-folders.collapsed { display: none; }
.folder-item {
    display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: var(--radius-sm);
    font-size: 13px; color: var(--text-muted); cursor: pointer;
}
.folder-item:hover { background: var(--bg-hover); color: var(--text-main); }
.folder-item.active { background: var(--primary-light); color: var(--primary-dark); font-weight: 600; }
.folder-item .badge { margin-left: auto; font-size: 10.5px; color: var(--text-faint); font-weight: 600; }
.account-actions { padding: 6px 10px 6px; }

.sidebar-bottom { margin-top: auto; padding: 10px 6px 4px; border-top: 1px solid var(--border); }
.sidebar-bottom .nav-item { font-size: 13px; }

.email-list-col {
    width: 380px; flex: 0 0 auto; border-right: 1px solid var(--border); background: #fff;
    display: flex; flex-direction: column; overflow: hidden;
}
.list-toolbar {
    display: flex; align-items: center; gap: 6px; padding: 10px 14px; border-bottom: 1px solid var(--border);
    font-size: 13px; color: var(--text-muted);
}
.list-toolbar .list-title { font-weight: 700; color: var(--text-main); font-size: 15px; margin-right: auto; }
.email-list { flex: 1; overflow-y: auto; }
.email-item {
    display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid #f1f1f5; cursor: pointer;
    position: relative;
}
.email-item:hover { background: var(--bg-app); }
.email-item.active { background: var(--primary-light); }
.email-item.unread { background: #fbfaff; }
.email-item.unread .email-from, .email-item.unread .email-subject { font-weight: 700; }
.email-item .unread-dot {
    position: absolute; left: 4px; top: 50%; transform: translateY(-50%);
    width: 6px; height: 6px; border-radius: 50%; background: var(--primary);
}
.email-avatar {
    width: 36px; height: 36px; border-radius: 50%; flex: 0 0 auto; display: flex; align-items: center;
    justify-content: center; font-weight: 700; font-size: 13px; color: #fff;
}
.email-item-body { flex: 1; min-width: 0; }
.email-item-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.email-from { font-size: 13.5px; color: var(--text-main); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.email-date { font-size: 11.5px; color: var(--text-faint); flex: 0 0 auto; }
.email-subject { font-size: 13.5px; color: var(--text-main); margin: 2px 0 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.email-snippet { font-size: 12.5px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.email-meta-row { display: flex; align-items: center; gap: 6px; margin-top: 3px; }
.account-tag { font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 8px; color: #fff; }
.attach-icon { color: var(--text-faint); font-size: 12px; }
.empty-state { padding: 60px 20px; text-align: center; color: var(--text-faint); font-size: 13.5px; }
.empty-state .empty-icon { font-size: 34px; margin-bottom: 10px; }

.reading-pane { flex: 1; background: var(--bg-app); overflow-y: auto; display: flex; flex-direction: column; }
.reading-header { background: #fff; padding: 18px 28px; border-bottom: 1px solid var(--border); }
.reading-subject { font-size: 19px; font-weight: 700; margin: 0 0 12px; }
.reading-meta { display: flex; align-items: flex-start; gap: 12px; }
.reading-meta-text { flex: 1; }
.reading-meta .from-line { font-size: 14px; font-weight: 600; }
.reading-meta .to-line { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.reading-meta .date-line { font-size: 12px; color: var(--text-faint); white-space: nowrap; }
.reading-actions { display: flex; gap: 6px; padding: 10px 28px; background: #fff; border-bottom: 1px solid var(--border); }
.reading-body { padding: 24px 28px; font-size: 14.5px; line-height: 1.65; color: var(--text-main); max-width: 800px; }
.reading-body img { max-width: 100%; }
.attachments-block { padding: 0 28px 20px; display: flex; flex-wrap: wrap; gap: 8px; }
.attachment-chip {
    display: flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); font-size: 12.5px; background: #fff; cursor: pointer;
}
.attachment-chip:hover { background: var(--bg-hover); }

.reply-box { margin: 0 28px 28px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.reply-box-header { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 13px; font-weight: 600; color: var(--text-muted); }
.reply-box textarea, .reply-box .editable-body {
    width: 100%; border: none; padding: 14px 16px; font-family: inherit; font-size: 14px; resize: vertical;
    min-height: 130px; outline: none;
}
.reply-box-footer { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--border); }

.modal-overlay {
    position: fixed; inset: 0; background: rgba(20, 20, 30, .45); display: flex; align-items: center;
    justify-content: center; z-index: 1000; padding: 20px;
}
.modal-overlay.hidden { display: none; }
.modal-box { background: #fff; border-radius: 14px; width: 520px; max-width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-md); }
.modal-box.modal-wide { width: 640px; }
.modal-header { display: flex; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-header h3 { margin: 0; font-size: 16.5px; }
.modal-close { margin-left: auto; cursor: pointer; color: var(--text-faint); font-size: 18px; background: none; border: none; }
.modal-body { padding: 20px 22px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 22px; border-top: 1px solid var(--border); }

.form-group { margin-bottom: 14px; }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
.form-group label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-size: 13.5px; font-family: inherit;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light);
}
.form-hint { font-size: 11.5px; color: var(--text-faint); margin-top: 4px; }
.form-note { font-size: 12px; background: #f8f7ff; border: 1px solid var(--primary-light); color: #4c2fb0; padding: 8px 11px; border-radius: var(--radius-sm); margin-bottom: 14px; }

.test-result { margin-top: 12px; padding: 10px 12px; border-radius: var(--radius-sm); font-size: 12.5px; display: none; }
.test-result.show { display: block; }
.test-line { display: flex; align-items: center; gap: 7px; margin-bottom: 4px; }
.test-line:last-child { margin-bottom: 0; }
.test-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.test-dot.ok { background: var(--success); }
.test-dot.fail { background: var(--error); }

.filter-row { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid #f1f1f5; font-size: 13px; }
.filter-row:last-child { border-bottom: none; }
.filter-row .filter-desc { flex: 1; }
.filter-row .filter-desc b { color: var(--primary-dark); }

.spinner {
    display: inline-block; width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.35);
    border-top-color: #fff; border-radius: 50%; animation: spin .6s linear infinite;
}
.btn-outline .spinner, .btn-ghost .spinner { border-color: rgba(103,61,230,.25); border-top-color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }

.toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast {
    background: #1a1a2e; color: #fff; padding: 11px 16px; border-radius: 8px; font-size: 13px;
    box-shadow: var(--shadow-md); animation: slideIn .2s ease;
}
.toast.error { background: #7f1d1d; }
.toast.success { background: #14532d; }
@keyframes slideIn { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #d8d8e2; border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 900px) {
    .sidebar { display: none; }
    .email-list-col { width: 100%; }
    .reading-pane { display: none; }
}
