/* ЭнергоИД — сначала телефон, потом всё остальное.
   Палитра та же, что в презентации: графит, светлый туман, охра. */
:root {
  --ink: #222C33;
  --slate: #3C4A52;
  --muted: #677884;
  --mist: #EEF1F2;
  --line: #D8DFE3;
  --paper: #FFFFFF;
  --ground: #F4F6F7;
  --accent: #C8701C;
  --accent-dark: #A65A10;
  --ok: #2F7D51;
  --ok-bg: #E4F1E9;
  --alert: #A6462F;
  --alert-bg: #F7E6E1;
  --warn: #8A5510;
  --warn-bg: #FBEFDC;
  --radius: 12px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent-dark); }

/* --- шапка --- */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px;
  background: var(--ink); color: #fff;
}
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 19px; letter-spacing: .01em; }
.brand b { color: var(--accent); }
.who {
  color: #C2CED4; text-decoration: none; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55%;
}

.wrap {
  max-width: 680px; margin: 0 auto;
  padding: 20px 16px calc(40px + env(safe-area-inset-bottom, 0px));
}

h1 { font-size: 26px; line-height: 1.2; margin: 4px 0 8px; text-wrap: balance; }
h2 { font-size: 19px; margin: 28px 0 10px; }
.card h2 { margin-top: 0; }
p { margin: 0 0 12px; }
.muted, .hint { color: var(--muted); }
.hint { font-size: 14px; }
.empty { color: var(--muted); padding: 20px 0; }
.back { margin: 0 0 6px; font-size: 15px; }
.back a { text-decoration: none; color: var(--muted); }
.count {
  display: inline-block; min-width: 30px; padding: 0 9px; border-radius: 99px;
  background: var(--mist); color: var(--slate); font-size: 16px; vertical-align: middle; text-align: center;
}

/* --- сообщения --- */
.flash {
  padding: 12px 14px; border-radius: var(--radius); margin-bottom: 14px;
  background: var(--ok-bg); color: var(--ok); font-weight: 600;
}
.flash.error { background: var(--alert-bg); color: var(--alert); }
.flash.warn { background: var(--warn-bg); color: var(--warn); }

/* --- карточки --- */
.card {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin: 0 0 16px;
}
.notice { padding: 22px 18px; }

/* --- главное меню --- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 20px 0; }
.tile {
  position: relative; display: flex; flex-direction: column; justify-content: space-between; gap: 10px;
  min-height: 108px; padding: 16px; border-radius: var(--radius);
  background: var(--paper); border: 1px solid var(--line);
  color: var(--ink); text-decoration: none; font-weight: 600; line-height: 1.25;
}
.tile:active { background: var(--mist); }
.tile .ico { font-size: 26px; line-height: 1; }
.badge {
  position: absolute; top: 12px; right: 12px; min-width: 26px; height: 26px; padding: 0 7px;
  border-radius: 99px; background: var(--accent); color: #fff; font-size: 14px; font-weight: 700;
  display: grid; place-items: center;
}

/* --- формы --- */
.form { display: flex; flex-direction: column; gap: 16px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.form small { font-weight: 400; color: var(--muted); font-size: 14px; }
input[type=text], input[type=email], input[type=password], select, textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--ink);
  padding: 12px 13px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper);
}
textarea { resize: vertical; min-height: 110px; }
input[type=file] { width: 100%; font: inherit; font-size: 15px; padding: 6px 0; }
input[type=file]::file-selector-button {
  min-height: 46px; margin-right: 12px; padding: 10px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, .chip:focus-visible, a:focus-visible {
  outline: 3px solid rgba(200, 112, 28, .35); outline-offset: 1px; border-color: var(--accent);
}

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  min-height: 50px; padding: 12px 16px; border: 0; border-radius: var(--radius);
  background: var(--accent); color: #fff; font: inherit; font-weight: 700; text-decoration: none;
  cursor: pointer;
}
.btn:active { background: var(--accent-dark); }
.btn.secondary { background: var(--paper); color: var(--ink); border: 1px solid var(--line); }
.btn.secondary:active { background: var(--mist); }
.btn.ok { background: var(--ok); }
.btn.danger { background: var(--alert); }
.btn.current { background: var(--ink); color: #fff; }
button.link {
  background: none; border: 0; padding: 8px; font: inherit; color: var(--muted);
  text-decoration: underline; cursor: pointer;
}

/* быстрые подсказки — как кнопки в боте */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: -6px; }
.chip {
  min-height: 42px; min-width: 48px; padding: 8px 14px; border-radius: 99px;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  font: inherit; font-size: 15px; cursor: pointer;
}
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }

