:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --line: #e1e4ea;
  --text: #1b2230;
  --muted: #667085;
  --accent: #0f6b63;
  --accent-ink: #ffffff;
  --accent-soft: #e2f1ef;
  --ok: #17794a;
  --ok-soft: #e3f4ea;
  --warn: #a45a06;
  --warn-soft: #fdf0d9;
  --bad: #b3261e;
  --bad-soft: #fde7e5;
  --info: #2457b5;
  --info-soft: #e5edfb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b; --surface: #1b2029; --surface-2: #222835; --line: #2f3746; --text: #e8ebf1; --muted: #9aa4b5;
    --accent: #3fb8ab; --accent-ink: #06211e; --accent-soft: #17332f;
    --ok: #57c98d; --ok-soft: #173426; --warn: #f0b354; --warn-soft: #3a2c12;
    --bad: #f28b82; --bad-soft: #40201d; --info: #8ab4f8; --info-soft: #1c2b47;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
h1 { font-size: 22px; margin: 0; line-height: 1.25; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0; }
a { color: var(--accent); }
small, .muted { color: var(--muted); }
.loading { padding: 48px 16px; text-align: center; color: var(--muted); }

/* ---------- каркас ---------- */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.side {
  background: var(--surface); border-right: 1px solid var(--line); padding: 18px 12px;
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px;
}
.brand { font-weight: 700; font-size: 16px; padding: 4px 10px 14px; display: flex; gap: 10px; align-items: center; }
.brand svg { color: var(--accent); flex: none; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px;
  color: var(--text); text-decoration: none; font-weight: 500;
}
.nav a svg { flex: none; color: var(--muted); }
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav a.active svg { color: var(--accent); }
.nav .dot {
  margin-left: auto; background: var(--bad); color: #fff; border-radius: 999px; font-size: 11px;
  min-width: 18px; height: 18px; padding: 0 5px; display: grid; place-items: center; font-weight: 700;
}
.side .who { margin-top: auto; padding: 10px; border-top: 1px solid var(--line); font-size: 13px; }
.side .who b { display: block; font-size: 14px; }
.main { padding: 22px 26px 60px; min-width: 0; max-width: 1280px; }
.page-head { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; margin-bottom: 18px; }
.page-head .grow { flex: 1; min-width: 180px; }
.crumb { font-size: 13px; color: var(--muted); text-decoration: none; display: inline-block; margin-bottom: 2px; }

/* ---------- элементы ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card, .stack > * + * { margin-top: 14px; }
.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 14px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.tile .n { font-size: 26px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile .l { color: var(--muted); font-size: 13px; margin-top: 4px; }
.tile.bad .n { color: var(--bad); }
.tile.warn .n { color: var(--warn); }

button, .btn {
  font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 9px; padding: 8px 13px; cursor: pointer; text-decoration: none; display: inline-flex;
  align-items: center; justify-content: center; gap: 6px; min-height: 38px;
}
button:hover, .btn:hover { background: var(--surface-2); }
button:disabled { opacity: .55; cursor: default; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover, .btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
button.danger { color: var(--bad); }
button.small, .btn.small { padding: 4px 9px; min-height: 30px; font-size: 13px; font-weight: 500; }
button.link { border: 0; background: none; color: var(--accent); padding: 0; min-height: 0; font-weight: 500; }
button.big { min-height: 54px; font-size: 16px; padding: 12px 16px; width: 100%; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 9px; padding: 8px 10px; width: 100%; min-height: 38px;
}
textarea { min-height: 80px; resize: vertical; }
input[type=checkbox] { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.field small { display: block; margin-top: 3px; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0 12px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.toolbar > * { flex: 1 1 150px; }
.toolbar > button, .toolbar > .btn { flex: 0 0 auto; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; border: 1px solid var(--line); }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge + .badge { margin-left: 6px; }
h1 .badge { vertical-align: middle; }
td > a:first-child { white-space: nowrap; }
.bar { height: 8px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; min-width: 70px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.progress { display: flex; align-items: center; gap: 8px; }
.progress .bar { flex: 1; }
.progress b { font-variant-numeric: tabular-nums; font-size: 13px; min-width: 38px; text-align: right; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child > td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--surface-2); }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 9px 0; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: flex-start; }
.list > li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list a { text-decoration: none; color: inherit; }
.list a:hover { text-decoration: underline; }
.empty { color: var(--muted); padding: 10px 0; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px 16px; }
.kv div span { display: block; font-size: 12px; color: var(--muted); }
.kv div b { font-weight: 600; }

/* показатели этапа */
.counters { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: 6px; margin: 8px 0; }
.counters div { background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; padding: 6px 8px; }
.counters b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; line-height: 1.2; }
.counters span { font-size: 11.5px; color: var(--muted); }
.counters .hl-ok b { color: var(--ok); }
.counters .hl-warn b { color: var(--warn); }
.counters .hl-bad b { color: var(--bad); }

