/* ==========================================================================
   CRM «Механизатор ВЛ» — дизайн-система. Без внешних зависимостей.
   ========================================================================== */
:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --bg: #F3F5F8;
  --surface: #FFFFFF;
  --surface-2: #F8FAFC;
  --border: #E3E8EF;
  --border-strong: #CBD5E1;
  --text: #0F172A;
  --text-2: #475569;
  --text-3: #94A3B8;
  --primary: #1F4E79;
  --primary-600: #1A4369;
  --primary-50: #EAF1F8;
  --primary-100: #D6E3F0;
  --accent: #F08A24;
  --accent-50: #FFF4E8;
  --success: #1F9D63;
  --success-50: #E8F7F0;
  --warning: #D9A21B;
  --warning-50: #FFF8E6;
  --danger: #D64545;
  --danger-50: #FDECEC;
  --info: #2B7DBF;
  --info-50: #E9F3FB;
  --radius: 10px;
  --radius-sm: 7px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 1px rgba(15, 23, 42, .04);
  --shadow: 0 4px 14px rgba(15, 23, 42, .08);
  --shadow-lg: 0 18px 40px rgba(15, 23, 42, .16);
  --sidebar-w: 248px;
  --topbar-h: 60px;
  --tap: 44px;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 14.5px; line-height: 1.45; color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.45rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; } h4 { font-size: .92rem; }
p { margin: 0 0 .75rem; }
small, .muted { color: var(--text-2); }
.text-3 { color: var(--text-3); }
.small { font-size: .85rem; }
.xs { font-size: .78rem; }
.mono { font-family: var(--mono); font-size: .9em; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.num { font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }
.flex { display: flex; gap: .5rem; align-items: center; }
.flex-wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }
.stack > * + * { margin-top: .75rem; }
.gap-1 { gap: .25rem; } .gap-2 { gap: .5rem; } .gap-3 { gap: .75rem; } .gap-4 { gap: 1rem; }
.mt-1 { margin-top: .25rem; } .mt-2 { margin-top: .5rem; } .mt-3 { margin-top: .75rem; } .mt-4 { margin-top: 1rem; } .mt-6 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: .5rem; } .mb-3 { margin-bottom: .75rem; } .mb-4 { margin-bottom: 1rem; }
.w-100 { width: 100%; }
.icon { width: 18px; height: 18px; flex: 0 0 auto; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }
.icon.sm { width: 15px; height: 15px; }
.icon.lg { width: 24px; height: 24px; }

