/* Odysseus CRM — мини-приложение. Цвета берём у Telegram, вне Telegram — свои светлая/тёмная. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f2f6);
  --card: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #14171f);
  --hint: var(--tg-theme-hint-color, #6b7385);
  --accent: var(--tg-theme-button-color, #2f6fed);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: rgba(128, 134, 150, 0.22);
  --red: #d93a3a;
  --red-bg: rgba(217, 58, 58, 0.12);
  --amber: #b97a00;
  --amber-bg: rgba(233, 162, 0, 0.16);
  --green: #1f8f4d;
  --green-bg: rgba(31, 143, 77, 0.13);
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-secondary-bg-color, #0f1218);
    --card: var(--tg-theme-bg-color, #1a1f29);
    --text: var(--tg-theme-text-color, #eef0f5);
    --hint: var(--tg-theme-hint-color, #8c94a6);
    --accent: var(--tg-theme-button-color, #4c8dff);
    --amber: #f0b03a;
    --red: #ff6b6b;
    --green: #4ecb85;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
  overflow-wrap: anywhere;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

#top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; background: var(--bg); border-bottom: 1px solid var(--line);
}
#top h1 { flex: 1; margin: 0; font-size: 18px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#top button {
  width: 40px; height: 40px; border: 0; border-radius: 12px; background: var(--card);
  font-size: 22px; line-height: 1; cursor: pointer;
}
#back { font-size: 28px !important; }

#view { padding: 12px; max-width: 760px; margin: 0 auto; }

#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabs a { flex: 1; text-align: center; padding: 8px 4px 9px; font-size: 12px; color: var(--hint); }
#tabs a span { display: block; font-size: 22px; line-height: 1.15; filter: grayscale(1); opacity: 0.7; }
#tabs a.on { color: var(--accent); font-weight: 600; }
#tabs a.on span { filter: none; opacity: 1; }

h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--hint); margin: 18px 4px 8px; font-weight: 600; }
.card { background: var(--card); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
.muted { color: var(--hint); }
.small { font-size: 13px; }
.empty { text-align: center; color: var(--hint); padding: 36px 12px; }
.error { background: var(--red-bg); color: var(--red); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }

/* Плитки на главной */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 560px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--card); border-radius: var(--radius); padding: 12px 14px; display: block; }
.tile b { display: block; font-size: 28px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile span { font-size: 13px; color: var(--hint); }
.tile.red b { color: var(--red); }
.tile.amber b { color: var(--amber); }
.tile.zero b { color: var(--hint); opacity: 0.6; }

/* Строка заказа */
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; margin-bottom: 10px; }
.row { display: flex; gap: 10px; align-items: center; padding: 11px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.row:last-child { border-bottom: 0; }
.row:active { background: var(--line); }
.row .ico { font-size: 22px; width: 28px; text-align: center; flex: none; }
.row .body { flex: 1; min-width: 0; }
.row .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .s { font-size: 13px; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .right { text-align: right; flex: none; font-size: 13px; max-width: 42%; }
.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--line); white-space: nowrap; }
.chip.red { background: var(--red-bg); color: var(--red); }
.chip.amber { background: var(--amber-bg); color: var(--amber); }
.chip.green { background: var(--green-bg); color: var(--green); }

/* Вкладки и поиск */
.seg { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button {
  flex: none; border: 0; border-radius: 999px; padding: 8px 14px; background: var(--card); color: var(--hint);
  font-size: 14px; cursor: pointer; white-space: nowrap;
}
.seg button.on { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.search { width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 11px 14px; margin-bottom: 10px; outline: none; }
.search:focus { border-color: var(--accent); }

/* Карточка заказа */
.head { display: flex; align-items: flex-start; gap: 10px; }
.head .big { font-size: 20px; font-weight: 700; flex: 1; }
.kv { display: grid; grid-template-columns: 108px 1fr; gap: 6px 10px; font-size: 15px; }
.kv dt { color: var(--hint); }
.kv dd { margin: 0; min-width: 0; }
.banner { border-radius: 12px; padding: 10px 12px; margin-top: 10px; font-weight: 600; }
.banner.red { background: var(--red-bg); color: var(--red); }
.banner.amber { background: var(--amber-bg); color: var(--amber); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn {
  border: 0; border-radius: 12px; padding: 13px 10px; background: var(--line); cursor: pointer; font-weight: 600;
  min-height: 48px; text-align: center;
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.wide { grid-column: 1 / -1; }
.btn.danger { color: var(--red); }
.btn:disabled { opacity: 0.5; }
.payform { display: flex; gap: 8px; margin-top: 10px; }
.payform input { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 12px; outline: none; }
.payform select { border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 0 8px; }
textarea.note { width: 100%; min-height: 72px; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 10px 12px; resize: vertical; outline: none; }
details { background: var(--card); border-radius: var(--radius); margin-bottom: 10px; }
details > summary { padding: 13px 14px; cursor: pointer; font-weight: 600; list-style: none; display: flex; justify-content: space-between; }
details > summary::-webkit-details-marker { display: none; }
details > summary::after { content: '›'; color: var(--hint); transform: rotate(90deg); }
details[open] > summary::after { transform: rotate(-90deg); }
details .in { padding: 0 14px 12px; }
.msg { margin: 0 0 8px; padding: 8px 11px; border-radius: 12px; background: var(--bg); font-size: 14px; white-space: pre-wrap; }
.msg.client { background: var(--green-bg); margin-right: 14%; }
.msg.bot { margin-left: 14%; }
.msg.manager { margin-left: 14%; background: var(--amber-bg); }
.msg small { display: block; color: var(--hint); font-size: 11px; margin-bottom: 2px; }
.ev { font-size: 14px; padding: 5px 0; border-bottom: 1px solid var(--line); display: flex; gap: 8px; justify-content: space-between; }
.ev:last-child { border-bottom: 0; }

#toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: rgba(20, 23, 31, 0.92); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 9;
  max-width: 90vw; text-align: center;
}
.spinner { text-align: center; padding: 40px; color: var(--hint); }
