/*
  Meliora CRM components. All colors, sizes and type come from tokens in theme.css.

  Breakpoints used below (see theme.css):
    phone    max-width: 639.98px
    tablet   640px to 1023.98px
    desktop  min-width: 1024px (all table columns from 1280px)
*/

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; overflow-x: clip; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: var(--font-family);
  font-size: var(--text-body);
  font-weight: var(--weight-regular);
  line-height: var(--line-height);
  color: var(--color-text);
  background: var(--color-page);
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}
button, input, select, textarea { font: inherit; color: inherit; margin: 0; }
button { -webkit-tap-highlight-color: transparent; }
h1, h2, h3, p { margin: 0; }
a { color: var(--color-accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
[hidden] { display: none !important; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; border-radius: var(--radius-sm); }
.noscript { padding: var(--space-5); }
/* Scroll lock while a dialog is open. It sits on the root so the sticky top bar keeps working. */
html.no-scroll { overflow: hidden; }

.muted { color: var(--color-muted); }
.small { font-size: var(--text-small); }
.overdue { color: var(--color-danger); font-weight: var(--weight-medium); }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.clip { display: block; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Longer text in a table cell: at most two lines, the full text is in the title attribute. */
.clamp {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2;
  min-width: 220px; max-width: 420px; overflow: hidden; overflow-wrap: anywhere;
}
/* Muted second line under the name in a table cell: one line, the full text is in the title
   attribute. It may break anywhere and is cut after one line, so it never makes its column wider. */
.cell-sub {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 1; line-clamp: 1;
  max-width: 320px; overflow: hidden; overflow-wrap: anywhere;
  color: var(--color-muted); font-size: var(--text-small); font-weight: var(--weight-regular);
}
.strong { font-weight: var(--weight-semibold); }
.only-phone { display: none !important; }
.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;
}
.row { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; }
.stack-sm { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }
.grow { flex: 1 1 auto; min-width: 0; }

/* ---------- Shell ---------- */
.shell { min-height: 100vh; min-height: 100dvh; }
.sidebar {
  position: fixed; top: 0; bottom: 0; left: 0;
  width: var(--sidebar-width);
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  background: var(--color-primary);
  color: var(--color-on-primary);
  overflow-y: auto;
  z-index: 40;
}
.sidebar :focus-visible { outline-color: var(--color-on-primary); }
.sidebar-logo { display: block; padding: 20px 20px var(--space-4); }
/* The white variant ships with unfilled (black) wordmark paths; the filter renders the whole mark white. */
.sidebar-logo img { display: block; width: 148px; height: auto; filter: brightness(0) invert(1); }
.nav { display: flex; flex-direction: column; gap: 2px; padding: var(--space-2); }
.nav-item {
  display: flex; align-items: center;
  min-height: max(38px, var(--control-height));
  padding: 0 var(--space-3);
  border-radius: var(--radius);
  color: var(--color-on-primary-muted);
  font-weight: var(--weight-medium);
  text-decoration: none;
}
.nav-item:hover { background: var(--color-on-primary-hover); color: var(--color-on-primary); text-decoration: none; }
.nav-item.active { background: var(--color-on-primary-active); color: var(--color-on-primary); }
/* Tasks group: a header that folds its links, then My tasks, All tasks and one link per task tab
   with its open count on the right. */
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group-head {
  justify-content: space-between; gap: var(--space-2); width: 100%;
  border: 0; background: transparent; text-align: left; cursor: pointer;
}
.nav-group-head .icon { flex: none; opacity: 0.8; transition: transform 0.12s; }
.nav-group.is-collapsed .nav-group-head .icon { transform: rotate(-90deg); }
.nav-group.is-current .nav-group-head { color: var(--color-on-primary); }
.nav-group.is-collapsed.is-current .nav-group-head { background: var(--color-on-primary-active); }
.nav-sub { display: flex; flex-direction: column; gap: 2px; padding-bottom: var(--space-1); }
.nav-group.is-collapsed .nav-sub { display: none; }
.nav-sub-item {
  display: flex; align-items: center; gap: var(--space-2); width: 100%;
  min-height: max(32px, var(--control-height));
  padding: 0 var(--space-3) 0 var(--space-5);
  border: 0; border-radius: var(--radius); background: transparent;
  color: var(--color-on-primary-muted); text-align: left; text-decoration: none; cursor: pointer;
}
.nav-sub-item:hover { background: var(--color-on-primary-hover); color: var(--color-on-primary); text-decoration: none; }
.nav-sub-item.active { background: var(--color-on-primary-active); color: var(--color-on-primary); font-weight: var(--weight-medium); }
.nav-sub-label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-sub-count { flex: none; font-size: var(--text-small); font-weight: var(--weight-regular); color: var(--color-on-primary-muted); font-variant-numeric: tabular-nums; }
.nav-sub-sep { height: 1px; margin: var(--space-1) var(--space-3) var(--space-1) var(--space-5); background: var(--color-on-primary-active); }
.nav-backdrop { display: none; }

.main { position: relative; margin-left: var(--sidebar-width); min-width: 0; overflow-x: clip; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  padding-top: env(safe-area-inset-top);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-line);
}
.topbar-inner {
  display: flex; align-items: center; gap: var(--space-3);
  height: var(--topbar-height);
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0 max(var(--page-gutter), env(safe-area-inset-right)) 0 max(var(--page-gutter), env(safe-area-inset-left));
}
.icon-btn.menu-btn { display: none; }
.page-title { display: flex; align-items: baseline; gap: var(--space-2); flex: 1 1 auto; min-width: 0; }
/* The link back to the list or tab keeps its own width up to 45% of the title area; a longer name
   (a task tab can have 40 characters) is cut with an ellipsis, the full name is in its title. */
.page-title-parent {
  flex: none; min-width: 0; max-width: 45%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: var(--text-body); font-weight: var(--weight-medium);
}
.page-title-sep { color: var(--color-muted); }
.page-title-text {
  font-size: var(--text-title); font-weight: var(--weight-semibold); line-height: 1.25;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.topbar-actions { display: flex; align-items: center; gap: var(--space-2); flex: none; }
.bell { position: relative; }
.bell-badge {
  position: absolute; top: 2px; right: 0;
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px;
  background: var(--color-danger); color: var(--color-on-primary);
  font-size: 11px; font-weight: var(--weight-semibold); line-height: 18px; text-align: center;
}
.user-btn {
  display: inline-flex; align-items: center; gap: var(--space-2);
  height: var(--control-height); padding: 0 var(--space-2) 0 var(--space-1);
  border: 0; border-radius: var(--radius); background: transparent; cursor: pointer;
  font-weight: var(--weight-medium);
}
.user-btn:hover { background: var(--color-hover); }
.user-name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  display: inline-grid; place-items: center; flex: none;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--color-accent-light); color: var(--color-primary);
  font-size: var(--text-small); font-weight: var(--weight-semibold);
}
.content {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-5) max(var(--page-gutter), env(safe-area-inset-right)) var(--space-7) max(var(--page-gutter), env(safe-area-inset-left));
}
.page { display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; }
.tabbar { display: none; }

/* ---------- Login ---------- */
.login {
  min-height: 100vh; min-height: 100dvh;
  display: grid; place-items: center;
  padding: var(--space-5) var(--space-4);
}
.login-card {
  width: 100%; max-width: 380px;
  padding: var(--space-6);
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-lg);
}
.login-logo { display: block; width: 180px; height: auto; margin: 0 auto var(--space-5); }
.login-card .field { margin-bottom: var(--space-4); }
.login-card .btn { width: 100%; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--control-height); padding: 0 14px;
  border: 1px solid transparent; border-radius: var(--radius);
  background: transparent;
  font-size: var(--text-body); font-weight: var(--weight-medium); line-height: 1;
  white-space: nowrap; cursor: pointer; text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--color-primary); color: var(--color-on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--color-accent); }
.btn-secondary { background: var(--color-surface); border-color: var(--color-border); color: var(--color-primary); }
.btn-secondary:hover:not(:disabled) { background: var(--color-accent-pale); }
.btn-quiet { padding: 0 var(--space-2); color: var(--color-accent); }
.btn-quiet:hover:not(:disabled) { background: var(--color-accent-pale); }
.btn-danger { background: var(--color-danger); color: var(--color-on-primary); }
.btn-danger:hover:not(:disabled) { opacity: 0.9; }
.btn-quiet.danger-text { color: var(--color-danger); }
.btn-quiet.danger-text:hover:not(:disabled) { background: var(--color-danger-pale); }
.icon-btn {
  display: inline-grid; place-items: center; flex: none;
  width: var(--control-height); height: var(--control-height);
  border: 0; border-radius: var(--radius); background: transparent;
  color: var(--color-primary); cursor: pointer;
}
.icon-btn:hover:not(:disabled) { background: var(--color-accent-pale); }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.icon { display: block; }
.new-btn .icon { display: none; }

