:root {
  --bg: #f4f4f1;
  --card: #fff;
  --text: #16161a;
  --muted: #6b6b73;
  --line: #e4e4df;
  --accent: #c8f53a;
  --accent-ink: #0b0b0c;
  --dark: #0b0b0c;
  --danger: #c0392b;
  --ok: #2f8a3d;
  --radius: 12px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
a { color: inherit; }
main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 60px; }
h1 { font-size: 24px; margin: 0; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
h2 { font-size: 16px; margin: 0 0 12px; }
code { background: #f0f0ea; padding: 1px 5px; border-radius: 4px; }

/* шапка */
.top { background: var(--dark); color: #fff; display: flex; align-items: center; gap: 24px; padding: 0 16px; min-height: 56px; flex-wrap: wrap; position: sticky; top: 0; z-index: 5; }
.logo { font-weight: 800; letter-spacing: .04em; text-decoration: none; color: #fff; white-space: nowrap; }
.logo b { color: var(--accent); }
.logo span { font-weight: 500; color: #888; font-size: 12px; margin-left: 4px; }
.logo.big { font-size: 28px; color: var(--dark); text-align: center; margin-bottom: 20px; }
.top nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.top nav a, .me a { text-decoration: none; color: #bbb; padding: 8px 12px; border-radius: 8px; white-space: nowrap; }
.top nav a:hover, .me a:hover { color: #fff; }
.top nav a.on, .me a.on { color: var(--accent-ink); background: var(--accent); }
.cnt { background: #e74c3c; color: #fff; border-radius: 10px; padding: 0 7px; font-size: 12px; margin-left: 2px; }
.me { display: flex; gap: 4px; align-items: center; }
.me form { margin: 0; }
.me .link { color: #888; }

/* общие блоки */
.head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 4px 0 16px; flex-wrap: wrap; }
.sub { margin: -10px 0 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.cards .card { margin: 0; display: flex; flex-direction: column; gap: 6px; }
.cards .card p { margin: 4px 0; flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + .card, .grid2 + .grid2, .grid2 + details { margin-top: 16px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.empty { background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); padding: 40px 20px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.late { color: var(--danger); }
.ok { color: var(--ok); }
.flash { background: var(--accent); color: var(--accent-ink); padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-weight: 600; }
.err { background: #fdecea; color: var(--danger); padding: 10px 12px; border-radius: 8px; }

/* кнопки и формы */
.btn { display: inline-block; background: var(--dark); color: #fff; border: 1px solid var(--dark); padding: 9px 16px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: #2a2a2e; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--text); }
.btn.danger { background: transparent; color: var(--danger); border-color: #f0c8c3; }
.lead .btn:not(.ghost) { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.link { background: none; border: 0; padding: 4px; font: inherit; color: var(--muted); cursor: pointer; text-decoration: underline; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; align-items: center; }
.actions form { margin: 0; display: flex; gap: 6px; flex-wrap: wrap; }
input, select, textarea { font: inherit; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); border-color: #9bc21f; }
.form { display: flex; flex-direction: column; gap: 12px; }
.form.wide { max-width: 720px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.form label.check { flex-direction: row; align-items: center; gap: 8px; padding-top: 22px; }
.form label.check input { width: auto; }
.form .btn { align-self: flex-start; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.inline { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.inline input, .inline select { width: auto; flex: 1 1 140px; }
.search { display: flex; gap: 8px; margin-bottom: 16px; max-width: 520px; }
details > summary { cursor: pointer; list-style: none; }
details > summary h2 { display: inline; }
details > summary::before { content: "▸ "; }
details[open] > summary::before { content: "▾ "; }
details[open] > summary { margin-bottom: 12px; }

/* вкладки */
.tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs.scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
.tabs a { text-decoration: none; padding: 7px 14px; border-radius: 20px; border: 1px solid var(--line); background: var(--card); white-space: nowrap; font-size: 14px; }
.tabs a.on { background: var(--dark); color: #fff; border-color: var(--dark); }

/* таблицы */
.table { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #fafaf6; }
tbody tr:last-child td { border-bottom: 0; }
tr.off { opacity: .5; }
td a { text-decoration: none; font-weight: 600; }
.r { text-align: right; white-space: nowrap; }
table.plain td { padding: 7px 6px; }
table.plain { margin-bottom: 10px; }

/* значки статусов */
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 20px; background: #eee; color: #444; white-space: nowrap; vertical-align: middle; }
.st-new, .ld-new { background: #e8f0ff; color: #2456c7; }
.st-contract { background: #f3e8ff; color: #7a32c4; }
.st-in_work, .ld-taken { background: #fff3d6; color: #8a5a00; }
.st-review { background: #ffe9dc; color: #b04a0e; }
.st-done { background: #e3f6e6; color: #22722f; }
.st-paid, .ld-converted { background: var(--accent); color: var(--accent-ink); }
.st-cancelled, .ld-rejected { background: #eee; color: #888; }
.sg-cold { background: #eee; color: #555; }
.sg-contacted { background: #e8f0ff; color: #2456c7; }
.sg-replied { background: #fff3d6; color: #8a5a00; }
.sg-talks { background: #f3e8ff; color: #7a32c4; }
.sg-client { background: var(--accent); color: var(--accent-ink); }
.sg-later { background: #e6f2f2; color: #2c6e6e; }
.sg-lost { background: #eee; color: #999; }
select.stage { font: inherit; font-size: 13px; font-weight: 600; min-width: 140px; padding: 5px 8px; border-radius: 20px; border: 1px solid transparent; cursor: pointer; }
select.stage.sg-cold { border-color: var(--line); background: var(--card); }
td.step { min-width: 170px; }
.items { display: flex; flex-direction: column; gap: 10px; }
.items .item { display: grid; grid-template-columns: 1.4fr 1fr auto; gap: 10px; align-items: end; }
.items.with-fee .item { grid-template-columns: 1.4fr 1fr 1fr auto; }
.items .del { padding: 9px 12px; }
.items .del[hidden] { display: none; }
.items-foot { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
@media (max-width: 640px) { .items .item, .items.with-fee .item { grid-template-columns: 1fr 1fr; } .items .item label:first-child { grid-column: 1 / -1; } }

/* карточки */
dl { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; margin: 0 0 8px; }
dt { color: var(--muted); font-size: 13px; }
dd { margin: 0; }
.events { list-style: none; padding: 0; margin: 0 0 8px; display: flex; flex-direction: column; gap: 10px; }
.events li { border-left: 3px solid var(--line); padding-left: 10px; }
.events li.comment { border-color: var(--accent); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 14px; }
.stats > div { background: #f7f7f3; border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.stats.big > div { background: var(--card); border: 1px solid var(--line); padding: 16px 18px; }
.stats span { font-size: 13px; color: var(--muted); }
.stats b { font-size: 22px; }
.stats.big b { font-size: 26px; }
.stats small { color: var(--muted); }

/* вход */
.login { max-width: 360px; margin: 10vh auto 0; }
.login .card { display: flex; flex-direction: column; gap: 14px; }
.login label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }

@media (max-width: 760px) {
  .grid2, .two, .stats { grid-template-columns: 1fr; }
  dl { grid-template-columns: 1fr; gap: 2px; }
  dd { margin-bottom: 8px; }
  .top { gap: 8px; padding: 8px 12px; }
  .top nav { order: 3; flex-basis: 100%; }
  .me { margin-left: auto; }
  h1 { font-size: 20px; }
  .cards { grid-template-columns: 1fr; }
}
