/* Mail web client - layout and look inspired by modern webmail; all original code. */
:root {
  --bg: #f6f8fc;
  --surface: #ffffff;
  --surface-2: #f2f6fc;
  --hover: #eaf1fb;
  --selected: #d3e3fd;
  --nav-active: #d3e3fd;
  --compose: #c2e7ff;
  --compose-hover: #b3dcf7;
  --text: #1f1f1f;
  --text-2: #444746;
  --text-3: #5f6368;
  --border: #e0e3e7;
  --accent: #0b57d0;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --warn-bg: #fef7e0;
  --star: #f4b400;
  --shadow: 0 1px 2px rgba(60,64,67,.3), 0 1px 3px 1px rgba(60,64,67,.15);
  --shadow-lg: 0 4px 8px 3px rgba(60,64,67,.15), 0 1px 3px rgba(60,64,67,.3);
  --radius: 16px;
  --font: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --sidebar: 256px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418; --surface: #1b1f24; --surface-2: #171a1f; --hover: #262b33; --selected: #2c3a52; --nav-active: #2c3a52;
    --compose: #2b4b6b; --compose-hover: #345a80; --text: #e3e3e3; --text-2: #c4c7c5; --text-3: #9aa0a6; --border: #2e333a;
    --accent: #a8c7fa; --accent-text: #062e6f; --danger: #f2b8b5; --warn-bg: #3a3420;
    --shadow: 0 1px 2px rgba(0,0,0,.5), 0 1px 3px 1px rgba(0,0,0,.3); --shadow-lg: 0 4px 8px 3px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.4 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--text-3); }
svg.i { width: 20px; height: 20px; fill: currentColor; flex: none; display: block; }

