:root {
  --bg: #f3f4f6; --card: #fff; --text: #1d232b; --muted: #687280; --line: #dde1e6;
  --accent: #1f4e79; --accent-h: #173c5e; --accent-soft: #e6eef6; --danger: #b42318;
  --ok-bg: #e7f4ec; --ok: #1d6b3a; --err-bg: #fdecea; --radius: 8px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15191e; --card: #1e242b; --text: #e5e8ec; --muted: #9aa3ae; --line: #313942;
    --accent: #5b9bd5; --accent-h: #78afe0; --accent-soft: #23313f; --danger: #f07167;
    --ok-bg: #18301f; --ok: #7fd09a; --err-bg: #3a1d1b;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; font-weight: 600; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 20px; padding-bottom: 48px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pre { white-space: pre-wrap; }
.inline { display: inline; margin: 0; }

/* шапка */
.top { background: var(--card); border-bottom: 1px solid var(--line); }
.top-in { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; flex-wrap: wrap; }
.brand { display: flex; flex-direction: column; color: var(--text); line-height: 1.2; padding: 8px 0; }
.brand:hover { text-decoration: none; }
.brand-t { font-weight: 650; }
.brand-o { font-size: 12px; color: var(--muted); }
.nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.nav a, .linkbtn { padding: 6px 10px; border-radius: 6px; color: var(--text); font-size: 14px; }
.nav a:hover, .linkbtn:hover { background: var(--accent-soft); text-decoration: none; }
.nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.linkbtn { background: none; border: 0; font: inherit; font-size: 14px; cursor: pointer; color: var(--muted); }

/* общие блоки */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.narrow { max-width: 520px; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.count { font-size: 14px; color: var(--muted); font-weight: 400; margin-left: 6px; }
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.error { background: var(--err-bg); color: var(--danger); }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 12px; }
.empty { text-align: center; color: var(--muted); padding: 36px 16px; }

/* кнопки */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px;
  padding: 0 14px; border-radius: 6px; border: 1px solid var(--line); background: var(--card);
  color: var(--text); font: inherit; font-size: 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-h); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.wide { width: 100%; }

/* формы */
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
input, select, textarea { font: inherit; font-size: 15px; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; min-height: 38px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=checkbox] { width: auto; min-height: 0; margin: 0; }
input[type=file] { padding: 6px; }
textarea { resize: vertical; }
label.chk { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form { max-width: 760px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.inline-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; max-width: none; }
.inline-form label { margin-bottom: 0; }
.grow { flex: 1 1 220px; }

/* фильтры */
.filters { display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: flex-end; }
.filters label { margin: 0; flex: 0 1 170px; }
.filters label.grow { flex: 1 1 220px; }
.f-actions { display: flex; gap: 8px; }
.tools { display: flex; gap: 8px; justify-content: flex-end; margin: -4px 0 12px; flex-wrap: wrap; }

/* список записей */
table.list { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted);
  font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--bg); }
.list td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.list tbody tr:last-child td { border-bottom: 0; }
.list:not(.plain) tbody tr { cursor: pointer; }
.list:not(.plain) tbody tr:hover { background: var(--accent-soft); }
.list tr.off td { color: var(--muted); }
.c-date { white-space: nowrap; width: 100px; }
.c-qty { white-space: nowrap; }
.c-ph { width: 56px; text-align: center; }
.c-work a { font-weight: 600; color: var(--text); }
.desc { color: var(--muted); font-size: 13px; margin-top: 2px; }
.badge { display: inline-block; min-width: 24px; padding: 1px 7px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin-top: 16px; }

