/* crm-core: own small stylesheet, no framework. --primary comes from /branding.css. */
:root {
  --primary: #2563eb;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --ok: #047857;
  --ok-bg: #ecfdf5;
  --radius: 10px;
  --sidebar: 240px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  line-height: 1.5;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); font-size: 15px; }
a { color: var(--primary); }
h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 .75rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Layout */
.content { padding: 2rem; max-width: 1100px; }
body.with-nav .content { margin-left: var(--sidebar); }
body.centered { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 1rem; }
body.centered .content { padding: 0; width: 100%; max-width: 400px; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar);
  display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 1.25rem .75rem; overflow-y: auto; z-index: 20;
}
.sidebar-brand { padding: 0 .5rem 1.25rem; }
.brand { display: inline-flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.brand-logo { height: 28px; width: auto; }
.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-list a {
  display: block; padding: .55rem .75rem; border-radius: 8px;
  color: var(--text); text-decoration: none; font-weight: 500;
}
.nav-list a:hover { background: var(--bg); }
.nav-list a.active { background: color-mix(in srgb, var(--primary) 12%, transparent); color: var(--primary); }
.nav-sep { margin-top: .75rem; padding-top: .75rem; border-top: 1px solid var(--border); }
.sidebar-user { margin-top: auto; padding: 1rem .75rem 0; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: .25rem; }
.sidebar-user .who { font-weight: 600; overflow-wrap: anywhere; }

.topbar { display: none; }

/* Demo deployments: a slim strip at the top of the page content, in normal flow, so nobody expects
   real email and it never covers anything. */
.demo-banner {
  display: block; margin: 0 0 1rem; padding: .35rem .85rem; text-align: center;
  background: #fef3c7; color: #78350f; border: 1px solid #f59e0b; border-radius: var(--radius);
  font-size: .85rem; font-weight: 600;
}

/* Components */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.5rem; margin-bottom: 1.25rem; }
.auth-card .auth-brand { margin-bottom: 1rem; }
.form-card { max-width: 480px; }
.empty-state { text-align: center; padding: 3rem 1.5rem; }
.empty-title { font-size: 1.15rem; font-weight: 600; margin: 0 0 .25rem; }
.page-head { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.below { margin-top: 1rem; text-align: center; }

.field { margin-bottom: 1rem; }
.field label { display: block; font-weight: 600; margin-bottom: .3rem; }
input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="datetime-local"], textarea, select {
  width: 100%; font: inherit; padding: .6rem .7rem;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text);
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }
.field-error { color: var(--danger); margin: .3rem 0 0; font-size: .9rem; }

.btn {
  display: inline-block; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  padding: .55rem 1rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text, #fff); }
.btn-primary:hover { background: var(--primary); filter: brightness(.92); }
.btn-block { width: 100%; }
.btn-small { padding: .3rem .65rem; font-size: .85rem; }
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--primary); cursor: pointer; text-align: left; }

.flash { padding: .75rem 1rem; border-radius: 8px; margin: 0 0 1rem; }
.flash-error { background: var(--danger-bg); color: var(--danger); }
.flash-ok { background: var(--ok-bg); color: var(--ok); }

.tiles { list-style: none; padding: 0; margin: 1.5rem 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1rem; }
.tile { display: block; padding: 1.25rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); color: var(--text); text-decoration: none; font-weight: 600; }
.tile:hover { border-color: var(--primary); }