/* ------------------------------------------------------------------ shell */
.app { display: grid; grid-template-columns: var(--sidebar) 1fr; grid-template-rows: 64px 1fr; height: 100vh; }
.app.collapsed { --sidebar: 72px; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; padding: 8px 16px 8px 12px; min-width: 0; }
.brand { display: flex; align-items: center; gap: 8px; width: 180px; text-decoration: none; color: var(--text-2); font-size: 22px; flex: none; }
.app.collapsed .brand { width: auto; }
.search { position: relative; flex: 1; max-width: 720px; display: flex; align-items: center; background: var(--hover); border-radius: 28px; height: 48px; padding: 0 6px; }
.search:focus-within { background: var(--surface); box-shadow: var(--shadow); }
.search input { flex: 1; border: 0; background: transparent; outline: none; font-size: 16px; min-width: 0; padding: 0 4px; }
.search input::-webkit-search-cancel-button { display: none; }
.search-panel { position: absolute; top: 52px; left: 0; right: 0; background: var(--surface); box-shadow: var(--shadow-lg); border-radius: 8px; padding: 20px 24px; z-index: 30; }
.search-panel .sp-row { display: grid; grid-template-columns: 140px 1fr; align-items: center; gap: 12px; margin-bottom: 10px; }
.search-panel input[type=text], .search-panel select, .search-panel input[type=number] { border: 0; border-bottom: 1px solid var(--border); background: transparent; padding: 6px 2px; outline: none; }
.search-panel .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.top-actions { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text-2); flex: none; text-decoration: none; }
.icon-btn:hover { background: rgba(68,71,70,.08); }
.icon-btn:disabled { opacity: .35; cursor: default; background: transparent; }
.icon-btn.small { width: 32px; height: 32px; }
.icon-btn.active svg { fill: var(--star); }
.avatar-btn { width: 32px; height: 32px; border-radius: 50%; border: 0; cursor: pointer; color: #fff; font-weight: 600; margin-left: 4px; }

.sidebar { overflow-y: auto; padding: 8px 0 24px; }
.compose-btn { display: inline-flex; align-items: center; gap: 12px; height: 56px; padding: 0 24px 0 16px; margin: 0 0 16px 8px; border: 0; border-radius: 16px; background: var(--compose); color: var(--text); font-weight: 500; cursor: pointer; box-shadow: none; transition: box-shadow .15s; }
.compose-btn:hover { box-shadow: var(--shadow); background: var(--compose-hover); }
.compose-btn svg { width: 24px; height: 24px; }
.app.collapsed .compose-btn { padding: 0 16px; }
.app.collapsed .compose-btn .label, .app.collapsed .nav .name, .app.collapsed .nav .count, .app.collapsed .nav-section span { display: none; }
.nav { list-style: none; margin: 0; padding: 0 12px 0 0; }
.nav a { display: flex; align-items: center; gap: 16px; height: 32px; padding: 0 12px 0 24px; border-radius: 0 16px 16px 0; color: var(--text); text-decoration: none; position: relative; }
.nav a:hover { background: rgba(68,71,70,.08); }
.nav a.active { background: var(--nav-active); font-weight: 700; }
.nav a.unread { font-weight: 700; }
.nav .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav .count { font-size: 12px; }
.nav .dot { width: 12px; height: 12px; border-radius: 3px; border: 2px solid var(--text-3); flex: none; margin: 0 4px; }
.nav .label-menu { position: absolute; right: 4px; display: none; }
.nav a:hover .label-menu { display: inline-flex; }
.nav a:hover .count { visibility: hidden; }
.nav-section { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 4px 26px; font-size: 16px; font-weight: 500; }

.main { background: var(--surface); border-radius: var(--radius); margin: 0 16px 16px 0; display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
.toolbar { display: flex; align-items: center; gap: 2px; height: 48px; padding: 0 16px 0 12px; border-bottom: 1px solid var(--border); flex: none; }
.toolbar .spacer { flex: 1; }
.toolbar .range { color: var(--text-3); font-size: 12px; margin-right: 8px; white-space: nowrap; }
.toolbar .sep { width: 1px; height: 20px; background: var(--border); margin: 0 8px; }
.content { flex: 1; overflow-y: auto; min-height: 0; }

/* ------------------------------------------------------------------ list */
.select-all { display: inline-flex; align-items: center; padding: 0 4px 0 8px; height: 40px; border-radius: 4px; }
.select-all:hover { background: rgba(68,71,70,.08); }
.select-all .icon-btn { width: 20px; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; margin: 0; }
.list { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; height: 40px; padding: 0 16px 0 12px; border-bottom: 1px solid var(--border); cursor: pointer; position: relative; background: var(--surface-2); }
.row.unread { background: var(--surface); font-weight: 700; }
.row:hover { box-shadow: inset 1px 0 0 #dadce0, inset -1px 0 0 #dadce0, 0 1px 2px 0 rgba(60,64,67,.3), 0 1px 3px 1px rgba(60,64,67,.15); z-index: 1; }
.row.selected { background: var(--selected); }
.row.cursor::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); }
.row .cb { width: 32px; display: flex; justify-content: center; flex: none; }
.row .star { width: 32px; height: 32px; flex: none; color: var(--text-3); }
.row .star.on { color: var(--star); }
.row .who { width: 200px; flex: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 24px; }
.row .who .n { font-weight: 400; color: var(--text-3); font-size: 12px; margin-left: 4px; }
.row .who b { font-weight: 700; }
.row .who .draft { color: var(--danger); font-weight: 400; }
.row .middle { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; overflow: hidden; white-space: nowrap; }
.row .subject { overflow: hidden; text-overflow: ellipsis; flex: none; max-width: 70%; }
.row .snippet { color: var(--text-3); font-weight: 400; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.row .att { color: var(--text-3); flex: none; }
.row .date { width: 80px; text-align: right; font-size: 12px; flex: none; color: var(--text-2); }
.row.unread .date { color: var(--text); }
.row .snooze-date { color: #b06000; }
.row .hover-actions { display: none; position: absolute; right: 8px; top: 0; bottom: 0; align-items: center; background: inherit; padding-left: 8px; }
.row:hover .hover-actions { display: flex; }
.row:hover .date { visibility: hidden; }
.chip { display: inline-flex; align-items: center; gap: 2px; padding: 0 6px; height: 18px; border-radius: 4px; font-size: 12px; font-weight: 400; background: #dde3ea; color: #1f1f1f; flex: none; max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.chip button { border: 0; background: transparent; cursor: pointer; padding: 0; margin-left: 2px; display: inline-flex; color: inherit; }
.chip button svg { width: 14px; height: 14px; }
.empty { padding: 48px 24px; text-align: center; color: var(--text-3); }
.loading { padding: 32px; text-align: center; color: var(--text-3); }

/* ------------------------------------------------------------------ conversation */
.conversation { padding: 0 0 48px; }
.conv-head { display: flex; align-items: center; gap: 12px; padding: 20px 24px 8px 72px; flex-wrap: wrap; }
.conv-head h2 { font-size: 22px; font-weight: 400; margin: 0; word-break: break-word; }
.conv-head .chip { height: 20px; }
.banner { margin: 8px 24px 8px 72px; padding: 12px 16px; border-radius: 8px; background: var(--warn-bg); display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.banner.info { background: var(--hover); }
.msg { border-bottom: 1px solid var(--border); padding: 0 24px 0 16px; }
.msg-head { display: flex; align-items: flex-start; gap: 12px; padding: 16px 0 8px; cursor: pointer; }
.msg .avatar { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 600; font-size: 16px; flex: none; }
.msg-head .who { flex: 1; min-width: 0; }
.msg-head .who .name { font-weight: 700; }
.msg-head .who .addr { color: var(--text-3); font-size: 12px; margin-left: 4px; }
.msg-head .to { color: var(--text-3); font-size: 12px; display: flex; align-items: center; }
.msg-head .to button { border: 0; background: transparent; cursor: pointer; padding: 0; color: inherit; display: inline-flex; }
.msg-head .when { color: var(--text-3); font-size: 12px; white-space: nowrap; display: flex; align-items: center; gap: 2px; }
.msg.collapsed .msg-head { padding: 10px 0; }
.msg.collapsed .snippet { color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .details { margin: 0 0 8px 52px; padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px; font-size: 12px; display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; max-width: 640px; }
.msg .details dt { color: var(--text-3); text-align: right; }
.msg .details dd { margin: 0; word-break: break-word; }
.msg-body { margin-left: 52px; padding-bottom: 12px; }
.msg-body iframe { width: 100%; border: 0; display: block; min-height: 40px; background: #fff; border-radius: 4px; }
.attachments { display: flex; flex-wrap: wrap; gap: 12px; margin: 8px 0 16px 52px; }
.attachment { width: 180px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; text-decoration: none; color: var(--text); display: flex; flex-direction: column; background: var(--surface); }
.attachment:hover { box-shadow: var(--shadow); }
.attachment .thumb { height: 100px; display: flex; align-items: center; justify-content: center; background: var(--surface-2); color: var(--text-3); overflow: hidden; }
.attachment .thumb img { width: 100%; height: 100%; object-fit: cover; }
.attachment .thumb svg { width: 40px; height: 40px; }
.attachment .meta { padding: 8px 10px; font-size: 12px; }
.attachment .meta .fname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.delivery { margin: 0 0 12px 52px; font-size: 12px; color: var(--text-3); }
.delivery .failed { color: var(--danger); }
.reply-bar { display: flex; gap: 12px; padding: 16px 24px 0 68px; }
.pill-btn { display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 18px 0 14px; border-radius: 18px; border: 1px solid var(--text-3); background: transparent; cursor: pointer; font-weight: 500; color: var(--text-2); }
.pill-btn:hover { background: rgba(68,71,70,.08); }
.inline-compose { margin: 16px 24px 0 68px; border-radius: 8px; box-shadow: var(--shadow); }

/* ------------------------------------------------------------------ menus, dialogs, toasts */
.menu { position: fixed; background: var(--surface); box-shadow: var(--shadow-lg); border-radius: 4px; padding: 6px 0; min-width: 200px; max-height: 70vh; overflow-y: auto; z-index: 100; }
.menu button, .menu label, .menu a { display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 16px; border: 0; background: transparent; text-align: left; cursor: pointer; text-decoration: none; color: var(--text); min-height: 32px; }
.menu button:hover, .menu label:hover, .menu a:hover { background: var(--hover); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }
.menu .menu-title { padding: 6px 16px; font-size: 12px; color: var(--text-3); }
.menu input[type=text], .menu input[type=datetime-local] { margin: 4px 16px 8px; width: calc(100% - 32px); padding: 6px 8px; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); }
.menu .hint { margin-left: auto; color: var(--text-3); font-size: 12px; }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 200; }
.dialog { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 24px; width: min(520px, calc(100vw - 32px)); max-height: 85vh; overflow-y: auto; }
.dialog h3 { margin: 0 0 16px; font-weight: 400; font-size: 20px; }
.dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.dialog table { width: 100%; border-collapse: collapse; }
.dialog td { padding: 4px 8px; }
.dialog kbd, .shortcut kbd { background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 0 6px; font-family: inherit; font-size: 12px; }
.text-btn { border: 0; background: transparent; color: var(--accent); font-weight: 500; cursor: pointer; padding: 8px 12px; border-radius: 18px; }
.text-btn:hover { background: var(--hover); }
.primary-btn { border: 0; background: var(--accent); color: var(--accent-text); font-weight: 500; cursor: pointer; padding: 0 24px; height: 36px; border-radius: 18px; }
.primary-btn:hover { box-shadow: var(--shadow); }
.primary-btn:disabled { opacity: .6; cursor: default; }
.danger-btn { border: 1px solid var(--danger); color: var(--danger); background: transparent; border-radius: 18px; height: 32px; padding: 0 14px; cursor: pointer; }
.toasts { position: fixed; left: 24px; bottom: 24px; display: flex; flex-direction: column; gap: 8px; z-index: 300; }
.toast { background: #313131; color: #f2f2f2; border-radius: 4px; padding: 12px 16px; display: flex; align-items: center; gap: 16px; min-width: 280px; max-width: 560px; box-shadow: var(--shadow-lg); }
.toast button { border: 0; background: transparent; color: #a8c7fa; font-weight: 600; cursor: pointer; padding: 4px 8px; }
.toast .close { color: #ccc; margin-left: auto; display: inline-flex; }

/* ------------------------------------------------------------------ compose */
.compose-dock { position: fixed; right: 16px; bottom: 0; display: flex; align-items: flex-end; gap: 16px; z-index: 150; pointer-events: none; }
.compose { width: 540px; height: 560px; background: var(--surface); border-radius: 8px 8px 0 0; box-shadow: 0 8px 10px 1px rgba(0,0,0,.14), 0 3px 14px 2px rgba(0,0,0,.12), 0 5px 5px -3px rgba(0,0,0,.2); display: flex; flex-direction: column; pointer-events: auto; overflow: hidden; }
.compose.min { height: 40px; width: 280px; }
.compose.min > :not(.c-head) { display: none; }
.compose.full { position: fixed; inset: 5vh 10vw; width: auto; height: auto; border-radius: 8px; }
.inline-compose .compose, .compose.inline { width: auto; height: auto; min-height: 260px; border-radius: 8px; box-shadow: none; }
.c-head { display: flex; align-items: center; height: 40px; padding: 0 8px 0 16px; background: var(--hover); cursor: pointer; font-weight: 500; flex: none; }
.c-head .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-head .icon-btn { width: 28px; height: 28px; }
.c-head .icon-btn svg { width: 18px; height: 18px; }
.c-field { display: flex; align-items: center; border-bottom: 1px solid var(--border); margin: 0 16px; min-height: 36px; position: relative; flex: none; }
.c-field > span { color: var(--text-3); margin-right: 8px; }
.c-field input, .c-field select { flex: 1; border: 0; outline: none; background: transparent; padding: 6px 0; min-width: 0; }
.c-field .toggles { display: flex; gap: 4px; }
.c-field .toggles button { border: 0; background: transparent; cursor: pointer; color: var(--text-2); padding: 4px; }
.c-field .toggles button:hover { text-decoration: underline; }
.suggest { position: absolute; top: 100%; left: 0; right: 0; background: var(--surface); box-shadow: var(--shadow-lg); border-radius: 4px; z-index: 5; max-height: 260px; overflow-y: auto; }
.suggest div { padding: 8px 12px; cursor: pointer; display: flex; flex-direction: column; }
.suggest div small { color: var(--text-3); }
.suggest div.on, .suggest div:hover { background: var(--hover); }
.c-body { flex: 1; overflow-y: auto; padding: 12px 16px; outline: none; min-height: 120px; word-break: break-word; }
.c-body blockquote { margin: 0 0 0 .8ex; border-left: 1px solid #ccc; padding-left: 1ex; }
.c-quote-toggle { margin: 0 16px; border: 0; background: var(--surface-2); border-radius: 8px; cursor: pointer; padding: 0 8px; height: 16px; line-height: 10px; color: var(--text-3); align-self: flex-start; }
.c-attachments { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 8px; }
.c-attachments .file { display: inline-flex; align-items: center; gap: 6px; background: var(--surface-2); border-radius: 4px; padding: 4px 4px 4px 8px; font-size: 12px; font-weight: 500; max-width: 100%; }
.c-attachments .file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 300px; }
.c-attachments .file small { color: var(--text-3); font-weight: 400; }
.c-format { display: flex; gap: 2px; padding: 4px 12px; border-top: 1px solid var(--border); flex: none; }
.c-format .icon-btn { width: 32px; height: 32px; border-radius: 4px; }
.c-foot { display: flex; align-items: center; gap: 4px; padding: 10px 16px 14px; flex: none; }
.c-foot .status { color: var(--text-3); font-size: 12px; margin-left: 8px; }
.c-foot .spacer { flex: 1; }
.c-error { color: var(--danger); padding: 0 16px; font-size: 13px; }

/* ------------------------------------------------------------------ settings */
.settings { padding: 0 32px 48px; max-width: 980px; }
.settings h2 { font-weight: 400; font-size: 22px; margin: 20px 0 8px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 8px; overflow-x: auto; }
.tabs a { padding: 12px 16px; text-decoration: none; color: var(--text-2); border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 500; }
.setting { display: grid; grid-template-columns: 220px 1fr; gap: 16px; padding: 16px 0; border-bottom: 1px solid var(--border); align-items: start; }
.setting > label, .setting > .title { font-weight: 500; padding-top: 6px; }
.setting input[type=text], .setting input[type=password], .setting input[type=email], .setting select { padding: 8px 10px; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); width: 100%; max-width: 360px; }
.setting .editor { border: 1px solid var(--border); border-radius: 4px; min-height: 100px; padding: 8px 10px; outline: none; background: var(--surface); }
.setting .help { color: var(--text-3); font-size: 12px; margin-top: 4px; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { color: var(--text-3); font-weight: 500; font-size: 12px; }
.settings .save-row { padding: 20px 0; display: flex; gap: 12px; align-items: center; }
.color-swatches { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.color-swatches button { width: 24px; height: 24px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.color-swatches button.on { border-color: var(--text); }

/* ------------------------------------------------------------------ login */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: var(--surface); border-radius: 28px; padding: 40px; width: min(440px, calc(100vw - 32px)); display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); }
.login-card h1 { margin: 8px 0 0; font-weight: 400; font-size: 32px; }
.login-card .muted { margin: 0 0 12px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 12px; color: var(--text-3); }
.field input { height: 48px; border: 1px solid var(--text-3); border-radius: 4px; padding: 0 14px; font-size: 16px; background: var(--surface); }
.field input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.check { display: flex; gap: 8px; align-items: center; color: var(--text-2); }
.error { color: var(--danger); min-height: 1.2em; margin: 0; }
.login-card .primary-btn { align-self: flex-end; }

/* ------------------------------------------------------------------ small screens & print */
@media (max-width: 900px) {
  .app { --sidebar: 72px; }
  .brand span, .compose-btn .label, .nav .name, .nav .count, .nav-section span { display: none; }
  .brand { width: auto; }
  .row .who { width: 120px; }
  .conv-head, .banner { padding-left: 16px; margin-left: 16px; }
  .msg-body, .attachments, .delivery, .msg .details { margin-left: 0; }
  .reply-bar, .inline-compose { margin-left: 16px; padding-left: 0; }
  .compose:not(.inline) { width: 100vw; height: 100vh; border-radius: 0; }
  .compose-dock { right: 0; }
  .setting { grid-template-columns: 1fr; }
}
@media print {
  .topbar, .sidebar, .toolbar, .reply-bar, .compose-dock, .toasts { display: none !important; }
  .app { display: block; height: auto; }
  .main { margin: 0; border-radius: 0; }
  .content { overflow: visible; }
}
