/* halogen-chat: плоский компактный интерфейс */

:root {
  --bg: #0d1117;
  --panel: #161b22;
  --line: #21262d;
  --fg: #e6edf3;
  --dim: #8b949e;
  --acc: #58a6ff;
  --ok: #3fb950;
  --bad: #f85149;
  --vio: #bc8cff;
  --user: #12233a;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  max-width: 100%;
  overflow-x: hidden;           /* страховка: ничего не должно ехать вбок */
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}

body { display: flex; flex-direction: column; height: 100dvh; }

/* ---------- header ---------- */

header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: calc(5px + var(--safe-t)) 8px 5px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

header .title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

header .title small {
  display: block;
  font-weight: 400;
  font-size: 10px;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dot {
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  border-radius: 50%;           /* это индикатор, не декор — оставляю круглым */
  background: var(--dim);
}
.dot.on { background: var(--ok); }
.dot.err { background: var(--bad); }

button {
  font: inherit;
  color: var(--fg);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 4px 8px;
  cursor: pointer;
}
button:active { background: var(--bg); }
button.icon { padding: 3px 7px; font-size: 14px; line-height: 1.2; }
button.primary { background: #1f6feb; border-color: #1f6feb; }
button.danger { color: var(--bad); }
button:disabled { opacity: .45; }

/* ---------- лента ---------- */

main {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  padding: 8px;
  overflow-y: auto;
  overflow-x: hidden;           /* иначе лента станет горизонтальным скроллом */
  -webkit-overflow-scrolling: touch;
}

.msg {
  max-width: 100%;
  min-width: 0;
  margin: 0 0 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.msg .who {
  min-width: 0;
  font-size: 10px;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: .5px;
  display: flex;
  gap: 6px;
  align-items: baseline;
}
.msg .who .meta {
  text-transform: none;
  letter-spacing: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg .body {
  min-width: 0;
  max-width: 100%;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel);
  overflow-wrap: break-word;
  word-break: break-word;
}
.msg.user .body { background: var(--user); border-color: #1f4d7a; }
.msg.err .body { background: #2b0f0f; border-color: #7a2020; color: #ffb4ae; }

.msg .body > :first-child { margin-top: 0; }
.msg .body > :last-child { margin-bottom: 0; }
.msg .body p { margin: 0 0 .6em; }
.msg .body ul, .msg .body ol { margin: 0 0 .6em; padding-left: 1.2em; }
.msg .body li { margin: .1em 0; }
.msg .body h1, .msg .body h2, .msg .body h3, .msg .body h4 {
  margin: .7em 0 .35em;
  line-height: 1.25;
}
.msg .body h1 { font-size: 1.2em; }
.msg .body h2 { font-size: 1.1em; }
.msg .body h3, .msg .body h4 { font-size: 1em; }
.msg .body a { color: var(--acc); }
.msg .body hr { border: 0; border-top: 1px solid var(--line); margin: .8em 0; }
.msg .body del { color: var(--dim); }

.msg .body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .88em;
  background: #0b0f14;
  border: 1px solid var(--line);
  padding: 0 3px;
  overflow-wrap: break-word;
}

.msg .body pre {
  position: relative;
  margin: 0 0 .6em;
  padding: 8px;
  max-width: 100%;
  background: #0b0f14;
  border: 1px solid var(--line);
  overflow-x: auto;
}
.msg .body pre code {
  border: 0;
  padding: 0;
  background: none;
  font-size: .86em;
  line-height: 1.4;
  white-space: pre;
}

.msg .body blockquote {
  margin: 0 0 .6em;
  padding-left: 8px;
  border-left: 2px solid var(--line);
  color: var(--dim);
}

/* таблица живёт в своей прокручиваемой обёртке: колонки не сжимаются */
.msg .body .tw {
  max-width: 100%;
  margin: 0 0 .6em;
  overflow-x: auto;
}
.msg .body table {
  border-collapse: collapse;
  font-size: .9em;
  width: max-content;
  min-width: 100%;
}
.msg .body th, .msg .body td {
  border: 1px solid var(--line);
  padding: 3px 6px;
  text-align: left;
  white-space: nowrap;
}
.msg .body th { background: #0b0f14; font-weight: 600; }

details.think {
  margin: 0 0 .6em;
  padding: 4px 8px;
  border: 1px dashed var(--line);
  color: var(--dim);
  font-size: .9em;
}
details.think summary { cursor: pointer; color: var(--vio); }
details.think[open] { max-height: 45vh; overflow-y: auto; overflow-x: hidden; }

.copy {
  position: absolute;
  top: 4px;
  right: 4px;
  padding: 1px 5px;
  font-size: 10px;
  background: var(--panel);
  opacity: .5;
}

.cursor::after {
  content: "▍";
  color: var(--acc);
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---------- ввод ---------- */

footer {
  flex: 0 0 auto;
  padding: 6px 8px calc(6px + var(--safe-b));
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.composer {
  display: flex;
  gap: 6px;
  align-items: flex-end;
  min-width: 0;
}

.composer textarea {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 34px;
  max-height: 38vh;
  padding: 7px 9px;
  resize: none;
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 0;
  outline: none;
}
.composer textarea:focus { border-color: #1f6feb; }

.send {
  flex: 0 0 auto;
  width: 38px;
  height: 34px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 15px;
}
.send.stop { background: #7d1c1c; border-color: #7d1c1c; }

.hint {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
  font-size: 10px;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
}

/* ---------- панели ---------- */

.sheet {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 20;
  background: #000a;
}
.sheet.open { display: block; }

.sheet .inner {
  position: absolute;
  inset: auto 0 0 0;
  max-height: 88vh;
  padding: 10px 10px calc(12px + var(--safe-b));
  background: var(--panel);
  border-top: 1px solid var(--line);
  border-radius: 0;
  overflow-y: auto;
}

.sheet .inner h3 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 10px;
  font-size: 13px;
}

.field { margin-bottom: 10px; }
.field label {
  display: block;
  margin-bottom: 3px;
  font-size: 10px;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 7px 9px;
  font: inherit;
  font-size: 14px;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 0;
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: #1f6feb; }
.field textarea { min-height: 56px; resize: vertical; }
.field .note { margin-top: 3px; font-size: 10px; color: var(--dim); }

.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

.conv-list { display: flex; flex-direction: column; gap: 4px; }
.conv-item {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 8px 9px;
  background: var(--bg);
  border: 1px solid var(--line);
  cursor: pointer;
}
.conv-item.active { border-color: #1f6feb; }
.conv-item .name {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-item .when { flex: 0 0 auto; font-size: 10px; color: var(--dim); }
.conv-item .del {
  flex: 0 0 auto;
  padding: 0 4px;
  font-size: 12px;
  color: var(--bad);
  background: none;
  border: 0;
}

.empty {
  margin: 26px 8px;
  color: var(--dim);
  text-align: center;
  font-size: 13px;
  line-height: 1.6;
}
