/*
 * MGH CRM design system.
 *
 * Blueprint 002: consistent typography, standard spacing, reusable components,
 * status badges, colour-coded priorities, light and dark themes.
 *
 * Themes are driven by tokens only. No component hard-codes a colour, so a
 * future tenant-branding feature changes one block rather than every rule.
 */

/* ---------------------------------------------------------------- tokens */
:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-8: 3rem;

  --radius-sm: 4px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-full: 999px;

  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.875rem;
  --text-md: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.375rem;
  --text-2xl: 1.75rem;

  --sidebar-width: 240px;
  --header-height: 56px;

  --transition: 140ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Light is the default; dark follows the OS unless the user overrides it. */
:root,
:root[data-theme="light"] {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #fbfbfc;
  --surface-hover: #f2f4f7;
  --border: #e3e6ea;
  --border-strong: #cbd2d9;

  --text: #16191d;
  --text-muted: #5b6470;
  --text-subtle: #8a939f;

  --accent: #2f6fed;
  --accent-hover: #2559c9;
  --accent-soft: #e8f0fe;
  --accent-text: #ffffff;

  --success: #0f8a4a;
  --success-soft: #e3f5eb;
  --warning: #b26a00;
  --warning-soft: #fdf1de;
  --danger: #c02b2b;
  --danger-soft: #fdeaea;
  --info: #1b6f8a;
  --info-soft: #e2f2f7;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow: 0 4px 12px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.14);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1c2128;
    --surface-hover: #222831;
    --border: #262c35;
    --border-strong: #363e49;

    --text: #e6e9ee;
    --text-muted: #9aa4b2;
    --text-subtle: #6b7684;

    --accent: #5b8dff;
    --accent-hover: #7ba3ff;
    --accent-soft: #1a2440;
    --accent-text: #0f1216;

    --success: #3fbf7f;
    --success-soft: #12281d;
    --warning: #e0a44a;
    --warning-soft: #2a2011;
    --danger: #f0716f;
    --danger-soft: #2e1717;
    --info: #4fb3d0;
    --info-soft: #12262d;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.55);
  }
}

:root[data-theme="dark"] {
  --bg: #0f1216;
  --surface: #171b21;
  --surface-2: #1c2128;
  --surface-hover: #222831;
  --border: #262c35;
  --border-strong: #363e49;

  --text: #e6e9ee;
  --text-muted: #9aa4b2;
  --text-subtle: #6b7684;

  --accent: #5b8dff;
  --accent-hover: #7ba3ff;
  --accent-soft: #1a2440;
  --accent-text: #0f1216;

  --success: #3fbf7f;
  --success-soft: #12281d;
  --warning: #e0a44a;
  --warning-soft: #2a2011;
  --danger: #f0716f;
  --danger-soft: #2e1717;
  --info: #4fb3d0;
  --info-soft: #12262d;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.55);
}

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

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

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.3; }
h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }
h4 { font-size: var(--text-md); }
p { margin: 0 0 var(--space-3); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; height: auto; }

/* Blueprint 002 accessibility: focus must always be clearly visible. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; top: -100px; left: var(--space-4); z-index: 200;
  padding: var(--space-2) var(--space-4);
  background: var(--accent); color: var(--accent-text);
  border-radius: var(--radius);
}
.skip-link:focus { top: var(--space-2); }

/* ---------------------------------------------------------------- layout */
.app { display: grid; grid-template-columns: var(--sidebar-width) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}

.sidebar__brand {
  display: flex; align-items: center; gap: var(--space-2);
  height: var(--header-height); padding: 0 var(--space-4);
  border-bottom: 1px solid var(--border);
  font-weight: 700; font-size: var(--text-md); color: var(--text);
}
.sidebar__brand:hover { text-decoration: none; }

.sidebar__mark {
  width: 26px; height: 26px; flex-shrink: 0;
  border-radius: var(--radius-sm);
  background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center;
  font-size: var(--text-xs); font-weight: 700;
}

.sidebar__nav { flex: 1; overflow-y: auto; padding: var(--space-3) var(--space-2); }
.sidebar__section { margin-bottom: var(--space-4); }
.sidebar__label {
  padding: 0 var(--space-3) var(--space-1);
  font-size: var(--text-xs); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-subtle);
}

