/* Приложение Пинга (D-097): текст для долгого чтения, сонар — знак Пинга. */

/* Палитра — нейтральная (владелец, 2026-11-13): графит и бумага, без цветного акцента. Главная кнопка — цвет текста.
   Зелёный остался только у точки «на связи». */
:root {
  color-scheme: dark;
  --bg: #171717;
  --side: #111111;
  --surface: #1f1f1f;
  --raised: #262626;
  --line: #2e2e2e;
  --text: #ececec;
  --dim: #a0a0a0;
  --faint: #6e6e6e;
  --accent: #ececec;
  --accent-ink: #141414;
  --ok: #4cc38a;
  --warn: #e0b050;
  --error: #f27474;
  --code-bg: #1c1c1c;
  --shadow: 0 12px 40px rgb(0 0 0 / .5);
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --read: 46rem;
}
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #ffffff;
    --side: #f7f7f5;
    --surface: #ffffff;
    --raised: #efefec;
    --line: #e3e3df;
    --text: #1a1a1a;
    --dim: #686868;
    --faint: #9b9b9b;
    --accent: #1a1a1a;
    --accent-ink: #ffffff;
    --ok: #1f9d63;
    --warn: #8a6100;
    --error: #c0352b;
    --code-bg: #f6f6f3;
    --shadow: 0 12px 40px rgb(0 0 0 / .12);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.55 var(--sans); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  overflow: hidden; overscroll-behavior: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
::selection { background: color-mix(in srgb, var(--text) 22%, transparent); }
kbd { font: 11px var(--mono); color: var(--faint); }

/* Сонар: точка и расходящиеся дуги. Спокойный — знак, .live — Пинг думает. */
.sonar { position: relative; width: 22px; height: 16px; flex: none; }
.sonar i { position: absolute; top: 50%; left: 3px; border-radius: 50%; translate: -50% -50%; }
.sonar i:nth-child(1) { width: 5px; height: 5px; background: var(--text); }
.sonar i:nth-child(2), .sonar i:nth-child(3) {
  border: 1.5px solid transparent; border-right-color: var(--text);
}
.sonar i:nth-child(2) { width: 16px; height: 16px; }
.sonar i:nth-child(3) { width: 28px; height: 28px; opacity: .55; }
.sonar.live i:nth-child(2) { animation: ping 1.4s ease-out infinite; }
.sonar.live i:nth-child(3) { animation: ping 1.4s ease-out .25s infinite; }
@keyframes ping { 0% { opacity: 0; scale: .5; } 35% { opacity: 1; } 100% { opacity: 0; scale: 1.25; } }
.sonar-big { width: 66px; height: 48px; margin: 0 auto 18px; }
.sonar-big i { left: 9px; }
.sonar-big i:nth-child(1) { width: 14px; height: 14px; }
.sonar-big i:nth-child(2) { width: 48px; height: 48px; border-width: 4px; }
.sonar-big i:nth-child(3) { width: 84px; height: 84px; border-width: 4px; }
@media (prefers-reduced-motion: reduce) { .sonar.live i { animation: none; } * { scroll-behavior: auto !important; } }

/* Кнопки */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 20px;
  border-radius: 12px; font-weight: 600; width: 100%; transition: background .15s, opacity .15s;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, var(--text)); }
.btn-quiet { color: var(--dim); font-weight: 500; }
.btn-quiet:hover { color: var(--text); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-text { color: var(--faint); font-size: 13px; padding: 6px 4px; }
.btn-text:hover { color: var(--text); }
.icon-btn {
  width: 38px; height: 38px; flex: none; display: grid; place-items: center; border-radius: 10px; color: var(--dim);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--raised); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.on { color: var(--accent); }
.icon-btn-primary { background: var(--accent); color: var(--accent-ink); }
.icon-btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, var(--text)); color: var(--accent-ink); }
.icon-btn:disabled { opacity: .35; cursor: default; }

