:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f7f8f9;
  --surface-3: #eef0f2;
  --border: #e3e6e9;
  --border-strong: #cfd4d9;
  --text: #1a1d21;
  --muted: #5f6672;
  --faint: #8c949f;
  --accent: #2f5bd7;
  --accent-hover: #24499f;
  --accent-soft: #edf1fc;
  --green: #10784d;
  --green-soft: #e7f2ec;
  --red: #b83a30;
  --red-soft: #fbeceb;
  --amber: #8d5a11;
  --amber-soft: #faf1e3;
  --radius: 8px;
  --radius-sm: 6px;
  --card-pad: 16px;
  --sidebar-w: 204px;
  --topbar-h: 45px;
}

/*
 * Dark theme tokens. They are applied in two situations: when the operating system
 * asks for dark and the user has not overridden it, and when the user explicitly
 * picks dark. Both selectors set the same tokens, so they stay in one place here.
 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #14171c;
    --surface: #191d23;
    --surface-2: #1f242b;
    --surface-3: #272d36;
    --border: #282e36;
    --border-strong: #3a424c;
    --text: #e6e9ee;
    --muted: #9aa2af;
    --faint: #7b8492;
    --accent: #7d9bf5;
    --accent-hover: #97afff;
    --accent-soft: #1d2637;
    --green: #4ec48f;
    --green-soft: #16302a;
    --red: #f08477;
    --red-soft: #35201f;
    --amber: #dba965;
    --amber-soft: #302718;
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #14171c;
  --surface: #191d23;
  --surface-2: #1f242b;
  --surface-3: #272d36;
  --border: #282e36;
  --border-strong: #3a424c;
  --text: #e6e9ee;
  --muted: #9aa2af;
  --faint: #7b8492;
  --accent: #7d9bf5;
  --accent-hover: #97afff;
  --accent-soft: #1d2637;
  --green: #4ec48f;
  --green-soft: #16302a;
  --red: #f08477;
  --red-soft: #35201f;
  --amber: #dba965;
  --amber-soft: #302718;
}

:root[data-theme='light'] {
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

.app-loading {
  padding: 32px;
  color: var(--muted);
}

.icon {
  display: inline-flex;
  flex: none;
}
.icon svg {
  width: 16px;
  height: 16px;
  display: block;
}

/* ---------- Layout ---------- */
.layout {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
  height: 100dvh;
  width: var(--sidebar-w);
  flex: none;
  display: flex;
  flex-direction: column;
  padding: 0 8px 8px;
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  height: var(--topbar-h);
  padding: 0 8px;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--text);
}
.brand:hover {
  text-decoration: none;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 13.5px;
}
.nav-item .icon {
  color: var(--faint);
}
.nav-item:hover {
  background: var(--surface-3);
  color: var(--text);
  text-decoration: none;
}
.nav-item.active,
.nav-item.active:hover {
  background: var(--surface);
  color: var(--text);
  font-weight: 550;
  box-shadow: inset 0 0 0 1px var(--border);
}
.nav-item.active .icon {
  color: var(--accent);
}

.nav-secondary {
  margin-top: auto;
  padding-top: 8px;
}

.sidebar-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 4px 0;
  border-top: 1px solid var(--border);
}

