:root {
  --bg: #f6f7f5;
  --panel: #ffffff;
  --ink: #1c211d;
  --muted: #6b756e;
  --line: #e2e6e1;
  --accent: #1f7a4d;
  --accent-dark: #16603c;
  --accent-soft: #e8f4ed;
  --warn: #a3660a;
  --warn-soft: #fdf4e3;
  --error: #a52a2a;
  --error-soft: #fdeceb;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-dark); }

/* ---------- layout ---------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 228px;
  flex: 0 0 228px;
  background: #16301f;
  color: #dfe8e1;
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 26px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700;
}
.brand-text { font-weight: 600; color: #fff; letter-spacing: .2px; }
.version {
  display: inline-block;
  align-self: flex-start;
  margin: -18px 0 20px;
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .08);
  color: #9fb0a4;
  font-size: 11.5px;
  letter-spacing: .3px;
  text-decoration: none;
}
.version:hover { background: rgba(255, 255, 255, .16); color: #fff; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  color: #c6d2c9; text-decoration: none;
  padding: 9px 12px; border-radius: 8px; font-size: 14.5px;
}
.nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav a.active { background: var(--accent); color: #fff; font-weight: 600; }

.sidebar-foot { margin-top: auto; font-size: 13px; color: #9fb0a4; }
.sidebar-foot .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 6px; }
.sidebar-foot .link {
  background: none; border: 0; color: #c6d2c9;
  padding: 0; cursor: pointer; font: inherit; text-decoration: underline;
}

.main { flex: 1; padding: 28px 32px 64px; max-width: 1180px; }
.public-main { max-width: 460px; margin: 8vh auto 0; padding: 0 20px; }

/* ---------- headings ---------- */
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.2px; }
h2 { font-size: 16px; margin: 26px 0 10px; }
.sub { color: var(--muted); font-size: 14px; margin: 0; }

/* ---------- panels ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.panel.tight { padding: 0; overflow-x: auto; overflow-y: hidden; }

.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: 1fr 1fr; }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
@media (max-width: 860px) {
  .grid.two { grid-template-columns: 1fr; }
  .shell { flex-direction: column; }
  .sidebar { width: auto; flex: none; height: auto; position: static; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .main { padding: 20px 14px 48px; }
  /* Let wide data tables scroll inside their card instead of squashing. */
  .panel.tight table { min-width: 640px; }
}