/* ---------- Form fields ---------- */
.input {
  display: block; width: 100%;
  height: var(--control-height); padding: 0 10px;
  border: 1px solid var(--color-border); border-radius: var(--radius);
  background: var(--color-surface); color: var(--color-text);
  font-size: var(--text-input);
  min-width: 0;
}
.input::placeholder { color: var(--color-muted); opacity: 1; }
.input:hover { border-color: var(--color-accent); }
.input:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 0; border-color: var(--color-accent); border-radius: var(--radius); }
.input:disabled, .input[readonly] { background: var(--color-page); color: var(--color-muted); }
.input.invalid { border-color: var(--color-danger); }
textarea.input { height: auto; min-height: 88px; padding: var(--space-2) 10px; line-height: var(--line-height); resize: vertical; }
textarea.input[rows="2"] { min-height: 60px; }
select.input {
  appearance: none; -webkit-appearance: none;
  padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
  text-overflow: ellipsis;
}
input[type="color"].input { padding: 3px; width: 48px; flex: none; cursor: pointer; }
input[type="file"].input { padding: 5px 10px; height: auto; min-height: var(--control-height); }
.field { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.field-label { font-size: var(--text-small); font-weight: var(--weight-medium); color: var(--color-text); }
.field-label .req { color: var(--color-danger); margin-left: 2px; }
.field-hint { font-size: var(--text-small); color: var(--color-muted); }
.field-error { font-size: var(--text-small); color: var(--color-danger); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4); }
.field-full { grid-column: 1 / -1; }
.form-error {
  margin-top: var(--space-4); padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-danger); border-radius: var(--radius);
  background: var(--color-danger-pale); color: var(--color-danger);
  font-size: var(--text-body);
}
.form-section-title { font-size: var(--text-section); font-weight: var(--weight-semibold); margin: var(--space-5) 0 var(--space-3); }

.check { display: inline-flex; align-items: center; gap: var(--space-2); min-height: var(--control-height); cursor: pointer; }
.check input, .check-hit input { width: 16px; height: 16px; margin: 0; accent-color: var(--color-primary); cursor: pointer; flex: none; }
.check-hit { display: inline-grid; place-items: center; width: 24px; height: 24px; cursor: pointer; }
.switch { display: inline-flex; align-items: center; gap: var(--space-3); min-height: var(--control-height); cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
  position: relative; flex: none; width: 36px; height: 20px; border-radius: 10px;
  background: var(--color-border); transition: background 0.12s;
}
.switch-track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--color-surface); transition: transform 0.12s;
}
.switch input:checked + .switch-track { background: var(--color-primary); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--color-accent); outline-offset: 2px; }
.switch input:disabled + .switch-track { opacity: 0.5; }
.switch.disabled { cursor: not-allowed; color: var(--color-muted); }
.radio-list { display: flex; flex-direction: column; gap: var(--space-1); }

/* ---------- Segmented control and tabs ---------- */
.segmented { display: inline-flex; padding: 2px; border: 1px solid var(--color-border); border-radius: var(--radius); background: var(--color-surface); max-width: 100%; }
.segmented-item {
  display: inline-flex; align-items: center; gap: 6px;
  height: calc(var(--control-height) - 6px); padding: 0 var(--space-3);
  border: 0; border-radius: var(--radius-sm); background: transparent;
  color: var(--color-muted); font-weight: var(--weight-medium); white-space: nowrap; cursor: pointer;
}
.segmented-item:hover:not(:disabled) { color: var(--color-primary); }
.segmented-item.active { background: var(--color-accent-pale); color: var(--color-primary); }
.segmented-item:disabled { opacity: 0.5; cursor: not-allowed; }
/* A segmented control that may be wider than its place scrolls inside this container, never the page. */
.segmented-scroll {
  display: flex; min-width: 0; max-width: 100%;
  /* Room for the focus ring of the buttons, which the scroll container would otherwise cut off. */
  padding: 3px; margin: -3px;
  overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.segmented-scroll::-webkit-scrollbar { display: none; }
.segmented-scroll .segmented { flex: none; max-width: none; }
.tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--color-line); overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  height: max(40px, var(--control-height)); padding: 0 var(--space-3);
  border: 0; border-bottom: 2px solid transparent; background: transparent;
  color: var(--color-muted); font-weight: var(--weight-medium); white-space: nowrap; cursor: pointer;
}
.tab:hover { color: var(--color-primary); }
.tab.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }
.tab:focus-visible { outline-offset: -2px; }
.count { font-size: var(--text-small); color: var(--color-muted); font-weight: var(--weight-regular); }

/* ---------- Status chip ---------- */
.chip {
  display: inline-flex; align-items: center;
  height: 22px; padding: 0 var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-small); font-weight: var(--weight-medium); line-height: 1; white-space: nowrap;
  background: var(--tone-grey-bg); color: var(--tone-grey-text);
}
.chip-blue { background: var(--tone-blue-bg); color: var(--tone-blue-text); }
.chip-green { background: var(--tone-green-bg); color: var(--tone-green-text); }
.chip-grey { background: var(--tone-grey-bg); color: var(--tone-grey-text); }
.chip-red { background: var(--tone-red-bg); color: var(--tone-red-text); }
.chip-slate { background: var(--tone-slate-bg); color: var(--tone-slate-text); }

/* ---------- Panels ---------- */
.panel { background: var(--color-surface); border: 1px solid var(--color-line); border-radius: var(--radius-lg); min-width: 0; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap;
  min-height: 48px; padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--color-line);
}
.panel-title { display: flex; align-items: baseline; gap: var(--space-2); font-size: var(--text-section); font-weight: var(--weight-semibold); }
.panel-actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.panel-body { padding: var(--space-4); }
.panel-body.flush { padding: 0; }
.panel-subtle { background: var(--color-accent-pale); border-color: var(--color-border); }

/* ---------- Tables ---------- */
.table-wrap { position: relative; min-width: 0; overflow-x: auto; -webkit-overflow-scrolling: touch; }
/* A table wider than its container scrolls sideways inside it. ui.js dataTable adds .is-fit when the
   table fits, which releases the container so the header can stick under the top bar. */
.table-wrap.is-fit { overflow-x: visible; }
.table-wrap.is-fit th { position: sticky; top: var(--topbar-height); z-index: 2; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; }
.table th {
  height: 36px; padding: 0 var(--space-3);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-primary);
  font-size: var(--text-small); font-weight: var(--weight-semibold); text-align: left; white-space: nowrap;
}
/* Sortable column header (ui.js dataTable with sort and onSort): the label is a button. */
.th-sort {
  display: inline-flex; align-items: center; gap: var(--space-1);
  height: 36px; padding: 0;
  border: 0; background: transparent;
  font-weight: inherit; white-space: nowrap; cursor: pointer;
}
.th-sort .icon { flex: none; opacity: 0; }
.th-sort:hover .icon, .th-sort:focus-visible .icon { opacity: 0.45; }
.th-sort.active .icon { opacity: 1; }
.table th:first-child, .table td:first-child { padding-left: var(--space-4); }
.table th:last-child, .table td:last-child { padding-right: var(--space-4); }
.table td {
  height: var(--row-height); padding: 3px var(--space-3);
  border-bottom: 1px solid var(--color-line);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--color-hover); }
.table tr.clickable:focus-visible { outline-offset: -2px; }
.table tr.selected td { background: var(--color-accent-pale); }
.table tr.is-done .cell-primary { color: var(--color-muted); }
.table tr.is-done .task-name { text-decoration: line-through; }
.table td.cell-primary { font-weight: var(--weight-medium); min-width: 180px; }
.table td:not(.cell-primary):not(.cell-check):not(.cell-chip):not(.cell-action):not(.nowrap) { min-width: 120px; }
.table td.cell-check, .table th.cell-check { width: 40px; padding-right: 0; }
.table td.cell-action, .table th.cell-action { text-align: right; white-space: nowrap; }
.table td.cell-num, .table th.cell-num { text-align: right; }
.table-empty td, .state {
  padding: var(--space-5) var(--space-4); text-align: center; color: var(--color-muted);
}
.state { display: flex; flex-direction: column; align-items: center; gap: var(--space-3); }
.state-error { color: var(--color-danger); }
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--color-accent-light); border-top-color: var(--color-accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
  * { scroll-behavior: auto !important; transition: none !important; }
}
.inline-set { display: flex; gap: var(--space-2); align-items: center; min-width: 220px; }
.inline-set .input { flex: 1 1 auto; }

.date-inline { width: 150px; flex: none; }
.form-intro { margin-bottom: var(--space-4); color: var(--color-muted); overflow-wrap: anywhere; }

/* ---------- Notifications panel ---------- */
.notif-tools {
  position: sticky; top: 0; z-index: 1;
  display: flex; justify-content: flex-end;
  padding: var(--space-2) var(--space-4);
  background: var(--color-surface); border-bottom: 1px solid var(--color-line);
}
.notif-list { display: flex; flex-direction: column; }
.notif-item {
  display: flex; align-items: flex-start; gap: var(--space-3); width: 100%;
  padding: var(--space-3) var(--space-4);
  border: 0; border-bottom: 1px solid var(--color-line); background: transparent;
  text-align: left; cursor: pointer;
}
.notif-item:hover { background: var(--color-hover); }
.notif-item:focus-visible { outline-offset: -2px; }
.notif-item.unread { background: var(--color-accent-pale); }
.notif-dot { flex: none; width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; background: transparent; }
.notif-item.unread .notif-dot { background: var(--color-accent); }
.notif-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.notif-title { overflow-wrap: anywhere; }
.notif-item.unread .notif-title { font-weight: var(--weight-semibold); }
.notif-body { color: var(--color-text); overflow-wrap: anywhere; }
.notif-time { font-size: var(--text-small); color: var(--color-muted); }