.who {
  min-width: 0;
  line-height: 1.25;
  /* It links to My account, but it should not stand out as a link. */
  color: inherit;
  text-decoration: none;
  border-radius: var(--radius-sm);
  padding: 3px 5px;
  margin: -3px -5px;
}
.who:hover {
  background: var(--surface-2);
}
.who:hover .who-role {
  color: var(--muted);
}
.who-name {
  font-size: 12.5px;
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.who-role {
  font-size: 11.5px;
  color: var(--faint);
}

.icon-btn {
  margin-left: auto;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  flex: none;
  border: 1px solid transparent;
  background: none;
  color: var(--faint);
  border-radius: var(--radius-sm);
}
.icon-btn:hover {
  background: var(--surface-3);
  border-color: var(--border);
  color: var(--text);
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--topbar-h);
  padding: 0 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar-search {
  width: 100%;
  max-width: 320px;
}
.topbar-hint {
  color: var(--faint);
}
.topbar-spacer {
  margin-left: auto;
}
.theme-toggle {
  margin-left: 0;
  width: 28px;
  height: 28px;
}

main {
  padding: 18px 20px 48px;
  width: 100%;
  max-width: 1400px;
}


/* ---------- Typography ---------- */
h1 {
  font-size: 18px;
  font-weight: 620;
  letter-spacing: -0.2px;
  margin: 0;
}
h2 {
  font-size: 14px;
  font-weight: 620;
  margin: 0 0 10px;
}
h3 {
  font-size: 11px;
  font-weight: 620;
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--faint);
}
.page-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.page-head .spacer {
  margin-left: auto;
}
.subtle {
  color: var(--muted);
}
.small {
  font-size: 12.5px;
}
.mono {
  font-variant-numeric: tabular-nums;
}
.empty {
  color: var(--faint);
  padding: 12px 2px;
  font-size: 13px;
}

/* ---------- Cards and grids ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--card-pad);
}
.card + .card {
  margin-top: 12px;
}
.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.card-head h2 {
  margin: 0;
}
.card-head .spacer {
  margin-left: auto;
}

.grid {
  display: grid;
  gap: 12px;
}
.grid.cols-2 {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}
.grid.cols-3 {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}
.grid.cols-4 {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 13px;
}
.kpi .label {
  font-size: 12px;
  color: var(--muted);
}
.kpi .value {
  font-size: 20px;
  font-weight: 620;
  letter-spacing: -0.4px;
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
  margin-top: 1px;
}
.kpi .hint {
  font-size: 11.5px;
  color: var(--faint);
}
.kpi.alert .value {
  color: var(--red);
}
.kpi.good .value {
  color: var(--green);
}

/* ---------- Tables ---------- */
.table-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.table-count {
  font-size: 12px;
  color: var(--faint);
  white-space: nowrap;
}
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
th {
  text-align: left;
  font-size: 11px;
  font-weight: 620;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--faint);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  padding: 6px 10px;
  white-space: nowrap;
}
th.sortable {
  cursor: pointer;
  user-select: none;
}
th.sortable:hover,
th[data-sort] {
  color: var(--text);
}
th.sortable:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.th-caret::before {
  content: "↕";
  margin-left: 4px;
  font-size: 10px;
  opacity: 0;
}
th.sortable:hover .th-caret::before {
  opacity: 0.5;
}
th[data-sort="asc"] .th-caret::before {
  content: "↑";
  opacity: 1;
}
th[data-sort="desc"] .th-caret::before {
  content: "↓";
  opacity: 1;
}
td {
  border-bottom: 1px solid var(--border);
  padding: 7px 10px;
  vertical-align: top;
}
tbody tr:last-child td {
  border-bottom: none;
}
tbody tr:hover {
  background: var(--surface-2);
}
td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
td.empty {
  color: var(--faint);
  padding: 14px 10px;
}
td.actions,
th.actions {
  width: 1%;
  text-align: right;
  white-space: nowrap;
}

/* Dropdown in a cell: reads as text, behaves as a field. */
.cell-select {
  width: auto;
  max-width: 100%;
  border-color: transparent;
  background: transparent;
  padding: 1px 4px;
  font-size: 12.5px;
  font-weight: 550;
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
}
.cell-select:hover {
  border-color: var(--border-strong);
  background: var(--surface);
}
.cell-select:focus {
  background: var(--surface);
}
.cell-select:disabled {
  opacity: 0.6;
}
.cell-select[data-tone="blue"] {
  background: var(--accent-soft);
  color: var(--accent);
}
.cell-select[data-tone="green"] {
  background: var(--green-soft);
  color: var(--green);
}
.cell-select[data-tone="red"] {
  background: var(--red-soft);
  color: var(--red);
}
.cell-select[data-tone="amber"] {
  background: var(--amber-soft);
  color: var(--amber);
}

