:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --text: #1f2928;
  --muted: #66716f;
  --line: #e3e1da;
  --accent: #2f7566;
  --accent-soft: #e5f0ec;
  --danger: #b4443a;
  --danger-soft: #fbeceb;
  --warn-bg: #fff4cc;
  --warn-text: #6b5300;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(30, 40, 38, .05), 0 2px 8px rgba(30, 40, 38, .04);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
[hidden] { display: none !important; }

.container { max-width: 960px; margin: 0 auto; padding: 16px 16px 40px; outline: none; }

.demo-banner {
  background: var(--warn-bg); color: var(--warn-text);
  padding: 8px 16px; text-align: center; font-weight: 600; font-size: .9rem;
  border-bottom: 1px solid #f0dc8a;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 960px; margin: 0 auto; padding: 14px 16px 6px;
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }

.nav {
  max-width: 960px; margin: 0 auto; padding: 4px 16px;
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }
.nav a, .nav span {
  flex: none; padding: 7px 12px; border-radius: 999px; font-size: .92rem;
  text-decoration: none; color: var(--text); white-space: nowrap;
}
.nav a:hover { background: var(--accent-soft); }
.nav a.active { background: var(--accent); color: #fff; }
.nav span.soon { color: #a3aaa8; cursor: default; }

.footer { max-width: 960px; margin: 0 auto; padding: 0 16px 32px; color: var(--muted); font-size: .85rem; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }

.grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 720px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.grid .card + .card { margin-top: 0; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--bg); border-radius: 10px; padding: 10px 12px; }
.stat .num { font-size: 1.5rem; font-weight: 700; }
.stat .lbl { font-size: .82rem; color: var(--muted); }
@media (max-width: 420px) { .stat .num { font-size: 1.25rem; } }

.muted { color: var(--muted); }
.small { font-size: .88rem; }
.placeholder { color: var(--muted); font-size: .92rem; }
.tag { display: inline-block; font-size: .75rem; padding: 1px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); border: 1px solid var(--line); }