/* ---------- Toolbar and filters ---------- */
.toolbar { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.toolbar-search { flex: 0 1 260px; min-width: 160px; }
.toolbar-filters { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.toolbar-filters .input { width: auto; min-width: 140px; max-width: 200px; }
.filters-toggle { display: none; }
.toolbar-spacer { flex: 1 1 auto; }
.toolbar-actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; margin-left: auto; }

/* ---------- Dashboard counts ---------- */
.stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: var(--space-3); }
.stat {
  display: flex; flex-direction: column; gap: 2px;
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface); border: 1px solid var(--color-line); border-radius: var(--radius-lg);
  color: inherit; text-decoration: none; min-width: 0;
}
.stat:hover { border-color: var(--color-border); text-decoration: none; }
.stat-value { font-size: var(--text-title); font-weight: var(--weight-semibold); color: var(--color-primary); line-height: 1.25; }
.stat-value.overdue { color: var(--color-danger); }
.stat-label { font-size: var(--text-small); color: var(--color-muted); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4); align-items: start; }

/* ---------- Dashboard: All projects ---------- */
.projects-panel .panel-actions { flex: 1 1 420px; justify-content: flex-end; min-width: 0; }
.projects-search { flex: 0 1 240px; width: auto; min-width: 160px; }
/* Desktop table: lower floors for the name and the description than in other tables, so that the
   five default columns fit the panel from 1024px (about 754px next to the sidebar) without
   scrolling sideways. Below 1024px this table is a card list (see .cards-tablet). */
@media (min-width: 1024px) {
  .projects-panel .table td.cell-primary { min-width: 140px; }
  .projects-panel .table .clamp { min-width: 160px; }
}

/* Column chooser dialog */
.col-list { list-style: none; margin: 0 0 var(--space-3); padding: 0; border-top: 1px solid var(--color-line); }
.col-row {
  display: flex; align-items: center; gap: var(--space-2);
  min-height: calc(var(--control-height) + var(--space-1));
  border-bottom: 1px solid var(--color-line);
}
.col-row .check { flex: 1 1 auto; min-width: 0; }
.col-row .check span { min-width: 0; overflow-wrap: anywhere; }
.col-row.is-off .check span { color: var(--color-muted); }
.col-grip { display: inline-grid; place-items: center; flex: none; width: 20px; color: var(--color-muted); cursor: grab; }
.col-tools { display: flex; align-items: center; gap: 2px; flex: none; }
.col-row.dragging { opacity: 0.45; }
.col-row.drop-before { box-shadow: inset 0 2px 0 var(--color-accent); }
.col-row.drop-after { box-shadow: inset 0 -2px 0 var(--color-accent); }

/* ---------- Detail pages ---------- */
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; }
.detail-name { font-size: var(--text-title); font-weight: var(--weight-semibold); line-height: 1.25; }
.detail-meta { display: flex; align-items: center; gap: var(--space-2) var(--space-4); flex-wrap: wrap; min-height: var(--control-height); }
.detail-meta .meta-item { display: inline-flex; align-items: center; gap: 6px; }
.detail-meta .input { width: auto; min-width: 160px; }
.detail-description { max-width: 860px; overflow-wrap: anywhere; }
.action-bar { display: flex; justify-content: flex-end; min-width: 0; }
.action-bar-full { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; justify-content: flex-end; }
.action-bar-compact { display: none; }
.layout-2 { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: var(--space-4); align-items: start; }
.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-4); }
.detail-item { min-width: 0; }
.detail-item.full { grid-column: 1 / -1; }
.detail-label { font-size: var(--text-small); color: var(--color-muted); margin-bottom: 2px; }
.detail-value { min-height: 21px; overflow-wrap: anywhere; }
.inline-edit { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; min-width: 0; }
/* A card field edited in place. At rest: the value and a pencil mark, lit on hover and on focus,
   so it reads as something to click before it is clicked. Open: the control, Save and Cancel. */
.edit-field { min-width: 0; }
.edit-field-rest {
  display: inline-flex; align-items: flex-start; gap: var(--space-1); max-width: 100%; min-width: 0;
  margin: -3px -6px; padding: 3px 6px; border-radius: var(--radius); cursor: pointer;
}
.edit-field-rest:hover, .edit-field-rest:focus-within { background: var(--color-accent-pale); }
.edit-field-value { min-width: 0; overflow-wrap: anywhere; }
.edit-field-mark {
  display: inline-grid; place-items: center; flex: none; width: 22px; height: 21px; padding: 0;
  border: 0; border-radius: var(--radius); background: none; color: var(--color-muted); cursor: pointer;
}
.edit-field-rest:hover .edit-field-mark, .edit-field-mark:focus-visible { color: var(--color-accent); }
.edit-field-form { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); min-width: 0; }
.edit-field-form .input { flex: 1 1 180px; min-width: 0; }
.edit-field-textarea .edit-field-form .input { flex-basis: 100%; }
.edit-field-actions { display: flex; flex: none; gap: var(--space-2); }
.edit-field > select.input { width: 100%; max-width: 320px; }
.edit-field.is-busy { opacity: 0.6; }
.edit-field .field-error { margin-top: var(--space-1); }
.inline-edit-text { overflow-wrap: anywhere; min-width: 0; }
.inline-edit .input { flex: 1 1 240px; }

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline-item { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-line); }
.timeline-item:last-child { border-bottom: 0; }
.timeline-meta { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; font-size: var(--text-small); color: var(--color-muted); }
.timeline-subject { margin-top: var(--space-1); font-weight: var(--weight-medium); overflow-wrap: anywhere; }
.timeline-body { margin-top: 2px; white-space: pre-wrap; overflow-wrap: anywhere; }
.timeline-item.clickable { cursor: pointer; }
.timeline-item.clickable:hover { background: var(--color-hover); }

/* ---------- Plain lists (approvals, deliveries, channels, notifications) ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list-item { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-line); }
.list-item:last-child { border-bottom: 0; }
.list-item-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); flex-wrap: wrap; }
.list-item-title { font-weight: var(--weight-medium); overflow-wrap: anywhere; }
.basis-list { margin: 0; padding-left: 18px; }
.basis-list li { margin-bottom: var(--space-1); }

/* ---------- Boards (deals by pipeline stage, tasks by stage) ---------- */
.board-picker { display: none; margin-bottom: var(--space-2); }
.board { display: flex; align-items: flex-start; gap: var(--space-3); overflow-x: auto; padding-bottom: var(--space-3); -webkit-overflow-scrolling: touch; }
.board-col {
  flex: 0 0 248px; min-width: 0;
  background: var(--color-surface); border: 1px solid var(--color-line); border-radius: var(--radius-lg);
}
.board-col.drop-target { border-color: var(--color-accent); background: var(--color-accent-pale); }
/* A board with few fixed columns (the five task stages): from 640px they share the width and scroll
   sideways only when a column would get narrower than its floor. Phones keep the swipeable columns. */
@media (min-width: 640px) {
  .board-fit .board-col { flex: 1 1 0; min-width: 184px; }
}
.board-col-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
  padding: var(--space-3); border-bottom: 1px solid var(--color-line);
  font-size: var(--text-small); font-weight: var(--weight-semibold); color: var(--color-primary);
}
.board-cards { display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-2); min-height: 72px; }
.board-empty { padding: var(--space-3) var(--space-2); font-size: var(--text-small); color: var(--color-muted); text-align: center; }
.board-card {
  display: flex; flex-direction: column; gap: var(--space-1);
  padding: var(--space-3);
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius);
  cursor: pointer;
}
.board-card:hover { border-color: var(--color-accent); }
.board-card[draggable="true"] { cursor: grab; }
.board-card.dragging { opacity: 0.45; }
.board-card-name { font-weight: var(--weight-semibold); color: var(--color-primary); overflow-wrap: anywhere; }
.board-card-line { font-size: var(--text-small); color: var(--color-muted); overflow-wrap: anywhere; }
.board-card-next { font-size: var(--text-small); overflow-wrap: anywhere; }
.board-card-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); flex-wrap: wrap; font-size: var(--text-small); color: var(--color-muted); }
.board-card .input { margin-top: var(--space-1); }
.board-empty .btn { margin-top: var(--space-1); }