/* ---------- Action menu ---------- */
.kebab {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border-color: transparent;
  background: none;
  color: var(--faint);
}
.kebab:hover,
.kebab[aria-expanded="true"] {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--border);
}
.menu {
  position: fixed;
  z-index: 60;
  min-width: 168px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.16);
}
.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  padding: 6px 9px;
  font-weight: 450;
  color: var(--text);
}
.menu-item:hover {
  background: var(--surface-2);
}
.menu-item.danger {
  /* The background must stay away; button.danger further down fills buttons red. */
  color: var(--red);
  background: none;
  border-color: transparent;
}
.menu-item.danger:hover {
  background: var(--red-soft);
}

/* ---------- Settings (also used by quick-change panels) ---------- */
.settings-form .card + .card {
  margin-top: 12px;
}
.settings-list .setting {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 200px;
  gap: 12px;
  align-items: center;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}
.settings-list .setting:first-child {
  padding-top: 0;
}
.settings-list .setting:last-child {
  padding-bottom: 0;
  border-bottom: none;
}
.setting label {
  margin: 0;
  color: var(--text);
  font-size: 13.5px;
}
.setting-input {
  justify-self: end;
  width: 100%;
  display: flex;
  justify-content: flex-end;
}
.setting-input .cell-select {
  border-color: var(--border-strong);
  background: var(--surface);
  padding: 5px 8px;
  font-size: 13px;
  width: 100%;
}
.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}
@media (max-width: 560px) {
  .settings-list .setting {
    grid-template-columns: 1fr;
  }
  .setting-input {
    justify-self: stretch;
    justify-content: flex-start;
  }
}

/* A table that fills a card runs all the way to that card's edge. */
.card > .table-block:last-child {
  margin: 0 calc(var(--card-pad) * -1) calc(var(--card-pad) * -1);
}
.card > .table-block:first-child {
  margin-top: calc(var(--card-pad) * -1);
}
.card > .table-block > .table-toolbar {
  padding: 10px var(--card-pad);
  margin: 0;
  border-bottom: 1px solid var(--border);
}
.card > .table-block th:first-child,
.card > .table-block td:first-child {
  padding-left: var(--card-pad);
}
.card > .table-block th:last-child,
.card > .table-block td:last-child {
  padding-right: var(--card-pad);
}
.card > .table-block:first-child th:first-child {
  border-top-left-radius: calc(var(--radius) - 1px);
}
.card > .table-block:first-child th:last-child {
  border-top-right-radius: calc(var(--radius) - 1px);
}

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 4px;
  font-size: 11.5px;
  font-weight: 550;
  background: var(--surface-3);
  color: var(--muted);
  white-space: nowrap;
}
.badge.blue {
  background: var(--accent-soft);
  color: var(--accent);
}
.badge.green {
  background: var(--green-soft);
  color: var(--green);
}
.badge.red {
  background: var(--red-soft);
  color: var(--red);
}
.badge.amber {
  background: var(--amber-soft);
  color: var(--amber);
}

/* ---------- Forms and buttons ---------- */
input,
select,
textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 6px 9px;
  width: 100%;
}
input::placeholder,
textarea::placeholder {
  color: var(--faint);
}
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
textarea {
  min-height: 76px;
  resize: vertical;
}
input[type="search"] {
  -webkit-appearance: none;
}
.input-sm {
  padding: 4px 8px;
  font-size: 13px;
}

/* Search field with an icon in front. */
.input-search {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 180px;
  max-width: 280px;
  flex: 1;
}
.input-search .icon {
  position: absolute;
  left: 8px;
  color: var(--faint);
  pointer-events: none;
}
.input-search input {
  padding-left: 28px;
}