/* карточка записи */
.props { display: grid; grid-template-columns: 180px 1fr; gap: 10px 16px; margin: 0 0 16px; }
.props dt { color: var(--muted); font-size: 13px; padding-top: 1px; }
.props dd { margin: 0; }
.thumbs { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.thumb { width: 150px; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.thumb img { width: 150px; height: 112px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); }
.thumb .file { display: flex; align-items: center; justify-content: center; text-align: center; width: 150px; height: 112px;
  border: 1px solid var(--line); border-radius: 6px; padding: 8px; font-size: 12px; color: var(--text); word-break: break-all; background: var(--bg); }
.thumb .del { flex-direction: row; display: flex; gap: 6px; align-items: center; font-size: 12px; }

/* журнал: одна запись — одна строка */
.list.rows td { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 0; }
.list.rows .c-date { width: 1%; max-width: none; overflow: visible; }
.list.rows .c-obj { width: 18%; }
.list.rows .c-auth { width: 16%; }
.list.rows .c-work a { color: var(--text); font-weight: 400; }
.list.rows .c-work b { font-weight: 600; }
.list.rows .sep { color: var(--muted); }

/* список работ в журнале */
.wlist { list-style: none; margin: 0; padding: 0; }
.wlist li + li { margin-top: 2px; }
.wlist a { font-weight: 600; color: var(--text); }
.wq { color: var(--muted); white-space: nowrap; }

/* список работ в форме */
.works { margin-bottom: 14px; }
.works-head, .work-row { display: grid; grid-template-columns: 28px 1fr 110px 110px 32px; gap: 8px; align-items: center; }
.works-head { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.works-head span:first-child { grid-column: 1 / 3; }
.work-row { margin-bottom: 8px; }
.work-row .wn { color: var(--muted); font-size: 14px; text-align: right; }
.wx { width: 32px; height: 32px; border: 1px solid var(--line); border-radius: 6px; background: transparent; color: var(--muted); font-size: 18px; cursor: pointer; padding: 0; }
.wx:hover { color: var(--danger); border-color: var(--danger); }
.add-work { margin-left: 36px; }
@media (max-width: 760px) {
  .works-head { display: block; } .works-head span:not(:first-child) { display: none; }
  .work-row { grid-template-columns: 22px 1fr 1fr 32px; row-gap: 6px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
  .work-row input[name=item_name] { grid-column: 2 / 4; }
  .work-row .wx { grid-column: 4; grid-row: 1; }
  .work-row input[name=item_qty] { grid-column: 2; }
  .work-row [name=item_unit] { grid-column: 3; }
  .add-work { margin-left: 0; width: 100%; }
}

/* выполненные работы в документе */
.doc-works { width: 100%; border-collapse: collapse; margin-top: -1px; }
.doc-works th, .doc-works td { border: 1px solid var(--rule); padding: 7px 10px; vertical-align: top; }
.doc-works th { background: var(--shade); font-weight: normal; color: #333; text-align: center; font-size: 14px; }
.doc-works .c-n { width: 44px; text-align: center; }
.doc-works .c-q { width: 90px; text-align: center; white-space: nowrap; }
.doc-works .c-u { width: 80px; text-align: center; }

/* запись в виде документа */
.doc-tools { max-width: 820px; margin: 0 auto 14px; display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.doc-tools-r { display: flex; gap: 8px; flex-wrap: wrap; }
.doc { --ink: #1a1a1a; --rule: #9aa1a9; --shade: #f2f4f6;
  max-width: 820px; margin: 0 auto; background: #fff; color: var(--ink);
  padding: 44px 52px 36px; border-radius: 2px; box-shadow: 0 1px 3px rgba(0,0,0,.25), 0 8px 28px rgba(0,0,0,.18);
  font-family: "Times New Roman", Times, "Liberation Serif", serif; font-size: 16px; line-height: 1.4; }
.doc-head { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 2px solid var(--ink); padding-bottom: 6px; font-size: 14px; }
.doc-org { font-weight: bold; letter-spacing: .02em; }
.doc-reg { color: #444; }
.doc-title { font-family: inherit; font-size: 20px; font-weight: bold; text-transform: uppercase; text-align: center; letter-spacing: .04em; margin: 26px 0 2px; color: var(--ink); }
.doc-sub { text-align: center; margin-bottom: 22px; }
.doc-table { width: 100%; border-collapse: collapse; }
.doc-table th, .doc-table td { border: 1px solid var(--rule); padding: 8px 12px; vertical-align: top; text-align: left; }
.doc-table th { width: 34%; background: var(--shade); font-weight: normal; color: #333; }
.doc-sect { margin: 24px 0 10px; font-weight: bold; text-transform: uppercase; font-size: 14px; letter-spacing: .05em; border-bottom: 1px solid var(--rule); padding-bottom: 4px; }
.doc-photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.doc-photos figure { margin: 0; }
.doc-photos img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border: 1px solid var(--rule); background: var(--shade); }
.doc-photos a:hover img { outline: 2px solid #1f4e79; outline-offset: 1px; }
.doc-photos figcaption { text-align: center; font-size: 13px; color: #444; margin-top: 4px; }
.doc-file { display: flex; align-items: center; justify-content: center; aspect-ratio: 4 / 3; border: 1px solid var(--rule); font-size: 13px; padding: 8px; word-break: break-all; color: #1f4e79; }
.doc-sign { width: 100%; border-collapse: collapse; margin-top: 34px; }
.doc-sign td { padding: 0 4px; height: 22px; vertical-align: bottom; }
.doc-sign .lbl { width: 130px; }
.doc-sign .ln { border-bottom: 1px solid var(--ink); width: 34%; }
.doc-sign .name { text-align: center; }
.doc-sign .sp { width: 24px; }
.doc-sign .cap { font-size: 11px; text-align: center; color: #555; height: auto; vertical-align: top; padding-bottom: 14px; }
.doc-foot { margin-top: 18px; padding-top: 6px; border-top: 1px solid var(--rule); font-size: 12px; color: #666; }
@media (max-width: 760px) {
  .doc { padding: 22px 16px 20px; font-size: 15px; }
  .doc-table th, .doc-table td { display: block; width: auto; border-top: 0; }
  .doc-table tr:first-child th { border-top: 1px solid var(--rule); }
  .doc-table th { padding: 5px 10px; font-size: 13px; }
  .doc-photos { grid-template-columns: repeat(2, 1fr); }
  .doc-sign .lbl { width: 90px; }
}
@media print {
  .doc-works th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  @page { size: A4 portrait; margin: 15mm 12mm 15mm 20mm; }
  body { background: #fff; }
  .top, .doc-tools, .flash, .lb { display: none !important; }
  main.wrap { padding: 0; max-width: none; }
  .doc { box-shadow: none; padding: 0; max-width: none; font-size: 12pt; }
  .doc-table th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .doc-photos figure { break-inside: avoid; }
}

/* просмотр фото поверх страницы */
.lb { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.88); display: flex; align-items: center; justify-content: center; }
.lb[hidden] { display: none; }
.lb img { max-width: calc(100vw - 32px); max-height: calc(100vh - 96px); object-fit: contain; background: #fff; border-radius: 4px; }
.lb button { position: absolute; border: 0; background: rgba(255,255,255,.14); color: #fff; cursor: pointer; border-radius: 50%; padding: 0; }
.lb button:hover { background: rgba(255,255,255,.3); }
.lb button[hidden] { display: none; }
.lb-x { top: 14px; right: 14px; width: 44px; height: 44px; font-size: 30px; line-height: 44px; }
.lb-nav { top: 50%; width: 48px; height: 48px; margin-top: -24px; font-size: 34px; line-height: 44px; }
.lb-prev { left: 14px; } .lb-next { right: 14px; }
.lb-bar { position: absolute; bottom: 14px; left: 0; right: 0; display: flex; gap: 20px; justify-content: center; color: #ddd; font-size: 14px; }
.lb-bar a { color: #fff; text-decoration: underline; }

/* выбор фото с предпросмотром */
.pick { margin-bottom: 4px; }
.pick .lbl { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.pick:not(.js) .pthumb.add { display: none; }
.pick.js .fallback { display: none; }
.pthumbs { display: flex; flex-wrap: wrap; gap: 10px; }
.pthumb { position: relative; width: 150px; height: 112px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); overflow: hidden; margin: 0; }
.pthumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pthumb .file { display: flex; align-items: center; justify-content: center; height: 100%; padding: 8px; font-size: 12px; text-align: center; word-break: break-all; color: var(--text); }
.pthumb .px { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%; border: 0;
  background: rgba(0,0,0,.6); color: #fff; font-size: 18px; line-height: 28px; padding: 0; cursor: pointer; }
.pthumb .px:hover { background: var(--danger); }
.pthumb .gone { display: none; }
.pthumb.del img, .pthumb.del .file { opacity: .25; }
.pthumb.del .px { display: none; }
.pthumb.del .gone { display: flex; flex-direction: column; gap: 4px; position: absolute; inset: 0; align-items: center; justify-content: center; text-align: center;
  font-size: 12px; color: var(--danger); cursor: pointer; }
.pthumb.add { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer;
  border: 1.5px dashed var(--line); color: var(--accent); font-size: 13px; }
.pthumb.add:hover { border-color: var(--accent); background: var(--accent-soft); }
.pthumb.add .plus { font-size: 28px; line-height: 1; }
.pthumb.add input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.btn:disabled { opacity: .6; cursor: wait; }

/* объекты */
.obj-row { display: grid; grid-template-columns: 2fr 2fr auto auto auto; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.obj-row:last-child { border-bottom: 0; }
.obj-row label.chk { margin: 0; }
.obj-row.off input[name=name] { color: var(--muted); }

/* вход */
.login { max-width: 380px; margin: 10vh auto 0; text-align: center; }
.login h1 { margin-bottom: 4px; }
.login .card { text-align: left; margin-top: 20px; }

/* телефон */
@media (max-width: 760px) {
  h1 { font-size: 19px; }
  .row2 { grid-template-columns: 1fr; }
  .filters label { flex: 1 1 calc(50% - 6px); }
  .filters label.grow { flex-basis: 100%; }
  .tools { justify-content: stretch; }
  .tools .btn { flex: 1; }
  table.list:not(.plain) thead { display: none; }
  table.list:not(.plain), .list:not(.plain) tbody, .list:not(.plain) tr, .list:not(.plain) td { display: block; width: auto; }
  .list:not(.plain) tr { padding: 10px 12px; border-bottom: 1px solid var(--line); position: relative; }
  .list:not(.plain) td { border: 0; padding: 1px 0; }
  .list:not(.plain) .c-date { font-size: 13px; color: var(--muted); }
  .list:not(.plain) .c-obj { font-size: 13px; color: var(--muted); }
  .list:not(.plain) .c-auth, .list:not(.plain) .c-qty { display: inline-block; font-size: 13px; color: var(--muted); margin-right: 12px; }
  .list:not(.plain) .c-ph { position: absolute; top: 10px; right: 12px; width: auto; }
  table.plain { display: block; overflow-x: auto; }
  .list.rows td { max-width: none; width: auto !important; }
  .list.rows .c-date, .list.rows .c-obj, .list.rows .c-auth { white-space: nowrap; }
  .list.rows .c-work { white-space: normal; display: -webkit-box !important; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .props { grid-template-columns: 1fr; gap: 2px; }
  .props dd { margin-bottom: 10px; }
  .obj-row { grid-template-columns: 1fr; }
  .thumb, .thumb img, .thumb .file { width: calc(50vw - 40px); }
  .pthumb { width: calc((100vw - 84px) / 3); height: calc((100vw - 84px) / 3); }
}
