:root {
  --bg: #f6f7f9;
  --panel: #fff;
  --text: #16181d;
  --muted: #6f7682;
  --line: #e8eaee;
  --accent: #111827;
  --radius: 14px;
  --sidebar: 236px;
  --topbar: 64px;
  --shadow: 0 8px 30px rgba(18, 24, 40, .06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { min-height: 100vh; }
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
svg { display: block; }
code { font-size: .92em; }

.app { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar) 1fr; }
.sidebar { position: sticky; top: 0; height: 100vh; background: #fff; border-right: 1px solid var(--line); padding: 18px 14px; display: flex; flex-direction: column; }
.brand { height: 46px; display: flex; align-items: center; gap: 10px; padding: 0 10px; margin-bottom: 12px; font-weight: 700; letter-spacing: -.02em; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; background: #111827; color: #fff; display: grid; place-items: center; font-size: 14px; flex: 0 0 auto; }
.compose-btn { height: 44px; border: 0; border-radius: 11px; background: #111827; color: #fff; display: flex; align-items: center; justify-content: center; gap: 9px; font-weight: 600; margin: 6px 2px 18px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a { display: flex; align-items: center; gap: 11px; height: 42px; padding: 0 12px; border-radius: 10px; color: #4b5563; font-size: 14px; }
.nav a:hover, .nav a.active { background: #f1f3f6; color: #111827; }
.nav .count { margin-left: auto; color: #8a919d; font-size: 12px; }
.nav a.active .count { color: #111827; }
.sidebar-bottom { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--line); }
.account { display: flex; align-items: center; gap: 10px; padding: 8px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: #e5e7eb; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: 0 0 auto; }
.account-meta { min-width: 0; }
.account-meta strong { display: block; font-size: 13px; }
.account-meta span { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logout-btn { width: 100%; border: 0; background: transparent; color: var(--muted); font-size: 12px; padding: 7px 8px; text-align: left; border-radius: 8px; }
.logout-btn:hover { background: #f4f5f7; color: var(--text); }

.main { min-width: 0; }
.topbar { height: var(--topbar); display: flex; align-items: center; gap: 16px; border-bottom: 1px solid var(--line); background: rgba(246, 247, 249, .94); padding: 0 22px; position: sticky; top: 0; z-index: 10; backdrop-filter: blur(10px); }
.page-title { font-weight: 700; font-size: 17px; letter-spacing: -.015em; min-width: 120px; }
.search { max-width: 620px; flex: 1; position: relative; margin: 0 auto; }
.search input { width: 100%; height: 40px; border: 1px solid var(--line); border-radius: 11px; background: #fff; padding: 0 42px; color: var(--text); outline: none; }
.search input:focus { border-color: #cfd4dc; box-shadow: 0 0 0 3px rgba(17, 24, 39, .04); }
.search svg { position: absolute; left: 14px; top: 11px; color: #8b929d; }
.icon-btn { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: #fff; display: grid; place-items: center; color: #505866; flex: 0 0 auto; }
.icon-btn:hover { background: #f5f6f8; }
.content { padding: 22px; }
.panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.alert { max-width: 920px; margin: 0 auto 14px; border: 1px solid; border-radius: 10px; padding: 11px 14px; font-size: 13px; }
.alert.error { color: #9b1c1c; background: #fff7f7; border-color: #f3cccc; }
.alert.success { color: #17633b; background: #f4fbf6; border-color: #cdebd7; }

.toolbar { min-height: 52px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; padding: 0 14px; }
.toolbar .spacer, .editor-header .spacer { flex: 1; }
.toolbar .small { font-size: 12px; color: var(--muted); }
.tool-btn { min-height: 34px; padding: 7px 11px; border: 1px solid var(--line); background: #fff; border-radius: 9px; color: #525a67; display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.tool-btn:hover { background: #f7f8fa; }
.tool-btn.primary { background: #111827; color: #fff; border-color: #111827; }

.mail-list { display: flex; flex-direction: column; }
.mail-row { display: grid; grid-template-columns: 22px minmax(160px, 220px) 1fr 132px; gap: 12px; align-items: center; min-height: 60px; padding: 9px 16px; border-bottom: 1px solid var(--line); background: #fff; }
.mail-row:last-child { border-bottom: 0; }
.mail-row:hover { background: #fafbfc; }
.mail-row.unread { background: #fff; font-weight: 650; }
.mail-dot { width: 7px; height: 7px; border-radius: 50%; background: transparent; margin: auto; }
.mail-row.unread .mail-dot { background: #111827; }
.mail-row .sender, .mail-row .subject { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mail-row .subjectline { min-width: 0; display: flex; gap: 7px; align-items: baseline; }
.mail-row .snippet { color: var(--muted); font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mail-row .time { text-align: right; color: #7b838f; font-size: 12px; white-space: nowrap; }
.mail-row .time small { display: inline-grid; place-items: center; min-width: 19px; height: 19px; margin-left: 7px; padding: 0 5px; border-radius: 999px; background: #f0f2f5; color: #59616d; }
.empty { padding: 70px 24px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--text); margin-bottom: 6px; }

.thread-wrap { max-width: 920px; margin: 0 auto; }
.thread-head { padding: 22px 24px; border-bottom: 1px solid var(--line); }
.thread-head h1 { font-size: 24px; line-height: 1.25; margin: 0 0 12px; letter-spacing: -.025em; }
.thread-meta { font-size: 13px; color: var(--muted); }
.message { padding: 22px 24px; border-bottom: 1px solid var(--line); }
.message.outbound { background: #fcfcfd; }
.message-top { display: flex; align-items: flex-start; gap: 12px; }
.message-avatar { width: 38px; height: 38px; border-radius: 50%; background: #e9ebef; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: 0 0 auto; }
.message-who { flex: 1; min-width: 0; }
.message-who strong { display: block; font-size: 14px; }
.message-who span { font-size: 12px; color: var(--muted); }
.message-time { font-size: 12px; color: var(--muted); text-transform: capitalize; }
.message-body { margin: 18px 0 0 50px; line-height: 1.65; font-size: 14px; color: #2d3138; white-space: pre-wrap; overflow-wrap: anywhere; }
.reply-box { padding: 18px 24px; }
.reply-box textarea { width: 100%; min-height: 120px; border: 1px solid var(--line); border-radius: 11px; padding: 14px; resize: vertical; outline: none; background: #fff; }
.reply-box textarea:focus { border-color: #cfd4dc; box-shadow: 0 0 0 3px rgba(17, 24, 39, .04); }
.reply-actions { display: flex; align-items: center; gap: 8px; margin-top: 10px; }

.editor { max-width: 920px; margin: 0 auto; }
.editor-header { padding: 18px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.editor-header h1 { font-size: 17px; margin: 0; letter-spacing: -.015em; }
.form-row { display: grid; grid-template-columns: 72px 1fr; align-items: center; min-height: 52px; border-bottom: 1px solid var(--line); padding: 0 18px; }
.form-row label { font-size: 13px; color: var(--muted); }
.form-row input { width: 100%; border: 0; outline: none; height: 50px; color: #222; background: transparent; }
.editor-body { padding: 18px; }
.editor-body textarea { width: 100%; min-height: 420px; resize: vertical; border: 0; outline: none; font-size: 14px; line-height: 1.7; color: #2d3138; }
.editor-footer { border-top: 1px solid var(--line); padding: 14px 18px; display: flex; align-items: center; gap: 8px; }

.settings { max-width: 880px; margin: 0 auto; display: grid; gap: 16px; }
.settings-section { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.settings-section h2 { font-size: 15px; margin: 0; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.setting-row { display: grid; grid-template-columns: 220px 1fr; gap: 28px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.setting-row:last-child { border-bottom: 0; }
.setting-label strong { display: block; font-size: 13px; }
.setting-label span { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; line-height: 1.45; }
.setting-field input, .setting-field textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: none; background: #fff; }
.setting-field input[readonly] { background: #f7f8fa; color: var(--muted); }
.setting-field textarea { min-height: 100px; resize: vertical; }
.note { font-size: 12px; color: var(--muted); margin-top: 7px; line-height: 1.5; }
.settings-actions { display: flex; justify-content: flex-end; }

.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #f6f7f9; }
.login-shell { width: min(100%, 420px); }
.login-brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 22px; font-weight: 700; letter-spacing: -.02em; font-size: 18px; }
.login-card { background: #fff; border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); padding: 28px; }
.login-card h1 { margin: 0 0 8px; font-size: 24px; letter-spacing: -.03em; }
.login-card > p:not(.login-note) { margin: 0 0 24px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.login-card .alert { margin-bottom: 18px; }
.login-field { margin-bottom: 16px; }
.login-field label { display: block; margin-bottom: 7px; font-size: 13px; font-weight: 600; }
.login-field input { width: 100%; height: 44px; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; outline: none; background: #fff; }
.login-field input:focus { border-color: #c7ccd4; box-shadow: 0 0 0 3px rgba(17, 24, 39, .04); }
.login-btn { width: 100%; height: 44px; border: 0; border-radius: 10px; background: #111827; color: #fff; font-weight: 600; }
.login-note { margin: 18px 0 0; text-align: center; color: var(--muted); font-size: 12px; line-height: 1.5; }
.login-note a:hover { color: var(--text); }

@media (max-width: 820px) {
  :root { --sidebar: 72px; }
  .brand span:not(.brand-mark), .nav .label, .nav .count, .account-meta, .logout-btn { display: none; }
  .brand { justify-content: center; padding: 0; }
  .compose-btn span { display: none; }
  .compose-btn { width: 44px; margin-left: auto; margin-right: auto; }
  .nav a { justify-content: center; padding: 0; }
  .sidebar { padding-left: 10px; padding-right: 10px; }
  .mail-row { grid-template-columns: 14px minmax(100px, 140px) 1fr 84px; }
  .setting-row { grid-template-columns: 1fr; gap: 10px; }
}

@media (max-width: 600px) {
  :root { --sidebar: 58px; }
  .sidebar { padding: 12px 7px; }
  .compose-btn { width: 40px; }
  .content { padding: 12px; }
  .topbar { padding: 0 12px; gap: 10px; }
  .page-title { min-width: auto; }
  .mail-row { grid-template-columns: 10px 1fr 70px; gap: 8px; padding: 10px; }
  .mail-row .sender { display: none; }
  .mail-row .subjectline { display: block; }
  .mail-row .subject, .mail-row .snippet { display: block; }
  .message { padding: 18px 14px; }
  .message-time { max-width: 105px; text-align: right; }
  .message-body { margin-left: 0; }
  .reply-box { padding: 14px; }
  .form-row { grid-template-columns: 54px 1fr; padding: 0 12px; }
  .editor-body { padding: 12px; }
}