label {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 3px;
}
.field {
  margin-bottom: 10px;
}
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
/* A row of three fields, such as street/house number/addition. */
.field-row:has(> :nth-child(3)) {
  grid-template-columns: 2fr 1fr 1fr;
}
/* Long lists in a table cell stay on one line, with the full text in the tooltip. */
.clip {
  display: inline-block;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}
/* Multi-line text from an import keeps its line breaks. */
.prewrap {
  white-space: pre-wrap;
}
.check {
  display: flex;
  align-items: center;
  gap: 7px;
}
.check input {
  width: auto;
  accent-color: var(--accent);
}
.check label {
  margin: 0;
}

button {
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  padding: 5px 11px;
}
button:hover {
  background: var(--surface-2);
}
button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--accent-soft);
  border-color: var(--accent);
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
button.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
button.danger {
  color: var(--red);
}
button.danger:hover {
  background: var(--red-soft);
}
button.link {
  border: none;
  background: none;
  color: var(--accent);
  padding: 2px 3px;
}
button.link:hover {
  background: none;
  text-decoration: underline;
}
button.small {
  padding: 3px 8px;
  font-size: 12.5px;
}
button:disabled {
  opacity: 0.5;
  cursor: default;
}
.btn-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 12px;
}
.filters .field {
  margin: 0;
  min-width: 140px;
}
.filters .field.grow {
  flex: 1;
  min-width: 200px;
}
.filters label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--faint);
}

/* ---------- Tabs within a page ---------- */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.tabs a,
.tabs button {
  border: none;
  background: none;
  padding: 6px 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  margin-bottom: -1px;
}
.tabs a.active,
.tabs button.active {
  color: var(--text);
  border-bottom-color: var(--accent);
  font-weight: 550;
}
.tabs a:hover,
.tabs button:hover {
  background: none;
  color: var(--text);
  text-decoration: none;
}

/* ---------- Kanban ---------- */
.kanban {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 10px;
  align-items: flex-start;
}
.kanban-col {
  flex: 0 0 246px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px;
  min-height: 100px;
}
.kanban-col.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.kanban-col h4 {
  margin: 0;
  font-size: 12.5px;
  font-weight: 620;
}
.kanban-col .col-meta {
  font-size: 11.5px;
  color: var(--faint);
  margin-bottom: 8px;
  font-variant-numeric: tabular-nums;
}
.deal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 9px;
  margin-bottom: 6px;
  cursor: grab;
}
.deal-card:hover {
  border-color: var(--border-strong);
}
.deal-card:active {
  cursor: grabbing;
}
.deal-card.dragging {
  opacity: 0.4;
}
.deal-card .name {
  font-weight: 550;
  font-size: 13px;
}
.deal-card .meta {
  font-size: 11.5px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 6px;
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}

/* ---------- Timeline ---------- */
.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
}
.timeline li {
  padding: 7px 0 7px 14px;
  border-left: 1px solid var(--border);
  position: relative;
}
.timeline li::before {
  content: "";
  position: absolute;
  left: -3px;
  top: 14px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--border-strong);
}
.timeline .when {
  font-size: 11.5px;
  color: var(--faint);
}
.timeline .what {
  margin-top: 1px;
}

/* ---------- Small lists ---------- */
.list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.list li {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
}
.list li:last-child {
  border-bottom: none;
}
.list li .grow {
  flex: 1;
  min-width: 0;
}
.list li .title {
  font-weight: 500;
}
.list li .sub {
  font-size: 11.5px;
  color: var(--faint);
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 30, 0.35);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 16px;
  overflow-y: auto;
  z-index: 50;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  width: 100%;
  max-width: 520px;
  padding: 18px;
  box-shadow: 0 10px 30px rgba(16, 24, 40, 0.14);
}
.modal-sm {
  max-width: 420px;
}
.modal-md {
  max-width: 460px;
}
.modal h2 {
  margin-bottom: 14px;
}
.modal-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  margin-top: 16px;
}
.form-error {
  color: var(--red);
  background: var(--red-soft);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
  font-size: 12.5px;
  margin-bottom: 10px;
}

