/* MailSync – clean, professional UI */
:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --ink: #172033;
    --ink-soft: #5a667a;
    --line: #e3e8f1;
    --brand: #2b59e0;
    --brand-dark: #1b3fae;
    --brand-tint: #eaf0ff;
    --ok: #137a4b;
    --ok-tint: #e6f6ee;
    --bad: #b42318;
    --bad-tint: #fdecea;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(23, 32, 51, .06), 0 8px 24px rgba(23, 32, 51, .06);
    --font: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: 24px; }
h2 { font-size: 20px; }
h3 { font-size: 17px; }
p { margin: 0 0 12px; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--ink-soft); }
.right { text-align: right; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 40px; padding: 0 16px;
    font: inherit; font-weight: 600; font-size: 14px;
    border: 1px solid transparent; border-radius: 10px;
    cursor: pointer; transition: background .15s, border-color .15s, box-shadow .15s;
}
.btn:disabled, .btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 1px 2px rgba(27, 63, 174, .3); }
.btn-primary:hover:not(:disabled) { background: var(--brand-dark); text-decoration: none; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: #f1f4fa; }
.btn-ghost.danger { color: var(--bad); }
.btn-block { width: 100%; }
.btn-lg { height: 46px; font-size: 15px; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn:focus-visible, input:focus-visible { outline: 3px solid rgba(43, 89, 224, .35); outline-offset: 1px; }

/* ---------- Forms ---------- */
.field { display: block; margin-bottom: 16px; }
.field > span:first-child { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field input[type=text], .field input[type=email], .field input:not([type]), .field input[type=search] {
    width: 100%; height: 44px; padding: 0 14px;
    font: inherit; color: var(--ink);
    background: #fff; border: 1px solid #cfd7e6; border-radius: 10px;
}
.field input:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px rgba(43, 89, 224, .18); }
.field-error { display: block; color: var(--bad); font-size: 13px; margin-top: 4px; }
.field-error:empty { display: none; }
.code-input { text-align: center; font-size: 28px; font-weight: 700; letter-spacing: 10px; height: 56px !important; }
.check { display: flex; align-items: center; gap: 10px; margin: 4px 0 20px; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.check-inline { margin: 0; }

.alert { padding: 12px 14px; border-radius: 10px; font-size: 14px; margin-bottom: 16px; }
.alert:empty { display: none; }
.alert ul { margin: 0; padding-left: 18px; }
.alert-error { background: var(--bad-tint); color: var(--bad); }
.alert-ok { background: var(--ok-tint); color: var(--ok); }

/* ---------- Sign-in screens ---------- */
body.auth { background: var(--surface); }
.auth-grid { min-height: 100vh; display: grid; grid-template-columns: minmax(320px, 5fr) 6fr; }
.auth-brand {
    background: radial-gradient(1200px 600px at 0% 0%, #3b6cf0 0%, transparent 60%), linear-gradient(160deg, #1b3fae, #0f2468);
    color: #fff; display: flex; align-items: center; padding: 48px;
}
.auth-brand-inner { max-width: 420px; }
.auth-brand h1 { font-size: 40px; margin: 18px 0 12px; font-weight: 600; }
.auth-brand h1 b { font-weight: 800; }
.auth-brand p { color: rgba(255, 255, 255, .85); font-size: 17px; }
.auth-points { list-style: none; padding: 0; margin: 28px 0 0; }
.auth-points li { padding: 8px 0 8px 30px; position: relative; color: rgba(255, 255, 255, .92); }
.auth-points li::before {
    content: ""; position: absolute; left: 0; top: 12px; width: 16px; height: 16px; border-radius: 50%;
    background: rgba(255, 255, 255, .22) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 8.5l2.5 2.5L12 5.5' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/16px no-repeat;
}
.auth-panel { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 32px; background: var(--bg); }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 36px; box-shadow: var(--shadow); }
.auth-card h2 { margin-bottom: 8px; }
.auth-card .muted { margin-bottom: 24px; }
.auth-alt { text-align: center; margin: 18px 0 0; font-size: 14px; }
.auth-foot { margin-top: 20px; color: var(--ink-soft); font-size: 13px; }

.brand-mark {
    display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
    background: linear-gradient(145deg, #4f7bff, #1f3fae); color: #fff; font-weight: 800; font-size: 18px;
    box-shadow: 0 2px 6px rgba(27, 63, 174, .35);
}
.brand-mark-lg { width: 56px; height: 56px; font-size: 30px; border-radius: 16px; background: rgba(255, 255, 255, .18); box-shadow: none; }

/* ---------- App shell ---------- */
.topbar {
    position: sticky; top: 0; z-index: 10; height: 64px;
    display: grid; grid-template-columns: 240px 1fr auto; align-items: center; gap: 16px;
    padding: 0 20px 0 20px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-size: 20px; font-weight: 500; }
.brand:hover { text-decoration: none; }
.brand b { font-weight: 800; color: var(--brand); }
.topbar-search input {
    width: 100%; max-width: 560px; height: 40px; padding: 0 16px; font: inherit;
    background: var(--bg); border: 1px solid transparent; border-radius: 10px;
}
.topbar-user { display: flex; align-items: center; gap: 12px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-tint); color: var(--brand-dark); font-weight: 700; }
.who { display: flex; flex-direction: column; line-height: 1.2; }
.who-name { font-weight: 600; font-size: 14px; }
.who-mail { font-size: 12px; color: var(--ink-soft); }

.shell { display: grid; grid-template-columns: 240px 1fr; min-height: calc(100vh - 64px); }
.sidebar { padding: 20px 14px; background: var(--surface); border-right: 1px solid var(--line); }
.nav-list { list-style: none; margin: 18px 0 0; padding: 0; }
.nav-item {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px; margin-bottom: 2px;
    border-radius: 10px; color: var(--ink); font-weight: 500;
}
.nav-item:hover { background: #f1f4fa; text-decoration: none; }
.nav-item.active { background: var(--brand-tint); color: var(--brand-dark); font-weight: 700; }
.nav-item.disabled { color: #98a2b3; cursor: not-allowed; }
.nav-item.disabled:hover { background: transparent; }
.nav-item .ico { width: 20px; text-align: center; font-size: 16px; }
.nav-section { margin: 22px 12px 4px; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: #98a2b3; }

.content { padding: 28px 32px 48px; max-width: 1100px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 20px; }
.page-head .muted { margin: 4px 0 0; }

/* ---------- Cards, tables, lists ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; margin-bottom: 24px; box-shadow: var(--shadow); }
.card-flush { padding: 0; overflow: hidden; }
.card-title { font-size: 16px; margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; align-items: end; }
.form-grid .alert { grid-column: 1 / -1; }
.form-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; padding: 12px 16px; font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-soft); background: #fafbfe; border-bottom: 1px solid var(--line); }
.table td { padding: 14px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafbfe; }
.inline { display: inline-block; margin-left: 6px; }
.table th.right, .table td.right { text-align: right; white-space: nowrap; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eef1f6; color: var(--ink-soft); }
.badge-blue { background: var(--brand-tint); color: var(--brand-dark); }
.badge-green { background: var(--ok-tint); color: var(--ok); }
.badge-grey { background: #eef1f6; color: #6b7587; }

.empty { text-align: center; padding: 72px 24px; background: var(--surface); border: 1px dashed #cfd7e6; border-radius: var(--radius); color: #98a2b3; }
.empty h3 { color: var(--ink); margin: 16px 0 6px; }
.empty .muted { max-width: 420px; margin: 0 auto; }

.mail-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.mail-row { display: grid; grid-template-columns: 220px 1fr 80px; gap: 16px; padding: 14px 18px; border-bottom: 1px solid var(--line); cursor: pointer; }
.mail-row:last-child { border-bottom: 0; }
.mail-row:hover { background: #fafbfe; }
.mail-row.unread { font-weight: 700; background: #fcfdff; }
.mail-row .mail-from, .mail-row .mail-subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-date { text-align: right; color: var(--ink-soft); font-weight: 500; font-size: 13px; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .auth-grid { grid-template-columns: 1fr; }
    .auth-brand { padding: 32px 24px; }
    .auth-brand h1 { font-size: 30px; }
    .auth-points { display: none; }
    .shell { grid-template-columns: 1fr; }
    .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
    .nav-list { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 12px; }
    .nav-section { display: none; }
    .topbar { grid-template-columns: auto 1fr auto; }
    .topbar-search, .who { display: none; }
    .content { padding: 20px 16px 40px; }
    .form-grid { grid-template-columns: 1fr; }
    .mail-row { grid-template-columns: 1fr 70px; }
    .mail-row .mail-from { grid-column: 1 / -1; }
}

/* ---------- Phase 2: inbox and message view ---------- */
.small { font-size: 13px; }
.count { margin-left: auto; min-width: 22px; padding: 1px 8px; border-radius: 999px; background: var(--brand); color: #fff; font-size: 12px; font-weight: 700; text-align: center; }
.nav-item.active .count { background: var(--brand-dark); }

a.mail-row { color: inherit; }
a.mail-row:hover { text-decoration: none; }
.mail-row .clip { margin-left: 8px; font-size: 13px; opacity: .7; }
.mail-row:not(.unread) .mail-from, .mail-row:not(.unread) .mail-subject { color: var(--ink-soft); }

.pager { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 20px; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.toolbar-actions .inline { margin-left: 0; }

.message-head { padding: 24px 28px 18px; border-bottom: 1px solid var(--line); }
.message-head h1 { font-size: 22px; margin-bottom: 16px; overflow-wrap: anywhere; }
.message-meta { display: flex; align-items: center; gap: 14px; }
.message-meta-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.avatar-lg { width: 44px; height: 44px; font-size: 18px; flex: none; }
.message-body { padding: 22px 28px; }
.mailframe { width: 100%; min-height: 120px; border: 0; display: block; background: #fff; }
.mail-text { margin: 0; font: inherit; white-space: pre-wrap; overflow-wrap: anywhere; }

.notice { padding: 10px 28px; background: #fff8e6; color: #7a5a00; border-bottom: 1px solid #f3e3b3; font-size: 14px; }

.attachments { padding: 18px 28px 24px; border-top: 1px solid var(--line); background: #fafbfe; }
.attachments-title { font-size: 14px; margin-bottom: 12px; }
.attachment-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.attachment { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.attachment-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }

@media (max-width: 900px) {
    .message-head, .message-body, .attachments, .notice { padding-left: 16px; padding-right: 16px; }
    .message-meta { flex-wrap: wrap; }
    .topbar-search { display: none; }
}