.nav-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  color: var(--text-muted); font-weight: 500;
  transition: background var(--transition), color var(--transition);
}
.nav-item:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.nav-item--active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item__icon { width: 18px; text-align: center; flex-shrink: 0; opacity: 0.85; }

.sidebar__footer { border-top: 1px solid var(--border); padding: var(--space-3); }

.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: var(--header-height);
  display: flex; align-items: center; gap: var(--space-3);
  padding: 0 var(--space-5);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 40;
}

.content { padding: var(--space-5); flex: 1; max-width: 1400px; width: 100%; }

/* ---------------------------------------------------------------- search */
.search { position: relative; flex: 1; max-width: 520px; }

.search__input {
  width: 100%; height: 36px;
  padding: 0 var(--space-3) 0 var(--space-8);
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); color: var(--text); font-size: var(--text-base);
  font-family: inherit;
}
.search__input:focus { border-color: var(--accent); outline: none; background: var(--surface); }
.search__icon {
  position: absolute; left: var(--space-3); top: 50%; transform: translateY(-50%);
  color: var(--text-subtle); pointer-events: none;
}
.search__hint {
  position: absolute; right: var(--space-2); top: 50%; transform: translateY(-50%);
  font-size: var(--text-xs); color: var(--text-subtle);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 1px var(--space-1); pointer-events: none;
}

.search__results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 60;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  max-height: 60vh; overflow-y: auto; padding: var(--space-2);
}
.search__results[hidden] { display: none; }
.search__group-label {
  padding: var(--space-2) var(--space-3) var(--space-1);
  font-size: var(--text-xs); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-subtle);
}
.search__result {
  display: block; padding: var(--space-2) var(--space-3);
  border-radius: var(--radius); color: var(--text);
}
.search__result:hover, .search__result--active { background: var(--surface-hover); text-decoration: none; }
.search__result-title { font-weight: 500; }
.search__result-sub { font-size: var(--text-sm); color: var(--text-muted); }
.search__empty { padding: var(--space-4); text-align: center; color: var(--text-muted); }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  height: 36px; padding: 0 var(--space-4);
  border: 1px solid transparent; border-radius: var(--radius);
  font-family: inherit; font-size: var(--text-base); font-weight: 500;
  cursor: pointer; white-space: nowrap;
  transition: background var(--transition), border-color var(--transition), opacity var(--transition);
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn--primary { background: var(--accent); color: var(--accent-text); }
.btn--primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn--secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn--secondary:hover:not(:disabled) { background: var(--surface-hover); }

.btn--ghost { background: transparent; color: var(--text-muted); }
.btn--ghost:hover:not(:disabled) { background: var(--surface-hover); color: var(--text); }

.btn--danger { background: var(--danger); color: #fff; }

.btn--sm { height: 30px; padding: 0 var(--space-3); font-size: var(--text-sm); }
.btn--icon { width: 36px; padding: 0; }

/* ---------------------------------------------------------------- cards */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}
.card__header {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border);
}
.card__title { font-size: var(--text-md); font-weight: 600; }
.card__body { padding: var(--space-5); }
.card__body--flush { padding: 0; }
.card__footer { padding: var(--space-3) var(--space-5); border-top: 1px solid var(--border); }

/* ---------------------------------------------------------------- stats */
.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-4); margin-bottom: var(--space-5);
}
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: var(--space-4) var(--space-5);
}
.stat__label {
  font-size: var(--text-xs); font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--text-subtle); margin-bottom: var(--space-2);
}
.stat__value { font-size: var(--text-2xl); font-weight: 650; line-height: 1; }
.stat__meta { font-size: var(--text-sm); color: var(--text-muted); margin-top: var(--space-2); }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--text-base); }
.table th {
  text-align: left; padding: var(--space-3) var(--space-4);
  font-size: var(--text-xs); font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--text-subtle);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); }
.table tbody tr { transition: background var(--transition); }
.table tbody tr:hover { background: var(--surface-hover); }
.table tbody tr:last-child td { border-bottom: none; }
.table__primary { font-weight: 550; color: var(--text); }
.table__muted { color: var(--text-muted); }