/* ---------- stats ---------- */
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .n { font-size: 26px; font-weight: 650; letter-spacing: -.5px; }
.stat .l { color: var(--muted); font-size: 13px; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-weight: 600; font-size: 12px; text-transform: uppercase;
  letter-spacing: .5px; color: var(--muted); padding: 11px 14px;
  border-bottom: 1px solid var(--line); background: #fbfcfb;
}
td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfb; }
.nowrap { white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- badges ---------- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; border: 1px solid transparent; white-space: nowrap;
}
.badge.new { background: #eef1ee; color: #55605a; }
.badge.contacted { background: var(--accent-soft); color: var(--accent-dark); }
.badge.replied, .badge.interested { background: #e6efff; color: #23518f; }
.badge.won { background: #dff5e6; color: #14653c; }
.badge.lost, .badge.not_interested { background: #f2eeee; color: #6d5a5a; }
.badge.queued { background: var(--warn-soft); color: var(--warn); }
.badge.sent { background: var(--accent-soft); color: var(--accent-dark); }
.badge.failed { background: var(--error-soft); color: var(--error); }
.badge.sending { background: #eef1ee; color: #55605a; }
.badge.cancelled { background: #f2eeee; color: #6d5a5a; }
.badge.flag { background: var(--error-soft); color: var(--error); }

/* ---------- buttons ---------- */
button, .btn {
  font: inherit; cursor: pointer; border-radius: 8px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 8px 14px; text-decoration: none; display: inline-block;
}
button:hover, .btn:hover { background: #f3f5f3; }
.btn.primary, button.primary {
  background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600;
}
.btn.primary:hover, button.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn.small, button.small { padding: 5px 10px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent-dark); padding: 5px 8px; }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.danger { color: var(--error); border-color: #eccfcd; }
.btn.danger:hover { background: var(--error-soft); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- forms ---------- */
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.hint { font-size: 12.5px; color: var(--muted); margin: 4px 0 0; }
input[type=text], input[type=email], input[type=password], input[type=url],
input[type=tel], input[type=search], input[type=datetime-local], input[type=number],
select, textarea {
  width: 100%; font: inherit; padding: 9px 11px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { resize: vertical; min-height: 180px; line-height: 1.55; }
.field { margin-bottom: 14px; }
.field-row { display: flex; gap: 14px; }
.field-row > .field { flex: 1; }
.checkbox { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 14px; }
.checkbox input { width: auto; }

fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 0 0 18px; }
legend { font-size: 13px; font-weight: 600; padding: 0 6px; color: var(--muted); }

/* ---------- banners ---------- */
.banner { border-radius: var(--radius); padding: 11px 14px; margin-bottom: 16px; font-size: 14px; border: 1px solid; }
.banner.ok { background: var(--accent-soft); border-color: #cbe6d6; color: var(--accent-dark); }
.banner.error { background: var(--error-soft); border-color: #f0cdcb; color: var(--error); }
.banner.warn { background: var(--warn-soft); border-color: #f0e0bd; color: var(--warn); }
.banner.alert { background: #fdf0ef; border-color: #f0cfcb; color: #8d2b25; }

/* ---------- repeat-contact warning on the compose page ---------- */
.history { list-style: none; margin: 10px 0 0; padding: 0; font-size: 13.5px; }
.history li { padding: 5px 0; border-top: 1px solid rgba(0, 0, 0, .07); color: var(--ink); }
.history li:first-child { border-top: 0; }
.history .when { font-weight: 600; }
.confirm-send {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(0, 0, 0, .09);
  color: var(--ink);
  font-weight: 600;
}

.add-company {
  background: #fbfcfb;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 14px;
  margin-bottom: 14px;
  font-size: 14px;
}
.add-company .checkbox { align-items: flex-start; }
.add-company .checkbox input { margin-top: 3px; }
.wrap-anywhere { word-break: break-all; }
.preview {
  font-size: 12.5px;
  line-height: 1.4;
  max-width: 380px;
  margin-top: 2px;
}

/* ---------- changelog ---------- */
.changelog h3.release {
  font-size: 16px;
  margin: 26px 0 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}
.changelog h3.release:first-child { margin-top: 0; }
.changelog h4 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  margin: 16px 0 6px;
}
.changelog p { margin: 6px 0; }
.changelog ul { margin: 6px 0; padding-left: 20px; }
.changelog li { margin: 4px 0; }
.changelog.whats-new h3.release { font-size: 14px; margin-top: 0; }
.changelog.whats-new h4 { margin-top: 12px; }
.changelog.whats-new ul { padding-left: 18px; font-size: 13.5px; }
.changelog code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  background: #f3f5f3;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
}

/* ---------- misc ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 12px 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: 0; }
.timeline .when { font-size: 12.5px; color: var(--muted); }
.timeline pre {
  white-space: pre-wrap; font: inherit; margin: 6px 0 0;
  background: #fafbfa; border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; font-size: 13.5px; color: #3c443e;
}

.empty { padding: 32px 20px; text-align: center; color: var(--muted); }
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filter-bar .field { margin-bottom: 0; }
.filter-bar .field.grow { flex: 1 1 220px; }
.filter-bar .field.narrow { flex: 0 0 170px; }

.qr { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; background: #fff; display: inline-block; }
.secret {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: #f3f5f3; border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; word-break: break-all; font-size: 14px; letter-spacing: 1px;
}
.codes { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.codes span { font-family: ui-monospace, Menlo, Consolas, monospace; background: #f3f5f3; padding: 8px 10px; border-radius: 8px; text-align: center; letter-spacing: 1px; }

.login-card { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 28px; margin-top: 10vh; }
.login-card .brand { justify-content: center; margin-bottom: 18px; }
.login-card h1 { text-align: center; font-size: 19px; margin-bottom: 22px; }
.login-card .brand-text { color: var(--ink); }
.login-card button { width: 100%; }

@media print { .sidebar, .actions, button { display: none !important; } }

/* ---------- utilities (kept here so no template needs an inline style,
   which the content-security policy would block anyway) ---------- */
.mt-0 { margin-top: 0 !important; }
.mt-sm { margin-top: 12px; }
.mt-md { margin-top: 14px; }
.mb-0 { margin-bottom: 0 !important; }
.mb-sm { margin-bottom: 8px; }
.mb-md { margin-bottom: 10px; }
.mb-lg { margin-bottom: 18px; }
.center { text-align: center; }
.right { text-align: right; }
.inline-form { display: inline; }
.label-flush { margin: 0; font-weight: 500; }
.align-end { flex: 0 0 auto; align-self: flex-end; }
.col-narrow { width: 1%; }
.error-text { color: var(--error); }
.error-text.narrow { max-width: 230px; }

/* read-only key/value tables */
.kv th {
  background: none;
  text-transform: none;
  font-size: 13px;
  letter-spacing: 0;
  color: var(--ink);
  width: 1%;
  white-space: nowrap;
  padding-right: 20px;
  vertical-align: top;
}

/* preformatted body text (notes, quoted emails) */
.term {
  white-space: pre-wrap;
  font: inherit;
  background: #fafbfa;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}
.term.compact { font-size: 13px; }

/* large single-code inputs (authenticator codes) */
.code-input { font-size: 20px; letter-spacing: 6px; text-align: center; }

textarea.ta-90 { min-height: 90px; }
textarea.ta-100 { min-height: 100px; }
textarea.ta-110 { min-height: 110px; }