.quick { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 16px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 8px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  font: inherit; font-size: .95rem; cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: #c9c6bc; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #276455; border-color: #276455; }
.btn-danger { color: var(--danger); border-color: #e9c3bf; }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn[disabled], .btn.disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn-sm { min-height: 34px; padding: 4px 12px; font-size: .88rem; }
.link-btn { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: 4px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.page-head h1 { margin: 0; }
.back { display: inline-block; margin-bottom: 10px; text-decoration: none; font-size: .92rem; }

/* Списки записей */
.list { list-style: none; margin: 0; padding: 0; }
.list li + li { border-top: 1px solid var(--line); }
.list a.row { display: block; padding: 12px 2px; color: inherit; text-decoration: none; }
.list a.row:hover .row-title { color: var(--accent); }
.row-title { font-weight: 600; }
.row-sub { color: var(--muted); font-size: .9rem; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.month { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 0 4px; }
.month:first-child { margin-top: 0; }

/* Просмотр записи */
.fields { display: grid; grid-template-columns: 1fr; gap: 12px; margin: 0; }
.fields div { margin: 0; }
.fields dt { font-size: .82rem; color: var(--muted); }
.fields dd { margin: 2px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
@media (min-width: 720px) { .fields { grid-template-columns: 220px 1fr; gap: 10px 16px; } .fields div { display: contents; } }
.meta { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: .85rem; }

details.history { margin-top: 12px; }
details.history summary { cursor: pointer; color: var(--accent); font-size: .92rem; }
.rev { padding: 10px 0; border-top: 1px dashed var(--line); font-size: .9rem; }
.rev:first-of-type { border-top: 0; }
.rev ul { margin: 4px 0 0; padding-left: 18px; }
.rev .was { color: var(--danger); text-decoration: line-through; overflow-wrap: anywhere; }
.rev .now { color: var(--accent); overflow-wrap: anywhere; }

/* Формы */
.form { display: grid; gap: 16px; }
.field label, .field .label { display: block; font-weight: 600; margin-bottom: 4px; font-size: .95rem; }
.field .hint { display: block; color: var(--muted); font-size: .85rem; margin-top: 4px; font-weight: 400; }
.req { color: var(--danger); }
input[type=text], input[type=password], input[type=number], input[type=url], input[type=date], input[type=datetime-local], select, textarea {
  width: 100%; min-height: 44px; padding: 9px 12px;
  border: 1px solid #d4d1c8; border-radius: 10px; background: #fff; color: var(--text);
  font: inherit; font-size: 16px;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.inline { display: flex; gap: 8px; }
.inline > * { flex: 1; min-width: 0; }
.inline > .btn, .inline > select { flex: none; width: auto; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px 16px; margin: 0; display: grid; gap: 14px; }
legend { padding: 0 6px; font-weight: 700; }

.error-box { background: var(--danger-soft); color: var(--danger); border-radius: 10px; padding: 10px 12px; font-size: .92rem; }

.login { max-width: 380px; margin: 8vh auto 0; }
.login h1 { text-align: center; }
.login .hint-box { margin-top: 12px; background: var(--warn-bg); color: var(--warn-text); padding: 10px 12px; border-radius: 10px; font-size: .9rem; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: .92rem; box-shadow: 0 4px 16px rgba(0,0,0,.18); max-width: calc(100% - 32px); z-index: 10;
}

.dialog { border: 0; border-radius: var(--radius); padding: 20px; max-width: 400px; width: calc(100% - 32px); box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.dialog::backdrop { background: rgba(20, 30, 28, .35); }
.dialog p { margin: 0; }
.dialog .actions { justify-content: flex-end; }

.empty { text-align: center; padding: 28px 12px; color: var(--muted); }

/* Терапия */
.med { padding: 12px 0; }
.med + .med { border-top: 1px solid var(--line); }
.med h3 { margin: 0; font-size: 1.05rem; }
.med h3 a { color: var(--text); text-decoration: none; }
.med h3 a:hover { color: var(--accent); }
.med .card-head { align-items: center; margin-bottom: 4px; }
.med .fields { margin-top: 8px; }
h2.sub { margin-top: 20px; font-size: 1rem; }
.note { background: var(--warn-bg); color: var(--warn-text); padding: 6px 10px; border-radius: 8px; }
.info-box { background: var(--accent-soft); border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; font-size: .9rem; }
.info-box p { margin: 4px 0; }
.info-box.warn { background: var(--warn-bg); color: var(--warn-text); }
.info-box.warn a { color: inherit; font-weight: 600; }
.choice { display: flex; align-items: flex-start; gap: 8px; font-weight: 400 !important; margin: 6px 0; cursor: pointer; }
.choice input { width: 18px; height: 18px; margin: 3px 0 0; flex: none; accent-color: var(--accent); }
input.narrow { max-width: 220px; }
input:disabled { background: var(--bg); color: var(--muted); }
.actions.tight { margin-top: 0; }
.cmp { width: 100%; border-collapse: collapse; margin: 8px 0 16px; font-size: .95rem; }
.cmp th, .cmp td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
.cmp thead th { font-size: .82rem; color: var(--muted); font-weight: 600; }
.cmp tbody th { font-weight: 400; color: var(--muted); font-size: .88rem; width: 32%; }
.cmp td.changed { font-weight: 700; color: var(--accent); }
/* В карточках на главной колонка подписей уже, чтобы значения не переносились по буквам */
@media (min-width: 720px) { .grid .fields { grid-template-columns: minmax(100px, 38%) 1fr; } }

/* Фильтр по категориям */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--text); text-decoration: none; font-size: .9rem; }
.chip span { color: var(--muted); margin-left: 2px; }
.chip:hover { border-color: var(--accent); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.active span { color: rgba(255,255,255,.8); }

/* Показатели обследований */
.table-wrap { overflow-x: auto; }
.cmp.results th, .cmp.results td { font-size: .92rem; }
.cmp.results thead th { white-space: nowrap; }
.result-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1.4fr auto; gap: 8px; align-items: end; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.result-row .rf span { display: block; font-size: .8rem; color: var(--muted); margin-bottom: 2px; }
.result-row .remove-row { min-height: 44px; color: var(--danger); }
#add-row { justify-self: start; }
@media (max-width: 719px) {
  .result-row { grid-template-columns: 1fr 1fr; }
  .result-row .rf:first-child { grid-column: 1 / -1; }
  .result-row .remove-row { grid-column: 1 / -1; justify-self: end; min-height: 34px; }
}

/* Журнал событий */
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; align-items: end; margin-bottom: 12px; }
.filters .field label { font-size: .88rem; }
.filter-actions { grid-column: 1 / -1; }
.list.events li + li { border-top: 1px solid var(--line); }
details.event summary { list-style: none; cursor: pointer; padding: 11px 2px; display: grid; grid-template-columns: auto 1fr auto; gap: 4px 10px; align-items: baseline; }
details.event summary::-webkit-details-marker { display: none; }
details.event summary:hover .ev-title { color: var(--accent); }
.ev-title { font-weight: 600; overflow-wrap: anywhere; }
.ev-date { color: var(--muted); font-size: .88rem; white-space: nowrap; }
.ev-body { padding: 0 2px 12px; }
.ev-details { margin: 0 0 8px; padding-left: 18px; font-size: .92rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.tag-seizure { background: #fbeceb; border-color: #f0cfcb; color: #8f3a31; }
.tag-medication, .tag-dose_change { background: #e5f0ec; border-color: #c9e0d7; color: #245c50; }
.tag-parasite { background: #f3efe2; border-color: #e3dcc3; color: #6a5a24; }
.tag-vaccination { background: #e8eef8; border-color: #cfdaee; color: #34507d; }
.tag-exam { background: #efe9f5; border-color: #ddd1ea; color: #5b4277; }
@media (max-width: 480px) {
  details.event summary { grid-template-columns: auto 1fr; }
  .ev-date { grid-column: 1 / -1; }
}
.danger-zone { border-color: #ecc9c5; }
.danger-zone h2 { color: var(--danger); }
code { background: var(--bg); padding: 1px 5px; border-radius: 5px; font-size: .88em; overflow-wrap: anywhere; }

/* Главная: ближайшие даты */
.due-label { font-size: .85rem; color: var(--muted); }
.due-date-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin: 2px 0 8px; }
.due-date { font-size: 1.9rem; font-weight: 700; line-height: 1.15; letter-spacing: -.01em; }
.due-rel { color: var(--muted); font-size: .95rem; }
.due-status { display: inline-block; font-weight: 700; font-size: .95rem; padding: 5px 12px; border-radius: 8px; border: 1px solid transparent; margin-bottom: 8px; }
.status-planned { background: var(--accent-soft); color: #245c50; border-color: #c9e0d7; }
.status-soon { background: #fff1c2; color: #6b4e00; border-color: #e9c46a; }
.status-today { background: #ffe2c7; color: #7f3500; border-color: #ef9f5c; }
.status-overdue { background: #fbe3e0; color: #962f25; border-color: #e19b92; }
.due-what { margin: 0 0 10px; overflow-wrap: anywhere; }
.due-empty { margin: 0 0 12px; color: var(--muted); }
.due-more { list-style: none; padding: 10px 0 0; margin: 12px 0 0; border-top: 1px solid var(--line); font-size: .92rem; display: grid; gap: 6px; }
.due-more-what { overflow-wrap: anywhere; }
.status-inline { display: inline-block; font-size: .8rem; font-weight: 600; padding: 0 8px; border-radius: 6px; border: 1px solid transparent; }
.card.due .small.muted { margin: 10px 0 0; }
/* Карточка с приближающейся или прошедшей датой выделяется рамкой и полосой слева */
.card.due-soon { border-color: #e9c46a; box-shadow: inset 4px 0 0 #e0b03c, var(--shadow); }
.card.due-today { border-color: #ef9f5c; box-shadow: inset 4px 0 0 #e8853a, var(--shadow); }
.card.due-overdue { border-color: #e19b92; box-shadow: inset 4px 0 0 #c8574b, var(--shadow); }
@media (max-width: 420px) { .due-date { font-size: 1.6rem; } }
.home-top { margin-bottom: 16px; }
/* Одинаковые колонки во всех рядах, чтобы карточки стояли ровно друг под другом */
@media (min-width: 720px) { .grid-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }

/* Совместный доступ */
.topbar-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who { color: var(--muted); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 45vw; }
.member { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 2px; flex-wrap: wrap; }
.member > div:first-child { min-width: 0; overflow-wrap: anywhere; }
.member-actions { display: flex; gap: 8px; align-items: center; }
.member-actions select { min-height: 34px; padding: 4px 8px; width: auto; }
.invite-box input { font-size: .9rem; }
/* Кнопки, недоступные роли, скрыты (права всё равно проверяет сервер) */
body.role-viewer a[href$="/new"], body.role-viewer a[href*="/new?"], body.role-viewer a[href$="/edit"],
body:not(.role-owner) #del-btn, body:not(.role-owner) a[href="#/profile"], body:not(.role-owner) .danger-zone { display: none !important; }

/* Отчёт для невролога */
body:not(.role-owner) .owner-only { display: none !important; }
.report h1 { font-size: 1.4rem; margin-bottom: 6px; }
.r-head { border-bottom: 2px solid var(--line); padding-bottom: 10px; margin-bottom: 8px; }
.r-head p { margin: 4px 0; }
.r-pet { font-size: 1.05rem; overflow-wrap: anywhere; }
.r-sec { padding: 14px 0 6px; border-bottom: 1px solid var(--line); }
.r-sec:last-child { border-bottom: 0; }
.r-sec h2 { font-size: 1.1rem; }
.r-sec h4 { margin: 12px 0 6px; font-size: .95rem; }
.r-item { padding: 10px 0; border-top: 1px dashed var(--line); }
.r-item-title { font-weight: 700; }
.r-dl { display: grid; grid-template-columns: minmax(120px, 30%) 1fr; gap: 4px 12px; margin: 6px 0 0; font-size: .92rem; }
.r-dl dt { color: var(--muted); }
.r-dl dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.rtable { width: 100%; border-collapse: collapse; font-size: .88rem; margin: 6px 0 10px; }
.rtable th, .rtable td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: top; overflow-wrap: anywhere; }
.rtable th { background: var(--bg); font-weight: 600; }
@media (max-width: 560px) { .r-dl { grid-template-columns: 1fr; } .r-dl dt { margin-top: 4px; } }

@media print {
  body { background: #fff; font-size: 11pt; }
  .topbar, .nav, .footer, .toast, .no-print, dialog { display: none !important; }
  .container { max-width: none; padding: 0; }
  .card { border: 0; box-shadow: none; padding: 0; }
  .demo-banner { border: 1px solid #999; }
  .table-wrap { overflow: visible; }
  .r-sec h2, .r-item-title { break-after: avoid; }
  .r-item, .rtable tr { break-inside: avoid; }
  a { color: inherit; text-decoration: none; }
}
a.who { text-decoration: none; }
a.who[href]:hover { color: var(--accent); text-decoration: underline; }