/* ---------- Toast ---------- */
#toast-root {
  position: fixed;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 100;
}
.toast {
  background: var(--text);
  color: var(--bg);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(16, 24, 40, 0.2);
}
.toast.error {
  background: var(--red);
  color: #fff;
}

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  width: 100%;
  max-width: 340px;
}
.login-brand {
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 16px;
}
.login-sub {
  margin: 2px 0 16px;
}

/* ---------- Detail page ---------- */
.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
  gap: 12px;
  align-items: start;
}
@media (max-width: 900px) {
  .detail-grid {
    grid-template-columns: 1fr;
  }
}
.kv {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 5px 12px;
  font-size: 13.5px;
}
.kv dt {
  color: var(--muted);
}
.kv dd {
  margin: 0;
}
.progress {
  height: 5px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}
.progress span {
  display: block;
  height: 100%;
  background: var(--accent);
}
.overdue {
  color: var(--red);
  font-weight: 550;
}
.today {
  color: var(--amber);
  font-weight: 550;
}

/* ---------- Authentication screens ---------- */
.auth-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 420px;
}
.auth-card h1 {
  font-size: 20px;
  margin: 0;
}
.auth-foot {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  color: var(--muted);
}
.auth-foot p {
  margin: 0 0 4px;
}
/* The name of the invitee, above the password field. */
.auth-identity {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  margin-bottom: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.auth-identity .icon {
  color: var(--muted);
}
.auth-identity .title {
  font-weight: 550;
}
.code-input {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 2px;
  text-transform: uppercase;
}

/* ---------- Password field with live feedback ---------- */
.pw-input {
  position: relative;
  display: flex;
}
.pw-input input {
  padding-right: 38px;
}
.pw-reveal {
  position: absolute;
  right: 1px;
  top: 1px;
  bottom: 1px;
  width: 34px;
  display: grid;
  place-items: center;
  padding: 0;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.pw-reveal:hover {
  color: var(--text);
  background: none;
}
.pw-strength {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 10px 0 12px;
}
.pw-bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 3px;
  flex: 1;
  height: 5px;
}
.pw-bar span {
  border-radius: 999px;
  background: var(--surface-3);
}
/* Colour in as many segments as the score, in a colour that suits that score. */
.pw-bar.score-0 span:nth-child(-n + 1),
.pw-bar.score-1 span:nth-child(-n + 2) {
  background: var(--red);
}
.pw-bar.score-2 span:nth-child(-n + 3) {
  background: var(--amber);
}
.pw-bar.score-3 span:nth-child(-n + 4) {
  background: var(--green);
}
.pw-bar.score-4 span {
  background: var(--green);
}
.pw-strength-label {
  font-size: 12px;
  color: var(--muted);
  min-width: 118px;
  text-align: right;
}
.pw-strength-label.score-0,
.pw-strength-label.score-1 {
  color: var(--red);
}
.pw-strength-label.score-2 {
  color: var(--amber);
}
.pw-strength-label.score-3,
.pw-strength-label.score-4 {
  color: var(--green);
}
.pw-feedback {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
}
.pw-feedback-title {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 6px;
}
.pw-feedback-title:not(:first-child) {
  margin-top: 12px;
}
.pw-rules {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.pw-rule {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  font-size: 12.5px;
  line-height: 1.45;
}
.pw-rule-icon {
  flex: none;
  margin-top: 1px;
}
.pw-rule-icon .icon svg {
  width: 14px;
  height: 14px;
  stroke-width: 2.2;
}
.pw-rule.met {
  color: var(--green);
}
.pw-rule.unmet {
  color: var(--red);
}
.pw-rule.todo {
  color: var(--muted);
}
.pw-rule.todo .pw-rule-icon {
  color: var(--faint);
}
.pw-rule-detail {
  color: inherit;
  opacity: 0.75;
}
.pw-rules-advice .pw-rule.met {
  color: var(--muted);
}
.pw-note {
  margin: 10px 0 0;
}
.pw-match {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  min-height: 18px;
}
.pw-match.ok {
  color: var(--green);
}
.pw-match.bad {
  color: var(--red);
}
.pw-match .icon svg {
  width: 14px;
  height: 14px;
  stroke-width: 2.2;
}

/* ---------- Invitation code ---------- */
.invite-box {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
  padding: 12px;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
}
.invite-code {
  flex: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 2px;
  user-select: all;
}
.notice {
  background: var(--amber-soft);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  color: var(--amber);
}
.notice .title {
  font-weight: 600;
  font-size: 13px;
}
.notice p {
  margin: 3px 0 0;
}
.ok-text {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--green);
}
.ok-text .icon svg {
  width: 14px;
  height: 14px;
  stroke-width: 2.2;
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}
.tab {
  padding: 8px 12px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover {
  color: var(--text);
}
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ---------- Permission matrix ---------- */
.table-scroll {
  overflow-x: auto;
  margin: 0 calc(var(--card-pad) * -1);
  padding: 0 var(--card-pad);
}
.perm-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.perm-table th,
.perm-table td {
  padding: 7px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.perm-table thead th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 550;
  vertical-align: bottom;
}
.perm-col {
  text-align: center !important;
  width: 108px;
}
.perm-role {
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}
.perm-table .perm-group td {
  padding-top: 14px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: var(--faint);
  border-bottom-color: var(--border-strong);
}
.perm-table input[type='checkbox'] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}
.perm-table input[type='checkbox']:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}
.perm-legend {
  display: grid;
  gap: 3px;
  margin-top: 14px;
}
.perm-list {
  display: grid;
  gap: 3px;
}

