
:root {
  --bg: #f6f8fc;
  --surface: #ffffff;
  --surface-2: #f1f3f4;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15,23,42,.04), 0 8px 24px rgba(15,23,42,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #171a22;
    --surface-2: #1f2430;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --line: #2a3040;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.sr-only { position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; border:0; }
.icon { width: 20px; height: 20px; flex: none; }
.icon.small { width: 16px; height: 16px; }

.topbar {
  position: sticky; top: 0; z-index: 20; height: 64px; display: flex; align-items: center; gap: 12px;
  padding: 0 18px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; letter-spacing: -.02em; min-width: 190px; }
.brand-mark, .auth-mark { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 10px; background: var(--primary); color: white; }
.brand-mark .icon, .auth-mark .icon { width: 19px; height: 19px; }
.search { flex: 1; max-width: 720px; display: flex; align-items: center; gap: 8px; background: var(--surface-2); border: 1px solid transparent; border-radius: 999px; padding: 0 16px; height: 44px; }
.search:focus-within { background: var(--surface); border-color: var(--line); box-shadow: var(--shadow); }
.search .icon { color: var(--muted); }
.search input { border: 0; background: transparent; outline: 0; width: 100%; font-size: 15px; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 2px; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; border-radius: 50%; border: 0; background: transparent; color: var(--muted); }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.small { width: 30px; height: 30px; }
.icon-btn.small .icon { width: 16px; height: 16px; }
.inline-form { display: inline; }
.menu-btn { display: none; }

.shell { display: flex; min-height: calc(100vh - 64px); }
.sidebar { width: 248px; flex: none; padding: 14px 10px 18px; display: flex; flex-direction: column; gap: 10px; }
.compose-btn {
  display: flex; align-items: center; gap: 10px; padding: 0 18px; height: 50px; border-radius: 14px;
  background: var(--primary); color: #fff; font-weight: 600; box-shadow: 0 6px 16px rgba(79,70,229,.25);
  margin: 0 6px 8px; align-self: flex-start;
}
.compose-btn:hover { background: var(--primary-dark); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: 14px; height: 40px; padding: 0 18px; border-radius: 999px; color: var(--text); }
.nav-item .icon { color: var(--muted); }
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: #e0e7ff; color: var(--primary-dark); font-weight: 600; }
.nav-item.active .icon { color: var(--primary-dark); }
@media (prefers-color-scheme: dark) { .nav-item.active { background: #28305a; color: #c7d2fe; } .nav-item.active .icon { color:#c7d2fe; } }
.nav-label { flex: 1; }
.nav-count { font-size: 12px; font-weight: 700; background: var(--primary); color: #fff; border-radius: 999px; min-width: 20px; height: 20px; padding: 0 6px; display: inline-flex; align-items: center; justify-content: center; }
.sidebar-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--line); }
.account { display: flex; align-items: center; gap: 10px; padding: 8px; }
.account-text { min-width: 0; display: flex; flex-direction: column; }
.account-text strong { font-size: 13px; }
.account-text span { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mailbox-switch { padding: 6px 8px; }
.mailbox-switch select { width: 100%; padding: 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); }

.avatar { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 50%; background: var(--primary); color: #fff; font-weight: 700; font-size: 14px; flex: none; }
.avatar.small { width: 32px; height: 32px; font-size: 12px; }

.main { flex: 1; min-width: 0; background: var(--surface); border-radius: 20px 20px 0 0; margin: 0 12px 0 0; box-shadow: var(--shadow); min-height: calc(100vh - 76px); }
.list-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 22px 26px 10px; }
.list-header h1 { margin: 0; font-size: 21px; font-weight: 600; letter-spacing: -.02em; }
.list-header p { margin: 4px 0 0; }
.list-toolbar { display: flex; align-items: center; justify-content: space-between; padding: 8px 26px; border-bottom: 1px solid var(--line); }
.link-btn { border: 0; background: none; color: var(--primary); font-weight: 600; padding: 4px; }
.link-btn:hover { text-decoration: underline; }
.thread-list { padding: 4px 8px 30px; }
.thread-row { display: flex; align-items: center; gap: 6px; border-radius: 12px; padding: 0 6px; position: relative; }
.thread-row:hover { background: var(--surface-2); }
.thread-row.unread .sender, .thread-row.unread .thread-subject { font-weight: 700; }
.thread-row.unread { background: color-mix(in srgb, var(--primary) 5%, transparent); }
.star-form { display: flex; }
.star-btn { border: 0; background: transparent; color: #cbd5e1; padding: 6px; border-radius: 50%; }
.star-btn:hover { background: var(--surface); }
.star-btn.on { color: #f59e0b; }
.star-btn.on .icon { fill: #f59e0b; }
.thread-link { flex: 1; min-width: 0; display: block; padding: 12px 8px; }
.thread-top { display: flex; align-items: baseline; gap: 12px; }
.sender { font-size: 13.5px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-date { margin-left: auto; font-size: 12px; color: var(--muted); white-space: nowrap; }
.thread-bottom { display: flex; align-items: baseline; gap: 8px; margin-top: 2px; min-width: 0; }
.thread-subject { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55%; }
.thread-snippet { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.count-badge { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 6px; }
.row-actions { display: none; gap: 2px; padding-right: 4px; }
.thread-row:hover .row-actions { display: flex; }
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 90px 20px; color: var(--muted); gap: 12px; }
.empty .icon { width: 48px; height: 48px; opacity: .4; }

.thread-view { padding-bottom: 40px; }
.thread-toolbar { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.toolbar-actions { display: flex; gap: 2px; }
.star-on { color: #f59e0b; }
.star-on .icon { fill: #f59e0b; }
.thread-title { padding: 22px 28px 6px; display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.thread-title h1 { margin: 0; font-size: 23px; font-weight: 600; letter-spacing: -.02em; }
.messages { padding: 10px 20px; }
.message { border: 1px solid var(--line); border-radius: 14px; margin: 14px 0; overflow: hidden; background: var(--surface); }
.msg-head { display: flex; align-items: flex-start; gap: 12px; padding: 16px 18px; background: var(--surface-2); }
.msg-meta { min-width: 0; flex: 1; }
.msg-from { font-size: 13.5px; }
.msg-from .muted { font-weight: 400; font-size: 12.5px; }
.msg-to { font-size: 12px; margin-top: 2px; }
.msg-date { font-size: 12px; color: var(--muted); white-space: nowrap; }
.msg-body { padding: 20px; overflow: hidden; }
.msg-text { margin: 0; white-space: pre-wrap; word-break: break-word; font-family: inherit; font-size: 14px; line-height: 1.55; }
.email-frame { width: 100%; height: 420px; border: 0; background: #fff; border-radius: 8px; }
.show-images { display: inline-block; margin-top: 8px; font-size: 12px; color: var(--primary); font-weight: 600; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 20px 18px; }
.attachment { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 12.5px; background: var(--surface-2); max-width: 100%; }
.attachment span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment em { color: var(--muted); font-style: normal; font-size: 11px; }
.attachment .icon { width: 15px; height: 15px; color: var(--muted); }

.reply-card { margin: 20px; border: 1px solid var(--line); border-radius: 14px; padding: 16px; background: var(--surface); }
.reply-head { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-bottom: 10px; }
.reply-head .icon { color: var(--muted); width: 18px; height: 18px; }
.reply-card textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); padding: 12px; resize: vertical; outline: none; }
.reply-card textarea:focus { border-color: var(--primary); background: var(--surface); }
.reply-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 18px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; font-size: 13.5px; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.small { height: 30px; padding: 0 12px; font-size: 12px; }
.btn.block { width: 100%; height: 44px; }

.compose-page, .settings-page, .admin-page { padding-bottom: 60px; }
.compose-form { padding: 8px 26px 26px; }
.compose-row { display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); padding: 12px 0; }
.compose-row > span { width: 64px; color: var(--muted); font-size: 13px; }
.compose-row input, .compose-row select { flex: 1; border: 0; background: transparent; outline: none; font-size: 14px; }
.compose-body { width: 100%; border: 0; outline: none; background: transparent; padding: 16px 0; resize: vertical; font-size: 14px; line-height: 1.6; }
.compose-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.compose-hint { margin-left: auto; font-size: 12px; }

.settings-page .panel, .admin-page .panel { margin: 16px 26px; border: 1px solid var(--line); border-radius: 14px; padding: 20px; }
.panel h2 { margin: 0 0 14px; font-size: 15px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.field > span { color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); outline: none; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--primary); background: var(--surface); }
.grid-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-action { display: flex; align-items: flex-end; }
.input-suffix { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); overflow: hidden; }
.input-suffix input { border: 0; background: transparent; border-radius: 0; }
.input-suffix span { padding: 0 12px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.table td { padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.user-cell { display: flex; align-items: center; gap: 10px; }
.pill { display: inline-flex; align-items: center; height: 22px; padding: 0 9px; border-radius: 999px; background: var(--surface-2); font-size: 11px; font-weight: 700; text-transform: capitalize; }
.pill.admin { background: #ede9fe; color: #6d28d9; }
.pill.on { background: #dcfce7; color: #15803d; }
.pill.off { background: #fee2e2; color: #b91c1c; }
.row-actions-cell { display: flex; gap: 6px; align-items: center; white-space: nowrap; }
.credentials { margin: 16px 26px; border: 1px solid #a7f3d0; background: #ecfdf5; color: #065f46; border-radius: 14px; padding: 18px 20px; }
@media (prefers-color-scheme: dark) { .credentials { background: #052e24; border-color: #065f46; color: #a7f3d0; } }
.credentials h2 { margin: 0 0 6px; font-size: 15px; }
.credentials dl { display: grid; grid-template-columns: 160px 1fr; gap: 6px 12px; margin: 12px 0 0; }
.credentials dt { font-weight: 700; }
.credentials dd { margin: 0; }
.credentials code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: rgba(0,0,0,.06); padding: 2px 6px; border-radius: 6px; }
.flash { display: flex; align-items: center; gap: 8px; margin: 12px 26px 0; padding: 10px 14px; border-radius: 10px; background: #ecfdf5; color: #065f46; font-size: 13px; }
.flash.error { background: #fef2f2; color: #991b1b; }
.flash .icon { width: 17px; height: 17px; }

.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: radial-gradient(circle at 50% 0%, color-mix(in srgb, var(--primary) 14%, transparent), transparent 60%), var(--bg); padding: 20px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 30px; box-shadow: var(--shadow); }
.auth-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 19px; margin-bottom: 24px; }
.auth-card h1 { margin: 0; font-size: 24px; letter-spacing: -.02em; }
.auth-card .muted { margin: 6px 0 20px; font-size: 13px; }
.auth-foot { margin: 20px 0 0; text-align: center; font-size: 12px; color: var(--muted); }

@media (max-width: 860px) {
  .brand-name { display: none; }
  .brand { min-width: 44px; }
  .menu-btn { display: inline-flex; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 40; background: var(--surface); width: 270px; transform: translateX(-105%); transition: transform .2s ease; box-shadow: var(--shadow); }
  body.menu-open .sidebar { transform: translateX(0); }
  .mobile-scrim { display: none; position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.35); }
  body.menu-open .mobile-scrim { display: block; }
  .main { margin: 0; border-radius: 0; }
  .grid-form { grid-template-columns: 1fr; }
  .thread-subject { max-width: 45%; }
  .row-actions { display: none !important; }
  .email-frame { height: 360px; }
}