/* ---------------------------------------------------------------- badges */
.badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 2px var(--space-2); border-radius: var(--radius-full);
  font-size: var(--text-xs); font-weight: 600; white-space: nowrap;
}
.badge--lead     { background: var(--info-soft); color: var(--info); }
.badge--prospect { background: var(--warning-soft); color: var(--warning); }
.badge--customer { background: var(--success-soft); color: var(--success); }
.badge--dormant  { background: var(--surface-hover); color: var(--text-muted); }
.badge--lost     { background: var(--danger-soft); color: var(--danger); }
.badge--neutral  { background: var(--surface-hover); color: var(--text-muted); }
/* Tone rather than meaning, for states that are not customer lifecycle stages —
   an account being suspended is not the same idea as a customer being lost, and
   reusing that class would make the next reader look for a customer. */
.badge--success  { background: var(--success-soft); color: var(--success); }
.badge--warning  { background: var(--warning-soft); color: var(--warning); }
.badge--danger   { background: var(--danger-soft); color: var(--danger); }

/* ---------------------------------------------------------------- forms */
.field { margin-bottom: var(--space-4); }
.field__label {
  display: block; margin-bottom: var(--space-2);
  font-size: var(--text-sm); font-weight: 550; color: var(--text);
}
.field__required { color: var(--danger); margin-left: 2px; }

.input, .select, .textarea {
  width: 100%; padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font-family: inherit; font-size: var(--text-base); line-height: 1.5;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input[aria-invalid="true"], .select[aria-invalid="true"] { border-color: var(--danger); }
.textarea { min-height: 90px; resize: vertical; }

.field__error { margin-top: var(--space-1); font-size: var(--text-sm); color: var(--danger); }
.field__help { margin-top: var(--space-1); font-size: var(--text-sm); color: var(--text-muted); }

.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 var(--space-4); }

.form-section {
  padding-bottom: var(--space-4); margin-bottom: var(--space-4);
  border-bottom: 1px solid var(--border);
}
.form-section:last-of-type { border-bottom: none; margin-bottom: 0; }
.form-section__title { font-size: var(--text-sm); font-weight: 650; margin-bottom: var(--space-3); }

/* -------------------------------------------------------- inline editing */
/* Blueprint 002: inline editing and auto-save, so the 360 screen never needs a
   separate edit form. */
.inline-edit {
  display: block; width: 100%;
  padding: var(--space-1) var(--space-2); margin: calc(var(--space-1) * -1) calc(var(--space-2) * -1);
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: transparent; color: inherit;
  font: inherit; cursor: text;
  transition: background var(--transition), border-color var(--transition);
}
.inline-edit:hover { background: var(--surface-hover); border-color: var(--border); }
.inline-edit:focus { outline: none; background: var(--surface); border-color: var(--accent); cursor: text; }
.inline-edit--saving { opacity: 0.6; }
.inline-edit--saved { border-color: var(--success); background: var(--success-soft); }
.inline-edit--error { border-color: var(--danger); background: var(--danger-soft); }
.inline-edit--empty::before { content: attr(data-placeholder); color: var(--text-subtle); }

/* ---------------------------------------------------------------- 360 */
.profile-header {
  display: flex; align-items: flex-start; gap: var(--space-4);
  padding: var(--space-5); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  margin-bottom: var(--space-5);
}
.profile-avatar {
  width: 52px; height: 52px; flex-shrink: 0; border-radius: var(--radius);
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-size: var(--text-lg); font-weight: 650;
}
.profile-meta { display: flex; flex-wrap: wrap; gap: var(--space-3); margin-top: var(--space-2); }
.profile-meta__item { font-size: var(--text-sm); color: var(--text-muted); }

.profile-grid { display: grid; grid-template-columns: 1fr 340px; gap: var(--space-5); align-items: start; }

.detail-list { display: grid; gap: var(--space-3); }
.detail-row { display: grid; grid-template-columns: 130px 1fr; gap: var(--space-3); align-items: baseline; }
.detail-row__label { font-size: var(--text-sm); color: var(--text-muted); }
.detail-row__value { min-width: 0; word-break: break-word; }