/* ---------- Каркас ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w); background: #10243A; color: #CBD5E1; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: .65rem; padding: 1.1rem 1.1rem .9rem; color: #fff; }
.brand-mark { width: 36px; height: 36px; border-radius: 9px; background: linear-gradient(135deg, var(--accent), #F6B46A); display: grid; place-items: center; color: #10243A; font-weight: 800; }
.brand-name { font-weight: 700; font-size: 1rem; line-height: 1.15; }
.brand-sub { font-size: .72rem; color: #94A3B8; }
.nav { padding: .25rem .6rem; display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: .7rem; padding: .6rem .7rem; border-radius: 8px; color: #CBD5E1; font-weight: 500;
}
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav a.active { background: rgba(240,138,36,.16); color: #fff; }
.nav a.active .icon { color: var(--accent); }
.nav .count { margin-left: auto; background: rgba(255,255,255,.12); color: #fff; font-size: .72rem; padding: 1px 7px; border-radius: 999px; font-weight: 600; }
.nav .count.alert { background: var(--danger); }
.nav-section { padding: .9rem .9rem .3rem; font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: #64748B; }
.sidebar-user { margin-top: auto; padding: .9rem; border-top: 1px solid rgba(255,255,255,.08); display: flex; align-items: center; gap: .6rem; }
.sidebar-user .name { color: #fff; font-weight: 600; font-size: .9rem; }
.sidebar-user .role { font-size: .75rem; color: #94A3B8; }
.sidebar-user form { margin-left: auto; }
.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h); display: flex; align-items: center; gap: .9rem; padding: 0 1.4rem; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30;
}
.topbar .title { font-weight: 650; font-size: 1.05rem; }
.topbar .search { flex: 1 1 320px; max-width: 460px; margin-left: auto; position: relative; }
.topbar .search input { padding-left: 2.2rem; height: 38px; }
.topbar .search .icon { position: absolute; left: .7rem; top: 10px; color: var(--text-3); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid transparent; background: transparent; display: inline-grid; place-items: center;
  color: var(--text-2); cursor: pointer; position: relative;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn .dot { position: absolute; top: 7px; right: 7px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px; background: var(--danger); color: #fff; font-size: .66rem; font-weight: 700; display: grid; place-items: center; }
.content { padding: 1.4rem; max-width: 1600px; width: 100%; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.1rem; flex-wrap: wrap; }
.page-head h1 { margin-bottom: .15rem; }
.page-head .sub { color: var(--text-2); }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.bottom-nav { display: none; }
.menu-btn { display: none; }

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem; height: 38px; padding: 0 .95rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  white-space: nowrap; transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-600); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #1a1a1a; }
.btn.accent:hover { background: #E07C14; }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.outline-danger { color: var(--danger); border-color: #F3B4B4; background: #fff; }
.btn.outline-danger:hover { background: var(--danger-50); }
.btn.sm { height: 31px; padding: 0 .65rem; font-size: .82rem; }
.btn.lg { height: 46px; padding: 0 1.3rem; font-size: 1rem; }
.btn.block { width: 100%; }
.btn .icon { width: 16px; height: 16px; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.btn-group .btn.active { background: var(--primary-50); color: var(--primary); border-color: var(--primary-100); position: relative; z-index: 1; }

/* ---------- Карточки, панели ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-body { padding: 1.1rem 1.2rem; }
.card-head { padding: .9rem 1.2rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.card.pad { padding: 1.1rem 1.2rem; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) { .grid-2, .grid-3, .grid-4, .grid-main { grid-template-columns: 1fr; } }
.stat { padding: .95rem 1.1rem; }
.stat .label { color: var(--text-2); font-size: .8rem; font-weight: 500; }
.stat .value { font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em; margin-top: .15rem; font-variant-numeric: tabular-nums; }
.stat .value.danger { color: var(--danger); }
.stat .value.success { color: var(--success); }
.empty { padding: 2rem 1rem; text-align: center; color: var(--text-2); }
.empty .icon { width: 36px; height: 36px; color: var(--text-3); margin-bottom: .5rem; }
.divider { height: 1px; background: var(--border); margin: 1rem 0; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: .35rem 1rem; font-size: .92rem; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; }
@media (max-width: 600px) { .kv { grid-template-columns: 1fr; gap: 0; } .kv dt { margin-top: .5rem; font-size: .78rem; } }

/* ---------- Бейджи ---------- */
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: 2px 9px; border-radius: 999px; font-size: .76rem; font-weight: 600; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }
.badge.primary { background: var(--primary-50); color: var(--primary); border-color: var(--primary-100); }
.badge.success { background: var(--success-50); color: var(--success); border-color: #BDE6D0; }
.badge.warning { background: var(--warning-50); color: #9A6D00; border-color: #F1DDA0; }
.badge.danger { background: var(--danger-50); color: var(--danger); border-color: #F3B4B4; }
.badge.info { background: var(--info-50); color: var(--info); border-color: #BBD8F0; }
.badge.accent { background: var(--accent-50); color: #B35D00; border-color: #F8CFA3; }
.badge.dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip { display: inline-flex; align-items: center; gap: .35rem; padding: 4px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: .82rem; color: var(--text-2); }
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: inline-grid; place-items: center; color: #fff; font-size: .72rem; font-weight: 700; flex: 0 0 auto; }
.avatar.lg { width: 42px; height: 42px; font-size: .9rem; }

/* ---------- Формы ---------- */
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
label { display: block; font-size: .82rem; font-weight: 600; color: var(--text-2); margin-bottom: .3rem; }
input:not([type]), input[type="text"], input[type="search"], input[type="password"], input[type="email"], input[type="tel"], input[type="number"], input[type="date"], input[type="time"], input[type="datetime-local"], input[type="url"], select, textarea {
  width: 100%; height: 40px; padding: 0 .75rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: #fff; color: var(--text);
  font: inherit; outline: none; transition: border-color .12s, box-shadow .12s;
}
textarea { height: auto; min-height: 90px; padding: .6rem .75rem; resize: vertical; line-height: 1.4; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31,78,121,.15); }
input[readonly], input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--text-2); }
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; accent-color: var(--primary); vertical-align: -4px; margin-right: .35rem; }
.field { margin-bottom: .9rem; }
.field .hint { font-size: .78rem; color: var(--text-3); margin-top: .3rem; }
.field.inline { display: flex; align-items: center; gap: .5rem; }
.field.inline label { margin: 0; }
.form-row { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.check { display: flex; align-items: center; gap: .4rem; font-weight: 500; color: var(--text); font-size: .9rem; cursor: pointer; }
.check input { margin: 0; }
.input-group { display: flex; }
.input-group > * { border-radius: 0; }
.input-group > *:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group > *:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.input-group .btn { margin-left: -1px; }
.form-actions { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-top: 1rem; }
.required::after { content: " *"; color: var(--danger); }
.error-text { color: var(--danger); font-size: .82rem; }

/* ---------- Таблицы ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: .6rem .75rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
.table tr:hover td { background: #FAFBFD; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table .row-link { color: inherit; display: block; }
.table.compact th, .table.compact td { padding: .4rem .55rem; }
.pagination { display: flex; gap: .4rem; align-items: center; justify-content: flex-end; padding: .75rem 0; color: var(--text-2); font-size: .85rem; }

/* ---------- Сообщения, тосты ---------- */
.flashes { display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1rem; }
.alert { padding: .7rem 1rem; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); display: flex; gap: .6rem; align-items: flex-start; font-size: .9rem; }
.alert.success { background: var(--success-50); border-color: #BDE6D0; color: #0F6B43; }
.alert.error, .alert.danger { background: var(--danger-50); border-color: #F3B4B4; color: #9B2C2C; }
.alert.warning { background: var(--warning-50); border-color: #F1DDA0; color: #7A5600; }
.alert.info { background: var(--info-50); border-color: #BBD8F0; color: #1F5D8F; }
.alert .close { margin-left: auto; background: none; border: 0; cursor: pointer; color: inherit; font-size: 1.1rem; line-height: 1; }
#toasts { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 200; max-width: 360px; }
.toast { background: #0F172A; color: #fff; padding: .7rem 1rem; border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); font-size: .9rem; animation: toast-in .2s ease-out; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Вкладки ---------- */
.tabs { display: flex; gap: .15rem; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; margin-bottom: 1rem; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { padding: .65rem .9rem; color: var(--text-2); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; font-size: .9rem; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }
.tabs .count { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 0 6px; font-size: .72rem; margin-left: .3rem; }

/* ---------- Модальные окна, выпадающие списки ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: none; align-items: center; justify-content: center; z-index: 100; padding: 1rem; }
.modal-backdrop.open { display: flex; }
.modal { background: var(--surface); border-radius: var(--radius-lg); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; box-shadow: var(--shadow-lg); animation: toast-in .15s ease-out; }
.modal.wide { max-width: 860px; }
.modal-head { padding: 1rem 1.2rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { margin: 0; }
.modal-body { padding: 1.1rem 1.2rem; }
.modal-foot { padding: .9rem 1.2rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: .6rem; flex-wrap: wrap; }
.dropdown { position: relative; display: inline-block; }
.dropdown-menu { position: absolute; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow); min-width: 200px; padding: .3rem; display: none; z-index: 40; }
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu a, .dropdown-menu button { display: flex; width: 100%; align-items: center; gap: .5rem; padding: .5rem .7rem; border-radius: 6px; color: var(--text); background: none; border: 0; font: inherit; text-align: left; cursor: pointer; }
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--surface-2); text-decoration: none; }
.dropdown-menu .danger { color: var(--danger); }

/* ---------- Канбан ---------- */
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(270px, 1fr); gap: .8rem; overflow-x: auto; padding-bottom: 1rem; align-items: start; min-height: 60vh; }
.kanban-col { background: #EDF1F6; border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 230px); min-height: 200px; }
.kanban-col.drag-over { outline: 2px dashed var(--primary); outline-offset: -4px; background: var(--primary-50); }
.kanban-head { padding: .75rem .85rem .5rem; display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .5rem; position: sticky; top: 0; }
.kanban-head .color { width: 9px; height: 9px; border-radius: 50%; }
.kanban-head .name { font-weight: 700; font-size: .9rem; }
.kanban-head .n { margin-left: auto; background: #fff; border-radius: 999px; padding: 0 8px; font-size: .75rem; font-weight: 700; color: var(--text-2); }
.kanban-head .role { font-size: .72rem; color: var(--text-3); width: 100%; }
.kanban-cards { padding: 0 .55rem .55rem; display: flex; flex-direction: column; gap: .5rem; overflow-y: auto; flex: 1; }
.kcard { background: #fff; border-radius: 9px; border: 1px solid var(--border); padding: .65rem .75rem; box-shadow: var(--shadow-sm); cursor: grab; display: block; color: inherit; position: relative; }
.kcard:hover { text-decoration: none; border-color: var(--border-strong); box-shadow: var(--shadow); }
.kcard.dragging { opacity: .5; }
.kcard .num { font-size: .74rem; color: var(--text-3); font-weight: 600; }
.kcard .client { font-weight: 650; margin-top: .1rem; }
.kcard .desc { color: var(--text-2); font-size: .84rem; margin-top: .2rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.kcard .foot { display: flex; align-items: center; justify-content: space-between; gap: .4rem; margin-top: .55rem; font-size: .76rem; color: var(--text-2); }
.kcard .due.overdue { color: var(--danger); font-weight: 600; }
.kcard .flag { position: absolute; top: .55rem; right: .6rem; color: var(--danger); }

/* ---------- Карточка заявки ---------- */
.lead-head { display: flex; gap: 1rem; align-items: flex-start; flex-wrap: wrap; }
.lead-head .num { font-size: .8rem; color: var(--text-3); font-weight: 600; letter-spacing: .02em; }
.stage-track { display: flex; gap: 4px; margin: .75rem 0 1rem; flex-wrap: wrap; }
.stage-track .step { flex: 1 1 110px; padding: .45rem .6rem; border-radius: 7px; background: var(--surface-2); border: 1px solid var(--border); font-size: .78rem; color: var(--text-2); display: flex; align-items: center; gap: .4rem; }
.stage-track .step.done { background: var(--success-50); border-color: #BDE6D0; color: #0F6B43; }
.stage-track .step.current { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.stage-track .step .i { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: .68rem; font-weight: 700; background: rgba(255,255,255,.7); color: var(--text-2); flex: 0 0 auto; }
.stage-track .step.current .i { background: rgba(255,255,255,.25); color: #fff; }
.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { display: flex; gap: .5rem; align-items: flex-start; padding: .3rem 0; font-size: .9rem; }
.checklist li .icon { color: var(--danger); margin-top: 2px; }
.checklist li.ok .icon { color: var(--success); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: .45rem 0 .45rem 1.4rem; border-left: 2px solid var(--border); margin-left: .4rem; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: .9rem; width: 10px; height: 10px; border-radius: 50%; background: var(--border-strong); }
.timeline .when { font-size: .76rem; color: var(--text-3); }
.timeline .what { font-size: .9rem; }
.comment { padding: .7rem .9rem; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); margin-bottom: .6rem; }
.comment.client { background: var(--info-50); border-color: #BBD8F0; }
.comment .meta { font-size: .76rem; color: var(--text-2); margin-bottom: .25rem; display: flex; gap: .5rem; flex-wrap: wrap; }
.task-row { display: flex; gap: .75rem; align-items: flex-start; padding: .65rem 0; border-bottom: 1px solid var(--border); }
.task-row:last-child { border-bottom: 0; }
.task-row .title { font-weight: 600; }
.task-row .meta { font-size: .8rem; color: var(--text-2); display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .15rem; }
.task-row .meta .overdue { color: var(--danger); font-weight: 600; }
.task-row.done .title { color: var(--text-3); text-decoration: line-through; }

/* ---------- Смета ---------- */
.est-section { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 1rem; background: #fff; overflow: hidden; }
.est-section-head { display: flex; align-items: center; gap: .6rem; padding: .6rem .9rem; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.est-section-head input.name { height: 34px; font-weight: 700; border-color: transparent; background: transparent; padding-left: .3rem; }
.est-section-head input.name:focus { border-color: var(--primary); background: #fff; }
.est-table { width: 100%; border-collapse: collapse; font-size: .88rem; table-layout: fixed; }
.est-table.readonly td { padding: .5rem .6rem; }
.est-table input.right { text-align: right; }
.est-table th { font-size: .72rem; text-transform: uppercase; color: var(--text-3); padding: .4rem .5rem; text-align: left; border-bottom: 1px solid var(--border); }
.est-table td { padding: .25rem .4rem; border-bottom: 1px solid #F1F4F8; vertical-align: middle; }
.est-table tr.group td { background: #FBFCFE; color: var(--text-2); font-weight: 600; font-size: .8rem; padding: .4rem .6rem; }
.est-table input, .est-table select { height: 34px; font-size: .88rem; padding: 0 .5rem; }
.est-table td.amount { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.est-table tr.by-fact td.amount { color: var(--text-3); font-weight: 500; }
.est-table .drag { cursor: grab; color: var(--text-3); width: 24px; }
.est-totals { display: grid; grid-template-columns: 1fr auto; gap: .3rem 1.5rem; max-width: 420px; margin-left: auto; font-size: .95rem; }
.est-totals .grand { font-size: 1.25rem; font-weight: 800; color: var(--primary); border-top: 2px solid var(--border); padding-top: .4rem; }
.est-totals .label { color: var(--text-2); }
.sticky-bar { position: sticky; bottom: 0; background: rgba(255,255,255,.95); backdrop-filter: blur(6px); border-top: 1px solid var(--border); padding: .7rem 1rem; display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; z-index: 20; margin: 1rem -1.4rem -1.4rem; }
.catalog-popup { position: absolute; z-index: 50; background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); max-height: 280px; overflow: auto; min-width: 320px; }
.catalog-popup button { display: block; width: 100%; text-align: left; padding: .5rem .7rem; border: 0; background: none; font: inherit; cursor: pointer; }
.catalog-popup button:hover { background: var(--primary-50); }
.catalog-popup .sec { font-size: .72rem; color: var(--text-3); text-transform: uppercase; padding: .4rem .7rem 0; }

/* ---------- Календарь ---------- */
.cal-month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cal-dow { background: var(--surface-2); padding: .4rem; font-size: .74rem; text-transform: uppercase; color: var(--text-2); text-align: center; font-weight: 600; }
.cal-cell { background: #fff; min-height: 108px; padding: .35rem; font-size: .8rem; }
.cal-cell.out { background: #FAFBFC; color: var(--text-3); }
.cal-cell.today .d { background: var(--primary); color: #fff; }
.cal-cell .d { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; font-weight: 600; margin-bottom: .2rem; }
.cal-ev { display: block; padding: 2px 6px; border-radius: 5px; margin-bottom: 2px; color: #fff; font-size: .74rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-ev:hover { text-decoration: none; filter: brightness(1.08); }
.cal-ev.draft { background: #94A3B8 !important; }
.cal-ev.paused { opacity: .7; }
.cal-ev.completed { background: #64748B !important; }
.cal-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .6rem; }
.cal-day { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); min-height: 200px; }
.cal-day .head { padding: .5rem .7rem; border-bottom: 1px solid var(--border); font-weight: 600; font-size: .85rem; display: flex; justify-content: space-between; }
.cal-day.today .head { background: var(--primary-50); color: var(--primary); }
.cal-day .body { padding: .5rem; display: flex; flex-direction: column; gap: .4rem; }
.ev-card { display: block; padding: .5rem .6rem; border-radius: 8px; border-left: 4px solid var(--primary); background: var(--surface-2); color: inherit; font-size: .82rem; }
.ev-card:hover { text-decoration: none; background: #EEF2F7; }
.ev-card .t { font-weight: 700; }
.legend { display: flex; gap: .8rem; flex-wrap: wrap; font-size: .8rem; color: var(--text-2); }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .3rem; background: var(--c, #999); vertical-align: -1px; }

/* ---------- Этапы объекта ---------- */
.wstage { display: flex; gap: .8rem; align-items: flex-start; padding: .8rem .9rem; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; margin-bottom: .55rem; }
.wstage .n { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: .85rem; background: var(--surface-2); color: var(--text-2); flex: 0 0 auto; }
.wstage.in_progress { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-50); }
.wstage.in_progress .n { background: var(--primary); color: #fff; }
.wstage.completed .n { background: var(--success); color: #fff; }
.wstage.paused .n { background: var(--warning); color: #fff; }
.wstage.cancelled, .wstage.skipped { opacity: .65; }
.wstage .name { font-weight: 650; }
.wstage .meta { font-size: .8rem; color: var(--text-2); margin-top: .15rem; }
.wstage .ctrl { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .55rem; }
.progress { height: 10px; background: var(--border); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--success), #4CC38A); border-radius: 999px; transition: width .4s ease; }

/* ---------- Медиа ---------- */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .7rem; }
.media-item { position: relative; border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); aspect-ratio: 1; }
.media-item img, .media-item video { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-item .ph { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-3); font-size: .78rem; text-align: center; padding: .5rem; }
.media-item .tag { position: absolute; left: 6px; top: 6px; }
.media-item .cap { position: absolute; left: 0; right: 0; bottom: 0; background: linear-gradient(transparent, rgba(0,0,0,.65)); color: #fff; font-size: .74rem; padding: 1rem .5rem .4rem; }
.media-item .menu { position: absolute; right: 4px; top: 4px; }
.uploader { border: 2px dashed var(--border-strong); border-radius: var(--radius); padding: 1.1rem; text-align: center; background: #fff; }
.uploader.drag { border-color: var(--primary); background: var(--primary-50); }
.upload-row { display: flex; align-items: center; gap: .7rem; padding: .5rem 0; font-size: .85rem; }
.upload-row .bar { flex: 1; height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; }
.upload-row .bar span { display: block; height: 100%; background: var(--primary); transition: width .2s; }
.upload-row.error .bar span { background: var(--danger); }

/* ---------- Отчёты ---------- */
.bar-row { display: grid; grid-template-columns: 180px 1fr 70px; gap: .7rem; align-items: center; padding: .35rem 0; font-size: .88rem; }
.bar-row .bar { height: 14px; background: var(--primary-50); border-radius: 4px; overflow: hidden; }
.bar-row .bar span { display: block; height: 100%; background: var(--primary); border-radius: 4px; }
.bar-row.accent .bar span { background: var(--accent); }
.stars { color: var(--warning); letter-spacing: 1px; }

/* ---------- Логин ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: radial-gradient(1200px 600px at 20% -10%, #1F4E79 0%, #10243A 55%, #0B1829 100%); }
.auth-card { width: 100%; max-width: 400px; background: #fff; border-radius: var(--radius-lg); padding: 2rem; box-shadow: var(--shadow-lg); }
.auth-card .brand { padding: 0 0 1.2rem; color: var(--text); }
.auth-card .brand-sub { color: var(--text-2); }

/* ---------- Адаптив ---------- */
@media (max-width: 960px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%); transition: transform .2s; z-index: 60; height: 100vh; }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .sidebar-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.4); z-index: 55; display: none; }
  .sidebar-backdrop.open { display: block; }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 0 .9rem; }
  .topbar .search { display: none; }
  .content { padding: 1rem .9rem calc(1rem + 70px); }
  .bottom-nav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; height: 62px; background: #fff; border-top: 1px solid var(--border); z-index: 50; padding-bottom: env(safe-area-inset-bottom); }
  .bottom-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--text-2); font-size: .68rem; font-weight: 600; }
  .bottom-nav a.active { color: var(--primary); }
  .bottom-nav .icon { width: 22px; height: 22px; }
  .kanban { grid-auto-columns: 86vw; scroll-snap-type: x mandatory; }
  .kanban-col { scroll-snap-align: start; max-height: none; }
  .sticky-bar { margin: 1rem -.9rem -1rem; bottom: 62px; }
  .cal-month .cal-cell { min-height: 64px; padding: .2rem; }
  .cal-ev { font-size: .62rem; padding: 1px 3px; }
  .cal-week { grid-template-columns: 1fr; }
  .btn { min-height: var(--tap); }
  .btn.sm { min-height: 36px; }
  .bar-row { grid-template-columns: 110px 1fr 60px; }
  .page-head { flex-direction: column; align-items: stretch; }
  h1 { font-size: 1.25rem; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
@media print { .sidebar, .topbar, .bottom-nav, .sticky-bar, .actions, .btn { display: none !important; } .content { padding: 0; } .card { box-shadow: none; } }
