/* DeStressToys CRM — one quiet workspace, one loud signal: how long a client has been waiting. */
:root {
  --bg: #eef1f4;
  --surface: #ffffff;
  --surface-2: #f6f8fa;
  --ink: #16202a;
  --muted: #5b6875;
  --line: #d8dee4;
  --focus: #1d4ed8;
  --out: #e3ecfb;          /* our messages */
  --foam-1: #ffc83d;       /* waiting < 4 h: squeeze ball yellow */
  --foam-2: #ff9a2e;       /* < 24 h */
  --foam-3: #e5484d;       /* a day or more */
  --ok: #15803d;
  --ch-telegram: #229ed9;
  --ch-max: #6e56cf;
  --ch-email: #64748b;
  --ch-form: #15803d;
  --ch-amo_import: #b45309;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(22 32 42 / 0.06), 0 1px 1px rgb(22 32 42 / 0.04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f151b; --surface: #17202a; --surface-2: #1d2833; --ink: #e7edf3; --muted: #97a4b1;
    --line: #2a3542; --focus: #7aa2ff; --out: #1f3350; --ok: #4ade80;
    --shadow: none; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 var(--font); font-variant-numeric: tabular-nums;
  padding-bottom: 72px; /* room for the mobile tab bar */
}
a { color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.35rem; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; font-weight: 650; }
h3 { font-size: 0.95rem; font-weight: 600; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 0.85em; }
.page { max-width: 1400px; margin: 0 auto; padding: 16px; }
.page.narrow { max-width: 760px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- navigation: top on desktop, thumb-reach tab bar on phones ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar .inner { max-width: 1400px; margin: 0 auto; padding: 10px 16px; display: flex; gap: 16px; align-items: center; }
.brand { font-weight: 700; letter-spacing: -0.02em; text-decoration: none; }
.brand span { color: var(--muted); font-weight: 500; }
.tabs { display: flex; gap: 4px; }
.tabs a {
  text-decoration: none; padding: 8px 12px; border-radius: 8px; color: var(--muted); font-weight: 500;
  display: inline-flex; gap: 6px; align-items: center; min-height: 40px;
}
.tabs a[aria-current="page"] { color: var(--ink); background: var(--surface-2); }
.count {
  min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; font-size: 0.75rem; font-weight: 700;
  display: inline-grid; place-items: center; background: var(--line); color: var(--ink);
}
.count.hot { background: var(--foam-1); color: #3b2a00; }
.logout { margin-left: auto; }
@media (max-width: 719px) {
  .topbar .tabs { position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface);
    border-top: 1px solid var(--line); justify-content: space-around; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .tabs a { flex-direction: column; gap: 2px; font-size: 0.72rem; padding: 4px 6px; min-width: 64px; }
  .tabs a[aria-current="page"] { background: none; color: var(--focus); }
}
@media (min-width: 720px) { body { padding-bottom: 0; } }

/* ---------- controls ---------- */
button, .button, input, select, textarea { font: inherit; color: inherit; }
button, .button {
  min-height: 44px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-weight: 600; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
button.primary { background: var(--ink); color: var(--surface); border-color: var(--ink); }
button.danger { color: var(--foam-3); }
button.link { border: 0; background: none; padding: 0 4px; min-height: 32px; color: var(--muted); font-weight: 500; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface);
}
textarea { min-height: 96px; resize: vertical; }
label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.search { display: flex; gap: 8px; margin: 12px 0 16px; }
.search input { flex: 1; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px; border-radius: 18px;
  border: 1px solid var(--line); background: var(--surface); text-decoration: none; font-size: 0.9rem;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }

/* ---------- the signature: waiting ball ---------- */
.wait {
  --c: var(--foam-1);
  flex: none; width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center;
  background: var(--c); color: #2b1d00; font-size: 0.72rem; font-weight: 800; line-height: 1; text-align: center;
  box-shadow: inset -3px -4px 0 rgb(0 0 0 / 0.12), inset 3px 3px 0 rgb(255 255 255 / 0.35);
}
.wait.l2 { --c: var(--foam-2); }
.wait.l3 { --c: var(--foam-3); color: #fff; }
.wait.none { background: transparent; box-shadow: inset 0 0 0 2px var(--line); color: var(--muted); font-weight: 600; }
.wait.lg { width: 64px; height: 64px; font-size: 0.9rem; }
@media (prefers-reduced-motion: no-preference) {
  .wait.l3 { animation: squeeze 2.4s ease-in-out infinite; }
  @keyframes squeeze { 0%, 88%, 100% { transform: scale(1, 1); } 93% { transform: scale(1.08, 0.9); } }
}

/* ---------- pipeline ---------- */
.board { display: grid; gap: 16px; }
@media (min-width: 1000px) {
  .board { grid-auto-flow: column; grid-auto-columns: minmax(270px, 1fr); overflow-x: auto; align-items: start; padding-bottom: 8px; }
}
.column-head { display: flex; justify-content: space-between; align-items: baseline; margin: 0 2px 8px; }
.column-head .sum { color: var(--muted); font-size: 0.85rem; }
.cards { display: grid; gap: 8px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px; display: flex; gap: 12px; align-items: flex-start; text-decoration: none;
}
.card:hover { border-color: var(--muted); }
.card .body { min-width: 0; flex: 1; }
.card .title { font-weight: 600; overflow-wrap: anywhere; }
.card .meta { display: flex; gap: 8px; flex-wrap: wrap; font-size: 0.82rem; color: var(--muted); margin-top: 4px; }
.card .amount { font-weight: 650; white-space: nowrap; }
.closed-stages summary { cursor: pointer; color: var(--muted); padding: 8px 2px; min-height: 44px; }
.empty { color: var(--muted); font-size: 0.9rem; padding: 12px; border: 1px dashed var(--line); border-radius: var(--radius); }

.ch { display: inline-flex; align-items: center; gap: 5px; font-size: 0.78rem; color: var(--muted); }
.ch::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--dot, var(--muted)); }
.ch-telegram { --dot: var(--ch-telegram); } .ch-max { --dot: var(--ch-max); } .ch-email { --dot: var(--ch-email); }
.ch-form { --dot: var(--ch-form); } .ch-amo_import { --dot: var(--ch-amo_import); }
.badge { font-size: 0.72rem; font-weight: 700; padding: 2px 8px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); }
.badge.approval { background: var(--out); border-color: transparent; }

