:root {
  --bg: #f4f4f2;
  --surface: #ffffff;
  --ink: #111111;
  --muted: #66666b;
  --line: #e3e3df;
  --black: #000000;
  --accent: #111111;
  --danger: #b3261e;
  --radius: 8px;

  --st-0: #8a8a90;
  --st-0-bg: #ececee;
  --st-1: #1d5fd1;
  --st-1-bg: #e1ebfc;
  --st-2: #a45f00;
  --st-2-bg: #fdefd3;
  --st-3: #14733a;
  --st-3-bg: #dcf3e3;
  --st-4: #b3261e;
  --st-4-bg: #fbe3e1;
}

* { box-sizing: border-box; }

html, body, #app { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

h1 { font-size: 24px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 10px; }
p { margin: 0; }
a { color: var(--st-1); }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); padding: 12px 0; list-style: none; }

/* ---------------------------------------------------------------- controls */

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

input[type="text"], input[type="email"], input[type="password"], input[type="date"],
input[type="search"], select, textarea {
  width: 100%;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid #c9c9c4;
  border-radius: 6px;
}

textarea { resize: vertical; }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid #c9c9c4;
  border-radius: 6px;
  font-weight: 600;
  text-decoration: none;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: #f0f0ee; }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-primary { background: var(--black); border-color: var(--black); color: #fff; }
.btn-primary:hover { background: #2b2b2b; }
.btn-danger { color: var(--danger); border-color: #e5b5b1; }
.btn-danger:hover { background: var(--st-4-bg); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.push-right { margin-left: auto; }

.link-btn {
  padding: 0;
  background: none;
  border: 0;
  color: var(--st-1);
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}
.link-btn:hover { text-decoration: underline; }

.icon-btn {
  width: 32px;
  height: 32px;
  background: none;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
}
.icon-btn:hover { background: #ececea; }

.field { display: block; margin-bottom: 14px; min-width: 0; }
.field-label { display: block; margin-bottom: 4px; font-weight: 600; font-size: 13px; }
.field-hint { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-error { color: var(--danger); min-height: 20px; margin-bottom: 8px; }
.input-row { display: flex; gap: 8px; }

.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--black); }

/* -------------------------------------------------------------------- auth */

.auth {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 24px 16px;
  background: var(--black);
}
.auth-logo { width: 220px; max-width: 70%; }
.auth-card {
  width: 100%;
  max-width: 380px;
  padding: 28px;
  background: var(--surface);
  border-radius: 12px;
}
.auth-card h1 { margin-bottom: 6px; }
.auth-card > .muted { margin-bottom: 20px; }
.auth-card .small { margin-top: 14px; text-align: center; }

/* ------------------------------------------------------------------- shell */

.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); height: 100%; }

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--black);
  color: #fff;
  padding: 18px 12px;
  overflow-y: auto;
}

