:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #e2e5ea;
  --text: #1f2430;
  --muted: #6b7280;
  /* Default brand colours - each client's own are set in Settings > Branding
     and served as /brand/theme.css, which overrides these. */
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-tint: #eef0ff;
  --accent-teal: #0f9f8f;
  --danger: #dc2626;
  --danger-tint: #fef2f2;
  --success: #16a34a;
  --warning: #d97706;
  --warning-tint: #fffbeb;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 200px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  padding: 8px 12px 20px;
}
.sidebar .brand img {
  width: 100%;
  height: auto;
  max-width: 170px;
}

.sidebar a {
  color: var(--text);
  padding: 10px 12px 10px 9px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  border-left: 3px solid transparent;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background 0.15s ease, color 0.15s ease;
}

.sidebar a .nav-icon { font-size: 1rem; line-height: 1; }

.sidebar a:hover { background: var(--primary-tint); text-decoration: none; }
.sidebar a.active {
  background: var(--primary-tint);
  color: var(--primary-dark);
  border-left-color: var(--primary);
  font-weight: 600;
}
.sidebar a.logout-link { margin-top: auto; color: var(--muted); }
.sidebar a.logout-link:hover { background: var(--danger-tint); color: var(--danger); }

.currency-toggle {
  margin-top: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 0.85rem;
  cursor: pointer;
  text-align: left;
}
.currency-toggle:hover { background: #e9ecf1; }

.main-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 56px;
  flex-shrink: 0;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.notif-wrap { position: relative; }
.notif-bell {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  position: relative;
  padding: 6px 8px;
  border-radius: var(--radius);
  line-height: 1;
}
.notif-bell:hover { background: var(--bg); }
.notif-badge {
  position: absolute;
  top: 0;
  right: 0;
  background: var(--danger);
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
  border-radius: 999px;
  min-width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}

.notif-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 340px;
  max-height: 420px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  padding: 8px 0;
}
.notif-item {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  display: block;
  color: var(--text);
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--bg); text-decoration: none; }
.notif-item-severity-warning { border-left: 3px solid var(--warning); background: var(--warning-tint); }
.notif-item-severity-error { border-left: 3px solid var(--danger); background: var(--danger-tint); }
.notif-item-message { display: block; }
.notif-item-time { display: block; color: var(--muted); font-size: 0.75rem; margin-top: 2px; }
.notif-empty { padding: 20px 16px; color: var(--muted); font-size: 0.85rem; text-align: center; }

.content {
  flex: 1;
  padding: 28px 32px;
  max-width: 1100px;
}

h1 { margin: 0 0 20px; font-size: 1.6rem; }
h2 { margin: 0 0 12px; font-size: 1.1rem; }
h3 { font-size: 1rem; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 10px;
}

.actions { display: flex; gap: 8px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 20px;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 800px) {
  .two-col { grid-template-columns: 1fr; }
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; overflow-x: auto; }
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent-teal);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
}

.stat-card-won { border-top-color: var(--success); }
.stat-card-lost { border-top-color: var(--danger); }
.stat-card-clickable { cursor: pointer; transition: transform 0.1s ease, box-shadow 0.1s ease; }
.stat-card-clickable:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.08); }

.bar-row-clickable { cursor: pointer; border-radius: 6px; padding: 4px 6px; margin: -4px -6px 8px; }
.bar-row-clickable:hover { background: var(--bg); }

.stat-value { font-size: 1.8rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 0.85rem; margin-top: 4px; }

.muted { color: var(--muted); font-size: 0.9rem; }

.row-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.row-line:last-child { border-bottom: none; }

