/* Чувак: рабочее место. Бетон, графит и сигнальный жёлтый — как в мастерской. */
:root {
  --bg: #E6E8E3;
  --surface: #F7F8F5;
  --line: #CDD2CB;
  --ink: #1E2428;
  --muted: #5F6A70;
  --signal: #F2B705;
  --signal-ink: #1E2428;
  --ok: #2E6B57;
  --bad: #B0412C;
  --owner: #DDE2DC;
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Roboto", "Helvetica Neue", Arial, sans-serif;
  --radius-s: 4px;
  --radius-m: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15191B;
    --surface: #1C2225;
    --line: #2E363A;
    --ink: #E4E8E6;
    --muted: #97A2A6;
    --owner: #27302F;
    --ok: #5FB395;
    --bad: #E0735D;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }

.brand { font-weight: 800; font-size: 22px; letter-spacing: -0.02em; }

/* ---------- кнопки и поля ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius-s);
  padding: 7px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--signal); color: var(--signal-ink); border-color: var(--signal); font-weight: 600; }
.btn.primary:hover { filter: brightness(.95); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
input, textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: 8px 10px;
}
input:focus, textarea:focus { border-color: var(--ink); outline: none; }
textarea { resize: vertical; min-height: 44px; max-height: 40vh; }

/* ---------- вход ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-box { width: min(340px, 100%); display: grid; gap: 8px; }
.login-box .brand { font-size: 40px; margin: 0; }
.login-sub { margin: 0 0 16px; color: var(--muted); }
.login-box label { font-weight: 600; }
.form-error { min-height: 1.5em; margin: 0; color: var(--bad); }

/* ---------- каркас ---------- */
.app {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "top top" "chat side";
}
.top {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.top-left { display: flex; align-items: baseline; gap: 12px; }
.shop { font-weight: 700; font-size: 15px; }
.shop-switch { font: inherit; font-weight: 700; font-size: 15px; padding: 4px 8px; border-radius: var(--radius-s); border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.mode { font-size: 13px; color: var(--muted); }
.mode.live { color: var(--bad); font-weight: 600; }
.status { flex: 1; min-width: 0; color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status.busy::before {
  content: "";
  display: inline-block;
  width: 8px; height: 8px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--signal);
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: .25; } }
.top-actions { display: flex; gap: 8px; }
.mobile-tabs { display: none; }

/* ---------- чат ---------- */
.chat { grid-area: chat; display: flex; flex-direction: column; min-height: 0; }
.feed { flex: 1; overflow-y: auto; padding: 24px 20px 8px; }
#messages { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.load-more { display: block; margin: 0 auto 16px; background: none; border: 0; color: var(--muted); cursor: pointer; text-decoration: underline; }

.msg { max-width: 100%; }
.msg .meta { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.chuvak { padding-left: 14px; border-left: 3px solid var(--ink); }
.msg.owner { align-self: flex-end; max-width: 80%; }
.msg.owner .body { background: var(--owner); padding: 8px 12px; border-radius: var(--radius-m) var(--radius-m) var(--radius-s) var(--radius-m); }
.msg.owner .meta { text-align: right; }

/* Вопрос — единственное яркое место: он ждёт тебя */
.question {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  overflow: hidden;
}
.question::before {
  content: "";
  display: block;
  height: 8px;
  background: repeating-linear-gradient(-45deg, var(--signal) 0 10px, var(--ink) 10px 20px);
}
.question.answered::before { background: var(--line); }
.question .q-inner { padding: 12px 14px 14px; }
.question .q-title { font-weight: 700; margin-bottom: 4px; }
.question .options { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.question .custom { display: flex; gap: 8px; margin-top: 8px; }
.question .answer { margin-top: 10px; color: var(--muted); }
.question .answer b { color: var(--ink); }

/* ---------- ввод задачи ---------- */
.composer { border-top: 1px solid var(--line); background: var(--surface); padding: 12px 20px 10px; }
.composer > * { max-width: 760px; margin-left: auto; margin-right: auto; }
.skus { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 8px; }
.skus input { flex: 1; min-width: 180px; width: auto; border-style: dashed; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--ink); color: var(--bg);
  border-radius: var(--radius-s);
  padding: 3px 4px 3px 9px;
  font-size: 13px; font-weight: 600;
}
.chip button { border: 0; background: none; color: inherit; cursor: pointer; padding: 0 5px; font-size: 15px; line-height: 1; opacity: .7; }
.chip button:hover { opacity: 1; }
.compose-row { display: flex; gap: 8px; align-items: flex-end; }
.compose-row .send { height: 44px; }
.hint { font-size: 12px; color: var(--muted); margin: 6px auto 0; }

/* ---------- боковая панель ---------- */
.side { grid-area: side; border-left: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); padding: 0 8px; overflow-x: auto; }
.tabs button, .mobile-tabs button {
  border: 0; background: none; cursor: pointer;
  padding: 12px 10px 10px;
  color: var(--muted);
  border-bottom: 3px solid transparent;
}
.tabs button.active, .mobile-tabs button.active { color: var(--ink); border-bottom-color: var(--signal); font-weight: 600; }
.panel { flex: 1; overflow-y: auto; padding: 14px 16px 24px; }
.filter { margin-bottom: 12px; }
.empty { color: var(--muted); padding: 8px 0; }

.row { padding: 10px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.row .sku { font-weight: 700; }
.row .when { font-size: 12px; color: var(--muted); white-space: nowrap; }
.row .what { margin-top: 2px; }
.row .why { margin-top: 4px; font-size: 13px; color: var(--muted); }
.tag { font-size: 12px; padding: 1px 6px; border-radius: var(--radius-s); border: 1px solid currentColor; white-space: nowrap; }
.tag.dry { color: var(--muted); }
.tag.applied, .tag.done { color: var(--ok); }
.tag.error { color: var(--bad); }
.tag.active { color: var(--ink); }
.up { color: var(--ok); }
.down { color: var(--bad); }

.rule-form { display: flex; gap: 8px; margin-bottom: 12px; }
.rule { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }

.usage-today { font-size: 32px; font-weight: 800; letter-spacing: -0.02em; margin: 4px 0 2px; }
.usage-note { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.usage-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.usage-table th { text-align: left; font-weight: 600; color: var(--muted); padding: 6px 4px; border-bottom: 1px solid var(--line); }
.usage-table td { padding: 6px 4px; border-bottom: 1px solid var(--line); }
.usage-table td.num, .usage-table th.num { text-align: right; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: var(--radius-s);
  max-width: calc(100% - 32px);
}

/* ---------- телефон ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto auto minmax(0, 1fr); grid-template-areas: "top" "tabs" "main"; }
  .top { flex-wrap: wrap; gap: 8px 12px; padding: 10px 14px; }
  .status { order: 3; flex-basis: 100%; }
  .top-actions { margin-left: auto; }
  .top-actions #btn-report { display: none; }
  .mobile-tabs { grid-area: tabs; display: flex; overflow-x: auto; background: var(--surface); border-bottom: 1px solid var(--line); padding: 0 8px; }
  .chat, .side { grid-area: main; }
  .side { border-left: 0; }
  .side .tabs { display: none; }
  .app[data-view="chat"] .side { display: none; }
  .app:not([data-view="chat"]) .chat { display: none; }
  .feed { padding: 16px 14px 8px; }
  .composer { padding: 10px 14px; }
  .msg.owner { max-width: 92%; }
  .hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .status.busy::before { animation: none; }
}

/* ---------- результаты тестов ---------- */
.result { margin-top: 6px; display: grid; grid-template-columns: auto 1fr auto; gap: 2px 10px; font-size: 13px; }
.result .k { color: var(--muted); }
.result .v { text-align: right; }
.result .d { text-align: right; min-width: 52px; font-weight: 600; }
.warn { font-size: 13px; color: var(--muted); margin-top: 4px; }

/* ---------- опыт ---------- */
.k-section + .k-section { margin-top: 22px; }
.k-title { font-weight: 700; margin: 0 0 6px; }
.k-sub { color: var(--muted); font-size: 13px; margin: 0 0 10px; }
.playbook { white-space: pre-wrap; background: var(--bg); border-left: 3px solid var(--signal); padding: 10px 12px; font-size: 14px; }
.scope { font-size: 12px; color: var(--muted); }
.question .custom input { flex: 1; }
.k-actions { margin-top: 10px; }
