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

:root {
    --bg:          #f4f5f7;
    --bg-panel:    #ffffff;
    --bg-header:   #ffffff;
    --bg-hover:    #f0f2f5;
    --accent:      #2563eb;
    --accent-h:    #1d4ed8;
    --text:        #1f2430;
    --text-muted:  #6b7280;
    --border:      #e3e5ea;
    --red-text:    #c0392b;
    --banner-bg:   #fff4e0;
    --banner-border: #f0b429;
    --banner-text: #7a5a10;
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: 'Arial', sans-serif;
    background: var(--bg);
    color: var(--text);
}

a { color: inherit; }

/* ── Login pages ── */

.login-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(180deg, #eef1f6 0%, #e4e8ef 100%);
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-header__title {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--text);
}

.login-header__sub {
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-muted);
    letter-spacing: 0.06em;
}

.login-card {
    background: var(--bg-panel);
    border-radius: 8px;
    padding: 32px 36px 28px;
    width: 340px;
    box-shadow: 0 12px 40px rgba(20, 30, 50, 0.12);
    border: 1px solid var(--border);
}

.login-hint {
    margin: 0 0 18px;
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.5;
}

.login-card label {
    display: block;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: #555;
    margin-bottom: 6px;
    margin-top: 16px;
    text-transform: uppercase;
}

.login-card label:first-of-type { margin-top: 0; }

.login-card input {
    display: block;
    width: 100%;
    border: 1.5px solid var(--border);
    border-radius: 5px;
    padding: 10px 12px;
    font-size: 14px;
    outline: none;
    color: var(--text);
    background: #fff;
    transition: border-color 0.15s;
}

.login-card input:focus { border-color: var(--accent); }

.login-btn {
    display: block;
    width: 100%;
    margin-top: 22px;
    padding: 11px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 5px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.08em;
    cursor: pointer;
    transition: background 0.15s;
}

.login-btn:hover { background: var(--accent-h); }

.login-error {
    margin-top: 14px;
    text-align: center;
    font-size: 12px;
    color: var(--red-text);
}

.login-forgot {
    display: block;
    margin-top: 18px;
    text-align: center;
    font-size: 12px;
    color: var(--accent);
    text-decoration: none;
}

.login-forgot:hover { text-decoration: underline; }

/* ── Archive banner ── */

.archive-banner {
    background: var(--banner-bg);
    color: var(--banner-text);
    border-bottom: 1px solid var(--banner-border);
    font-size: 12.5px;
    padding: 8px 20px;
    text-align: center;
}

/* ── App shell ── */

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

.app-header {
    height: 56px;
    background: var(--bg-header);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 14px;
    flex-shrink: 0;
    z-index: 10;
}

.app-header__title {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--text);
}

.app-header__user {
    flex: 1;
    text-align: right;
    font-size: 12px;
    color: var(--text-muted);
}

.app-header__logout {
    font-size: 12px;
    color: var(--text-muted);
    text-decoration: none;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    transition: color 0.15s, border-color 0.15s;
}

.app-header__logout:hover { color: var(--text); border-color: #c7cbd4; }

.app-body {
    flex: 1;
    display: flex;
    min-height: 0;
}

/* ── Sidebar ── */

.sidebar {
    width: 220px;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    padding: 16px 12px;
    gap: 2px;
}

.compose-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    margin-bottom: 14px;
    padding: 11px 14px;
    background: var(--bg-hover);
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 700;
    cursor: not-allowed;
}

.compose-btn svg { width: 16px; height: 16px; }

.sidebar-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 12px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 6px;
    transition: color 0.15s, background 0.15s;
}

.sidebar-link:hover { color: var(--text); background: var(--bg-hover); }

.sidebar-link.active {
    color: var(--accent);
    background: rgba(37, 99, 235, 0.1);
}

.sidebar-count {
    font-size: 11px;
    font-weight: 700;
    color: var(--accent);
    background: rgba(37, 99, 235, 0.12);
    border-radius: 10px;
    padding: 1px 8px;
}

/* ── Content ── */

.content {
    flex: 1;
    overflow-y: auto;
    padding: 24px 32px;
    min-width: 0;
}

.page-title {
    font-size: 19px;
    font-weight: 700;
    color: var(--text);
    margin: 0 0 18px;
}

.toolbar { margin-bottom: 18px; }

.search-form {
    display: flex;
    align-items: center;
    max-width: 420px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2px 4px 2px 14px;
}

.search-form input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 13px;
    padding: 9px 0;
    color: var(--text);
}

