:root {
  --bg: #f6f8fc;
  --surface: #ffffff;
  --border: #e4e7ec;
  --row-border: #f1f3f4;
  --text: #202124;
  --muted: #5f6368;
  --accent: #1a73e8;
  --accent-soft: #e8f0fe;
  --accent-contrast: #ffffff;
  --unread: #ffffff;
  --hover: #f1f3f4;
  --star: #f4b400;
  --danger: #d93025;
  --radius: 12px;
  font-family: "Roboto", system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181c;
    --surface: #1e2024;
    --border: #2b2e33;
    --row-border: #26292e;
    --text: #e3e3e3;
    --muted: #9aa0a6;
    --accent: #8ab4f8;
    --accent-soft: #283142;
    --accent-contrast: #0b1016;
    --unread: #24272c;
    --hover: #282b30;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 0.9rem; cursor: pointer;
}
.btn:hover { background: var(--hover); }
.btn-primary { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.btn-primary:hover { opacity: 0.92; background: var(--accent); }
.btn-block { width: 100%; justify-content: center; }
.btn[disabled] { opacity: 0.6; cursor: default; }
.gm-icon-btn {
  border: 0; background: transparent; color: var(--muted);
  cursor: pointer; padding: 8px 10px; border-radius: 8px; font-size: 0.95rem;
  display: inline-flex; align-items: center; gap: 6px;
}
.gm-icon-btn:hover { background: var(--hover); color: var(--text); }

/* ── App shell ─────────────────────────────────────────────────────── */
#app-shell { display: flex; flex-direction: column; height: 100vh; }

.gm-topbar {
  height: 60px; flex: none; display: flex; align-items: center; gap: 16px;
  padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.gm-menu { display: none; border: 0; background: none; color: var(--muted); font-size: 1.2rem; cursor: pointer; }
.gm-logo { font-size: 1.25rem; font-weight: 500; display: flex; align-items: center; gap: 10px; cursor: pointer; white-space: nowrap; }
.gm-logo-mark { color: var(--accent); }
.gm-search {
  flex: 1; max-width: 700px; display: flex; align-items: center; gap: 12px;
  background: var(--bg); border-radius: 10px; padding: 0 16px; height: 46px;
  border: 1px solid transparent;
}
.gm-search:focus-within { background: var(--surface); border-color: var(--border); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.gm-search-ico { color: var(--muted); }
.gm-search input { flex: 1; border: 0; background: transparent; outline: none; font-size: 0.95rem; color: var(--text); }
.gm-search-clear { border: 0; background: none; color: var(--muted); cursor: pointer; }
.gm-account { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.gm-account-email { color: var(--muted); font-size: 0.9rem; }

.gm-body { flex: 1; display: flex; min-height: 0; }

.gm-sidebar { width: 256px; flex: none; padding: 12px 8px; overflow-y: auto; }
.gm-compose {
  display: inline-flex; align-items: center; gap: 12px;
  padding: 14px 26px 14px 20px; margin: 4px 8px 14px;
  border: 0; border-radius: 16px; cursor: pointer;
  background: var(--accent-soft); color: var(--accent);
  font-size: 0.95rem; font-weight: 600;
  box-shadow: 0 1px 3px rgba(60,64,67,.15);
}
.gm-compose:hover { box-shadow: 0 2px 6px rgba(60,64,67,.25); }
.gm-folders { display: flex; flex-direction: column; }
.gm-folder {
  display: flex; align-items: center; gap: 18px;
  padding: 0 14px 0 20px; height: 38px;
  border-radius: 0 20px 20px 0; color: var(--text); font-size: 0.9rem;
}
.gm-folder:hover { background: var(--hover); text-decoration: none; }
.gm-folder.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.gm-fi { width: 18px; text-align: center; }

.gm-main { flex: 1; min-width: 0; overflow-y: auto; background: var(--surface);
  border-top-left-radius: 16px; border-left: 1px solid var(--border); }
.gm-list-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 18px 6px; }
.gm-list-title { margin: 0; font-size: 1.1rem; font-weight: 500; }

/* ── Message list (Gmail rows) ─────────────────────────────────────── */
.msg-list { list-style: none; margin: 0; padding: 0; }
.msg-row {
  display: flex; align-items: center; gap: 14px;
  padding: 0 18px; height: 46px; border-bottom: 1px solid var(--row-border);
  cursor: pointer;
}
.msg-row:hover { box-shadow: inset 1px 0 0 var(--border), inset -1px 0 0 var(--border), 0 1px 3px rgba(0,0,0,.08); z-index: 1; }
.msg-row.unread { background: var(--unread); }
.msg-row.unread .msg-from, .msg-row.unread .msg-subject { font-weight: 700; color: var(--text); }
.msg-star { width: 22px; flex: none; color: var(--muted); opacity: .55; cursor: pointer; text-align: center; }
.msg-star:hover { opacity: 1; }
.msg-star.on { color: var(--star); opacity: 1; }
.msg-from { width: 200px; min-width: 110px; flex: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.msg-subject { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.msg-date { color: var(--muted); font-size: 0.78rem; white-space: nowrap; flex: none; }

/* ── Message & compose panes ───────────────────────────────────────── */
.gm-msg-toolbar { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--row-border); }
.gm-compose-title { font-weight: 500; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin: 16px; }
.meta { color: var(--muted); font-size: 0.88rem; margin: 2px 0; }
.meta strong { color: var(--text); }
.msg-body { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.msg-body iframe { width: 100%; min-height: 55vh; border: 0; background: #fff; border-radius: 6px; }
pre.plain { white-space: pre-wrap; word-break: break-word; font-family: inherit; margin: 0; }
.status { color: var(--muted); padding: 8px 18px; }
.empty { color: var(--muted); text-align: center; padding: 48px 16px; }
.error { color: var(--danger); font-size: 0.9rem; margin: 8px 0; }

/* ── Gmail-style compose ───────────────────────────────────────────── */
.compose { padding: 0; overflow: hidden; }
.compose-row { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--row-border); }
.compose-prefix { color: var(--muted); font-size: 0.9rem; width: 54px; flex: none; }
.compose-input { flex: 1; border: 0; background: transparent; color: var(--text); font-size: 0.95rem; font-family: inherit; outline: none; padding: 2px 0; }

.rte-toolbar { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; padding: 6px 12px; border-bottom: 1px solid var(--row-border); background: var(--bg); }
.rte-btn { min-width: 32px; height: 32px; padding: 0 8px; border: 1px solid transparent; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; font-size: 0.9rem; }
.rte-btn:hover { background: var(--surface); color: var(--text); border-color: var(--border); }
.rte-btn.active { background: var(--accent-soft); color: var(--accent); }
.rte-sep { width: 1px; height: 20px; background: var(--border); margin: 0 6px; }

.rte-editor { min-height: 260px; padding: 16px; outline: none; font-size: 0.95rem; line-height: 1.6; color: var(--text); overflow-wrap: break-word; }
.rte-editor:empty::before { content: attr(data-placeholder); color: var(--muted); pointer-events: none; }
.rte-editor a { color: var(--accent); }

.attach-dropzone { margin: 0 16px 12px; padding: 16px; text-align: center; border: 1.5px dashed var(--border); border-radius: 8px; color: var(--muted); font-size: 0.88rem; transition: border-color .15s, background .15s; }
.attach-dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.link-btn { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }
.link-btn:hover { text-decoration: underline; }
.attach-list { list-style: none; margin: 0 16px 8px; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.attach-chip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 20px; background: var(--bg); font-size: 0.82rem; }
.attach-chip .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.attach-chip .size { color: var(--muted); }
.attach-chip .rm { border: 0; background: none; color: var(--muted); cursor: pointer; line-height: 1; padding: 0; }
.attach-chip .rm:hover { color: var(--danger); }
.compose-footer { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--row-border); }
.compose-footer .spacer { flex: 1; }
.btn-icon { padding: 8px 10px; }
.attach-size { color: var(--muted); font-size: 0.82rem; }

/* ── Login ─────────────────────────────────────────────────────────── */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; margin: 0; }
.login-card h1 { margin: 0 0 4px; font-size: 1.4rem; display: flex; align-items: center; gap: 10px; }
.login-card p.sub { margin: 0 0 20px; color: var(--muted); font-size: 0.9rem; }
.field { display: block; margin-bottom: 14px; }
.field label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
.input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font-size: 0.95rem; font-family: inherit; }
.input:focus { outline: none; border-color: var(--accent); }

/* ── Responsive ────────────────────────────────────────────────────── */
@media (max-width: 820px) {
  .gm-menu { display: inline-flex; }
  .gm-account-email { display: none; }
  .gm-sidebar {
    position: fixed; top: 60px; left: 0; bottom: 0; width: 260px; z-index: 20;
    background: var(--surface); border-right: 1px solid var(--border);
    transform: translateX(-100%); transition: transform .2s;
  }
  .gm-sidebar.open { transform: translateX(0); }
  .gm-main { border-radius: 0; border-left: 0; }
  .msg-from { width: 130px; }
}