/* Вход */
.gate { height: 100dvh; display: grid; place-items: center; padding: 24px; }
.gate-card { width: min(100%, 22rem); text-align: center; }
.gate-card h1 { margin: 0 0 6px; font-size: 30px; letter-spacing: -.02em; }
.gate-note { min-height: 1.5em; margin: 0 0 22px; color: var(--dim); font-size: 14px; }
.gate-note.bad { color: var(--error); }
.gate-text { margin: 0 0 16px; color: var(--dim); font-size: 14.5px; text-align: left; }
.gate-step { display: grid; gap: 10px; }
#code-form { display: grid; gap: 10px; }
.code-input {
  height: 54px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); text-align: center;
  font: 600 22px var(--mono); letter-spacing: .12em; text-transform: uppercase;
}
.code-input::placeholder { color: var(--faint); font-weight: 400; }

/* Каркас */
.app { height: 100dvh; display: grid; grid-template-columns: 19rem minmax(0, 1fr); }
.side {
  display: flex; flex-direction: column; min-height: 0; background: var(--side); border-right: 1px solid var(--line);
  padding: max(14px, env(safe-area-inset-top)) 10px max(8px, env(safe-area-inset-bottom));
}
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 8px 14px; }
.brand { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 18px; letter-spacing: -.01em; }
.link-state { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.link-state.up { background: var(--ok); }
.new-chat {
  display: flex; align-items: center; justify-content: space-between; height: 44px; padding: 0 14px; margin: 0 2px 10px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); font-weight: 600; text-align: left;
  transition: border-color .15s;
}
.new-chat:hover { border-color: var(--faint); background: var(--raised); }
.chats { flex: 1; min-height: 0; overflow-y: auto; padding: 0 2px; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.group-head {
  display: flex; align-items: center; justify-content: space-between; padding: 14px 10px 6px;
  font: 600 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--faint);
}
.group-head button { color: var(--faint); width: 24px; height: 24px; border-radius: 6px; display: grid; place-items: center; }
.group-head button:hover { color: var(--text); background: var(--raised); }
.group-head svg { width: 16px; height: 16px; }
.group-empty { padding: 4px 10px 8px; color: var(--faint); font-size: 13px; }
.chat-item {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 9px 10px; border-radius: 10px; text-align: left;
}
.chat-item:hover { background: var(--raised); }
.chat-item.current { background: var(--raised); }
.chat-name { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 14.5px; }
.chat-item.service .chat-name { color: var(--dim); }
.chat-tag { font: 10px var(--mono); color: var(--faint); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
.chat-when { font: 11px var(--mono); color: var(--faint); flex: none; }
.chat-item.unread .chat-when { color: var(--text); }
.chat-item.unread .chat-name { font-weight: 600; }
.chat-item.busy .chat-when { color: var(--dim); }
.more { width: 100%; padding: 8px 10px; color: var(--faint); font-size: 13px; text-align: left; border-radius: 10px; }
.more:hover { color: var(--text); background: var(--raised); }
.name-form { padding: 2px 2px 6px; }
.name-form input {
  width: 100%; height: 38px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--faint); background: var(--surface);
  font-size: 14.5px; outline: none;
}
.side-foot { padding: 6px 8px 0; display: flex; justify-content: space-between; }
.chat-item.renaming { padding: 3px 4px; }
.chat-item.renaming:hover { background: none; }
.chat-item input {
  width: 100%; height: 34px; padding: 0 8px; border-radius: 8px; border: 1px solid var(--faint); background: var(--surface);
  font-size: 14.5px; outline: none; user-select: text;
}
.archive-back { display: flex; align-items: center; gap: 6px; padding: 8px 6px; color: var(--dim); font-size: 14px; border-radius: 10px; }
.archive-back:hover { color: var(--text); }
.archive-back svg { width: 18px; height: 18px; }
.chat-item .restore { font: 11px var(--mono); color: var(--faint); flex: none; }
.chat-item:hover .restore { color: var(--text); }