/* ---------- deal page ---------- */
.deal-head { display: flex; gap: 14px; align-items: center; margin-bottom: 16px; }
.deal-head .client { color: var(--muted); }
.deal-grid { display: grid; gap: 16px; }
@media (min-width: 1000px) { .deal-grid { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; } }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.panel + .panel { margin-top: 16px; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fields .wide { grid-column: 1 / -1; }
.saved, .resolved { color: var(--ok); font-weight: 600; font-size: 0.9rem; }
.error { color: var(--foam-3); font-weight: 600; }

.timeline { display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: min(640px, 92%); padding: 10px 12px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.msg.in { align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.out { align-self: flex-end; background: var(--out); border-color: transparent; border-bottom-right-radius: 4px; }
.msg .head { display: flex; gap: 8px; align-items: center; font-size: 0.78rem; color: var(--muted); margin-bottom: 4px; }
.msg .subject { font-weight: 600; margin-bottom: 4px; }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg details { margin-top: 6px; font-size: 0.85rem; color: var(--muted); }
.msg details summary { cursor: pointer; }
.msg details pre { white-space: pre-wrap; font: inherit; margin: 6px 0 0; }
.event { align-self: center; font-size: 0.8rem; color: var(--muted); text-align: center; }
.reply { margin-top: 16px; scroll-margin-top: 72px; }
.deal-head .to-reply { margin-left: auto; }

.check { font-size: 0.9rem; border-left: 3px solid var(--line); padding-left: 10px; }
.check.warn { border-color: var(--foam-2); }
.check dt { color: var(--muted); font-size: 0.78rem; margin-top: 6px; }
.check dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.draft-text { white-space: pre-wrap; background: var(--surface-2); border-radius: 8px; padding: 10px 12px; }
.pair { display: grid; gap: 12px; }
@media (min-width: 720px) { .pair { grid-template-columns: 1fr 1fr; } }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li + li { margin-top: 4px; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(360px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 24px; }
.login .wait { margin-bottom: 14px; }
.full { width: 100%; }
.filters { margin-bottom: 16px; }
.tags { margin-top: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* phones: empty stages only take room — list them in one line instead */
@media (max-width: 999px) { .board > section.is-empty { display: none; } }
@media (min-width: 1000px) { .empty-stages { display: none; } }
.empty-stages { font-size: 0.85rem; margin: 4px 2px 12px; }
.fields > *, .deal-grid > * { min-width: 0; }
