/* Дневник и «История дневника и питания» в новом виде (этап 2, шаг 5; макет кабинета клиента, экраны
   «Дневник» и «История дневника и питания»). Классы dy-…; общие компоненты — ui-kit.css.
   Прежние стили дневника (diary-compact.css) привязаны к .diary-compact и сюда не действуют. */

/* ---------- Страница дневника ---------- */
.dy {
  color: var(--ui-ink);
  font-size: var(--ui-body);
  line-height: var(--ui-leading);
}
.dy-head {
  position: sticky;
  top: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ui-space-4);
  margin: 0 0 var(--ui-space-3);
  padding: var(--ui-space-3) 0;
  background: var(--ui-paper);
}
body.ui-readable .dy-head h1 {
  margin: 0;
  font-size: var(--ui-section);
  font-weight: 600;
  line-height: var(--ui-leading);
}
.dy-save {
  flex: none;
}
/* На телефоне сверху уже закреплена плашка «Мой путь к цели» (64 px, client-home.css) — заголовок с «Сохранить»
   закрепляется сразу под ней и остаётся виден при прокрутке формы. */
@media (max-width: 760px) {
  body.client-view .dy-head:has(.dy-save) {
    top: 64px;
  }
}
.dy-histlink {
  margin: 0 0 var(--ui-space-4);
  border: 1px solid var(--ui-rule);
  border-radius: var(--ui-radius);
  background: var(--ui-surface-soft);
  font-weight: 600;
}
.dy-histlink .ui-row__lead,
.dy-replies .ui-row__lead {
  background: none;
}
:is(.dy-histlink, .dy-replies) :is(.ui-row__lead, .ui-row__chevron) svg {
  width: 20px;
  height: 20px;
}
.dy-datebar {
  display: grid;
  grid-template-columns: var(--ui-tap) minmax(0, 1fr) var(--ui-tap);
  align-items: center;
  min-height: var(--ui-tap);
  border: 1px solid var(--ui-rule);
  border-radius: var(--ui-radius);
  background: var(--ui-surface);
}
body.ui-readable .dy-datebar .dc-icon {
  display: grid;
  place-items: center;
  width: var(--ui-tap);
  height: var(--ui-tap);
  min-height: var(--ui-tap);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: var(--ui-radius);
  background: none;
  color: var(--ui-green-dark);
}
.dy-datebar .dc-icon svg {
  width: 20px;
  height: 20px;
}
.dy-datebar .dc-icon:disabled {
  color: #b9c3bd;
}
.dy-prev svg {
  transform: rotate(180deg);
}
.dy-dpick {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--ui-space-3);
  min-height: var(--ui-tap);
  margin: 0;
  font-weight: 600;
  cursor: pointer;
}
.dy-dpick svg {
  width: 20px;
  height: 20px;
  flex: none;
}
body.ui-readable .dy-dpick input[type='date'] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  cursor: pointer;
}
.dy-dpick:focus-within {
  outline: 2px solid var(--ui-focus);
  outline-offset: -2px;
  border-radius: var(--ui-radius);
}
.dy-hint,
.dy-pnote,
.dy-note {
  margin: var(--ui-space-3) 0;
  color: var(--ui-muted);
  font-size: var(--ui-caption);
}
.dy-pnote {
  padding: var(--ui-space-3) var(--ui-space-5);
  border-radius: var(--ui-radius-sm);
  background: var(--ui-amber-bg);
  color: var(--ui-amber);
}
.dy-note {
  margin: var(--ui-space-3) 0 0;
}
.dy-note.is-warn {
  color: var(--ui-amber);
  font-weight: 600;
}
.dy-list {
  overflow: hidden;
}
.dy-fields {
  display: contents;
}
.dy-group > .ui-group__head > span:first-of-type {
  min-width: 0;
}
.dy-group__body {
  padding: var(--ui-space-4) var(--ui-row-pad-x) var(--ui-space-5);
  border-top: 1px solid var(--ui-rule-soft);
}
.dy-group + .dy-group > .ui-group__head,
.dy-fields + .ui-group > .ui-group__head,
.dy-group + .dy-fields > .dy-group:first-child > .ui-group__head {
  border-top: 1px solid var(--ui-rule-soft);
}