/* ---------- Small helper classes ---------- */
.setting-input {
  align-items: center;
  gap: 7px;
}
.setting-unit {
  flex: none;
}
.setting-input input[type='checkbox'] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  margin: 0;
  flex: none;
}
.cell-stack {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: flex-start;
}
.btn-row-tight {
  gap: 4px;
  flex-wrap: wrap;
}
button.danger {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

/* ---------- Mobile ---------- */

/*
 * These parts exist for the narrow view only: the hamburger button, the close button
 * and the backdrop of the menu drawer, the sort dropdown under a table and the stage
 * dropdown in a kanban card.
 */
.nav-toggle,
.nav-close,
.nav-backdrop,
.table-sort,
.deal-card .stage-move {
  display: none;
}

/* Without the drawer the brand name simply sits first in the sidebar. */
.sidebar-head {
  display: contents;
}

/*
 * Below this width the whole app switches over: the menu becomes a drawer, tables
 * become cards stacked underneath each other and dialogs rise up from the bottom.
 */
@media (max-width: 820px) {
  :root {
    --topbar-h: 52px;
    --card-pad: 14px;
  }

  /* ---- Menu as a drawer over the page ---- */
  .layout {
    display: block;
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    height: auto;
    width: min(272px, 82vw);
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
    z-index: 45;
    transform: translateX(-100%);
    transition: transform 0.18s ease-out;
  }
  body.nav-open .sidebar {
    transform: none;
  }
  body.nav-open {
    overflow: hidden;
  }

  .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(16, 20, 26, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease-out;
  }
  body.nav-open .nav-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
  }
  .brand {
    flex: 1;
    min-width: 0;
    height: 40px;
    margin: 0;
  }
  .nav-close,
  .nav-toggle {
    display: grid;
  }
  .nav-toggle {
    margin-left: 0;
  }
  .nav-item {
    padding: 10px;
    font-size: 14.5px;
  }

  /* ---- Top bar ---- */
  .topbar {
    gap: 8px;
    height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) max(12px, env(safe-area-inset-right, 0px)) 0 max(12px, env(safe-area-inset-left, 0px));
  }
  .topbar-search {
    max-width: none;
    min-width: 0;
  }
  .topbar-hint {
    display: none;
  }

  main {
    padding: 14px max(12px, env(safe-area-inset-right, 0px)) calc(40px + env(safe-area-inset-bottom, 0px))
      max(12px, env(safe-area-inset-left, 0px));
  }

  /* Long email addresses and web addresses must not stretch the column. */
  .kv dd,
  .list li .grow,
  .timeline .what,
  .card p {
    overflow-wrap: anywhere;
  }

  /* ---- Inputs: at least 16px, otherwise iOS zooms in on tap ---- */
  input,
  select,
  textarea {
    font-size: 16px;
    padding: 9px 11px;
  }
  .input-sm {
    font-size: 16px;
    padding: 7px 10px;
  }
  .input-search input {
    padding-left: 30px;
  }
  .input-search {
    max-width: none;
    min-width: 0;
  }
  .cell-select {
    font-size: 14px;
    padding: 3px 6px;
  }

  .filters .field {
    min-width: 0;
    flex: 1 1 150px;
  }
  .filters .field.grow {
    flex: 1 1 100%;
  }

  /* ---- Tables as cards stacked underneath each other ---- */
  .table-wrap {
    overflow-x: visible;
  }
  .table-block table,
  .table-block tbody,
  .table-block tr,
  .table-block td {
    display: block;
  }
  /* The headers live in the sort dropdown in the toolbar, so that row can go. */
  .table-block thead {
    display: none;
  }

  .table-block tr {
    position: relative;
    padding: 11px 0;
    border-bottom: 1px solid var(--border);
  }
  .table-block tbody tr:last-child {
    border-bottom: none;
  }
  .table-block tbody tr:hover {
    background: none;
  }

  .table-block td {
    display: grid;
    grid-template-columns: minmax(84px, 34%) 1fr;
    gap: 10px;
    align-items: baseline;
    border: none;
    padding: 2px 0;
    overflow-wrap: anywhere;
  }
  .table-block td::before {
    content: attr(data-label);
    color: var(--faint);
    font-size: 12px;
  }

  /* The first column is the name and serves as the card's heading. */
  .table-block td:first-child {
    display: block;
    font-size: 15px;
    font-weight: 600;
    padding-right: 44px;
    margin-bottom: 4px;
  }
  .table-block td:first-child::before {
    content: none;
  }
  .table-block td.num {
    text-align: left;
  }
  /* A dropdown in a cell stays as wide as its content, not as wide as the column. */
  .table-block td > .cell-select {
    justify-self: start;
  }
  /* A bigger touch target than in the table view, it is a real field now. */
  .table-block .cell-select {
    padding: 5px 7px;
  }
  .clip {
    max-width: 100%;
  }

  /* The action menu belongs in the top right of the card. */
  .table-block td.cell-actions {
    position: absolute;
    top: 8px;
    right: 0;
    display: block;
    width: auto;
    padding: 0;
  }
  .table-block td.cell-actions::before {
    content: none;
  }

  /* The "nothing found" line is not a card but a message. */
  .table-block td.empty {
    display: block;
    font-size: 13px;
    font-weight: 400;
    color: var(--faint);
    padding: 10px 0;
    margin: 0;
  }
  .table-block td.empty::before {
    content: none;
  }

  /* A cell without content yields no line. This rule belongs last. */
  .table-block td:empty {
    display: none;
  }

  /* ---- Toolbar above a table: search and sort stacked ---- */
  .table-toolbar {
    flex-wrap: wrap;
    gap: 8px;
  }
  .table-toolbar .input-search {
    flex: 1 1 100%;
  }
  .table-sort {
    display: flex;
    gap: 6px;
    flex: 1 1 100%;
  }
  .table-sort-select {
    flex: 1;
    min-width: 0;
  }
  .table-sort-dir {
    flex: none;
    width: 42px;
    padding: 0;
  }

  /* On mobile a table in a card no longer runs to the edge. */
  .card > .table-block:first-child,
  .card > .table-block:last-child {
    margin: 0;
  }
  .card > .table-block > .table-toolbar {
    padding: 0 0 10px;
    border-bottom: none;
  }
  .card > .table-block td:first-child,
  .card > .table-block td:last-child {
    padding-left: 0;
    padding-right: 0;
  }
  .card > .table-block td:first-child {
    padding-right: 44px;
  }

  /* ---- Kanban: one column per swipe ---- */
  .kanban {
    margin: 0 -12px;
    padding: 0 12px 10px;
    scroll-snap-type: x mandatory;
  }
  .kanban-col {
    flex: 0 0 min(86%, 300px);
    scroll-snap-align: start;
  }
  .deal-card .stage-move {
    display: block;
  }

  /* ---- Dialogs rise up from the bottom ---- */
  .modal-backdrop {
    padding: 0;
    align-items: flex-end;
  }
  .modal,
  .modal-sm,
  .modal-md {
    max-width: none;
    max-height: 92dvh;
    overflow-y: auto;
    border-radius: 14px 14px 0 0;
    border-bottom: none;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom, 0px));
  }
  .modal-actions {
    flex-direction: column-reverse;
    gap: 8px;
  }
  .modal-actions button {
    width: 100%;
  }

  /* ---- Toasts across the full width ---- */
  #toast-root {
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
}

