/* All visual constants are driven by CSS variables, which are populated
   at runtime from config/settings.json -> theme. Edit settings.json to
   re-skin the entire UI without touching CSS. */
:root {
  --primary: #0078d4;
  --primary-dark: #106ebe;
  --background: #faf9f8;
  --panel: #ffffff;
  --border: #edebe9;
  --text-primary: #201f1e;
  --text-secondary: #605e5c;
  --unread: #0078d4;
  --hover: #f3f2f1;
  --selected: #deecf9;
  --shadow: 0 1.6px 3.6px rgba(0,0,0,.132), 0 .3px .9px rgba(0,0,0,.108);
  --topbar-h: 48px;
  --ui-scale: 1;
  --mail-font-size: 14px;
  --font: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: var(--font); color: var(--text-primary); background: var(--background); font-size: calc(14px * var(--ui-scale)); }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

.app-shell { display: flex; flex-direction: column; height: 100vh; }

/* ===== Topbar ===== */
.topbar {
  height: var(--topbar-h); flex: 0 0 var(--topbar-h);
  background: var(--primary); color: #fff;
  display: flex; align-items: center; padding: 0 12px; gap: 12px;
}
.topbar .waffle, .topbar .gear, .topbar .bell { width: 42px; height: 42px; border: 0; background: transparent; color: #fff; border-radius: 4px; display: inline-flex; align-items: center; justify-content: center; font-size: 22px; cursor: pointer; }
.topbar .waffle:hover, .topbar .gear:hover, .topbar .bell:hover { background: rgba(255,255,255,.12); }
.topbar .brand { font-weight: 600; font-size: 15px; letter-spacing: .2px; min-width: 70px; }
.topbar .search { flex: 1; max-width: 720px; height: 32px; border-radius: 4px; border: 0; padding: 0 12px 0 32px;
  background: rgba(255,255,255,.92) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23605e5c' stroke-width='2'><circle cx='11' cy='11' r='7'/><path d='m21 21-4.3-4.3'/></svg>") no-repeat 10px center;
  color: var(--text-primary); font-size: 13px; }
.topbar .search:focus { outline: 2px solid #fff8; }
.topbar .spacer { flex: 1; }
.topbar .avatar {
  width: 32px; height: 32px; border-radius: 50%; background: #c7e0f4; color: var(--primary-dark);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 13px;
  border: 2px solid #fff;
}

/* ===== Workspace + Splits ===== */
.workspace { flex: 1; display: flex; min-height: 0; background: var(--background); }
.gutter { background: var(--background); background-repeat: no-repeat; background-position: 50%; }
.gutter.gutter-horizontal { cursor: col-resize; width: 6px; }
.gutter.gutter-horizontal:hover { background: var(--border); }

.pane { background: var(--panel); overflow: hidden; display: flex; flex-direction: column; min-width: 0; }

/* ===== Sidebar ===== */
.sidebar { padding: 8px 4px; gap: 2px; }
.sidebar .new-mail {
  margin: 12px 12px 16px;
  height: 52px;
  border: none;
  border-radius: 16px;
  background: #c2e7ff;
  color: #001d35;
  font-weight: 600;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 0 22px;
  align-self: flex-start;
  box-shadow: 0 1px 3px rgba(0,0,0,.15), 0 1px 2px rgba(0,0,0,.1);
  transition: box-shadow .15s, background .15s;
}
.sidebar .new-mail:hover { background: #a8d8f5; box-shadow: 0 2px 6px rgba(0,0,0,.2); }
.sidebar .new-mail .icon { width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.sidebar .new-mail .icon svg { width: 22px; height: 22px; }
.sidebar .folder {
  display: flex; align-items: center; gap: 10px; padding: 5px 12px; margin: 0 4px;
  border-radius: 20px; font-size: 14px; cursor: pointer; user-select: none; color: var(--text-primary);
}
.sidebar .folder:hover { background: var(--hover); }
.sidebar .folder.active { background: var(--selected); font-weight: 600; }
.sidebar .folder .icon { width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; color: var(--text-secondary); flex-shrink: 0; }
.sidebar .folder .icon svg { width: 20px; height: 20px; }
.sidebar .folder.active .icon { color: var(--primary-dark); }
.sidebar .folder .count { margin-left: auto; color: var(--text-secondary); font-size: 12px; font-weight: 400; }

/* ===== Email list ===== */
.list { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
.list .list-header { padding: 12px 16px 8px; display: flex; align-items: baseline; justify-content: space-between; border-bottom: 1px solid var(--border); }
.list .list-header h2 { margin: 0; font-size: 16px; font-weight: 600; }
.list .list-header .filter { font-size: 12px; color: var(--text-secondary); }
.list .items { overflow-y: auto; flex: 1; }
.list .item {
  padding: 10px 14px 10px 18px; border-bottom: 1px solid var(--border); cursor: pointer; position: relative;
  display: grid; grid-template-columns: 1fr auto; gap: 2px 8px;
}
.list .item:hover { background: var(--hover); }
.list .item.active { background: var(--selected); }
.list .item.unread::before { content: ""; position: absolute; left: 6px; top: 14px; width: 6px; height: 6px; border-radius: 50%; background: var(--unread); }
.list .item .sender { font-weight: 600; font-size: 14px; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .item .date { font-size: 12px; color: var(--text-secondary); white-space: nowrap; }
.list .item .subject { grid-column: 1 / -1; font-size: 13px; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .item.unread .subject { color: var(--unread); font-weight: 600; }
.list .item .preview { grid-column: 1 / -1; font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .item .mail-labels-row { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.mail-label { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11px; font-weight: 600;
  color: #fff; background: var(--label-color, #888); white-space: nowrap; }

/* ===== Reader ===== */
.reader { border-left: 1px solid var(--border); }
.reader .reader-toolbar { height: 40px; display: flex; align-items: center; gap: 4px; padding: 0 12px; border-bottom: 1px solid var(--border); }
.reader .reader-toolbar button { height: 28px; padding: 0 10px; border: 0; background: transparent; border-radius: 4px; font-size: 13px; color: var(--text-primary); }
.reader .reader-toolbar button:hover { background: var(--hover); }
.reader .reader-toolbar .label-toolbar-btn { border: 1px solid var(--border); }

/* Label picker menu */
.label-menu { position: fixed; z-index: 9999; background: var(--panel); border: 1px solid var(--border);
  border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,.18); padding: 4px 0; min-width: 150px; }
.label-menu-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 14px;
  background: none; border: none; cursor: pointer; font-size: 13px; color: var(--text-primary); text-align: left; }
.label-menu-item:hover { background: var(--hover); }
.label-menu-item.checked { font-weight: 700; }
.label-menu-item.checked::after { content: '✓'; margin-left: auto; color: var(--text-secondary); font-size: 12px; }
.label-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.reader .scroll {
  overflow-y: auto; flex: 1; padding: 24px 32px 80px; max-width: 100%;
}
.reader .empty { color: var(--text-secondary); font-size: 14px; padding: 40px; text-align: center; }
.reader .email-subject { font-size: 22px; font-weight: 600; margin: 0 0 12px; }
.reader .email-meta { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.reader .email-meta .pic { width: 40px; height: 40px; border-radius: 50%; background: #c7e0f4; color: var(--primary-dark); display: inline-flex; align-items: center; justify-content: center; font-weight: 600; }
.reader .email-meta .meta-text { flex: 1; font-size: 13px; }
.reader .email-meta .from { font-weight: 600; }
.reader .email-meta .to { color: var(--text-secondary); }
.reader .email-meta .date { color: var(--text-secondary); font-size: 12px; }
.reader .email-body { font-size: var(--mail-font-size); line-height: 1.55; color: var(--text-primary); }
.reader .email-body p { margin: 0 0 14px; }
.reader .email-body .signature { color: var(--text-secondary); font-size: 13px; margin-top: 20px; white-space: pre-wrap; }

.inline-novel {
  margin: 18px 0;
  padding: 0;
  color: var(--text-primary);
}
.inline-novel-text {
  white-space: pre-wrap;
  line-height: 1.72;
  /* height + overflow are set inline by mountInlineNovel based on linesPerPage */
}
.inline-novel-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 12px;
}
.inline-novel-btn {
  width: 28px;
  height: 26px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 2px;
  font-size: 18px;
  line-height: 1;
}
.inline-novel-btn:hover { background: var(--hover); }
.inline-novel-btn:disabled { opacity: .45; cursor: default; }
.inline-novel-status { min-width: 88px; text-align: center; }
.inline-novel-panic { color: var(--text-primary); }

/* Novel date navigation — the disguised page indicator in the email header */
.novel-date-nav { cursor: pointer; user-select: none; position: relative; display: inline-flex; align-items: baseline; gap: 0; }
.novel-date-nav:hover { text-decoration: underline dotted; text-underline-offset: 2px; }

/* Jump panel that drops down from the date */
.novel-jump-panel {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 200;
  background: #fff; border: 1px solid var(--border);
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
  border-radius: 3px; padding: 8px 10px;
  display: flex; flex-direction: column; gap: 6px;
  min-width: 220px; font-size: 12px; font-weight: normal;
  color: var(--text-primary); cursor: default;
}
.novel-jump-panel.hidden { display: none; }
.novel-jump-chapter {
  width: 100%; font-size: 12px; padding: 3px 4px;
  border: 1px solid var(--border); border-radius: 2px;
  background: #fff; color: var(--text-primary);
}
.novel-jump-row { display: flex; align-items: center; gap: 5px; }
.novel-jump-input {
  width: 52px; font-size: 12px; padding: 2px 5px;
  border: 1px solid var(--border); border-radius: 2px; text-align: center;
}
.novel-jump-total { color: var(--text-secondary); }
.novel-jump-go {
  padding: 2px 10px; font-size: 12px; border: 1px solid var(--border);
  background: #f3f3f3; border-radius: 2px; cursor: pointer;
}
.novel-jump-go:hover { background: var(--hover); }

/* Bookmark list inside jump panel */
.novel-jump-section-label {
  font-size: 10px; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: var(--text-secondary);
  margin: 6px 0 3px;
}
.novel-jump-section-label:first-child { margin-top: 0; }
.novel-bm-list { display: flex; flex-direction: column; gap: 2px; margin-bottom: 4px; max-height: 140px; overflow-y: auto; }
.novel-bm-empty { color: var(--text-secondary); font-style: italic; font-size: 11px; padding: 2px 0; }
.novel-bm-row { display: flex; align-items: center; gap: 4px; }
.novel-bm-row.current .novel-bm-goto { font-weight: 600; color: var(--primary); }
.novel-bm-goto {
  flex: 1; text-align: left; background: none; border: none; cursor: pointer;
  font-size: 12px; padding: 2px 4px; border-radius: 2px; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.novel-bm-goto:hover { background: var(--hover); }
.novel-bm-del {
  flex-shrink: 0; background: none; border: none; cursor: pointer;
  font-size: 10px; color: var(--text-secondary); padding: 2px 4px; border-radius: 2px;
}
.novel-bm-del:hover { background: var(--hover); color: #c00; }
.novel-bm-label-input {
  flex: 1; font-size: 12px; padding: 2px 5px;
  border: 1px solid var(--border); border-radius: 2px; min-width: 0;
}

.attachments { margin-top: 28px; border-top: 1px solid var(--border); padding-top: 16px; }
/* Attachment section header row: title left, controls right */
.attachments-hdr { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.attachments-hdr h4 { margin: 0; font-size: 13px; color: var(--text-secondary); font-weight: 600; }
.att-filter-row { display: flex; align-items: center; gap: 6px; }
/* Small dropdown trigger button */
.att-filter-btn {
  height: 24px; padding: 0 8px; border: 1px solid var(--border);
  background: #fff; border-radius: 2px; font-size: 11px;
  color: var(--text-secondary); cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px;
}
.att-filter-btn:hover { background: var(--hover); color: var(--text-primary); }
/* Dropdown menu (appended to body, positioned absolutely) */
.att-filter-menu {
  position: fixed; z-index: 1300;
  background: #fff; border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0,0,0,.18); border-radius: 4px;
  min-width: 196px; padding: 4px 0;
}
.att-filter-menu .afm-section {
  font-size: 10px; font-weight: 700; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: .06em; padding: 8px 12px 4px;
}
.att-filter-menu .afm-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; font-size: 12px; cursor: pointer; color: var(--text-primary);
}
.att-filter-menu .afm-item:hover { background: var(--hover); }
.att-filter-menu .afm-item.active { color: var(--primary); font-weight: 600; }
.att-filter-menu .afm-item .afm-check { width: 14px; font-size: 10px; text-align: center; flex-shrink: 0; }
/* ===== Sponsored / ad attachment shells ===== */
.att-ad-wrap { margin-top: 12px; }
.att-ad-badge {
  font-size: 10px; color: var(--text-secondary); margin-bottom: 4px;
  display: flex; align-items: center; gap: 6px; padding-left: 2px;
}
.att-ad-badge::before {
  content: 'Sponsored'; display: inline-block;
  border: 1px solid var(--border); border-radius: 2px;
  padding: 0 4px; line-height: 1.6; font-size: 9px;
  text-transform: uppercase; letter-spacing: .05em;
}
.att-ad-body {
  padding: 14px 16px; display: flex; align-items: center;
  gap: 14px; cursor: default; min-height: 72px;
}
.att-ad-icon {
  width: 36px; height: 36px; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
}
.att-ad-copy { flex: 1; min-width: 0; }
.att-ad-copy .ad-headline { font-size: 13px; font-weight: 600; color: var(--text-primary); margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-ad-copy .ad-body { font-size: 12px; color: var(--text-secondary); line-height: 1.4; }
.att-ad-cta {
  height: 28px; padding: 0 12px; border: 1px solid var(--primary);
  background: transparent; color: var(--primary); border-radius: 2px;
  font-size: 12px; font-weight: 600; cursor: pointer; flex-shrink: 0;
  white-space: nowrap;
}
.att-ad-cta:hover { background: var(--selected); }
.attachment-shell {
  border: 1px solid var(--border); border-radius: 4px; background: var(--panel);
  overflow: hidden; box-shadow: var(--shadow);
  position: relative; /* needed so att-resize can be absolute relative to this shell */
}
.attachment-shell .att-header { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); background: #fafafa; font-size: 13px; }
.attachment-shell .att-header .icon { width: 22px; height: 22px; background: var(--primary); color: #fff; display: inline-flex; align-items: center; justify-content: center; border-radius: 3px; font-size: 11px; font-weight: 700; }
.attachment-shell .att-body {
  background: #fff;
  min-height: 32px;
  position: relative;
  height: 480px;
  overflow: hidden;
}
.attachment-shell .app-host {
  width: 100%; height: 100%; min-height: 0; display: block;
}
.attachment-shell iframe.app-host { border: 0; }
/* Bottom-right corner resize grip — sits OUTSIDE att-body so it is never
   clipped by att-body's overflow:hidden and remains reachable at any frame size. */
.attachment-shell .att-resize {
  position: absolute; bottom: 0; right: 0;
  width: 18px; height: 18px;
  cursor: nwse-resize; z-index: 10;
  /* Three stair-step lines — standard SE resize icon in pure CSS */
  background-image:
    linear-gradient(135deg,
      transparent 0 40%, var(--border) 40% 55%, transparent 55% 100%),
    linear-gradient(135deg,
      transparent 0 55%, var(--border) 55% 70%, transparent 70% 100%),
    linear-gradient(135deg,
      transparent 0 70%, var(--border) 70% 85%, transparent 85% 100%);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  border-radius: 0 0 3px 0;
  opacity: .55;
  transition: opacity .15s;
}
.attachment-shell .att-resize:hover { opacity: 1; background-color: rgba(0,0,0,.04); }

/* ===== Attachment start / splash screen ===== */
.att-splash {
  width: 100%; height: 100%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px;
  background: #fafafa; padding: 24px; text-align: center;
}
.att-splash-icon { font-size: 38px; line-height: 1; }
.att-splash-label {
  font-size: 13px; font-weight: 700; color: var(--text-primary);
  max-width: 80%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.att-splash-type { font-size: 12px; color: var(--text-secondary); }
.att-splash-hint { font-size: 11px; color: var(--text-secondary); max-width: 70%; line-height: 1.4; }
.att-splash .btn { min-width: 130px; margin-top: 6px; }

/* ===== Generic stealth-game styling (used by built-in games) ===== */
.sa-host { width: 100%; height: 100%; display: flex; flex-direction: column; background: #fff; }
.sa-host .sa-body { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 12px; gap: 10px; overflow: auto; }
.sa-host .sa-stage { display: flex; justify-content: center; align-items: flex-start; }
.sa-host .sa-side  { display: flex; flex-direction: column; gap: 8px; min-width: 140px; }
.sa-host .sa-row   { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.sa-host .sa-card  { border: 1px solid var(--border); border-radius: 4px; background: #fafafa; padding: 8px 12px; font-size: 13px; min-width: 120px; }
.sa-host .sa-card h5 { margin: 0 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-secondary); font-weight: 700; }
.sa-host .sa-kv    { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.sa-host .sa-btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.sa-host .sa-btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.sa-host .sa-tab-row { display: flex; gap: 4px; padding: 6px 10px; border-bottom: 1px solid var(--border); background: #fafafa; }
.sa-host .sa-tab { background: transparent; border: 0; padding: 4px 10px; border-radius: 3px; font-size: 12px; color: var(--text-secondary); cursor: pointer; }
.sa-host .sa-tab.active { background: var(--selected); color: var(--primary-dark); font-weight: 600; }
.sa-host .sa-leaderboard { font-size: 12px; max-height: 200px; overflow: auto; }
.sa-host .sa-leaderboard table { width: 100%; border-collapse: collapse; }
.sa-host .sa-leaderboard th, .sa-host .sa-leaderboard td { padding: 4px 6px; text-align: left; border-bottom: 1px solid var(--border); }
.sa-host .sa-leaderboard th { color: var(--text-secondary); font-weight: 600; font-size: 11px; text-transform: uppercase; }
.sa-host canvas { background: #fff; display: block; }
.sa-host .sa-banner { padding: 8px 12px; background: var(--selected); color: var(--primary-dark); font-size: 13px; border-radius: 3px; }

/* ===== Fake loader ===== */
.fake-loader {
  position: fixed; inset: 0; background: rgba(255,255,255,.86); z-index: 1000;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  color: var(--text-primary); font-size: 14px;
}
.fake-loader .spinner { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Boss overlay (panic mode) ===== */
.boss-overlay {
  position: fixed; bottom: 12px; right: 16px; z-index: 1500;
  background: #323130; color: #fff; font-size: 12px;
  padding: 8px 12px; border-radius: 4px; box-shadow: var(--shadow);
}

/* Builtin app helpers */
.sa-host { font-family: var(--font); color: var(--text-primary); }
.sa-host .sa-toolbar { display: flex; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); background: #fafafa; font-size: 12px; }
.sa-host .sa-toolbar button { height: 26px; padding: 0 10px; border: 1px solid var(--border); background: #fff; border-radius: 2px; }

/* ===== Sidebar sections ===== */
.sidebar .side-section {
  margin: 14px 12px 4px; font-size: 11px; font-weight: 600;
  color: var(--text-secondary); text-transform: uppercase; letter-spacing: .5px;
}

/* ===== Avatar menu ===== */
.menu {
  position: fixed; z-index: 1200;
  background: #fff; border: 1px solid var(--border); box-shadow: 0 8px 24px rgba(0,0,0,.18);
  border-radius: 4px; min-width: 260px; padding: 6px 0;
}
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
.menu .menu-head { display: flex; gap: 12px; padding: 12px; align-items: center; }
.menu .avatar-lg {
  width: 40px; height: 40px; border-radius: 50%; background: #c7e0f4; color: var(--primary-dark);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 600;
}
.menu .menu-name { font-weight: 600; font-size: 14px; }
.menu .menu-sub  { font-size: 12px; color: var(--text-secondary); }
.menu .menu-item {
  display: block; width: 100%; text-align: left;
  padding: 8px 14px; background: transparent; border: 0; font-size: 13px; color: var(--text-primary); cursor: pointer;
}
.menu .menu-item:hover { background: var(--hover); }

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.42); z-index: 2000;
  display: flex; align-items: center; justify-content: center;
}
.modal-card {
  background: #fff; border-radius: 6px; box-shadow: 0 12px 32px rgba(0,0,0,.28);
  display: flex; flex-direction: column; max-height: 86vh; max-width: 92vw;
}
.modal-header { display: flex; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 16px; font-weight: 600; flex: 1; }
.modal-close { background: transparent; border: 0; font-size: 20px; cursor: pointer; color: var(--text-secondary); }
.modal-close:hover { color: var(--text-primary); }
.modal-body { padding: 16px; overflow: auto; }
.modal-footer { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

/* form controls */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; flex: 1; }
.field > span { font-size: 12px; color: var(--text-secondary); font-weight: 600; }
.control {
  height: 32px; padding: 0 10px; border: 1px solid var(--border); border-radius: 2px;
  font-size: 13px; font-family: inherit; color: var(--text-primary); background: #fff;
}
textarea.control { height: auto; padding: 8px 10px; resize: vertical; min-height: 100px; }
.control:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.btn {
  height: 32px; padding: 0 16px; border: 1px solid var(--border);
  background: #fff; color: var(--text-primary); border-radius: 2px; cursor: pointer; font-size: 13px;
}
.btn:hover { background: var(--hover); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn[disabled] { opacity: .55; cursor: default; }

.notice { padding: 8px 12px; border-radius: 3px; font-size: 12px; margin: 8px 0; }
.notice-info  { background: #eff6fc; color: var(--primary-dark); border: 1px solid #c7e0f4; }
.notice-warn  { background: #fff4ce; color: #8a6a00; border: 1px solid #f1c40f; }
.notice-error { background: #fde7e9; color: #a4262c; border: 1px solid #f1bbb6; }

/* auth tabs / compose tabs */
.auth-tabs, .compose-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.auth-tabs .tab, .compose-tabs .tab {
  background: transparent; border: 0; padding: 8px 14px; font-size: 13px; cursor: pointer;
  border-bottom: 2px solid transparent; color: var(--text-secondary);
}
.auth-tabs .tab.active, .compose-tabs .tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* Subject field with inline camouflage toggle */
.field-label-row { display: flex; align-items: center; justify-content: space-between; }
.camo-toggle { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--text-secondary); font-weight: 600; cursor: pointer; user-select: none; }
.camo-toggle input[type="checkbox"] { cursor: pointer; accent-color: var(--primary); margin: 0; }

/* OAuth row */
.oauth-row { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.oauth-btn { width: 100%; height: 36px; font-weight: 600; border-radius: 2px; }
.oauth-btn:hover { filter: brightness(.92); }
.auth-divider {
  text-align: center; font-size: 11px; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: .08em; margin: 0 0 12px;
  position: relative;
}
.auth-divider::before, .auth-divider::after {
  content: ''; position: absolute; top: 50%; width: 40%; height: 1px; background: var(--border);
}
.auth-divider::before { left: 0; }
.auth-divider::after  { right: 0; }

/* Settings modal */
.settings-section {
  font-size: 11px; font-weight: 700; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: .08em; margin: 12px 0 8px;
}
.theme-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; }
.theme-grid .field { margin-bottom: 4px; }
.color-control { padding: 0; height: 32px; width: 100%; cursor: pointer; }

/* Mailbox manager */
.mailbox-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.mailbox-row { display: flex; align-items: center; gap: 8px; padding: 4px 6px;
  background: var(--background); border: 1px solid var(--border); border-radius: 4px; font-size: 13px; }
.mailbox-row .icon { width: 18px; height: 18px; display: flex; align-items: center; color: var(--text-secondary); }
.mailbox-row .icon svg { width: 18px; height: 18px; }
.mailbox-add-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.mailbox-add-row .field-label-small { font-size: 11px; color: var(--text-secondary); white-space: nowrap; }
.icon-btn { background: none; border: none; cursor: pointer; color: var(--text-secondary);
  font-size: 12px; padding: 2px 6px; border-radius: 3px; }
.icon-btn:hover { background: var(--hover); color: var(--text-primary); }

/* Icon picker */
.icon-picker-wrap { position: static; }
.icon-picker-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: 4px;
  background: var(--panel); cursor: pointer;
}
.icon-picker-btn:hover { background: var(--hover); }
.icon-picker-btn .icon { width: 18px; height: 18px; display: flex; align-items: center; }
.icon-picker-btn .icon svg { width: 18px; height: 18px; }
.icon-picker-drop {
  position: fixed; z-index: 9999;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.18);
  display: none;
  grid-template-columns: repeat(4, 36px); gap: 4px;
}
.icon-picker-drop.open { display: grid; }
.icon-option {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid transparent; border-radius: 6px;
  background: transparent; cursor: pointer;
  color: var(--text-primary);
}
.icon-option svg { width: 20px; height: 20px; }
.icon-option:hover { background: var(--hover); border-color: var(--border); }
.icon-option.selected { background: var(--selected); border-color: var(--primary); }

/* Add mailbox sidebar button */
.add-mailbox-btn { display: flex; align-items: center; gap: 8px; width: 100%;
  background: none; border: none; cursor: pointer; padding: 5px 12px 5px 16px;
  color: var(--text-secondary); font-size: 12px; text-align: left;
  border-top: 1px solid var(--border); margin-top: 4px; }
.add-mailbox-btn:hover { background: var(--hover); color: var(--text-primary); }

.compose .row { display: flex; gap: 12px; }
.compose .row .field { flex: 1; }

/* ===== Monochrome filter overlays applied to embedded apps ===== */
.app-host.mono-grayscale { filter: grayscale(100%) contrast(.95); }
.app-host.mono-sepia     { filter: sepia(85%) contrast(.95); }
.app-host.mono-blue      { filter: grayscale(100%) sepia(40%) hue-rotate(180deg) saturate(2.2) brightness(.95); }
.app-host.mono-green     { filter: grayscale(100%) sepia(60%) hue-rotate(60deg) saturate(2) brightness(.9); }

/* ===== Misc ===== */
.empty { padding: 32px; text-align: center; color: var(--text-secondary); font-size: 13px; }
.list .items > .empty { background: transparent; }

/* ===== Acknowledge button ===== */
.reader .reader-toolbar .ack-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); padding: 0 10px; height: 28px;
  border-radius: 14px; background: transparent;
}
.reader .reader-toolbar .ack-btn:hover { background: var(--hover); }
.reader .reader-toolbar .ack-btn.acked {
  background: #e6f4ea; border-color: #34a853; color: #1e7e34;
}
.reader .reader-toolbar .ack-btn .ack-icon { display: inline-flex; }

/* ===== Comments thread ===== */
.comments-thread {
  margin: 24px 0 8px; padding: 16px; border-top: 1px solid var(--border);
  background: var(--surface, #fafafa);
}
.comments-heading { margin: 0 0 8px; font-size: 14px; color: var(--text-primary); }
.comments-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.comments-empty { color: var(--text-secondary); font-size: 13px; padding: 8px 0; }
.comment-item {
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px;
}
.comment-meta {
  display: flex; gap: 8px; align-items: baseline;
  font-size: 12px; color: var(--text-secondary); margin-bottom: 4px;
}
.comment-name { font-weight: 600; color: var(--text-primary); }
.comment-text { font-size: 13px; color: var(--text-primary); white-space: pre-wrap; }
.comments-form { display: flex; gap: 8px; align-items: flex-start; }
.comments-input {
  flex: 1; min-height: 44px; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 8px; font: inherit; resize: vertical;
}
.comments-send {
  padding: 8px 14px; border: 0; border-radius: 8px;
  background: var(--primary, #0078d4); color: #fff; cursor: pointer;
}
.comments-send:disabled { opacity: .6; cursor: default; }
.comments-hint { color: var(--text-secondary); font-size: 13px; }

/* ===== Toast ===== */
.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%) translateY(20px);
  background: #323232; color: #fff; padding: 10px 16px; border-radius: 6px;
  font-size: 13px; opacity: 0; transition: opacity .2s, transform .2s;
  z-index: 10000; box-shadow: 0 4px 12px rgba(0,0,0,.2);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== Disclaimer ===== */
.disclaimer-body { max-height: 60vh; overflow: auto; }
.disclaimer-text {
  white-space: pre-wrap; font: inherit; color: var(--text-primary);
  background: #fffbe6; border: 1px solid #ffe58f; border-radius: 8px;
  padding: 12px; margin: 0;
}

/* ===== Tutorial / spotlight overlay ===== */
.tut-overlay {
  position: fixed; inset: 0; z-index: 10000; pointer-events: none;
  background: rgba(0, 0, 0, 0.55);
}
.tut-cutout {
  position: absolute; box-shadow: 0 0 0 9999px rgba(0,0,0,.55);
  border-radius: 10px; outline: 2px solid #fff; pointer-events: none;
  background: transparent; transition: top .2s, left .2s, width .2s, height .2s;
}
.tut-card {
  position: absolute; pointer-events: auto;
  box-sizing: border-box;
  background: #fff; color: var(--text-primary);
  border-radius: 10px; padding: 16px; box-shadow: 0 12px 32px rgba(0,0,0,.3);
  font-size: 14px;
}
.tut-step  { font-size: 11px; color: var(--text-secondary); margin-bottom: 4px; }
.tut-title { margin: 0 0 6px; font-size: 15px; }
.tut-body  { margin: 0 0 12px; line-height: 1.4; }
.tut-actions { display: flex; gap: 8px; justify-content: flex-end; }
.tut-actions button {
  padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; cursor: pointer; font-size: 13px;
}
.tut-actions .tut-skip { margin-right: auto; color: var(--text-secondary); }
.tut-actions .tut-next {
  background: var(--primary, #0078d4); color: #fff; border-color: var(--primary, #0078d4);
}
.tut-actions button:disabled { opacity: .5; cursor: default; }

/* ================================================================== */
/* Ad placements (1)–(5). Slot badges are toggled in JS via             */
/* settings.ads.showSlotLabel — they exist so the dev/owner can verify */
/* placements during testing.                                          */
/* ================================================================== */

.ad-slot-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  color: #8a4a00;
  background: #fff4ce;
  border: 1px solid #f2c94c;
  border-radius: 8px;
  vertical-align: middle;
  letter-spacing: .3px;
}

/* (1) Sponsored inbox row — looks identical to a real inbox item, with a
       small "Ad" pill in the labels row + the test "(1)" badge. */
.list .item.ad-item {
  background: #fffaf3;
}
.list .item.ad-item:hover { background: #fff3df; }
.list .item.ad-item .mail-label.ad-tag {
  --label-color: #8a4a00;
  background: #fff4ce;
  border-color: #f2c94c;
  color: #8a4a00;
}

/* (2) Suggested attachment under the subject line — narrow horizontal
       card, sits between the subject and the email-meta header. */
.ad-undersubject {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  margin: 0 0 12px;
  background: #fffaf3;
  border: 1px solid #f2c94c;
  border-radius: 6px;
  font-size: 13px;
}
.ad-undersubject-icon {
  width: 28px; height: 28px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: #fff4ce; border-radius: 4px; font-size: 16px;
}
.ad-undersubject-copy { flex: 1; min-width: 0; }
.ad-undersubject-headline { font-weight: 600; color: var(--text-primary); }
.ad-undersubject-body { color: var(--text-secondary); font-size: 12px; margin-top: 2px; }

/* (3) Topbar promoted-app tile — small pill in the topbar between
       spacer and gear, mirrors the look of an Office app tile. */
.ad-topbar-tile {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px;
  margin-right: 6px;
  background: rgba(255,255,255,.14);
  color: #fff;
  border: 0;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.ad-topbar-tile:hover { background: rgba(255,255,255,.22); }
.ad-topbar-icon { font-size: 14px; }
.ad-topbar-tile .ad-slot-badge {
  /* invert badge for dark topbar */
  color: #fff; background: rgba(0,0,0,.25); border-color: rgba(255,255,255,.3);
}

/* (4) Sticky strip pinned at the bottom of the reader pane.
       Always in viewport → highest viewability. Dismissible. */
.ad-sticky-strip {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: #fffaf3;
  border-top: 1px solid #f2c94c;
  font-size: 13px;
}
.ad-sticky-icon { font-size: 16px; }
.ad-sticky-text { flex: 1; color: var(--text-primary); }
.ad-sticky-cta {
  height: 28px; padding: 0 12px; font-size: 12px; font-weight: 600;
  border: 1px solid var(--primary); background: var(--primary); color: #fff;
  border-radius: 4px; cursor: pointer;
}
.ad-sticky-cta:hover { background: var(--primary-dark); }
.ad-sticky-close {
  width: 24px; height: 24px; padding: 0; font-size: 18px; line-height: 1;
  background: transparent; border: 0; color: var(--text-secondary); cursor: pointer;
  border-radius: 4px;
}
.ad-sticky-close:hover { background: rgba(0,0,0,.06); }

/* (5) Below-attachment banner — already styled by .att-ad-wrap; only the
       slot badge is added inline by JS so no extra rules needed. */

