:root {
  --bg: #f4f6f8; --panel: #fff; --text: #1f2328; --muted: #5f6872; --line: #e3e7eb;
  --accent: #1f6feb; --accent-text: #fff; --accent-soft: #dfeafd; --hover: #eef1f4; --unread: #fff;
  --read: #f8f9fa; --star: #e0a100; --danger: #c62828; --shadow: 0 8px 28px rgba(20, 30, 45, .22);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181c; --panel: #1d2126; --text: #e6e9ec; --muted: #9aa4ae; --line: #30363d;
    --accent: #5b9dff; --accent-text: #08111f; --accent-soft: #233a5c; --hover: #272c33; --unread: #1d2126;
    --read: #191c20; --danger: #ff7b72; --shadow: 0 8px 28px rgba(0, 0, 0, .6);
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn { border: 1px solid transparent; border-radius: 8px; padding: 7px 14px; background: transparent; white-space: nowrap; }
.btn.primary { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:disabled { opacity: .6; cursor: default; }
.btn.ghost { color: var(--text); }
.btn.ghost:hover { background: var(--hover); }
.btn.outline { border-color: var(--line); background: var(--panel); }
.btn.outline:hover { background: var(--hover); }
.icon-btn { border: 0; background: none; font-size: 20px; line-height: 1; width: 30px; height: 30px; border-radius: 6px; }
.link-btn { border: 0; background: none; color: var(--muted); padding: 0 2px; white-space: nowrap; }
.link-btn:hover { color: var(--text); text-decoration: underline; }
.form-error { color: var(--danger); margin: 6px 0; min-height: 0; }
.form-error:empty { display: none; }

.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: flex; flex-direction: column; }
.login-card h1 { font-size: 20px; margin: 10px 0 18px; }
.login-card label { font-weight: 600; margin: 8px 0 4px; }
.login-card input { padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); }
.login-card .btn { margin-top: 16px; padding: 10px; }
.brand-mark { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--accent); color: var(--accent-text); font-size: 22px; }
.brand-mark.small { width: 28px; height: 28px; font-size: 16px; border-radius: 7px; }

.app { height: 100%; display: grid; grid-template: 56px minmax(0, 1fr) / 216px minmax(0, 1fr); }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 0 14px; min-width: 0; }
.brand { display: flex; align-items: center; gap: 8px; font-size: 18px; font-weight: 600; color: var(--text); text-decoration: none; width: 180px; flex: none; }
.menu-btn { display: none; padding: 6px 10px; font-size: 18px; }
.search { flex: 1; max-width: 680px; min-width: 0; }
.search input { width: 100%; padding: 9px 16px; border: 1px solid transparent; border-radius: 22px; background: var(--hover); }
.search input:focus { background: var(--panel); border-color: var(--line); outline: none; box-shadow: 0 1px 4px rgba(0, 0, 0, .15); }
.account { margin-left: auto; display: flex; align-items: center; gap: 6px; min-width: 0; }
.account-email { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar { padding: 6px 10px; overflow-y: auto; }
.compose-btn { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 13px 22px; font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .12); margin-bottom: 12px; }
.compose-btn:hover { background: var(--hover); }
.folder { display: flex; justify-content: space-between; gap: 8px; padding: 7px 14px; border-radius: 18px; color: var(--text); text-decoration: none; }
.folder:hover { background: var(--hover); }
.folder.active { background: var(--accent-soft); font-weight: 600; }
.folder .count { font-size: 12px; font-weight: 600; }