/* ---------- Overlays: modal, drawer, menu ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: flex-start; justify-content: center;
  padding: var(--space-7) var(--space-4);
  background: var(--color-backdrop);
  overflow-y: auto;
}
.modal {
  display: flex; flex-direction: column;
  width: 100%; max-width: 580px; max-height: calc(100vh - 96px); max-height: calc(100dvh - 96px);
  background: var(--color-surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-overlay);
}
.modal-sm { max-width: 440px; }
.modal-lg { max-width: 780px; }
.modal-columns { max-width: 460px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex: none;
  padding: var(--space-3) var(--space-3) var(--space-3) 20px;
  border-bottom: 1px solid var(--color-line);
}
.modal-title { font-size: var(--text-section); font-weight: var(--weight-semibold); overflow-wrap: anywhere; min-width: 0; }
.modal-form { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.modal-body { flex: 1 1 auto; min-height: 0; padding: 20px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal-footer {
  display: flex; align-items: center; justify-content: flex-end; gap: var(--space-2); flex: none; flex-wrap: wrap;
  padding: var(--space-3) 20px;
  border-top: 1px solid var(--color-line);
}
.modal-footer .footer-left { margin-right: auto; }
.overlay-drawer { align-items: stretch; justify-content: flex-end; padding: 0; }
.drawer {
  display: flex; flex-direction: column;
  width: 420px; max-width: 100%; height: 100vh; height: 100dvh;
  background: var(--color-surface); box-shadow: var(--shadow-overlay);
}
.drawer .modal-body { padding: 0; }

.menu {
  position: fixed; z-index: 60;
  min-width: 200px; max-width: min(320px, calc(100vw - 16px));
  padding: var(--space-1);
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius);
  box-shadow: var(--shadow-overlay);
}
.menu-backdrop { position: fixed; inset: 0; z-index: 59; background: var(--color-backdrop); }
.menu-title { padding: var(--space-2) var(--space-3); font-size: var(--text-section); font-weight: var(--weight-semibold); }
.menu-header { padding: var(--space-2) var(--space-3); }
.menu-header-title { font-weight: var(--weight-semibold); overflow-wrap: anywhere; }
.menu-header-sub { font-size: var(--text-small); color: var(--color-muted); overflow-wrap: anywhere; }
.menu-sep { height: 1px; margin: var(--space-1) 0; background: var(--color-line); }
.menu-item {
  display: flex; align-items: center; width: 100%;
  min-height: var(--control-height); padding: 0 var(--space-3);
  border: 0; border-radius: var(--radius-sm); background: transparent;
  text-align: left; cursor: pointer;
}
.menu-item { justify-content: space-between; gap: var(--space-3); }
.menu-item-label { min-width: 0; overflow-wrap: anywhere; }
.menu-item.is-current { font-weight: var(--weight-semibold); color: var(--color-primary); }
.menu-item .icon { flex: none; }
.menu-item:hover, .menu-item:focus-visible { background: var(--color-accent-pale); outline: none; }
.menu-item.danger-text { color: var(--color-danger); }
.menu-sheet {
  left: 0; right: 0; bottom: 0; max-width: none; max-height: 82vh; max-height: 82dvh; overflow-y: auto;
  padding: var(--space-2) var(--space-2) calc(var(--space-2) + env(safe-area-inset-bottom));
  border: 0; border-radius: 12px 12px 0 0;
}

/* ---------- Toasts ---------- */
.toast-root {
  position: fixed; right: var(--space-4); bottom: var(--space-4); z-index: 70;
  display: flex; flex-direction: column; gap: var(--space-2);
  width: 360px; max-width: calc(100vw - 32px);
  pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: var(--space-2);
  padding: var(--space-3) var(--space-2) var(--space-3) var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border); border-left: 3px solid var(--color-accent); border-radius: var(--radius);
  box-shadow: var(--shadow-overlay);
  pointer-events: auto;
}
.toast-success { border-left-color: var(--color-success); }
.toast-error { border-left-color: var(--color-danger); }
.toast-content { flex: 1 1 auto; min-width: 0; padding-top: 2px; }
.toast-content.clickable { cursor: pointer; }
.toast-title { font-weight: var(--weight-semibold); overflow-wrap: anywhere; }
.toast-message { overflow-wrap: anywhere; }
.toast .icon-btn { width: 28px; height: 28px; color: var(--color-muted); }

/* ---------- Notices ---------- */
.notice {
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap;
  padding: var(--space-3) var(--space-4);
  background: var(--color-accent-pale);
  border: 1px solid var(--color-border); border-left: 3px solid var(--color-accent); border-radius: var(--radius);
}
.notice-body { flex: 1 1 240px; min-width: 0; overflow-wrap: anywhere; }
.notice-title { font-weight: var(--weight-semibold); }
.notice-danger { background: var(--color-danger-pale); border-color: var(--color-danger); color: var(--color-text); }
.notice-danger .notice-title { color: var(--color-danger); }
.notice-attention { background: var(--tone-slate-bg); border-color: var(--color-border); border-left-color: var(--color-warning); }
.notice-success { background: var(--color-success-pale); border-color: var(--color-border); border-left-color: var(--color-success); }
.test-label {
  display: inline-flex; align-items: center; height: 22px; padding: 0 var(--space-2);
  border-radius: var(--radius-sm); border: 1px solid var(--color-warning);
  background: var(--tone-slate-bg); color: var(--tone-slate-text);
  font-size: var(--text-small); font-weight: var(--weight-semibold); white-space: nowrap;
}

/* ---------- Status track (top of the deal, task, client and email cards) ----------
   One row of connected steps on a white band. Done steps: navy with a check mark. Current step:
   blue with a marker dot and a bold label. Later steps: pale with grey text. States outside the
   path (On Hold, Failed) are pills after the track. No gradients, no shadows. */
.track {
  --track-h: 34px;   /* height of a step */
  --track-a: 10px;   /* depth of the arrow point */
  min-width: 0; padding: var(--space-2);
  background: var(--color-surface); border: 1px solid var(--color-line); border-radius: var(--radius-lg);
}
.track[aria-busy="true"] { opacity: 0.7; }
/* The steps and the side state pills share one row while the steps keep a usable width (480px);
   otherwise the pills move to a second row. */
.track-full { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); min-width: 0; }
/* When the steps do not fit, the track scrolls inside this container, never the page. The padding
   leaves room for the focus ring, which the scroll container would otherwise cut off. */
.track-scroll {
  position: relative; flex: 1 1 480px; min-width: 0;
  padding: 3px; margin: -3px;
  overflow-x: auto; scrollbar-width: thin; -webkit-overflow-scrolling: touch;
}
.track-steps { display: flex; list-style: none; margin: 0; padding: 0; width: max-content; min-width: 100%; }
/* A step is as wide as its label, up to 280px; a longer label is cut with an ellipsis (the full
   name is in the title attribute). */
.track-step { display: flex; flex: 1 0 auto; max-width: 280px; margin-left: calc(3px - var(--track-a)); }
.track-step:first-child { margin-left: 0; border-radius: var(--radius) 0 0 var(--radius); overflow: hidden; }
.track-step:last-child { border-radius: 0 var(--radius) var(--radius) 0; overflow: hidden; }
.track-step:first-child:last-child { border-radius: var(--radius); }
.track-seg {
  display: flex; align-items: center; justify-content: center; gap: 6px; flex: 1 1 auto; min-width: 0;
  height: var(--track-h);
  padding: 0 calc(var(--track-a) + var(--space-2)) 0 calc(var(--track-a) + var(--space-3));
  border: 0; border-radius: 0;
  background: var(--color-accent-pale); color: var(--tone-grey-text);
  font-size: var(--text-small); font-weight: var(--weight-medium); line-height: 1; white-space: nowrap;
  clip-path: polygon(0 0, calc(100% - var(--track-a)) 0, 100% 50%, calc(100% - var(--track-a)) 100%, 0 100%, var(--track-a) 50%);
}
.track-step:first-child .track-seg {
  padding-left: var(--space-4);
  clip-path: polygon(0 0, calc(100% - var(--track-a)) 0, 100% 50%, calc(100% - var(--track-a)) 100%, 0 100%);
}
.track-step:last-child .track-seg {
  padding-right: var(--space-4);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, var(--track-a) 50%);
}
.track-step:first-child:last-child .track-seg { clip-path: none; }
.track-seg .icon { flex: none; }
/* The line height leaves room for descenders, which the cut-off box would otherwise clip. */
.track-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; line-height: 1.4; }
.track-dot { flex: none; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.track-step.is-done .track-seg { background: var(--color-primary); color: var(--color-on-primary); }
.track-step.is-current .track-seg { background: var(--color-accent); color: var(--color-on-primary); font-weight: var(--weight-semibold); }
.track-step.is-held .track-seg { background: var(--color-accent-light); color: var(--color-primary); }
/* A track the user may change: the other steps are buttons. A read only track has no pointer cursor. */
button.track-seg, button.track-side { cursor: pointer; }
.track-step.is-upcoming button.track-seg:hover { background: var(--color-accent-light); color: var(--color-primary); }
.track-step.is-done button.track-seg:hover { background: var(--color-accent); }
.track-step.is-held button.track-seg:hover { background: var(--color-border); }
/* Keyboard focus. The arrow shape cuts off an outline of the step itself, so the ring is drawn
   around its list item (blue, like every other focus ring) and a white line inside the step keeps
   it visible on the dark steps. Without :has() the ring is drawn inside the step: blue, then white. */
.track-seg:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--color-accent), inset 0 0 0 4px var(--color-surface); }
@supports selector(:has(*)) {
  .track-step:has(.track-seg:focus-visible) {
    position: relative; z-index: 1;
    outline: 2px solid var(--color-accent); outline-offset: 1px; border-radius: var(--radius-sm);
  }
  .track-seg:focus-visible { box-shadow: inset 0 0 0 2px var(--color-surface); }
}
.track-sides { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); flex: 0 1 auto; min-width: 0; max-width: 100%; }
/* A pill is one line: a name wider than the track is cut with an ellipsis (full name in the title). */
.track-side {
  display: block; flex: 0 1 auto; min-width: 0; max-width: 100%;
  height: var(--track-h); padding: 0 var(--space-3);
  border: 1px solid var(--color-border); border-radius: calc(var(--track-h) / 2);
  background: var(--color-surface); color: var(--tone-grey-text);
  font-size: var(--text-small); font-weight: var(--weight-medium); line-height: calc(var(--track-h) - 2px);
  text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
button.track-side:hover { background: var(--color-accent-pale); border-color: var(--color-accent); color: var(--color-primary); }
button.track-side:focus-visible { border-radius: calc(var(--track-h) / 2); }
.track-side.is-current { background: var(--color-accent); border-color: var(--color-accent); color: var(--color-on-primary); font-weight: var(--weight-semibold); }
.track-side.is-current.is-danger { background: var(--color-danger); border-color: var(--color-danger); }
/* Compact form (phones, or the `compact` option): one line plus a thin bar with a segment per step. */
.track-compact { display: none; flex-direction: column; gap: var(--space-2); }
.track-compact-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.track-compact-text { min-width: 0; overflow-wrap: anywhere; }
.track-compact-pos { color: var(--color-muted); }
.track-compact .btn { flex: none; }
.track-bar { display: flex; gap: 3px; }
.track-bar-seg { flex: 1 1 0; height: 4px; border-radius: 2px; background: var(--color-accent-light); }
.track-bar-seg.is-done { background: var(--color-primary); }
.track-bar-seg.is-current { background: var(--color-accent); }
.track-bar-seg.is-held { background: var(--color-border); }
.track.is-compact { padding: var(--space-3) var(--space-4); }
.track.is-compact .track-full { display: none; }
.track.is-compact .track-compact { display: flex; }

/* ---------- Tasks: tab strip, page head, task card ---------- */
/* The strip stands in for the sidebar group where the sidebar is off-canvas (below 1024px). */
.task-strip { display: none; position: relative; }
/* Tab name in a task table: one line of at most 138px, cut with an ellipsis (card lists show it in full). */
.table .tab-clip { max-width: 138px; }
/* The task tables of the tasks section (tasks.js taskTable with the tab or the stage) where the
   panel next to the sidebar is at its narrowest, 754px at 1024px: a lower floor for the title and
   a shorter tab name, so that the columns fit without scrolling sideways, also with the wider
   checkbox column of touch screens. From 1120px the usual widths fit. Below 1024px these tables
   are card lists. */
@media (min-width: 1024px) and (max-width: 1119.98px) {
  .task-table .table td.cell-primary { min-width: 140px; }
  .task-table .table .tab-clip { max-width: 104px; }
}
/* A title without a space (a pasted link) breaks inside the cell instead of widening the table. */
.task-name { overflow-wrap: anywhere; }
.task-head { display: flex; align-items: center; gap: var(--space-1) var(--space-3); flex-wrap: wrap; min-width: 0; min-height: var(--control-height); }
.task-head-name { font-size: var(--text-section); font-weight: var(--weight-semibold); overflow-wrap: anywhere; min-width: 0; }
/* The tab menu button of the toolbar: only where the page head is hidden (below 1024px). */
.tab-menu-compact { display: none; }
/* Link back to the tab of a task. From 640px the top bar carries it ("Daily Tasks / task title"). */
.back-link { display: none; align-items: center; gap: var(--space-1); align-self: flex-start; min-height: var(--control-height); font-weight: var(--weight-medium); }
.task-title { font-size: var(--text-title); font-weight: var(--weight-semibold); line-height: 1.25; overflow-wrap: anywhere; }
.tab-rows { list-style: none; margin: 0; padding: 0; }
.tab-row {
  display: flex; align-items: center; gap: var(--space-2) var(--space-3); flex-wrap: wrap;
  min-height: calc(var(--control-height) + var(--space-3)); padding: var(--space-1) var(--space-4);
  border-bottom: 1px solid var(--color-line);
}
.tab-row:last-child { border-bottom: 0; }
.tab-row-pos { flex: none; width: 20px; color: var(--color-muted); font-size: var(--text-small); text-align: right; }
.tab-row-main { display: flex; align-items: center; gap: var(--space-2); flex: 1 1 200px; flex-wrap: wrap; min-width: 0; }
.tab-row-name {
  display: inline-flex; align-items: center; min-height: var(--control-height); min-width: 0;
  font-weight: var(--weight-medium); overflow-wrap: anywhere;
}
.tab-row-tools { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; flex: 0 1 auto; min-width: 0; margin-left: auto; }

/* ---------- Email page ---------- */
.mail-view { display: flex; flex-direction: column; gap: var(--space-3); }
.mail-line { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: var(--space-2); }
.mail-line-label { color: var(--color-muted); font-size: var(--text-small); padding-top: 2px; }
.mail-body {
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-line); border-radius: var(--radius);
  background: var(--color-surface);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.attachments { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-1); }
