:root {
    --accent: #1a73e8;
    --accent-dark: #0b57d0;
    --bg: #f6f8fc;
    --surface: #ffffff;
    --border: #e2e5ea;
    --text: #202124;
    --text-secondary: #5f6368;
    --unread-bg: #ffffff;
    --hover: #f1f3f4;
    --danger: #d93025;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}

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

/* --- Login --- */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}
.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 40px 36px;
    width: 340px;
    text-align: center;
}
.login-logo { font-size: 26px; font-weight: 600; margin-bottom: 4px; }
.login-sub { color: var(--text-secondary); margin-bottom: 20px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-secondary); }
.login-footnote { margin-top: 20px; font-size: 12px; color: var(--text-secondary); }

input[type="text"], input[type="email"], input[type="password"], input[type="search"], textarea {
    font-family: inherit;
    font-size: 14px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 100%;
    background: var(--surface);
    color: var(--text);
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.btn {
    display: inline-block;
    border: none;
    border-radius: 20px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    background: var(--hover);
    color: var(--text);
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-text { background: none; padding: 8px 12px; color: var(--text-secondary); }
.btn-text:hover { background: var(--hover); text-decoration: none; }
.btn-block { width: 100%; }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; }
.alert-error { background: #fce8e6; color: var(--danger); }
.alert-success { background: #e6f4ea; color: #188038; }
.alert-info { background: #e8f0fe; color: var(--accent-dark); }

/* --- Topbar --- */
.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}
.logo { font-size: 18px; font-weight: 600; white-space: nowrap; }
.search-form { flex: 1; display: flex; max-width: 600px; background: var(--bg); border-radius: 8px; overflow: hidden; }
.search-form input { border: none; background: transparent; flex: 1; }
.search-form button { border: none; background: transparent; cursor: pointer; padding: 0 12px; }
.topbar-actions { display: flex; gap: 4px; }
.icon-btn {
    border: none; background: none; font-size: 18px; cursor: pointer;
    width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
    color: var(--text-secondary);
}
.icon-btn:hover { background: var(--hover); text-decoration: none; }
.sidebar-toggle { display: none; }

/* --- Layout --- */
.app-layout { display: flex; min-height: calc(100vh - 57px); }
.sidebar {
    width: 220px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 16px 8px;
    flex-shrink: 0;
}
.compose-btn { display: block; text-align: center; margin: 0 8px 16px; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.folder-nav { display: flex; flex-direction: column; gap: 2px; }
.folder-link {
    display: flex; align-items: center; gap: 12px;
    padding: 9px 14px; border-radius: 0 20px 20px 0;
    color: var(--text); font-size: 14px;
}
.folder-link:hover { background: var(--hover); text-decoration: none; }
.folder-link.active { background: #d3e3fd; color: var(--accent-dark); font-weight: 600; }
.folder-icon { width: 18px; text-align: center; }
.unread-badge { margin-left: auto; font-size: 12px; font-weight: 600; }
.folder-divider { height: 1px; background: var(--border); margin: 8px 14px; }

.main-content { flex: 1; padding: 16px 24px; max-width: 900px; }

/* --- Mailbox toolbar & list --- */
.mailbox-toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 4px; }
.toolbar-spacer { flex: 1; }
.pagination { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--text-secondary); }

.message-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.message-row { display: flex; align-items: center; border-bottom: 1px solid var(--border); }
.message-row:last-child { border-bottom: none; }
.message-row:hover { background: var(--hover); box-shadow: inset 0 0 0 1px var(--border); }
.message-row.unread { font-weight: 600; background: var(--unread-bg); }
.star-form { display: contents; }
.star-btn { border: none; background: none; font-size: 18px; cursor: pointer; padding: 12px; color: #f4b400; }
.message-link { display: flex; flex: 1; align-items: center; gap: 12px; padding: 12px 8px; color: var(--text); min-width: 0; }
.message-link:hover { text-decoration: none; }
.msg-from { width: 180px; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-subject { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-secondary); }
.message-row.unread .msg-subject { color: var(--text); }
.thread-count { color: var(--text-secondary); font-weight: 400; }
.msg-date { width: 70px; text-align: right; flex-shrink: 0; color: var(--text-secondary); font-weight: 400; font-size: 12.5px; }

.empty-state { padding: 60px 20px; text-align: center; color: var(--text-secondary); }

/* --- Message detail --- */
.message-toolbar { display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap; }
.message-detail { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 24px; }
.message-subject { font-size: 20px; margin: 0 0 12px; }
.message-meta { border-bottom: 1px solid var(--border); padding-bottom: 12px; margin-bottom: 16px; }
.meta-secondary { color: var(--text-secondary); font-size: 13px; }
.message-body { line-height: 1.5; word-wrap: break-word; overflow-x: auto; }
.message-body img { max-width: 100%; height: auto; }
.attachments { margin-top: 24px; border-top: 1px solid var(--border); padding-top: 16px; }
.attachments ul { list-style: none; padding: 0; }
.attachments li { padding: 6px 0; }

/* --- Compose --- */
.compose-form { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 20px; max-width: 760px; }
.compose-field { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--border); padding: 6px 0; margin-bottom: 4px; }
.compose-field label { width: 90px; flex-shrink: 0; color: var(--text-secondary); font-size: 13px; }
.compose-field input, .compose-field textarea { border: none; padding: 6px 0; }
.compose-field input:focus { outline: none; }
.field-hint { font-size: 12px; color: var(--text-secondary); margin: 4px 0 0; }
.compose-actions { margin-top: 16px; display: flex; gap: 8px; align-items: center; }

/* --- Settings --- */
.settings-panel { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 24px; max-width: 600px; }
.settings-panel .compose-field { flex-direction: column; align-items: flex-start; border: none; }
.settings-panel label { width: auto; margin-bottom: 6px; }

.search-heading { font-size: 18px; font-weight: 500; margin: 8px 0 16px; }

/* --- Mobile --- */
@media (max-width: 800px) {
    .sidebar-toggle { display: flex; }
    .search-form { display: none; }
    .sidebar {
        position: fixed; top: 57px; left: 0; bottom: 0;
        transform: translateX(-100%);
        transition: transform .2s ease;
        z-index: 20;
        box-shadow: 2px 0 8px rgba(0,0,0,.15);
    }
    .sidebar.open { transform: translateX(0); }
    .main-content { padding: 10px; }
    .msg-from { width: 110px; }
    .compose-field { flex-direction: column; align-items: stretch; gap: 4px; }
    .compose-field label { width: auto; }
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #131314;
        --surface: #1e1f20;
        --border: #3c4043;
        --text: #e8eaed;
        --text-secondary: #9aa0a6;
        --hover: #28292a;
        --unread-bg: #1e1f20;
    }
    .folder-link.active { background: #2b3c56; color: #a8c7fa; }
    .alert-error { background: #3d2422; }
    .alert-success { background: #1e3a2a; }
    .alert-info { background: #1c2b41; }
}
