:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f4f7);
  --text: var(--tg-theme-text-color, #14171f);
  --hint: var(--tg-theme-hint-color, #7a808c);
  --line: color-mix(in srgb, var(--text) 12%, transparent);
  --navy: #0A2463;
  --cyan: #00C4FF;
  --cyan-text: #0090CC;
  --red: #d9483b;
  --amber: #c98a00;
  --green: #1f9d61;
  --violet: #6a4fd8;
  --radius: 12px;
  --pad: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, "SF Pro Text", Roboto, "Segoe UI", system-ui, sans-serif; }
body { padding-bottom: calc(84px + var(--safe-b)); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--cyan-text); }
.center { display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 60vh; text-align: center; padding: var(--pad); gap: 8px; }
.hint { color: var(--hint); }
.small { font-size: 13px; }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- шапка ---------- */
.top { position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: baseline; justify-content: space-between; padding: 12px var(--pad) 4px; }
.brand b { font-size: 15px; letter-spacing: .12em; color: var(--navy); }
@media (prefers-color-scheme: dark) { .brand b { color: var(--cyan); } }
.brand span { font-size: 13px; color: var(--hint); }
.tabs { display: flex; padding: 0 var(--pad); gap: 18px; }
.tabs button { background: none; border: 0; padding: 10px 0 8px; color: var(--hint); font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--text); border-bottom-color: var(--cyan); }
.search { padding: 8px var(--pad) 10px; }
.search input { width: 100%; border: 0; background: var(--bg2); border-radius: 10px; padding: 10px 12px; outline: none; }
.search input:focus { box-shadow: 0 0 0 2px var(--cyan); }

/* ---------- список ---------- */
.row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px var(--pad);
  border-bottom: 1px solid var(--line); width: 100%; text-align: left; background: none; border-left: 0; border-right: 0; border-top: 0; }
.row:active { background: var(--bg2); }
.row .num { font-weight: 700; font-size: 17px; letter-spacing: .02em; }
.row .client { color: var(--text); }
.row .work { color: var(--hint); font-size: 13px; grid-column: 1; }
.row .right { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; grid-row: 1 / span 3; }
.row .who { font-size: 12px; color: var(--hint); }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  background: color-mix(in srgb, var(--c, var(--hint)) 16%, transparent); color: var(--c, var(--hint)); white-space: nowrap; }
.pill.accepted { --c: var(--hint); }
.pill.diagnostics, .pill.agreement { --c: var(--violet); }
.pill.in_work { --c: var(--amber); }
.pill.done { --c: var(--green); }
.pill.issued { --c: var(--green); opacity: .7; }
.pill.refused, .pill.cancelled { --c: var(--red); }
.due { font-size: 12px; color: var(--hint); white-space: nowrap; }
.due.over { color: var(--red); font-weight: 600; }

/* ---------- нижняя панель ---------- */
.bottom { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; padding: 10px var(--pad) calc(10px + var(--safe-b));
  background: var(--bg); border-top: 1px solid var(--line); display: flex; gap: 8px; }
.btn { flex: 1; border: 0; border-radius: var(--radius); padding: 13px 14px; font-weight: 600; font-size: 15px;
  background: var(--bg2); color: var(--text); }
