/* ──────────────────────────────────────────────────────────────────
   Flip — Brand tokens (compact CRM build)
   ────────────────────────────────────────────────────────────────── */

@font-face {
  font-family: "GT Maru";
  src: url("fonts/GT-Maru-Medium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Brand */
  --flip-deep-blue:   #0033A0;
  --flip-blue:        #0068E9;
  --flip-light-blue:  #78D2E1;
  --flip-lime:        #FAFFA0;
  --flip-yellow:      #FFBA00;
  --flip-dark-green:  #00693E;
  --flip-green:       #00C281;
  --flip-purple:      #962882;
  --flip-light-pink:  #FFF2F5;
  --flip-red:         #C8002D;
  --flip-white:       #FFFFFF;
  --flip-light-grey:  #F7F7F7;
  --flip-black:       #000000;

  /* Semantic */
  --bg-page:        var(--flip-white);
  --bg-soft:        var(--flip-light-grey);
  --fg-1:           var(--flip-deep-blue);
  --fg-on-blue:     var(--flip-light-blue);
  --fg-muted:       #6b7280;
  --border-subtle:  #E5E9F2;
  --border-strong:  var(--flip-deep-blue);

  /* Type */
  --font-body: "GT Maru", "Inter", system-ui, -apple-system, sans-serif;
  --tracking-body: -0.01em;
  --tracking-tight: -0.02em;

  /* Radii */
  --radius-input: 5px;
  --radius-card:  8px;
  --radius-pill:  100px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 13px;
  line-height: 1.35;
  letter-spacing: var(--tracking-body);
  color: var(--fg-1);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.hidden { display: none !important; }

/* ── Auth gate ───────────────────────────────────────────── */
.auth-gate { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--bg-soft); }
.auth-card { background: var(--flip-white); padding: 36px 44px; border-radius: var(--radius-card); border: 1px solid var(--flip-deep-blue); text-align: center; max-width: 380px; }
.auth-card h1 { margin: 0 0 8px; font-size: 24px; letter-spacing: var(--tracking-tight); color: var(--flip-deep-blue); }
.auth-card p { color: var(--fg-muted); margin: 0 0 18px; font-size: 13px; }

/* ── App shell ───────────────────────────────────────────── */
#app { display: flex; min-height: 100vh; background: var(--bg-soft); }

.sidebar { width: 220px; background: var(--flip-white); color: var(--flip-deep-blue); padding: 24px 0; display: flex; flex-direction: column; border-right: 1px solid var(--border-subtle); }
.brand { padding: 0 24px 24px; border-bottom: 1px solid var(--border-subtle); margin-bottom: 12px; display: flex; align-items: center; justify-content: center; }
.brand img { display: block; max-width: 92px; height: auto; }
.sidebar nav { display: flex; flex-direction: column; }
.nav-item { background: none; border: none; color: var(--flip-deep-blue); text-align: left; padding: 12px 24px; cursor: pointer; font-family: inherit; font-size: 14px; font-weight: 500; letter-spacing: var(--tracking-body); }
.nav-item:hover { background: var(--flip-light-grey); }
.nav-item.active { background: var(--flip-light-blue); color: var(--flip-deep-blue); }

/* Signed-in user, bottom of the sidebar */
.sidebar { position: sticky; top: 0; height: 100vh; box-sizing: border-box; align-self: flex-start; overflow-y: auto; }
.sidebar-user { margin-top: auto; padding: 16px 24px 0; border-top: 1px solid var(--border-subtle); font-size: 12px; color: var(--fg-muted); }
.sidebar-user .su-name { color: var(--flip-deep-blue); font-weight: 500; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user .su-role { display: inline-block; margin: 4px 0 8px; padding: 1px 8px; border-radius: var(--radius-pill); background: var(--flip-light-grey); }
.sidebar-user button { display: block; background: none; border: none; padding: 0; color: var(--fg-muted); font: inherit; cursor: pointer; text-decoration: underline; }
.auth-error { color: var(--flip-red) !important; }

/* Viewer: read-only — every control that changes a record is hidden (the server refuses those writes anyway) */
body.role-viewer #add-btn, body.role-viewer #detail-save, body.role-viewer #detail-delete, body.role-viewer [data-del],
body.role-viewer #new-act-btn, body.role-viewer #new-deal-btn, body.role-viewer #new-event-btn, body.role-viewer #sp-add-new,
body.role-viewer #sister-locs-edit-btn, body.role-viewer #company-edit-btn, body.role-viewer #timeline-edit-btn,
body.role-viewer #deal-company-edit-btn, body.role-viewer [data-co-new], body.role-viewer [data-co-edit],
body.role-viewer [data-act-edit], body.role-viewer [data-act-del], body.role-viewer [data-del-rule], body.role-viewer [data-rule],
body.role-viewer [data-company-edit], body.role-viewer .link-field-edit, body.role-viewer [data-set-tag], body.role-viewer #tag-picker,
body.role-viewer [data-link-event], body.role-viewer #unlink-event, body.role-viewer #move-acct, body.role-viewer #reply,
body.role-viewer .conv-add-crm, body.role-viewer #compose, body.role-viewer #rules-btn { display: none !important; }

/* Team page */
.team-table { width: 100%; border-collapse: collapse; background: var(--flip-white); border: 1px solid var(--border-subtle); border-radius: var(--radius-card); overflow: hidden; }
.team-table th, .team-table td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border-subtle); font-size: 13px; }
.team-table th { color: var(--fg-muted); font-weight: 500; }
.team-table tr:last-child td { border-bottom: none; }
.team-table select, .team-table input { font: inherit; font-size: 13px; padding: 4px 8px; border: 1px solid var(--border-subtle); border-radius: 6px; background: var(--flip-white); color: var(--flip-deep-blue); }
.team-table input.team-owner { width: 70px; }
.team-status { font-size: 12px; color: var(--fg-muted); }
.team-status.ok { color: #00693E; }
.team-invite { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; margin-bottom: 20px; padding: 16px; background: var(--flip-white); border: 1px solid var(--border-subtle); border-radius: var(--radius-card); }
.team-invite label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--fg-muted); }
.team-invite input, .team-invite select { font: inherit; font-size: 13px; padding: 7px 10px; border: 1px solid var(--border-subtle); border-radius: 6px; color: var(--flip-deep-blue); }
.team-roles { margin-top: 16px; font-size: 12px; color: var(--fg-muted); line-height: 1.6; }

main { flex: 1; padding: 32px 40px; overflow: auto; background: var(--bg-soft); }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.page-head h2 { margin: 0; font-size: 24px; font-weight: 500; letter-spacing: var(--tracking-tight); color: var(--flip-deep-blue); }
.page-head .actions { display: flex; gap: 8px; }