/* Утренний вес */
.dy-weight {
  display: grid;
  gap: var(--ui-space-2);
}
.dy-weight > label {
  margin: 0;
  font-weight: 400;
  color: var(--ui-muted);
  font-size: var(--ui-caption);
}
.dy-unit {
  display: flex;
  align-items: center;
  gap: var(--ui-space-4);
}
body.ui-readable .dy-unit input {
  width: 9.5em;
  max-width: 60%;
  min-height: 48px;
  margin: 0;
  font-size: var(--ui-card);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.dy-unit span {
  color: var(--ui-muted);
}
.dy-state {
  display: grid;
  gap: 2px;
  margin-top: var(--ui-space-3);
  color: var(--ui-muted);
  font-size: var(--ui-caption);
}
.dy-state__main {
  display: inline-flex;
  align-items: center;
  gap: var(--ui-space-2);
}
.dy-state__main svg {
  width: 16px;
  height: 16px;
  flex: none;
}
.dy-state__main.is-ok {
  color: var(--ui-green-dark);
}
.dy-state__main.is-wait {
  color: var(--ui-amber);
}
.dy-state__dirty {
  color: var(--ui-amber);
  font-weight: 600;
}
.dy-state__dirty:empty {
  display: none;
}
.dy-state b {
  color: var(--ui-ink);
}

/* Запись за день: вопрос слева, «Да / Нет» справа */
.dy-q {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ui-space-4);
  padding: var(--ui-space-2) 0;
}
.dy-q + .dy-q {
  border-top: 1px solid var(--ui-rule-soft);
}
.dy-q__text {
  min-width: 0;
}
.dy-yn {
  display: flex;
  flex: none;
  gap: var(--ui-space-2);
}
body.ui-readable .dy-yn label {
  position: relative;
  margin: 0;
  font-weight: 400;
  cursor: pointer;
}
.dy-yn input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.dy-yn span {
  display: grid;
  place-items: center;
  min-width: 56px;
  min-height: var(--ui-tap);
  padding: 0 var(--ui-space-4);
  border: 1px solid var(--ui-rule);
  border-radius: var(--ui-radius);
  background: var(--ui-surface);
  font-size: var(--ui-control);
}
.dy-yn input:checked + span {
  border-color: var(--ui-green-dark);
  background: var(--ui-green-dark);
  color: #fff;
  font-weight: 600;
}
.dy-yn input:focus-visible + span {
  outline: 2px solid var(--ui-focus);
  outline-offset: 2px;
}
.dy-yn input:disabled + span {
  cursor: default;
  opacity: 0.7;
}
.dy-sub {
  display: grid;
  font-weight: 400;
  gap: var(--ui-space-2);
  margin: var(--ui-space-3) 0 0;
  color: var(--ui-muted);
  font-size: var(--ui-caption);
}
.dy-sub[hidden] {
  display: none;
}
body.ui-readable .dy-sub input {
  width: 100%;
  margin: 0;
  font-size: var(--ui-control);
  color: var(--ui-ink);
}

/* Самочувствие */
.dy-cap {
  display: block;
  font-weight: 400;
  margin: 0 0 var(--ui-space-3);
  color: var(--ui-muted);
  font-size: var(--ui-caption);
}
body.ui-readable .dy textarea {
  width: 100%;
  min-height: 110px;
  margin: 0;
  font-size: var(--ui-control);
  line-height: var(--ui-leading);
  resize: vertical;
}
.dy-meta {
  display: flex;
  justify-content: space-between;
  gap: var(--ui-space-4);
  margin-top: var(--ui-space-2);
  color: var(--ui-muted);
  font-size: var(--ui-caption);
}

