@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

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

:root {
    --bg:       #060c1a;
    --bg2:      #0d1830;
    --surface:  #111827;
    --surface2: #1a2540;
    --accent:   #3b82f6;
    --accent2:  #06b6d4;
    --accent-hover: #2563eb;
    --text:     #f8fafc;
    --text-muted: #94a3b8;
    --border:   rgba(255,255,255,0.08);
    --border2:  rgba(59,130,246,0.2);
    --unread-bg: #0d1830;
    --radius:   10px;
    --shadow:   0 2px 8px rgba(0,0,0,0.3);
}

body { font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }
a { color: inherit; text-decoration: none; }

/* ===== LOGIN ===== */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 1rem; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 2.5rem; width: 100%; max-width: 420px; box-shadow: 0 20px 60px rgba(0,0,0,0.5); }
.login-logo { text-align: center; margin-bottom: 2rem; }
.login-logo h1 { font-size: 1.8rem; font-weight: 700; color: var(--text); }
.login-logo h1 span { background: linear-gradient(135deg, #3b82f6, #06b6d4); -webkit-background-clip: text; background-clip: text; color: transparent; }
.login-logo p { color: var(--text-muted); font-size: 0.875rem; margin-top: 0.25rem; }
.login-card label { display: block; font-size: 0.75rem; font-weight: 600; color: var(--text-muted); margin-bottom: 0.35rem; text-transform: uppercase; letter-spacing: 0.05em; }
.login-card input[type=email],
.login-card input[type=password],
.login-card input[type=text],
.login-card input[type=number] {
    width: 100%; padding: 0.75rem 1rem; border: 1.5px solid var(--border); border-radius: 8px;
    font-size: 0.95rem; font-family: inherit; color: var(--text); background: var(--bg2);
    transition: border-color 0.2s; margin-bottom: 1rem;
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-options { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.checkbox-label { display: flex; align-items: center; gap: 0.5rem; font-size: 0.8rem; color: var(--text-muted); cursor: pointer; }
.checkbox-label input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--accent); margin: 0; }
.forgot-link { font-size: 0.8rem; color: var(--accent); }
.forgot-link:hover { text-decoration: underline; }
.btn-login { width: 100%; padding: 0.85rem; background: var(--accent); color: #fff; border: none; border-radius: 8px; font-size: 1rem; font-weight: 700; cursor: pointer; transition: background 0.2s; font-family: inherit; }
.btn-login:hover { background: var(--accent-hover); }
.flash-error { background: rgba(220,38,38,0.1); border: 1px solid rgba(220,38,38,0.25); color: #f87171; padding: 0.75rem 1rem; border-radius: 8px; font-size: 0.875rem; margin-bottom: 1rem; }
.flash-success { background: rgba(34,197,94,0.1); border: 1px solid rgba(34,197,94,0.25); color: #4ade80; padding: 0.75rem 1rem; border-radius: 8px; font-size: 0.875rem; margin-bottom: 1rem; }
.account-list-mini { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.account-chip { display: flex; align-items: center; gap: 0.5rem; background: var(--bg2); border: 1px solid var(--border); border-radius: 20px; padding: 0.35rem 0.75rem 0.35rem 0.35rem; font-size: 0.78rem; color: var(--text-muted); transition: border-color 0.15s; }
.account-chip:hover { border-color: var(--accent); color: var(--text); }
.account-chip-avatar { width: 22px; height: 22px; border-radius: 50%; background: linear-gradient(135deg,var(--accent),var(--accent2)); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 0.65rem; font-weight: 700; flex-shrink: 0; }

/* ===== APP LAYOUT ===== */
.app { display: flex; height: 100vh; overflow: hidden; }

/* ===== ACCOUNT SWITCHER ===== */
.account-switcher { border-bottom: 1px solid var(--border); padding: 0.5rem 0; }
.account-item { display: flex; align-items: center; gap: 0.6rem; padding: 0.45rem 1rem; text-decoration: none; color: var(--text-muted); font-size: 0.78rem; transition: background 0.12s; }
.account-item:hover { background: rgba(59,130,246,0.08); color: var(--text); }
.account-item.active { color: var(--text); }
.account-avatar { width: 26px; height: 26px; border-radius: 50%; background: linear-gradient(135deg,var(--accent),var(--accent2)); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 0.7rem; font-weight: 700; flex-shrink: 0; }
.account-avatar.add { background: rgba(255,255,255,0.08); color: var(--text-muted); font-size: 1rem; }
.account-email { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-check { color: var(--accent); font-size: 0.75rem; flex-shrink: 0; }

/* ===== SIDEBAR ===== */
.sidebar { width: 240px; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; overflow-y: auto; transition: transform 0.25s; }
.sidebar-logo { padding: 1.25rem 1.25rem 0.75rem; border-bottom: 1px solid var(--border); }
.sidebar-logo h1 { font-size: 1.15rem; font-weight: 700; }
.sidebar-logo h1 span { background: linear-gradient(135deg, #3b82f6, #06b6d4); -webkit-background-clip: text; background-clip: text; color: transparent; }
.sidebar-logo p { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.2rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.compose-btn { margin: 0.875rem 1rem; background: var(--accent); color: #fff; border: none; border-radius: 8px; padding: 0.65rem 1rem; font-size: 0.875rem; font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 0.5rem; font-family: inherit; transition: background 0.2s; text-decoration: none; justify-content: center; }
.compose-btn:hover { background: var(--accent-hover); }
.sidebar-section { padding: 0.35rem 0; }
.sidebar-section-title { padding: 0.5rem 1.25rem 0.2rem; font-size: 0.68rem; font-weight: 600; color: rgba(255,255,255,0.25); text-transform: uppercase; letter-spacing: 0.08em; }
.sidebar-link { display: flex; align-items: center; gap: 0.65rem; padding: 0.55rem 1.25rem; color: var(--text-muted); text-decoration: none; font-size: 0.85rem; transition: background 0.15s, color 0.15s; position: relative; }
.sidebar-link:hover { background: rgba(59,130,246,0.08); color: var(--text); }
.sidebar-link.active { background: rgba(59,130,246,0.15); color: var(--accent); font-weight: 600; }
.sidebar-link.active::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); border-radius: 0 3px 3px 0; }
.sidebar-link .badge { margin-left: auto; background: var(--accent); color: #fff; font-size: 0.68rem; font-weight: 700; border-radius: 10px; padding: 0.1rem 0.45rem; min-width: 20px; text-align: center; }
.sidebar-link svg { width: 15px; height: 15px; flex-shrink: 0; opacity: 0.7; }
.sidebar-link.active svg { opacity: 1; }
.sidebar-footer { margin-top: auto; padding: 1rem 1.25rem; border-top: 1px solid var(--border); }
.sidebar-footer a { color: var(--text-muted); font-size: 0.78rem; display: flex; align-items: center; gap: 0.5rem; transition: color 0.15s; }
.sidebar-footer a:hover { color: #f87171; }

/* ===== MAIN ===== */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 0.75rem 1.25rem; display: flex; align-items: center; gap: 0.75rem; flex-shrink: 0; }
.topbar-menu-btn { display: none; background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 0.25rem; }
.topbar-title { font-size: 0.95rem; font-weight: 600; color: var(--text); flex: 1; }
.topbar-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.btn-icon { background: none; border: 1px solid var(--border); border-radius: 7px; padding: 0.4rem 0.7rem; cursor: pointer; font-size: 0.78rem; color: var(--text-muted); display: flex; align-items: center; gap: 0.35rem; font-family: inherit; transition: border-color 0.15s, color 0.15s; text-decoration: none; }
.btn-icon:hover { border-color: var(--accent); color: var(--accent); }
.content { flex: 1; overflow-y: auto; }

/* ===== MESSAGE LIST ===== */
.msg-list { list-style: none; }
.msg-item { display: grid; grid-template-columns: 38px 1fr 70px; gap: 0.75rem; align-items: center; padding: 0.7rem 1.25rem; border-bottom: 1px solid var(--border); cursor: pointer; background: transparent; transition: background 0.1s; text-decoration: none; color: inherit; }
.msg-item:hover { background: rgba(255,255,255,0.03); }
.msg-item.unread { background: var(--unread-bg); }
.msg-item.unread .msg-from { font-weight: 700; color: var(--text); }
.msg-item.unread .msg-subject { color: var(--text); }
.msg-item.unread::before { content: ''; display: block; position: absolute; left: 0; width: 3px; }
.msg-avatar { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.8rem; flex-shrink: 0; }
.msg-body { min-width: 0; }
.msg-from { font-size: 0.85rem; font-weight: 500; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-subject { font-size: 0.78rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 0.1rem; }
.msg-date { font-size: 0.72rem; color: var(--text-muted); white-space: nowrap; text-align: right; }
.empty-state { text-align: center; padding: 5rem 2rem; color: var(--text-muted); }
.empty-state svg { width: 44px; height: 44px; margin: 0 auto 1rem; opacity: 0.2; display: block; }
.empty-state p { font-size: 0.9rem; }

/* ===== PAGINATION ===== */
.pagination { display: flex; align-items: center; justify-content: center; gap: 0.4rem; padding: 1rem; border-top: 1px solid var(--border); }
.pagination a, .pagination span { padding: 0.35rem 0.65rem; border-radius: 6px; font-size: 0.78rem; text-decoration: none; color: var(--text-muted); border: 1px solid var(--border); transition: border-color 0.15s, color 0.15s; }
.pagination a:hover { border-color: var(--accent); color: var(--accent); }
.pagination .current { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 700; }

/* ===== MESSAGE VIEW ===== */
.message-view { padding: 1.25rem; max-width: 860px; }
.message-header { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; margin-bottom: 1rem; }
.message-subject { font-size: 1.2rem; font-weight: 700; margin-bottom: 1rem; line-height: 1.3; }
.message-meta { display: flex; align-items: flex-start; gap: 0.75rem; }
.message-avatar { width: 38px; height: 38px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.85rem; flex-shrink: 0; }
.message-from-block { flex: 1; min-width: 0; }
.message-from-name { font-weight: 600; font-size: 0.875rem; }
.message-from-email { color: var(--text-muted); font-size: 0.78rem; margin-top: 0.1rem; }
.message-date { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; }
.message-actions { display: flex; gap: 0.5rem; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); flex-wrap: wrap; }
.message-body { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; font-size: 0.875rem; line-height: 1.75; color: var(--text); }
.message-body .email-html { color: #e2e8f0; }
.message-body .email-html a { color: var(--accent); }
.message-body pre { white-space: pre-wrap; word-break: break-word; font-family: inherit; color: var(--text-muted); }
.attachments { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.5rem; margin-top: 1rem; }
.attachments h4 { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 0.75rem; }
.attachment-list { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.attachment-item { display: flex; align-items: center; gap: 0.5rem; background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; padding: 0.5rem 0.75rem; font-size: 0.78rem; color: var(--text-muted); transition: border-color 0.15s, color 0.15s; }
.attachment-item:hover { border-color: var(--accent); color: var(--accent); }

/* ===== COMPOSE ===== */
.compose-wrap { padding: 1.25rem; max-width: 860px; }
.compose-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.compose-header { padding: 0.875rem 1.5rem; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 0.9rem; color: var(--text-muted); }
.compose-field { display: flex; align-items: center; border-bottom: 1px solid var(--border); }
.compose-label { padding: 0.75rem 1rem 0.75rem 1.5rem; font-size: 0.75rem; font-weight: 600; color: var(--text-muted); width: 80px; flex-shrink: 0; text-transform: uppercase; }
.compose-field input { flex: 1; padding: 0.75rem 1rem; border: none; outline: none; font-size: 0.875rem; font-family: inherit; background: transparent; color: var(--text); }
.compose-body { padding: 1rem 1.5rem; }
.compose-body textarea { width: 100%; border: none; outline: none; font-size: 0.875rem; font-family: inherit; resize: vertical; min-height: 320px; line-height: 1.7; background: transparent; color: var(--text); }
.compose-footer { padding: 0.75rem 1.5rem; border-top: 1px solid var(--border); display: flex; gap: 0.75rem; align-items: center; }
.btn-send { background: var(--accent); color: #fff; border: none; border-radius: 8px; padding: 0.6rem 1.25rem; font-size: 0.85rem; font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 0.5rem; font-family: inherit; transition: background 0.2s; }
.btn-send:hover { background: var(--accent-hover); }
.btn-discard { background: none; border: none; color: var(--text-muted); font-size: 0.85rem; cursor: pointer; font-family: inherit; }
.btn-discard:hover { color: #f87171; }
.flash { padding: 0.75rem 1.25rem; font-size: 0.85rem; font-weight: 500; border-bottom: 1px solid var(--border); }
.flash.success { background: rgba(34,197,94,0.08); color: #4ade80; }
.flash.error { background: rgba(220,38,38,0.08); color: #f87171; }

/* ===== MOBILE OVERLAY ===== */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 40; }

/* ===== SETTINGS ===== */
.settings-wrap { padding: 1.25rem; max-width: 620px; display: flex; flex-direction: column; gap: 1rem; }
.settings-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.settings-card-title { display: flex; align-items: center; gap: 0.5rem; padding: 0.875rem 1.25rem; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 0.875rem; color: var(--text-muted); }
.settings-row { display: flex; align-items: center; padding: 0.6rem 1.25rem; border-bottom: 1px solid var(--border); gap: 1rem; }
.settings-row:last-child { border-bottom: none; }
.settings-label { font-size: 0.8rem; color: var(--text-muted); width: 140px; flex-shrink: 0; }
.settings-value { font-size: 0.875rem; color: var(--text); }
.settings-form-row { padding: 0.6rem 1.25rem; border-bottom: 1px solid var(--border); }
.settings-form-row label { display: block; font-size: 0.72rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.3rem; }
.settings-form-row input { width: 100%; padding: 0.6rem 0.875rem; background: var(--bg2); border: 1.5px solid var(--border); border-radius: 7px; color: var(--text); font-size: 0.875rem; font-family: inherit; }
.settings-form-row input:focus { outline: none; border-color: var(--accent); }
.settings-form-row textarea { width: 100%; padding: 0.6rem 0.875rem; background: var(--bg2); border: 1.5px solid var(--border); border-radius: 7px; color: var(--text); font-size: 0.875rem; font-family: inherit; resize: vertical; min-height: 100px; line-height: 1.6; }
.settings-form-row textarea:focus { outline: none; border-color: var(--accent); }
.field-hint { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.3rem; }
.settings-card > div:last-child:not(.settings-card-title):not(.settings-form-row):not(.settings-row) { padding: 0.875rem 1.25rem; }

/* ===== AVATAR ===== */
.avatar-section { display: flex; align-items: flex-start; gap: 1.5rem; padding: 1.25rem; }
.avatar-preview img { width: 80px; height: 80px; border-radius: 50%; object-fit: cover; border: 2px solid var(--border); display: block; }
.avatar-actions { flex: 1; }
.avatar-hint { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.5rem; line-height: 1.4; }
.btn-danger-sm { background: none; border: 1px solid rgba(248,113,113,0.3); color: #f87171; border-radius: 7px; padding: 0.4rem 0.75rem; font-size: 0.78rem; cursor: pointer; font-family: inherit; transition: background 0.15s; margin-top: 0.5rem; display: inline-block; text-decoration: none; }
.btn-danger-sm:hover { background: rgba(248,113,113,0.08); }

/* ===== COMPOSE ATTACHMENTS ===== */
.compose-attachments { padding: 0.6rem 1.5rem; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.attach-btn { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.78rem; color: var(--text-muted); cursor: pointer; border: 1px dashed var(--border); border-radius: 6px; padding: 0.35rem 0.75rem; transition: border-color 0.15s, color 0.15s; }
.attach-btn:hover { border-color: var(--accent); color: var(--accent); }
.file-list { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.file-chip { background: rgba(59,130,246,0.1); border: 1px solid rgba(59,130,246,0.2); color: var(--accent); border-radius: 20px; padding: 0.2rem 0.65rem; font-size: 0.72rem; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .sidebar { position: fixed; top: 0; left: 0; bottom: 0; z-index: 50; transform: translateX(-100%); width: 260px; }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.open { display: block; }
    .topbar-menu-btn { display: flex; align-items: center; justify-content: center; }
    .msg-item { grid-template-columns: 34px 1fr; }
    .msg-date { display: none; }
    .message-view, .compose-wrap { padding: 0.75rem; }
    .topbar-actions .btn-icon span { display: none; }
}