/* ---------------------------------------------------------------- timeline */
.timeline { position: relative; padding-left: var(--space-5); }
.timeline::before {
  content: ""; position: absolute; left: 7px; top: 6px; bottom: 6px;
  width: 2px; background: var(--border);
}
.timeline__item { position: relative; padding-bottom: var(--space-4); }
.timeline__item:last-child { padding-bottom: 0; }
.timeline__dot {
  position: absolute; left: calc(var(--space-5) * -1); top: 4px;
  width: 8px; height: 8px; border-radius: var(--radius-full);
  background: var(--accent); box-shadow: 0 0 0 3px var(--surface);
}
.timeline__label { font-weight: 550; }
.timeline__meta { font-size: var(--text-sm); color: var(--text-muted); margin-top: 2px; }

/* ---------------------------------------------------------------- misc */
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--space-4); margin-bottom: var(--space-5); flex-wrap: wrap;
}
.page-header__sub { color: var(--text-muted); margin-top: var(--space-1); }

.breadcrumbs { display: flex; gap: var(--space-2); font-size: var(--text-sm); margin-bottom: var(--space-3); }
.breadcrumbs a { color: var(--text-muted); }
.breadcrumbs span { color: var(--text-subtle); }

.toolbar { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; margin-bottom: var(--space-4); }

.empty { padding: var(--space-8) var(--space-5); text-align: center; }
.empty__title { font-weight: 600; margin-bottom: var(--space-2); }
.empty__text { color: var(--text-muted); margin-bottom: var(--space-4); }

.alert {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-3) var(--space-4); border-radius: var(--radius);
  margin-bottom: var(--space-4); font-size: var(--text-base);
}
.alert--success { background: var(--success-soft); color: var(--success); }
.alert--error   { background: var(--danger-soft); color: var(--danger); }
.alert--warning { background: var(--warning-soft); color: var(--warning); }
.alert--info    { background: var(--info-soft); color: var(--info); }