/* ── List search bar ─────────────────────────────────────── */
.list-search-bar { position: relative; display: inline-flex; align-items: center; margin-bottom: 16px; }
.list-search-bar svg { position: absolute; left: 11px; color: var(--fg-muted, #888); pointer-events: none; flex-shrink: 0; }
.list-search-bar input { padding: 7px 14px 7px 32px; border: 1px solid var(--border-subtle); border-radius: var(--radius-pill); font-family: inherit; font-size: 13px; color: var(--flip-deep-blue); background: var(--flip-white); width: 280px; transition: border-color .15s, box-shadow .15s; }
.list-search-bar input:focus { outline: none; border-color: var(--flip-deep-blue); box-shadow: 0 0 0 2px rgba(0,51,160,.1); }
.list-search-bar input::-webkit-search-cancel-button { cursor: pointer; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn { padding: 8px 16px; border-radius: var(--radius-pill); border: 1px solid var(--flip-deep-blue); background: var(--flip-white); color: var(--flip-deep-blue); cursor: pointer; font-family: inherit; font-size: 14px; font-weight: 500; letter-spacing: var(--tracking-body); transition: background .12s ease, color .12s ease, border-color .12s ease; }
.btn:hover { background: var(--flip-deep-blue); color: var(--flip-white); }
.btn:disabled { opacity: .35; cursor: not-allowed; }

.btn-primary { background: var(--flip-deep-blue); color: var(--flip-white); }
.btn-primary:hover { background: #00256E; color: var(--flip-white); }

.btn-danger { background: var(--flip-red); color: var(--flip-white); border-color: var(--flip-red); }
.btn-danger:hover { background: #95001F; color: var(--flip-white); border-color: #95001F; }

.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: var(--radius-pill); }

/* ── Tables ──────────────────────────────────────────────── */
table { width: 100%; table-layout: fixed; background: var(--flip-white); border-collapse: collapse; border-radius: var(--radius-card); overflow: hidden; border: 1px solid var(--border-subtle); }
th, td { padding: 7px 12px; text-align: left; font-size: 12.5px; border-bottom: 1px solid var(--border-subtle); }
th { background: var(--flip-light-grey); font-weight: 500; color: var(--flip-deep-blue); cursor: pointer; user-select: none; position: relative; letter-spacing: var(--tracking-body); }
th:hover { background: #ECEEF3; }
td { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--flip-deep-blue); }
.col-resizer { position: absolute; right: 0; top: 0; bottom: 0; width: 8px; cursor: col-resize; user-select: none; background: transparent; border-right: 2px solid transparent; z-index: 2; }
.col-resizer:hover, th:hover .col-resizer { border-right-color: var(--flip-deep-blue); }
tbody tr:hover { background: rgba(120, 210, 225, .12); cursor: pointer; }
td a { color: var(--flip-blue); text-decoration: none; }
td a:hover { text-decoration: underline; }
td.row-actions { display: flex; gap: 4px; overflow: visible; }

/* ── Kanban ──────────────────────────────────────────────── */
.kanban { display: grid; gap: 10px; overflow-x: auto; }
.kanban-col { background: var(--flip-light-grey); border-radius: var(--radius-card); padding: 10px; min-height: 280px; }
.kanban-col h4 { margin: 0 0 10px; font-size: 11px; text-transform: uppercase; color: var(--flip-deep-blue); letter-spacing: .04em; font-weight: 500; }
.kanban-card { background: var(--flip-white); border: 1px solid var(--border-subtle); border-radius: var(--radius-card); padding: 10px; margin-bottom: 6px; cursor: pointer; transition: border-color .12s ease; }
.kanban-card:hover { border-color: var(--flip-deep-blue); }
.kanban-card.dragging { opacity: .4; }
.kanban-col.drag-over { background: rgba(120, 210, 225, .25); outline: 2px dashed var(--flip-deep-blue); outline-offset: -4px; }
.kanban-card .title { font-weight: 500; font-size: 13px; margin-bottom: 4px; color: var(--flip-deep-blue); }
.kanban-card .meta { font-size: 11px; color: var(--fg-muted); }

/* ── View toggle ─────────────────────────────────────────── */
.view-toggle { display: inline-flex; background: var(--flip-light-grey); border: 1px solid var(--border-subtle); border-radius: var(--radius-pill); padding: 2px; }
.view-toggle button { background: none; border: 1px solid transparent; padding: 6px 14px; font-family: inherit; font-size: 13px; cursor: pointer; border-radius: var(--radius-pill); color: var(--flip-deep-blue); }
.view-toggle button.active { background: var(--flip-white); border-color: var(--flip-deep-blue); }

/* ── Modal ───────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; background: rgba(0, 51, 160, .25); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-card { background: var(--flip-white); border: 1px solid var(--flip-deep-blue); border-radius: var(--radius-card); width: 480px; max-width: 92vw; max-height: 90vh; overflow: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border-subtle); }
.modal-head h3 { margin: 0; font-size: 15px; letter-spacing: var(--tracking-tight); color: var(--flip-deep-blue); }
.icon-btn { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--fg-muted); }
.icon-btn:hover { color: var(--flip-deep-blue); }
#modal-body { padding: 14px 16px; }

/* ── Forms ───────────────────────────────────────────────── */
.form-row { display: flex; flex-direction: column; margin-bottom: 10px; }
.form-row label { font-size: 10px; font-weight: 500; color: var(--flip-deep-blue); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .04em; }
.form-row input, .form-row select, .form-row textarea {
  padding: 7px 10px;
  border: 1px solid transparent;
  background: var(--flip-light-grey);
  border-radius: var(--radius-input);
  font-size: 13px;
  font-family: inherit;
  color: var(--flip-deep-blue);
  letter-spacing: var(--tracking-body);
  transition: border-color .12s ease, background .12s ease;
}
.form-row input::placeholder, .form-row textarea::placeholder { color: rgba(0, 51, 160, .45); }
.form-row input:focus, .form-row select:focus, .form-row textarea:focus { outline: none; border-color: var(--flip-deep-blue); background: var(--flip-white); }
.form-row textarea { min-height: 60px; resize: vertical; }
.form-actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 12px; }

.multi-select { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px; border: 1px solid var(--border-subtle); border-radius: var(--radius-input); background: var(--flip-white); }
.multi-select label { font-size: 12px; font-weight: 500; display: inline-flex; align-items: center; gap: 4px; background: var(--flip-light-grey); padding: 4px 8px; border-radius: var(--radius-pill); cursor: pointer; color: var(--flip-deep-blue); }
.multi-select label:has(input:checked) { background: var(--flip-light-blue); }

/* ── Emails ──────────────────────────────────────────────── */
.email-layout { display: grid; grid-template-columns: 380px 1fr; gap: 16px; height: calc(100vh - 120px); }
.email-list { background: var(--flip-white); border: 1px solid var(--border-subtle); border-radius: 12px; display: flex; flex-direction: column; overflow: hidden; }
.email-list-head { padding: 12px; border-bottom: 1px solid var(--border-subtle); }
.email-list-head .list-search-bar { margin: 0; display: flex; }
.email-list-head .list-search-bar input { width: 100%; }
.email-list-items { overflow-y: auto; flex: 1; }
.email-empty { padding: 32px 16px; text-align: center; color: var(--fg-muted); font-size: 13px; }
.avatar { flex-shrink: 0; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 600; color: var(--flip-deep-blue); letter-spacing: 0; }
/* Company logo over the initials (see avatarHtml) */
.avatar { position: relative; overflow: hidden; }
.avatar-logo { position: absolute; inset: 0; margin: auto; width: 64%; height: 64%; object-fit: contain; }
.avatar-logo.full { width: 100%; height: 100%; object-fit: cover; }
.avatar.has-logo { color: transparent; box-shadow: inset 0 0 0 1px var(--border-subtle); }
.name-with-logo { display: inline-flex; align-items: center; gap: 8px; }
.email-item { display: flex; gap: 4px; padding: 10px 16px 11px 6px; cursor: pointer; position: relative; }
.email-item::after { content: ''; position: absolute; left: 22px; right: 0; bottom: 0; border-bottom: 1px solid var(--border-subtle); }
.email-item:hover { background: var(--flip-light-grey); }
.email-item-dot { flex-shrink: 0; width: 10px; height: 10px; margin: 5px 6px 0 2px; border-radius: 50%; }
.email-item.unread .email-item-dot { background: var(--flip-blue); }
.email-item-main { min-width: 0; flex: 1; color: #1d1d1f; }
.email-item-top, .email-item-mid { display: flex; align-items: center; gap: 6px; min-width: 0; }
.email-item-from { font-size: 14.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.email-item-date { margin-left: auto; padding-left: 8px; font-size: 13px; color: #86868b; white-space: nowrap; font-variant-numeric: tabular-nums; }
.email-item-mid { margin-top: 2px; }
.email-item-subject { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
.email-item-clip { color: #a1a1a6; display: inline-flex; }
.email-item-count { display: inline-flex; align-items: center; gap: 3px; font-size: 13.5px; color: var(--flip-blue); }
.email-item-snippet { margin-top: 2px; font-size: 13px; line-height: 1.4; color: #86868b; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.email-item.active { background: var(--flip-blue); }
.email-item.active::after { border-color: transparent; }
.email-item.active .email-item-main, .email-item.active .email-item-date, .email-item.active .email-item-snippet,
.email-item.active .email-item-clip, .email-item.active .email-item-count { color: var(--flip-white); }
.email-item.active .email-item-snippet { opacity: .85; }
.email-item.active.unread .email-item-dot { background: var(--flip-white); }
.email-item-crm { flex-shrink: 1; min-width: 0; font-size: 10.5px; font-weight: 500; padding: 1px 7px; border-radius: var(--radius-pill); background: #D7F5E9; color: var(--flip-dark-green); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
a.email-item-crm:hover { text-decoration: underline; }
.email-detail { background: var(--flip-white); border: 1px solid var(--border-subtle); border-radius: 12px; padding: 24px 28px; overflow: auto; }
.email-thread-head { display: flex; align-items: flex-start; gap: 16px; justify-content: space-between; margin-bottom: 16px; }
.email-thread-head h2 { margin: 0; font-size: 20px; line-height: 1.3; letter-spacing: var(--tracking-tight); }
.email-msg { border: 1px solid var(--border-subtle); border-radius: 10px; margin-bottom: 10px; }
.email-msg-head { display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; cursor: pointer; }
.email-msg-who { flex: 1; min-width: 0; font-size: 13px; }
.email-msg-addr { color: var(--fg-muted); font-size: 12px; }
.email-msg-to { font-size: 12px; color: var(--fg-muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.email-msg-preview { font-size: 12px; color: var(--fg-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.email-msg-date { font-size: 11.5px; color: var(--fg-muted); white-space: nowrap; }
.email-msg-body { display: none; white-space: pre-wrap; font-size: 13.5px; line-height: 1.6; color: #1d2a4d; padding: 4px 16px 18px 60px; overflow-wrap: anywhere; }
.email-msg.open .email-msg-body { display: block; }
.email-msg.open .email-msg-preview { display: none; }
.email-msg:not(.open) .email-msg-to { display: none; }

/* ── Pills (chips) ───────────────────────────────────────── */
.pill { display: inline-block; padding: 2px 8px; border-radius: var(--radius-pill); font-size: 10.5px; font-weight: 500; letter-spacing: .02em; background: var(--flip-light-grey); color: var(--flip-deep-blue); }

/* Status: products / generic */
.pill.active   { background: var(--flip-green); color: var(--flip-white); }
.pill.inactive { background: var(--flip-light-grey); color: var(--fg-muted); }

/* Hot 🔥 toggle — yellow when on, light-grey when off */
.pill.hot { background: var(--flip-yellow); color: var(--flip-deep-blue); cursor: pointer; user-select: none; transition: background .12s ease, color .12s ease; }
.pill.hot.off { background: var(--flip-light-grey); color: var(--fg-muted); }
.pill.hot.off:hover { background: #ECEEF3; }
.pill.hot:hover { filter: brightness(1.05); }
.pill.risk { background: #FDE2E1; color: var(--flip-red); cursor: pointer; user-select: none; transition: background .12s ease, color .12s ease; }
.pill.risk.off { background: var(--flip-light-grey); color: var(--fg-muted); }
.pill.risk.off:hover { background: #ECEEF3; }
.deal-flags { display: inline-flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.deal-tags-row { grid-column: 2; }
.deal-tags-row .deal-flags { padding: 6px 0; }
.field-hint { display: block; font-size: 11px; color: var(--fg-muted); margin-top: 4px; }

/* Siradis YES/NO */
.pill.yes { background: var(--flip-lime); color: var(--flip-deep-blue); }
.pill.no  { background: var(--flip-light-grey); color: var(--fg-muted); }

/* Deal stages */
.pill.stage-lead                    { background: var(--flip-light-blue); color: var(--flip-deep-blue); }
.pill.stage-discussion-started      { background: var(--flip-yellow); color: var(--flip-deep-blue); }
.pill.stage-sample-box-sent-droped  { background: var(--flip-light-pink); color: var(--flip-purple); }
.pill.stage-tasting-done            { background: var(--flip-lime); color: var(--flip-deep-blue); }
.pill.stage-verbal-commitment       { background: var(--flip-light-blue); color: var(--flip-dark-green); }
.pill.stage-won                     { background: var(--flip-green); color: var(--flip-white); }
.pill.stage-lost                    { background: var(--flip-black); color: var(--flip-white); }
.pill.stage-lost-after-won          { background: var(--flip-light-grey); color: var(--fg-muted); }

/* Inline stage dropdown in the deals list — looks like a stage pill, reuses the .pill.stage-* colours */
.stage-select { max-width: 100%; appearance: none; -webkit-appearance: none; border: 0; border-radius: var(--radius-pill); padding: 2px 20px 2px 8px; font-family: inherit; font-size: 10.5px; font-weight: 500; letter-spacing: .02em; cursor: pointer; background-color: var(--flip-light-grey); color: var(--flip-deep-blue); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5'%3E%3Cpath d='M0 0l4 5 4-5z' fill='currentColor' opacity='.55'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 7px center; }
.stage-select:hover { filter: brightness(.96); }
.stage-select:focus-visible { outline: 2px solid var(--flip-deep-blue); outline-offset: 1px; }
.stage-select option { background: var(--flip-white); color: var(--flip-deep-blue); }
.stage-select.stage-lead                    { background-color: var(--flip-light-blue); }
.stage-select.stage-discussion-started      { background-color: var(--flip-yellow); }
.stage-select.stage-sample-box-sent-droped  { background-color: var(--flip-light-pink); color: var(--flip-purple); }
.stage-select.stage-tasting-done            { background-color: var(--flip-lime); }
.stage-select.stage-verbal-commitment       { background-color: var(--flip-light-blue); color: var(--flip-dark-green); }
.stage-select.stage-won                     { background-color: var(--flip-green); color: var(--flip-white); }
.stage-select.stage-lost                    { background-color: var(--flip-black); color: var(--flip-white); }
.stage-select.stage-lost-after-won          { background-color: var(--flip-light-grey); color: var(--fg-muted); }

/* ── Detail page ─────────────────────────────────────────── */
.detail-page { max-width: 860px; }
.detail-page-wide { max-width: 1280px; }

/* Two-column company detail layout */
.company-detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  align-items: start;
}
@media (max-width: 1100px) {
  .company-detail-layout { grid-template-columns: 1fr; }
}
.company-detail-main { min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.company-detail-sidebar { display: flex; flex-direction: column; gap: 12px; }

/* Sidebar cards */
.detail-card {
  background: var(--flip-white);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  overflow: hidden;
}
.detail-card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
}
.detail-card-head h4 {
  margin: 0; font-size: 11px; text-transform: uppercase;
  letter-spacing: .04em; color: var(--flip-deep-blue); font-weight: 500;
}
.detail-card-body { padding: 14px 16px; }
.detail-card-body .form-row:last-child { margin-bottom: 0; }

/* Compact deal rows for the sidebar card */
.deal-list-card { display: flex; flex-direction: column; }
.deal-card-row {
  display: flex; flex-direction: column; gap: 4px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
}
.deal-card-row:first-child { padding-top: 0; }
.deal-card-row:last-child { padding-bottom: 0; border-bottom: none; }
.deal-card-row:hover { background: rgba(120,210,225,.08); margin: 0 -8px; padding-left: 8px; padding-right: 8px; border-radius: var(--radius-input); }
.deal-card-chips { display: flex; gap: 4px; flex-wrap: wrap; }
.deal-card-title { font-size: 13px; font-weight: 500; color: var(--flip-deep-blue); }
.deal-card-meta { font-size: 11px; color: var(--fg-muted); }

/* Email log list (in sidebar cards) */
.email-log-list { display: flex; flex-direction: column; }
.email-log-row {
  display: flex; flex-direction: column; gap: 2px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-subtle);
  text-decoration: none; color: inherit;
}
.email-log-row:first-child { padding-top: 0; }
.email-log-row:last-child  { border-bottom: none; padding-bottom: 0; }
.email-log-row:hover { background: rgba(120,210,225,.08); margin: 0 -8px; padding-left: 8px; padding-right: 8px; border-radius: var(--radius-input); }
.email-log-head { display: flex; align-items: center; gap: 6px; min-width: 0; }
.email-log-dir { font-weight: 700; font-size: 12px; }
.email-log-dir-in  { color: var(--flip-blue); }
.email-log-dir-out { color: var(--flip-green); }
.email-log-date { font-size: 11px; color: var(--fg-muted); font-variant-numeric: tabular-nums; }
.email-log-subject { font-size: 12.5px; color: var(--flip-deep-blue); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.email-log-snippet { font-size: 11px; color: var(--fg-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.detail-form-card {
  background: var(--flip-white);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  padding: 24px 28px;
}
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 28px;
}
.detail-grid .form-row.full-width { grid-column: 1 / -1; }
/* Two-column layout inside the company info card */
.company-info-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
  align-items: stretch; /* both columns always the same height */
}
.company-info-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
/* Location block grows to fill all available space in the right column */
.company-location-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  margin-bottom: 4px;
}
/* Map iframe fills whatever vertical space the location block has left */
.company-location-col iframe {
  flex: 1;
  min-height: 140px;
  display: block;
}
.detail-location-head {
  font-size: 10px; text-transform: uppercase; letter-spacing: .05em;
  font-weight: 500; color: var(--flip-deep-blue); margin-bottom: 8px;
}
.address-line { font-size: 12px; color: var(--fg-body); line-height: 1.5; }
/* Legacy full-bleed location section (kept for safety, no longer rendered) */
.detail-location-section {
  border-top: 1px solid var(--border-subtle);
  margin: 20px -28px -24px;
  padding: 20px 28px 24px;
}
/* Legacy — kept in case other pages still use .detail-section */
.detail-section {
  background: var(--flip-white);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  padding: 18px 24px;
  margin-top: 12px;
}
.detail-section h4 { margin: 0 0 12px; font-size: 11px; text-transform: uppercase; color: var(--flip-deep-blue); letter-spacing: .04em; font-weight: 500; }
.detail-section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.detail-section-head h4 { margin: 0; }
.deal-list { display: flex; flex-direction: column; }
.deal-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border-subtle); cursor: pointer; gap: 12px; }
.deal-row:last-child { border-bottom: none; }
.deal-row:hover { background: rgba(120,210,225,.08); margin: 0 -8px; padding: 8px; border-radius: var(--radius-input); }
.deal-row-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.deal-row-title { font-size: 13px; font-weight: 500; color: var(--flip-deep-blue); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.deal-row-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; font-size: 12px; }
.form-static { padding: 7px 10px; background: var(--flip-light-grey); border-radius: var(--radius-input); font-size: 13px; color: var(--flip-deep-blue); }
.linked-record {
  display: flex; align-items: center; gap: 12px;
  padding: 7px 0; border-bottom: 1px solid var(--border-subtle);
  cursor: pointer; font-size: 13px;
}
.linked-record:last-child { border-bottom: none; }
.linked-record:hover { color: var(--flip-blue); }

/* ── Misc ────────────────────────────────────────────────── */
.sub-section { margin-top: 18px; }
.sub-section h4 { margin: 0 0 6px; font-size: 11px; text-transform: uppercase; color: var(--flip-deep-blue); letter-spacing: .04em; font-weight: 500; }
.muted { color: var(--fg-muted); font-size: 12px; }

/* ── Link field (Primary/Secondary contacts) ─────────────── */
.link-field-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 4px;
}
.link-field-head label { margin-bottom: 0; }
.link-field { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border: 1px solid var(--border-subtle); border-radius: var(--radius-input); background: var(--flip-white); }
.link-field-display { flex: 1; font-size: 13px; color: var(--flip-deep-blue); }
.link-field-display .muted { font-size: 13px; }
.contact-nav-link, .company-nav-link { color: var(--flip-blue); cursor: pointer; }
.contact-nav-link:hover, .company-nav-link:hover { text-decoration: underline; }

/* ── Side panel (contact picker) ─────────────────────────── */
.side-panel-backdrop { position: fixed; inset: 0; background: rgba(0, 51, 160, .15); z-index: 99; }
.side-panel { position: fixed; top: 0; right: 0; bottom: 0; width: 33vw; min-width: 320px; max-width: 520px; background: var(--flip-white); border-left: 1px solid var(--flip-deep-blue); z-index: 100; display: flex; flex-direction: column; transform: translateX(100%); transition: transform .22s ease; }
.side-panel.open { transform: translateX(0); }
.side-panel-head { padding: 14px 18px; border-bottom: 1px solid var(--border-subtle); display: flex; align-items: center; justify-content: space-between; }
.side-panel-head h3 { margin: 0; font-size: 15px; color: var(--flip-deep-blue); letter-spacing: var(--tracking-tight); }
.side-panel-search { padding: 10px 18px; border-bottom: 1px solid var(--border-subtle); }
.side-panel-search input { width: 100%; padding: 7px 10px; border: 1px solid transparent; background: var(--flip-light-grey); border-radius: var(--radius-input); font-family: inherit; font-size: 13px; color: var(--flip-deep-blue); }
.side-panel-search input:focus { outline: none; border-color: var(--flip-deep-blue); background: var(--flip-white); }
.side-panel-list { flex: 1; overflow: auto; padding: 6px 10px; }
.side-panel-body { flex: 1; overflow: auto; padding: 14px 18px; }
.side-panel-foot { padding: 10px 18px; border-top: 1px solid var(--border-subtle); display: flex; justify-content: flex-end; gap: 6px; }
.contact-result { padding: 8px 10px; border-radius: var(--radius-input); cursor: pointer; display: flex; align-items: center; gap: 8px; }
.contact-result:hover { background: var(--flip-light-grey); }
.contact-result.selected { background: rgba(120, 210, 225, .25); }
.contact-result .name { font-weight: 500; font-size: 13px; color: var(--flip-deep-blue); }
.contact-result .meta { font-size: 11px; color: var(--fg-muted); }
.contact-result input[type="checkbox"] { transform: scale(1.05); accent-color: var(--flip-deep-blue); }

/* ── Duplicate-detection warning banner ──────────────────── */
.dup-warning { background: #fffbeb; border: 1px solid #f59e0b; border-radius: 6px; padding: 12px 14px; margin: 10px 0 4px; }
.dup-warning-title { font-weight: 600; font-size: 13px; color: #92400e; margin-bottom: 6px; }
.dup-warning-list { margin: 0 0 10px 18px; padding: 0; font-size: 12px; color: #78350f; }
.dup-warning-list li { margin: 2px 0; }
.dup-warning-btns { display: flex; gap: 8px; justify-content: flex-end; }

/* ── New Company – mode tabs & Places search ─────────────── */
.modal-mode-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.modal-mode-tab { flex: 1; padding: 7px 10px; border: 1px solid var(--border-subtle); border-radius: var(--radius-pill); background: var(--flip-white); color: var(--flip-deep-blue); font-size: 13px; font-weight: 500; font-family: inherit; cursor: pointer; transition: background .14s, color .14s, border-color .14s; }
.modal-mode-tab:hover:not(.active) { background: var(--flip-light-grey); }
.modal-mode-tab.active { background: var(--flip-deep-blue); color: var(--flip-white); border-color: var(--flip-deep-blue); }

.place-search-bar { display: flex; gap: 8px; margin-bottom: 10px; }
.place-search-bar input { flex: 1; padding: 7px 10px; border: 1px solid var(--border-subtle); border-radius: var(--radius-input); font-family: inherit; font-size: 13px; color: var(--flip-deep-blue); background: var(--flip-white); }
.place-search-bar input:focus { outline: none; border-color: var(--flip-deep-blue); }

.place-results { max-height: 300px; overflow-y: auto; }
.place-result { padding: 9px 10px; border-radius: 6px; cursor: pointer; transition: background .12s; }
.place-result + .place-result { border-top: 1px solid var(--border-subtle); }
.place-result:hover, .place-result.loading { background: rgba(120, 210, 225, .2); }
.place-result-name { font-weight: 600; font-size: 13px; color: var(--flip-deep-blue); }
.place-result-addr { font-size: 12px; color: var(--fg-muted); margin-top: 2px; }

/* ── Activities card ─────────────────────────────────────── */
.activity-list { display: flex; flex-direction: column; }
.activity-row {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border-subtle);
}
.activity-row:first-child { padding-top: 0; }
.activity-row:last-child  { border-bottom: none; padding-bottom: 0; }
.activity-future { background: rgba(120, 210, 225, .08); margin: 0 -16px; padding-left: 16px; padding-right: 16px; border-radius: var(--radius-input); border-bottom-color: transparent; }
.activity-future + .activity-row { border-top: 1px solid var(--border-subtle); }
.activity-row-main { display: flex; align-items: flex-start; gap: 8px; flex: 1; min-width: 0; }
.activity-icon { font-size: 15px; flex-shrink: 0; margin-top: 1px; }
.activity-content { flex: 1; min-width: 0; }
.activity-title { font-size: 13px; font-weight: 500; color: var(--flip-deep-blue); }
.activity-badge {
  display: inline-block; font-size: 9px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .04em; padding: 1px 5px; border-radius: var(--radius-pill);
  background: var(--flip-light-blue); color: var(--flip-deep-blue); vertical-align: middle; margin-left: 4px;
}
.activity-meta { font-size: 11px; color: var(--fg-muted); margin-top: 2px; font-variant-numeric: tabular-nums; }
.activity-notes { font-size: 12px; color: var(--fg-muted); margin-top: 3px; white-space: pre-wrap; }
.activity-row-actions { display: flex; gap: 4px; flex-shrink: 0; }
/* Stage change audit rows — read-only, visually quieter */
.activity-stage-change { opacity: 0.75; }
.activity-stage-change .activity-title { font-weight: 400; color: var(--fg-muted); }
/* Email log rows rendered inside the unified Activity Log card */
a.activity-email-log {
  text-decoration: none; color: inherit; cursor: pointer;
}
a.activity-email-log:hover { background: var(--flip-light-grey); margin: 0 -16px; padding-left: 16px; padding-right: 16px; border-radius: var(--radius-input); }
a.activity-email-log .activity-title { color: var(--flip-deep-blue); }
a.activity-email-log:hover .activity-title { text-decoration: underline; }

/* ── Dashboard ───────────────────────────────────────────────── */
.dashboard { padding: 32px; max-width: 1100px; }
.dash-welcome { margin-bottom: 28px; }
.dash-welcome h2 { margin: 0; font-size: 24px; font-weight: 700; color: var(--flip-deep-blue); }

.dash-top-cards {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 2fr;
  gap: 20px;
  align-items: stretch;
}

.dash-stat-card .detail-card-body { display: flex; }
.dash-stat-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px 24px;
  gap: 6px;
}
.dash-stat-number {
  font-size: 56px;
  font-weight: 800;
  line-height: 1;
  color: var(--flip-deep-blue);
  letter-spacing: -0.02em;
}
.dash-stat-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--fg-1);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.dash-stat-sub {
  font-size: 12px;
  color: var(--fg-muted);
}

.dash-pie-body {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 16px;
}
.dash-pie-legend {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.dash-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.dash-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dash-legend-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--fg-1);
}
.dash-legend-count { font-weight: 600; color: var(--fg-1); flex-shrink: 0; }
.dash-legend-pct { font-weight: 400; color: var(--fg-muted); }

/* ── Stage Timeline ──────────────────────────────────────────── */
.stage-timeline { display: flex; flex-direction: column; }
.stage-tl-item { display: flex; gap: 12px; align-items: flex-start; }
.stage-tl-connector { display: flex; flex-direction: column; align-items: center; flex-shrink: 0; width: 14px; padding-top: 3px; }
.stage-tl-connector::before {
  content: '';
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 2px solid var(--border-subtle);
  background: var(--flip-white);
  flex-shrink: 0;
  display: block;
}
.stage-tl-line { width: 2px; flex: 1; min-height: 20px; background: var(--border-subtle); margin: 3px 0; }
.stage-tl-content { padding-bottom: 18px; flex: 1; min-width: 0; }
.stage-tl-item:last-child .stage-tl-content { padding-bottom: 0; }
.stage-tl-label { font-size: 13px; font-weight: 500; color: var(--fg-muted); line-height: 1.3; }
.stage-tl-date  { font-size: 11px; color: var(--fg-muted); margin-top: 2px; opacity: 0.8; }
.stage-tl-close { font-size: 11px; color: var(--fg-muted); margin-top: 3px; font-style: italic; }

/* past items already use the defaults above; active/won/lost override */
.stage-tl-item.tl-active .stage-tl-connector::before { border-color: var(--flip-deep-blue); background: var(--flip-deep-blue); }
.stage-tl-item.tl-active .stage-tl-label { color: var(--flip-deep-blue); font-weight: 600; }
.stage-tl-item.tl-won .stage-tl-connector::before { border-color: var(--flip-dark-green); background: var(--flip-dark-green); }
.stage-tl-item.tl-won .stage-tl-label { color: var(--flip-dark-green); font-weight: 600; }
.stage-tl-item.tl-lost .stage-tl-connector::before { border-color: var(--flip-red); background: var(--flip-red); }
.stage-tl-item.tl-lost .stage-tl-label { color: var(--flip-red); font-weight: 600; }

/* ── Timeline Edit Modal ─────────────────────────────────────── */
.tl-edit-wrap { display: flex; flex-direction: column; gap: 0; }
.tl-edit-section-head {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-muted);
  padding: 4px 0 8px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 4px;
}
.tl-edit-list { display: flex; flex-direction: column; gap: 0; margin-bottom: 16px; }
.tl-edit-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-subtle);
}
.tl-edit-row:last-child { border-bottom: none; }
.tl-edit-label {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  color: var(--fg-1);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tl-edit-badge {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 20px;
  background: var(--bg-hover);
  color: var(--fg-muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.tl-edit-input {
  flex-shrink: 0;
  width: 180px;
  font-size: 13px;
  padding: 5px 8px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  background: var(--flip-white);
  color: var(--fg-1);
}
.tl-edit-divider {
  border: none;
  border-top: 2px solid var(--border-subtle);
  margin: 8px 0 16px;
}
.tl-edit-add-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.tl-edit-select {
  flex: 1;
  min-width: 140px;
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  background: var(--flip-white);
  color: var(--fg-1);
}

/* Deals filter toolbar */
.list-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 16px; }
.list-toolbar .list-search-bar { margin-bottom: 0; }
.filter-select { padding: 7px 28px 7px 12px; border: 1px solid var(--border-subtle); border-radius: var(--radius-pill); font-family: inherit; font-size: 13px; color: var(--flip-deep-blue); background: var(--flip-white) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5'%3E%3Cpath d='M0 0l4 5 4-5z' fill='%23001f7a' opacity='.55'/%3E%3C/svg%3E") no-repeat right 11px center; appearance: none; -webkit-appearance: none; cursor: pointer; }
.filter-select:hover { border-color: var(--flip-deep-blue); }
.filter-select.active { border-color: var(--flip-deep-blue); background-color: var(--flip-light-blue); font-weight: 500; }
.filter-count { font-size: 12px; color: var(--fg-muted); margin-left: 4px; }
.ms-filter { position: relative; }
.ms-panel { position: absolute; top: calc(100% + 4px); left: 0; z-index: 50; min-width: 220px; max-height: 340px; overflow-y: auto; background: var(--flip-white); border: 1px solid var(--border-subtle); border-radius: 12px; box-shadow: 0 8px 24px rgba(0, 31, 122, .12); padding: 6px; }
.ms-panel[hidden] { display: none; }
.ms-actions { display: flex; justify-content: space-between; gap: 8px; padding: 4px 6px 8px; margin-bottom: 4px; border-bottom: 1px solid var(--border-subtle); }
.ms-actions button { background: none; border: 0; padding: 2px 0; font-family: inherit; font-size: 12px; font-weight: 500; color: var(--flip-deep-blue); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.ms-opt { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; font-size: 13px; color: var(--flip-deep-blue); cursor: pointer; white-space: nowrap; }
.ms-opt:hover { background: var(--flip-light-grey); }
.ms-opt input { accent-color: var(--flip-deep-blue); margin: 0; }
.ms-none { color: var(--fg-muted); font-style: italic; }
@media (max-width: 1100px) {
  .email-layout { grid-template-columns: 300px 1fr; }
  .email-detail { padding: 18px 20px; }
  .email-msg-body { padding-left: 16px; }
}

/* Email auto-tags */
.email-tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 10px; }
.email-tabs button { border: 1px solid var(--border-subtle); background: var(--flip-white); border-radius: var(--radius-pill); padding: 4px 10px; font-family: inherit; font-size: 12px; color: var(--flip-deep-blue); cursor: pointer; }
.email-tabs button span { color: var(--fg-muted); margin-left: 2px; font-variant-numeric: tabular-nums; }
.email-tabs button.active { background: var(--flip-deep-blue); border-color: var(--flip-deep-blue); color: var(--flip-white); }
.email-tabs button.active span { color: rgba(255,255,255,.75); }
.email-tag { display: inline-block; margin-top: 6px; font-size: 10.5px; font-weight: 500; padding: 1px 8px; border-radius: var(--radius-pill); border: 1px solid transparent; background: var(--flip-light-grey); color: var(--fg-muted); }
.email-tag.tag-b2b-sales { background: #E3E9FF; color: var(--flip-deep-blue); }
.email-tag.tag-e-comm    { background: #FFF1CC; color: #8a5a00; }
.email-tag.tag-events-sponsoring { background: var(--flip-lime); color: #5b5200; }
.email-tag.tag-others    { background: var(--flip-light-grey); color: var(--fg-muted); }
.email-tag.tag-unsure    { background: var(--flip-light-pink); color: var(--flip-purple); }
.email-tag.pending { background: transparent; border: 1px dashed var(--border-subtle); color: var(--fg-muted); }
.email-item.active .email-tag { box-shadow: 0 0 0 1px rgba(255,255,255,.6); }
.email-tag-picker { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: -6px 0 16px; }
.email-tag-picker .email-tag { margin: 0; cursor: pointer; font-family: inherit; font-size: 12px; padding: 3px 10px; opacity: .55; }
.email-tag-picker .email-tag:hover { opacity: .85; }
.email-tag-picker .email-tag.selected { opacity: 1; border-color: currentColor; }
.email-tag-reason { font-size: 11.5px; color: var(--fg-muted); font-style: italic; }
.rule-offer { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: -8px 0 16px; padding: 8px 12px; background: #F3F6FF; border: 1px solid #DCE3FA; border-radius: 10px; font-size: 12.5px; }
.rule-offer .btn-sm { font-size: 12px; }
.rule-offer-no { background: none; border: 0; font-family: inherit; font-size: 12px; color: var(--fg-muted); cursor: pointer; text-decoration: underline; }
.rules-list { display: flex; flex-direction: column; gap: 8px; }
.rules-row { display: flex; align-items: center; gap: 10px; }
.rules-row .email-tag { margin: 0; }
.rules-row .btn-danger { margin-left: auto; }
.rules-match { font-weight: 500; }
.email-load-more { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 16px; }
.email-load-more span { font-size: 11.5px; color: var(--fg-muted); }
.email-item-to { font-weight: 400; color: #86868b; }
.email-item-more { font-weight: 400; color: #86868b; font-size: 12.5px; }
.email-item.active .email-item-to, .email-item.active .email-item-more { color: rgba(255,255,255,.8); }

/* Company directory card */
.dir-group + .dir-group { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border-subtle); }
.dir-group-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--fg-muted); margin-bottom: 6px; }
.dir-row { padding: 6px 0; }
.dir-row + .dir-row { border-top: 1px dashed var(--border-subtle); }
.dir-name { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; min-width: 0; }
.dir-name .dir-meta { font-weight: 400; }
.dir-email { font-size: 12px; color: var(--flip-deep-blue); overflow-wrap: anywhere; }
.dir-meta { font-size: 11px; color: var(--fg-muted); }
.dir-empty { font-size: 12px; color: var(--fg-muted); }
.dir-edit { background: none; border: 0; padding: 0 2px; cursor: pointer; color: var(--fg-muted); font-size: 13px; line-height: 1; }
.dir-edit:hover { color: var(--flip-deep-blue); }
.dir-name-input { font: inherit; font-size: 13px; padding: 2px 6px; border: 1px solid var(--flip-deep-blue); border-radius: var(--radius-input); width: 100%; }
.dir-add { margin-top: 4px; font-size: 11px; padding: 2px 8px; }
.dir-role { margin-left: auto; flex-shrink: 0; font-family: inherit; font-size: 11px; padding: 1px 4px; border: 1px solid var(--border-subtle); border-radius: var(--radius-pill); background: var(--flip-white); color: var(--fg-muted); cursor: pointer; }
.dir-role.primary { background: var(--flip-deep-blue); border-color: var(--flip-deep-blue); color: var(--flip-white); }
.dir-role.secondary { background: #E3E9FF; border-color: #E3E9FF; color: var(--flip-deep-blue); }
.dir-more[hidden] { display: none; }
.dir-more > .dir-row:first-child { border-top: 1px dashed var(--border-subtle); }
.dir-toggle { background: none; border: 0; padding: 6px 0 0; font-family: inherit; font-size: 12px; font-weight: 500; color: var(--flip-blue); cursor: pointer; }
.dir-toggle:hover { text-decoration: underline; }

/* ── Emails: account view (B2B Sales) — conversations grouped by customer, latest exchange first ── */
.acct { border-bottom: 1px solid var(--border-subtle); }
.acct.open { background: #F7F9FF; }
.acct-head { display: flex; align-items: flex-start; gap: 8px; width: 100%; padding: 12px 14px 12px 6px; border: 0; background: none; font: inherit; text-align: left; cursor: pointer; color: #1d1d1f; }
.acct-head:hover { background: var(--flip-light-grey); }
.acct-head:focus-visible { outline: 2px solid var(--flip-blue); outline-offset: -2px; }
.acct-head .avatar { flex-shrink: 0; }
.acct.unread > .acct-head .email-item-dot { background: var(--flip-blue); }
.acct-main { display: block; flex: 1; min-width: 0; }
.acct-top { display: flex; align-items: center; gap: 6px; min-width: 0; }
.acct-name { font-size: 14.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.acct-date { margin-left: auto; padding-left: 8px; font-size: 13px; color: #86868b; white-space: nowrap; font-variant-numeric: tabular-nums; }
.acct-subject { display: block; margin-top: 2px; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acct-snippet { display: block; margin-top: 2px; font-size: 13px; color: #86868b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acct-people { display: block; margin-top: 4px; font-size: 12px; color: var(--fg-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acct-meta { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 12px; color: var(--fg-muted); min-width: 0; }
.acct-domain { margin-left: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.acct-chev { display: inline-flex; color: var(--flip-blue); transition: transform .15s ease; }
.acct.open .acct-chev { transform: rotate(90deg); }
.acct-threads { padding: 0 0 6px 36px; }
.acct-threads .email-item { padding-top: 8px; padding-bottom: 8px; border-radius: 8px; }
.acct-threads .email-item::after { left: 16px; }
.acct-threads .email-item:last-child::after { border-bottom: 0; }
.acct-threads .email-item-count { color: var(--fg-muted); font-size: 12.5px; }
.acct-thread-from { margin-top: 1px; font-size: 12.5px; color: #86868b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acct-threads .email-item.active .acct-thread-from { color: var(--flip-white); opacity: .85; }
.acct-more { padding: 6px 16px 4px 22px; font-size: 12px; color: var(--fg-muted); }

/* Conversation pane (account card + thread), after the mockup */
.email-detail { background: #F5F6FA; }
.conv-account { display: flex; align-items: center; gap: 16px; background: var(--flip-white); border: 1px solid var(--border-subtle); border-radius: 14px; padding: 18px 22px; margin-bottom: 26px; }
.conv-account .avatar { font-size: 17px; }
.conv-account-main { flex: 1; min-width: 0; }
.conv-account-name { font-size: 18px; font-weight: 700; letter-spacing: var(--tracking-tight); }
.conv-account-name a { color: inherit; text-decoration: none; }
.conv-account-name a:hover { text-decoration: underline; }
.conv-account-sub { font-size: 13px; color: var(--fg-muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-account-stats { font-size: 13px; font-weight: 600; color: var(--fg-muted); white-space: nowrap; }
.conv-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 10px; }
.conv-head h2 { margin: 0; font-size: 26px; line-height: 1.2; letter-spacing: var(--tracking-tight); }
.conv-sub { font-size: 13px; color: var(--fg-muted); margin-top: 6px; }
.conv-reply-btn { flex-shrink: 0; padding: 10px 22px; }
.conv-msg { background: var(--flip-white); border: 1px solid var(--border-subtle); border-radius: 14px; padding: 18px 22px; margin-bottom: 12px; }
.conv-msg-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 8px; }
.conv-msg-from { font-weight: 700; font-size: 14px; }
.conv-msg-date { font-size: 12.5px; font-weight: 600; color: var(--fg-muted); white-space: nowrap; }
.conv-msg-body { white-space: pre-wrap; font-size: 14px; line-height: 1.6; color: #1d2a4d; overflow-wrap: anywhere; }
.conv-msg-body[hidden] { display: none; }
.conv-quoted-toggle { margin-top: 8px; background: none; border: 0; padding: 0; font-family: inherit; font-size: 12px; color: var(--flip-blue); cursor: pointer; }
.conv-quoted-toggle:hover { text-decoration: underline; }
.reply-box { background: var(--flip-white); border: 1px solid var(--flip-deep-blue); border-radius: 14px; padding: 14px 18px; margin-bottom: 16px; display: flex; flex-direction: column; gap: 8px; }
.reply-box label { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--fg-muted); }
.reply-box input { flex: 1; font-family: inherit; font-size: 13px; padding: 5px 8px; border: 1px solid var(--border-subtle); border-radius: var(--radius-input); color: var(--flip-deep-blue); }
.reply-box textarea { font-family: inherit; font-size: 14px; line-height: 1.5; padding: 10px; border: 1px solid var(--border-subtle); border-radius: 8px; resize: vertical; color: #1d2a4d; }
.reply-actions { display: flex; align-items: center; gap: 8px; }
.reply-subject { flex: 1; font-size: 12px; color: var(--fg-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Verified (in CRM) badge + conversation header contact/deal + Add to CRM form */
.crm-verified { display: inline-flex; color: var(--flip-blue); margin-left: 5px; vertical-align: -2px; flex-shrink: 0; }
.conv-account-name { display: flex; align-items: center; }
.conv-account-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 6px; white-space: normal; }
.conv-contact { font-size: 13px; color: var(--flip-deep-blue); text-decoration: none; font-weight: 500; }
.conv-contact::before { content: '👤 '; font-size: 11px; }
a.conv-contact:hover { text-decoration: underline; }
.conv-contact.unknown { color: var(--fg-muted); font-weight: 400; }
.conv-more { font-size: 12px; color: var(--fg-muted); }
.conv-deal { text-decoration: none; }
.conv-deal .pill { font-size: 11.5px; padding: 3px 10px; }
.conv-account-side { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.conv-add-crm { white-space: nowrap; }
.crm-ai-status { font-size: 12.5px; color: var(--fg-muted); background: #F3F6FF; border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; }
.crm-form fieldset { border: 1px solid var(--border-subtle); border-radius: 10px; padding: 10px 14px 12px; margin: 0 0 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.crm-form legend { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--fg-muted); padding: 0 4px; }
.crm-f { display: flex; flex-direction: column; gap: 3px; font-size: 11.5px; color: var(--fg-muted); }
.crm-f.wide { grid-column: 1 / -1; }
.crm-f input, .crm-f select { font-family: inherit; font-size: 13px; padding: 6px 8px; border: 1px solid var(--border-subtle); border-radius: var(--radius-input); color: var(--flip-deep-blue); background: var(--flip-white); }
.crm-check { display: inline-flex; align-items: center; gap: 6px; text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--flip-deep-blue); }
.crm-existing { font-size: 13px; margin-bottom: 12px; display: flex; align-items: center; }
.location-head-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.place-result.picked { border-color: var(--flip-blue); background: #EEF6FF; }
.crm-place-picked { font-style: normal; color: var(--flip-dark-green); margin-left: 6px; }
#co-place .place-search-bar, #place-modal .place-search-bar { display: flex; gap: 6px; }
#co-place .place-q, #place-modal .place-q { flex: 1; font-family: inherit; font-size: 13px; padding: 6px 8px; border: 1px solid var(--border-subtle); border-radius: var(--radius-input); }
#co-place .place-results { max-height: 180px; overflow-y: auto; }

/* ── Events ─────────────────────────────────────────────── */
/* Status colours (pills, inline selects, calendar chips) */
.pill.stage-request,        .stage-select.stage-request,        .cal-ev.stage-request        { background-color: var(--flip-light-blue); color: var(--flip-deep-blue); }
.pill.stage-in-discussion,  .stage-select.stage-in-discussion,  .cal-ev.stage-in-discussion  { background-color: var(--flip-yellow); color: var(--flip-deep-blue); }
.pill.stage-confirmed,      .stage-select.stage-confirmed,      .cal-ev.stage-confirmed      { background-color: var(--flip-lime); color: var(--flip-deep-blue); }
.pill.stage-preparing,      .stage-select.stage-preparing,      .cal-ev.stage-preparing      { background-color: var(--flip-light-pink); color: var(--flip-purple); }
.pill.stage-debrief,        .stage-select.stage-debrief,        .cal-ev.stage-debrief        { background-color: var(--flip-light-pink); color: var(--flip-purple); }
.pill.stage-done,           .stage-select.stage-done,           .cal-ev.stage-done           { background-color: var(--flip-green); color: var(--flip-white); }
.pill.stage-declined,       .stage-select.stage-declined,       .cal-ev.stage-declined       { background-color: var(--flip-black); color: var(--flip-white); }
.pill.stage-cancelled,      .stage-select.stage-cancelled,      .cal-ev.stage-cancelled      { background-color: var(--flip-light-grey); color: var(--fg-muted); }

.ev-card-foot { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: 6px; }
.ev-section-title { margin: 0 0 10px; font-size: 13px; color: var(--flip-deep-blue); }
.ev-venue { font-weight: 600; color: var(--flip-deep-blue); margin-bottom: 4px; }
.ev-company-link { text-decoration: none; color: var(--flip-deep-blue); font-weight: 500; display: inline-flex; align-items: center; gap: 4px; }
.ev-company-sub { font-size: 11.5px; color: var(--fg-muted); margin: 4px 0 0 32px; }
.detail-card-actions { display: inline-flex; gap: 6px; }

/* Calendar */
.cal-layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; align-items: start; }
.cal { background: var(--flip-white); border: 1px solid var(--border-subtle); border-radius: var(--radius-card); padding: 12px; }
.cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.cal-head h3 { margin: 0 auto 0 4px; font-size: 16px; color: var(--flip-deep-blue); order: -1; min-width: 160px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--border-subtle); border-left: 1px solid var(--border-subtle); }
.cal-dow { font-size: 11px; color: var(--fg-muted); padding: 6px; border-right: 1px solid var(--border-subtle); border-bottom: 1px solid var(--border-subtle); }
.cal-day { min-height: 96px; padding: 4px; border-right: 1px solid var(--border-subtle); border-bottom: 1px solid var(--border-subtle); display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cal-day.other { background: var(--flip-light-grey); opacity: .65; }
.cal-num { font-size: 11px; color: var(--fg-muted); padding: 1px 3px; align-self: flex-start; border-radius: 10px; }
.cal-day.today .cal-num { background: var(--flip-deep-blue); color: var(--flip-white); }
.cal-ev { display: block; width: 100%; border: 0; border-radius: 4px; padding: 2px 6px; font: inherit; font-size: 11px; font-weight: 500; text-align: left; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-ev.closed { opacity: .55; text-decoration: line-through; }
.cal-more { font-size: 10.5px; color: var(--fg-muted); padding: 0 4px; }
.cal-agenda-row { padding: 8px 0; border-bottom: 1px solid var(--border-subtle); cursor: pointer; }
.cal-agenda-row:last-child { border-bottom: 0; }
.cal-agenda-row:hover .cal-agenda-name { text-decoration: underline; }
.cal-agenda-date { font-size: 11px; color: var(--fg-muted); }
.cal-agenda-name { font-weight: 600; color: var(--flip-deep-blue); font-size: 13px; margin: 2px 0 4px; }
.cal-agenda-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 11px; color: var(--fg-muted); }
@media (max-width: 1100px) { .cal-layout { grid-template-columns: 1fr; } }

/* Emails: event on a conversation */
.conv-event { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; color: var(--flip-deep-blue); font-size: 12px; font-weight: 500; }
.conv-event-suggest { font-size: 12px; color: var(--fg-muted); display: inline-flex; align-items: center; gap: 6px; }
.email-item-event { display: inline-block; font-size: 10.5px; color: var(--flip-deep-blue); background: var(--flip-light-pink); border-radius: var(--radius-pill); padding: 1px 7px; margin-top: 4px; }

.ev-debrief.todo { border: 1.5px solid var(--flip-purple); }

.dash-stat-link { cursor: pointer; transition: border-color .12s ease; }
.dash-stat-link:hover { border-color: var(--flip-deep-blue); }
@media (max-width: 1100px) { .dash-top-cards { grid-template-columns: 1fr 1fr; } }

/* Deals: Hot / At risk quick filters (toggle chips, several = any of them) */
.tag-filters { display: inline-flex; gap: 6px; }
.tag-filter { display: inline-flex; align-items: center; gap: 7px; padding: 6px 7px 6px 12px; border: 1px solid var(--border-subtle); border-radius: var(--radius-pill); background: var(--flip-white); font: inherit; font-size: 13px; color: var(--flip-deep-blue); cursor: pointer; transition: background .12s ease, border-color .12s ease, color .12s ease; }
.tag-filter:hover { border-color: var(--flip-deep-blue); }
.tag-filter-n { min-width: 20px; padding: 1px 6px; border-radius: var(--radius-pill); background: var(--flip-light-grey); font-size: 11px; font-weight: 600; text-align: center; }
.tag-filter.hot.on { background: var(--flip-yellow); border-color: var(--flip-yellow); font-weight: 500; }
.tag-filter.risk.on { background: #FDE2E1; border-color: var(--flip-red); color: var(--flip-red); font-weight: 500; }
.tag-filter.on .tag-filter-n { background: rgba(255, 255, 255, .7); }
.tag-filter:focus-visible { outline: 2px solid var(--flip-deep-blue); outline-offset: 1px; }

.acct-others { display: block; width: 100%; border: 0; background: none; font: inherit; text-align: left; cursor: pointer; color: var(--flip-deep-blue); }
.acct-others:hover { text-decoration: underline; }

.conv-filed { font-size: 11.5px; color: var(--fg-muted); text-align: right; }
.conv-filed .conv-quoted-toggle { margin: 0; }

/* Gmail write-back */
.gmail-sync-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; padding: 8px 10px; border-radius: 10px; background: var(--flip-light-blue); color: var(--flip-deep-blue); font-size: 12px; }
.gmail-sync-banner[hidden] { display: none; }
.conv-head-actions { display: inline-flex; gap: 8px; align-items: center; flex-shrink: 0; }

/* Email signatures: collapsed behind "•••" like Gmail */
.conv-msg-more { display: flex; gap: 14px; align-items: center; margin-top: 6px; }
.conv-msg-more .conv-quoted-toggle { margin-top: 0; }
.conv-quoted-toggle[data-show="sig"] { padding: 0 8px; border-radius: 8px; background: var(--flip-light-grey); color: var(--fg-muted); font-size: 13px; letter-spacing: 1px; line-height: 18px; text-decoration: none; }
.conv-quoted-toggle[data-show="sig"]:hover { background: #E3E7EF; text-decoration: none; }
.conv-msg-sig { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border-subtle); font-size: 12.5px; color: var(--fg-muted); }
.conv-quoted-toggle[hidden] { display: none; }
