/* Общий стиль сайта */
:root {
  --bg: #f5f6f8; --card: #fff; --text: #1d2330; --muted: #6b7280; --line: #e3e6eb;
  --accent: #1f6feb; --accent-soft: #e8f0fe; --ok: #1a7f37; --warn: #b35900; --err: #c62828;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 12px; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 0 0 8px; }

/* Шапка и вкладки */
/* Шапка: на узком экране пункты меню переносятся на следующую строку, а не прячутся */
.top { background: #1d2330; color: #fff; display: flex; flex-wrap: wrap; align-items: center; gap: 0 18px; padding: 0 20px; min-height: 52px; }
.top .logo { font-weight: 700; letter-spacing: .5px; }
.top nav { display: flex; flex-wrap: wrap; gap: 2px; flex: 1 1 auto; }
.top nav a { color: #c9d1d9; padding: 15px 12px; white-space: nowrap; }
.top nav a.on, .top nav a:hover { color: #fff; background: rgba(255,255,255,.08); text-decoration: none; }
.top .user { color: #c9d1d9; white-space: nowrap; font-size: 13px; }
.top .user form { display: inline; }
.top .user button { background: none; border: 0; color: #c9d1d9; cursor: pointer; text-decoration: underline; padding: 0 0 0 8px; }
main { padding: 20px; max-width: 1400px; margin: 0 auto; }

/* Карточки и сетка */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Таблицы */
table.list { width: 100%; border-collapse: collapse; background: var(--card); }
table.list th, table.list td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.list th { font-size: 12px; text-transform: uppercase; color: var(--muted); font-weight: 600; background: #fafbfc; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: var(--accent-soft); }
td.r, th.r { text-align: right; }
.table-wrap { overflow-x: auto; }
dl.kv { display: grid; grid-template-columns: 170px 1fr; gap: 4px 12px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }

/* Формы */
input, select, textarea { font: inherit; padding: 6px 8px; border: 1px solid #cfd4dc; border-radius: 6px; background: #fff; max-width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px 16px; }
.form-grid label, .field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.form-grid input, .form-grid select, .form-grid textarea { width: 100%; }
.field { margin-bottom: 10px; }
.helptext { font-size: 12px; color: var(--muted); }
.errorlist { color: var(--err); margin: 2px 0; padding-left: 16px; font-size: 12px; }

.btn { display: inline-block; padding: 7px 14px; border-radius: 6px; border: 1px solid #cfd4dc; background: #fff; color: var(--text); cursor: pointer; font: inherit; }
.btn:hover { background: #f0f2f5; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1a5fd0; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--err); }
.btn.sm { padding: 3px 8px; font-size: 12px; }
form.inline { display: inline; }

/* Метки этапов и статусов */
.tag { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; background: #eef1f5; color: #3b4452; white-space: nowrap; }
.tag.new { background: #e8f0fe; color: #1f4fbf; }
.tag.final { background: #f3f4f6; color: #6b7280; }
.tag.approval { background: #fff4e5; color: var(--warn); }
.tag.approved { background: #e6f4ea; color: var(--ok); }
.tag.sent { background: #e6f4ea; color: var(--ok); }

.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.messages li { padding: 10px 14px; border-radius: 6px; margin-bottom: 6px; background: var(--accent-soft); }
.messages li.success { background: #e6f4ea; color: var(--ok); }
.messages li.error { background: #fdecea; color: var(--err); }
.messages li.warning { background: #fff4e5; color: var(--warn); }
.note-box { background: #fffbe6; border: 1px solid #f0e2a8; border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; }
.notice { background: #fff4e5; color: var(--warn); border-radius: 6px; padding: 8px 12px; margin-bottom: 10px; }
.warn { color: var(--warn); }

/* Фото */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.photos a img { width: 100%; height: 110px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }

/* Просмотр фото */
.lightbox { position: fixed; inset: 0; background: rgba(10,12,16,.92); z-index: 70; display: flex; align-items: center; justify-content: center; }
.lightbox[hidden] { display: none; }
.lightbox img { max-width: calc(100vw - 140px); max-height: calc(100vh - 110px); object-fit: contain; border-radius: 4px; background: #222; }
.lightbox button { position: absolute; background: rgba(255,255,255,.12); border: 0; color: #fff; cursor: pointer; border-radius: 50%; }
.lightbox button:hover { background: rgba(255,255,255,.25); }
.lb-close { top: 14px; right: 16px; width: 40px; height: 40px; font-size: 26px; }
.lb-prev, .lb-next { top: 50%; transform: translateY(-50%); width: 52px; height: 52px; font-size: 34px; line-height: 1; }
.lb-prev { left: 16px; }
.lb-next { right: 16px; }
.lb-bar { position: absolute; bottom: 14px; left: 0; right: 0; text-align: center; color: #ddd; font-size: 13px; }
.lb-bar a { color: #9cc2ff; margin-left: 10px; }
@media (max-width: 600px) { .lightbox img { max-width: 100vw; } .lb-prev, .lb-next { width: 40px; height: 40px; } }
.form-grid input[type=checkbox] { width: auto; }

/* Комментарии и история */
.comment { border-bottom: 1px solid var(--line); padding: 8px 0; }
.comment .meta { font-size: 12px; color: var(--muted); }
.events { font-size: 12px; color: var(--muted); max-height: 260px; overflow-y: auto; }

/* Редактор расчёта */
.lamp { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 12px; background: #fcfcfd; overflow-x: auto; }
#parts { overflow-x: auto; }
.ed td input, .ed td select { width: 100%; }
#lamps .ed td:nth-child(2) { min-width: 300px; }   /* колонка «Работа» — только в таблице работ */
/* Таблица запчастей должна помещаться без прокрутки на ширине ~900 px (цены видны и менеджеру) */
#parts .ed td:nth-child(3) { min-width: 170px; }
#parts .ed td.w-num input { width: 62px; }
#parts .ed td.w-price input { width: 92px; }
#parts .ed th, #parts .ed td { padding: 6px 5px; }
.ed td.w-num input { width: 80px; }
.ed td.w-price input { width: 110px; }
.manual-flag { font-size: 11px; color: var(--warn); }
.totals { text-align: right; font-size: 15px; }
.totals b { font-size: 18px; }
.suggest { position: relative; }
.suggest-list { position: absolute; z-index: 10; background: #fff; border: 1px solid var(--line); border-radius: 6px; max-height: 280px; overflow-y: auto; width: 100%; box-shadow: 0 6px 20px rgba(0,0,0,.08); }
.suggest-list div { padding: 6px 10px; cursor: pointer; border-bottom: 1px solid #f0f2f5; }
.suggest-list div:hover { background: var(--accent-soft); }

/* Документ (как в PDF) */
/* Кнопки в шапке, счётчики */
.topbtn { background: none; border: 0; color: #c9d1d9; font: inherit; cursor: pointer; padding: 6px 8px; white-space: nowrap; }
.topbtn:hover { color: #fff; text-decoration: none; }
.badge[hidden] { display: none; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: #e5534b; color: #fff; font-size: 11px; text-align: center; line-height: 18px; }

/* Панель задач справа */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: 420px; max-width: 100%; background: #fff; border-left: 1px solid var(--line);
          box-shadow: -8px 0 24px rgba(0,0,0,.08); padding: 16px; overflow-y: auto; z-index: 40; }
#drawer-body, #modal-body { padding-right: 26px; }
button.armed { background: #c62828 !important; border-color: #c62828 !important; color: #fff !important; width: auto !important; padding: 3px 8px; }
.modal-back { border: 0; background: none; color: var(--accent); cursor: pointer; font: inherit; padding: 0; margin-bottom: 8px; }
.chk-space { width: 20px; flex: none; }
table.cal td[data-day] { cursor: pointer; }
table.cal td[data-day]:hover { background: #f7f9fc; }
details.done-list > summary { cursor: pointer; color: var(--muted); font-size: 13px; padding: 6px 0; }
[data-task] { cursor: pointer; }
.top nav { scrollbar-width: none; }
.top nav::-webkit-scrollbar { display: none; }
.drawer-close { position: absolute; top: 8px; right: 10px; border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.pitem { display: flex; gap: 8px; align-items: flex-start; padding: 6px 0; border-bottom: 1px solid #f0f2f5; }
.chk { width: 20px; height: 20px; border: 1.5px solid #9aa1ab; border-radius: 5px; background: #fff; cursor: pointer; font-size: 13px; line-height: 16px; padding: 0; color: var(--ok); flex: none; text-align: center; }
.ev-done { opacity: .55; text-decoration: line-through; }
/* Подпись «кто и когда сделал» — не зачёркнутая */
.done-note { display: inline-block; text-decoration: none; font-size: 11px; color: var(--ok); margin-left: 4px; }
.ev-link { cursor: pointer; }
.ok { color: var(--ok); }

/* Окно карточки */
.modal { position: fixed; inset: 0; background: rgba(15,20,30,.45); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 60px 16px; }
.modal[hidden] { display: none; }
.modal-box { position: relative; background: #fff; border-radius: 10px; padding: 20px; width: 760px; max-width: 100%; max-height: calc(100vh - 120px); overflow-y: auto; }

/* Всплывающие уведомления */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: #1d2330; color: #fff; padding: 12px 16px; border-radius: 8px; max-width: 360px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast:hover { text-decoration: none; background: #2a3242; }
tr.unread td { font-weight: 600; }

/* Календарь */
table.cal { width: 100%; border-collapse: collapse; table-layout: fixed; background: #fff; }
table.cal th { padding: 6px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); }
table.cal td { border: 1px solid var(--line); vertical-align: top; height: 110px; padding: 4px; }
table.cal td.other { background: #fafbfc; }
table.cal td.other .cal-day { color: #b0b6bf; }
table.cal td.today { background: #f2f7ff; }
.cal-day { font-size: 12px; font-weight: 600; margin-bottom: 3px; }
.ev { font-size: 12px; line-height: 1.3; padding: 2px 5px; border-radius: 4px; margin-bottom: 3px; border-left: 3px solid #9aa1ab; background: #f3f4f6; overflow: hidden; }
.ev[data-case] { cursor: pointer; }
.ev[data-case]:hover { filter: brightness(.95); }
.ev-callback { border-color: #d97706; background: #fff4e5; }
.ev-repair { border-color: #1f6feb; background: #e8f0fe; }
.ev-in_repair { border-color: #7c3aed; background: #f1ebff; }
.ev-nnr { border-color: #c62828; background: #fdecea; }
.ev-task { border-color: #1a7f37; background: #e6f4ea; }
.ev-assignment { border-color: #0e7490; background: #e0f4f8; }
.ev-overdue { box-shadow: inset 0 0 0 1px #c62828; }
.legend { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.legend .ev { margin: 0; }
.legend label.flt { cursor: pointer; user-select: none; }
.legend label.flt input, .legend .flt-done input { vertical-align: -2px; margin: 0 2px 0 0; }
.legend label.flt.off { opacity: .45; }
/* Звонки владельцу: строки переносятся на узком экране */
.cb-item { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line); }
.cb-item.cb-closed .cb-info { color: var(--muted); }
.cb-info { flex: 1 1 200px; min-width: 0; }
.cb-actions { flex: 1 1 260px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.cb-form { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.cb-form input:not([type=hidden]) { flex: 1 1 140px; min-width: 0; }
.cb-form button { flex: none; }

/* Как #doc в калькуляторе — просмотр совпадает с PDF */
.doc { background: #fff; color: #000; padding: 12mm; border: 1px solid var(--line); max-width: 210mm; font: 11px/1.35 Arial, Helvetica, sans-serif; }
.doc h1 { font-size: 15px; margin: 0 0 8px; }
.doc table { border-collapse: collapse; width: 100%; }
.doc td, .doc th { border: 1px solid #000; padding: 3px 5px; vertical-align: top; }
.doc th { background: #eee; font-weight: bold; text-align: center; }
.doc .nb td { border: 0; padding: 1px 4px; }
.doc .r { text-align: right; white-space: nowrap; }
.doc .t { font-weight: bold; margin: 10px 0 3px; }
.doc .tot td { border: 0; font-weight: bold; }
.hidden-price { color: #9aa1ab; font-style: italic; }

/* Склад */
.stock-tag { color: #1f4fbf; margin-top: 2px; }
.ok-text { color: var(--ok); }
.stock-table td.r { white-space: nowrap; }
.stock-actions { display: flex; flex-direction: column; gap: 4px; align-items: stretch; }
.stock-actions .btn { text-align: center; }
/* Переключатели (radio) в формах-сетках: в строку, обычным шрифтом */
.form-grid input[type=radio] { width: auto; margin: 0 6px 0 0; }
.form-grid label:has(> input[type=radio]) { display: inline-flex; align-items: center; font-size: 14px; color: var(--text); margin: 4px 16px 0 0; cursor: pointer; }
.form-grid div:has(> label > input[type=radio]) { display: inline-block; }