.attachment { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; min-height: var(--control-height); }
.attachment-name { overflow-wrap: anywhere; min-width: 0; }
.picks { display: flex; gap: var(--space-1) var(--space-2); flex-wrap: wrap; align-items: center; }
.pick {
  display: inline-flex; align-items: center; min-height: max(24px, calc(var(--control-height) - 8px)); padding: 0 var(--space-2);
  border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  background: var(--color-surface); color: var(--color-primary);
  font-size: var(--text-small); cursor: pointer; max-width: 100%; overflow-wrap: anywhere; text-align: left;
}
.pick:hover { background: var(--color-accent-pale); }
.sticky-actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }

/* ---------- Settings ---------- */
.stage-list { display: flex; flex-direction: column; gap: var(--space-2); }
.stage-row { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.stage-row .stage-pos { flex: none; width: 20px; color: var(--color-muted); font-size: var(--text-small); text-align: right; }
.stage-row .input { flex: 1 1 200px; }
.stage-row .stage-flags { display: flex; align-items: center; gap: var(--space-3); flex: none; }
.stage-row .stage-tools { display: flex; align-items: center; gap: 2px; flex: none; }
.color-row { display: flex; align-items: center; gap: var(--space-2); }
.color-row .input:not([type="color"]) { flex: 1 1 auto; }
.setting-row {
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap;
  padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-line);
}
.setting-row:last-child { border-bottom: 0; }
.setting-text { flex: 1 1 260px; min-width: 0; }
.setting-title { font-weight: var(--weight-medium); }
.contact-rows { display: flex; flex-direction: column; gap: var(--space-3); }
.contact-row {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2);
  padding: var(--space-3); border: 1px solid var(--color-line); border-radius: var(--radius);
}
.contact-row-foot { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }

/* ---------- Plus panel: stage and documents under a list row (peek.js, documents.js) ---------- */
/* The toggle and the name it stands in front of. */
/* The toggle takes 30px in front of the name (--peek-lead). In a table the name keeps the room it
   had before: the floors below are the room for text in a cell at its own floor (96px in a 120px
   cell, 152px in the 180px name cell, 112px in the 140px name cell of All projects) plus the
   toggle, so names do not wrap into more lines. The table gets the 30px back from its clipped text
   (the next action, which the panel shows in full): the lists stay as wide as they were and keep
   fitting their panels. */
.peek-lead {
  --peek-lead: 30px;
  display: inline-flex; align-items: center; gap: 6px; min-width: calc(96px + var(--peek-lead)); max-width: 100%; vertical-align: middle;
}
.cell-primary .peek-lead { min-width: calc(152px + var(--peek-lead)); }
.peek-lead-text { min-width: 0; }
.table-wrap.has-peek .clip { max-width: 230px; }
@media (max-width: 1279.98px) {
  .table-wrap.has-peek .clip { max-width: 170px; }
}
@media (min-width: 1024px) {
  .projects-panel .cell-primary .peek-lead { min-width: calc(112px + var(--peek-lead)); }
  /* All projects has no clipped text among its default columns: there the two-line description
     gives the 30px (it is cut with an ellipsis and has the full text in its title). */
  .table-wrap.has-peek .clamp { max-width: 390px; }
}
.peek-toggle {
  display: inline-grid; place-items: center; flex: none;
  width: 24px; height: 24px; padding: 0;
  border: 0; border-radius: var(--radius-sm); background: transparent;
  color: var(--color-primary); cursor: pointer;
}
.peek-toggle-box {
  display: inline-grid; place-items: center;
  width: 22px; height: 22px;
  border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  background: var(--color-surface);
}
.peek-toggle-box { pointer-events: none; }
.peek-plus, .peek-minus { display: grid; place-items: center; }
.peek-minus, .peek-toggle[aria-expanded="true"] .peek-plus { display: none; }
.peek-toggle[aria-expanded="true"] .peek-minus { display: grid; }
.peek-toggle:hover .peek-toggle-box { background: var(--color-accent-pale); border-color: var(--color-accent); }
.peek-toggle[aria-expanded="true"] .peek-toggle-box { background: var(--color-primary); border-color: var(--color-primary); color: var(--color-on-primary); }
/* A row can carry one toggle for the table and one for the card list (projects.js): one shows at a time. */
.peek-cards-only { display: none; }

/* The open row and its panel read as one block: the same tint and a blue line on the left. */
.table tr.is-peek-open > td { background: var(--color-hover); border-bottom-color: transparent; }
.table tr.is-peek-open > td:first-child, .table tr.peek-row > td.peek-cell { box-shadow: inset 3px 0 0 var(--color-accent); }
.table tr.peek-row > td.peek-cell { height: auto; padding: 0; background: var(--color-hover); }
/* The panel never takes part in the column widths of its table (width 0, then stretched), so opening
   it does not move the columns. In a table that scrolls sideways it stays in view, as wide as the
   part of the table that shows (--peek-width is set by peek.js). */
.peek-panel {
  position: sticky; left: 0;
  width: 0; min-width: min(100%, var(--peek-width, 100%));
  padding: 0 var(--space-4) var(--space-4);
  font-weight: var(--weight-regular); white-space: normal; text-align: left;
}
.peek-body { min-width: 0; padding-top: var(--space-3); }
.peek-body > .state { padding: var(--space-4); }
.peek-stage { display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; }
.peek-meta { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-5); min-width: 0; overflow-wrap: anywhere; }
.peek-meta-item { display: inline-flex; gap: 6px; min-width: 0; }
.peek-meta-item > .muted { flex: none; }
.peek-heading {
  display: flex; align-items: baseline; gap: var(--space-2);
  font-size: var(--text-small); font-weight: var(--weight-semibold); color: var(--color-primary);
}
.peek-tasks { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-1); min-width: 0; }
.peek-task-list {
  list-style: none; margin: 0; padding: 0; align-self: stretch;
  background: var(--color-surface); border: 1px solid var(--color-line); border-radius: var(--radius-lg);
}
.peek-task {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: var(--space-1) var(--space-3);
  min-height: 36px; padding: var(--space-1) var(--space-3);
  border-bottom: 1px solid var(--color-line);
}
.peek-task:last-child { border-bottom: 0; }
.peek-task-name { flex: 1 1 240px; min-width: 0; overflow-wrap: anywhere; font-weight: var(--weight-medium); }
.peek-task-meta { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-1) var(--space-3); min-width: 0; }
.peek-more, .peek-open { font-weight: var(--weight-medium); }
/* A line of the status history: the note of a stage change stands under the two stage names. */
.peek-change-note { display: block; font-weight: var(--weight-regular); color: var(--color-muted); white-space: pre-wrap; }
/* Client rows: one block per project. */
.peek-deal { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }
.peek-deal + .peek-deal { padding-top: var(--space-3); border-top: 1px solid var(--color-line); }
.peek-deal-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0 var(--space-2); min-width: 0; }
.peek-deal-name { font-weight: var(--weight-semibold); overflow-wrap: anywhere; min-width: 0; }

