/* Логист-ассистент: одни стили на все страницы. Светлая и тёмная тема — по системе. */
:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1d2330;
  --muted: #687082;
  --line: #dfe3ea;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
  --mine: #e8f0fc;
  --error: #b3261e;
  --error-bg: #fdecea;
  --ok: #1e7b34;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181e;
    --panel: #1e222a;
    --text: #e6e8ec;
    --muted: #9aa2b1;
    --line: #2f3542;
    --accent: #5b9bf0;
    --accent-text: #0d1117;
    --mine: #23334d;
    --error: #ff8a80;
    --error-bg: #3b1f1f;
    --ok: #6fcf87;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); line-height: 1.45; }
a { color: var(--accent); }
h1 { font-size: 1.4rem; margin: 0 0 .6rem; }
h2 { font-size: 1.15rem; margin: 1.2rem 0 .6rem; }
.muted { color: var(--muted); }
.error { color: var(--error); background: var(--error-bg); padding: .5rem .7rem; border-radius: 6px; }
.ok { color: var(--ok); }
.small { font-size: .85rem; }

/* Поля и кнопки */
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%; padding: .5rem .6rem; border: 1px solid var(--line);
  border-radius: 6px; background: var(--panel);
}
button {
  padding: .5rem .9rem; border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel); cursor: pointer;
}
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.link { border: none; background: none; color: var(--accent); padding: 0; }
button:disabled { opacity: .55; cursor: default; }
.stack { display: flex; flex-direction: column; gap: .8rem; }
.stack label { display: flex; flex-direction: column; gap: .25rem; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* Каркас страниц */
.centered { display: flex; align-items: center; justify-content: center; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; }
.narrow { width: 100%; max-width: 400px; }
.page { max-width: 1100px; margin: 0 auto; padding: 16px; }
.topbar {
  display: flex; align-items: center; gap: 1rem; padding: .55rem 16px;
  background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.topbar .brand { font-weight: 600; text-decoration: none; color: var(--text); }
.topbar nav { display: flex; gap: .9rem; flex-wrap: wrap; flex: 1; }
.topbar nav a { text-decoration: none; }
.topbar .logout { display: flex; gap: .6rem; align-items: center; margin: 0; }
.who { color: var(--muted); }

/* Таблицы админки */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; background: var(--panel); }
th, td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; font-size: .9rem; color: var(--muted); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.over td { background: var(--error-bg); }
.badge { display: inline-block; padding: 0 .4rem; border-radius: 4px; font-size: .8rem; border: 1px solid var(--line); }
.inline-form { display: inline; margin: 0; }

/* Чат */
/* Страница чата — колонка во весь экран: шапка сколько займёт, остальное — чат. */
body.chat-page { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.chat-layout { display: flex; flex: 1; min-height: 0; position: relative; }
.sidebar {
  width: 260px; flex-shrink: 0; border-right: 1px solid var(--line); background: var(--panel);
  display: flex; flex-direction: column;
}
.sidebar .new { margin: .7rem; }
.conv-list { overflow-y: auto; flex: 1; }
.conv-list a {
  display: block; padding: .5rem .8rem; text-decoration: none; color: var(--text);
  border-bottom: 1px solid var(--line); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.conv-list a.active { background: var(--mine); }
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: .7rem; }
.msg { max-width: 820px; width: fit-content; padding: .6rem .8rem; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--mine); border-color: transparent; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; }
.msg.system { align-self: center; color: var(--muted); font-size: .9rem; background: none; border: none; }
.msg.error { align-self: center; }
.msg p { margin: .3rem 0; }
.msg table { font-size: .9rem; display: block; overflow-x: auto; width: max-content; max-width: 100%; }
.msg pre { overflow-x: auto; background: var(--bg); padding: .5rem; border-radius: 6px; }
.msg code { font-size: .9em; }
.tool-line { align-self: flex-start; color: var(--muted); font-size: .85rem; }
.files a { display: block; }
.question { margin: .5rem 0 .8rem; }
.question .opts { display: flex; flex-direction: column; gap: .35rem; margin: .4rem 0; }
.question .opts label { display: flex; gap: .5rem; align-items: center; cursor: pointer; }
.question .opts input { width: auto; }
.form-msg .stack label { font-size: .95rem; }
.answered { opacity: .7; }
.status { padding: 0 16px .3rem; color: var(--muted); font-size: .9rem; min-height: 1.3rem; }
.composer { border-top: 1px solid var(--line); padding: .6rem 16px; background: var(--panel); }
.composer form { display: flex; gap: .5rem; align-items: flex-end; }
.composer textarea { resize: none; min-height: 2.6rem; max-height: 12rem; }
.attached { display: flex; flex-wrap: wrap; gap: .3rem; margin-bottom: .4rem; }
.attached span { font-size: .85rem; border: 1px solid var(--line); border-radius: 4px; padding: 0 .4rem; }
.drop-hint {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--accent) 15%, transparent); border: 3px dashed var(--accent);
  font-size: 1.2rem; z-index: 5;
}
.chat.dragging .drop-hint { display: flex; }
.empty { margin: auto; color: var(--muted); text-align: center; padding: 1rem; }
.menu-btn { display: none; }

@media (max-width: 760px) {
  .sidebar { position: absolute; z-index: 10; top: 0; bottom: 0; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-block; margin: .4rem 16px 0; align-self: flex-start; }
  .msg { max-width: 100%; }
  /* Таблица ответа на телефоне — прокручивается вбок, а не сжимается в столбики. */
  .msg td, .msg th { white-space: nowrap; }
  .topbar nav { order: 3; flex-basis: 100%; }
}
