:root {
  --sidebar: #1c2838;
  --sidebar-2: #253447;
  --sidebar-text: #aab6c5;
  --sidebar-active: #2fc6f6;
  --bg: #eef2f5;
  --surface: #ffffff;
  --surface-2: #f6f8fa;
  --border: #dfe4ea;
  --text: #1f2a37;
  --muted: #6b7785;
  --primary: #1592e6;
  --primary-h: #0b7fcc;
  --success: #22a35a;
  --warn: #e69a12;
  --danger: #e2453c;
  --danger-bg: #fdecea;
  --warn-bg: #fff6e0;
  --ok-bg: #e7f7ee;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 45, .06), 0 2px 8px rgba(20, 30, 45, .05);
  --shadow-lg: 0 10px 40px rgba(20, 30, 45, .25);
  --topbar-h: 60px;
  --sidebar-w: 236px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; -webkit-text-size-adjust: 100%; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; font-weight: 600; }
h2 { font-size: 17px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
svg { width: 18px; height: 18px; flex: none; }
small, .muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- Каркас ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); background: var(--sidebar); color: var(--sidebar-text);
  position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column; z-index: 40;
  transition: transform .2s ease;
}
.brand { display: flex; align-items: center; gap: 10px; height: var(--topbar-h); padding: 0 20px; color: #fff; font-weight: 700; font-size: 17px; }
.brand:hover { text-decoration: none; }
.brand-mark { color: var(--sidebar-active); font-size: 20px; }
.nav { display: flex; flex-direction: column; padding: 8px 10px; gap: 2px; overflow-y: auto; flex: 1; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 8px; color: var(--sidebar-text); font-size: 14.5px; }
.nav a:hover { background: var(--sidebar-2); color: #fff; text-decoration: none; }
.nav a.active { background: var(--sidebar-2); color: #fff; box-shadow: inset 3px 0 0 var(--sidebar-active); }
.nav a.active svg { color: var(--sidebar-active); }
.nav-sep { margin: 16px 12px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #6c7c90; }
.sidebar-foot { padding: 14px 20px; font-size: 12px; color: #6c7c90; border-top: 1px solid rgba(255,255,255,.06); }
.sidebar-backdrop { display: none; }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h); background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; padding: 0 20px; position: sticky; top: 0; z-index: 30;
}
.topbar .burger { display: none; }
.search { flex: 1; max-width: 560px; position: relative; display: flex; align-items: center; }
.search > svg { position: absolute; left: 12px; color: var(--muted); }
.search input { width: 100%; padding: 9px 12px 9px 38px; border-radius: 20px; background: var(--surface-2); border: 1px solid var(--border); }
.search input:focus { background: #fff; }
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: #fff; border-radius: var(--radius);
  box-shadow: var(--shadow-lg); max-height: 420px; overflow-y: auto; padding: 6px 0; z-index: 50;
}
.search-results .sr-group { padding: 6px 14px 2px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.search-results a { display: block; padding: 8px 14px; color: var(--text); }
.search-results a:hover, .search-results a.focus { background: var(--surface-2); text-decoration: none; }
.search-results a small { display: block; }
.content { padding: 24px; flex: 1; min-width: 0; }

/* ---------- Элементы ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 16px; border-radius: 8px;
  border: 1px solid var(--border); background: #fff; color: var(--text); font: inherit; font-weight: 500; cursor: pointer;
  white-space: nowrap; text-decoration: none !important; min-height: 36px;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-h); }
.btn-danger { color: var(--danger); border-color: #f2c4c1; }
.btn-danger:hover { background: var(--danger-bg); }
.btn-sm { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btn-block { width: 100%; }
.btn svg { width: 16px; height: 16px; }
.icon-btn { background: none; border: 0; padding: 8px; border-radius: 8px; cursor: pointer; color: var(--muted); display: inline-flex; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.link-btn { background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; font: inherit; }
.link-btn.danger { color: var(--danger); }

input, select, textarea {
  font: inherit; color: inherit; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; background: #fff;
  min-height: 36px; width: 100%; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(21,146,230,.15); }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; }
input[type=color] { padding: 2px; width: 44px; height: 36px; }
textarea { resize: vertical; min-height: 80px; }

.avatar {
  width: 36px; height: 36px; border-radius: 50%; background: #5b7fa6; color: #fff; border: 0; cursor: pointer;
  font-weight: 600; font-size: 13px; display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.avatar.sm { width: 26px; height: 26px; font-size: 11px; cursor: default; }

.dropdown { position: relative; }
.dropdown-menu {
  display: none; position: absolute; top: calc(100% + 6px); left: 0; min-width: 180px; background: #fff; border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 6px 0; z-index: 60;
}
.dropdown-menu.right { left: auto; right: 0; }
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu a, .dropdown-menu button { display: block; width: 100%; text-align: left; padding: 9px 16px; color: var(--text); background: none; border: 0; font: inherit; cursor: pointer; }
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--surface-2); text-decoration: none; }
.dropdown-head { padding: 8px 16px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.dropdown-head small { display: block; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.flash-ok { background: var(--ok-bg); color: #166b3c; }
.flash-error { background: var(--danger-bg); color: #9b2018; }
.flash-warn { background: var(--warn-bg); color: #8a5a00; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 500; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge-stage { color: #fff; }
.badge-unpaid { background: var(--danger-bg); color: #b4261d; }
.badge-partial { background: var(--warn-bg); color: #8a5a00; }
.badge-paid { background: var(--ok-bg); color: #166b3c; }
.badge-postpay { background: #e8f1fd; color: #1d5fae; }
.badge-overdue { background: var(--danger); color: #fff; }
.badge-off { background: #e5e7eb; color: #6b7280; }

.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin-right: auto; }
.page-head .sub { flex-basis: 100%; color: var(--muted); margin-top: -8px; }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
.grid > * { min-width: 0; }
.grid > .card + .card, .form > .card + .card { margin-top: 0; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: 2fr 1fr; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.form { display: grid; gap: 14px; }
.form.narrow { max-width: 460px; }
.form label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 500; }
.form label > input, .form label > select, .form label > textarea { color: var(--text); font-weight: 400; }
.form .row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.form fieldset { border: 0; padding: 0; margin: 6px 0 0; display: grid; gap: 14px; }
.form legend { font-weight: 600; font-size: 15px; margin-bottom: 10px; color: var(--text); }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.check { display: flex !important; align-items: center; gap: 8px !important; color: var(--text) !important; }
.req::after { content: " *"; color: var(--danger); }

.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; align-items: center; }
.filters input, .filters select { width: auto; min-width: 150px; }
.filters input[type=checkbox] { min-width: 0; }
.filters .grow { flex: 1; min-width: 200px; }

.table-wrap { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); white-space: nowrap; }
.table th a { color: inherit; }
.table tbody tr:hover { background: #f8fafc; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table tr.overdue td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
.table tr.clickable { cursor: pointer; }
.table td.nowrap { white-space: nowrap; }
.table-foot { padding: 12px 14px; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; color: var(--muted); }
.pager { display: flex; gap: 6px; }

.overdue-text { color: var(--danger); font-weight: 600; }

.empty-state { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty-state.big { padding: 80px 20px; }
.empty-code { font-size: 64px; font-weight: 700; color: #c3ccd6; }

dl.props { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 0; }
dl.props dt { color: var(--muted); }
dl.props dd { margin: 0; word-break: break-word; }

/* ---------- Сводка ---------- */
.stat { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; display: block; color: inherit; }
a.stat:hover { text-decoration: none; box-shadow: 0 0 0 2px var(--primary); }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-value.danger { color: var(--danger); }
.stat-note { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stage-bars { display: grid; gap: 10px; }
.stage-bar { display: grid; grid-template-columns: 160px 1fr 40px; gap: 12px; align-items: center; color: inherit; }
.stage-bar:hover { text-decoration: none; }
.stage-bar:hover .stage-bar-name { color: var(--primary); }
.stage-bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stage-bar-track { background: var(--surface-2); border-radius: 4px; height: 14px; overflow: hidden; }
.stage-bar-fill { height: 100%; border-radius: 4px; min-width: 2px; }
.stage-bar-count { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.month-chart { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 2px; height: 180px; align-items: stretch; margin-bottom: 8px; border-bottom: 1px solid var(--border); }
.month-col { position: relative; display: flex; flex-direction: column; outline: none; cursor: default; }
.month-bar-wrap { flex: 1; display: flex; align-items: flex-end; justify-content: center; padding: 0 3px; }
.month-bar { width: 100%; max-width: 32px; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 2px; transition: background .15s; }
.month-col:hover .month-bar, .month-col:focus .month-bar { background: var(--primary-h); }
.month-label { text-align: center; font-size: 11px; color: var(--muted); padding: 4px 0 2px; white-space: nowrap; overflow: hidden; }
.month-tip { display: none; position: absolute; bottom: calc(100% - 20px); left: 50%; transform: translateX(-50%); background: var(--sidebar); color: #fff; padding: 6px 10px; border-radius: 6px; font-size: 12px; white-space: nowrap; z-index: 5; pointer-events: none; }
.month-tip small { color: #c7d0db; }
.month-col:hover .month-tip, .month-col:focus .month-tip { display: block; }
.month-col:first-child .month-tip { left: 0; transform: none; }
.month-col:last-child .month-tip { left: auto; right: 0; transform: none; }
.period { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.period input { width: auto; }

/* ---------- Канбан ---------- */
.board-wrap { margin: -24px; padding: 16px 24px 24px; height: calc(100vh - var(--topbar-h)); display: flex; flex-direction: column; }
.board-wrap .filters { margin-bottom: 12px; }
.board { display: flex; gap: 12px; overflow-x: auto; flex: 1; align-items: stretch; padding-bottom: 8px; scroll-snap-type: x proximity; }
.column { flex: 0 0 280px; display: flex; flex-direction: column; background: #e3e8ee; border-radius: var(--radius); max-height: 100%; scroll-snap-align: start; }
.column-head { padding: 12px 12px 10px; border-top: 4px solid var(--c, #999); border-radius: var(--radius) var(--radius) 0 0; background: var(--surface); }
.column-title { display: flex; align-items: center; justify-content: space-between; font-weight: 600; gap: 8px; }
.column-count { background: var(--surface-2); color: var(--muted); border-radius: 10px; padding: 0 8px; font-size: 12px; }
.column-sum { font-size: 12px; color: var(--muted); margin-top: 2px; min-height: 17px; }
.column-body { padding: 8px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; flex: 1; min-height: 80px; }
.kcard {
  background: var(--surface); border-radius: 8px; padding: 10px 12px; box-shadow: var(--shadow); cursor: grab;
  border-left: 3px solid transparent; user-select: none; -webkit-user-select: none;
}
.kcard:hover { box-shadow: 0 0 0 1px var(--primary), var(--shadow); }
.kcard.overdue { border-left-color: var(--danger); background: #fff8f7; }
.kcard-top { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }
.kcard-num { font-weight: 600; color: var(--primary); }
.kcard-title { font-weight: 600; margin: 4px 0 2px; word-break: break-word; }
.kcard-client { color: var(--muted); font-size: 13px; }
.kcard-foot { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: 8px; font-size: 12px; flex-wrap: wrap; }
.kcard-due { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); }
.kcard-due svg { width: 14px; height: 14px; }
.kcard.overdue .kcard-due { color: var(--danger); font-weight: 600; }
.kcard-sum { font-weight: 600; font-variant-numeric: tabular-nums; }
.kcard.flash-update { animation: flashUpd 1.2s ease; }
@keyframes flashUpd { from { box-shadow: 0 0 0 3px var(--sidebar-active); } to { box-shadow: var(--shadow); } }
.sortable-ghost { opacity: .35; }
/* Плашки этапов сверху (телефон) — появляются при перетаскивании карточки */
.stage-drop {
  position: fixed; left: 0; right: 0; top: var(--topbar-h); z-index: 45; display: none; grid-template-columns: 1fr 1fr; gap: 6px;
  padding: 8px 10px; background: rgba(255, 255, 255, .95); box-shadow: 0 6px 24px rgba(20, 30, 45, .15);
}
.stage-drop.show { display: grid; }
.stage-chip {
  position: relative; display: flex; align-items: center; justify-content: space-between; gap: 6px; min-height: 44px; padding: 6px 10px;
  border-radius: 8px; background: var(--surface-2); border: 2px dashed var(--border); border-left: 5px solid var(--c, #999);
  font-weight: 600; font-size: 13px; overflow: hidden;
}
.stage-chip span { pointer-events: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stage-chip small { pointer-events: none; color: var(--muted); }
.stage-chip .kcard { position: absolute; inset: 0; opacity: 0; }
.stage-chip:has(.kcard) { border-style: solid; border-color: var(--c, var(--primary)); background: #fff; transform: scale(1.03); }
html.board-dragging, html.board-dragging body { overflow: hidden; overscroll-behavior: none; }
html.board-dragging .board { touch-action: none; scroll-snap-type: none; }

/* Зоны итога внизу доски — появляются при перетаскивании карточки */
.outcome-bar {
  position: fixed; left: var(--sidebar-w); right: 0; bottom: 0; z-index: 45; display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 12px; padding: 12px 24px calc(12px + env(safe-area-inset-bottom)); background: rgba(255, 255, 255, .92);
  box-shadow: 0 -6px 24px rgba(20, 30, 45, .15); transform: translateY(110%); transition: transform .18s ease; pointer-events: none;
}
.outcome-bar.show { transform: none; pointer-events: auto; }
.outcome-zone {
  position: relative; height: 84px; border-radius: 12px; display: flex; align-items: center; justify-content: center; overflow: hidden;
  border: 2px dashed currentColor; font-weight: 700; font-size: 15px; transition: transform .12s, box-shadow .12s;
}
.outcome-zone > span { pointer-events: none; }
.outcome-zone .kcard { position: absolute; inset: 0; opacity: 0; }
.outcome-zone:has(.kcard) { transform: scale(1.04); border-style: solid; box-shadow: 0 0 0 4px rgba(0, 0, 0, .06); }
.zone-failed { color: #c62828; background: #fdecea; }
.zone-analysis { color: #ad1457; background: #fce4ec; }
.zone-success { color: #1b7a43; background: #e7f7ee; }
.stat-success { box-shadow: inset 4px 0 0 #22a35a, var(--shadow); }
.stat-analysis { box-shadow: inset 4px 0 0 #e91e63, var(--shadow); }
.stat-failed { box-shadow: inset 4px 0 0 #e2453c, var(--shadow); }
.stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.outcome-banner { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; padding: 8px 12px; border-radius: 8px; }
.outcome-banner span { color: var(--muted); font-size: 13px; margin-right: auto; }
.outcome-failed { background: #fdecea; color: #c62828; }
.outcome-analysis { background: #fce4ec; color: #ad1457; }
.outcome-success { background: #e7f7ee; color: #1b7a43; }
.badge.outcome-failed, .badge.outcome-analysis, .badge.outcome-success { font-weight: 600; }
.sortable-chosen { cursor: grabbing; }
.sortable-drag { transform: rotate(2deg); box-shadow: var(--shadow-lg) !important; }
.sortable-fallback { opacity: .95 !important; transform: rotate(2deg); box-shadow: var(--shadow-lg) !important; pointer-events: none; z-index: 1000 !important; }

/* ---------- Выезжающая карточка ---------- */
.drawer { position: fixed; inset: 0; z-index: 80; pointer-events: none; visibility: hidden; transition: visibility 0s .25s; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 35, .45); opacity: 0; transition: opacity .2s; }
.drawer-panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(920px, 92vw); background: var(--bg);
  transform: translateX(100%); transition: transform .25s ease; display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
}
.drawer.open { pointer-events: auto; visibility: visible; transition: visibility 0s; }
.drawer.open .drawer-backdrop { opacity: 1; }
.drawer.open .drawer-panel { transform: none; }
.drawer-close { position: absolute; left: -46px; top: 12px; background: var(--sidebar); color: #fff; border-radius: 50% 0 0 50%; padding: 10px; }
.drawer-close:hover { background: var(--sidebar-2); color: #fff; }
.drawer-body { overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.drawer-loading { padding: 40px; text-align: center; color: var(--muted); }
body.no-scroll { overflow: hidden; }

.order-head { background: var(--surface); padding: 18px 24px; border-bottom: 1px solid var(--border); }
.order-head-top { display: flex; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.order-head h1 { font-size: 20px; flex: 1; min-width: 200px; }
.order-head .meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; align-items: center; }
.stage-path { display: flex; gap: 2px; margin-top: 14px; overflow-x: auto; padding-bottom: 2px; }
.stage-step {
  flex: 1 0 auto; min-width: 90px; padding: 7px 10px 7px 16px; font-size: 12px; background: #e6eaef; color: var(--muted); border: 0; cursor: pointer;
  clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 50%, calc(100% - 8px) 100%, 0 100%, 8px 50%); white-space: nowrap; font: inherit; font-size: 12px;
}
.stage-step:first-child { clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 50%, calc(100% - 8px) 100%, 0 100%); border-radius: 6px 0 0 6px; padding-left: 10px; }
.stage-step.done, .stage-step.current { background: var(--c); color: #fff; }
.stage-step.done { opacity: .55; }
.stage-step.current { font-weight: 600; }
.stage-step:disabled { cursor: default; }
.stage-step:not(:disabled):hover { filter: brightness(.95); }

.order-body > * { min-width: 0; }
.order-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; padding: 16px 24px 24px; align-items: start; }
.order-page .order-body { padding: 16px 0 0; }
.order-page .order-head { border-radius: var(--radius); box-shadow: var(--shadow); border: 0; }
.items-table td, .items-table th { padding: 8px 10px; }
.items-cost { display: block; width: 100%; text-align: right; padding: 10px 10px 0; font-size: 14px; color: var(--muted); }
.items-cost + .items-total { padding-top: 4px; }
.items-total { text-align: right; font-weight: 700; padding: 10px; font-size: 15px; }
.files { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.files li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--surface-2); border-radius: 8px; }
.files li a.name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Лента событий */
.feed-form { display: grid; gap: 8px; margin-bottom: 16px; }
.feed-form textarea { min-height: 64px; }
.feed { list-style: none; margin: 0; padding: 0; position: relative; }
.feed::before { content: ""; position: absolute; left: 13px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.feed li { position: relative; padding: 0 0 16px 40px; }
.feed .dot { position: absolute; left: 4px; top: 2px; width: 20px; height: 20px; border-radius: 50%; background: #fff; border: 2px solid var(--border); display: flex; align-items: center; justify-content: center; font-size: 10px; }
.feed .ev-stage .dot { border-color: var(--primary); background: var(--primary); }
.feed .ev-comment .dot { border-color: var(--warn); background: #fff; }
.feed .ev-created .dot { border-color: var(--success); background: var(--success); }
.feed .ev-file .dot { border-color: #8b5cf6; }
.feed .ev-outcome .dot { border-color: #e91e63; background: #fce4ec; }
.feed .ev-head { font-size: 12px; color: var(--muted); }
.feed .ev-head b { color: var(--text); font-weight: 600; }
.feed .ev-text { margin-top: 3px; white-space: pre-wrap; word-break: break-word; }
.feed .ev-comment .ev-text { background: #fff; border: 1px solid var(--border); padding: 8px 12px; border-radius: 0 10px 10px 10px; display: inline-block; max-width: 100%; }
.feed .arrow { color: var(--muted); margin: 0 4px; }

/* Кнопки выгрузки и таблицы отчётов */
.btn-export svg { width: 18px; height: 18px; }
.btn-xlsx svg { color: #1d7044; }
.btn-pdf svg { color: #c62828; }
.table-scroll { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
.report-table { width: 100%; }
.report-table th, .report-table td { padding: 9px 10px; }
.report-table td { word-break: break-word; }
.report-table .num { white-space: nowrap; }

/* Диск */
.disk-privacy { display: flex; align-items: center; gap: 6px; }
.disk-privacy svg { width: 15px; height: 15px; color: var(--success); }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 14px; color: var(--muted); }
.modal-head .crumbs { margin: 4px 0 0; font-size: 13px; }
.disk-drop {
  display: none; position: fixed; inset: 12px; z-index: 70; border: 3px dashed var(--primary); border-radius: 16px;
  background: rgba(21, 146, 230, .08); align-items: center; justify-content: center; font-size: 18px; font-weight: 600; color: var(--primary);
  pointer-events: none;
}
.disk-drop.show { display: flex; }
.disk-table td { vertical-align: middle; }
.disk-name { display: inline-flex; align-items: center; gap: 10px; color: var(--text); min-width: 0; max-width: 100%; }
.disk-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.disk-name:hover span { color: var(--primary); text-decoration: underline; }
.folder-ico { width: 24px; height: 24px; color: #f5b83d; }
.ficon { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 24px; border-radius: 4px;
  font-size: 9.5px; font-weight: 800; color: #fff; letter-spacing: .02em; }
.ficon-pdf { background: #d93025; }
.ficon-doc { background: #2b579a; }
.ficon-xls { background: #1d7044; }
.ficon-img { background: #7b5cd6; }
.disk-actions { white-space: nowrap; text-align: right; width: 1%; }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-bg); }
.disk-usage { margin-top: 14px; max-width: 420px; }
.disk-usage-bar { height: 6px; border-radius: 3px; background: #dfe4ea; overflow: hidden; margin-bottom: 4px; }
.disk-usage-bar span { display: block; height: 100%; background: var(--primary); border-radius: 3px; }
.disk-pick { margin-top: 8px; }
.modal.modal-small .modal-panel { width: min(640px, 100%); }
.picker-list { list-style: none; margin: 0; padding: 0; }
.picker-list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--border); }
.picker-list li small { color: var(--muted); white-space: nowrap; }
.picker-list label { cursor: pointer; }
.picker-list input[type=checkbox] { width: 18px; height: 18px; flex: none; }
.move-form .form { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }

/* Переключатель вида и вкладки */
.view-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: #fff; }
.view-toggle a { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; color: var(--muted); font-weight: 500; }
.view-toggle a + a { border-left: 1px solid var(--border); }
.view-toggle a:hover { background: var(--surface-2); text-decoration: none; }
.view-toggle a.active { background: var(--primary); color: #fff; }
.view-toggle svg { width: 16px; height: 16px; }
.tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab { padding: 9px 14px; color: var(--muted); font-weight: 500; white-space: nowrap; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--text); border-bottom-color: var(--primary); }
.tab-success.active { border-bottom-color: #22a35a; }
.tab-analysis.active { border-bottom-color: #e91e63; }
.tab-failed.active { border-bottom-color: #e2453c; }
.tab-count { display: inline-block; min-width: 22px; padding: 0 6px; border-radius: 10px; background: var(--surface-2); font-size: 12px; text-align: center; }

/* Карточки в списках */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.ecard { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ecard[data-open-order] { cursor: pointer; }
.ecard:hover { box-shadow: 0 0 0 1px var(--primary), var(--shadow); }
.ecard.overdue { box-shadow: inset 4px 0 0 var(--danger), var(--shadow); }
.ecard.inactive { opacity: .65; }
.ecard-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.ecard-num { font-weight: 700; }
.ecard-title { font-weight: 700; font-size: 16px; color: var(--text); word-break: break-word; }
a.ecard-title:hover { color: var(--primary); }
.ecard-sub { color: var(--muted); }
.ecard-props { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 6px 0 0; font-size: 13px; }
.ecard-props dt { color: var(--muted); }
.ecard-props dd { margin: 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ecard-stats { display: flex; gap: 12px; flex-wrap: wrap; margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border); font-size: 13px; color: var(--muted); }
.ecard-stats b { color: var(--text); }
.role-badge { background: #e8f1fd; color: #1d5fae; }

/* Модальное окно */
.modal { position: fixed; inset: 0; z-index: 90; display: none; align-items: center; justify-content: center; padding: 24px; }
.modal.open { display: flex; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 35, .55); }
.modal-panel {
  position: relative; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); width: min(1440px, 100%);
  max-height: calc(100vh - 48px); display: flex; flex-direction: column; animation: modalIn .18s ease;
}
@keyframes modalIn { from { transform: translateY(12px); opacity: 0; } }
.route-form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 18px 22px 12px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 2px 0 4px; font-size: 19px; }
.modal-body { padding: 14px 22px; overflow: auto; flex: 1; min-height: 0; }
.modal-foot { display: flex; gap: 10px; align-items: center; justify-content: flex-end; padding: 12px 22px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 14px 14px; }
.modal-foot .route-legend { margin-right: auto; font-size: 12px; display: flex; align-items: center; gap: 6px; }
.dot-done, .dot-late { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--ok-bg); border: 1px solid #9fd8b5; }
.dot-late { background: var(--danger-bg); border-color: #f2b1ac; margin-left: 8px; }

/* Маршрутный лист */
.route-scroll { overflow-x: auto; }
.route-table { width: 100%; border-collapse: collapse; min-width: 1170px; table-layout: fixed; }
.route-table th { font-size: 12px; color: var(--muted); font-weight: 500; text-align: left; padding: 6px 5px; line-height: 1.25; vertical-align: bottom; border-bottom: 1px solid var(--border); }
.route-table td { padding: 5px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.route-table input, .route-table select { min-height: 34px; padding: 6px 8px; min-width: 0; max-width: 100%; box-sizing: border-box; }
.route-table input[type=date] { padding: 6px 2px 6px 6px; font-size: 13px; font-variant-numeric: tabular-nums; }
.route-table input:disabled, .route-table select:disabled { background: var(--surface-2); color: var(--text); opacity: 1; }
.route-table .c-n { width: 34px; text-align: center; color: var(--muted); }
.route-table .c-name { width: auto; }
.route-table .c-qty { width: 78px; }
.route-table .c-exec { width: 172px; }
.route-table .c-date { width: 152px; }
.route-table .c-price { width: 104px; }
.route-table .c-sum { width: 112px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.route-table .c-x { width: 40px; }
.route-table tr.op-done td { background: #f1faf4; }
.route-table tr.op-late td { background: #fff5f4; }
.route-table input.late, .route-table tr.op-late [data-f="plan_end_date"] { border-color: var(--danger); color: var(--danger); }
.route-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.route-total { margin-left: auto; font-size: 15px; }
.route-total small { color: var(--muted); }
.item-link { text-align: left; font-weight: 600; text-decoration: underline dotted; text-underline-offset: 3px; }

/* Поиск в разделах */
.live-search { position: relative; flex: 1; min-width: 200px; display: flex; }
.live-search input { width: 100%; }

/* Позиции заказа в форме */
.items-editor { width: 100%; border-collapse: collapse; }
.items-editor th { font-size: 12px; color: var(--muted); text-align: left; padding: 4px 6px; font-weight: 500; }
.items-editor td { padding: 4px 6px; vertical-align: top; }
.items-editor td.sum { white-space: nowrap; text-align: right; padding-top: 12px; font-variant-numeric: tabular-nums; }
.items-editor .w-qty { width: 100px; }
.items-editor .w-unit { width: 80px; }
.items-editor .w-price { width: 130px; }

/* Контакты клиента */
.contact-row { display: grid; grid-template-columns: 1.3fr 1fr 1fr 1fr auto; gap: 8px; align-items: center; }
.contacts-list { display: grid; gap: 10px; }
.contact { padding: 10px 12px; background: var(--surface-2); border-radius: 8px; }
.contact b { display: block; }

/* Уведомления */
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 100; max-width: calc(100vw - 32px); }
.toast { background: var(--sidebar); color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow-lg); animation: toastIn .2s ease; max-width: 380px; }
.toast.error { background: var(--danger); }
@keyframes toastIn { from { transform: translateY(10px); opacity: 0; } }

/* Пользователи / этапы */
.stage-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.stage-item { display: grid; grid-template-columns: 24px 50px 1fr auto auto auto; gap: 10px; align-items: center; background: var(--surface); padding: 10px 12px; border-radius: 8px; box-shadow: var(--shadow); }
.stage-item .handle { cursor: grab; color: var(--muted); text-align: center; font-size: 18px; }
.stage-item .cnt { color: var(--muted); font-size: 12px; white-space: nowrap; }
.stage-item .form-actions { flex-wrap: nowrap; }
.stage-item .form-actions form { display: inline-flex; margin: 0; }
.optype-item { grid-template-columns: 24px minmax(0, 1fr) auto auto auto; }
.optype-item form[id^="optype-"] { min-width: 0; }
.optype-item input[name=name] { width: 100%; min-width: 260px; font-weight: 500; }
.optype-item.inactive input[name=name] { color: var(--muted); text-decoration: line-through; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.settings-tile { display: flex; gap: 14px; align-items: flex-start; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; color: var(--text); }
.settings-tile:hover { text-decoration: none; box-shadow: 0 0 0 2px var(--primary); }
.settings-tile svg { width: 26px; height: 26px; color: var(--primary); margin-top: 2px; }
.settings-tile b { display: block; font-size: 15px; margin-bottom: 4px; }
.settings-tile small { color: var(--muted); }
.route-hint { margin-bottom: 10px; }

/* ---------- Вход ---------- */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, var(--sidebar) 0%, #2c4a6b 100%); padding: 16px; }
.auth-card { background: #fff; padding: 32px; border-radius: 14px; width: 100%; max-width: 380px; display: grid; gap: 16px; box-shadow: var(--shadow-lg); }
.auth-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.auth-brand { font-weight: 700; font-size: 18px; color: var(--sidebar); }
.auth-brand .brand-mark { color: var(--primary); }

/* ---------- Мобильная версия ---------- */
@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: 1fr; }
  .order-body { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); }
  body.sidebar-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(15,23,35,.45); z-index: 35; }
  .main { margin-left: 0; }
  .topbar .burger { display: inline-flex; }
  .topbar { padding: 0 10px; gap: 8px; }
  .topbar .btn-primary span { display: none; }
  .view-toggle span { display: none; }
  .hide-sm { display: none; }
  .disk-table td, .disk-table th { padding: 10px 8px; }
  .modal.modal-small .modal-panel { height: auto; max-height: 100%; margin-top: auto; border-radius: 14px 14px 0 0; }
  .cards-grid { grid-template-columns: 1fr; }
  .topbar .btn-primary { padding: 8px 10px; }
  .content { padding: 16px; }
  .board-wrap { margin: -16px; padding: 12px 16px 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  .drawer-panel { width: 100vw; }
  .drawer-close { left: auto; right: 8px; top: 8px; border-radius: 50%; z-index: 2; }
  .order-head { padding: 16px 56px 16px 16px; }
  .order-page .order-head { padding: 16px; }
  .order-body { padding: 12px; }
  .stage-bar { grid-template-columns: 110px 1fr 32px; }
  .contact-row { grid-template-columns: 1fr 1fr; }
  .filters input:not([type=checkbox]), .filters select { flex: 1 1 140px; min-width: 0; }
  .column { flex-basis: 85vw; }
  .outcome-bar { left: 0; gap: 8px; padding-left: 10px; padding-right: 10px; }
  .outcome-zone { height: 72px; font-size: 13px; text-align: center; padding: 0 4px; }
  .table.responsive thead { display: none; }
  .table.responsive tr { display: block; padding: 10px 12px; border-bottom: 1px solid var(--border); }
  .table.responsive tr.overdue { box-shadow: inset 3px 0 0 var(--danger); }
  .table.responsive td { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; border: 0; text-align: right; }
  .table.responsive td::before { content: attr(data-label); color: var(--muted); text-align: left; font-size: 12px; flex: none; max-width: 45%; }
  .table.responsive td.num { text-align: right; }
  .table.responsive tr.overdue td:first-child { box-shadow: none; }
  .stage-item { grid-template-columns: 20px 44px 1fr auto; }
  .stage-item .cnt { grid-column: 3 / -1; }
  .stage-item:not(.optype-item) {
    grid-template-columns: 20px 44px 1fr auto;
    grid-template-areas: "h color name name" ". . fin cnt" "act act act act";
  }
  .stage-item:not(.optype-item) > .handle { grid-area: h; }
  .stage-item:not(.optype-item) > form:first-of-type { grid-area: color; }
  .stage-item:not(.optype-item) > input[name=name] { grid-area: name; min-width: 0; }
  .stage-item:not(.optype-item) > .check { grid-area: fin; }
  .stage-item:not(.optype-item) > .cnt { grid-area: cnt; text-align: right; }
  .stage-item:not(.optype-item) > .form-actions { grid-area: act; justify-content: flex-end; }
  .optype-item { grid-template-columns: 20px 1fr auto; grid-template-areas: "h name name" ". act cnt" ". btn btn"; }
  .optype-item .handle { grid-area: h; }
  .optype-item form[id^="optype-"] { grid-area: name; }
  .optype-item input[name=name] { min-width: 0; }
  .optype-item .check { grid-area: act; }
  .optype-item .cnt { grid-area: cnt; text-align: right; }
  .optype-item .form-actions { grid-area: btn; justify-content: flex-end; }
  .modal { padding: 0; }
  .modal-panel { width: 100%; height: 100%; max-height: none; border-radius: 0; }
  .modal-head, .modal-body, .modal-foot { padding-left: 14px; padding-right: 14px; }
  .modal-foot { border-radius: 0; }
  .modal-foot .route-legend { display: none; }
  /* Маршрутный лист на телефоне: каждая операция — карточка с подписанными полями */
  .route-table { min-width: 0; }
  .route-table thead { display: none; }
  .route-table, .route-table tbody { display: block; }
  .route-table tr[data-op] {
    display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; position: relative;
    border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px;
  }
  .route-table tr.op-done { border-color: #9fd8b5; }
  .route-table tr.op-late { border-color: #f2b1ac; }
  .route-table td { display: grid; gap: 3px; padding: 0; border: 0; width: auto !important; min-width: 0 !important; background: none !important; }
  .route-table td::before { content: attr(data-label); font-size: 11px; color: var(--muted); }
  .route-table td.c-n { grid-column: 1 / -1; display: block; text-align: left; font-weight: 600; color: var(--text); }
  .route-table td.c-n::before { content: "Операция "; font-size: 13px; color: var(--text); }
  .route-table td.c-name, .route-table td.c-exec { grid-column: 1 / -1; }
  .route-table td.c-sum { align-content: end; text-align: left; padding-bottom: 8px; font-weight: 600; }
  .route-table td.c-x { position: absolute; top: 4px; right: 4px; }
  .route-table td.c-x::before { content: none; }
  .route-table input[type=date] { min-width: 0; }
  .route-total { margin-left: 0; }
}
@media (max-width: 520px) {
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 20px; }
  .page-head h1 { font-size: 19px; }
  dl.props { grid-template-columns: 1fr; gap: 2px; }
  dl.props dd { margin-bottom: 8px; }
}
