/* BrickWise Tech team lead tracker. Mobile first; brand colours from the main site. */
:root {
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ink: #0b1630;
  --accent: #1d4ed8;
  --accent-soft: #e6edfb;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --line: #dde3f0;
  --muted: #5b6785;
  --ok: #0f7a4a;
  --ok-soft: #dcf3e8;
  --amber: #fbbf24;
  --danger: #b42318;
  --radius: 10px;
  --tap: 44px;
  --bar: 60px;
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235b6785' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font:
    16px/1.4 system-ui,
    -apple-system,
    'Segoe UI',
    Roboto,
    sans-serif;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

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

svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

input,
select,
button {
  font: inherit;
  color: inherit;
}

input,
.select {
  min-height: var(--tap);
  width: 100%;
  min-width: 0;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color 0.15s;
}

input:hover,
.select:hover {
  border-color: #c5cee3;
}

/* Dropdowns: our own chevron instead of the browser's. */
select {
  appearance: none;
  padding-right: 34px !important;
  background: var(--surface) var(--chevron) right 10px center / 16px no-repeat;
  cursor: pointer;
}

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

.btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0 18px;
  border: 0;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}

.btn:hover {
  background: var(--accent);
}

.btn:disabled {
  cursor: progress;
}

.btn-sm {
  padding: 0;
  font-size: 1.3rem;
}