.search-form button {
    border: none;
    background: transparent;
    color: var(--text-muted);
    padding: 8px;
    cursor: pointer;
}

.search-form button svg { width: 16px; height: 16px; display: block; }

.empty-state {
    color: var(--text-muted);
    font-size: 13px;
    padding: 40px 0;
    text-align: center;
}

/* ── Message list ── */

.message-list {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.message-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 13px 18px;
    text-decoration: none;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.message-row:last-child { border-bottom: none; }

.message-row:hover { background: var(--bg-hover); }

.message-row__dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: transparent;
    flex-shrink: 0;
}

.message-row.unread .message-row__dot { background: var(--accent); }
.message-row.unread .message-row__from,
.message-row.unread .message-row__subject { font-weight: 700; }

.message-row__from {
    width: 170px;
    flex-shrink: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message-row__subject {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message-row__preview { color: var(--text-muted); font-weight: 400; }

.message-row__clip {
    width: 13px;
    height: 13px;
    color: var(--text-muted);
    vertical-align: -2px;
    margin: 0 2px;
}

.message-row__date {
    width: 150px;
    flex-shrink: 0;
    text-align: right;
    color: var(--text-muted);
    font-size: 12px;
}

/* ── Message view ── */

.back-link {
    display: inline-block;
    margin-bottom: 16px;
    font-size: 12px;
    color: var(--accent);
    text-decoration: none;
}

.back-link:hover { text-decoration: underline; }

.message-view {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 26px 28px;
    max-width: 760px;
}

.message-view__subject {
    font-size: 19px;
    font-weight: 700;
    margin: 0 0 16px;
}

.message-view__meta {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.message-view__from { font-weight: 700; }
.message-view__email { font-weight: 400; color: var(--text-muted); margin-left: 4px; }
.message-view__to { color: var(--text-muted); font-size: 12px; margin-top: 3px; }
.message-view__date { color: var(--text-muted); font-size: 12px; white-space: nowrap; }

.message-view__actions {
    display: flex;
    gap: 10px;
    margin: 16px 0;
}

.message-view__actions button {
    padding: 7px 16px;
    border-radius: 5px;
    font-size: 12px;
    font-weight: 700;
    border: 1px solid var(--border);
    background: var(--bg-hover);
    color: var(--text-muted);
    cursor: not-allowed;
}

/* ── Attachments ── */

.attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 4px 0 18px;
}

.attachment {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 9px 14px;
    text-decoration: none;
    color: var(--text);
    min-width: 180px;
}

.attachment--link:hover { border-color: var(--accent); background: rgba(37, 99, 235, 0.06); }

.attachment__icon {
    width: 30px;
    height: 30px;
    border-radius: 5px;
    background: rgba(37, 99, 235, 0.12);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.attachment__icon svg { width: 16px; height: 16px; }

.attachment__name { display: block; font-size: 12.5px; font-weight: 600; }
.attachment__size { display: block; font-size: 11px; color: var(--text-muted); }

/* ── Message body ── */

.message-view__body { margin-top: 4px; }

.message-text-body {
    white-space: pre-wrap;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text);
}

.message-html-frame {
    width: 100%;
    min-height: 420px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
}

/* ══════════════════════════════
   Mobile
   ══════════════════════════════ */

.sidebar-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 6px;
    margin-right: 2px;
    border-radius: 4px;
    cursor: pointer;
    flex-shrink: 0;
}

.sidebar-toggle svg { display: block; width: 22px; height: 22px; }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 56px 0 0 0;
    background: rgba(20, 25, 35, 0.45);
    z-index: 199;
    opacity: 0;
    transition: opacity 0.25s;
    pointer-events: none;
}

.sidebar-overlay.visible { opacity: 1; pointer-events: auto; }

@media (max-width: 768px) {
    .sidebar-toggle { display: flex; }
    .app-header__user { display: none; }
    .app-header__title { font-size: 13px; }
    .sidebar-overlay { display: block; }
    .app-body { display: block; }

    .sidebar {
        position: fixed;
        top: 56px;
        left: 0;
        bottom: 0;
        z-index: 200;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        width: 240px;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25);
    }

    .sidebar.open { transform: translateX(0); }

    .content { padding: 16px; }

    .message-row { flex-wrap: wrap; }
    .message-row__from { width: auto; max-width: 55%; }
    .message-row__date { width: auto; margin-left: auto; }
    .message-row__subject { flex: 0 0 100%; order: 3; }

    .message-view { padding: 18px; }
    .message-view__meta { flex-direction: column; gap: 6px; }
    .message-view__actions { flex-wrap: wrap; }
}