.btn.primary { background: var(--navy); color: #fff; }
.btn.danger { color: var(--red); }
.btn.ghost { background: none; border: 1px solid var(--line); }
.btn:disabled { opacity: .5; }
.btn.sm { padding: 9px 12px; font-size: 14px; flex: 0 0 auto; }

/* ---------- карточка заявки ---------- */
.screen { padding: 0 var(--pad); }
.head { display: flex; align-items: center; justify-content: space-between; padding: 14px 0 10px; }
.head .num { font-size: 26px; font-weight: 800; letter-spacing: .02em; }
.kv { display: grid; grid-template-columns: 96px 1fr; gap: 10px 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.kv .k { color: var(--hint); font-size: 14px; }
.kv .v { word-break: break-word; }
.kv .v.strong { font-weight: 600; }
.flag { display: inline-block; font-size: 13px; padding: 2px 8px; border-radius: 6px; background: var(--bg2); margin: 2px 6px 2px 0; }
.flag.warn { background: color-mix(in srgb, var(--amber) 18%, transparent); color: var(--amber); }
.flag.bad { background: color-mix(in srgb, var(--red) 14%, transparent); color: var(--red); }
.flag.good { background: color-mix(in srgb, var(--green) 14%, transparent); color: var(--green); }
.hist { padding: 12px 0 8px; border-top: 1px solid var(--line); }
.hist h4 { margin: 0 0 8px; font-size: 14px; color: var(--hint); font-weight: 500; }
.ev { display: grid; grid-template-columns: 78px 1fr; gap: 6px 10px; font-size: 14px; padding: 4px 0; }
.ev .ts { color: var(--hint); font-variant-numeric: tabular-nums; }
.ev .who { color: var(--hint); }

/* ---------- форма ---------- */
.form { padding: 4px 0; }
.f { margin: 14px 0; }
.f label { display: block; font-size: 13px; color: var(--hint); margin-bottom: 6px; }
.f label i { font-style: normal; opacity: .7; }
.f input, .f select, .f textarea { width: 100%; border: 1px solid var(--line); background: var(--bg2);
  border-radius: 10px; padding: 11px 12px; outline: none; }
.f input:focus, .f select:focus, .f textarea:focus { border-color: var(--cyan); }
.f textarea { min-height: 72px; resize: vertical; }
.f .err { border-color: var(--red) !important; }
.f.err .seg { box-shadow: 0 0 0 1px var(--red); }
.seg { display: flex; background: var(--bg2); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px 6px; border-radius: 8px; color: var(--hint); font-weight: 500; }
.seg button.on { background: var(--bg); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.seg button.on.warn { color: var(--amber); }
.seg button.on.bad { color: var(--red); }
.seg button.on.good { color: var(--green); }
.inline { display: flex; gap: 8px; align-items: center; }
.inline > * { flex: 1; }
.inline .seg { flex: 0 0 132px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--bg2); border-radius: 999px; padding: 7px 12px; font-size: 14px; }
.chip.on { border-color: var(--navy); background: color-mix(in srgb, var(--navy) 12%, transparent); font-weight: 600; }
@media (prefers-color-scheme: dark) { .chip.on { border-color: var(--cyan); background: color-mix(in srgb, var(--cyan) 14%, transparent); } }
.hintbtn { background: none; border: 0; color: var(--cyan-text); padding: 4px 0; font-size: 14px; }
.msg.error { color: var(--red); font-size: 14px; margin: 8px 0; }

/* ---------- шторка ---------- */
.veil { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; display: flex; align-items: flex-end; }
.sheet { width: 100%; background: var(--bg); border-radius: 16px 16px 0 0; padding: 14px var(--pad) calc(16px + var(--safe-b)); }
.sheet h3 { margin: 4px 0 12px; font-size: 17px; }
.sheet .actions { display: flex; gap: 8px; margin-top: 12px; }
.sheet .list button { display: block; width: 100%; text-align: left; background: none; border: 0;
  border-bottom: 1px solid var(--line); padding: 12px 0; }

/* ---------- тост ---------- */
.toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%);
  background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 30;
  box-shadow: 0 4px 16px rgba(0,0,0,.25); }

/* ---------- настройки ---------- */
.menu button { display: flex; justify-content: space-between; width: 100%; background: none; border: 0;
  border-bottom: 1px solid var(--line); padding: 14px 0; text-align: left; }
.menu button span:last-child { color: var(--hint); }

@media (prefers-reduced-motion: no-preference) {
  .sheet { animation: up .18s ease-out; }
  @keyframes up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
}

.req { color: var(--red); font-weight: 700; }
.later { margin: 22px 0 6px; padding-top: 12px; border-top: 1px dashed var(--line); color: var(--hint); font-size: 13px; }
