/* Панель автомойки. Мобильная вёрстка основная, ПК — от 900px.
   Палитра своя, в Telegram подставляются --tg-theme-* и colorScheme. */

:root {
  --bg: var(--tg-theme-bg-color, #eef1f6);
  --bg2: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #182230);
  --hint: var(--tg-theme-hint-color, #6b7684);
  --accent: var(--tg-theme-button-color, #2f6bff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --accent-soft: color-mix(in srgb, var(--accent) 11%, transparent);
  --danger: #d34545;
  --danger-soft: rgba(211, 69, 69, 0.11);
  --warn: #a86e08;
  --warn-soft: rgba(196, 138, 24, 0.14);
  --ok: #1d8a50;
  --ok-soft: rgba(29, 138, 80, 0.12);
  --border: rgba(24, 34, 48, 0.08);
  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 6px 20px rgba(16, 24, 40, 0.05);
  --nav-h: 64px;
}

[data-theme="dark"] .badge.warn { color: #2a1e05; }
[data-theme="dark"] .badge.danger { color: #330f0f; }

[data-theme="dark"] {
  --bg: var(--tg-theme-bg-color, #0e141b);
  --bg2: var(--tg-theme-secondary-bg-color, #171f29);
  --text: var(--tg-theme-text-color, #e7edf4);
  --hint: var(--tg-theme-hint-color, #8d99a8);
  --accent: var(--tg-theme-button-color, #5d8dff);
  --accent-soft: color-mix(in srgb, var(--accent) 16%, transparent);
  --danger: #ec7272;
  --danger-soft: rgba(236, 114, 114, 0.14);
  --warn: #d9a441;
  --warn-soft: rgba(217, 164, 65, 0.15);
  --ok: #4dbd85;
  --ok-soft: rgba(77, 189, 133, 0.14);
  --border: rgba(255, 255, 255, 0.08);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
}
a { color: var(--accent); text-decoration: none; }

#app { max-width: 900px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; }

/* Шапка */
.top-bar {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -0.01em; min-width: 0; }
.brand #brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-mark {
  width: 32px; height: 32px; flex: 0 0 32px; border-radius: 10px;
  background: var(--accent-soft); color: var(--accent);
  display: inline-flex; align-items: center; justify-content: center;
}
.brand-mark svg { width: 19px; height: 19px; }
.badge {
  font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums;
  padding: 3px 8px; border-radius: 8px; background: var(--accent);
  color: var(--accent-text); min-width: 24px; text-align: center;
}
.badge.warn { background: var(--warn); color: #fff; }
.badge.danger { background: var(--danger); color: #fff; }

main { flex: 1; padding: 14px 14px calc(var(--nav-h) + 34px + env(safe-area-inset-bottom)); overflow-y: auto; }

/* Навигация: снизу на телефоне, слева на ПК */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; max-width: 900px; margin: 0 auto; z-index: 20;
  background: var(--bg2); border-top: 1px solid var(--border);
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 8px 6px calc(10px + env(safe-area-inset-bottom));
}
.bottom-nav button {
  background: none; border: none; color: var(--hint); font: inherit; font-size: 11.5px; font-weight: 500;
  padding: 6px 2px 4px; border-radius: 12px; min-height: 48px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  cursor: pointer; transition: color 0.15s ease, background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.bottom-nav .nav-icon { width: 23px; height: 23px; }
.bottom-nav button.active { color: var(--accent); font-weight: 600; }
.bottom-nav button.active .nav-icon { stroke-width: 2.1; }

.section { display: none; animation: fade 0.18s ease; }
.section.active { display: block; }
.split > .card { margin-bottom: 12px; }
@keyframes fade { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

/* Карточки */
.card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
.card h3 { margin: 0 0 12px; font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.card h4 { margin: 16px 0 8px; font-size: 12px; color: var(--hint); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.row:last-child { margin-bottom: 0; }
.grow { flex: 1; }
.meta { color: var(--hint); font-size: 13px; }

/* Поля и кнопки */
input, select, textarea, button.btn {
  font: inherit; padding: 10px 13px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg); color: var(--text); outline: none; min-height: 42px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
input::placeholder, textarea::placeholder { color: var(--hint); }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type="date"], input[type="time"] { font-variant-numeric: tabular-nums; }
textarea { width: 100%; min-height: 90px; resize: vertical; }
button.btn, a.btn {
  background: var(--accent); color: var(--accent-text); border-color: transparent;
  cursor: pointer; font-weight: 600; text-align: center;
}
button.btn:hover { filter: brightness(1.05); }
button.btn:active { transform: translateY(1px); }
button.btn:disabled { opacity: 0.5; cursor: default; transform: none; }
button.btn.secondary, a.btn.secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
button.btn.secondary:hover { border-color: var(--accent); filter: none; }
button.btn.danger { background: var(--danger-soft); color: var(--danger); }
button.btn.warn { background: var(--warn-soft); color: var(--warn); }
button.btn.small { min-height: 32px; padding: 5px 11px; font-size: 12.5px; border-radius: 9px; }
a.btn { display: inline-flex; align-items: center; }
button.chip {
  font: inherit; font-size: 13px; font-weight: 500; padding: 7px 13px; border-radius: 20px; min-height: 36px;
  border: 1px solid transparent; background: var(--bg); color: var(--text); cursor: pointer;
  font-variant-numeric: tabular-nums; transition: background 0.15s ease, color 0.15s ease;
}
button.chip:hover { border-color: var(--border); }
button.chip.active { background: var(--accent); color: var(--accent-text); font-weight: 600; }

/* KPI */
.kpi-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.kpi {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 13px 14px;
}
.kpi .label { font-size: 12px; color: var(--hint); margin-bottom: 5px; font-weight: 500; }
.kpi .value { font-size: 24px; font-weight: 750; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.15; }

/* Распределения и бары */
.bar-list { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.bar-row .name { width: 110px; flex: 0 0 110px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .bar-wrap { flex: 1; background: var(--bg); border-radius: 6px; height: 8px; overflow: hidden; }
.bar-row .bar { background: var(--accent); height: 100%; border-radius: 6px; min-width: 2px; }
.bar-row .count { width: 32px; text-align: right; font-variant-numeric: tabular-nums; color: var(--hint); }
#schedule-grid .bar-row .name { width: auto; flex: 0 0 auto; min-width: 46px; font-variant-numeric: tabular-nums; }
#schedule-grid .bar-row .grow { min-width: 0; }

/* Записи */
.booking-card {
  background: var(--bg); border: 1px solid var(--border); border-left: 3px solid var(--ok);
  border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 10px;
}
.booking-card.unsynced { border-left-color: var(--warn); }
.booking-card.cancelled { border-left-color: var(--danger); opacity: 0.72; }
.booking-card .line { display: flex; justify-content: space-between; gap: 4px 10px; margin-bottom: 5px; align-items: baseline; flex-wrap: wrap; }
.booking-card .line > :first-child { min-width: 0; }
.booking-card .line > :last-child { margin-left: auto; white-space: nowrap; font-variant-numeric: tabular-nums; }
.booking-card .line strong { font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.booking-card .meta { color: var(--hint); font-size: 13px; }
.booking-card .actions { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }
.booking-card .actions .btn { min-height: 36px; padding: 7px 12px; font-size: 13px; }

/* Обращения, клиенты, задачи, очередь */
.case-card, .customer-card, .task-row, .op-row {
  border-bottom: 1px solid var(--border); padding: 13px 0;
}
.case-card:last-child, .customer-card:last-child, .task-row:last-child, .op-row:last-child { border-bottom: none; }
.customer-card { cursor: pointer; border-radius: 8px; }
.customer-card:hover strong { color: var(--accent); }
.case-card pre { white-space: pre-wrap; font: inherit; font-size: 14px; margin: 7px 0; }
.case-card .reply-box { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }
.task-row details { margin-top: 8px; }
.task-row pre { white-space: pre-wrap; overflow-wrap: anywhere; }

/* Переписка */
.chat-thread { max-height: 55vh; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.msg { padding: 10px 13px; border-radius: 16px; max-width: 85%; font-size: 14px; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 6px; }
.msg.bot, .msg.manager, .msg.event { align-self: flex-start; background: var(--bg); border: 1px solid var(--border); border-bottom-left-radius: 6px; }
.msg.manager { border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.msg .meta { font-size: 11px; margin-top: 5px; opacity: 0.75; }
.msg.user .meta { color: var(--accent-text); opacity: 0.8; }
.msg.bot .meta, .msg.manager .meta, .msg.event .meta { color: var(--hint); opacity: 1; }

.timeline { display: flex; flex-direction: column; gap: 10px; }
.timeline .entry { padding: 11px 12px; background: var(--bg); border-radius: var(--radius-sm); font-size: 13px; }
.timeline .entry .kind { font-weight: 600; font-size: 11px; color: var(--hint); text-transform: uppercase; letter-spacing: 0.04em; }

/* Правила */
.rule-item { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.rule-item:last-child { border-bottom: none; }
.rule-item .num {
  color: var(--hint); font-size: 12px; font-weight: 600; width: 24px; height: 24px; flex: 0 0 24px;
  background: var(--bg); border-radius: 8px; display: inline-flex; align-items: center; justify-content: center;
  font-variant-numeric: tabular-nums;
}
.rule-item .text { flex: 1; min-width: 140px; font-size: 14px; }
.rule-actions { display: flex; gap: 6px; margin-left: auto; }

.json-editor { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; line-height: 1.55; }
pre { overflow-wrap: anywhere; }

/* Модалки: на телефоне — нижний лист, на ПК — по центру */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10, 16, 24, 0.45); z-index: 100;
  display: flex; align-items: flex-end; justify-content: center; padding: 0;
  animation: overlay-in 0.15s ease;
}
.modal {
  background: var(--bg2); border-radius: 20px 20px 0 0; width: 100%; max-width: 560px;
  max-height: 92vh; overflow-y: auto; box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.25);
  animation: sheet-in 0.2s ease;
}
.modal header { padding: 16px 18px; border-bottom: 1px solid var(--border); font-weight: 700; font-size: 16px; position: sticky; top: 0; background: var(--bg2); border-radius: 20px 20px 0 0; }
.modal .body { padding: 16px 18px; }
.modal footer {
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px; position: sticky; bottom: 0; background: var(--bg2);
}
@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0.6; } to { transform: none; opacity: 1; } }

/* Тост */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + 26px + env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--text); color: var(--bg2); padding: 11px 20px; border-radius: 14px;
  font-size: 14px; font-weight: 500; opacity: 0; transition: all 0.2s ease; z-index: 200; pointer-events: none;
  max-width: calc(100vw - 40px); text-align: center; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.empty { color: var(--hint); text-align: center; padding: 34px 12px; font-size: 14px; }

/* Статусы: единая система из четырёх цветов */
.status-pill {
  display: inline-flex; align-items: center; font-size: 11.5px; font-weight: 600; line-height: 1.5;
  padding: 2px 9px; border-radius: 8px; white-space: nowrap;
  background: var(--bg); color: var(--hint); border: 1px solid var(--border);
}
.status-pill.active, .status-pill.done { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.status-pill.past { background: var(--bg); color: var(--hint); border-color: var(--border); }
.status-pill.cancelled { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.status-pill.pending { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.status-pill.processing { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* Вход */
.login-overlay {
  position: fixed; inset: 0; background: var(--bg); z-index: 300;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.login-box {
  width: 100%; max-width: 360px; background: var(--bg2); border: 1px solid var(--border);
  border-radius: 20px; box-shadow: var(--shadow); padding: 24px; display: flex; flex-direction: column; gap: 14px;
}
.login-box h3 { margin: 0; font-size: 19px; letter-spacing: -0.01em; }
.login-box input { width: 100%; }

@media (min-width: 600px) {
  .kpi-grid { grid-template-columns: repeat(4, 1fr); }
  .modal-overlay { align-items: center; padding: 20px; }
  .modal { border-radius: 20px; }
  .modal header { border-radius: 20px 20px 0 0; }
}

@media (min-width: 900px) {
  #app {
    max-width: 1240px; display: grid; align-items: start;
    grid-template-columns: 224px 1fr; grid-template-rows: auto 1fr;
  }
  .top-bar { grid-column: 1 / -1; grid-row: 1; padding: 14px 24px; }
  main { grid-column: 2; grid-row: 2; padding: 20px 24px 40px 20px; }
  .bottom-nav {
    position: sticky; top: 20px; grid-column: 1; grid-row: 2;
    max-width: none; height: auto; min-height: 0; margin: 20px 0 20px 20px; align-self: start;
    display: flex; flex-direction: column; gap: 4px; padding: 8px;
    background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow);
  }
  .bottom-nav button {
    flex-direction: row; justify-content: flex-start; gap: 12px; font-size: 14px;
    padding: 11px 14px; min-height: 46px; border-radius: var(--radius-sm);
  }
  .bottom-nav button:hover { background: var(--bg); }
  .bottom-nav button.active { background: var(--accent-soft); }
  .section.active.split { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; align-items: start; }
  .section.active.split > .card { margin-bottom: 14px; }
  .card { padding: 18px; }
  .toast { bottom: 28px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
