:root {
  --bg: #f3f6f5; --surface: #ffffff; --surface-2: #eaf0ef; --border: #d9e2e0; --text: #182423; --muted: #5d6e6c;
  --accent: #0f6e66; --accent-hover: #0b5a54; --accent-soft: #d9efec; --on-accent: #ffffff; --danger: #b3261e; --star: #c98a00;
  --shadow: 0 12px 40px rgba(16, 40, 38, .18);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101615; --surface: #171f1e; --surface-2: #212b2a; --border: #2d3a38; --text: #e6eeec; --muted: #94a5a2;
    --accent: #4fc4b8; --accent-hover: #6ad4c9; --accent-soft: #1d3a37; --on-accent: #06211e; --danger: #f2877f; --star: #efb935;
    --shadow: 0 12px 40px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
#root { height: 100%; }
h1, h2 { margin: 0; line-height: 1.25; }
[hidden] { display: none !important; }
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.spacer { flex: 1; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 38px; padding: 8px 14px; border: 1px solid transparent; border-radius: 9px; font: inherit; font-weight: 600; color: var(--text); background: transparent; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.ghost { border-color: var(--border); background: var(--surface); }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn.wide { width: 100%; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; flex: none; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
input, select { font: inherit; color: var(--text); }
input[type=text], input[type=password], input[type=search] { width: 100%; min-height: 40px; padding: 8px 11px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); }
label { display: block; font-size: 13px; font-weight: 600; }
label input { margin-top: 5px; font-weight: 400; font-size: 15px; }

/* login */
.login-page { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; display: grid; gap: 14px; padding: 30px 26px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; }
.login-card h1 { font-size: 24px; }
.login-card p { margin: 0; }
.login-logo { width: 44px; height: 44px; }
.form-error { margin: 0; padding: 9px 11px; border-radius: 8px; background: color-mix(in srgb, var(--danger) 13%, transparent); color: var(--danger); font-size: 14px; }

/* layout */
.app { height: 100%; display: grid; grid-template-columns: 236px minmax(310px, 400px) minmax(0, 1fr); }
.sidebar { display: flex; flex-direction: column; gap: 10px; padding: 14px 10px; min-height: 0; border-right: 1px solid var(--border); background: var(--surface); }
.brand { display: flex; align-items: center; gap: 9px; padding: 2px 6px; font-weight: 700; font-size: 16px; }
.brand img { width: 26px; height: 26px; }
.compose-btn { margin: 4px 2px; }
.folders { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.folder { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 38px; padding: 7px 10px; border: 0; border-radius: 8px; background: transparent; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.folder:hover { background: var(--surface-2); }
.folder.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.folder-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { min-width: 22px; padding: 0 6px; border-radius: 11px; background: var(--accent); color: var(--on-accent); font-size: 12px; font-weight: 700; line-height: 22px; text-align: center; }
.new-folder { margin: 0 2px; font-weight: 500; }
.account { display: flex; align-items: center; gap: 8px; padding: 8px 4px 0; border-top: 1px solid var(--border); }
.account-email { flex: 1; min-width: 0; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; flex: none; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.avatar.small { width: 30px; height: 30px; font-size: 12px; }
.backdrop { display: none; }

.list-pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; border-right: 1px solid var(--border); background: var(--surface); }
.toolbar { display: flex; align-items: center; gap: 6px; padding: 10px 10px 6px; }
.nav-toggle { display: none; }
.search { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 0 11px; border-radius: 10px; background: var(--surface-2); color: var(--muted); }
.search input { border: 0; background: transparent; min-height: 38px; padding: 0; outline: none; }
.list-head { display: flex; align-items: center; gap: 6px; min-height: 46px; padding: 4px 14px; border-bottom: 1px solid var(--border); }
.msg-list { flex: 1; min-height: 0; overflow-y: auto; }
.empty { padding: 36px 20px; color: var(--muted); text-align: center; }
.msg { display: flex; align-items: flex-start; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--border); border-left: 3px solid transparent; cursor: pointer; }
.msg:hover { background: var(--surface-2); }
.msg.active { background: var(--accent-soft); }
.msg.unread { border-left-color: var(--accent); }
.msg.unread .msg-from, .msg.unread .msg-subject { font-weight: 700; color: var(--text); }
.msg-check { margin: 3px 0 0; width: 16px; height: 16px; accent-color: var(--accent); flex: none; }
.msg-body { flex: 1; min-width: 0; }
.msg-top, .msg-bottom { display: flex; align-items: center; gap: 8px; }
.msg-from { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.msg-date { flex: none; font-size: 12px; color: var(--muted); }
.msg-subject { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 14px; }
.msg-bottom .icon { width: 15px; height: 15px; color: var(--muted); }
.star { display: inline-flex; padding: 2px; border: 0; background: transparent; color: var(--muted); cursor: pointer; border-radius: 5px; }
.star.on .icon { color: var(--star); fill: var(--star); }

.reader { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface); }
.reader-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: var(--muted); }
.reader-empty .icon { width: 42px; height: 42px; opacity: .55; }
.reader-bar { display: flex; align-items: center; gap: 6px; padding: 9px 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.reader-bar .back { display: none; }
.move-select { min-height: 34px; max-width: 130px; padding: 3px 6px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); font-size: 13px; }
.reader-head { padding: 16px 20px 12px; }
.reader-head h2 { font-size: 20px; margin-bottom: 12px; overflow-wrap: anywhere; }
.sender { display: flex; gap: 11px; align-items: flex-start; }
.sender-info { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.sender time { flex: none; }
.notice { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: 0 20px 10px; padding: 8px 12px; border-radius: 9px; background: var(--surface-2); font-size: 13px; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 20px 12px; }
.attachment { display: inline-flex; align-items: center; gap: 7px; max-width: 100%; padding: 6px 10px; border: 1px solid var(--border); border-radius: 9px; color: var(--text); text-decoration: none; font-size: 13px; }
a.attachment:hover { background: var(--surface-2); }
.att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-frame { flex: 1; min-height: 0; width: 100%; border: 0; border-top: 1px solid var(--border); background: #fff; }

/* compose */
.compose { position: fixed; right: 24px; bottom: 0; z-index: 30; display: flex; flex-direction: column; width: min(640px, calc(100vw - 48px)); height: min(640px, calc(100dvh - 40px)); background: var(--surface); border: 1px solid var(--border); border-radius: 14px 14px 0 0; box-shadow: var(--shadow); }
.compose-head { display: flex; align-items: center; padding: 6px 8px 6px 16px; border-bottom: 1px solid var(--border); }
.field { display: flex; align-items: center; gap: 8px; padding: 0 16px; border-bottom: 1px solid var(--border); font-weight: 400; }
.field span { width: 34px; flex: none; color: var(--muted); font-size: 13px; }
.field input { margin: 0; border: 0; border-radius: 0; background: transparent; outline: none; }
.subject-input { flex: none; border: 0 !important; border-bottom: 1px solid var(--border) !important; border-radius: 0 !important; padding: 8px 16px !important; font-weight: 600; outline: none; }
.tools { display: flex; gap: 2px; padding: 5px 12px; border-bottom: 1px solid var(--border); }
.tool { min-width: 32px; height: 30px; border: 0; border-radius: 6px; background: transparent; color: var(--text); font: inherit; font-weight: 700; cursor: pointer; }
.tool:hover { background: var(--surface-2); }
.editor { flex: 1; min-height: 80px; overflow-y: auto; padding: 12px 16px; outline: none; overflow-wrap: anywhere; }
.editor blockquote { margin: 8px 0 8px 4px; padding-left: 12px; border-left: 3px solid var(--border); color: var(--muted); }
.compose-att { padding: 8px 16px 0; max-height: 92px; overflow-y: auto; }
.chip-x { display: inline-flex; padding: 0; border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.chip-x .icon { width: 14px; height: 14px; }
.compose-foot { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 10px 12px; }

/* toasts and dialogs */
#toasts { position: fixed; left: 50%; bottom: 20px; z-index: 60; display: grid; gap: 8px; width: min(440px, calc(100vw - 32px)); transform: translateX(-50%); pointer-events: none; }
.toast { padding: 10px 14px; border-radius: 10px; background: var(--text); color: var(--bg); font-size: 14px; box-shadow: var(--shadow); text-align: center; }
.toast.error { background: var(--danger); color: #fff; }
.dialog { width: min(440px, calc(100vw - 32px)); padding: 22px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(8, 20, 19, .5); }
.dialog h2 { font-size: 18px; margin-bottom: 6px; }
.dialog p { margin: 0 0 12px; }
.dialog form { display: grid; gap: 4px; }
.dialog .form-error { margin-top: 8px; }
.dialog-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.cred { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 0; padding: 12px; border-radius: 10px; background: var(--surface-2); }
.cred dt { color: var(--muted); font-size: 13px; }
.cred dd { margin: 0; overflow-wrap: anywhere; font-weight: 600; }

/* admin */
.admin { min-height: 100%; }
.admin-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--border); }
.admin-main { max-width: 960px; margin: 0 auto; padding: 22px 16px; display: grid; gap: 18px; }
.card { padding: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }
.card h2 { font-size: 17px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.create-form { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 12px; margin-top: 12px; }
.create-form .grow { flex: 1 1 240px; }
.with-suffix { display: flex; align-items: flex-end; gap: 6px; }
.suffix { padding-bottom: 10px; color: var(--muted); font-weight: 400; font-size: 14px; white-space: nowrap; }
.accounts { width: 100%; border-collapse: collapse; }
.accounts th { padding: 8px 10px; color: var(--muted); font-size: 12px; font-weight: 600; text-align: left; border-bottom: 1px solid var(--border); }
.accounts td { padding: 10px; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.accounts tr:last-child td { border-bottom: 0; }
.accounts .actions { text-align: right; }

@media (max-width: 1040px) {
  .app { grid-template-columns: 210px minmax(0, 1fr); }
  .reader { display: none; grid-column: 2; }
  body.reading .list-pane { display: none; }
  body.reading .reader { display: flex; }
  .reader-bar .back { display: inline-flex; }
}
@media (max-width: 720px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .reader { grid-column: 1; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 20; width: min(280px, 84vw); transform: translateX(-100%); transition: transform .18s ease; }
  body.nav-open .sidebar { transform: none; box-shadow: var(--shadow); }
  body.nav-open .backdrop { display: block; position: fixed; inset: 0; z-index: 15; background: rgba(8, 20, 19, .45); }
  .nav-toggle { display: inline-flex; }
  .lbl { display: none; }
  .reader-head { padding: 14px 16px 10px; }
  .notice { margin: 0 16px 10px; }
  .attachments { padding: 0 16px 12px; }
  .sender { flex-wrap: wrap; }
  .sender time { width: 100%; padding-left: 51px; }
  .compose { inset: 0; width: 100%; height: 100dvh; border: 0; border-radius: 0; }
  .accounts thead { display: none; }
  .accounts, .accounts tbody, .accounts tr, .accounts td { display: block; width: 100%; }
  .accounts tr { padding: 10px 0; border-bottom: 1px solid var(--border); }
  .accounts tr:last-child { border-bottom: 0; }
  .accounts td { padding: 2px 0; border: 0; }
  .accounts td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: 13px; }
  .accounts .actions { padding-top: 8px; text-align: left; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