/* Below this width there is no room left for two columns side by side. */
@media (max-width: 560px) {
  .field-row,
  .field-row:has(> :nth-child(3)) {
    grid-template-columns: 1fr;
  }
  .kv {
    grid-template-columns: 1fr;
    gap: 0;
  }
  .kv dt {
    margin-top: 9px;
    font-size: 12px;
  }
  .kv dt:first-of-type {
    margin-top: 0;
  }
  .btn-row button {
    flex: 1 1 auto;
  }
}

/*
 * Touch screens: buttons and menu items big enough to hit with a finger, and in the
 * pipeline a dropdown instead of dragging.
 */
@media (pointer: coarse) {
  button:not(.link) {
    min-height: 40px;
    padding: 9px 14px;
  }
  button.small {
    min-height: 34px;
    padding: 6px 10px;
  }
  .icon-btn {
    min-height: 0;
    width: 40px;
    height: 40px;
  }
  .kebab {
    min-height: 0;
    width: 38px;
    height: 38px;
  }
  .pw-reveal {
    min-height: 0;
    width: 42px;
    padding: 0;
  }
  .pw-input input {
    padding-right: 46px;
  }
  .menu {
    min-width: 210px;
  }
  .menu-item {
    min-height: 42px;
    padding: 10px 12px;
  }
  .nav-item {
    padding: 10px;
  }
  .tab,
  .tabs a,
  .tabs button {
    padding: 11px 12px;
  }
  .check input,
  .setting-input input[type='checkbox'],
  .perm-table input[type='checkbox'] {
    width: 20px;
    height: 20px;
  }
  /* Dragging does not work with a finger, which is what the stage dropdown is for. */
  .deal-card {
    cursor: default;
  }
  .deal-card .stage-move {
    display: block;
  }
}

/* The stage dropdown in a kanban card reads as a real field, not as cell text. */
.deal-card .stage-move {
  width: 100%;
  margin-top: 8px;
  padding: 6px 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border-strong);
}

/* Anyone who prefers motion off gets the drawer without animation. */
@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .nav-backdrop {
    transition: none;
  }
}