.stage { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-top: 8px; background: var(--surface); }
.stage.skipped { opacity: .6; }
.stage-head { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.stage-head h3 { flex: 1; min-width: 140px; }
.stage-meta { font-size: 13px; color: var(--muted); margin-top: 3px; }
.task-row { border-top: 1px dashed var(--line); padding: 8px 0 2px; margin-top: 8px; }
.task-row .row { justify-content: space-between; }
.comment { font-size: 13px; padding: 6px 0 0; }
.batch { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; background: var(--surface-2); margin-top: 12px; }
.batch-head { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.batch-head h3 { font-size: 16px; }
.history li { font-size: 13.5px; }
.history time { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* мои задачи */
.task-card h3 { font-size: 17px; }
.task-card .actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.task-card .actions .wide { grid-column: 1 / -1; }
.note { background: var(--info-soft); color: var(--text); border-radius: 9px; padding: 8px 10px; font-size: 14px; margin-top: 8px; white-space: pre-wrap; }
.note.warn { background: var(--warn-soft); }
.note.bad { background: var(--bad-soft); }

/* вход */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth .card { width: 100%; max-width: 380px; padding: 22px; }
.auth h1 { margin-bottom: 4px; }
.error { color: var(--bad); font-size: 14px; margin: 6px 0; min-height: 1px; }
.code-box { font: 700 24px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 3px; background: var(--surface-2); border: 1px dashed var(--line); border-radius: 10px; padding: 12px; text-align: center; user-select: all; word-break: break-all; }

/* модальные окна и сообщения */
.overlay { position: fixed; inset: 0; background: rgba(15, 20, 30, .5); display: grid; place-items: center; padding: 16px; z-index: 50; overflow-y: auto; }
.dialog { background: var(--surface); border-radius: 14px; width: 100%; max-width: 520px; padding: 18px; box-shadow: 0 20px 50px rgba(0, 0, 0, .3); max-height: calc(100vh - 32px); overflow-y: auto; }
.dialog.wide { max-width: 720px; }
.dialog h2 { margin-bottom: 14px; }
.dialog .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }
#toast-root { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
.toast { background: #1f2937; color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; }
.toast.bad { background: var(--bad); color: #fff; }

/* симулятор */
.chat { display: flex; flex-direction: column; gap: 8px; height: 440px; overflow-y: auto; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.msg { max-width: 86%; padding: 8px 11px; border-radius: 12px; white-space: pre-wrap; word-break: break-word; font-size: 14px; }
.msg.in { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.msg.out { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg .btns { display: grid; gap: 5px; margin-top: 8px; }
.msg .btns .r { display: flex; gap: 5px; }
.msg .btns button { flex: 1; font-size: 13px; padding: 5px 8px; min-height: 32px; font-weight: 500; }
.menu-kbd { display: grid; gap: 6px; margin-top: 8px; }
.menu-kbd .r { display: flex; gap: 6px; }
.menu-kbd button { flex: 1; font-weight: 500; }
.tabs { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.tabs button { border: 0; border-radius: 0; background: var(--surface); }
.tabs button.active { background: var(--accent); color: var(--accent-ink); }

/* ---------- телефон ---------- */
.bottom-nav { display: none; }
@media (max-width: 860px) {
  .shell { display: block; }
  .side { display: none; }
  .main { padding: 14px 16px 96px; }
  .grid.two { grid-template-columns: minmax(0, 1fr); }
  h1 { font-size: 20px; }
  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: var(--surface);
    border-top: 1px solid var(--line); padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    overflow-x: auto; scrollbar-width: none;
  }
  .bottom-nav::-webkit-scrollbar { display: none; }
  .bottom-nav a {
    flex: 1 0 68px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px;
    font-size: 11px; color: var(--muted); text-decoration: none; border-radius: 8px; position: relative; white-space: nowrap;
  }
  .bottom-nav a.active { color: var(--accent); background: var(--accent-soft); }
  .bottom-nav .dot { position: absolute; top: 2px; left: calc(50% + 6px); background: var(--bad); color: #fff; border-radius: 999px; font-size: 10px; min-width: 16px; height: 16px; padding: 0 4px; display: grid; place-items: center; font-weight: 700; }
  .task-card .actions { grid-template-columns: minmax(0, 1fr); }
  .hide-mobile { display: none; }
  .dialog { padding: 16px; }
  .overlay { place-items: end center; padding: 0; }
  .dialog { border-radius: 16px 16px 0 0; max-height: 92vh; }
  .chat { height: 52vh; }
  input, select, textarea { font-size: 16px; }
}
