/* АвтоCRM. Палитра: асфальт, бумага, дорожная разметка. */
:root {
  --paper: #f2f3ef;
  --surface: #ffffff;
  --ink: #1e232a;
  --asphalt: #2a2f36;
  --asphalt-2: #353b43;
  --steel: #69717c;
  --line: #d8dbd3;
  --signal: #f2b705;
  --signal-soft: #fdf3cf;
  --risk: #b3412e;
  --risk-soft: #f8e3de;
  --ok: #2e7a4e;
  --ok-soft: #e0efe5;
  --radius: 6px;
  --font: "Segoe UI", "Roboto", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.45 var(--font);
  color: var(--ink);
  background: var(--paper);
  font-variant-numeric: tabular-nums;
}
a { color: inherit; }
a:hover { color: #000; }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }
h1 { font-size: 24px; line-height: 1.2; margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
.muted { color: var(--steel); }
.risk { color: var(--risk); font-weight: 600; }
.nowrap { white-space: nowrap; }
.r { text-align: right; }

/* ---------- каркас ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side {
  background: var(--asphalt);
  color: #e7e9ec;
  display: flex; flex-direction: column;
  padding: 20px 0;
  position: sticky; top: 0; height: 100vh;
}
.brand {
  font-weight: 700; font-size: 18px; text-decoration: none;
  padding: 0 20px 18px; color: #fff;
  border-bottom: 2px dashed var(--signal);
  margin: 0 20px 14px; padding-left: 0;
}
.nav { display: flex; flex-direction: column; }
.nav a {
  text-decoration: none; padding: 9px 20px; color: #c9cdd3;
  border-left: 4px solid transparent;
  display: flex; justify-content: space-between; align-items: center;
}
.nav a:hover { background: var(--asphalt-2); color: #fff; }
.nav a.on { border-left-color: var(--signal); color: #fff; background: var(--asphalt-2); }
.count {
  background: var(--signal); color: var(--ink); font-size: 12px; font-weight: 700;
  border-radius: 10px; padding: 0 7px; min-width: 22px; text-align: center;
}
.me { margin-top: auto; padding: 14px 20px 0; border-top: 1px solid var(--asphalt-2); font-size: 13px; }
.me .muted { color: #9aa1aa; }
.linkbtn { background: none; border: 0; color: #c9cdd3; padding: 6px 0 0; cursor: pointer; font: inherit; text-decoration: underline; }

.main { padding: 24px 32px 48px; min-width: 0; max-width: 1500px; }
.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.sub { color: var(--steel); margin-top: 4px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.actions form { margin: 0; }

/* ---------- кнопки, поля ---------- */
.btn {
  display: inline-block; font: inherit; font-weight: 600;
  padding: 7px 14px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  text-decoration: none; cursor: pointer; line-height: 1.3;
}
.btn:hover { border-color: var(--steel); }
.btn-main { background: var(--asphalt); color: #fff; border-color: var(--asphalt); }
.btn-main:hover { background: #000; color: #fff; }
.btn-danger { color: var(--risk); border-color: #e3b9b0; }
.btn-danger:hover { background: var(--risk-soft); }

input, select, textarea {
  font: inherit; color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 7px 9px; background: #fff; width: 100%;
}
textarea { resize: vertical; }
input[type="checkbox"] { width: auto; }

.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 16px;
}
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.panel-head h2 { margin: 0; }

.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 16px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field.wide { grid-column: 1 / -1; }
.field label { font-size: 13px; color: var(--steel); }
.field.check label { color: var(--ink); display: flex; gap: 8px; align-items: center; padding-top: 22px; }
.field small { font-size: 12px; }
.field .err { color: var(--risk); }
.field.has-error input, .field.has-error select { border-color: var(--risk); }
.form-foot { margin-top: 16px; display: flex; gap: 8px; }
.inline-form { display: flex; flex-direction: column; gap: 8px; }
.inline-form h2 { margin-bottom: 4px; }
.inline-form .btn { align-self: flex-start; }
.danger-zone { margin-top: 8px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters input, .filters select { width: auto; min-width: 160px; }
.filters input.short { min-width: 90px; width: 90px; }
.filters label { display: flex; gap: 6px; align-items: center; color: var(--steel); }
.check-inline input { min-width: 0 !important; }
.presets a { margin-left: 10px; color: var(--steel); }
.hint { margin: -6px 0 12px; }

/* ---------- сообщения ---------- */
.messages { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.msg { padding: 9px 12px; border-radius: var(--radius); border: 1px solid var(--line); background: #fff; }
.msg-success { border-color: #b8d8c3; background: var(--ok-soft); }
.msg-error { border-color: #e3b9b0; background: var(--risk-soft); }
.msg-warning, .msg-info { border-color: #ecd68b; background: var(--signal-soft); }

/* ---------- таблицы ---------- */
.tbl { width: 100%; border-collapse: collapse; background: var(--surface); }
.panel .tbl { background: transparent; }
.main > .tbl { border: 1px solid var(--line); border-radius: var(--radius); }
.tbl th {
  text-align: left; font-weight: 600; font-size: 12.5px; color: var(--steel);
  padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.tbl th.r { text-align: right; }
.tbl td { padding: 8px 10px; border-bottom: 1px solid #eceee8; vertical-align: top; }
.tbl tfoot td { font-weight: 600; border-top: 1px solid var(--line); }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: #f7f8f4; }
.tbl a { text-decoration: none; font-weight: 600; }
.row-stuck td:first-child { box-shadow: inset 3px 0 0 var(--risk); }

.tag {
  display: inline-block; font-size: 12px; font-weight: 600; white-space: nowrap;
  padding: 1px 8px; border-radius: 10px; background: #eceee8; color: var(--ink);
}
.tag-new, .tag-applied, .tag-ordered { background: var(--signal-soft); }
.tag-in_work, .tag-approved, .tag-in_transit, .tag-purchased { background: #e3e8ef; }
.tag-converted, .tag-closed, .tag-issued, .tag-delivered, .tag-in_stock { background: var(--ok-soft); color: var(--ok); }
.tag-rejected, .tag-lost, .tag-risk { background: var(--risk-soft); color: var(--risk); }

.row-link {
  display: flex; justify-content: space-between; gap: 10px; text-decoration: none;
  padding: 7px 0; border-bottom: 1px solid #eceee8;
}
.row-link:last-child { border-bottom: 0; }
.row-link:hover span:first-child { text-decoration: underline; }
.kv { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px dotted var(--line); }
.kv span { color: var(--steel); }
.pager { display: flex; gap: 12px; align-items: center; margin-top: 12px; }

/* ---------- раскладки ---------- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid2 > .panel { margin-bottom: 16px; }
.detail { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(300px, 1fr); gap: 16px; align-items: start; }

.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 16px; }
.figures div { background: var(--surface); padding: 14px 16px; display: flex; flex-direction: column; }
.figures b { font-size: 22px; font-weight: 600; }
.figures span { color: var(--steel); font-size: 13px; }

/* ---------- главная: дорожка этапов ---------- */
.lane-summary { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.lane-cell {
  text-decoration: none; padding: 10px 10px 8px; border-radius: 4px;
  background: #eef0eb; display: flex; flex-direction: column; gap: 2px;
  border-bottom: 4px solid #d3d6cf;
}
.lane-cell b { font-size: 20px; }
.lane-cell span { font-size: 12px; color: var(--steel); line-height: 1.25; }
.lane-cell.has { border-bottom-color: var(--signal); background: #fff; }

/* ---------- полоса этапов сделки: разметка на асфальте ---------- */
.stage-strip {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px;
  background: var(--asphalt); padding: 10px; border-radius: var(--radius); margin-bottom: 16px;
}
.seg { margin: 0; }
.seg button {
  width: 100%; height: 100%; min-height: 46px; font: inherit; font-size: 12.5px; font-weight: 600;
  border: 0; border-radius: 3px; cursor: pointer; padding: 6px 6px 10px; line-height: 1.2;
  position: relative; color: #c9cdd3; background: var(--asphalt-2);
}
.seg button::after {
  content: ""; position: absolute; left: 8px; right: 8px; bottom: 4px; height: 3px; border-radius: 2px;
  background: #4a515a;
}
.seg-done button { color: #fff; }
.seg-done button::after { background: #fff; }
.seg-current button { background: var(--signal); color: var(--ink); }
.seg-current button::after { background: var(--ink); }
.seg button:hover:not(:disabled) { outline: 2px solid var(--signal); outline-offset: -2px; }
.seg button:disabled { cursor: default; }
.stage-strip.is-lost .seg button { opacity: .45; }

/* ---------- канбан ---------- */
.board { display: grid; grid-template-columns: repeat(7, minmax(190px, 1fr)); gap: 10px; overflow-x: auto; padding-bottom: 8px; }
.col { background: #e7e9e3; border-radius: var(--radius); display: flex; flex-direction: column; min-height: 60vh; }
.col-head { padding: 10px 10px 8px; border-bottom: 3px dashed #c9ccc4; }
.col-title { font-weight: 600; font-size: 13px; }
.col-meta { font-size: 12px; color: var(--steel); display: flex; gap: 8px; }
.col-count { font-weight: 700; color: var(--ink); }
.col-body { padding: 8px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.col.drop-ok { background: var(--signal-soft); }
.col.drop-ok .col-head { border-bottom-color: var(--signal); }
.card {
  display: block; text-decoration: none; background: #fff; border-radius: 4px;
  padding: 8px 10px; border: 1px solid var(--line); cursor: grab;
}
.card:hover { border-color: var(--steel); }
.card.dragging { opacity: .4; }
.card.stuck { box-shadow: inset 3px 0 0 var(--risk); }
.card.overdue .card-top span:last-child { color: var(--risk); font-weight: 700; }
.card-top, .card-foot { display: flex; justify-content: space-between; font-size: 12px; color: var(--steel); }
.card-name { font-weight: 600; margin: 2px 0; }
.card-car { font-size: 12.5px; color: var(--steel); }
.card-foot { margin-top: 6px; }

/* ---------- отчёты ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { text-decoration: none; padding: 8px 14px; color: var(--steel); border-bottom: 3px solid transparent; margin-bottom: -2px; font-weight: 600; }
.tabs a.on { color: var(--ink); border-bottom-color: var(--signal); }
.funnel { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.f-row { display: grid; grid-template-columns: 200px 1fr 50px 150px; gap: 12px; align-items: center; }
.f-label { font-size: 13px; }
.f-bar { height: 18px; background: #eef0eb; border-radius: 3px; overflow: hidden; }
.f-bar span { display: block; height: 100%; background: var(--asphalt); border-right: 3px solid var(--signal); }
.risk-bar span { background: var(--risk); border-right-color: var(--risk); }
.f-num { text-align: right; font-weight: 600; }
.f-pct { font-size: 12.5px; color: var(--steel); }

/* ---------- заметки и история ---------- */
.note-form { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.note-form .btn { align-self: flex-start; }
.note { padding: 8px 0; border-top: 1px solid #eceee8; }
.note-meta { font-size: 12px; color: var(--steel); margin-bottom: 2px; }
.log { display: grid; grid-template-columns: 110px 1fr auto; gap: 8px; font-size: 13px; padding: 4px 0; }

/* ---------- вход ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; background: var(--asphalt); }
.login { background: #fff; padding: 28px; border-radius: var(--radius); width: 320px; display: flex; flex-direction: column; gap: 12px; }
.login label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--steel); }
.lane { display: flex; gap: 8px; margin: -4px 0 6px; }
.lane span { height: 4px; flex: 1; background: var(--signal); border-radius: 2px; }

@media (max-width: 1100px) {
  .detail, .grid2 { grid-template-columns: 1fr; }
  .lane-summary { grid-template-columns: repeat(4, 1fr); }
  .stage-strip { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; padding: 12px 0; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav a { border-left: 0; border-bottom: 3px solid transparent; padding: 6px 12px; }
  .nav a.on { border-bottom-color: var(--signal); }
  .me { display: none; }
  .main { padding: 16px; }
  .f-row { grid-template-columns: 1fr 40px; }
  .f-bar, .f-pct { display: none; }
  .lane-summary, .stage-strip { grid-template-columns: repeat(2, 1fr); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