.toast-stack { position: fixed; bottom: var(--space-5); right: var(--space-5); z-index: 200; display: grid; gap: var(--space-2); }
.toast {
  padding: var(--space-3) var(--space-4); border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-lg); font-size: var(--text-base);
  animation: toast-in 160ms ease-out;
}
.toast--success { border-left: 3px solid var(--success); }
.toast--error { border-left: 3px solid var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.pagination { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; }
.pagination__info { font-size: var(--text-sm); color: var(--text-muted); }
.pagination__links { display: flex; gap: var(--space-1); }

.user-chip {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2); border-radius: var(--radius); width: 100%;
  background: transparent; border: none; color: var(--text);
  font: inherit; text-align: left; cursor: pointer;
}
.user-chip:hover { background: var(--surface-hover); }
.user-chip__avatar {
  width: 28px; height: 28px; flex-shrink: 0; border-radius: var(--radius-full);
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-size: var(--text-xs); font-weight: 650;
}
.user-chip__name { font-size: var(--text-sm); font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip__role { font-size: var(--text-xs); color: var(--text-subtle); }

/* ---------------------------------------------------------------- auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: var(--space-5); background: var(--bg); }
.auth__card { width: 100%; max-width: 380px; }
.auth__brand { display: flex; align-items: center; justify-content: center; gap: var(--space-2); margin-bottom: var(--space-5); font-size: var(--text-lg); font-weight: 700; }

/* ---------------------------------------------------------------- responsive */
/* Blueprint 002 is mobile-first in intent: the sidebar collapses to a bottom
   bar so the primary actions stay reachable one-handed. */
@media (max-width: 900px) {
  .profile-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed; bottom: 0; left: 0; right: 0; top: auto;
    height: auto; z-index: 50;
    border-right: none; border-top: 1px solid var(--border);
    flex-direction: row;
  }
  .sidebar__brand, .sidebar__label, .sidebar__footer { display: none; }
  .sidebar__nav { display: flex; padding: var(--space-2); width: 100%; overflow-x: auto; }
  .sidebar__section { display: flex; margin: 0; gap: var(--space-1); }
  .nav-item { flex-direction: column; gap: 2px; font-size: var(--text-xs); padding: var(--space-2); min-width: 64px; }

  .content { padding: var(--space-4) var(--space-3) calc(var(--space-8) + var(--space-6)); }
  .topbar { padding: 0 var(--space-3); }
  .search__hint { display: none; }
  .detail-row { grid-template-columns: 1fr; gap: 2px; }
  .profile-header { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

@media print {
  .sidebar, .topbar, .btn, .toolbar { display: none !important; }
  .app { grid-template-columns: 1fr; }
  .card { border: 1px solid #ddd; box-shadow: none; }
}

/* ---------------------------------------------------------------- pipeline */
/*
 * The sales pipeline board. Columns scroll horizontally on narrow screens
 * rather than reflowing, because a pipeline read as a vertical list loses the
 * stage comparison that makes it useful.
 */
.pipeline {
  display: flex;
  gap: var(--space-4);
  overflow-x: auto;
  padding-bottom: var(--space-4);
  align-items: flex-start;
}

.pipeline__column {
  flex: 0 0 280px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  max-height: calc(100vh - 320px);
  display: flex;
  flex-direction: column;
}

.pipeline__column--over {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.pipeline__header {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface-2);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.pipeline__title { font-weight: 600; font-size: var(--text-sm); }
.pipeline__total { font-size: var(--text-sm); color: var(--text-muted); margin-top: var(--space-1); }

.pipeline__cards { padding: var(--space-2); overflow-y: auto; flex: 1; }

.pipeline__card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin-bottom: var(--space-2);
  transition: box-shadow var(--transition), transform var(--transition);
}
.pipeline__card:hover { box-shadow: var(--shadow); }
.pipeline__card[draggable="true"] { cursor: grab; }
.pipeline__card--dragging { opacity: 0.45; }

.pipeline__card-title { display: block; font-weight: 550; color: var(--text); margin-bottom: var(--space-1); }
.pipeline__card-title:hover { color: var(--accent); }
.pipeline__card-value { font-size: var(--text-sm); font-weight: 550; }
.pipeline__card-meta { font-size: var(--text-xs); color: var(--text-muted); margin-top: var(--space-1); }

.pipeline__move { display: flex; gap: var(--space-1); margin-top: var(--space-2); }
.select--sm { height: 28px; padding: 0 var(--space-2); font-size: var(--text-xs); }

/* Dragging is a convenience; the select-and-move form is always present, so
   the board works with a keyboard and without JavaScript. */
@media (max-width: 720px) {
  .pipeline__column { flex-basis: 85vw; }
}

/* ------------------------------------------------------------------ calendar */

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  border-top: 1px solid var(--border);
  border-left: 1px solid var(--border);
}

.cal-grid__head {
  padding: var(--space-2);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  background: var(--surface-hover);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.cal-day {
  min-height: 7.5rem;
  padding: var(--space-2);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

/* Days from the neighbouring month. Present and real — events on them are
   fetched and shown — but visually recessed. */
.cal-day--outside { background: var(--surface-hover); }
.cal-day--outside .cal-day__number { color: var(--text-subtle); }
.cal-day--closed { background: var(--warning-soft); }
.cal-day--today { box-shadow: inset 0 0 0 2px var(--accent); }
.cal-day--over { background: var(--info-soft); }

.cal-day__head { display: flex; align-items: baseline; gap: var(--space-2); flex-wrap: wrap; }
.cal-day__number { font-size: var(--text-sm); font-weight: 600; }
.cal-day__holiday {
  font-size: var(--text-xs);
  color: var(--warning);
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cal-day__events { display: grid; gap: 2px; align-content: start; }
.cal-day__more { font-size: var(--text-xs); color: var(--text-muted); }

.cal-entry {
  display: flex;
  align-items: baseline;
  gap: var(--space-1);
  padding: 2px var(--space-1);
  border-radius: var(--radius);
  border-left: 3px solid var(--accent);
  background: var(--surface-hover);
  font-size: var(--text-xs);
  color: var(--text);
  text-decoration: none;
  overflow: hidden;
}
.cal-entry:hover { background: var(--surface); box-shadow: var(--shadow); }
.cal-entry[draggable="true"] { cursor: grab; }
.cal-entry--dragging { opacity: .45; }
.cal-entry--task { border-left-color: var(--info); }
.cal-entry--overdue { border-left-color: var(--danger); }
.cal-entry--done { opacity: .55; text-decoration: line-through; }
.cal-entry__time { font-variant-numeric: tabular-nums; color: var(--text-muted); flex: none; }
.cal-entry__title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-entry__meta { color: var(--text-subtle); margin-left: auto; flex: none; }

.cal-columns { display: grid; gap: 1px; background: var(--border); }
.cal-columns--week { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-columns--day { grid-template-columns: 1fr; }

.cal-column { background: var(--surface); padding: var(--space-3); min-height: 12rem; }
.cal-column--today { box-shadow: inset 0 0 0 2px var(--accent); }
.cal-column--closed { background: var(--warning-soft); }
.cal-column--over { background: var(--info-soft); }
.cal-column__head { margin-bottom: var(--space-2); }
.cal-column__day { font-size: var(--text-xs); text-transform: uppercase; color: var(--text-muted); }
.cal-column__date { font-weight: 600; }
.cal-column__events { display: grid; gap: var(--space-1); align-content: start; }
.cal-column__events .cal-entry { font-size: var(--text-sm); padding: var(--space-1) var(--space-2); }

.cal-agenda__day { display: flex; gap: var(--space-4); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); }
.cal-agenda__day:last-child { border-bottom: 0; }
.cal-agenda__day--today { background: var(--surface-hover); }
.cal-agenda__date { flex: none; width: 3rem; text-align: center; }
.cal-agenda__weekday { font-size: var(--text-xs); text-transform: uppercase; color: var(--text-muted); }
.cal-agenda__number { font-size: var(--text-xl, 1.25rem); font-weight: 600; line-height: 1.1; }
.cal-agenda__month { font-size: var(--text-xs); color: var(--text-muted); }
.cal-agenda__entries { flex: 1; display: grid; gap: var(--space-1); align-content: start; min-width: 0; }
.cal-agenda__entries .cal-entry { font-size: var(--text-sm); padding: var(--space-1) var(--space-2); }

/* A seven-column grid is unreadable on a phone. The month grid keeps its shape
   and scrolls; week becomes a single stacked list, which is what an agenda is —
   so the two converge rather than one becoming unusable. */
@media (max-width: 860px) {
  .cal-grid { min-width: 44rem; }
  .cal-grid-scroll { overflow-x: auto; }
  .cal-columns--week { grid-template-columns: 1fr; }
  .cal-column { min-height: auto; }
}

/* ------------------------------------------------------------- notifications */

.notif-bell { position: relative; }
.notif-bell__count {
  position: absolute;
  top: -.25rem;
  right: -.25rem;
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 .2rem;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: .65rem;
  font-weight: 700;
  line-height: 1.1rem;
  text-align: center;
}

.notif {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
}
.notif:last-child { border-bottom: 0; }
.notif:hover { background: var(--surface-hover); }
/* Unread is carried by weight and a rule, not by colour alone — colour alone
   fails for anyone who cannot distinguish it. */
.notif--unread { background: var(--surface-hover); box-shadow: inset 3px 0 0 var(--accent, #2563eb); }
.notif--unread .notif__title { font-weight: 650; }

.notif__dot { flex: none; width: .5rem; height: .5rem; border-radius: 999px; margin-top: .45rem; background: var(--text-subtle); }
.notif__dot--attention { background: var(--warning); }
.notif__dot--urgent { background: var(--danger); }

.notif__body { display: grid; gap: .15rem; min-width: 0; }
.notif__title { overflow: hidden; text-overflow: ellipsis; }
.notif__text { font-size: var(--text-sm); color: var(--text-muted); }
.notif__meta { font-size: var(--text-xs); color: var(--text-subtle); }

/* --------------------------------------------------------------------- tags */

.tag-row { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }

.tag {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .1rem .5rem;
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: 999px;
  font-size: var(--text-xs);
  background: var(--surface-hover);
  white-space: nowrap;
}
.tag__remove {
  border: 0;
  background: none;
  color: var(--text-subtle);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 0 0 .1rem;
}
.tag__remove:hover { color: var(--danger); }

.tag-add { display: inline-flex; }
.tag-add__input {
  border: 1px dashed var(--border);
  border-radius: 999px;
  background: none;
  color: var(--text-muted);
  font-size: var(--text-xs);
  padding: .1rem .6rem;
  width: 6rem;
}
.tag-add__input:focus { width: 10rem; color: var(--text); border-style: solid; outline: none; border-color: var(--accent, #2563eb); }

.input--sm { height: 30px; padding: 0 var(--space-2); font-size: var(--text-sm); }