.badge {
  background: #eef0ff;
  color: var(--primary-dark);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.78rem;
  white-space: nowrap;
}
.badge-danger { background: #fee2e2; color: var(--danger); }
.badge-success { background: #dcfce7; color: var(--success); }
.badge-warning { background: var(--warning-tint); color: var(--warning); }

.btn {
  border: none;
  border-radius: var(--radius);
  padding: 8px 16px;
  font-size: 0.9rem;
  cursor: pointer;
  display: inline-block;
}
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #eceff3; color: var(--text); }
.btn-secondary:hover { background: #dfe3e8; }
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-danger:hover { background: #fecaca; }

.hidden-file { display: none; }

.input {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 0.9rem;
  width: 100%;
  font-family: inherit;
  background: white;
  color: var(--text);
}

.filter-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filter-bar .input { max-width: 220px; }

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.table th, .table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.table th { background: var(--bg); color: var(--muted); font-weight: 600; }
.table th.sortable-th { cursor: pointer; user-select: none; white-space: nowrap; }
.table th.sortable-th:hover { color: var(--primary-dark); }
.table tr.clickable:hover { background: var(--bg); cursor: pointer; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}
.form-field label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 4px;
}
.checkbox-label { display: block; font-size: 0.9rem; margin-top: 6px; }

/* Lead detail page: a narrow info sidebar next to a wider main column
   (email/meetings, activity) - an even 1fr/1fr split squeezed every
   field in the sidebar down to roughly a quarter of the page width
   (each field was already inside a 2-column form-grid), truncating
   values like emails and tags to a few characters. */
.lead-detail-grid {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 900px) {
  .lead-detail-grid { grid-template-columns: 1fr; }
}
/* One field per row so the sidebar's own width goes entirely to each
   value instead of splitting it into two more columns. */
.form-grid-single {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 24px;
  width: 480px;
  max-width: 92vw;
  max-height: 88vh;
  overflow-y: auto;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

.back-link { display: inline-block; margin-bottom: 12px; font-size: 0.9rem; }

.activity-row {
  border-bottom: 1px solid var(--border);
  padding: 10px 0;
}
.activity-row:last-child { border-bottom: none; }

.kanban-board {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding-bottom: 12px;
}
.kanban-column {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  max-height: 78vh;
}
.kanban-column-header {
  display: flex;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  cursor: default;
}
.pipeline-value-toggle { cursor: pointer; font-size: 0.85rem; }
.kanban-list {
  padding: 10px;
  overflow-y: auto;
  flex: 1;
  min-height: 60px;
}
.kanban-list.drag-over { background: #eef0ff; }
.kanban-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 10px;
  cursor: grab;
}
.kanban-card.dragging { opacity: 0.4; }
/* A generic auto-discovered contact's name is often the placeholder
   "Contact (long.email@address.com)" - without a width limit this (and
   a long company name) wraps to 2-3 lines, making that one card much
   taller than its neighbors and the column look ragged. Truncate both to
   a single line with an ellipsis instead - full detail is one click away
   via "Open". */
.kanban-card-title, .kanban-card .muted {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kanban-card-title { font-weight: 600; font-size: 0.92rem; }
.kanban-card-footer {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 0.85rem;
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #1f2430;
  color: white;
  padding: 12px 18px;
  border-radius: var(--radius);
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.25s ease;
  z-index: 200;
  max-width: 320px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-error { background: var(--danger); }

.bar-row { margin-bottom: 12px; }
.bar-row-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.88rem;
  margin-bottom: 4px;
}
.bar-track {
  background: var(--bg);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
}
.bar-fill {
  background: var(--primary);
  height: 100%;
  border-radius: 999px;
}
.bar-fill-won { background: var(--success); }
.bar-fill-lost { background: var(--danger); }
.bar-fill-warning { background: var(--warning); }

.email-thread { margin-top: 8px; }
.email-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 10px;
  cursor: pointer;
  background: var(--panel);
}
.email-item:hover { background: var(--bg); }
.email-item-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.email-item-subject {
  flex: 1;
  font-size: 0.92rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.email-item-date { font-size: 0.8rem; white-space: nowrap; }
.email-item-body {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.88rem;
  white-space: pre-wrap;
  max-height: 4.2em;
  overflow: hidden;
  position: relative;
}
.email-item-body:not(.expanded)::after {
  content: "";
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 1.4em;
  background: linear-gradient(to bottom, transparent, var(--panel));
}
.email-item-body.expanded { max-height: none; }

.legacy-notes {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--muted);
  font-size: 0.88rem;
  white-space: pre-wrap;
  margin-bottom: 10px;
}

/* ---------- Agents screen (static/js/views/agents.js) ---------- */
.agents-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.agents-header h1 { margin-bottom: 4px; }
.agents-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.agents-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 20px; margin-top: 16px; }
.agent-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; border-top: 4px solid var(--border); transition: border-color .3s, box-shadow .3s;
}
.agent-card.agent-running { border-top-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-tint); }
.agent-card.agent-passed { border-top-color: var(--success); }
.agent-card.agent-warning { border-top-color: var(--warning); }
.agent-card.agent-failed { border-top-color: var(--danger); }
.agent-head { display: flex; gap: 14px; align-items: flex-start; }
.agent-head .btn { margin-left: auto; flex-shrink: 0; }
.agent-avatar { position: relative; width: 60px; height: 60px; flex-shrink: 0; display: grid; place-items: center; }
.agent-emoji {
  width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center;
  font-size: 1.7rem; background: var(--primary-tint);
}
.agent-ring { position: absolute; inset: 0; border-radius: 50%; border: 3px solid transparent; }
.agent-running .agent-ring { border-top-color: var(--primary); border-right-color: var(--accent-teal); animation: agent-spin 1s linear infinite; }
.agent-running .agent-emoji { animation: agent-bob 1.2s ease-in-out infinite; }
.agent-passed .agent-ring { border-color: var(--success); }
.agent-warning .agent-ring { border-color: var(--warning); }
.agent-failed .agent-ring { border-color: var(--danger); }
@keyframes agent-spin { to { transform: rotate(360deg); } }
@keyframes agent-bob { 50% { transform: translateY(-3px) scale(1.05); } }
.agent-name { font-weight: 700; font-size: 1.15rem; }
.agent-role { color: var(--primary); font-weight: 600; font-size: .85rem; }
.agent-about { color: var(--muted); font-size: .85rem; margin-top: 4px; }
.agent-statusline { display: flex; align-items: center; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.agent-pill { padding: 3px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; background: var(--bg); color: var(--muted); }
.pill-running { background: var(--primary-tint); color: var(--primary); }
.pill-passed { background: #ecfdf3; color: var(--success); }
.pill-warning { background: var(--warning-tint); color: var(--warning); }
.pill-failed { background: var(--danger-tint); color: var(--danger); }
.agent-now { font-size: .85rem; color: var(--muted); }
.agent-progress { height: 6px; background: var(--bg); border-radius: 999px; margin-top: 10px; overflow: hidden; }
.agent-progress-fill { height: 100%; background: var(--muted); border-radius: 999px; transition: width .5s ease; }
.agent-running .agent-progress-fill {
  background: linear-gradient(90deg, var(--primary), var(--accent-teal), var(--primary));
  background-size: 200% 100%; animation: agent-shimmer 1.5s linear infinite;
}
.agent-passed .agent-progress-fill { background: var(--success); }
.agent-warning .agent-progress-fill { background: var(--warning); }
.agent-failed .agent-progress-fill { background: var(--danger); }
@keyframes agent-shimmer { to { background-position: -200% 0; } }
.agent-tally { display: flex; gap: 14px; font-size: .8rem; margin-top: 10px; font-weight: 600; }
.t-pass { color: var(--success); } .t-warn { color: var(--warning); } .t-fail { color: var(--danger); }
.agent-steps { list-style: none; padding: 0; margin: 14px 0 0; display: flex; flex-direction: column; gap: 4px; }
.agent-step { display: flex; gap: 10px; align-items: flex-start; padding: 7px 8px; border-radius: 8px; }
.step-icon {
  width: 20px; height: 20px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center;
  font-size: .7rem; font-weight: 800; color: white; margin-top: 1px;
}
.step-pass .step-icon { background: var(--success); }
.step-warn .step-icon { background: var(--warning); }
.step-fail .step-icon { background: var(--danger); }
.step-running { background: var(--primary-tint); animation: agent-glow 1.2s ease-in-out infinite; }
@keyframes agent-glow { 50% { background: #dfe3ff; } }
.step-running .step-icon { border: 2px solid var(--primary); border-top-color: transparent; animation: agent-spin .8s linear infinite; }
.step-warn { background: var(--warning-tint); }
.step-fail { background: var(--danger-tint); }
.step-name { font-size: .9rem; font-weight: 500; }
.step-detail { font-size: .8rem; color: var(--muted); margin-top: 1px; }
.agent-empty { margin-top: 14px; }
.agent-history { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.hist-dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid transparent; padding: 0; cursor: pointer; background: var(--muted); }
.dot-passed { background: var(--success); } .dot-warning { background: var(--warning); }
.dot-failed { background: var(--danger); } .dot-running { background: var(--primary); }
.hist-dot.dot-active { border-color: var(--text); transform: scale(1.2); }
@media (max-width: 600px) { .agents-grid { grid-template-columns: 1fr; } }