/* Documents by stage (the Documents tab of the plus panel and the Documents panel of the deal card). */
.docs { display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; }
.peek-body .docs {
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface); border: 1px solid var(--color-line); border-radius: var(--radius-lg);
}
.docs-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-3); }
.docs-project { display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; }
.docs-project + .docs-project { padding-top: var(--space-3); border-top: 1px solid var(--color-line); }
.docs-group { min-width: 0; }
.docs-group-head { display: flex; align-items: center; gap: var(--space-2); min-height: 24px; min-width: 0; font-weight: var(--weight-semibold); color: var(--color-primary); }
.docs-group-name { min-width: 0; overflow-wrap: anywhere; }
.docs-group-head .count { flex: none; }
/* The mark in front of a stage name: the colors and shapes of the step on the status track. */
.stage-mark {
  display: inline-grid; place-items: center; flex: none;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--color-accent-pale); color: var(--tone-grey-text);
  box-shadow: inset 0 0 0 1px var(--color-border);
}
.stage-mark.is-done { background: var(--color-primary); color: var(--color-on-primary); box-shadow: none; }
.stage-mark.is-current { background: var(--color-accent); color: var(--color-on-primary); box-shadow: none; }
.stage-mark.is-held { background: var(--color-accent-light); color: var(--color-primary); box-shadow: none; }
/* The lists line up with the stage names, to the right of the marks. */
.docs-list { list-style: none; margin: 0 0 0 28px; padding: 0; }
.docs-none { margin-left: 28px; font-size: var(--text-small); }
.docs > .docs-none { margin-left: 0; font-size: var(--text-body); }
.docs-later { font-size: var(--text-small); }
/* A document line. The icon and the menu button stand next to the first line of text, also when
   the title or the details wrap to more lines on a narrow screen. */
.doc { display: flex; align-items: flex-start; gap: var(--space-2); padding: 1px 0; border-bottom: 1px solid var(--color-line); }
.doc:last-child { border-bottom: 0; }
.doc-icon { display: inline-grid; place-items: center; flex: none; width: 20px; height: var(--control-height); color: var(--color-muted); }
.doc-main {
  display: flex; flex: 1 1 auto; flex-wrap: wrap; align-items: baseline; gap: 0 var(--space-4); min-width: 0;
  padding: calc((var(--control-height) - 1.45em) / 2) 0;
}
.doc-name { display: flex; flex: 1 1 260px; flex-wrap: wrap; align-items: baseline; gap: 0 var(--space-2); min-width: 0; }
.doc-title { min-width: 0; overflow-wrap: anywhere; font-weight: var(--weight-medium); }
.doc-sub { min-width: 0; overflow-wrap: anywhere; }
.doc-meta { display: flex; flex-wrap: wrap; gap: 0 var(--space-3); min-width: 0; }
/* A button that reads as a link: View and the title of a file that opens in the preview dialog. */
.link-button { padding: 0; border: 0; background: none; font: inherit; text-align: left; color: var(--color-accent); cursor: pointer; }
.link-button:hover { text-decoration: underline; }
/* The simplified preview of a Word, Excel or PowerPoint file. Tables scroll sideways inside it. */
.pv { display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; margin-top: var(--space-4); }
.pv-part { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }
.pv-slide { padding-top: var(--space-3); border-top: 1px solid var(--color-line); }
.pv-heading { margin: 0; font-size: var(--text-section); font-weight: var(--weight-semibold); overflow-wrap: anywhere; }
.pv-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.pv-table-wrap { max-width: 100%; overflow-x: auto; border: 1px solid var(--color-line); border-radius: var(--radius); }
.pv-table { border-collapse: collapse; font-size: var(--text-small); }
.pv-table td { padding: 4px 8px; border: 1px solid var(--color-line); vertical-align: top; white-space: pre-wrap; min-width: 48px; max-width: 320px; overflow-wrap: anywhere; }
/* The two actions of a file, View and Download, side by side at the end of its line. */
.doc-actions { display: flex; flex: none; align-items: baseline; gap: var(--space-4); }
.doc-action { font-weight: var(--weight-medium); white-space: nowrap; }
/* Upload dialog: progress while the files go up, then the files that failed with their reasons. */
.upload-status { display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-4); color: var(--color-muted); overflow-wrap: anywhere; }
.upload-status .spinner { flex: none; }
.upload-status > span { min-width: 0; }
.upload-result {
  margin-top: var(--space-4); padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-danger); border-radius: var(--radius);
  background: var(--color-danger-pale); overflow-wrap: anywhere;
}
.upload-result-title { font-weight: var(--weight-semibold); color: var(--color-danger); }
.upload-failed { margin: var(--space-1) 0 0; padding-left: 18px; }

/* ---------- Knowledge base ---------- */
/* An entry line: icon, then title, excerpt and details one under the other, then the row menu.
   The icon and the menu button stand next to the first line, also when the text wraps. */
.kb-entries { list-style: none; margin: 0; padding: 0; }
.kb-entry { display: flex; align-items: flex-start; gap: var(--space-2); padding: var(--space-1) var(--space-4); border-bottom: 1px solid var(--color-line); }
.kb-entry:last-child { border-bottom: 0; }
.kb-entry-main {
  display: flex; flex: 1 1 auto; flex-direction: column; gap: 2px; min-width: 0;
  padding: calc((var(--control-height) - 1.45em) / 2) 0;
}
.kb-entry-name { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 var(--space-2); min-width: 0; }
/* At most three lines of the text: the list stays easy to scan, also on a phone. */
.kb-excerpt {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; overflow: hidden;
  min-width: 0; overflow-wrap: anywhere; color: var(--color-text);
}
.kb-none { padding: var(--space-3) var(--space-4); }
/* The page of one entry. The text keeps its line breaks and a comfortable line length. */
.kb-head { display: flex; align-items: flex-start; flex-wrap: wrap; gap: var(--space-3); min-width: 0; }
.kb-head-main { display: flex; flex: 1 1 320px; flex-direction: column; gap: var(--space-2); min-width: 0; }
.kb-head-meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-3); min-width: 0; }
.kb-text { max-width: 76ch; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; }
.kb-target { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-3); min-width: 0; }
.kb-target-text { min-width: 0; overflow-wrap: anywhere; }

/* ============================================================
   Below 1440px detail pages use one column. Below 1280px the
   low-priority table columns hide and dashboard pairs stack.
   ============================================================ */
@media (max-width: 1439.98px) {
  .layout-2 { grid-template-columns: minmax(0, 1fr); }
}
/* A column for the wide table only (ui.js dataTable, `wide`): hidden where the table has the least
   room. Card lists (phones, cards: 'tablet') show its value like any other. */