.table-card { padding: 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .75rem 1rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.table tr:last-child td { border-bottom: 0; }
form.inline { display: flex; gap: .4rem; align-items: center; }
form.inline select { width: auto; padding: .3rem .5rem; }
.actions { display: flex; flex-wrap: wrap; gap: .4rem; }
.badge { font-size: .75rem; background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: 0 .45rem; color: var(--muted); }
.status { font-size: .85rem; font-weight: 600; }
.status-on { color: var(--ok); }
.status-off { color: var(--muted); }
.label { font-weight: 600; margin-bottom: .25rem; }
.secret { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.2rem; padding: .75rem 1rem; background: var(--bg); border: 1px dashed var(--border); border-radius: 8px; overflow-wrap: anywhere; user-select: all; }

/* Phone and small tablet: the sidebar becomes a slide-in drawer behind a top bar. */
@media (max-width: 800px) {
  body.with-nav .content { margin-left: 0; padding: 1.25rem 1rem; }
  .topbar {
    display: flex; align-items: center; gap: .75rem; position: sticky; top: 0; z-index: 30;
    background: var(--surface); border-bottom: 1px solid var(--border); padding: .6rem 1rem;
  }
  .nav-toggle { display: inline-flex; align-items: center; gap: .5rem; font: inherit; font-weight: 600; background: none; border: 1px solid var(--border); border-radius: 8px; padding: .35rem .6rem; color: var(--text); cursor: pointer; }
  .nav-toggle-bars, .nav-toggle-bars::before, .nav-toggle-bars::after { display: block; width: 16px; height: 2px; background: currentColor; position: relative; }
  .nav-toggle-bars::before, .nav-toggle-bars::after { content: ""; position: absolute; left: 0; }
  .nav-toggle-bars::before { top: -5px; }
  .nav-toggle-bars::after { top: 5px; }
  /* visibility keeps the closed drawer's links out of the tab order and the accessibility tree. */
  .sidebar { top: 53px; transform: translateX(-100%); visibility: hidden; transition: transform .2s ease, visibility .2s; box-shadow: var(--shadow); }
  .sidebar-brand { display: none; }
  body.nav-open .sidebar { transform: none; visibility: visible; }

  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border-bottom: 1px solid var(--border); padding: .5rem 0; }
  .table td { border: 0; padding: .35rem 1rem; }
  .table td::before { content: attr(data-label); display: block; font-size: .75rem; text-transform: uppercase; color: var(--muted); }
}