/* --- списки --- */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 14px;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--ink); text-decoration: none;
}
a.row:active { background: var(--mist); }
.row .num { font-weight: 700; color: var(--accent-dark); white-space: nowrap; }
.row .main { flex: 1; min-width: 0; font-weight: 600; }
.row .main small { display: block; font-weight: 400; color: var(--muted); font-size: 14px; margin-top: 2px; }
.row .go { color: var(--muted); font-size: 22px; }
.mini { font-size: 14px; white-space: nowrap; }

.pill {
  display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 13px; font-weight: 700;
  white-space: nowrap; background: var(--mist); color: var(--slate);
}
.pill.pending { background: var(--warn-bg); color: var(--warn); }
.pill.accepted { background: var(--ok-bg); color: var(--ok); }
.pill.returned { background: var(--alert-bg); color: var(--alert); }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 16px; }
.pager .btn { width: auto; min-height: 44px; }
.pager span { color: var(--muted); font-size: 14px; }

/* --- карточка заявки --- */
/* подписи не шире 8em: на узком экране длинная «Причина возврата» переносится,
   а не отнимает место у значений */
.facts { display: grid; grid-template-columns: fit-content(8em) 1fr; gap: 8px 16px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.facts .reason { font-weight: 500; white-space: pre-line; }

.decide { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.return summary { list-style: none; }
.return summary::-webkit-details-marker { display: none; }
.return[open] summary { border-radius: var(--radius) var(--radius) 0 0; }
.return .form {
  padding: 16px; background: var(--paper); border: 1px solid var(--line); border-top: 0;
  border-radius: 0 0 var(--radius) var(--radius);
}
a.btn.secondary + .decide { margin-top: 10px; }

/* --- подписи акта --- */
.signs { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.signs legend { font-weight: 600; margin-bottom: 8px; padding: 0; }
.sign { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 14px; }
.check { flex-direction: row !important; align-items: center; gap: 12px !important; min-height: 48px; cursor: pointer; }
.check input { width: 24px; height: 24px; accent-color: var(--ok); flex: none; }
.why { display: flex; flex-direction: column; gap: 10px; padding: 0 0 12px; }
.why label { font-weight: 500; font-size: 15px; }
/* подписал — причина не нужна; «Другое» — нужен свой текст.
   Где :has не поддерживается, поля просто остаются видимыми. */
.sign:has(input[type=checkbox]:checked) .why { display: none; }
.why:not(:has(option[value="Другое"]:checked)) .other { display: none; }

/* --- сводка --- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0; }
.stat {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
  display: flex; flex-direction: column;
}
.stat b { font-size: 30px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 14px; }
.stat.ok b { color: var(--ok); }
.stat.warn b { color: var(--warn); }
.bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.bars li { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; }
.bars b { font-variant-numeric: tabular-nums; }
.bars i { grid-column: 1 / -1; height: 8px; border-radius: 99px; background: var(--accent); display: block; }
.w0 { width: 2%; } .w10 { width: 10%; } .w20 { width: 20%; } .w30 { width: 30%; }
.w40 { width: 40%; } .w50 { width: 50%; } .w60 { width: 60%; } .w70 { width: 70%; }
.w80 { width: 80%; } .w90 { width: 90%; } .w100 { width: 100%; }

/* --- пользователи --- */
.roles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 18px; }
.roles form { display: flex; }  /* кнопки в ряду — одной высоты */
.temp-password {
  font: 700 28px/1.2 ui-monospace, "Cascadia Mono", Consolas, monospace; letter-spacing: .08em;
  padding: 12px 14px; margin: 4px 0 12px; border-radius: 10px; background: var(--mist);
  user-select: all; overflow-wrap: anywhere;
}
.roles .btn { min-height: 48px; font-size: 15px; }
.status-form { margin-top: 8px; }

/* --- вход --- */
.auth { max-width: 420px; margin: 16px auto 0; }
.links { display: flex; justify-content: space-between; margin-top: 18px; }
.logout { text-align: center; margin-top: 28px; }

@media (min-width: 720px) {
  .tiles { grid-template-columns: repeat(3, 1fr); }
  .tiles.two { grid-template-columns: 1fr 1fr; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .roles { grid-template-columns: repeat(3, 1fr); }
  .btn { width: auto; min-width: 220px; }
  .form .btn, .decide .btn, .roles .btn, .status-form .btn { width: 100%; }
}

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