@media (min-width: 1024px) and (max-width: 1279.98px) {
  .table .col-wide { display: none; }
}
@media (max-width: 1279.98px) {
  .table .col-low { display: none; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .clip { max-width: 200px; }
}

/* ============================================================
   Tablet and phone (below 1024px): off-canvas sidebar.
   ============================================================ */
@media (max-width: 1023.98px) {
  .sidebar {
    width: min(280px, 84vw);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.18s ease, visibility 0.18s;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .nav-open .sidebar { transform: none; visibility: visible; }
  .nav-open .nav-backdrop { display: block; position: fixed; inset: 0; z-index: 39; background: var(--color-backdrop); }
  .nav-item, .nav-sub-item { min-height: 44px; }
  .main { margin-left: 0; }
  .task-strip {
    display: flex; gap: var(--space-1);
    margin: calc(var(--space-5) * -1) calc(var(--page-gutter) * -1) 0;
    padding: 0 var(--page-gutter);
    background: var(--color-surface); border-bottom: 1px solid var(--color-line);
    overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .task-strip::-webkit-scrollbar { display: none; }
  .task-strip .tab { text-decoration: none; }
  .task-strip .tab .icon { flex: none; }
  /* The strip names the tab and its count, so the page head only repeats them from 1024px. The tab
     menu moves to the end of the toolbar. */
  .task-head { display: none; }
  .tab-menu-compact { display: inline-grid; }
  .icon-btn.menu-btn { display: inline-grid; margin-left: calc(var(--space-2) * -1); }
  .detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .board-picker { display: block; }
  /* Plus toggle: a 44px tap target. The negative margins keep rows and card heads as high as before. */
  .peek-toggle { width: 44px; height: 44px; margin: -10px 0 -10px -10px; }
  .peek-toggle-box { width: 26px; height: 26px; }
  .peek-lead { --peek-lead: 34px; gap: 0; }
}

/* ============================================================
   Tablet (640px to 1023px): a table that asks for it (ui.js dataTable with cards: 'tablet', used by
   the dashboard "All projects") is a stacked card list here too, instead of scrolling sideways.
   These rules repeat the phone card rules further down with the .cards-tablet prefix: keep the two
   in step.
   ============================================================ */
@media (min-width: 640px) and (max-width: 1023.98px) {
  .table-wrap.cards-tablet, .table-wrap.cards-tablet.is-fit { overflow-x: visible; }
  .cards-tablet .table, .cards-tablet .table tbody { display: block; width: 100%; }
  .cards-tablet .table thead { display: none; }
  .cards-tablet .table tr {
    display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: start;
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-line);
  }
  .cards-tablet .table tbody tr:last-child { border-bottom: 0; }
  .cards-tablet .table tr.clickable:hover td { background: transparent; }
  .cards-tablet .table tr.clickable:hover, .cards-tablet .table tr.clickable:active { background: var(--color-hover); }
  .cards-tablet .table td:not(.cell-primary):not(.cell-check):not(.cell-chip):not(.cell-action):not(.nowrap) { min-width: 0; }
  .cards-tablet .table td, .cards-tablet .table td:first-child, .cards-tablet .table td:last-child {
    display: block; grid-column: 1 / -1;
    height: auto; min-width: 0; padding: 2px 0; border: 0;
    text-align: left; white-space: normal; overflow-wrap: anywhere;
  }
  .cards-tablet .table td[data-label] { display: grid; grid-template-columns: 108px minmax(0, 1fr); column-gap: var(--space-2); align-items: baseline; }
  .cards-tablet .table td[data-label]::before { content: attr(data-label); color: var(--color-muted); font-size: var(--text-small); }
  .cards-tablet .table .cell-value { min-width: 0; overflow-wrap: anywhere; }
  .cards-tablet .table td.cell-primary { grid-column: 2; grid-row: 1; min-width: 0; font-weight: var(--weight-semibold); padding-bottom: var(--space-1); }
  .cards-tablet .table td.cell-check { grid-column: 1; grid-row: 1; width: auto; padding: 0 var(--space-2) 0 0; margin: -10px 0 -10px -10px; }
  .cards-tablet .table td.cell-chip { grid-column: 3; grid-row: 1; padding-left: var(--space-2); justify-self: end; }
  .cards-tablet .table td.cell-mobile-hide, .cards-tablet .table td.is-empty, .cards-tablet .table td.col-low { display: none; }
  .cards-tablet .table td.cell-action { display: flex; flex-wrap: wrap; gap: var(--space-2); padding-top: var(--space-2); white-space: normal; }
  .cards-tablet .table td.cell-action .btn-quiet { padding: 0 var(--space-3); border: 1px solid var(--color-border); color: var(--color-primary); }
  .cards-tablet .table .table-empty { display: block; padding: 0; }
  .cards-tablet .table .table-empty td { padding: var(--space-5) var(--space-4); text-align: center; }
  .cards-tablet .table .clip { display: inline; max-width: none; white-space: normal; }
  .cards-tablet .table .clamp { display: block; min-width: 0; max-width: none; overflow: visible; -webkit-line-clamp: none; line-clamp: none; }
  /* Plus panel on cards: the client line with the toggle heads the card, the project name follows,
     and the panel opens inside the card. Keep in step with the phone rules further down. */
  .cards-tablet .peek-cards-only { display: inline-grid; }
  .cards-tablet .peek-table-only { display: none; }
  .cards-tablet .peek-lead { min-width: 0; }
  .cards-tablet .table tr.row-peek-head > td.cell-peek-head { display: block; grid-column: 1 / 3; grid-row: 1; padding: 0 0 2px; }
  .cards-tablet .table tr.row-peek-head > td.cell-peek-head::before { content: none; }
  .cards-tablet .table tr.row-peek-head > td.cell-primary { grid-column: 1 / -1; grid-row: 2; }
  .cards-tablet .table tr.is-peek-open { padding-bottom: var(--space-2); border-bottom: 0; background: var(--color-hover); box-shadow: inset 3px 0 0 var(--color-accent); }
  .cards-tablet .table tr.is-peek-open > td, .cards-tablet .table tr.is-peek-open > td:first-child { background: transparent; box-shadow: none; }
  .cards-tablet .table tr.peek-row { display: block; padding: 0; background: var(--color-hover); box-shadow: inset 3px 0 0 var(--color-accent); }
  .cards-tablet .table tr.peek-row > td.peek-cell { display: block; padding: 0; background: transparent; box-shadow: none; }
  .cards-tablet .peek-panel { position: static; width: auto; min-width: 0; padding: 0 var(--space-4) var(--space-3); }
}

/* ============================================================
   Phone (below 640px): bottom tab bar, card lists, sheets.
   ============================================================ */
@media (max-width: 639.98px) {
  .only-phone { display: revert !important; }
  .not-phone { display: none !important; }

  /* Top bar: menu, title, +, bell, avatar */
  .topbar-inner { gap: var(--space-1); }
  .page-title-parent, .page-title-sep { display: none; }
  .topbar-actions { gap: 0; }
  .new-btn { width: 44px; padding: 0; }
  .new-btn .icon { display: block; }
  .new-btn-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  .user-btn { width: 44px; padding: 0; justify-content: center; }
  .user-name, .user-btn .icon { display: none; }
  .content {
    padding-top: var(--space-3);
    padding-bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom) + var(--space-5));
  }
  .page { gap: var(--space-3); }

  /* Bottom tab bar */
  .tabbar {
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    height: calc(var(--tabbar-height) + env(safe-area-inset-bottom));
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    background: var(--color-surface); border-top: 1px solid var(--color-line);
  }
  .tabbar-item {
    display: flex; align-items: center; justify-content: center;
    min-width: 0; padding: 0 2px;
    border-top: 2px solid transparent;
    color: var(--color-muted); font-size: var(--text-small); font-weight: var(--weight-medium);
    text-decoration: none; white-space: nowrap;
  }
  .tabbar-item:hover { text-decoration: none; }
  .tabbar-item.active { color: var(--color-primary); border-top-color: var(--color-primary); font-weight: var(--weight-semibold); }
  .tabbar-item:focus-visible { outline-offset: -3px; }

  /* Forms */
  .form-grid { grid-template-columns: minmax(0, 1fr); gap: var(--space-3); }
  .contact-row { grid-template-columns: minmax(0, 1fr); }
  .login-card { padding: var(--space-5) var(--space-4); }

  /* Tables become stacked card lists. One card per row: primary line, chip top right,
     then labelled secondary lines. Hints come from the column definitions in ui.js dataTable. */
  .table-wrap, .table-wrap.is-fit { overflow-x: visible; }
  .table, .table tbody { display: block; width: 100%; }
  .table thead { display: none; }
  .table tr {
    display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: start;
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-line);
  }
  .table tbody tr:last-child { border-bottom: 0; }
  .table tr.clickable:hover td { background: transparent; }
  .table tr.clickable:active { background: var(--color-hover); }
  .table td:not(.cell-primary):not(.cell-check):not(.cell-chip):not(.cell-action):not(.nowrap) { min-width: 0; }
  .table td, .table td:first-child, .table td:last-child {
    display: block; grid-column: 1 / -1;
    height: auto; min-width: 0; padding: 2px 0; border: 0;
    text-align: left; white-space: normal; overflow-wrap: anywhere;
  }
  .table td[data-label] { display: grid; grid-template-columns: 108px minmax(0, 1fr); column-gap: var(--space-2); align-items: baseline; }
  .table td[data-label]::before { content: attr(data-label); color: var(--color-muted); font-size: var(--text-small); }
  .table .cell-value { min-width: 0; overflow-wrap: anywhere; }
  .table td.cell-primary { grid-column: 2; grid-row: 1; min-width: 0; font-weight: var(--weight-semibold); padding-bottom: var(--space-1); }
  .table td.cell-check { grid-column: 1; grid-row: 1; width: auto; padding: 0 var(--space-2) 0 0; margin: -10px 0 -10px -10px; }
  .table td.cell-chip { grid-column: 3; grid-row: 1; padding-left: var(--space-2); justify-self: end; }
  .table td.cell-mobile-hide, .table td.is-empty, .table td.col-low { display: none; }
  .table td.cell-action { display: flex; flex-wrap: wrap; gap: var(--space-2); padding-top: var(--space-2); white-space: normal; }
  .table td.cell-action .btn-quiet { padding: 0 var(--space-3); border: 1px solid var(--color-border); color: var(--color-primary); }
  .table .table-empty { display: block; padding: 0; }
  .table .table-empty td { padding: var(--space-5) var(--space-4); text-align: center; }
  .table .clip { display: inline; max-width: none; white-space: normal; }
  .table .clamp { display: block; min-width: 0; max-width: none; overflow: visible; -webkit-line-clamp: none; line-clamp: none; }
  .inline-set { min-width: 0; width: 100%; }
  .date-inline { flex: 1 1 140px; width: auto; }
  /* Plus panel on cards: the client line with the toggle heads the card, the project name follows,
     and the panel opens inside the card. Keep in step with the .cards-tablet rules above. */
  .peek-cards-only { display: inline-grid; }
  .peek-table-only { display: none; }
  .peek-lead { min-width: 0; }
  .table tr.row-peek-head > td.cell-peek-head { display: block; grid-column: 1 / 3; grid-row: 1; padding: 0 0 2px; }
  .table tr.row-peek-head > td.cell-peek-head::before { content: none; }
  .table tr.row-peek-head > td.cell-primary { grid-column: 1 / -1; grid-row: 2; }
  .table tr.is-peek-open { padding-bottom: var(--space-2); border-bottom: 0; background: var(--color-hover); box-shadow: inset 3px 0 0 var(--color-accent); }
  .table tr.is-peek-open > td, .table tr.is-peek-open > td:first-child { background: transparent; box-shadow: none; }
  .table tr.peek-row { display: block; padding: 0; background: var(--color-hover); box-shadow: inset 3px 0 0 var(--color-accent); }
  .table tr.peek-row > td.peek-cell { display: block; padding: 0; background: transparent; box-shadow: none; }
  .peek-panel { position: static; width: auto; min-width: 0; padding: 0 var(--space-4) var(--space-3); }
  .peek-body .docs { padding: var(--space-3); }
  .docs-actions .btn { flex: 1 1 auto; }
  /* The document lines start under the stage marks: the narrow screen keeps its width for the text. */
  .docs-list { margin-left: 0; }

  /* Toolbar: search stays, other filters collapse behind the Filters button */
  .toolbar-search { flex: 1 1 0; min-width: 0; }
  .filters-toggle { display: inline-flex; flex: none; }
  .toolbar-filters { display: none; flex: 1 0 100%; flex-direction: column; align-items: stretch; }
  .toolbar-filters.open { display: flex; }
  .toolbar-filters .input { width: 100%; max-width: none; }
  .toolbar-spacer { display: none; }
  .toolbar-actions { flex: 1 0 100%; }
  .toolbar-actions .segmented { flex: 1 1 auto; }
  .toolbar-actions .segmented-item { flex: 1 1 0; justify-content: center; }
  .toolbar-actions > .btn { flex: 1 1 auto; }

  /* Dashboard */
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2); }
  .stats .stat:last-child:nth-child(odd) { grid-column: 1 / -1; }
  /* All projects controls: search on its own line, then the state filter (scrolls inside its
     container when it is wider than the screen), then Columns. */
  .projects-panel .panel-head { padding-right: var(--space-4); padding-bottom: var(--space-3); }
  .projects-panel .panel-actions { flex: 1 0 100%; justify-content: flex-start; }
  .projects-search { flex: 1 0 100%; }
  .segmented-scroll { flex: 1 1 100%; }
  .projects-panel .panel-actions > .btn { flex: 1 1 auto; }

  /* Detail pages: single column, one primary action plus Actions sheet */
  .detail-head { flex-direction: column; align-items: stretch; gap: var(--space-3); }
  .detail-grid { grid-template-columns: minmax(0, 1fr); gap: var(--space-3); }
  .action-bar-full { display: none; }
  .action-bar-compact { display: flex; gap: var(--space-2); width: 100%; }
  .action-bar-compact .btn { flex: 1 1 0; }
  .detail-meta .input { width: 100%; }
  .detail-meta .meta-item.wide { flex: 1 0 100%; }
  .panel-head { padding: var(--space-2) var(--space-3) var(--space-2) var(--space-4); }

  /* Deals board: swipeable columns with scroll snap */
  .board {
    margin: 0 calc(var(--page-gutter) * -1); padding: 0 var(--page-gutter) var(--space-3);
    scroll-snap-type: x mandatory; scroll-padding: 0 var(--page-gutter);
    gap: var(--space-2);
  }
  .board-col { flex: 0 0 85vw; scroll-snap-align: start; }
  .board-card .input { height: 44px; }

  /* Modals and drawers: full-screen sheets, sticky header and footer */
  .overlay { padding: 0; align-items: stretch; overflow: hidden; }
  .modal, .drawer {
    width: 100%; max-width: none; height: 100vh; height: 100dvh; max-height: none; border-radius: 0; box-shadow: none;
  }
  .modal-header { padding: calc(var(--space-1) + env(safe-area-inset-top)) var(--space-1) var(--space-1) var(--space-4); }
  .modal-body { padding: var(--space-4); }
  .modal-footer { padding: var(--space-2) var(--space-4) calc(var(--space-2) + env(safe-area-inset-bottom)); }
  .modal-footer .btn { flex: 1 1 auto; }
  .modal-footer .footer-left { margin-right: 0; flex: 1 0 100%; order: 3; }
  /* Small confirm dialogs sit at the bottom as a sheet */
  .overlay.overlay-sm { align-items: flex-end; }
  .modal-sm { height: auto; max-height: 92vh; max-height: 92dvh; border-radius: 12px 12px 0 0; }
  .modal-columns { max-width: none; }
  .modal-sm .modal-header { padding-top: var(--space-1); }

  /* Toasts above the tab bar, full width with margins */
  .toast-root {
    left: var(--space-3); right: var(--space-3); width: auto; max-width: none;
    bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom) + var(--space-2));
  }
  /* A page with a sticky action bar (the email page) keeps that strip free: toasts move under the
     top bar, whatever the height of the action bar. While a sheet is open (html.no-scroll) they stay
     at the bottom, above the sheet footer. */
  html:not(.no-scroll) body:has(.sticky-actions) .toast-root {
    bottom: auto;
    top: calc(var(--topbar-height) + env(safe-area-inset-top) + var(--space-2));
  }

  /* Status track: the compact form */
  .track { padding: var(--space-3) var(--space-4); }
  .track-full { display: none; }
  .track-compact { display: flex; }

  /* Tasks */
  .task-strip { margin-top: calc(var(--space-3) * -1); }
  .back-link { display: inline-flex; }
  .toolbar-actions .switch { flex: 1 0 100%; }
  .tab-row { padding: var(--space-2) var(--space-4); }
  .tab-row-tools { flex: 1 1 100%; margin-left: 0; }

  /* Email page */
  .mail-line { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .sticky-actions {
    position: sticky; z-index: 5;
    bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom));
    margin: var(--space-4) calc(var(--space-4) * -1) calc(var(--space-4) * -1);
    padding: var(--space-2) var(--space-4);
    background: var(--color-surface); border-top: 1px solid var(--color-line);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  }
  .sticky-actions .btn { flex: 1 1 auto; }

  /* Settings */
  .stage-row { padding: var(--space-2) 0; border-bottom: 1px solid var(--color-line); }
  .stage-row .input { flex: 1 1 calc(100% - 36px); }
  .stage-row .stage-flags { margin-left: 28px; flex: 1 1 auto; }
  .setting-row { flex-direction: column; gap: var(--space-2); }
  .setting-row .setting-text { flex: none; }
}