.icon-btn {
  position: relative;
  display: grid;
  place-items: center;
  min-width: var(--tap);
  min-height: var(--tap);
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.icon-btn:hover {
  background: rgb(255 255 255 / 0.1);
}

.icon-btn:focus-within {
  outline: 3px solid var(--accent);
}

.error {
  min-height: 1.4em;
  margin: 0;
  color: var(--danger);
  font-size: 0.9rem;
  text-align: center;
}

.error.hint {
  color: var(--muted);
}

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

.spinner {
  display: inline-block;
  width: 22px;
  height: 22px;
  border: 3px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* A busy button keeps its size and shows a spinner instead of its label. */
.busy {
  color: transparent !important;
  pointer-events: none;
}

.busy::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 18px;
  height: 18px;
  border: 2.5px solid rgb(255 255 255 / 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.spin svg {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading {
  display: grid;
  justify-items: center;
  padding: 12px 16px;
  color: var(--muted);
  font-size: 0.9rem;
}

.loading__text:empty {
  display: none;
}

/* Placeholder rows while the first load runs. */
.skeleton-row td {
  height: var(--tap);
}

.skel {
  display: block;
  height: 12px;
  margin: 0 10px;
  border-radius: 6px;
  background: linear-gradient(90deg, #eceff6 25%, #f6f8fc 50%, #eceff6 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s linear infinite;
}

.skel--num {
  width: 14px;
  margin-left: auto;
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

/* ---------- login ---------- */

.login {
  display: grid;
  place-items: center;
  min-height: 100svh;
  padding: 16px;
}

.login__card {
  display: grid;
  gap: 12px;
  justify-items: center;
  width: 100%;
  max-width: 320px;
}

.mark {
  width: 56px;
  height: 56px;
  margin-bottom: 8px;
  border-radius: 14px;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cg fill='%23fff'%3E%3Crect x='6' y='19.5' width='9' height='5' rx='1.25'/%3E%3Crect x='17' y='19.5' width='9' height='5' rx='1.25'/%3E%3Crect x='6' y='13' width='4' height='5' rx='1.25'/%3E%3Crect x='12' y='13' width='14' height='5' rx='1.25'/%3E%3Crect x='6' y='6.5' width='9' height='5' rx='1.25'/%3E%3Crect x='17' y='6.5' width='9' height='5' rx='1.25'/%3E%3C/g%3E%3C/svg%3E")
      center / 100% no-repeat,
    var(--accent);
}

.login__card .btn {
  width: 100%;
}

/* ---------- top bar ---------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 2px;
  min-height: var(--bar);
  padding: 8px 6px 8px 8px;
  background: var(--ink);
  color: #fff;
}

.bar h1 {
  flex: 1;
  margin: 0 0 0 6px;
  font-size: 1.125rem;
  white-space: nowrap;
}

.count {
  margin-left: 4px;
  color: #bfd0f8;
  font-weight: 500;
}

.who {
  margin-right: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--amber);
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 700;
}

/* Category manager (dialog) */

.list {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.list li {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  border-bottom: 1px solid var(--line);
}

.list .cat-name {
  flex: 1;
  min-width: 0;
  padding-left: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list small {
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.mini {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  opacity: 0.7;
}

.mini svg {
  width: 17px;
  height: 17px;
}

.mini:hover {
  background: var(--bg);
  color: var(--ink);
  opacity: 1;
}

.mini.danger:hover {
  color: var(--danger);
}

.rename {
  flex: 1;
  min-height: 38px;
  padding: 0 10px;
}

.cat-form {
  display: grid;
  grid-template-columns: 1fr var(--tap);
  gap: 6px;
  margin-top: 8px;
}

/* ---------- main ---------- */

.main {
  min-width: 0;
}

.add {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px 16px 8px;
}

.add #new-map {
  grid-column: 1 / -1;
}

.add .btn {
  font-size: 1.4rem;
  padding: 0;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px 12px;
  overflow-x: auto;
  scrollbar-width: none;
}

.toolbar::-webkit-scrollbar {
  display: none;
}

.search {
  position: relative;
  flex: 1 1 14rem;
  min-width: 12rem;
}

.search input {
  min-height: 40px;
}

.search svg {
  position: absolute;
  top: 50%;
  left: 12px;
  width: 18px;
  height: 18px;
  color: var(--muted);
  transform: translateY(-50%);
  pointer-events: none;
}

.search input {
  padding-left: 38px;
}

.clear-btn {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 4px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  cursor: pointer;
}

.clear-btn svg {
  width: 19px;
  height: 19px;
}

.clear-btn:hover {
  background: var(--accent);
  color: #fff;
}

/* Filters (next to the search): custom dropdowns, the Trash toggle and the category ✎. */
.filters {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 8px;
}

.filter-icon,
.filter-toggle {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 40px;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.9rem;
  cursor: pointer;
}

.filter-icon svg {
  width: 17px;
  height: 17px;
}

.filter-icon:hover,
.filter-toggle:hover {
  border-color: #c5cee3;
}

.filter-toggle[aria-pressed='true'] {
  border-color: var(--danger);
  background: #fdecea;
  color: var(--danger);
  font-weight: 700;
}

#trash-count {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.dd {
  position: relative;
  flex-shrink: 0;
}

.dd__btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 10px 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.9rem;
  white-space: nowrap;
  cursor: pointer;
  transition:
    border-color 0.15s,
    background-color 0.15s,
    color 0.15s;
}

.dd__btn:hover {
  border-color: #c5cee3;
}

.dd__btn svg {
  width: 16px;
  height: 16px;
  color: var(--muted);
  transition: transform 0.25s var(--ease);
}

.dd.open .dd__btn svg {
  transform: rotate(180deg);
}

.dd.is-active .dd__btn {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.dd.is-active .dd__btn svg {
  color: var(--accent);
}

.dd__list {
  position: fixed;
  z-index: 20;
  max-height: min(320px, 60svh);
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  list-style: none;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 12px 32px rgb(11 22 48 / 0.16);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px) scale(0.98);
  transform-origin: top left;
  transition:
    opacity 0.16s ease,
    transform 0.22s var(--ease),
    visibility 0.22s;
}

.dd__list:focus {
  outline: none;
}

.dd.open .dd__list {
  opacity: 1;
  visibility: visible;
  transform: none;
}

.dd__option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 40px;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 0.92rem;
  white-space: nowrap;
  cursor: pointer;
}

.dd__option.is-active {
  background: var(--bg);
}

.dd__option[aria-selected='true'] {
  color: var(--accent);
  font-weight: 700;
}

.dd__option small {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* The spreadsheet: scrolls sideways on phones, header stays visible. */
.sheet {
  view-transition-name: leads-sheet;
  overflow: auto;
  max-height: 75svh;
  margin: 0 16px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  font-size: 0.95rem;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 9px 8px;
  border-bottom: 1px solid var(--line);
  background: #eef2fb;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

td {
  padding: 0;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  vertical-align: middle;
  transition: background 0.15s;
}

td:last-child {
  border-right: 0;
}

tr:hover td {
  background: #fafbfe;
}

/* Cells look like a sheet: no box until you edit. */
td input,
td select {
  min-height: var(--tap);
  border: 0;
  border-radius: 0;
  background-color: transparent;
  padding: 0 8px;
}

td select {
  min-width: 8.5rem;
  background-position: right 6px center;
  padding-right: 28px !important;
}

td input:focus,
td select:focus {
  background-color: var(--accent-soft);
  outline-offset: -3px;
}

/* Saving a cell: a thin moving line along its bottom, not a colour flash. */
td.saving {
  position: relative;
}

td.saving::after {
  content: '';
  position: absolute;
  inset: auto 0 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  background-size: 50% 100%;
  background-repeat: no-repeat;
  animation: saving 0.9s linear infinite;
}

@keyframes saving {
  from {
    background-position: -50% 0;
  }

  to {
    background-position: 150% 0;
  }
}

tr.removing {
  opacity: 0.5;
  transition: opacity 0.2s;
}

/* Rows leaving (trash, restore, delete) slide out; a new row slides in highlighted. */
tr.leaving td {
  animation: row-out 0.22s var(--ease) forwards;
}

tr.is-new td {
  animation:
    row-in 0.42s var(--ease),
    row-glow 1.6s ease;
}

@keyframes row-out {
  to {
    opacity: 0;
    transform: translateX(16px);
  }
}

@keyframes row-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
}

@keyframes row-glow {
  from {
    background: var(--accent-soft);
  }
}

/* Row numbers: position in the list as shown (after filters). */
.col-num {
  width: 1%;
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

td.col-num {
  padding: 0 8px;
}

.col-date .date {
  display: block;
  padding: 0 10px;
  color: var(--muted);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Empty link / e-mail cells. */
.map .none {
  padding: 0 12px;
  color: var(--muted);
}

.map {
  display: flex;
  align-items: center;
}

.map input {
  min-width: 6rem;
  text-overflow: ellipsis;
}

.map a,
.map button {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: var(--tap);
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
}

.map svg {
  width: 17px;
  height: 17px;
}

.map button {
  color: var(--muted);
}

.map button:hover,
.map a:hover {
  color: var(--ink);
}

.map button.done {
  color: var(--ok);
}

/* Proper checkboxes. Locked when the other person owns them. */
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
  min-width: 7rem;
  padding: 0 10px;
  cursor: pointer;
  user-select: none;
}

.check input {
  appearance: none;
  flex: none;
  display: grid;
  place-items: center;
  width: 22px;
  min-width: 22px;
  height: 22px;
  min-height: 22px;
  margin: 0;
  padding: 0;
  border: 2px solid #b5c0d8;
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s;
}

.check input::after {
  content: '';
  width: 6px;
  height: 11px;
  margin-top: -2px;
  border: solid #fff;
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg) scale(0);
  transition: transform 0.15s;
}

.check input:checked {
  border-color: var(--ok);
  background: var(--ok);
}

.check input:checked::after {
  transform: rotate(45deg) scale(1);
}

.check input:hover:not(:disabled) {
  border-color: var(--accent);
}

/* The name next to a tick appears at once and slides in. */
.check span.appear {
  animation: name-in 0.28s var(--ease);
}

.check.pending span {
  opacity: 0.75;
}

@keyframes name-in {
  from {
    opacity: 0;
    transform: translateX(-4px);
  }
}

.check span {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.check input:checked + span {
  color: var(--ok);
}

.check.locked {
  cursor: not-allowed;
}

.check.locked input {
  cursor: not-allowed;
  opacity: 0.55;
}

.del {
  display: grid;
  place-items: center;
  width: var(--tap);
  min-height: var(--tap);
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.del svg {
  width: 17px;
  height: 17px;
}

.del:hover {
  color: var(--danger);
}

/* Row actions: trash, or (in the trash) restore + delete for good. */
.actions {
  display: flex;
  justify-content: flex-end;
}

.del.restore:hover {
  color: var(--accent);
}

/* Looking at the trash: a red line under the top bar says so. */
.in-trash .bar {
  box-shadow: inset 0 -3px 0 var(--danger);
}

/* Mail: copy buttons only, never the text itself. */
.mail {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: var(--tap);
  padding: 0 6px;
  white-space: nowrap;
}

.mail button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 34px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.mail button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.mail button.done {
  border-color: var(--ok);
  color: var(--ok);
}

.mail svg {
  width: 15px;
  height: 15px;
}

.mail .edit-mail {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.mail .add-mail {
  border-style: dashed;
  color: var(--muted);
}

.dialog {
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100svh - 32px);
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 20px 50px rgb(11 22 48 / 0.25);
}

.dialog::backdrop {
  background: rgb(11 22 48 / 0.45);
}

.dialog__form {
  display: grid;
  gap: 6px;
  padding: 20px;
}

.dialog h2 {
  margin: 0;
  font-size: 1.15rem;
}

.dialog__for {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.dialog label {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.dialog textarea {
  width: 100%;
  min-height: 14rem;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: inherit;
  font-size: 0.95rem;
  resize: vertical;
}

.dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

.btn-ghost {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.btn-ghost:hover {
  background: var(--bg);
}

.empty {
  margin: 0;
  padding: 32px 16px;
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 16px;
  z-index: 10;
  max-width: calc(100vw - 32px);
  margin: 0;
  padding: 10px 16px;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Small phones: tighter top bar so it never scrolls sideways. */
@media (max-width: 400px) {
  .bar {
    gap: 0;
    padding-inline: 4px;
  }

  .bar .icon-btn {
    min-width: 38px;
  }

  .bar h1 {
    margin-left: 2px;
    font-size: 1rem;
  }

  .who {
    max-width: 3.4em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-inline: 7px;
  }
}

@media (max-width: 340px) {
  .count {
    display: none;
  }
}

@media (min-width: 48rem) {
  .add {
    grid-template-columns: 2fr 1fr 1fr 1fr auto;
  }

  .add #new-map {
    grid-column: auto;
  }

  .toolbar .search {
    max-width: 28rem;
  }

  .sheet {
    max-height: calc(100svh - 200px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast,
  .check input,
  .check input::after {
    transition: none;
  }
}

/* ---------- motion ---------- */

/* Login and the app fade in; buttons press in a little. */
.fade-in {
  animation: fade-in 0.35s var(--ease);
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

.btn:active,
.icon-btn:active,
.dd__btn:active,
.filter-toggle:active,
.filter-icon:active,
.clear-btn:active {
  transform: scale(0.97);
}

/* Toast: slides up from below. */
.toast {
  transform: translate(-50%, 8px);
  transition:
    opacity 0.2s,
    transform 0.25s var(--ease);
}

/* Dialogs (mail, categories): rise and fade in, backdrop fades. */
.dialog,
.dialog::backdrop {
  transition:
    opacity 0.22s ease,
    transform 0.28s var(--ease),
    overlay 0.28s allow-discrete,
    display 0.28s allow-discrete;
}

.dialog {
  opacity: 0;
  transform: translateY(12px) scale(0.98);
}

.dialog[open] {
  opacity: 1;
  transform: none;
}

.dialog::backdrop {
  opacity: 0;
}

.dialog[open]::backdrop {
  opacity: 1;
}

@starting-style {
  .dialog[open] {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }

  .dialog[open]::backdrop {
    opacity: 0;
  }
}

/* Switching filters or the trash: the old list fades, the new one slides in. */
::view-transition-old(leads-sheet) {
  animation: sheet-out 0.16s ease both;
}

::view-transition-new(leads-sheet) {
  animation: sheet-in 0.32s var(--ease) both;
}

@keyframes sheet-out {
  to {
    opacity: 0;
  }
}

@keyframes sheet-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after,
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .skel {
    animation: none;
  }
}
