/* Письма — проект и переписка по объектам (src/letters.js).

   Строится поверх общего шаблона раздела (page.css): та же полоса сверху,
   то же поле --gut, та же прокрутка одного тела. Своё здесь — строки-
   карточки вместо таблиц: у мастера телефон, и колонки таблицы на нём не
   читаются, а крупная строка с одним главным словом — читается. */

.lt-page { --lt-row: 64px; }
.lt-body { overscroll-behavior: contain; }

/* ── полоса сверху ────────────────────────────────────────── */
.pg-head.lt-head { gap: 9px; }
.lt-find { flex: 1; min-width: 0; }
.lt-find input { width: 100%; max-width: 380px; }
.lt-head .btn-brand { flex: none; }

.pg-head.strip.lt-top { min-height: 56px; }
.lt-top .lt-h1 { flex: 1 1 auto; flex-direction: column; align-items: flex-start; gap: 1px;
  padding-right: 8px; }
.lt-top .lt-h1 h2 { max-width: 100%; }
.lt-top .lt-h1 > i {
  font-style: normal; font-size: 11px; color: var(--ink3);
  max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lt-crumb {
  padding: 0; border: 0; background: none; cursor: pointer;
  font: inherit; font-size: 11px; color: var(--ink3);
  max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lt-crumb:hover { color: var(--brand-deep); }
.lt-top .lt-edit { flex: none; align-self: center; width: 32px; height: 32px; }

.lt-hint {
  padding: 11px var(--gut); border-bottom: 1px solid var(--line2);
  background: var(--raise); font-size: 11.5px; color: var(--ink2); line-height: 1.5;
}
.lt-hint b { color: var(--ink); }

/* ── строки: объекты и письма ─────────────────────────────── */
.lt-list { display: flex; flex-direction: column; }
.lt-row {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: var(--lt-row);
  padding: 12px var(--gut);
  border: 0; border-bottom: 1px solid var(--line2);
  background: none; color: inherit; font: inherit; text-align: left;
  cursor: pointer;
  transition: background .15s var(--ease);
}
.lt-row:hover { background: var(--raise); }
.lt-row:active { background: var(--box-bg-h); }
.lt-row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.lt-row-main > b {
  font-size: 13px; font-weight: 600; color: var(--ink); line-height: 1.35;
  overflow-wrap: anywhere;
}
.lt-row:hover .lt-row-main > b { color: var(--brand-deep); }
.lt-row-main > i {
  font-style: normal; font-size: 11px; color: var(--ink3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lt-row-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 5px 10px; margin-top: 3px; }
.lt-go { flex: none; color: var(--ink4); display: grid; place-items: center; }
.lt-go svg, .lt-cnt svg, .lt-st svg, .lt-dir svg, .lt-block-h h3 svg, .lt-file-ico svg,
.lt-chip svg, .lt-av svg, .lt-attach svg, .lt-more svg, .lt-pickb svg, .lt-dirseg svg {
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.lt-go svg { width: 16px; height: 16px; }
.lt-row:hover .lt-go { color: var(--brand); }

.lt-cnt { display: inline-flex; align-items: center; gap: 3.5px; font-size: 11px; color: var(--ink3);
  font-variant-numeric: tabular-nums; }
.lt-cnt svg { width: 13px; height: 13px; }

/* Состояние письма — главное слово строки. Цвет — сколько ждём. */
.lt-st {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1.5px 8px; border-radius: 999px;
  font-size: 10.5px; font-weight: 600; line-height: 16px; white-space: nowrap;
}
.lt-st svg { width: 11px; height: 11px; stroke-width: 2.6; }
.lt-st.info { background: var(--info-soft); color: var(--info); }
.lt-st.warn { background: var(--warn-soft); color: var(--warn); }
.lt-st.bad { background: var(--bad-soft); color: var(--bad); }
.lt-st.done { background: var(--ok-soft); color: var(--ok); }

/* Кто кому: наше исходящее — фирменным, входящее — синим. */
.lt-dir {
  flex: none; display: inline-grid; place-items: center;
  width: 30px; height: 30px; border-radius: 999px;
}
.lt-dir svg { width: 15px; height: 15px; stroke-width: 2.2; }
.lt-dir.out { background: var(--brand-tint); color: var(--brand-deep); }
.lt-dir.in { background: var(--info-soft); color: var(--info); }
.lt-let { align-items: flex-start; }
.lt-let .lt-dir { margin-top: 1px; }
.lt-let .lt-go { align-self: center; }
.lt-let.closed .lt-row-main > b { font-weight: 500; color: var(--ink2); }
.lt-let.closed .lt-dir { filter: grayscale(1); opacity: .6; }
.lt-last {
  margin-top: 2px; font-size: 11px; color: var(--ink2); line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.lt-last b { font-weight: 600; color: var(--ink); }

/* ── блоки объекта ────────────────────────────────────────── */
.lt-block { padding-bottom: 8px; }
.lt-block + .lt-block { border-top: 6px solid var(--raise); }
.lt-block-h {
  display: flex; align-items: center; gap: 10px;
  padding: 14px var(--gut) 10px;
}
.lt-block-h h3 {
  flex: 1; min-width: 0; margin: 0;
  display: flex; align-items: center; gap: 8px;
  font-size: 13.5px; font-weight: 600; color: var(--ink); letter-spacing: -.01em;
}
.lt-block-h h3 svg { width: 16px; height: 16px; color: var(--ink3); flex: none; }
.lt-block-h h3 i {
  font-style: normal; font-weight: 500; font-size: 11px; color: var(--ink3);
  padding: 0 6px; border-radius: 999px; background: var(--raise); line-height: 17px;
}
.lt-empty {
  padding: 2px var(--gut) 14px; max-width: 64ch;
  font-size: 11.5px; line-height: 1.55; color: var(--ink3);
}
.lt-seg { margin: 0 var(--gut) 8px; }
.lt-seg .seg-b i { font-style: normal; margin-left: 5px; color: var(--ink3); font-weight: 500; }

/* Файлы проекта: значок, что это и кто положил, действия. */
.lt-files { border-top: 1px solid var(--line2); }
.lt-file {
  display: flex; align-items: center; gap: 10px;
  padding: 8px var(--gut);
  border-bottom: 1px solid var(--line2);
}
.lt-file:last-child { border-bottom: 0; }
.lt-file-ico {
  flex: none; display: grid; place-items: center;
  width: 32px; height: 32px; border-radius: 9px;
  background: var(--raise); color: var(--ink3);
}
.lt-file-ico svg { width: 17px; height: 17px; stroke-width: 1.8; }
.lt-file:first-child .lt-file-ico { background: var(--brand-tint); color: var(--brand-deep); }
.lt-file-main {
  flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px;
  padding: 2px 0; border: 0; background: none; cursor: pointer;
  font: inherit; text-align: left; color: inherit;
}
.lt-file-main b {
  font-size: 12.5px; font-weight: 600; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lt-file-main:hover b { color: var(--brand-deep); text-decoration: underline; }
.lt-file-main i {
  font-style: normal; font-size: 11px; color: var(--ink3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lt-file-main i em { font-style: normal; color: var(--brand-deep); }
.lt-file-main .lt-file-name { color: var(--ink4); font-size: 10.5px; }
.lt-file-acts { flex: none; display: flex; gap: 2px; }
.lt-file-acts .ico { width: 30px; height: 30px; }
.lt-more {
  display: block; width: calc(100% - 2 * var(--gut)); margin: 0 var(--gut) 8px;
  padding: 7px 10px; border: 1px dashed var(--line); border-radius: 9px;
  background: none; cursor: pointer; font: inherit; font-size: 11px; color: var(--ink2);
}
.lt-more:hover { border-color: var(--brand); color: var(--brand-deep); }

/* ── письмо ───────────────────────────────────────────────── */
.lt-sum {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px;
  padding: 12px var(--gut);
  border-bottom: 1px solid var(--line2); background: var(--raise);
}
.lt-facts {
  flex: 1 1 360px; min-width: 0; margin: 0;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: 8px 18px;
}
.lt-facts dt {
  font: 600 9px var(--sans); letter-spacing: .07em; text-transform: uppercase; color: var(--ink3);
}
.lt-facts dd {
  margin: 3px 0 0; display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--ink);
}
.lt-facts .lt-dir { width: 22px; height: 22px; }
.lt-facts .lt-dir svg { width: 12px; height: 12px; }
.pg .btn-ghost.lt-close { flex: none; height: 34px; background: var(--card); }
@media (hover: hover) { #ltClose:hover { color: var(--ok); border-color: var(--ok); } }
/* Тему письма читают целиком: две строки, а не обрезок в одну. */
.lt-card .lt-top .lt-h1 h2 {
  white-space: normal; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.lt-card .pg-head.strip.lt-top { padding-top: 8px; padding-bottom: 8px; }

.lt-feed { padding: 6px var(--gut) 16px; }
.lt-item {
  display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 11px;
  padding: 10px 0;
}
.lt-item + .lt-item { border-top: 1px solid var(--line2); }
.lt-av {
  display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 999px;
  background: var(--raise); color: var(--ink2);
  font-size: 12px; font-weight: 600;
}
.lt-av svg { width: 14px; height: 14px; stroke-width: 2.4; }
.lt-item.sys .lt-av { background: none; color: var(--ink4); border: 1px dashed var(--line); }
.lt-item.sys .lt-av svg { fill: currentColor; stroke: none; width: 9px; height: 9px; }
.lt-item.status .lt-av { background: var(--ok-soft); color: var(--ok); }
.lt-item-h { display: flex; align-items: baseline; gap: 8px; min-height: 18px; }
.lt-item-h b { font-size: 12px; font-weight: 600; color: var(--ink); }
.lt-item-h time { font-size: 10.5px; color: var(--ink3); white-space: nowrap; }
.lt-item-h .lt-del { margin-left: auto; align-self: center; width: 26px; height: 26px; opacity: 0;
  transition: opacity .15s var(--ease); }
.lt-item:hover .lt-del, .lt-del:focus-visible { opacity: 1; }
@media (hover: none) { .lt-item-h .lt-del { opacity: .7; } }
.lt-item p {
  margin: 3px 0 0; font-size: 12.5px; line-height: 1.5; color: var(--ink);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.lt-item p.lt-sys { color: var(--ink2); }
.lt-item.status p.lt-sys { color: var(--ok); font-weight: 500; }
.lt-chip {
  display: inline-flex; align-items: center; gap: 8px; max-width: 100%;
  margin-top: 6px; padding: 8px 12px 8px 10px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--ink); cursor: pointer; font: inherit; text-align: left;
  transition: border-color .15s var(--ease), background .15s var(--ease);
}
.lt-chip:hover { border-color: var(--brand); background: var(--brand-tint); }
.lt-chip svg { width: 17px; height: 17px; flex: none; color: var(--brand-deep); stroke-width: 1.8; }
.lt-chip b { min-width: 0; font-size: 12px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lt-chip i { flex: none; font-style: normal; font-size: 10.5px; color: var(--ink3); }

/* Поле записи — прижато к низу раздела, как в мессенджере. */
.lt-compose {
  flex: none; display: flex; align-items: flex-end; gap: 8px;
  padding: 10px var(--gut) calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line2); background: var(--card);
}
.lt-compose textarea {
  flex: 1; min-width: 0; min-height: 38px; max-height: 160px; resize: none;
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 11px;
  background: var(--raise); color: var(--ink);
  font: 400 12.5px/1.45 var(--sans); outline: none;
  transition: border-color .15s var(--ease), background .15s var(--ease);
}
.lt-compose textarea:focus { border-color: var(--brand); background: var(--card); }
.lt-attach {
  flex: none; display: grid; place-items: center;
  width: 38px; height: 38px; border-radius: 11px;
  border: 1px solid var(--line); color: var(--ink2); cursor: pointer;
  transition: .15s var(--ease);
}
.lt-attach:hover { border-color: var(--brand); color: var(--brand-deep); background: var(--brand-tint); }
.lt-attach svg { width: 18px; height: 18px; }
.pg .btn-brand.lt-send { flex: none; height: 38px; border-radius: 11px; }

/* Загрузки: полоса на файл. */
.lt-queue {
  display: flex; flex-direction: column; gap: 6px;
  padding: 9px var(--gut); border-bottom: 1px solid var(--line2); background: var(--raise);
}
.lt-card .lt-queue { border-top: 1px solid var(--line2); }
.lt-q {
  display: grid; grid-template-columns: minmax(0, 1fr) 110px auto; gap: 4px 10px;
  align-items: center; font-size: 11px;
}
.lt-q-name { color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lt-q-bar { height: 4.5px; border-radius: 3px; background: var(--line2); overflow: hidden; }
.lt-q-bar i { display: block; height: 100%; background: var(--brand); transition: width .3s linear; }
.lt-q-st { color: var(--ink3); white-space: nowrap; text-align: right; }
.lt-q.bad .lt-q-name, .lt-q-err { color: var(--bad); }
.lt-q-err { grid-column: 2 / -1; text-align: right; }
.lt-queue #ltQClear { align-self: flex-start; margin-left: -7px; }

/* ── окна ─────────────────────────────────────────────────── */
.lt-form { display: flex; flex-direction: column; gap: 11px; width: min(470px, 94vw); }
.lt-form h3 { margin: 0 0 2px; font-size: 14.5px; }
.lt-form .fld textarea { resize: vertical; }
.lt-form .pf-modal-foot { margin-top: 4px; }
.lt-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.lt-form-err {
  padding: 8px 11px; border-radius: 9px;
  background: var(--bad-soft); color: var(--bad); font-size: 11.5px;
}
.lt-form-err[hidden] { display: none; }
.lt-dirseg { display: flex; width: 100%; }
.lt-dirseg .seg-b {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 10px; cursor: pointer; font-size: 12px;
}
.lt-dirseg .seg-b svg { width: 14px; height: 14px; }
.lt-dirseg .seg-b.on:first-child { color: var(--brand-deep); background: var(--brand-tint); }
.lt-dirseg .seg-b.on:last-child { color: var(--info); background: var(--info-soft); }
.lt-pickb {
  display: inline-flex; align-items: center; gap: 7px; width: fit-content;
  padding: 8px 13px; cursor: pointer; font-size: 12px;
}
.lt-pickb svg { width: 15px; height: 15px; }
.lt-pickf [data-picked] { display: block; margin-top: 5px; overflow-wrap: anywhere; }
.lt-presets { display: flex; flex-wrap: wrap; gap: 6px; }
.lt-preset {
  padding: 6px 11px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--card); color: var(--ink2); cursor: pointer; font: inherit; font-size: 11.5px;
}
.lt-preset:hover { border-color: var(--ink3); color: var(--ink); }
.lt-preset.on { border-color: var(--ok); background: var(--ok-soft); color: var(--ok); }
.lt-danger { display: inline-flex; align-items: center; gap: 5px; color: var(--bad) !important; }
.lt-danger svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; }

/* ── телефон ──────────────────────────────────────────────────
   Поля уже, строки крупнее, окна встают снизу во всю ширину — до кнопок
   дотягивается большой палец. Шрифт в полях — 16px: на меньшем iPhone
   сам увеличивает страницу при вводе, и она так и остаётся увеличенной. */
/* Кнопка главного действия внизу экрана — «Новое письмо», «Загрузить». */
.lt-foot {
  flex: none; padding: 10px var(--gut) calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line2); background: var(--card);
}
.pg .lt-foot .btn-brand { width: 100%; height: 44px; border-radius: 12px; font-size: 13.5px;
  font-weight: 600; }
.pg .lt-foot .btn-brand svg { width: 16px; height: 16px; }
.lt-sub { font-size: 11.5px; color: var(--ink3); line-height: 1.4; }
.lt-proj .lt-file-ico { background: var(--brand-tint); color: var(--brand-deep); }
.lt-empty-top { padding-top: 16px; }

@media (max-width: 684px) {
  .lt-page { --gut: 14px; --lt-row: 52px; }
  /* Первые экраны — только главное: название и состояние. Номер, дата,
     заказчик, счётчики и последняя запись — внутри письма. */
  .lt-row { gap: 10px; padding: 10px var(--gut); }
  .lt-row-main { gap: 4px; }
  .lt-row-main > b { font-size: 14px; }
  .lt-row-main > i, .lt-cnt, .lt-last, .lt-hint, .lt-top .lt-h1 > i { display: none; }
  .lt-row-meta { margin-top: 0; }
  .lt-row-meta:not(:has(.lt-st)) { display: none; }
  .lt-dir { width: 26px; height: 26px; }
  .lt-dir svg { width: 13px; height: 13px; }
  .lt-let .lt-dir { margin-top: 0; }
  .lt-let { align-items: center; }
  .lt-block-h { padding: 12px var(--gut) 8px; }
  .lt-block-h h3 { font-size: 13px; }
  .lt-block + .lt-block, .lt-proj + .lt-block { border-top: 6px solid var(--raise); }
  .lt-proj { border-bottom: 0; }
  .lt-seg .seg-b { padding: 5px 11px; font-size: 12px; }
  .lt-file { padding: 9px var(--gut); }
  .lt-file-main .lt-file-name { display: none; }
  /* Письмо: карточка одной строкой без подписей. */
  .lt-sum { padding: 10px var(--gut); gap: 8px; }
  .lt-facts { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; }
  .lt-facts dt { display: none; }
  .lt-facts dd { margin: 0; font-size: 12.5px; color: var(--ink2); }
  .lt-item { grid-template-columns: 26px minmax(0, 1fr); gap: 9px; padding: 9px 0; }
  .lt-av { width: 26px; height: 26px; font-size: 11px; }
  .lt-item p { font-size: 13.5px; }
  .lt-item-h .lt-del { display: none; }
  .lt-item.sel .lt-item-h .lt-del { display: grid; opacity: 1; }
  .lt-item.sel { background: var(--raise); margin: 0 calc(-1 * var(--gut)); padding-left: var(--gut);
    padding-right: var(--gut); }
  .lt-file-acts .ico.warn { display: none; }
  .lt-find input { max-width: none; }
  .lt-head .btn-brand span { display: none; }
  .lt-head .btn-brand { width: 36px; padding: 0; }
  .lt-head .btn-brand svg { width: 16px; height: 16px; }
  .pg-head.strip.lt-top { padding: 0 10px 0 var(--gut); }
  .lt-top .lt-h1 h2 {
    font-size: 14.5px; white-space: normal; line-height: 1.3;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  }
  .pg-head.strip.lt-top { padding-top: 8px; padding-bottom: 8px; min-height: 52px; }
  .lt-block-h .btn-ghost.sm span { display: none; }
  .lt-block-h .btn-ghost.sm, .lt-block-h .btn-brand.sm { height: 34px; min-width: 38px; }
  .lt-block-h .btn-brand.sm span { display: inline; }
  .lt-sum { gap: 10px; }
  .pg .btn-ghost.lt-close { width: 100%; height: 36px; }
  .pg .btn-brand.lt-send { width: 42px; padding: 0; }
  .pg .btn-brand.lt-send span { display: none; }
  .pg .btn-brand.lt-send svg { width: 18px; height: 18px; }
  .lt-compose { gap: 7px; padding-left: 10px; padding-right: 10px; }
  .lt-q { grid-template-columns: minmax(0, 1fr) 70px; }
  .lt-q-st, .lt-q-err { grid-column: 1 / -1; text-align: left; }
  .lt-compose textarea { font-size: 13.5px; }
  .lt-form input, .lt-form textarea, .lt-form select { font-size: 13.5px; }
  .lt-modal { align-items: flex-end; padding: 0; }
  .lt-form {
    width: 100%; max-width: 100%; max-height: 92vh; overflow-y: auto;
    border-radius: 18px 18px 0 0;
    padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  }
  .lt-form .pf-modal-foot .btn { height: 42px; padding: 0 18px; }
}
