:root {
  --ink: #33383d;
  --ink-soft: #6d7379;
  --line: #cfd2d4;
  --field: #efeff0;
  --accent: #5b5c94;
  --accent-soft: #e3e6f6;
  --page: #eef0f2;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.45 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------- шапка сайта ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 0 22px; height: 52px;
  background: #fff; border-bottom: 1px solid #dfe1e3;
}
.brand-link {
  font-size: 12.5px; letter-spacing: 1.6px; font-weight: 600;
  color: #4a4f54; text-decoration: none;
}
.topnav { display: flex; align-items: center; gap: 14px; font-size: 13px; color: var(--ink-soft); }
.inline { display: inline; margin: 0; }
.linkbtn {
  background: none; border: 0; padding: 0; cursor: pointer;
  font: inherit; color: var(--accent); text-decoration: underline;
}

.messages { max-width: 1000px; margin: 16px auto -4px; padding: 0 20px; }
.msg { padding: 9px 13px; border-radius: 6px; font-size: 13.5px; background: #e7efe6; color: #2f5a33; }
.msg.error { background: #fbe9e7; color: #8c3b31; }

/* ---------- лист ---------- */
.sheet {
  background: #fff; max-width: 1010px; margin: 20px auto 60px;
  padding: 30px 34px 26px; border-radius: 4px;
  box-shadow: 0 1px 2px rgba(28, 33, 38, .07), 0 8px 26px rgba(28, 33, 38, .06);
}

.doc-head {
  display: grid; grid-template-columns: 190px 1fr 200px;
  align-items: center; gap: 14px; margin-bottom: 16px;
}
.bc svg { width: 100%; height: 44px; display: block; }
.bc-num { font-size: 12px; letter-spacing: 1.1px; color: #3c4146; margin-top: 1px; }
.doc-title {
  font-size: 21px; font-weight: 600; letter-spacing: .3px;
  text-align: center; margin: 0; color: #2f3439;
}
.doc-num {
  display: inline-block; min-width: 150px; padding: 1px 14px 2px;
  background: var(--field); border-radius: 4px; text-align: center;
  font-weight: 600; vertical-align: 2px;
}
.doc-num.empty { color: #b3b7ba; font-weight: 400; }

.brand { display: flex; align-items: center; gap: 8px; justify-content: flex-end; color: #3f4449; }
.brand-tooth { width: 25px; height: 29px; flex: none; }
.brand-name { font-size: 19px; letter-spacing: 1.4px; font-weight: 500; line-height: 1.1; }
.brand-sub { font-size: 7.6px; letter-spacing: 1.05px; color: #7d8287; text-transform: uppercase; }

/* ---------- верхний блок ---------- */
.row-top { display: grid; grid-template-columns: 1fr 1.06fr; gap: 26px; align-items: start; }
.frow { display: grid; grid-template-columns: 84px 1fr; align-items: center; gap: 10px; margin-bottom: 8px; }
.fl { font-size: 12.5px; line-height: 1.12; color: var(--ink-soft); }
.fv {
  background: var(--field); border-radius: 4px; padding: 6px 10px;
  min-height: 32px; font-size: 14px; overflow-wrap: anywhere;
}
.fv.empty { color: #b3b7ba; }
.frow.due { margin-top: 14px; }
.frow.due .fl { font-size: 17px; color: var(--ink); font-weight: 500; }
.frow.due .fv { font-size: 17px; font-weight: 500; padding: 4px 12px; }

.req {
  border: 1px solid var(--line); border-radius: 6px;
  padding: 10px 12px 12px; min-height: 196px;
  display: flex; flex-direction: column;
}
.req-label { font-size: 12.5px; color: var(--ink-soft); margin-bottom: 6px; }
.req-body { font-size: 13.5px; white-space: pre-wrap; overflow-wrap: anywhere; flex: 1; }
.req-body.empty { color: #b9bdbf; }

.rule { border: 0; border-top: 2.5px solid #2f3337; margin: 18px 0 16px; }

/* ---------- зубной ряд ---------- */
.row-mid { display: grid; grid-template-columns: 1fr 300px; gap: 8px; align-items: start; }
.arch { padding: 0 6px; }
.arch-svg { width: 100%; height: auto; display: block; overflow: visible; }
.tooth .tk { fill: #fff; stroke: var(--accent); stroke-width: 1.4; transition: fill .12s; }
.tooth.sel .tk { fill: var(--accent-soft); stroke-width: 2.3; }
.tooth .tb { fill: none; stroke: #9a9cbe; stroke-width: 0.8; stroke-linecap: round; opacity: .6; pointer-events: none; }
.tooth.sel .tb { stroke: #4f5187; opacity: .9; }
.tn { font-size: 9.6px; fill: #55577f; font-family: inherit; }
.teeth-labels { pointer-events: none; }
.arch-svg.is-editable .tooth { cursor: pointer; }
.arch-svg.is-editable .tooth:hover .tk { fill: #f1f3fc; }
.arch-svg.is-editable .tooth.sel:hover .tk { fill: #d5daf1; }

.side { border-left: 1px solid #b9bcbe; padding: 6px 0 6px 22px; }
.srow { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 8px; margin-bottom: 13px; font-size: 13.5px; }
.srow .sl { color: var(--ink-soft); font-size: 12.5px; line-height: 1.15; }
.srow .sv { background: var(--field); border-radius: 4px; padding: 5px 10px; min-height: 30px; }
.srow.color-row { margin-bottom: 16px; }
.srow.color-row .sl { font-size: 20px; color: var(--ink); font-weight: 500; }
.srow.color-row .sv { font-size: 17px; font-weight: 500; }
.checks { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.check-item { display: inline-flex; align-items: center; gap: 5px; font-size: 13.5px; }

/* галочки */
.box {
  width: 14px; height: 14px; border: 1.2px solid #85898d; border-radius: 2px;
  display: inline-block; position: relative; flex: none; background: #fff;
}
.box.on { border-color: #4a4d51; }
.box.on::after {
  content: ""; position: absolute; left: 2.6px; top: 2.2px; width: 3.2px; height: 6.4px;
  border: solid #3f4348; border-width: 0 1.7px 1.7px 0; transform: rotate(42deg);
}

/* ---------- таблицы ---------- */
.bottom-grid { display: grid; grid-template-columns: 1fr 340px; gap: 26px; margin-top: 24px; align-items: start; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: fixed; }
table.grid th, table.grid td { border: 1px solid #c6c9cb; padding: 5px 8px; text-align: center; vertical-align: middle; height: 33px; }
table.grid th { font-weight: 400; color: #4c5155; font-size: 13px; }
table.grid td.name, table.grid td.wide { text-align: left; }
table.grid td { overflow-wrap: anywhere; }
table.works col.c-num { width: 34px; }
table.works col.c-date { width: 118px; }
table.works col.c-qty { width: 66px; }

.comment {
  border: 1px solid var(--line); border-radius: 6px;
  padding: 10px 12px 12px; margin-top: 26px; min-height: 150px;
  display: flex; flex-direction: column;
}
.comment-label { font-size: 12.5px; color: var(--ink-soft); margin-bottom: 6px; }
.comment-body { font-size: 13.5px; white-space: pre-wrap; overflow-wrap: anywhere; flex: 1; }
.comment-body.empty { color: #b9bdbf; }

/* ---------- панель действий ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.toolbar .spacer { flex: 1; }
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 16px; border-radius: 6px; border: 1px solid #cfd3d6;
  background: #fff; color: #34393e; font: inherit; font-size: 13.5px;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: #a9aeb2; }
.btn.primary { background: #3b4046; border-color: #3b4046; color: #fff; }
.btn.primary:hover { background: #2c3035; }
.btn.danger { color: #9b3a2e; border-color: #e2c7c1; }
.btn.danger:hover { background: #fdf3f1; border-color: #cf9c92; }
.btn.small { padding: 5px 11px; font-size: 12.5px; }

/* ---------- формы ---------- */
input[type="text"], input[type="date"], input[type="number"], textarea, select {
  font: inherit; font-size: 14px; color: var(--ink);
  background: var(--field); border: 1px solid transparent;
  border-radius: 4px; padding: 6px 9px; width: 100%;
  transition: background .12s, border-color .12s, box-shadow .12s;
}
input[type="text"]:focus, input[type="date"]:focus, input[type="number"]:focus,
textarea:focus, select:focus {
  background: #fff; border-color: #a9b0d2; outline: none;
  box-shadow: 0 0 0 3px rgba(91, 92, 148, .13);
}
textarea { resize: vertical; line-height: 1.45; }
textarea.area { background: #fff; border-color: var(--line); }
input::placeholder { color: #a8acae; }

input[type="checkbox"], input[type="radio"] {
  appearance: none; -webkit-appearance: none;
  width: 15px; height: 15px; margin: 0 1px 0 0; vertical-align: -2px;
  border: 1.3px solid #85898d; border-radius: 2px; background: #fff;
  cursor: pointer; position: relative; flex: none;
}
input[type="radio"] { border-radius: 50%; }
input[type="checkbox"]:checked, input[type="radio"]:checked { background: #3b4046; border-color: #3b4046; }
input[type="checkbox"]:checked::after {
  content: ""; position: absolute; left: 3.4px; top: 0.6px; width: 3.6px; height: 7.4px;
  border: solid #fff; border-width: 0 1.8px 1.8px 0; transform: rotate(42deg);
}
input[type="radio"]:checked::after {
  content: ""; position: absolute; inset: 3.2px; border-radius: 50%; background: #fff;
}
input[type="checkbox"]:focus-visible, input[type="radio"]:focus-visible { box-shadow: 0 0 0 3px rgba(91, 92, 148, .25); }

ul.pills { list-style: none; display: flex; gap: 14px; margin: 0; padding: 0; }
ul.pills li { margin: 0; }
ul.pills label { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; font-size: 13.5px; }

.form-block { min-width: 0; }
.field-row { display: grid; grid-template-columns: 84px 1fr; align-items: center; gap: 10px; margin-bottom: 8px; }
.field-row > label, .field-row .fl { font-size: 12.5px; color: var(--ink-soft); line-height: 1.12; }
.field-row.due { margin-top: 14px; }
.field-row.due > label { font-size: 17px; color: var(--ink); font-weight: 500; }
.field-row.due input { font-size: 17px; font-weight: 500; }
.errorlist { list-style: none; margin: 2px 0 0; padding: 0; color: #8c3b31; font-size: 12px; }
.form-errors { background: #fbe9e7; color: #8c3b31; padding: 9px 13px; border-radius: 6px; font-size: 13.5px; margin-bottom: 14px; }

.teeth-tools { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 12.5px; color: var(--ink-soft); }
.teeth-tools input.teeth-input { max-width: 240px; font-size: 12.5px; padding: 4px 8px; }
.teeth-tools .count { white-space: nowrap; }

.works-table td { padding: 0; border: 1px solid #c6c9cb; height: 36px; }
.works-table td .cell-num { display: block; text-align: center; padding: 6px 4px; font-size: 13px; color: #4c5155; }
.works-table td input { border: 0; border-radius: 0; background: transparent; height: 34px; font-size: 13px; }
.works-table td input:focus { background: #fff; box-shadow: inset 0 0 0 2px rgba(91, 92, 148, .3); }
.works-table td.del { width: 26px; text-align: center; }
table.grid td.del button {
  border: 0; background: none; color: #b4b8ba; cursor: pointer; font-size: 15px; line-height: 1;
  padding: 4px 2px;
}
table.grid td.del button:hover { color: #9b3a2e; }
tr.removed { display: none; }
.addrow { margin-top: 8px; }

.side .srow input[type="text"] { padding: 5px 9px; min-height: 30px; }
.side .checks { margin-top: 2px; }

@media (max-width: 860px) {
  .sheet { padding: 20px 16px; margin: 12px 8px 40px; }
  .doc-head { grid-template-columns: 1fr; gap: 10px; justify-items: center; }
  .brand { justify-content: center; }
  .row-top, .row-mid, .bottom-grid { grid-template-columns: 1fr; gap: 18px; }
  .side { border-left: 0; border-top: 1px solid #b9bcbe; padding: 16px 0 0; }
  .frow, .field-row { grid-template-columns: 76px 1fr; }
  .doc-title { font-size: 18px; }
  .topbar { padding: 0 14px; }
  .messages { padding: 0 14px; }
}

/* ---------- печать ---------- */
@media print {
  @page { size: A4; margin: 9mm 10mm; }
  body { background: #fff; font-size: 11.5px; }
  .no-print, .topbar, .messages, .toolbar { display: none !important; }
  .sheet {
    box-shadow: none; margin: 0; padding: 0; max-width: none; border-radius: 0;
  }
  .doc-head { grid-template-columns: 170px 1fr 180px; margin-bottom: 12px; }
  .doc-title { font-size: 18px; }
  .brand-name { font-size: 16px; }
  .row-top { gap: 16px; }
  .frow { margin-bottom: 6px; }
  .req { min-height: 168px; }
  .row-mid { grid-template-columns: 1fr 268px; gap: 6px; }
  .bottom-grid { grid-template-columns: 1fr 300px; gap: 16px; margin-top: 16px; }
  table.grid th, table.grid td { height: 28px; padding: 4px 6px; font-size: 11.5px; }
  .comment { min-height: 120px; margin-top: 16px; }
  .tooth .tk { stroke-width: 1.1; }
  .tooth.sel .tk { stroke-width: 2; }
  .rule { margin: 12px 0 12px; }
  .sheet { zoom: 0.85; }
  .row-top, .row-mid, .bottom-grid, .comment, .doc-head { page-break-inside: avoid; }
}

/* ---------- список ---------- */
.list-wrap { max-width: 1010px; margin: 24px auto 60px; padding: 0 20px; }
.list-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 16px; }
.list-head h1 { font-size: 20px; margin: 0; font-weight: 600; letter-spacing: .2px; }
.search { display: flex; gap: 8px; flex: 1; min-width: 220px; max-width: 420px; }
.search input { background: #fff; border-color: #d5d8da; }
.cards { display: grid; gap: 10px; }
.card {
  background: #fff; border: 1px solid #e2e4e6; border-radius: 7px;
  padding: 12px 14px; display: grid; grid-template-columns: 74px 1fr auto; gap: 12px;
  align-items: center; text-decoration: none; color: inherit; transition: border-color .12s, box-shadow .12s;
}
.card:hover { border-color: #b9bfd0; box-shadow: 0 2px 10px rgba(28, 33, 38, .06); }
.card .cnum { font-size: 15px; font-weight: 600; color: #3b4046; }
.card .cnum small { display: block; font-weight: 400; font-size: 11px; color: var(--ink-soft); }
.card .cmain { min-width: 0; }
.card .cpatient { font-size: 14.5px; }
.card .cmeta { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .cdate { font-size: 12.5px; color: var(--ink-soft); text-align: right; white-space: nowrap; }
.card .cdate b { display: block; color: #4c5155; font-weight: 500; }
.empty-state { background: #fff; border: 1px dashed #cfd3d6; border-radius: 8px; padding: 34px; text-align: center; color: var(--ink-soft); }

/* ---------- вход ---------- */
.auth { max-width: 360px; margin: 14vh auto; background: #fff; padding: 30px 28px; border-radius: 8px; border: 1px solid #e2e4e6; }
.auth h1 { font-size: 17px; margin: 0 0 18px; font-weight: 600; }
.auth .field-row { grid-template-columns: 1fr; gap: 6px; margin-bottom: 14px; }
.auth input { background: #fff; border-color: #d5d8da; }
.auth .btn { width: 100%; justify-content: center; margin-top: 6px; }

/* ---------- доработки формы ---------- */
.req textarea, .comment textarea {
  background: transparent; border: 0; border-radius: 0; padding: 0;
  flex: 1; min-height: 150px; box-shadow: none;
}
.comment textarea { min-height: 110px; }
.req textarea:focus, .comment textarea:focus { background: transparent; box-shadow: none; border: 0; }

table.grid td.del input[type="checkbox"],
.techs-table td.del input[type="checkbox"] { display: none; }
.works-table td input[type="number"] { text-align: center; padding: 6px 4px; }
.works-table td input[type="date"] { font-size: 12.5px; padding: 6px 4px; }
.works-table td.numcell, .techs-table td.numcell { width: 34px; background: #fafafa; }

/* радио «Пол» — квадратные галочки */
[id^="id_gender"] { display: flex; gap: 16px; flex-wrap: wrap; }
[id^="id_gender"] > div { display: flex; }
[id^="id_gender"] label { display: inline-flex; align-items: center; gap: 5px; font-size: 13.5px; cursor: pointer; }
.side .checks label { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.side .srow input[type="text"] { font-size: 13.5px; }

@media (max-width: 860px) {
  .toolbar .spacer { display: none; }
  .arch { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .arch .arch-svg { min-width: 500px; }
  .teeth-tools { flex-wrap: wrap; }
}

@media (max-width: 860px) {
  .techs-table input[type="date"] { font-size: 11.5px; padding: 6px 3px; }
  .works-table input[type="date"] { font-size: 11.5px; }
}