/* Чат */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.main-head {
  display: flex; align-items: center; gap: 8px; min-height: 58px; border-bottom: 1px solid var(--line);
  padding: max(8px, env(safe-area-inset-top)) 14px 8px 20px;
}
.main-title { flex: 1; min-width: 0; }
.main-title h2 {
  margin: 0; font-size: 16px; font-weight: 650; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.main-title h2.editable { cursor: text; }
.main-title input {
  width: 100%; height: 30px; margin: -3px 0; padding: 0 8px; border-radius: 8px; border: 1px solid var(--faint);
  background: var(--surface); font-size: 16px; font-weight: 650; outline: none;
}
.main-sub { display: block; font: 11px var(--mono); color: var(--faint); }
.main-actions { display: flex; gap: 2px; }
.only-narrow { display: none; }
/* Список чатов можно скрыть: кнопка в шапке или ⌘\ */
@media (min-width: 761px) {
  body[data-side="hidden"] .app { grid-template-columns: minmax(0, 1fr); }
  body[data-side="hidden"] .side { display: none; }
  .main-head { padding-left: 10px; }
}

.feed { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--line) transparent; outline: none; }
.feed-inner { max-width: var(--read); margin: 0 auto; padding: 22px 20px 28px; display: flex; flex-direction: column; gap: 22px; min-height: 100%; }
.hello { margin: auto; text-align: center; color: var(--dim); padding: 40px 0; }
.hello h3 { margin: 0 0 6px; font-size: 22px; color: var(--text); letter-spacing: -.01em; }
.hello p { margin: 0; font-size: 14.5px; }
.day { align-self: center; font: 11px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--faint); }

