/*
 * Zinform CRM web: the Zinform 7 desktop look (values and sources in docs/LOOK.md).
 * Plain CSS, no framework. Phone layout under 700px; works down to 360px.
 */

:root {
  /* text and chrome */
  --z-text: #000000;
  --z-chrome-text: #1A1A1B;
  --z-muted: #808080;
  --z-disabled-text: #838383;

  /* accents */
  --z-accent: #1183CF;
  --z-dock-accent: #007ACC;
  --z-orange: #F57E20;
  --z-danger: #B22222;
  --z-warn: #FF8C00;
  --z-success: #06B025;
  --z-select: #0078D7;
  --z-select-soft: #E5F1FB;
  --z-select-softer: #CCE4F7;

  /* surfaces and lines */
  --z-page-bg: #F5F5F5;
  --z-panel: #FFFFFF;
  --z-pane-bg: #F0F0F1;
  --z-line: #D4D5D8;
  --z-line-soft: #E3E4E6;
  --z-line-strong: #C2C4C7;
  --z-hover: #E8E9EB;
  --z-pressed: #D9DADD;
  --z-tab-hover-line: #C4C6C9;

  /* buttons (Aero2) */
  --z-btn-bg: #DDDDDD;
  --z-btn-border: #707070;
  --z-btn-hover-bg: #BEE6FD;
  --z-btn-hover-border: #3C7FB1;
  --z-btn-pressed-bg: #C4E5F6;
  --z-btn-pressed-border: #2C628B;
  --z-btn-disabled-bg: #F4F4F4;
  --z-btn-disabled-border: #ADB2B5;

  /* text boxes and combo boxes */
  --z-input-border: #ABADB3;
  --z-input-hover: #7EB4EA;
  --z-input-focus: #569DE5;
  --z-combo-top: #F0F0F0;
  --z-combo-bottom: #E5E5E5;
  --z-combo-border: #ACACAC;
  --z-arrow: #606060;
  --z-check-border: #707070;
  --z-tick: #212121;

  /* data grids */
  --z-grid-frame: #688CAF;
  --z-grid-empty: #F0F0F0;
  --z-grid-line: #000000;
  --z-grid-head-line: #D5D5D5;

  /* tabs and toolbars */
  --z-tab-frame: #ACACAC;
  --z-toolbar: #EEF5FD;
  --z-toolbar-sep: #B6BDC5;

  /* alerts (web only) */
  --z-error-bg: #FBECEC;
  --z-info-bg: #E5F1FB;
  --z-info-text: #0B5E99;
  --z-success-bg: #E8F6EA;
  --z-success-text: #1E6B2B;

  /* type */
  --z-font: Roboto, "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  --z-chrome-font: "Segoe UI", Roboto, system-ui, -apple-system, Arial, sans-serif;
  --z-size: 13px;
  --z-size-small: 12px;
  --z-size-section: 14px;
  --z-size-title: 15px;
  --z-size-heading: 16px;

  /* sizes */
  --z-control-height: 28px;
  --z-gutter: 16px;
  --z-header-height: 44px;
}

/* ---------- base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--z-page-bg);
  color: var(--z-text);
  font-family: var(--z-font);
  font-size: var(--z-size);
  line-height: 1.4;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.25; }
h1 { font-size: var(--z-size-heading); margin: 2px 0 4px; }
h2 { font-size: var(--z-size-section); margin: 14px 0 4px; }
h3 { font-size: var(--z-size); margin: 10px 0 2px; }
p { margin: 0 0 8px; }

a { color: var(--z-select); }
a:hover { color: var(--z-accent); }

:focus-visible { outline: 2px solid var(--z-accent); outline-offset: 1px; }

.muted, .note { color: var(--z-muted); font-size: var(--z-size-small); }
.warn { color: var(--z-warn); }
.danger-text, .overdue { color: var(--z-danger); }
.money, .num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
[hidden] { display: none !important; }

/* ---------- header and nav (the ribbon's look) ---------- */

.app-header {
  background: var(--z-panel);
  border-bottom: 1px solid var(--z-line);
  font-family: var(--z-chrome-font);
  color: var(--z-chrome-text);
}

.app-header__bar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--z-header-height);
  padding: 0 var(--z-gutter);
}

/* The Zinform Prospect logo (static/images, made from ZinProspect.svg); the dark look swaps in the white one. */
.app-brand {
  display: inline-flex;
  align-items: center;
  flex: none;
  line-height: 0;
  text-decoration: none;
}
.app-brand__logo { display: block; width: auto; height: 32px; max-height: 35px; }
.app-brand__logo--dark { display: none; }