.content { background: var(--panel); border-radius: 14px 0 0 0; min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.toolbar { display: flex; align-items: center; gap: 2px; padding: 6px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; min-height: 46px; }
.toolbar .btn { padding: 5px 10px; }
.toolbar .spacer, .spacer { flex: 1; }
.pager { color: var(--muted); display: flex; align-items: center; gap: 2px; white-space: nowrap; }
.list { flex: 1; overflow-y: auto; min-height: 0; }
.row { display: grid; grid-template-columns: 26px 26px minmax(90px, 200px) minmax(0, 1fr) auto; align-items: center; gap: 6px; padding: 0 14px 0 12px; height: 42px; border-bottom: 1px solid var(--line); background: var(--read); cursor: pointer; }
.row:hover { box-shadow: inset 0 0 0 1px var(--line), 0 1px 4px rgba(0, 0, 0, .12); position: relative; }
.row.unread { background: var(--unread); font-weight: 650; }
.row.selected { background: var(--accent-soft); }
.row .who, .row .subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.row.unread .when { color: var(--text); }
.star { border: 0; background: none; color: var(--muted); font-size: 17px; line-height: 1; padding: 2px; }
.star.on { color: var(--star); }
.empty { padding: 56px 20px; text-align: center; color: var(--muted); }

.reader { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.reader-head { padding: 12px 20px 8px; }
.reader-head h2 { margin: 0 0 10px; font-size: 20px; font-weight: 500; overflow-wrap: anywhere; }
.meta { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.meta .from { font-weight: 600; overflow-wrap: anywhere; }
.meta .recipients { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.meta .when { color: var(--muted); font-size: 13px; white-space: nowrap; }
.notice { margin: 8px 20px 0; padding: 7px 12px; border-radius: 8px; background: var(--hover); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.frame { flex: 1; min-height: 220px; width: 100%; border: 0; background: #fff; padding: 0 18px; }
.attachments { display: flex; gap: 8px; flex-wrap: wrap; padding: 10px 20px; border-top: 1px solid var(--line); }
.chip { border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; text-decoration: none; color: var(--text); overflow-wrap: anywhere; }
.chip:hover { background: var(--hover); }
.chip small { color: var(--muted); margin-left: 6px; }
.reply-bar { display: flex; gap: 8px; padding: 10px 20px 14px; border-top: 1px solid var(--line); flex-wrap: wrap; }

.composer { position: fixed; right: 24px; bottom: 0; z-index: 20; width: 560px; max-width: 100%; height: min(620px, 92vh); background: var(--panel); border-radius: 12px 12px 0 0; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.composer-head { background: var(--text); color: var(--panel); border-radius: 12px 12px 0 0; padding: 8px 8px 8px 16px; display: flex; justify-content: space-between; align-items: center; font-weight: 600; }
.composer-head .icon-btn { color: var(--panel); }
#composer-form { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 0 14px 10px; }
.field { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); padding: 2px 0; }
.field label { color: var(--muted); min-width: 50px; }
.field input { flex: 1; min-width: 0; border: 0; background: none; padding: 7px 0; outline: none; }
#c-body { flex: 1; min-height: 80px; border: 0; background: none; resize: none; outline: none; padding: 10px 0; }
.file-list { list-style: none; margin: 0; padding: 0; max-height: 96px; overflow-y: auto; }
.file-list li { display: flex; justify-content: space-between; gap: 8px; align-items: center; background: var(--hover); border-radius: 6px; padding: 2px 4px 2px 10px; margin-bottom: 4px; overflow-wrap: anywhere; }
.composer-foot { display: flex; align-items: center; gap: 4px; padding-top: 8px; flex-wrap: wrap; }
.attach { cursor: pointer; }

.toast { position: fixed; left: 24px; bottom: 24px; z-index: 30; background: var(--text); color: var(--panel); padding: 10px 16px; border-radius: 8px; max-width: calc(100% - 48px); }

@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .menu-btn { display: block; }
  .brand { width: auto; }
  .brand span:last-child, .account-email { display: none; }
  .topbar { gap: 6px; padding: 0 8px; }
  .sidebar { position: fixed; z-index: 10; top: 56px; bottom: 0; left: 0; width: 240px; background: var(--bg); transform: translateX(-105%); transition: transform .15s; }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .content { border-radius: 0; }
  .row { grid-template-columns: 26px 26px minmax(0, 1fr) auto; grid-template-rows: auto auto; height: auto; padding: 8px 12px 8px 8px; row-gap: 0; }
  .row .check, .row .star { grid-row: 1 / 3; }
  .row .who { grid-column: 3; }
  .row .when { grid-column: 4; grid-row: 1; }
  .row .subject { grid-column: 3 / 5; grid-row: 2; color: var(--muted); }
  .composer { right: 0; width: 100%; height: 100%; border-radius: 0; }
  .composer-head { border-radius: 0; }
  .toast { left: 16px; bottom: 16px; max-width: calc(100% - 32px); }
  .reader-head, .attachments, .reply-bar { padding-left: 14px; padding-right: 14px; }
  .frame { padding: 0 12px; }
}