.msg { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.msg-meta { font: 11px var(--mono); color: var(--faint); letter-spacing: .02em; }
.msg-meta b { font-weight: 600; color: var(--dim); }
.msg.user { align-items: flex-end; }
.msg.user .msg-body {
  max-width: min(85%, 34rem); padding: 10px 14px; border-radius: 16px 16px 4px 16px; background: var(--raised);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.note .msg-body { color: var(--dim); font-size: 14px; }
.msg.note.bad .msg-body { color: var(--error); }
.msg.fresh { animation: rise .25s ease-out; }
@keyframes rise { from { opacity: 0; translate: 0 6px; } }

/* Разметка ответа */
.md { overflow-wrap: anywhere; min-width: 0; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md blockquote, .md pre, .md .table { margin: 0 0 .8em; }
.md h1, .md h2, .md h3, .md h4 { margin: 1.3em 0 .5em; line-height: 1.25; letter-spacing: -.01em; }
.md h1 { font-size: 1.4em; } .md h2 { font-size: 1.22em; } .md h3 { font-size: 1.08em; } .md h4 { font-size: 1em; }
.md ul, .md ol { padding-left: 1.4em; }
.md li { margin: .2em 0; }
.md li::marker { color: var(--faint); }
.md a { color: inherit; text-decoration: underline; text-decoration-color: var(--faint); text-underline-offset: 3px; }
.md a:hover { text-decoration-color: currentColor; }
.md strong { font-weight: 650; }
.md blockquote { padding: 2px 0 2px 14px; border-left: 2px solid var(--line); color: var(--dim); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1.2em 0; }
.md code { font: .875em var(--mono); background: var(--code-bg); border: 1px solid var(--line); border-radius: 5px; padding: .1em .35em; }
.md pre {
  position: relative; background: var(--code-bg); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px;
  overflow-x: auto; line-height: 1.5; scrollbar-width: thin;
}
.md pre code { background: none; border: 0; padding: 0; font-size: 13.5px; }
.copy {
  position: sticky; float: right; top: 0; right: 0; margin: -6px -8px 0 8px; padding: 3px 8px; border-radius: 6px;
  font: 11px var(--mono); color: var(--faint); background: var(--raised); opacity: 0; transition: opacity .15s;
}
.md pre:hover .copy, .copy:focus-visible { opacity: 1; }
.copy:hover { color: var(--text); }
.md .table { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; scrollbar-width: thin; }
/* Слова в ячейках не рвём: узкой таблице тесно — она листается вбок. */
.md table { border-collapse: collapse; width: 100%; font-size: 14.5px; font-variant-numeric: tabular-nums; overflow-wrap: normal; }
.md th, .md td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.md th { font-weight: 600; color: var(--dim); background: var(--surface); white-space: nowrap; }
.md tr:last-child td { border-bottom: 0; }
.md img { max-width: 100%; border-radius: 10px; }

/* Вопрос Руки: «да / нет» */
.ask { border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; background: var(--surface); }
.ask-actions { display: flex; gap: 8px; margin-top: 12px; }
.ask-actions .btn { width: auto; min-height: 38px; padding: 0 18px; border-radius: 10px; }
.ask-no { border: 1px solid var(--line); color: var(--text); font-weight: 500; }
.ask-no:hover { background: var(--raised); }
.ask-done { margin-top: 10px; color: var(--dim); font-size: 14px; }

/* Пинг думает */
.thinking { display: flex; gap: 14px; align-items: flex-start; padding: 2px 0 2px 4px; }
.thinking .sonar { margin-top: 4px; }
.steps { font: 12.5px/1.7 var(--mono); color: var(--faint); min-width: 0; overflow-wrap: anywhere; }
.steps div:last-child { color: var(--dim); }

/* Поле ввода */
.composer { padding: 0 16px max(14px, env(safe-area-inset-bottom)); }
.composer-box {
  max-width: var(--read); margin: 0 auto; display: flex; align-items: flex-end; gap: 4px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px; transition: border-color .15s;
}
.composer-box:focus-within { border-color: var(--faint); }
.composer textarea {
  flex: 1; min-width: 0; resize: none; border: 0; outline: none; background: none; padding: 8px 8px 8px 10px;
  max-height: 40dvh; line-height: 1.45;
}
.composer textarea::placeholder { color: var(--faint); }
.rec { flex: 1; display: flex; align-items: center; gap: 10px; padding: 8px 10px; font: 14px var(--mono); }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--error); animation: blink 1s ease-in-out infinite; }
.rec-note { color: var(--faint); }
@keyframes blink { 50% { opacity: .25; } }
.recording #mic-btn { background: var(--error); color: #fff; }

/* Меню чата: правая кнопка или долгое нажатие */
.menu {
  position: fixed; z-index: 20; min-width: 13rem; padding: 5px; border-radius: 12px; background: var(--surface);
  border: 1px solid var(--line); box-shadow: var(--shadow);
}
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: 8px; text-align: left; font-size: 14.5px; }
.menu button:hover, .menu button:focus-visible { background: var(--raised); outline: none; }
.menu button.danger { color: var(--error); }
.menu svg { width: 17px; height: 17px; color: var(--dim); flex: none; }
.menu button.danger svg { color: inherit; }
.chat-item { -webkit-touch-callout: none; user-select: none; }

.toast {
  position: fixed; left: 50%; bottom: max(96px, calc(env(safe-area-inset-bottom) + 96px)); translate: -50% 0; z-index: 10;
  max-width: min(90vw, 30rem); padding: 10px 16px; border-radius: 12px; background: var(--raised); border: 1px solid var(--line);
  box-shadow: var(--shadow); font-size: 14px;
}

/* Телефон: один экран — список или чат */
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .only-narrow { display: grid; }
  .only-wide { display: none; }
  .new-chat kbd { display: none; }
  body[data-view="list"] .main, body[data-view="chat"] .side { display: none; }
  .side { border-right: 0; padding-left: 12px; padding-right: 12px; }
  .chat-item { padding: 12px 10px; }
  .chat-name { font-size: 16px; }
  .main-head { padding-left: 8px; padding-right: 8px; }
  .feed-inner { padding: 16px 16px 22px; }
  .composer { padding-left: 10px; padding-right: 10px; }
  .msg.user .msg-body { max-width: 88%; }
  .copy { opacity: 1; }
}