.brand { display: block; padding: 0 8px 18px; color: #fff; text-decoration: none; }
.brand img { display: block; width: 150px; margin-left: -12px; }
.brand span { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: #a9a9ad; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  padding: 9px 10px;
  border-radius: 6px;
  color: #d2d2d6;
  text-decoration: none;
  font-weight: 600;
}
.nav a:hover { background: #1f1f1f; color: #fff; }
.nav a.active { background: #fff; color: #000; }

.sidebar-user {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  align-items: center;
  margin-top: auto;
  padding: 14px 8px 0;
  border-top: 1px solid #2a2a2a;
}
.sidebar-user-name { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.sidebar-user-name small { display: block; color: #a9a9ad; font-weight: 400; }
.sidebar-user .link-btn { grid-column: 2; color: #d2d2d6; font-weight: 400; }

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 50%;
  background: #fff;
  color: #000;
  font-size: 12px;
  font-weight: 700;
}
.avatar-sm { width: 24px; height: 24px; font-size: 10px; background: var(--black); color: #fff; }

#main { overflow-y: auto; padding: 28px 32px 60px; }

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}
.page-head .muted { margin-top: 4px; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.card.narrow { max-width: 420px; }
.table-scroll { overflow-x: auto; }
.card.table-scroll { padding: 0; }
.card.table-scroll .empty { padding: 24px 18px; }

/* --------------------------------------------------------------- dashboard */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.tile {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: left;
  cursor: pointer;
}
.tile:hover { border-color: #9b9b97; }
.tile-num { font-size: 28px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile-label { color: var(--muted); font-size: 13px; }

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

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 6px;
  border-radius: 50%;
}
.dot.st-0, .bar .st-0 { background: var(--st-0); }
.dot.st-1, .bar .st-1 { background: var(--st-1); }
.dot.st-2, .bar .st-2 { background: #e39a1b; }
.dot.st-3, .bar .st-3 { background: #2aa35a; }
.dot.st-4, .bar .st-4 { background: #d9534a; }

.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-bottom: 10px; color: var(--muted); font-size: 12px; }

.rows, .feed { list-style: none; margin: 0; padding: 0; }
.rows { max-height: 300px; overflow-y: auto; }
.rows li + li { border-top: 1px solid var(--line); }
.row-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 9px 4px;
  background: none;
  border: 0;
  text-align: left;
  cursor: pointer;
}
.row-btn:hover { background: #f6f6f4; }
.row-main { min-width: 0; }
.row-main small { display: block; color: var(--muted); }

.cat-table { width: 100%; border-collapse: collapse; }
.cat-table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 8px; }
.cat-table th.num { text-align: right; }
.cat-table td { padding: 8px; border-top: 1px solid var(--line); }
.bar-cell { width: 55%; min-width: 140px; }
.bar { display: flex; gap: 2px; height: 10px; border-radius: 5px; overflow: hidden; }
.bar span { display: block; height: 100%; }

.feed li { padding: 10px 0; }
.feed li + li { border-top: 1px solid var(--line); }
.feed-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 12px; }
.feed-head small { color: var(--muted); }
.feed p { margin-top: 3px; white-space: pre-wrap; overflow-wrap: anywhere; }
.feed-change { color: var(--muted); font-size: 13px; }

/* ----------------------------------------------------------------- filters */

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  margin-bottom: 12px;
}
.filters .search { flex: 1 1 240px; width: auto; }
.filters select { width: auto; max-width: 100%; }
.filters + .muted { margin-bottom: 10px; }

/* ------------------------------------------------------------------- table */

table.data { width: 100%; border-collapse: collapse; }
table.data th {
  position: sticky;
  top: 0;
  padding: 10px 12px;
  background: #fafaf8;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}
table.data th.num { text-align: right; }
table.data td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f8f8f6; }
tr.inactive td { color: var(--muted); }

.th-btn { padding: 0; background: none; border: 0; font: inherit; color: inherit; cursor: pointer; }
.th-btn:hover { color: var(--ink); }

.col-company { min-width: 180px; }
.cell-btn {
  padding: 0;
  margin-right: 6px;
  background: none;
  border: 0;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.col-contact { min-width: 200px; max-width: 280px; overflow-wrap: anywhere; font-size: 13px; }
.col-notes { min-width: 240px; max-width: 380px; color: var(--muted); font-size: 13px; }
.clamp {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.row-actions { white-space: nowrap; text-align: right; }
.row-actions .btn + .btn { margin-left: 6px; }

.tag {
  display: inline-block;
  padding: 1px 7px;
  border: 1px solid #c9c9c4;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.badge, .status-select {
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge { display: inline-block; padding: 2px 10px; }
.status-select { width: auto; padding: 4px 8px; border-color: transparent; cursor: pointer; }
.badge.st-0, .status-select.st-0 { background: var(--st-0-bg); color: #4b4b50; }
.badge.st-1, .status-select.st-1 { background: var(--st-1-bg); color: var(--st-1); }
.badge.st-2, .status-select.st-2 { background: var(--st-2-bg); color: var(--st-2); }
.badge.st-3, .status-select.st-3 { background: var(--st-3-bg); color: var(--st-3); }
.badge.st-4, .status-select.st-4 { background: var(--st-4-bg); color: var(--st-4); }

.due { font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.due-over { color: var(--danger); font-weight: 600; }
.due-today { color: var(--st-2); font-weight: 600; }

/* ---------------------------------------------------------------- pipeline */

.board {
  display: grid;
  grid-template-columns: repeat(5, minmax(230px, 1fr));
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
}
.column {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 230px);
  min-height: 200px;
  padding: 12px 8px 8px;
  background: #eaeae7;
  border: 2px solid transparent;
  border-radius: var(--radius);
}
.column.drop { border-color: var(--black); }
.column h2 { display: flex; align-items: center; margin: 0 4px 10px; font-size: 13px; }
.count { margin-left: auto; color: var(--muted); font-weight: 400; }
.cards { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; padding: 2px; }
.kcard {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: grab;
  overflow-wrap: anywhere;
}
.kcard:hover { border-color: #9b9b97; }
.kcard-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; }

/* ------------------------------------------------------------------ drawer */

.overlay { position: fixed; inset: 0; z-index: 20; }
.overlay-bg { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.4); }
.drawer {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(560px, 100%);
  overflow-y: auto;
  background: var(--surface);
  box-shadow: -8px 0 30px rgba(0, 0, 0, 0.2);
}
.drawer-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.drawer-head h2 { margin: 0; font-size: 18px; overflow-wrap: anywhere; }
.drawer-form { padding: 20px 24px; }
.drawer-form > .check { margin-bottom: 14px; }
.drawer-actions { display: flex; gap: 8px; margin-top: 6px; }
.links { margin: -6px 0 14px; font-size: 13px; overflow-wrap: anywhere; color: var(--muted); }
.drawer-activity { padding: 20px 24px 40px; border-top: 1px solid var(--line); background: #fafaf8; }
.comment-form { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; margin-bottom: 8px; }

.modal {
  width: min(440px, calc(100% - 32px));
  padding: 0;
  border: 0;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.modal::backdrop { background: rgba(0, 0, 0, 0.4); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px 0; }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal form { padding: 16px 20px 20px; }

#toasts {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  padding: 10px 16px;
  background: var(--black);
  color: #fff;
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}
.toast-error { background: var(--danger); }

/* ------------------------------------------------------------------ mobile */

@media (max-width: 820px) {
  .shell { display: block; height: auto; }
  .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px; }
  .brand { padding: 0; }
  .brand img { width: 110px; }
  .brand span { display: none; }
  .nav { flex-direction: row; order: 3; width: 100%; overflow-x: auto; }
  .nav a { padding: 7px 10px; white-space: nowrap; }
  .sidebar-user { margin: 0 0 0 auto; padding: 0; border: 0; grid-template-columns: auto; }
  .sidebar-user .avatar, .sidebar-user-name { display: none; }
  .sidebar-user .link-btn { grid-column: 1; }
  #main { padding: 18px 16px 60px; overflow: visible; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .column { max-height: 70vh; }
  .form-row { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .drawer-head, .drawer-form, .drawer-activity { padding-left: 16px; padding-right: 16px; }
}

/* ---------------------------------------------------------------- language */

.lang { display: inline-flex; gap: 2px; padding: 2px; border: 1px solid #3a3a3a; border-radius: 6px; }
.lang button {
  padding: 3px 10px;
  background: none;
  border: 0;
  border-radius: 4px;
  color: #d2d2d6;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.lang button:hover { color: #fff; }
.lang button.active { background: #fff; color: #000; }
.lang :focus-visible { outline-color: #fff; }

.sidebar-foot { margin-top: auto; padding: 0 8px; }
.sidebar-foot .lang { margin-bottom: 14px; }
.sidebar-foot .sidebar-user { margin-top: 0; padding: 14px 0 0; }

@media (max-width: 820px) {
  .sidebar-foot { display: flex; align-items: center; gap: 12px; margin: 0 0 0 auto; padding: 0; }
  .sidebar-foot .lang { margin: 0; }
  .sidebar-foot .sidebar-user { padding: 0; }
}

table.data select { width: auto; min-width: 110px; }
.owner-select { padding: 4px 8px; border-color: transparent; background: transparent; cursor: pointer; }
.owner-select:hover, .owner-select:focus { border-color: #c9c9c4; background: var(--surface); }
.owner-select.unset { color: var(--muted); }

/* -------------------------------------------------------------- onboarding */

.auth-card.onboarding { max-width: 560px; }
.steps { list-style: none; margin: 0 0 16px; padding: 0; }
.step { display: flex; gap: 14px; padding: 16px 0; border-top: 1px solid var(--line); }
.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 50%;
  background: var(--black);
  color: #fff;
  font-weight: 700;
}
.step-body { min-width: 0; flex: 1; }
.step-body h2 { margin: 3px 0 6px; }
.step-body > .muted { margin-bottom: 10px; }
.substeps { margin: 0 0 12px; padding-left: 18px; }
.substeps li { margin-bottom: 6px; }
code { padding: 2px 6px; background: #ececea; border-radius: 4px; font: 13px ui-monospace, Menlo, monospace; }
.manual { margin-top: 12px; }
.manual summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.manual > .muted { margin: 8px 0; }
.manual .field { margin: 10px 0 0; }
.card.narrow + .card.narrow { margin-top: 16px; }
.card.narrow > .muted { margin-bottom: 8px; }

.feed-email {
  margin-top: 6px;
  padding: 10px 12px;
  background: var(--st-1-bg);
  border-radius: 6px;
  overflow-wrap: anywhere;
}
.feed-email summary { cursor: pointer; list-style: none; position: relative; padding-right: 22px; }
.feed-email summary::-webkit-details-marker { display: none; }
.feed-email summary::after { content: "▸"; position: absolute; top: 0; right: 0; color: var(--st-1); }
.feed-email[open] summary::after { content: "▾"; }
.email-text {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #c4d6f7;
  white-space: pre-wrap;
}
.feed-email strong { color: var(--st-1); }
.feed-email strong::before { content: "✉ "; }
.feed-email dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 4px 0 0; }
.feed-email dt { color: var(--muted); }
.feed-email dd { margin: 0; }

.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 4px; }
.tabs button {
  padding: 3px 12px;
  background: var(--surface);
  border: 1px solid #c9c9c4;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
}
.tabs button.active { background: var(--black); border-color: var(--black); color: #fff; }
.tag.via { margin-left: 8px; font-weight: 400; }