/* Фото */
.dy-thumbs,
.dy-thumbs #diary-photos {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ui-space-3);
}
.dy-thumb {
  position: relative;
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  overflow: hidden;
  border-radius: var(--ui-radius-sm);
  background: var(--ui-surface-soft);
}
.dy-thumb img {
  width: 76px;
  height: 76px;
  object-fit: cover;
  display: block;
}
body.ui-readable .dy-thumb .dc-icon {
  position: absolute;
  top: 2px;
  right: 2px;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  min-height: 30px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ui-ink);
}
.dy-thumb .dc-icon svg {
  width: 16px;
  height: 16px;
}
.dy-thumb--add {
  margin: 0;
  border: 1px dashed var(--ui-rule);
  color: var(--ui-green-dark);
  cursor: pointer;
  align-content: center;
  gap: 2px;
}
.dy-thumb--add svg {
  width: 22px;
  height: 22px;
}
.dy-thumb--add small {
  font-size: var(--ui-caption);
}
.dy-file {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.dy-thumb--add:focus-within {
  outline: 2px solid var(--ui-focus);
}

/* Замеры */
.dy-mgrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--ui-space-4);
}
@media (min-width: 520px) {
  .dy-mgrid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
.dy-mfield {
  display: grid;
  font-weight: 400;
  gap: var(--ui-space-2);
  margin: 0;
  color: var(--ui-muted);
  font-size: var(--ui-caption);
}
body.ui-readable .dy-mfield input {
  width: 100%;
  margin: 0;
  font-size: var(--ui-control);
  color: var(--ui-ink);
}

/* Исправления «было → стало» и прежние ответы — внутри списка формы */
.dy-list > .diary-changes {
  margin: 0;
  border: 0;
  border-top: 1px solid var(--ui-rule-soft);
  border-radius: 0;
}
.dy-replies {
  margin-top: var(--ui-space-4);
}
.dy-dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: 86vh;
  padding: 0;
  border: 0;
  border-radius: var(--ui-radius-lg);
}
.dy-dialog::backdrop {
  background: rgba(20, 30, 25, 0.4);
}
.dy-dialog header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ui-space-4);
  padding: var(--ui-space-3) var(--ui-space-3) 0 var(--ui-space-6);
}
.dy-dialog h2 {
  margin: 0;
  font-size: var(--ui-card);
}
body.ui-readable .dy-dialog .dc-icon {
  display: grid;
  place-items: center;
  width: var(--ui-tap);
  height: var(--ui-tap);
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ui-green-dark);
}
.dy-dialog .dc-icon svg {
  width: 22px;
  height: 22px;
}
.dy-dialog .dc-dialog-body {
  padding: var(--ui-space-3) var(--ui-space-6) var(--ui-space-6);
}

/* ---------- Страница «История дневника и питания» ---------- */
.dy-back {
  display: inline-flex;
  align-items: center;
  gap: var(--ui-space-2);
  min-height: var(--ui-tap);
  color: var(--ui-green-dark);
  font-weight: 600;
  text-decoration: none;
}
.dy-back svg {
  width: 20px;
  height: 20px;
  transform: rotate(180deg);
}
.dy-history .diary-history .pagehead {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--ui-space-3) var(--ui-space-4);
  margin: 0 0 var(--ui-space-4);
}
body.ui-readable .dy-history .diary-history .pagehead h1 {
  margin: 0;
  font-size: var(--ui-section);
  font-weight: 600;
  line-height: var(--ui-leading);
}
.dy-history .diary-history .pagehead p {
  margin: var(--ui-space-1) 0 0;
}
.diary-history .history-tools {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ui-space-3);
}
.diary-history .history-unit {
  display: none;
}
body.ui-readable .diary-history .history-date-short,
body.ui-readable .diary-history .history-cell-badges {
  display: none;
}
@media (min-width: 761px) {
  .diary-history .history-filter-open {
    display: none !important;
  }
  /* Отдельная страница клиента: таблица не сжимается до переносов посреди слов, её можно прокрутить вбок
     (вторая полоса прокрутки — над таблицей), колонку «Дата» видно всегда; ширину колонок меняют границы заголовков. */
  .dy-history .diary-history-table {
    min-width: 1500px !important;
  }
}