/* ============================================================
   Touch devices: 44px tap targets. Nothing relies on hover.
   ============================================================ */
@media (pointer: coarse) {
  .btn { min-width: 44px; }
  .check-hit { width: 44px; height: 44px; }
  .check input, .check-hit input { width: 20px; height: 20px; }
  .table td.cell-check, .table th.cell-check { width: 52px; }
  .toast .icon-btn { width: 44px; height: 44px; margin: -8px -4px -8px 0; }
  .segmented { padding: 0; }
  .segmented-item { height: var(--control-height); min-width: 44px; justify-content: center; }
  .th-sort { height: 44px; min-width: 44px; }
  .tab { min-width: 44px; justify-content: center; }
  .switch-track { width: 44px; height: 24px; border-radius: 12px; }
  .switch-track::after { width: 20px; height: 20px; }
  .switch input:checked + .switch-track::after { transform: translateX(20px); }
  .pick { min-height: 44px; padding: 0 var(--space-3); }
  /* Plus toggle: a 44px tap target. The negative margins keep the rows as high as before. */
  .peek-toggle { width: 44px; height: 44px; margin: -10px 0 -10px -10px; }
  .peek-toggle-box { width: 26px; height: 26px; }
  .peek-lead { --peek-lead: 34px; gap: 0; }
  .peek-task { min-height: 44px; }
  /* A track the user may change is 44px high on touch screens; a read only one keeps its height. */
  .track.is-selectable { --track-h: 44px; }
  .track.is-selectable .track-seg, .track.is-selectable .track-side { min-width: 44px; }
  .chip { height: 24px; }
  /* Inline links inside tables and timelines get a larger hit area without changing the layout */
  .table td a, .timeline a, .list a, .detail-value a, .detail-meta a, .board-card a { position: relative; }
  .table td a::after, .timeline a::after, .list a::after, .detail-value a::after, .detail-meta a::after, .board-card a::after {
    content: ""; position: absolute; left: -6px; right: -6px; top: -14px; bottom: -14px;
  }
  /* The pencil mark of a card field: a 44px tap target that keeps the line as high as before. */
  .edit-field-mark { position: relative; }
  .edit-field-mark::after { content: ""; position: absolute; left: -11px; right: -11px; top: -12px; bottom: -11px; }
  /* View and Download of a file: the same larger hit area, without touching each other. */
  .doc-action { position: relative; }
  .doc-action::after { content: ""; position: absolute; left: -8px; right: -8px; top: -14px; bottom: -14px; }
  /* The small text line of a board card (related client or deal) is 15px high: one pixel more on each side. */
  .board-card-line a::after { top: -15px; bottom: -15px; }
}
@media (pointer: coarse) and (min-width: 1024px) {
  /* The Tab link of a task table sits in a box that cuts a long name, and that box would cut the
     enlarged hit area of the link as well: here the box itself is 44px high, like the checkbox of
     the same row. Card lists (below 1024px) do not cut the name. */
  .table .tab-clip { line-height: 44px; }
}
@media (pointer: coarse) and (min-width: 640px) {
  /* A block, not a flex box: the ellipsis of a long name needs the text directly in a block. */
  .page-title-parent { display: block; min-width: 44px; min-height: 44px; line-height: 44px; text-align: center; }
}