/* Contacts, companies, custom fields and import */
input[type="search"], input[type="date"], input[type="file"], textarea {
  width: 100%; font: inherit; padding: .6rem .7rem;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text);
}
textarea { resize: vertical; }
textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.has-error textarea { border-color: var(--danger); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); filter: brightness(.92); }
.btn-danger-outline { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.form-card.wide { max-width: 720px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.filters { display: flex; flex-wrap: wrap; gap: .75rem 1rem; align-items: flex-end; padding: 1rem 1.25rem; }
.filters .field { margin: 0; min-width: 160px; }
.filters .grow { flex: 1 1 260px; }
.filter-buttons { display: flex; gap: .4rem; }
.pagination { display: flex; gap: .75rem; align-items: center; justify-content: center; margin: 0 0 1.25rem; }
.tag { display: inline-block; font-size: .8rem; font-weight: 600; padding: .05rem .5rem; border-radius: 999px; background: color-mix(in srgb, var(--primary) 10%, transparent); color: var(--primary); text-decoration: none; margin: 0 .15rem .15rem 0; }
.tag-list { margin: -.25rem 0 1rem; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 1.25rem; align-items: start; }
.details { margin: 0; display: grid; gap: .6rem; }
.details div { display: grid; grid-template-columns: 9rem minmax(0, 1fr); gap: .75rem; }
.details dt { color: var(--muted); }
.details dd { margin: 0; overflow-wrap: anywhere; }
.timeline { min-height: 12rem; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.tabs a { padding: .5rem .9rem; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }
.plain { list-style: none; padding: 0; margin: 0 0 1rem; }
.list-lines li { padding: .5rem 0; border-bottom: 1px solid var(--border); }
.list-lines li:last-child { border-bottom: 0; }
.stats { list-style: none; padding: 0; margin: 0 0 .5rem; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.stats .card { margin: 0; }
.stat { display: block; font-size: 1.8rem; font-weight: 700; }
.table.mapping select { min-width: 12rem; }
.scroll-x .table td, .scroll-x .table th { white-space: nowrap; }

@media (max-width: 800px) {
  .grid-2, .detail-grid, .stats { grid-template-columns: 1fr; }
  .details div { grid-template-columns: 1fr; gap: 0; }
  .filters .field, .filter-buttons { flex: 1 1 100%; }
  .scroll-x .table td, .scroll-x .table th { white-space: normal; }
  .table.mapping select { min-width: 0; }
}

/* Email (INT-117): status colours, plain-text body and the compose preview. */
.status-bounced, .status-complained, .status-failed { color: var(--danger); }
.status-delivered, .status-sent { color: var(--ok); }
.status-queued, .status-unknown { color: var(--muted); }
.mail-text { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; margin: 0; }
.mail-preview { border: 1px solid var(--border); border-radius: 8px; padding: 0 1rem; overflow-wrap: anywhere; }
.form-card form.inline { margin-bottom: 1rem; }

/* Pipeline board and settings */
.pipeline-page .content { max-width: none; }
.board { position: relative; display: flex; gap: 1rem; align-items: flex-start; overflow-x: auto; padding-bottom: 1rem; }
.column { flex: 1 0 220px; max-width: 320px; background: color-mix(in srgb, var(--border) 45%, var(--bg)); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem; }
.column.drop-target { outline: 2px dashed var(--primary); outline-offset: -2px; }
.column-head { margin-bottom: .6rem; }
.column-head h2 { margin: 0; font-size: 1rem; }
.column-won .column-head h2 { color: var(--ok); }
.column-lost .column-head h2 { color: var(--danger); }
.column-sum { color: var(--muted); font-size: .85rem; }
.cards { list-style: none; margin: 0; padding: 0; min-height: 3.5rem; display: grid; gap: .5rem; align-content: start; }
.deal-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); padding: .6rem .7rem; cursor: grab; }
.deal-card.dragging { opacity: .45; }
.deal-title { display: block; font-weight: 600; text-decoration: none; overflow-wrap: anywhere; }
.deal-line { display: flex; justify-content: space-between; gap: .5rem; align-items: baseline; margin-top: .25rem; }
.deal-value { font-weight: 600; }
.move-form { display: flex; gap: .4rem; margin-top: .5rem; }
.move-form select { padding: .3rem .4rem; font-size: .85rem; }
.board.js .move-submit { display: none; }
.column-more { margin: .5rem 0 0; }
.board-error { color: var(--danger); font-weight: 600; }
.status-pill { font-size: .75rem; font-weight: 700; padding: .1rem .55rem; border-radius: 999px; vertical-align: middle; background: var(--bg); border: 1px solid var(--border); }
.status-won { color: var(--ok); background: var(--ok-bg); border-color: transparent; }
.status-lost { color: var(--danger); background: var(--danger-bg); border-color: transparent; }
.btn-won { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-won:hover { background: var(--ok); filter: brightness(.92); }
.btn-lost { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.pipeline-head { display: flex; flex-wrap: wrap; gap: .75rem; justify-content: space-between; align-items: center; margin-bottom: .75rem; }
.pipeline-head h2 { margin: 0; }
.inline-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.inline-row input { width: auto; flex: 1 1 200px; }
.stage-list { margin-bottom: 1rem; }
.stage-row { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: flex-end; justify-content: space-between; padding: .75rem 0; border-bottom: 1px solid var(--border); }
.stage-edit { display: flex; flex-wrap: wrap; gap: .5rem .75rem; align-items: flex-end; }
.stage-edit .field { margin: 0; }
.stage-edit input[type="text"] { width: 12rem; }
.stage-edit input[inputmode="numeric"] { width: 5rem; }
.stage-edit select { width: auto; }
.stage-new { padding-top: .75rem; }
.stage-actions form { display: inline; }
@media (max-width: 800px) {
  .column { flex-basis: 78vw; }
  .stage-edit input[type="text"] { width: 100%; }
  .stage-edit .field { flex: 1 1 100%; }
}

/* Tasks, notes and the timeline (INT-116) */
textarea { resize: vertical; }
.note-form, .quick-task { margin-bottom: 1rem; }
.note-form label, .quick-task label:not(.visually-hidden) { display: block; font-weight: 600; margin-bottom: .3rem; }
.note-form textarea { margin-bottom: .5rem; }
.quick-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.quick-row input[type="text"] { flex: 1 1 200px; width: auto; }
.quick-row input[type="date"] { flex: 0 1 11rem; width: auto; }
.tl { list-style: none; margin: 1rem 0; padding: 0 0 0 1rem; border-left: 2px solid var(--border); }
.tl-item { position: relative; padding: 0 0 1rem .5rem; }
.tl-item::before { content: ""; position: absolute; left: -1.4rem; top: .35rem; width: .65rem; height: .65rem; border-radius: 50%; background: var(--surface); border: 2px solid var(--primary); }
.tl-task_done::before { border-color: var(--ok); background: var(--ok); }
.tl-stage_change::before { border-color: var(--muted); }
.tl-head { display: flex; flex-wrap: wrap; gap: .25rem .75rem; align-items: baseline; }
.tl-kind { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.note-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.inline-action { margin-top: .35rem; }
.task-row { display: flex; gap: 1rem; align-items: center; justify-content: space-between; }
.task-main { min-width: 0; overflow-wrap: anywhere; }
.task-title { font-weight: 600; }
.tasks-overdue h2 { color: var(--danger); }
.tasks-done .task-title { color: var(--muted); text-decoration: line-through; }
.tasks-section h2 { margin-top: 0; }
/* Forms (INT-118): builder tweaks and the public page (hosted or inside an iframe). */
.check-row { display: flex; align-items: center; gap: .5rem; }
.check-row label { margin: 0; font-weight: 500; }
.check-row input[type="checkbox"], .consent input[type="checkbox"] { width: 1.1rem; height: 1.1rem; flex: none; }
textarea[readonly], input[readonly] { background: var(--bg); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; }
.answer { white-space: pre-wrap; }
.public-form-page { background: transparent; }
.public-form { max-width: 560px; margin: 0 auto; padding: 1.25rem 1rem 2rem; }
.public-form-head { display: flex; align-items: center; gap: .5rem; margin-bottom: 1rem; color: var(--muted); font-weight: 600; }
.public-form .brand-logo { height: 24px; }
.public-form input[type="tel"], .public-form textarea { width: 100%; }
input[type="tel"] { font: inherit; padding: .6rem .7rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
.public-form .req { color: var(--danger); }
.public-form .consent .check { display: flex; gap: .6rem; align-items: flex-start; font-weight: 500; }
.public-thanks { padding: 1.5rem 0; }
.success-message { white-space: pre-line; overflow-wrap: anywhere; }
/* Honeypot: off-screen rather than display:none, which some bots skip. */
.hp { position: absolute; left: -10000px; top: auto; width: 1px; height: 1px; overflow: hidden; }

/* Settings hub, branding and modules (INT-120) */
.hub { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; margin: 1rem 0 1.5rem; }
.hub-card { display: flex; flex-direction: column; gap: .35rem; height: 100%; margin: 0; text-decoration: none; color: var(--text); }
.hub-card:hover, .hub-card:focus-visible { border-color: var(--primary); }
.hub-card strong { color: var(--primary); }
.branding-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.color-row { display: flex; gap: .5rem; align-items: center; }
.color-row input[type="color"] { width: 3rem; height: 2.5rem; padding: 0; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); flex: none; }
.color-row input[type="text"] { flex: 1 1 auto; }
.field + .field-hint { margin: -.6rem 0 1.25rem; }
.field .field-hint { margin: .4rem 0 0; }
.logo-remove { margin-top: 1rem; }
.preview { border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; background: var(--bg); }
.preview-brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; margin-bottom: 1rem; }
.preview-brand .brand-logo { max-height: 2rem; max-width: 8rem; }
.preview-item { border-left: 3px solid var(--primary); padding: .35rem .75rem; font-weight: 600; color: var(--primary); background: var(--surface); margin: 0 0 1rem; }
.module-list { margin: 0 0 1.25rem; }
.module-row { padding: .75rem 0; border-bottom: 1px solid var(--border); }
.module-row:last-child { border-bottom: 0; }
.check { display: flex; gap: .75rem; align-items: flex-start; cursor: pointer; }
.check input { width: 1.2rem; height: 1.2rem; margin-top: .15rem; flex: none; }
.check input:disabled + span { opacity: .7; }
.block { display: block; }
@media (max-width: 800px) {
  .branding-grid { grid-template-columns: 1fr; }
}

/* Automations (INT-119) */
.toggle { min-width: 4.5rem; font-weight: 600; }
.toggle-on { color: var(--ok); background: var(--ok-bg); border-color: transparent; }
.toggle-off { color: var(--muted); }
.flow-list { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: .5rem; }
.flow-list li { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem; padding: .65rem .8rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); position: relative; }
.flow-list li + li::before { content: ""; position: absolute; left: 1.45rem; top: calc(-.5rem - 1px); height: .5rem; border-left: 2px solid var(--border); }
.flow-trigger { border-left: 4px solid var(--primary) !important; background: var(--bg) !important; }
.flow-no { flex: none; width: 1.6rem; height: 1.6rem; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; background: var(--bg); border: 1px solid var(--border); font-weight: 700; font-size: .85rem; }
.flow-text { flex: 1 1 14rem; min-width: 0; overflow-wrap: anywhere; }
.flow-kind { display: block; font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.flow-list .actions { margin: 0; }
.add-step { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; border-top: 1px solid var(--border); padding-top: 1rem; }
.add-step .field { margin: 0; flex: 1 1 14rem; }
.run-status.run-done { color: var(--ok); }
.run-status.run-failed { color: var(--danger); }
.run-status.run-pending, .run-status.run-running, .run-status.run-waiting { color: var(--primary); }
.run-status.run-cancelled { color: var(--muted); }
.run-log { list-style: none; margin: 0; padding: 0; }
.run-log li { display: flex; flex-wrap: wrap; gap: .25rem .6rem; align-items: baseline; padding: .5rem 0; border-bottom: 1px solid var(--border); }
.run-log li:last-child { border-bottom: 0; }
.run-log .log-message { flex: 1 1 16rem; min-width: 0; overflow-wrap: anywhere; }
.run-log .log-error .log-message { color: var(--danger); }
.run-log time { flex: none; min-width: 7.5rem; }
.field[hidden] { display: none; }