/* Телефон: строками по дням (макет), заголовков и ширины колонок нет — они только на компьютере. */
@media (max-width: 760px) {
  .diary-history .history-horizontal-scroll,
  .diary-history .history-resize-handle {
    display: none !important;
  }
  body.ui-readable .diary-history .history-table-scroll {
    overflow: visible;
    border: 1px solid var(--ui-rule);
    border-radius: var(--ui-radius);
    background: var(--ui-surface);
  }
  body.ui-readable .diary-history .diary-history-table {
    display: block;
    width: 100% !important;
    min-width: 0 !important;
    table-layout: auto !important;
    font-size: var(--ui-caption);
  }
  .diary-history .diary-history-table :is(thead, colgroup) {
    display: none !important;
  }
  body.ui-readable .diary-history .diary-history-table tbody {
    display: block;
    margin: 0;
    border: 0 !important;
    border-radius: 0;
    background: none;
  }
  body.ui-readable .diary-history .diary-history-table tbody + tbody {
    border-top: 1px solid var(--ui-rule-soft) !important;
  }
  .diary-history .diary-history-table tbody[hidden],
  .diary-history .diary-history-table td[hidden],
  .diary-history .diary-history-table tr[hidden] {
    display: none !important;
  }
  body.ui-readable .diary-history .history-overview {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 1px var(--ui-space-4);
    padding: var(--ui-space-4) var(--ui-space-3) var(--ui-space-4) 62px;
  }
  body.ui-readable .diary-history .history-overview > td {
    display: block;
    width: auto;
    min-width: 0;
    padding: 0;
    border: 0;
    background: none;
    position: static;
    color: var(--ui-ink);
    font-weight: 400;
    font-size: var(--ui-caption);
    line-height: var(--ui-leading);
  }
  .diary-history .history-overview > td[data-label]::before {
    content: attr(data-label) ': ';
    display: inline;
    margin: 0;
    color: var(--ui-muted);
    font-size: inherit;
  }
  .diary-history .history-overview > td :is(p, div, span, small) {
    display: inline;
    margin: 0;
  }
  .diary-history .history-overview > td .pill {
    padding: 0;
    background: none;
    border: 0;
    color: inherit;
    font-size: inherit;
  }
  /* Дата — слева колонкой */
  body.ui-readable .diary-history .history-overview > .history-cell-date {
    position: absolute;
    left: var(--ui-space-4);
    top: var(--ui-space-4);
    width: 46px;
  }
  body.ui-readable .diary-history .history-cell-date .history-date-full {
    display: none;
  }
  body.ui-readable .diary-history .history-cell-date .history-date-short {
    display: grid;
  }
  .diary-history .history-cell-date .history-date-short b {
    font-size: var(--ui-body);
  }
  .diary-history .history-cell-date .history-date-short small {
    color: var(--ui-muted);
    font-size: var(--ui-caption);
  }
  .diary-history .history-cell-date .diary-change-badge {
    display: none !important;
  }
  /* «Заполнен · 84,1 кг» — первой строкой жирно; изменение веса и самочувствие — своими строками */
  .diary-history .history-overview > td:is(.history-cell-date, [data-history-column='diary'], [data-history-column='delta'], [data-history-column='details'])::before {
    content: none !important;
    display: none !important;
  }
  body.ui-readable .diary-history .history-overview > td:is([data-history-column='diary'], [data-history-column='weight']) {
    font-size: var(--ui-body);
    font-weight: 600;
  }
  body.ui-readable .diary-history .history-overview > td.history-empty {
    display: none;
  }
  .diary-history .history-overview > td[data-history-column='weight'] {
    margin-left: -0.35em;
  }
  .diary-history .history-overview > td[data-history-column='weight']::before {
    content: '· ' !important;
    display: inline !important;
    color: var(--ui-ink) !important;
  }
  .diary-history .history-unit {
    display: inline;
  }
  .diary-history .history-overview > :is([data-history-column='delta'], [data-history-column='health']) {
    flex-basis: 100%;
  }
  .diary-history .history-overview > [data-history-column='health'] .history-symptoms > span {
    padding: 0;
    background: none;
  }
  .diary-history .history-overview > [data-history-column='health'] .history-symptoms > span + span::before {
    content: ', ';
  }
  body.ui-readable .diary-history .history-overview > td[data-history-column='details'] {
    display: flex !important;
    justify-content: flex-end;
    flex-basis: 100%;
  }
  .diary-history .history-overview > [data-history-column='details']::before {
    display: none;
  }
  body.ui-readable .diary-history .history-overview > [data-history-column='details'] button {
    width: auto !important;
    min-height: 36px;
    padding: 0 var(--ui-space-2);
    border: 0;
    background: none;
    color: var(--ui-green-dark);
    font-size: var(--ui-caption);
    font-weight: 600;
    text-decoration: underline;
  }
  .diary-history .history-overview .history-warning {
    color: var(--ui-red);
    font-weight: 600;
  }
  /* Порядок в строке: «Заполнен · 84,1 кг», ярлыки «Исправлено · N» / «Изменено на день · N», остальное. */
  .diary-history .history-overview > :is([data-history-column='diary'], [data-history-column='weight']) {
    order: -2;
  }
  body.ui-readable .diary-history .history-overview > .history-cell-badges {
    display: flex !important;
    flex-wrap: wrap;
    gap: var(--ui-space-2);
    flex-basis: 100%;
    order: -1;
  }
  .diary-history .history-overview > .history-cell-badges .diary-change-badge {
    display: inline-block !important;
  }
  body.ui-readable .diary-history .history-detail-row,
  body.ui-readable .diary-history .history-detail-row > td {
    display: block;
    width: 100%;
  }
  body.ui-readable .diary-history .history-detail-row > td {
    padding: var(--ui-space-4);
    border-top: 1px solid var(--ui-rule-soft);
    background: var(--ui-surface-soft);
  }
  .diary-history .history-detail-viewport {
    width: auto !important;
    max-width: 100%;
  }
  .diary-history .history-detail-grid {
    grid-template-columns: 1fr !important;
  }
  .diary-history .history-bottom {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }
}
