/* ═══════════════════════════════════════════
   HMail Webmail — Outlook-style UI
   ═══════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --blue:       #0078d4;
    --blue-dark:  #005a9e;
    --blue-light: #e5f0fb;
    --sidebar-w:  220px;
    --list-w:     340px;
    --topbar-h:   48px;
    --bg:         #f3f3f3;
    --surface:    #ffffff;
    --border:     #d1d1d1;
    --text:       #1a1a1a;
    --text-muted: #666;
    --unread-bg:  #edf4fc;
    --hover-bg:   #f0f0f0;
    --active-bg:  #dce9f7;
    --danger:     #d13438;
}

html, body { height: 100%; font-family: "Segoe UI", system-ui, sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }

/* ── Utilities ── */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 12px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text);
    border-radius: 4px; cursor: pointer; font-size: 13px;
    transition: background .15s;
}
.btn:hover { background: var(--hover-bg); }
.btn.btn-primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn.btn-primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
.btn.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn.btn-block { width: 100%; justify-content: center; padding: 10px; font-size: 15px; }

.icon-btn {
    background: none; border: none; cursor: pointer;
    color: var(--text-muted); padding: 6px 8px; border-radius: 4px;
    font-size: 14px; display: inline-flex; align-items: center; gap: 5px;
    transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--hover-bg); color: var(--text); }

