:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #17202e;
  --muted: #6b7686;
  --line: #e2e6ec;
  --accent: #b8862b;
  --accent-ink: #101826;
  --blue: #2f6fdb;
  --green: #1f8a5b;
  --red: #c0392b;
  --amber: #b7791f;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 18px;
  background: var(--accent-ink);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}
.brand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
  text-decoration: none;
  flex: 0 0 auto;
}
.brand.big { width: 54px; height: 54px; font-size: 26px; border-radius: 14px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab {
  color: #c9d2e0;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 14px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tab:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.tab.active { background: rgba(255,255,255,.16); color: #fff; }
.count {
  font-size: 11px;
  background: rgba(255,255,255,.2);
  border-radius: 999px;
  padding: 1px 6px;
}
.search { margin-left: auto; }
.search input {
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.18);
  color: #fff;
  border-radius: 8px;
  padding: 7px 10px;
  width: 220px;
  outline: none;
}
.search input::placeholder { color: #aab4c4; }
.search input:focus { border-color: var(--accent); }

button, .button {
  font: inherit;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button:hover, .button:hover { border-color: var(--accent); text-decoration: none; }
button[type="submit"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.ghost { background: transparent; color: inherit; border-color: rgba(255,255,255,.25); }
main button.ghost { color: var(--ink); border-color: var(--line); }

.flash { margin: 12px 18px 0; padding: 10px 14px; border-radius: 8px; font-size: 14px; }
.flash.error { background: #fdeceb; color: #8a2318; border: 1px solid #f3c6c1; }
.flash.ok { background: #e9f7f0; color: #10633f; border: 1px solid #bfe6d5; }

main { max-width: 1080px; margin: 0 auto; padding: 18px; }
.muted { color: var(--muted); }

/* List */
.list-head { color: var(--muted); font-size: 13px; margin: 4px 2px 12px; }
.rows { display: flex; flex-direction: column; gap: 6px; }
.row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  color: inherit;
  text-decoration: none;
}
.row:hover { border-color: #c9d2e0; text-decoration: none; box-shadow: 0 1px 3px rgba(16,24,38,.06); }
.row.needs-reply { border-left: 3px solid var(--blue); }
.row-main { flex: 1; min-width: 0; }
.row-top { display: flex; align-items: center; gap: 8px; }
.row-top .who { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-top time { margin-left: auto; color: var(--muted); font-size: 12px; flex: 0 0 auto; }
.subject { margin-top: 2px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.snippet { margin-top: 2px; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-tags { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; flex: 0 0 auto; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--blue); margin-right: 6px; vertical-align: middle; }
.count-pill { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 0 6px; margin-left: 6px; }

.avatar {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #e8edf5;
  color: #41506a;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

/* Tags */
.tag {
  font-size: 11px;
  line-height: 1.6;
  padding: 1px 8px;
  border-radius: 999px;
  background: #eef1f6;
  color: #4b586e;
  white-space: nowrap;
}
.tag.action { background: #e5efff; color: #1f56b3; }
.tag.warn { background: #fff3d6; color: #8a5b00; }
.tag.neg { background: #fdeceb; color: #8a2318; }
.tag.link { background: var(--accent); color: var(--accent-ink); }
.bucket-action { background: #e5efff; color: #1f56b3; }
.bucket-new { background: #e6f7ee; color: #10633f; }
.bucket-review { background: #fff3d6; color: #8a5b00; }
.bucket-noise { background: #eee; color: #777; }
.cls-lead { background: #e6f7ee; color: #10633f; }
.cls-spam, .cls-newsletter { background: #eee; color: #777; }
.cls-admin, .cls-supplier { background: #eef1f6; color: #4b586e; }

.empty { text-align: center; color: var(--muted); padding: 60px 0; }

/* Thread */
.thread-head { margin-bottom: 16px; }
.thread-head h1 { font-size: 22px; margin: 6px 0 8px; }
.back { font-size: 13px; }
.thread-tags { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.thread-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
}
.thread-actions form { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.thread-actions label { font-size: 13px; color: var(--muted); }
.thread-actions input, .thread-actions select {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 8px;
  font: inherit;
  background: #fff;
}
.ai-note { font-size: 12px; color: var(--muted); margin: 10px 2px 0; }

.messages { display: flex; flex-direction: column; gap: 12px; }
.message {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.message.outbound { border-left: 3px solid var(--accent); }
.message header {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.message header .meta { flex: 1; min-width: 0; }
.message .line1 strong { font-weight: 650; }
.message .addr { color: var(--muted); font-size: 12px; margin-left: 4px; }
.message .line2 { color: var(--muted); font-size: 12px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; }
.message time { color: var(--muted); font-size: 12px; white-space: nowrap; }
iframe.mail-body {
  width: 100%;
  border: 0;
  min-height: 160px;
  background: #fff;
  display: block;
}
.img-blocked { font-size: 12px; color: var(--muted); border: 1px dashed var(--line); padding: 2px 6px; border-radius: 6px; }
.body-tools { font-size: 12px; padding: 8px 2px; }

/* Composer */
.composer {
  margin-top: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.composer-tabs { display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap; }
.composer-tabs a { padding: 6px 10px; border-radius: 8px; color: var(--muted); font-size: 14px; }
.composer-tabs a.active { background: #eef1f6; color: var(--ink); font-weight: 600; }
.composer label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.composer input, .composer textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  margin-top: 3px;
  background: #fff;
}
.composer textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.field-row { display: flex; gap: 10px; }
.field-row label { flex: 1; }
.composer-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }

/* Pager */
.pager { display: flex; gap: 14px; justify-content: center; align-items: center; padding: 18px 0; color: var(--muted); font-size: 13px; }

/* Login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--accent-ink); }
.login-card {
  background: var(--panel);
  border-radius: 16px;
  padding: 32px;
  width: min(360px, 92vw);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.login-card h1 { margin: 14px 0 2px; font-size: 22px; }
.login-card form { text-align: left; margin-top: 18px; }
.login-card label { font-size: 13px; color: var(--muted); }
.login-card input {
  width: 100%;
  margin: 6px 0 12px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
}
.login-card button { width: 100%; }
.login-card .button { display: block; margin-top: 12px; }

@media (max-width: 720px) {
  .topbar { gap: 8px; padding: 10px; }
  .search { order: 5; width: 100%; margin-left: 0; }
  .search input { width: 100%; }
  main { padding: 12px; }
  .row-tags { display: none; }
  .thread-head h1 { font-size: 18px; }
  .field-row { flex-direction: column; gap: 0; }
  .message header time { display: none; }
}

/* Auth + admin */
.userbox { display: flex; align-items: center; gap: 10px; }
.userbox form { margin: 0; }
.user-email { color: #c9d2e0; font-size: 12px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.small { font-size: 13px; }
.auth-links { margin-top: 16px; font-size: 13px; }
.login-card .flash { margin: 12px 0 0; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.panel h2 { font-size: 15px; margin: 0 0 12px; }
.invite { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.invite label { flex: 1; min-width: 220px; font-size: 13px; color: var(--muted); }
.invite input[type="email"] { width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.inline-check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--line); }
.table td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.table .actions form { margin: 0; }
.table .actions button { font-size: 12px; padding: 5px 8px; }