.app-who {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.app-who__text {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  min-width: 0;
  font-size: var(--z-size-small);
  line-height: 1.25;
}
.app-who__org { font-weight: 600; }
.app-who__org, .app-who__user {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.app-who form { margin: 0; }

.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px; height: 32px;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 3px;
  color: var(--z-chrome-text);
  cursor: pointer;
}
.nav-toggle:hover { background: var(--z-hover); }
.nav-toggle:active { background: var(--z-pressed); }
.nav-toggle__bars,
.nav-toggle__bars::before,
.nav-toggle__bars::after {
  display: block;
  width: 18px; height: 2px;
  background: currentColor;
  border-radius: 1px;
  position: relative;
}
.nav-toggle__bars::before,
.nav-toggle__bars::after { content: ""; position: absolute; left: 0; }
.nav-toggle__bars::before { top: -6px; }
.nav-toggle__bars::after { top: 6px; }

.app-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  padding: 0 calc(var(--z-gutter) - 11px);
  font-size: 13px;
}
.nav-section {
  display: flex;
  align-items: stretch;
  position: relative;
}
.nav-section + .nav-section { border-left: 1px solid var(--z-line); margin-left: 4px; padding-left: 4px; }
.nav-section__label {
  display: none;
  font-size: 11px;
  color: var(--z-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.nav-section ul { display: flex; list-style: none; margin: 0; padding: 0; }
.nav-item a {
  display: block;
  position: relative;
  height: 29px;
  padding: 5px 11px 0;
  color: var(--z-chrome-text);
  text-decoration: none;
  white-space: nowrap;
}
.nav-item a::after {
  content: "";
  position: absolute;
  left: 11px; right: 11px; bottom: 3px;
  height: 2px;
  border-radius: 1px;
  background: transparent;
}
.nav-item a:hover::after { background: var(--z-tab-hover-line); }
.nav-item a.active::after,
.nav-item a[aria-current="page"]::after { background: var(--z-accent); }

/* ---------- page frame ---------- */

.app-main-wrap {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  /* The page body (not the header or footer) stops at --z-body-max and sits centred on a wide screen. */
  width: 100%;
  max-width: var(--z-body-max);
  margin: 0 auto;
}

/* The page body's widest: 1450 px unless the browser chose another on the Account page (PageWidth). */
:root { --z-body-max: 1450px; }
:root[data-width="1750"] { --z-body-max: 1750px; }
:root[data-width="1600"] { --z-body-max: 1600px; }
:root[data-width="1300"] { --z-body-max: 1300px; }
:root[data-width="1150"] { --z-body-max: 1150px; }

.flash-area { padding: 0 4px; }
.flash-area:empty { display: none; }
.flash-area .alert { margin: 4px 0 0; }

main, .page {
  flex: 1 0 auto;
  display: block;
  margin: 4px;
  padding: 8px var(--z-gutter) 10px;
  background: var(--z-panel);
  min-width: 0;
}

.page-title {
  margin: -8px calc(-1 * var(--z-gutter)) 8px;
  padding: 10px var(--z-gutter);
  font-size: var(--z-size-title);
  font-weight: 600;
  border-bottom: 1px solid var(--z-page-bg);
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}
.page-actions .spacer { flex: 1 1 auto; }
.page-actions .btn { min-width: 100px; }
/* The toolbar under the title: no top gap, a gap before the first field or filter. */
.page-title + .page-actions { margin-top: 0; margin-bottom: 12px; }

.app-footer {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  justify-content: space-between;
  padding: 4px var(--z-gutter);
  background: var(--z-pane-bg);
  border-top: 1px solid var(--z-line);
  color: var(--z-chrome-text);
  font-family: var(--z-chrome-font);
  font-size: var(--z-size-small);
}

/* The top bar and status bar never scroll: they hold to the top and foot of the window while the page
   scrolls between them. app.js puts their heights in --app-header-h / --app-footer-h. */
html {
  scroll-padding-top: calc(var(--app-header-h, 0px) + 8px);
  scroll-padding-bottom: calc(var(--app-footer-h, 0px) + 8px);
}
body:not(.bare) .app-header { position: sticky; top: 0; z-index: 40; }
body:not(.bare) .app-footer { position: sticky; bottom: 0; z-index: 40; }

/* ---------- buttons ---------- */

/* A row of joined buttons, one chosen (Account page widths): radios hidden, labels as buttons. */
.segmented { display: inline-flex; flex-wrap: wrap; margin: 6px 0 2px; padding: 0; border: 0; }
.segmented label { position: relative; display: inline-flex; }
.segmented label + label { margin-left: -1px; }
.segmented input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.segmented span {
  display: inline-flex;
  align-items: center;
  min-height: var(--z-control-height, 24px);
  padding: 2px 14px;
  background: linear-gradient(var(--z-combo-top), var(--z-combo-bottom));
  border: 1px solid var(--z-line-strong);
  color: var(--z-text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.segmented label:hover span { border-color: var(--z-btn-hover-border); position: relative; z-index: 1; }
.segmented input:checked + span {
  position: relative;
  z-index: 2;
  background: var(--z-select);
  border-color: var(--z-select);
  color: #FFFFFF;
  font-weight: 600;
}
.segmented input:focus-visible + span { outline: 2px solid var(--z-accent); outline-offset: 1px; z-index: 3; }

.btn, button.btn, a.btn, input[type="submit"].btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--z-control-height);
  padding: 2px 12px;
  background: var(--z-btn-bg);
  border: 1px solid var(--z-btn-border);
  border-radius: 0;
  color: var(--z-text);
  font: inherit;
  font-size: var(--z-size);
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.btn:hover {
  background: var(--z-btn-hover-bg);
  border-color: var(--z-btn-hover-border);
  color: var(--z-text);
}
.btn:active {
  background: var(--z-btn-pressed-bg);
  border-color: var(--z-btn-pressed-border);
}
.btn:disabled, .btn[aria-disabled="true"] {
  background: var(--z-btn-disabled-bg);
  border-color: var(--z-btn-disabled-border);
  color: var(--z-disabled-text);
  cursor: default;
  pointer-events: none;
}

/* the default button (Save): Aero2's blue border, bold as on the CRM screens */
.btn-primary { border-color: var(--z-btn-hover-border); font-weight: 600; }

.btn-danger { background: var(--z-danger); border-color: #8B1A1A; color: #FFFFFF; }
.btn-danger:hover { background: #C62F2F; border-color: #8B1A1A; color: #FFFFFF; }
.btn-danger:active { background: #8B1A1A; border-color: #6E1414; color: #FFFFFF; }

.btn-small { min-height: 26px; padding: 1px 8px; }

/* flat (toolbar, link-like) */
.btn-flat {
  background: transparent;
  border-color: transparent;
}
.btn-flat:hover { background: var(--z-hover); border-color: transparent; }
.btn-flat:active { background: var(--z-pressed); border-color: transparent; }

.btn-link, a.btn.btn-link, button.btn.btn-link {
  background: none; border: 0; padding: 0; min-height: 0;
  color: var(--z-select); text-decoration: underline; cursor: pointer; font: inherit;
}
.btn-link:hover, a.btn.btn-link:hover, button.btn.btn-link:hover { background: none; color: var(--z-accent); }

.button-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
/* A box with its button as one field of a label-left form (Country + Change): one line, level with the label. */
.form-grid > .button-row { flex-wrap: nowrap; align-items: center; margin: 0; }
.form-grid > .button-row > select, .form-grid > .button-row > input { flex: 1 1 auto; min-width: 0; }

/* ---------- inputs ---------- */

label { color: var(--z-text); }

.input,
input[type="text"], input[type="email"], input[type="password"], input[type="search"],
input[type="tel"], input[type="url"], input[type="number"], input[type="date"],
input[type="datetime-local"], input[type="time"], input[type="month"], textarea, select {
  width: 100%;
  max-width: 100%;
  min-height: var(--z-control-height);
  padding: 3px 4px;
  background: #FFFFFF;
  border: 1px solid var(--z-input-border);
  border-radius: 0;
  color: var(--z-text);
  font: inherit;
  font-size: var(--z-size);
}
input:hover, textarea:hover, select:hover { border-color: var(--z-input-hover); }
input:focus, textarea:focus, select:focus {
  border-color: var(--z-input-focus);
  outline: none;
}
input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 1px solid var(--z-input-focus);
  outline-offset: 0;
}
input:disabled, textarea:disabled, select:disabled { opacity: 0.56; cursor: default; }
input[readonly], textarea[readonly] { background: #FAFAFA; }
textarea { min-height: 100px; resize: vertical; }
input.money, input.num { text-align: right; }

input.code-input {
  font-size: 20px;
  letter-spacing: 0.3em;
  text-align: center;
  font-variant-numeric: tabular-nums;
  max-width: 12ch;
}

/* combo box: Aero2's grey face and small arrow */
select {
  -webkit-appearance: none;
  appearance: none;
  padding: 3px 24px 3px 6px;
  border-color: var(--z-combo-border);
  background-color: var(--z-combo-top);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5' viewBox='0 0 8 5'%3E%3Cpath d='M0.5 0.5 L4 4 L7.5 0.5' fill='none' stroke='%23606060' stroke-width='1.2'/%3E%3C/svg%3E"),
    linear-gradient(var(--z-combo-top), var(--z-combo-bottom));
  background-repeat: no-repeat, no-repeat;
  background-position: right 8px center, 0 0;
  background-size: 8px 5px, 100% 100%;
  cursor: pointer;
}
select:hover {
  border-color: var(--z-btn-hover-border);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5' viewBox='0 0 8 5'%3E%3Cpath d='M0.5 0.5 L4 4 L7.5 0.5' fill='none' stroke='%23606060' stroke-width='1.2'/%3E%3C/svg%3E"),
    linear-gradient(#ECF4FC, #DCECFC);
}
select[multiple], select[size] {
  padding: 2px;
  background-image: none;
  background-color: #FFFFFF;
  border-color: var(--z-input-border);
}

/* check boxes and radio buttons */
input[type="checkbox"], input[type="radio"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 0 0 auto;
  width: 16px; height: 16px;
  min-height: 0;
  margin: 0;
  padding: 0;
  background: #FFFFFF;
  border: 1px solid var(--z-check-border);
  border-radius: 0;
  vertical-align: -3px;
  cursor: pointer;
  display: inline-grid;
  place-content: center;
}
input[type="radio"] { border-radius: 50%; border-color: #333333; }
input[type="checkbox"]::before {
  content: "";
  width: 10px; height: 10px;
  transform: scale(0);
  background: var(--z-tick);
  clip-path: polygon(14% 44%, 0 65%, 40% 100%, 100% 23%, 85% 9%, 39% 72%);
}
input[type="radio"]::before {
  content: "";
  width: 8px; height: 8px;
  border-radius: 50%;
  transform: scale(0);
  background: var(--z-tick);
}
input[type="checkbox"]:checked::before, input[type="radio"]:checked::before { transform: scale(1); }
input[type="checkbox"]:hover, input[type="radio"]:hover { border-color: var(--z-btn-hover-border); background: #F3F9FF; }
input[type="checkbox"]:disabled, input[type="radio"]:disabled { opacity: 0.5; cursor: default; }

.check {
  display: inline-flex;
  align-items: flex-start;
  gap: 6px;
  margin: 5px 15px 5px 0;
  cursor: pointer;
}
.check input { margin-top: 1px; }
.check.disabled, .check:has(input:disabled) { color: var(--z-disabled-text); cursor: default; }

/* ---------- forms ---------- */

.form-grid {
  display: grid;
  grid-template-columns: minmax(120px, max-content) minmax(0, 1fr);
  align-items: center;
  gap: 8px 8px;
  max-width: 640px;
}
.form-grid > label,
.form-grid > .label {
  padding: 4px 8px 4px 5px;
  font-size: var(--z-size);
}
.form-grid > .full { grid-column: 1 / -1; }
/* A tall box (notes): its label sits level with the first line, not the middle. */
.form-grid > label:has(+ textarea), .form-grid > label:has(+ div > textarea) { align-self: start; padding-top: 6px; }
.form-grid > .value { padding: 4px 0; }
.form-grid .narrow { max-width: 180px; }
.form-grid .medium { max-width: 300px; }
/* New Email: the Text label lines up with the labels above it, and the address finder shows its whole hint. */
.compose-body > label { padding-left: 5px; font-weight: 400; }
.compose-find .filters .filter input[type="search"] { width: 300px; max-width: 100%; }

/* Record forms: two columns of panels on wide screens, one under the other below that. */
.form-split { display: grid; grid-template-columns: minmax(0, 1fr); }
.form-split__col { min-width: 0; }
@media (min-width: 1100px) {
  .form-split { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 32px; align-items: start; }
  /* Each column's fields run to the column's edge, so the right column reaches the right of the page. */
  .form-split .form-grid { max-width: none; }
  .form-split .form-grid .medium { max-width: none; }
  .form-split .form-grid > .lookup input[type="search"], .form-split .form-grid > .lookup > .lookup-list { max-width: none; }
}

.form-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 32px;
}

.field { margin: 0 0 10px; }
.field > label:not(.check) { display: block; margin: 0 0 3px; }

.field-error {
  display: block;
  margin-top: 2px;
  color: var(--z-danger);
  font-size: var(--z-size-small);
}
.form-grid > .field-error { grid-column: 2; margin-top: -4px; }
input.invalid, select.invalid, textarea.invalid,
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] {
  border-color: var(--z-danger);
}
.required::after { content: " *"; color: var(--z-danger); }

fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
legend { padding: 0; font-weight: 600; font-size: var(--z-size-section); margin: 14px 0 4px; }

/* ---------- data grid ---------- */

.grid-wrap {
  overflow-x: auto;
  border: 1px solid var(--z-grid-frame);
  background: var(--z-grid-empty);
  -webkit-overflow-scrolling: touch;
}
.grid-wrap.tall { min-height: 160px; }

table.grid {
  width: 100%;
  border-collapse: collapse;
  background: var(--z-panel);
  font-size: var(--z-size);
  border: 1px solid var(--z-grid-frame);
}
.grid-wrap > table.grid { border: 0; }

table.grid th {
  padding: 4px 4px 4px 5px;
  background: linear-gradient(#FFFFFF 0%, #FFFFFF 41%, #F7F8FA 41%, #F1F2F4 100%);
  border-bottom: 1px solid var(--z-grid-head-line);
  border-right: 1px solid var(--z-grid-head-line);
  color: var(--z-text);
  font-weight: normal;
  text-align: left;
  white-space: nowrap;
  vertical-align: middle;
}
table.grid th:last-child { border-right: 0; }
table.grid th.num, table.grid th.money { text-align: right; }
table.grid th a { color: inherit; text-decoration: none; }
table.grid th a:hover { text-decoration: underline; }
table.grid th[aria-sort="ascending"] a::after { content: " \25B4"; color: #444444; }
table.grid th[aria-sort="descending"] a::after { content: " \25BE"; color: #444444; }

table.grid td {
  padding: 1px 4px;
  border: 1px solid var(--z-grid-line);
  border-top: 0;
  vertical-align: middle;
}
table.grid td:first-child { border-left: 0; }
table.grid td:last-child { border-right: 0; }
table.grid tbody tr:first-child td { border-top: 0; }
/* A pick column holding only a tick box is narrow with the box centred. */
table.grid td:has(> input[type="checkbox"]:only-child), table.grid td:has(> input[type="radio"]:only-child) { width: 1%; text-align: center; }
table.grid td > input[type="checkbox"]:only-child, table.grid td > input[type="radio"]:only-child { vertical-align: middle; }

table.grid tbody tr.clickable, table.grid tbody tr[data-href] { cursor: pointer; }
table.grid tbody tr.selected td,
table.grid tbody tr[aria-selected="true"] td {
  background: var(--z-select);
  color: #FFFFFF;
}
table.grid tbody tr.selected td a,
table.grid tbody tr[aria-selected="true"] td a { color: #FFFFFF; }
table.grid tbody tr.overdue td { color: var(--z-danger); }
table.grid tbody tr.closed td { color: var(--z-muted); }
table.grid td a { color: inherit; }
table.grid td a:hover { color: var(--z-select); }
table.grid td.actions { white-space: nowrap; text-align: right; }

table.grid .empty td, .grid-empty {
  padding: 12px 6px;
  color: var(--z-muted);
  text-align: center;
  background: var(--z-grid-empty);
}

/* ---------- tabs ---------- */

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  margin: 10px 0 0;
  padding: 0 2px;
  list-style: none;
  position: relative;
  z-index: 1;
}
.tabs a, .tabs button {
  display: block;
  margin: 2px 0 -1px;
  padding: 2px 8px 3px;
  background: linear-gradient(var(--z-combo-top), var(--z-combo-bottom));
  border: 1px solid var(--z-tab-frame);
  border-bottom: 0;
  border-radius: 0;
  color: var(--z-text);
  font: inherit;
  font-size: var(--z-size-small);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.tabs li + li a, .tabs li + li button, .tabs > a + a, .tabs > button + button { margin-left: -1px; }
.tabs a:hover, .tabs button:hover { background: linear-gradient(#ECF4FC, #DCECFC); }
.tabs a.active, .tabs a[aria-selected="true"], .tabs a[aria-current="page"],
.tabs button.active, .tabs button[aria-selected="true"] {
  position: relative;
  margin-top: 0;
  padding: 3px 10px 5px;
  background: #FFFFFF;
  z-index: 2;
}
.tab-panel {
  padding: 8px;
  background: #FFFFFF;
  border: 1px solid var(--z-tab-frame);
  min-height: 80px;
}

/* ---------- panels (section headings) and group boxes ---------- */

.panel { margin: 0 0 8px; }
.panel > h2:first-child, .panel__title { margin-top: 14px; font-size: var(--z-size-section); font-weight: 600; }
.panel.boxed {
  padding: 4px 10px 10px;
  border: 1px solid var(--z-line-strong);
  border-radius: 4px;
}
.panel.boxed > h2:first-child, .panel.boxed > .panel__title { margin-top: 6px; }

.sections {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 24px;
  align-items: start;
}

/* ---------- toolbar ---------- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  min-height: 28px;
  margin: 1px 1px 6px 3px;
  padding: 1px 2px 2px;
  background: var(--z-toolbar);
  border-radius: 3px;
}
.toolbar .btn {
  min-height: 24px;
  padding: 2px 6px;
  background: transparent;
  border-color: transparent;
}
.toolbar .btn:hover { background: rgba(0, 128, 255, 0.13); border-color: rgba(218, 218, 218, 0.5); }
.toolbar .btn:active { background: rgba(0, 128, 255, 0.25); border-color: rgba(0, 108, 217, 0.56); }
.toolbar .sep {
  width: 1px;
  align-self: stretch;
  margin: 2px;
  background: var(--z-toolbar-sep);
}
.toolbar .spacer { flex: 1 1 auto; }
/* A picker in a toolbar (Contact to add): label and box on the one line. */
.toolbar > label { padding: 0 4px 0 6px; }
.toolbar > select { width: auto; min-width: 220px; max-width: 100%; min-height: 24px; }

/* a search / filter strip above a list (Leads) */
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin: 8px 0;
}
.filters .filter { display: flex; align-items: center; gap: 8px; }
.filters .filter :where(input:not([type="checkbox"]):not([type="radio"])), .filters .filter select { width: auto; min-width: 140px; }
/* Every item in the strip sits on the one centre line: a picker's label goes beside its box (not above it),
   tick boxes lose their form margins, and a spacer pushes later buttons to the right. */
/* Search boxes wide enough for their hint; a long choice (Industry) does not stretch its box past the others. */
.filters .filter input[type="search"] { width: 220px; }
.filters .filter select { max-width: 220px; }
.filters .lookup { display: flex; align-items: center; gap: 8px; margin: 0; }
.filters .lookup > label:not(.check) { display: inline; margin: 0; }
.filters .lookup input[type="search"] { width: 220px; }
.filters .lookup > .lookup-list { top: 100%; left: auto; right: 0; width: 220px; }
.filters .check { margin: 0; align-items: center; }
.filters .check input { margin-top: 0; }
.filters .spacer { flex: 1 1 auto; }

/* ---------- alerts ---------- */

.alert {
  margin: 8px 0;
  padding: 8px 12px;
  border-left: 4px solid;
  font-size: var(--z-size);
}
.alert > :last-child { margin-bottom: 0; }
.alert-error { background: var(--z-error-bg); border-color: var(--z-danger); color: var(--z-danger); }
.alert-info { background: var(--z-info-bg); border-color: var(--z-accent); color: var(--z-info-text); }
.alert-success { background: var(--z-success-bg); border-color: var(--z-success); color: var(--z-success-text); }
.alert-warn { background: #FFF4E5; border-color: var(--z-warn); color: #8A4B00; }
.alert ul { margin: 4px 0 0; padding-left: 18px; }
.alert .alert-close {
  float: right;
  margin: -2px -4px 0 8px;
  padding: 0 4px;
  background: none;
  border: 0;
  color: inherit;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

/* Live updates (app.js data-watch): "changed by someone else - Reload" above the part that changed, and the page's
   "live updates have stopped" / "session has ended" notice. The bar stays in view under the header. */
.sync-bar {
  position: sticky;
  top: var(--app-header-h, 0px);
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}
.sync-bar__text { flex: 1 1 240px; }
.sync-bar .btn { flex: 0 0 auto; }
.sync-status { margin: 4px 4px 0; }
.sync-status a { color: inherit; font-weight: 600; }

/* ---------- badges ---------- */

.badge {
  display: inline-block;
  padding: 0 6px;
  background: var(--z-pane-bg);
  border: 1px solid var(--z-line-strong);
  border-radius: 3px;
  color: var(--z-text);
  font-size: 11px;
  line-height: 16px;
  white-space: nowrap;
  vertical-align: 1px;
}
.badge-info { background: var(--z-select-soft); border-color: var(--z-accent); color: var(--z-info-text); }
.badge-success { background: var(--z-success-bg); border-color: var(--z-success); color: var(--z-success-text); }
.badge-danger { background: var(--z-error-bg); border-color: var(--z-danger); color: var(--z-danger); }
.badge-warn { background: #FFF4E5; border-color: var(--z-warn); color: #8A4B00; }

/* ---------- pagination ---------- */

.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 8px 0;
  font-size: var(--z-size);
}
.pagination .btn { min-width: 0; min-height: 26px; padding: 1px 10px; }
.pagination .page-info { margin-left: 6px; }

/* ---------- form hints, read-only lists ---------- */

.field-hint {
  display: block;
  margin-top: 2px;
  color: var(--z-muted);
  font-size: var(--z-size-small);
}
.form-grid > .field-hint { grid-column: 2; margin-top: -4px; }
dl.form-grid, dl.form-grid dd { margin: 0; }

/* ---------- type-ahead picker (fragments/lookup.html) ---------- */

.lookup { position: relative; }
.lookup input[type="search"] { width: 100%; max-width: 420px; }
.lookup-list {
  position: absolute;
  z-index: 20;
  left: 0;
  right: 0;
  max-width: 420px;
  max-height: 280px;
  margin: 1px 0 0;
  padding: 2px;
  overflow-y: auto;
  list-style: none;
  background: var(--z-panel);
  border: 1px solid #959595;
  box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}
.lookup-list[hidden] { display: none; }
/* In a label-left form: the picker is one row of the grid (label column, then the box). */
.form-grid > .lookup {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: subgrid;
  align-items: center;
  margin: 0;
}
.form-grid > .lookup > label { display: block; margin: 0; padding: 4px 8px 4px 5px; }
.form-grid > .lookup > input[type="search"], .form-grid > .lookup > .field-error { grid-column: 2; }
.form-grid > .lookup > .lookup-list { grid-column: 2; top: 100%; }
.form-grid > .lookup input[type="search"] { max-width: 300px; }
/* Grids that follow one another (a picker row between two blocks of fields) keep the row gap. */
.form-grid ~ .form-grid { margin-top: 8px; }
/* In a two-column stacked form the box is as wide as the fields beside it. */
.form-columns .lookup input[type="search"], .form-columns .lookup-list { max-width: none; }
.lookup-option {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 6px;
  padding: 3px 6px;
  cursor: pointer;
}
.lookup-option:hover, .lookup-option.active { background: var(--z-select-soft); }
.lookup-option .lookup-detail { flex-basis: 100%; }
.lookup-more, .lookup-empty { padding: 3px 6px; }

/* ---------- dialog ---------- */

dialog.dialog, dialog {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  background: var(--z-panel);
  border: 1px solid var(--z-line-strong);
  border-radius: 0;
  color: var(--z-text);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.2); }
.dialog__title {
  margin: 0;
  padding: 10px var(--z-gutter);
  background: var(--z-pane-bg);
  border-bottom: 1px solid var(--z-line);
  font-size: var(--z-size-title);
  font-weight: 600;
}
.dialog__body { padding: 12px var(--z-gutter); overflow: auto; }
.dialog__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px var(--z-gutter);
  border-top: 1px solid var(--z-line-soft);
}
.dialog__actions .btn { min-width: 100px; }

/* ---------- sign-in (bare layout: web-only) ---------- */

body.bare {
  align-items: center;
  justify-content: center;
  padding: 32px var(--z-gutter);
  font-family: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background-color: #F3F5F9;
  background-image:
    radial-gradient(680px circle at 16% 14%, rgba(245, 126, 32, 0.09), transparent 60%),
    radial-gradient(720px circle at 85% 86%, rgba(17, 131, 207, 0.09), transparent 62%);
}
.bare-brand {
  margin: 0 0 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}
.bare-brand__logo { display: block; width: auto; height: 44px; }
.bare-brand__logo--dark { display: none; }

body.bare main, .signin-panel {
  position: relative;
  overflow: hidden;
  flex: 0 0 auto;
  width: 100%;
  max-width: 432px;
  margin: 0;
  padding: 32px 34px 30px;
  background: var(--z-panel);
  background-clip: padding-box;
  border: 1px solid rgba(15, 23, 42, 0.1);
  border-radius: 16px;
  box-shadow: 0 20px 44px -12px rgba(15, 23, 42, 0.12), 0 4px 12px rgba(15, 23, 42, 0.05);
}
body.bare main::before, .signin-panel::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--z-orange) 0%, #00AA44 48%, var(--z-accent) 100%);
}
body.bare main h1, .signin-panel h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--z-text);
  margin: 0 0 6px;
}
body.bare main .lead, .signin-panel .lead {
  font-size: 14px;
  line-height: 1.5;
  color: var(--z-muted);
  margin: 0 0 22px;
}
body.bare main .field { margin: 0 0 16px; }
body.bare main .field > label:not(.check) {
  display: block;
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--z-chrome-text);
}
body.bare main .field input:not([type="checkbox"]):not([type="radio"]) {
  min-height: 42px;
  padding: 9px 12px;
  font-size: 14px;
  background: var(--z-input-bg, #FFFFFF);
  border: 1px solid #CBD5E1;
  border-radius: 8px;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}
body.bare main .field input:not([type="checkbox"]):not([type="radio"]):hover {
  border-color: #94A3B8;
}
body.bare main .field input:not([type="checkbox"]):not([type="radio"]):focus {
  border-color: var(--z-accent);
  box-shadow: 0 0 0 3px rgba(17, 131, 207, 0.16);
  outline: none;
}
body.bare main .field input[type="text"].code-input {
  max-width: none;
  padding-left: calc(12px + 0.32em);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.32em;
  text-align: center;
}
body.bare main .field-hint {
  margin-top: 5px;
  font-size: 12px;
  line-height: 1.45;
}
body.bare main input[type="checkbox"] { border-radius: 4px; }
body.bare main input[type="checkbox"]:checked { background: var(--z-accent); border-color: var(--z-accent); }
body.bare main input[type="checkbox"]::before { background: #FFFFFF; }
body.bare main .signin-trust {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  background: var(--z-pane-bg);
  border: 1px solid var(--z-line);
  border-radius: 10px;
}
body.bare main .signin-trust .check { margin: 0; font-size: 13.5px; }
body.bare main .signin-trust .muted { margin: 2px 0 0; line-height: 1.4; }
body.bare main ol { margin: 0 0 14px; padding-left: 20px; line-height: 1.5; }
body.bare main ol li + li { margin-top: 4px; }
body.bare main .alert {
  border: 1px solid color-mix(in srgb, currentColor 24%, var(--z-panel));
  border-left: 4px solid;
  border-radius: 8px;
  margin-bottom: 16px;
}
body.bare main .alert-error { border-left-color: var(--z-danger); }
body.bare main .alert-info { border-left-color: var(--z-accent); }
body.bare main .alert-success { border-left-color: var(--z-success); }
body.bare main .alert-warn { border-left-color: var(--z-warn); }
body.bare main .btn { border-radius: 8px; font-weight: 500; }
body.bare main .actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  margin-top: 22px;
}
body.bare main .actions .btn-primary {
  width: 100%;
  min-height: 42px;
  padding: 8px 16px;
  font-size: 14.5px;
  font-weight: 600;
  color: #FFFFFF;
  background: linear-gradient(180deg, color-mix(in srgb, var(--z-accent) 90%, #ffffff) 0%, var(--z-accent) 100%);
  border: 1px solid color-mix(in srgb, var(--z-accent) 84%, #000000);
  border-radius: 8px;
  box-shadow: 0 2px 6px color-mix(in srgb, var(--z-accent) 26%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.22);
  transition: background 140ms ease, box-shadow 140ms ease, transform 80ms ease;
}
body.bare main .actions .btn-primary:hover {
  background: linear-gradient(180deg, var(--z-accent) 0%, color-mix(in srgb, var(--z-accent) 82%, #000000) 100%);
  box-shadow: 0 4px 12px color-mix(in srgb, var(--z-accent) 34%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.22);
  color: #FFFFFF;
}
body.bare main .actions .btn-primary:active { transform: translateY(0.5px); }
body.bare main .actions .btn-link {
  align-self: center;
  min-height: 0;
  font-size: 13px;
  text-decoration: none;
}
body.bare main .actions .btn-link:hover { text-decoration: underline; }
body.bare main .signin-back { margin: 16px 0 0; text-align: center; }
body.bare main .signin-back a { text-decoration: none; }
body.bare main .signin-back a:hover { text-decoration: underline; }
body.bare main .qr { margin: 10px auto 14px; padding: 6px; border: 1px solid var(--z-line); border-radius: 10px; }
body.bare main .secret { margin: 6px 0 18px; padding: 8px 10px; border-radius: 8px; }
body.bare .flash-area { width: 100%; max-width: 432px; padding: 0; margin-bottom: 12px; }
body.bare .flash-area .alert { border-radius: 8px; }
body.bare .app-footer {
  background: transparent;
  border: 0;
  justify-content: center;
  margin-top: 20px;
  color: var(--z-muted);
  font-size: 12px;
}

.qr {
  display: block;
  width: 200px;
  height: 200px;
  margin: 8px auto;
  image-rendering: pixelated;
  background: #FFFFFF;
}
.secret {
  display: block;
  padding: 6px 8px;
  background: var(--z-pane-bg);
  border: 1px solid var(--z-line);
  font-family: Consolas, "Cascadia Mono", Menlo, monospace;
  font-size: 13px;
  letter-spacing: 0.08em;
  word-break: break-all;
  text-align: center;
}

/* ---------- recovery codes ---------- */

.recovery-codes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 16px;
  margin: 10px 0;
  padding: 10px 14px;
  list-style: none;
  background: var(--z-pane-bg);
  border: 1px solid var(--z-line);
  font-family: Consolas, "Cascadia Mono", Menlo, monospace;
  font-size: 14px;
  letter-spacing: 0.06em;
  counter-reset: code;
}
.recovery-codes li { counter-increment: code; white-space: nowrap; }
.recovery-codes li::before {
  content: counter(code) ".";
  display: inline-block;
  width: 2.2em;
  color: var(--z-muted);
  font-size: 12px;
}

/* ---------- htmx loading ---------- */

.htmx-indicator {
  display: inline-block;
  opacity: 0;
  visibility: hidden;
  transition: opacity 150ms ease-in;
}
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  opacity: 1;
  visibility: visible;
}
.spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--z-line);
  border-top-color: var(--z-accent);
  border-radius: 50%;
  vertical-align: -3px;
  animation: z-spin 0.7s linear infinite;
}
@keyframes z-spin { to { transform: rotate(360deg); } }

/* thin progress line under the header while a request runs */
.app-progress {
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--z-accent), transparent);
  background-size: 50% 100%;
  background-repeat: no-repeat;
  animation: z-sweep 1s linear infinite;
}
@keyframes z-sweep { from { background-position: -50% 0; } to { background-position: 150% 0; } }

.app-progress.htmx-indicator { display: block; }

.htmx-request.btn, .btn.htmx-request { opacity: 0.7; cursor: progress; }
[hx-swap].htmx-swapping, .htmx-swapping { opacity: 0.6; transition: opacity 100ms ease-out; }

/* ---------- error pages ---------- */

.error-page { max-width: 640px; padding-top: 12px; }
.error-page .code { color: var(--z-muted); font-size: var(--z-size-small); }

/* ---------- phone ---------- */

@media (max-width: 700px) {
  :root { --z-gutter: 12px; }

  .nav-toggle { display: inline-flex; }
  .app-who__text { display: none; }

  .app-nav {
    display: none;
    flex-direction: column;
    padding: 4px 0 8px;
    border-top: 1px solid var(--z-line);
  }
  /* the open menu scrolls inside the fixed top bar */
  .app-nav.open { display: flex; max-height: calc(100dvh - 120px); overflow-y: auto; }
  .nav-section { flex-direction: column; }
  .nav-section + .nav-section { border-left: 0; margin: 4px 0 0; padding: 4px 0 0; border-top: 1px solid var(--z-line-soft); }
  .nav-section__label { display: block; padding: 4px var(--z-gutter) 2px; }
  .nav-section ul { flex-direction: column; }
  .nav-item a {
    height: auto;
    padding: 10px var(--z-gutter) 10px calc(var(--z-gutter) + 4px);
  }
  .nav-item a::after { left: 0; right: auto; top: 6px; bottom: 6px; width: 3px; height: auto; }

  main, .page { margin: 0; padding: 8px var(--z-gutter) 12px; }
  .page-title { margin: -8px calc(-1 * var(--z-gutter)) 8px; }

  /* 16px stops iOS zooming into a field on focus */
  .input,
  input[type="text"], input[type="email"], input[type="password"], input[type="search"],
  input[type="tel"], input[type="url"], input[type="number"], input[type="date"],
  input[type="datetime-local"], input[type="time"], input[type="month"], textarea, select {
    font-size: 16px;
    min-height: 36px;
  }
  .btn { min-height: 36px; }
  input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; }
  input[type="checkbox"]::before { width: 12px; height: 12px; }

  .form-grid, .form-columns, .sections { grid-template-columns: minmax(0, 1fr); max-width: none; }
  .form-grid { gap: 2px; }
  .form-grid > label, .form-grid > .label { padding: 8px 0 0; }
  .compose-body > label { padding-left: 0; }
  .form-grid > .field-error { grid-column: 1; margin-top: 0; }
  .form-grid > .field-hint { grid-column: 1; margin-top: 0; }
  .lookup input[type="search"], .lookup-list { max-width: none; }
  .lookup-option, .lookup-more, .lookup-empty { min-height: 36px; padding: 8px 6px; }
  .form-grid .narrow, .form-grid .medium { max-width: none; }

  .filters { flex-direction: column; align-items: stretch; }
  .filters .filter { flex-direction: column; align-items: stretch; gap: 2px; }
  .filters .filter input:not([type="checkbox"]):not([type="radio"]), .filters .filter select { width: 100%; }
  .filters .check.filter { flex-direction: row; align-items: center; gap: 6px; }
  .filters .filter select { max-width: none; }
  .filters .lookup { flex-direction: column; align-items: stretch; gap: 2px; }
  .filters .lookup input[type="search"], .filters .lookup > .lookup-list { width: 100%; max-width: none; left: 0; }

  .page-actions { justify-content: stretch; }
  .page-actions .btn { flex: 1 1 calc(50% - 8px); min-width: 0; }
  .page-actions .spacer { display: none; }

  .recovery-codes { grid-template-columns: minmax(0, 1fr); }

  /* data grid → stacked cards; each td carries data-label */
  .grid-wrap { overflow: visible; border: 0; background: transparent; }
  table.grid, table.grid tbody, table.grid tr, table.grid td { display: block; width: 100%; }
  table.grid { border: 0 !important; background: transparent; }
  table.grid thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  table.grid tbody tr {
    margin: 0 0 8px;
    padding: 6px 10px;
    background: var(--z-panel);
    border: 1px solid var(--z-grid-frame);
  }
  table.grid td {
    display: grid;
    grid-template-columns: minmax(90px, 38%) minmax(0, 1fr);
    gap: 8px;
    padding: 3px 0;
    border: 0;
    border-bottom: 1px solid var(--z-line-soft);
    text-align: left;
    overflow-wrap: anywhere;
  }
  table.grid td:last-child { border-bottom: 0; }
  table.grid td::before {
    content: attr(data-label);
    color: var(--z-muted);
    font-size: var(--z-size-small);
  }
  table.grid td:not([data-label])::before, table.grid td[data-label=""]::before { content: none; }
  table.grid td:not([data-label]), table.grid td[data-label=""] { display: block; }
  table.grid td.num, table.grid td.money { text-align: left; }
  table.grid td.actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-start; }
  table.grid tbody tr.selected, table.grid tbody tr[aria-selected="true"] { border-color: var(--z-select); }
  table.grid .empty td { display: block; }
  /* Email cards: a field with nothing in it (no record, nothing sending, no attachment) is left out, and a
     conversation with new mail is tinted across the whole card. */
  table.mail-grid td:empty { display: none; }
  /* the last field shown (the ones after it are empty, so hidden) ends the card without a line */
  table.mail-grid td:not(:has(~ td:not(:empty))) { border-bottom: 0; }
  table.mail-grid tbody tr.mail-new { background: var(--z-info-bg); border-color: var(--z-accent); }

  .tabs { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; }
  .tabs a, .tabs button { font-size: var(--z-size); padding: 6px 10px; }
  .tabs a.active, .tabs a[aria-selected="true"], .tabs a[aria-current="page"],
  .tabs button.active, .tabs button[aria-selected="true"] { padding: 7px 12px 8px; }

  .app-footer { justify-content: center; text-align: center; }
  body.bare main, .signin-panel { padding: 26px 24px 24px; }
  body.bare main .field input:not([type="checkbox"]):not([type="radio"]):not(.code-input) { font-size: 16px; }
}

@media (max-width: 400px) {
  .page-actions .btn { flex-basis: 100%; }
  table.grid td { grid-template-columns: minmax(0, 1fr); gap: 0; }
  body.bare main, .signin-panel { padding: 22px 18px 20px; }
}

/* ---------- print (recovery codes, records) ---------- */

@media print {
  body { background: #FFFFFF; }
  .app-header, .app-footer, .flash-area, .page-actions, .no-print, .htmx-indicator, .sync-bar, .sync-status { display: none !important; }
  .btn, .button-row, body.bare form { display: none !important; }
  main, .page, body.bare main { margin: 0; padding: 0; border: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .spinner, .app-progress { animation: none; }
}

/* ---------- records area (records/*) ---------- */
/* Header search box and its drop-down. */
.app-search { position: relative; flex: 1 1 200px; max-width: 360px; margin: 0 12px; }
.app-search input[type="search"] { width: 100%; }
.app-search__list {
  position: absolute;
  z-index: 30;
  left: 0;
  right: 0;
  max-height: 360px;
  margin: 1px 0 0;
  padding: 4px;
  overflow-y: auto;
  background: var(--z-panel);
  border: 1px solid #959595;
  box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}
.app-search__list[hidden] { display: none; }
.app-search__group + .app-search__group { margin-top: 4px; border-top: 1px solid var(--z-line-soft); }
.app-search__label { display: block; padding: 2px 6px; color: var(--z-muted); font-size: 0.9em; }
.app-search__group ul { margin: 0; padding: 0; list-style: none; }
.app-search__group a, .app-search__more { display: block; padding: 3px 6px; color: var(--z-text); text-decoration: none; }
.app-search__group a:hover, .app-search__more:hover { background: var(--z-select-soft); }
.app-search__more { color: var(--z-accent); }
.app-search__empty { margin: 0; padding: 3px 6px; color: var(--z-muted); }
.search-hits { margin: 0; padding: 0 0 0 18px; }
.search-hits li { margin: 2px 0; }
.home-search { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0 12px; }
.home-search input[type="search"] { flex: 1 1 220px; max-width: 420px; }
.home-links { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0 16px; }
.link-list { margin: 0; padding: 0 0 0 18px; }
/* Multi-line text kept as lines (an address as it prints). */
.pre-line { white-space: pre-line; }
.record-stamp { margin-top: 12px; font-size: 0.9em; }
/* A small form inside a grid cell (Mark Done, Dismiss). */
.inline-form { display: inline; margin: 0; }
.cell-note { display: block; font-size: 0.9em; }
.chain-col { width: 1.5em; }
.chain-mark { color: var(--z-muted); }
/* Contact methods grid on the record screens. */
.methods-grid input:not([type="checkbox"]):not([type="radio"]), .methods-grid select { width: 100%; }
.methods-grid td.primary { text-align: center; width: 4em; }
/* On a phone a grid cell is a label and value row, so a tick-only cell (narrow and centred on a desk) takes the full width. */
@media (max-width: 700px) {
  .methods-grid td.primary,
  table.grid td:has(> input[type="checkbox"]:only-child), table.grid td:has(> input[type="radio"]:only-child) { width: 100%; text-align: left; }
}
/* Duplicate prompt candidates. */
.dup-list { margin: 6px 0; padding: 0 0 0 18px; }
.dup-list li { margin: 3px 0; }
/* Merge: the two records side by side. */
.merge-grid td.choice { white-space: nowrap; }
.merge-grid tr.same { color: var(--z-muted); }
.merge-grid tr.same[hidden] { display: none; }
/* Import wizard. */
.wizard-steps { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 0 0 10px; padding: 0; list-style: none; color: var(--z-muted); }
.wizard-steps .current { color: var(--z-text); font-weight: 600; }
.import-counts { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 6px 0; padding: 0; list-style: none; }
.progress { width: 100%; max-width: 420px; height: 16px; }
.sample-table td { max-width: 18em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Form-grid rows shown only while another field has a value (app.js data-show-when). */
.show-group { display: contents; }
.show-group[hidden] { display: none; }
/* Record forms (organisation, contact, lead, address, contact link): the form's sections, then its action
   buttons bottom right, 100 x 28 and 8 apart (LOOK.md "Screen layout", MD:45-49). */
.record-form { margin: 0 0 8px; }
.record-form > .panel:first-of-type > h2:first-child { margin-top: 8px; }
.record-form > .button-row {
  justify-content: flex-end;
  gap: 8px;
  margin: 12px 0 0;
  padding-top: 8px;
  border-top: 1px solid var(--z-page-bg);
}
.record-form > .button-row .btn { min-width: 100px; }
/* Activities / Documents / Email tabs under a record page (records/fragments/shared :: record-tabs). */
.record-tabs { margin-top: 16px; }
.record-tabs .comms-panel { margin: 0; }
/* Lead: converted / merged / legal hold lines; the Convert page's choice groups. */
.record-status { margin: 0 0 10px; }
.choice-group { display: flex; flex-wrap: wrap; gap: 4px 16px; }

@media (max-width: 700px) {
  .app-header__bar { flex-wrap: wrap; }
  .app-search { order: 3; flex-basis: 100%; max-width: none; margin: 0 0 6px; }
  .record-form > .button-row { justify-content: flex-start; }
}

/* ==================== sales area ==================== */
/* Opportunity / activity forms: a full-width row in two columns; a fragment whose fields join the parent grid. */
.form-columns > .full { grid-column: 1 / -1; }
.form-columns__pair { display: contents; }
/* Filter chips (opportunities list): the remove cross. */
.chip-close { margin-left: 6px; color: inherit; text-decoration: none; font-weight: 600; }
.chip-close:hover, .chip-close:focus { color: var(--z-danger); }
/* Cancelled rows and items: struck through. */
table.grid tbody tr.cancelled td, .cancelled .timeline__subject { text-decoration: line-through; color: var(--z-muted); }
/* Reminders that are due now. */
table.grid tbody tr.due td { font-weight: 600; }
.check-list { margin: 4px 0 10px; padding-left: 18px; max-height: 220px; overflow-y: auto; }
.reminder-actions select { width: auto; }

/* Pipeline board */
.board { margin: 8px 0; }
.board__columns {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  overflow-x: auto;
  padding-bottom: 8px;
}
.board-col {
  flex: 1 0 200px;
  min-width: 0;
  background: var(--z-pane-bg);
  border: 1px solid var(--z-line);
}
.board-col--over { border-color: var(--z-select); background: var(--z-select-soft); }
.board-col__head { padding: 6px 8px; border-bottom: 1px solid var(--z-line); background: var(--z-panel); }
.board-col__title { margin: 0; font-size: var(--z-size-section); font-weight: 600; }
.board-col__totals { color: var(--z-muted); font-size: var(--z-size-small); }
.board-col__totals > span { display: block; }
.board-col__cards { list-style: none; margin: 0; padding: 6px; display: flex; flex-direction: column; gap: 6px; }
.board-col__empty, .board-col__more { padding: 4px 8px 8px; color: var(--z-muted); font-size: var(--z-size-small); }
.board-card {
  padding: 6px 8px;
  background: var(--z-panel);
  border: 1px solid var(--z-line-strong);
  border-left: 3px solid var(--z-accent);
}
.board-card[draggable="true"] { cursor: grab; }
.board-card:focus { outline: 2px solid var(--z-input-focus); outline-offset: 1px; }
.board-card--dragging { opacity: 0.5; }
.board-card--stale { border-left-color: var(--z-warn); }
.board-card--overdue { border-left-color: var(--z-danger); }
.board-card__name { display: block; font-weight: 600; overflow-wrap: anywhere; }
.board-card__party, .board-card__line { display: block; font-size: var(--z-size-small); color: var(--z-muted); }
.board-card--overdue .board-card__line { color: var(--z-danger); }
.board-card__move { display: none; margin-top: 6px; gap: 4px; align-items: center; }
.board-card__move select { flex: 1 1 auto; min-width: 0; }

/* Timeline panel */
.timeline__head { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 0 0 8px; }
.timeline__list { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--z-line); }
.timeline__item { position: relative; margin: 0 0 10px; padding: 0 0 0 12px; }
.timeline__item::before {
  content: "";
  position: absolute;
  left: -5px;
  top: 5px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--z-accent);
}
.timeline__item.overdue::before { background: var(--z-danger); }
.timeline__item.log { color: var(--z-muted); }
.timeline__item.log::before { background: var(--z-line-strong); }
.timeline__subject { font-weight: 600; overflow-wrap: anywhere; }
.timeline__body { margin: 2px 0 0; white-space: pre-line; overflow-wrap: anywhere; }
.timeline__actions { margin-top: 4px; display: flex; flex-wrap: wrap; gap: 6px; }

/* Forecast */
.forecast-grid td, .forecast-grid th { text-align: right; white-space: nowrap; }
.forecast-grid td:first-child, .forecast-grid th:first-child { text-align: left; }
table.grid.forecast-grid tbody tr.omitted td { color: var(--z-muted); font-style: italic; }
.forecast-grid tfoot td { font-weight: 600; border-top: 1px solid var(--z-line-strong); }

/* Editable grids (quote lines, contact methods, contact roles): the DataGrid's editing look on a wide screen.
   Each box fills its cell with no border of its own; the cell being edited gets a blue edge. Cells without a
   box keep the usual padding and sit centred on the row. Phones keep the card layout and the normal boxes. */
@media (min-width: 701px) {
  table.grid.grid-edit td { vertical-align: middle; }
  table.grid.grid-edit td:has(> input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]), > select, > .lookup) {
    padding: 0;
  }
  table.grid.grid-edit td > input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]),
  table.grid.grid-edit td > select,
  table.grid.grid-edit td > .lookup input[type="search"] {
    display: block;
    width: 100%;
    max-width: none;
    min-width: 0;
    min-height: 26px;
    margin: 0;
    padding: 3px 6px;
    border: 1px solid transparent;
    background-color: transparent;
    box-shadow: none;
  }
  table.grid.grid-edit td > select, table.grid.grid-edit td > select:hover {
    padding-right: 24px;
    border-color: transparent;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5' viewBox='0 0 8 5'%3E%3Cpath d='M0.5 0.5 L4 4 L7.5 0.5' fill='none' stroke='%23606060' stroke-width='1.2'/%3E%3C/svg%3E");
    background-size: 8px 5px;
    background-position: right 8px center;
  }
  table.grid.grid-edit td:focus-within { outline: 2px solid var(--z-select); outline-offset: -2px; background: #FFFFFF; }
  table.grid.grid-edit td > input:focus, table.grid.grid-edit td > select:focus,
  table.grid.grid-edit td > .lookup input[type="search"]:focus { outline: none; border-color: transparent; }
  table.grid.grid-edit td > input[aria-invalid="true"], table.grid.grid-edit td > select[aria-invalid="true"],
  table.grid.grid-edit td > .lookup input[aria-invalid="true"] { border-color: var(--z-danger); }
  table.grid.grid-edit td > input[readonly] { color: var(--z-text); }
  /* Row buttons (Remove) are flat, as on a DataGrid row, and light up on hover. */
  table.grid.grid-edit td.actions { padding: 0 2px; }
  table.grid.grid-edit td.actions .btn { min-height: 26px; padding: 1px 8px; background: transparent; border-color: transparent; color: var(--z-accent); }
  table.grid.grid-edit td.actions .btn:hover { background: var(--z-hover); border-color: transparent; }
  table.grid.grid-edit td.actions .btn:active { background: var(--z-pressed); border-color: transparent; }
  table.grid.grid-edit td > .cell-note, table.grid.grid-edit td > .field-error,
  table.grid.grid-edit td > .lookup > .field-error { padding: 0 6px 3px; }
}

/* Quotes */
.quote-progress { margin: 0 0 10px; color: var(--z-muted); }
.quote-lines { margin: 8px 0; }
.quote-lines__grid input:not([type="checkbox"]):not([type="radio"]), .quote-lines__grid select { min-width: 70px; }
.quote-lines__grid td.num, .quote-lines__grid th.num { text-align: right; }
/* One line per row: cells centred on the inputs, the picker without its form-field label and margin
   (the column header names it; the label stays for screen readers, and the card view shows data-label). */
@media (max-width: 700px) { .quote-lines__grid input.num { text-align: left; } }
.quote-lines__grid .lookup { margin: 0; }
.quote-lines__grid .lookup > label {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.quote-lines__grid .lookup input[type="search"] { max-width: none; }
.quote-lines__grid .field-error { display: block; text-align: left; }
.quote-lines__grid col.ql-item { width: 13%; }
.quote-lines__grid col.ql-qty, .quote-lines__grid col.ql-discount { width: 7%; }
.quote-lines__grid col.ql-price { width: 10%; }
.quote-lines__grid col.ql-measure, .quote-lines__grid col.ql-special { width: 6%; }
.quote-lines__grid col.ql-taxcat { width: 8%; }
.quote-lines__grid col.ql-tax, .quote-lines__grid col.ql-amount { width: 9%; }
.quote-lines__grid col.ql-actions { width: 1%; }
.quote-warnings { margin: 6px 0; padding-left: 18px; color: var(--z-warn); }
.quote-totals {
  display: grid;
  grid-template-columns: auto auto;
  gap: 2px 16px;
  justify-content: end;
  margin: 8px 0;
}
.quote-totals dt { text-align: right; color: var(--z-muted); }
.quote-totals dd { margin: 0; text-align: right; font-weight: 600; }

/* Reminder alerts: toasts the poll adds at the foot of the window. */
.toast-stack {
  position: fixed;
  right: 16px;
  bottom: calc(var(--app-footer-h, 0px) + 16px);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 320px;
  max-width: calc(100vw - 32px);
}
.toast {
  padding: 8px 10px;
  background: var(--z-panel);
  border: 1px solid var(--z-line-strong);
  border-left: 4px solid var(--z-orange);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}
.toast--error { border-left-color: var(--z-danger); background: var(--z-error-bg); }
.toast__title { font-weight: 600; overflow-wrap: anywhere; }
.toast__about, .toast__when { font-size: var(--z-size-small); }
.toast__when { color: var(--z-muted); }
.toast__actions { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin-top: 6px; }
.toast__actions select { width: auto; }

@media (max-width: 700px) {
  .form-columns > .full { grid-column: auto; }
  .board__columns { flex-direction: column; overflow-x: visible; }
  .board-col { flex: 1 1 auto; width: 100%; }
  .board-card__move { display: flex; }
  .toast-stack { left: 16px; right: 16px; width: auto; }
}

/* ---- Comms: documents, email, consent, privacy, reports, calendar ------------------------------------- */

.comms-panel { margin: 0 0 8px; }
.drop-zone {
  padding: 10px;
  border: 1px dashed var(--z-line-strong);
  background: var(--z-panel);
  text-align: center;
  cursor: pointer;
}
.drop-zone:hover { border-color: var(--z-select); }
.drop-zone.dragover { border-color: var(--z-select); background: var(--z-select-soft); }
.drop-zone__hint { color: var(--z-muted); font-size: var(--z-size-small); }
.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.comms-split { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 8px; align-items: start; }
.comms-split__side, .comms-split__main { min-width: 0; }
.mailbox-list, .report-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--z-line); background: var(--z-panel); }
.mailbox-list li, .report-list li { padding: 4px 8px; border-bottom: 1px solid var(--z-line-soft); overflow-wrap: anywhere; }
.mailbox-list li:last-child, .report-list li:last-child { border-bottom: 0; }
.mailbox-list li.active, .report-list li.active { background: var(--z-select-soft); }
/* A mailbox or message entry: the name on one line (cut short, full name on hover), the address or date under it. */
.mailbox-list li:has(> a[aria-current="page"]) { background: var(--z-select-soft); }
.mailbox-list li > a { display: block; color: inherit; text-decoration: none; }
.mailbox-list li > a:hover strong, .mailbox-list li > a:focus-visible strong { text-decoration: underline; }
.mailbox-list li > a strong { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mailbox-list li > a > .muted { display: block; font-size: var(--z-size-small); overflow-wrap: anywhere; }
.mailbox-list .mail-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; font-size: var(--z-size-small); }
.report-list .unavailable { display: block; color: var(--z-disabled-text); }

.mail-headers { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 2px 8px; margin: 0 0 8px; }
.mail-headers dt { color: var(--z-muted); }
.mail-headers dd { margin: 0; overflow-wrap: anywhere; }
.mail-about { font-size: var(--z-size-small); color: var(--z-muted); }
/* Mail received since the user last opened the conversation: bold on a light blue row, with a count badge;
   in a thread, a blue bar and a New badge. */
table.grid tbody tr.mail-new:not(.selected, [aria-selected="true"]) td { background: var(--z-info-bg); }
table.grid tbody tr.mail-new td { font-weight: 700; }
/* white on --z-info-text: Classic's --z-accent (#1183CF) gives only about 4.1:1 for this small bold text */
.badge.badge-new { background: var(--z-info-text); border-color: var(--z-info-text); color: #FFFFFF; font-weight: 700; }
.mailbox-list li.mail-new { box-shadow: inset 3px 0 0 var(--z-accent); }
.mailbox-list li.mail-new strong { font-weight: 700; }
.mail-subject { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; }
.mail-summary { margin: 4px 0 0; font-size: var(--z-size-small); color: var(--z-muted); }
.mail-summary-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin: 4px 0 0; }
.mail-summary-bar .mail-summary { margin: 0; }
.mail-body { display: block; width: 100%; height: 480px; border: 1px solid var(--z-line); background: #FFFFFF; }
.mail-body > iframe { display: block; width: 100%; height: 100%; border: 0; }

.compose .field, .compose-body { margin-bottom: 6px; }
.compose-body textarea { width: 100%; min-height: 240px; }
.compose-find, .subject-find { margin: 6px 0; }
.compose-find > summary, .subject-find > summary { display: inline-block; cursor: pointer; list-style: none; }
.compose-find > summary::-webkit-details-marker, .subject-find > summary::-webkit-details-marker { display: none; }
/* The summary is the only sign the panel opens, so it shows a turning arrow like a tree node. */
.compose-find > summary::before { content: "\25B8"; display: inline-block; width: 1em; color: var(--z-muted); }
.compose-find[open] > summary::before { content: "\25BE"; }
/* The subject (redrawn when a template is chosen) is a grid of its own under the header fields. */
.form-grid ~ #compose-merge { margin-top: 8px; }
#compose-merge > .form-grid + .compose-body { margin-top: 8px; }
.compose-attach label { display: block; }
.address-picker { list-style: none; margin: 4px 0; padding: 0; max-height: 200px; overflow-y: auto; }
.address-picker li { padding: 2px 0; overflow-wrap: anywhere; }
.richtext { border: 1px solid var(--z-input-border); background: #FFFFFF; }
.richtext__bar { display: flex; flex-wrap: wrap; gap: 2px; padding: 2px; background: var(--z-toolbar); border-bottom: 1px solid var(--z-line); }
.richtext__area { min-height: 240px; padding: 6px; overflow-wrap: anywhere; }
.richtext__area:focus { outline: 1px solid var(--z-input-focus); }

.inline-choices { border: 0; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.file-dialog-party { margin-bottom: 6px; }
fieldset.plain { border: 0; margin: 0; padding: 0; min-width: 0; }

.due-overdue { color: var(--z-danger); font-weight: 600; }
.due-soon { color: #8A4B00; font-weight: 600; }
tr.row-warning > td { background: #FFF4E5; }
tr.row-muted > td { color: var(--z-muted); }

@media (max-width: 700px) {
  .comms-split { grid-template-columns: minmax(0, 1fr); }
  .mail-body { height: 360px; }
}