/* ── Login ── */
.login-screen {
    min-height: 100vh; display: flex;
    align-items: center; justify-content: center;
    background: linear-gradient(135deg, #0078d4 0%, #005a9e 100%);
}
.login-card {
    background: #fff; border-radius: 8px;
    padding: 40px; width: 400px; max-width: 95vw;
    box-shadow: 0 8px 40px rgba(0,0,0,.25);
}
.login-logo { font-size: 40px; color: var(--blue); text-align: center; margin-bottom: 8px; }
.login-card h1 { text-align: center; font-size: 22px; font-weight: 600; margin-bottom: 24px; color: var(--text); }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 4px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.form-group input[type=text],
.form-group input[type=email],
.form-group input[type=password],
.form-group input[type=number] {
    width: 100%; padding: 8px 10px; border: 1px solid var(--border);
    border-radius: 4px; font-size: 14px; outline: none;
    transition: border-color .15s;
}
.form-group input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0,120,212,.15); }
.login-advanced { margin: 14px 0; }
.login-advanced summary { cursor: pointer; font-size: 12px; color: var(--text-muted); }
.advanced-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.checkbox-group label { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: normal; }
.login-error { background: #fde7e9; border: 1px solid #f1bdc0; border-radius: 4px; padding: 8px 12px; color: #c50f1f; font-size: 13px; margin-bottom: 10px; }

/* ── App shell ── */
.app-shell { display: grid; grid-template-rows: var(--topbar-h) 1fr; height: 100vh; overflow: hidden; }

/* ── Topbar ── */
.topbar {
    grid-row: 1; background: var(--blue); color: #fff;
    display: flex; align-items: center; gap: 12px;
    padding: 0 12px; box-shadow: 0 1px 4px rgba(0,0,0,.2); z-index: 100;
}
.topbar .icon-btn { color: rgba(255,255,255,.85); }
.topbar .icon-btn:hover { background: rgba(255,255,255,.15); color: #fff; }
.topbar-brand { font-size: 16px; font-weight: 600; white-space: nowrap; }
.topbar-brand i { margin-right: 6px; }
.topbar-search { flex: 1; max-width: 460px; }
.search-wrap { display: flex; align-items: center; background: rgba(255,255,255,.15); border-radius: 20px; padding: 0 8px 0 12px; gap: 6px; }
.search-wrap i { color: rgba(255,255,255,.7); }
.search-wrap input { flex: 1; background: none; border: none; outline: none; color: #fff; font-size: 14px; padding: 6px 0; }
.search-wrap input::placeholder { color: rgba(255,255,255,.6); }
.search-wrap .icon-btn { color: rgba(255,255,255,.8); padding: 4px 6px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.topbar-user { font-size: 13px; color: rgba(255,255,255,.85); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }

/* ── Main layout ── */
.main-layout { grid-row: 2; display: flex; overflow: hidden; }

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-w); flex-shrink: 0;
    background: var(--surface); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; overflow: hidden;
    transition: width .2s ease;
}
.sidebar.collapsed { width: 0; }
.compose-btn { margin: 10px; gap: 8px; font-size: 13px; }
.folder-tree { flex: 1; overflow-y: auto; padding: 4px 0; }
.folder-item {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 12px; cursor: pointer; border-radius: 0;
    font-size: 13px; color: var(--text); white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
    transition: background .1s;
}
.folder-item:hover { background: var(--hover-bg); }
.folder-item.active { background: var(--active-bg); color: var(--blue); font-weight: 600; }
.folder-item i { width: 16px; text-align: center; color: var(--text-muted); flex-shrink: 0; }
.folder-item.active i { color: var(--blue); }
.folder-item .folder-badge { margin-left: auto; background: var(--blue); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 6px; flex-shrink: 0; }
.sidebar-footer { padding: 8px; border-top: 1px solid var(--border); }

/* ── Message list panel ── */
.msg-list-panel {
    width: var(--list-w); flex-shrink: 0;
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column; background: #fafafa; overflow: hidden;
}
.msg-list-toolbar {
    display: flex; align-items: center; gap: 4px;
    padding: 6px 8px; border-bottom: 1px solid var(--border);
    background: var(--surface); min-height: 40px; flex-shrink: 0;
}
.toolbar-left { display: flex; align-items: center; gap: 2px; }
.toolbar-folder-name { flex: 1; text-align: center; font-weight: 600; font-size: 13px; color: var(--text-muted); }
.toolbar-right { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.page-info { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.move-wrap { position: relative; }
.move-dropdown {
    position: absolute; top: 100%; left: 0; z-index: 200;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 4px; min-width: 160px; box-shadow: 0 4px 12px rgba(0,0,0,.1);
    max-height: 240px; overflow-y: auto;
}
.move-dropdown .move-opt { padding: 7px 12px; cursor: pointer; font-size: 13px; }
.move-dropdown .move-opt:hover { background: var(--hover-bg); }

.msg-list { flex: 1; overflow-y: auto; }
.msg-item {
    display: grid; grid-template-columns: 22px 1fr auto; grid-template-rows: auto auto;
    gap: 2px 8px; padding: 8px 10px;
    border-bottom: 1px solid var(--border); cursor: pointer;
    background: var(--surface); position: relative;
    transition: background .1s;
    align-items: start;
}
.msg-item:hover { background: var(--hover-bg); }
.msg-item.active { background: var(--active-bg); }
.msg-item.unread { background: var(--unread-bg); }
.msg-item.unread .msg-item-from,
.msg-item.unread .msg-item-subject { font-weight: 700; }
.msg-item.selected { outline: 2px solid var(--blue); outline-offset: -2px; }
.msg-item-check { grid-row: 1/3; align-self: center; }
.msg-item-from { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-item-date { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.msg-item-subject { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; grid-column: 2/4; }
.msg-item .flag-icon { position: absolute; right: 6px; top: 6px; color: #e67a00; font-size: 11px; }
.msg-item .attach-icon { color: var(--text-muted); font-size: 11px; margin-left: 4px; }
.panel-loader { display: flex; align-items: center; justify-content: center; padding: 24px; font-size: 22px; color: var(--text-muted); }

/* ── Message detail ── */
.msg-detail-panel { flex: 1; display: flex; flex-direction: column; background: var(--surface); overflow: hidden; }
.detail-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #bbb; gap: 12px; }
.msg-detail-toolbar {
    display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
    padding: 8px 16px; border-bottom: 1px solid var(--border);
    background: #fafafa; flex-shrink: 0;
}
.msg-header { padding: 16px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.msg-header h2 { font-size: 18px; font-weight: 600; margin-bottom: 10px; }
.msg-meta { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--text-muted); }
.msg-meta strong { color: var(--text); margin-right: 4px; }
.msg-body-wrap { flex: 1; overflow: auto; }
.msg-body-frame { width: 100%; height: 100%; border: none; }

.attachments-bar { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.attach-chip {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--blue-light); border: 1px solid #b3d4f5;
    border-radius: 4px; padding: 4px 10px; font-size: 12px; cursor: pointer;
}
.attach-chip:hover { background: #cce1f8; }
.attach-chip i { color: var(--blue); }

/* ── Compose ── */
.compose-pane { flex: 1; display: flex; flex-direction: column; }
.compose-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 16px; border-bottom: 1px solid var(--border);
    font-weight: 600; font-size: 15px; flex-shrink: 0;
}
.compose-fields { border-bottom: 1px solid var(--border); flex-shrink: 0; }
.compose-row {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 16px; border-bottom: 1px solid #eee;
}
.compose-row label { font-size: 12px; font-weight: 600; color: var(--text-muted); width: 44px; flex-shrink: 0; }
.compose-row input[type=text] { flex: 1; border: none; outline: none; font-size: 14px; }
.attach-row { align-items: flex-start; flex-wrap: wrap; }
.attach-list { display: flex; flex-wrap: wrap; gap: 4px; }
.attach-list .attach-chip { font-size: 11px; }
.compose-toolbar {
    display: flex; align-items: center; gap: 2px; flex-wrap: wrap;
    padding: 4px 12px; border-bottom: 1px solid var(--border);
    background: #fafafa; flex-shrink: 0;
}
.toolbar-sep { width: 1px; height: 18px; background: var(--border); margin: 0 4px; }
.compose-toolbar select { font-size: 12px; border: 1px solid var(--border); border-radius: 3px; padding: 2px 4px; }
.compose-body {
    flex: 1; padding: 16px; outline: none; overflow-y: auto;
    font-size: 14px; line-height: 1.6; min-height: 200px;
}
.compose-actions {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 16px; border-top: 1px solid var(--border);
    background: #fafafa; flex-shrink: 0;
}
.compose-status { font-size: 12px; color: var(--text-muted); margin-left: 8px; }

/* ── Context menu ── */
.context-menu {
    position: fixed; z-index: 9999; background: var(--surface);
    border: 1px solid var(--border); border-radius: 4px;
    box-shadow: 0 4px 16px rgba(0,0,0,.15); min-width: 160px;
}
.ctx-item { padding: 8px 16px; cursor: pointer; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.ctx-item:hover { background: var(--hover-bg); }
.ctx-item i { width: 16px; text-align: center; color: var(--text-muted); }
.ctx-sep { border-top: 1px solid var(--border); margin: 3px 0; }

/* ── Toast ── */
.toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 99999; display: flex; flex-direction: column; gap: 8px; }
.toast {
    background: #323130; color: #fff; border-radius: 4px;
    padding: 10px 18px; font-size: 13px; box-shadow: 0 4px 12px rgba(0,0,0,.2);
    display: flex; align-items: center; gap: 10px;
    animation: slideIn .25s ease;
    min-width: 200px; max-width: 340px;
}
.toast.success { background: #107c10; }
.toast.error   { background: var(--danger); }
@keyframes slideIn { from { transform: translateX(60px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Scrollbars ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #aaa; }

/* ── Responsive ── */
@media (max-width: 800px) {
    :root { --list-w: 100%; }
    .msg-detail-panel { display: none; }
    .msg-detail-panel.mobile-show { display: flex; position: fixed; inset: var(--topbar-h) 0 0 0; z-index: 50; }
}
