:root {
  --ink: #18222d;
  --paper: #e9edf1;
  --surface: #ffffff;
  --line: #cbd3dc;
  --line-soft: #e2e7ec;
  --muted: #5a6878;
  --steel: #27496a;
  --steel-2: #1c3650;
  --open: #b87a06;
  --open-bg: #fcefd2;
  --new-bg: #fff8e8;
  --done: #2c7a4c;
  --done-bg: #dff0e5;
  --cancel: #8a95a1;
  --cancel-bg: #eef1f4;
  --danger: #b3261e;
  --hour: 72px;
  --r: 6px;
  font-family: 'Onest', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--paper);
  font-variant-numeric: tabular-nums;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
a { color: var(--steel); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--steel); outline-offset: 2px; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 14px; border-radius: var(--r);
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  text-decoration: none; font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--steel); border-color: var(--steel); color: #fff; }
.btn.primary:hover { background: var(--steel-2); }
.btn.danger { color: var(--danger); border-color: #e3b7b3; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(0,0,0,.05); }
.btn.sm { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn.icon { width: 38px; padding: 0; font-size: 22px; line-height: 1; }
.btn[disabled] { opacity: .5; pointer-events: none; }

label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 500; }
input, select, textarea {
  width: 100%; min-height: 40px; padding: 8px 10px; border-radius: var(--r);
  border: 1px solid var(--line); background: #fff; color: var(--ink); font-size: 15px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--steel); box-shadow: 0 0 0 3px rgba(39,73,106,.15); }
label.chk { display: flex; align-items: center; gap: 8px; color: var(--ink); font-weight: 400; font-size: 14px; }
label.chk input { width: 18px; min-height: 18px; margin: 0; }
.err { color: var(--danger); font-size: 14px; margin: 0; min-height: 1em; }
.grid2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 560px) { .grid2, .grid3 { grid-template-columns: 1fr 1fr; } }
.row { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- каркас ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 20px;
  padding: 0 20px; height: 56px; background: var(--ink); color: #dfe6ed;
}
.brand { display: flex; align-items: baseline; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; font-size: 18px; letter-spacing: .04em; }
.brand span { font-weight: 400; font-size: 13px; letter-spacing: 0; color: #9fb0c1; }
.top nav { display: flex; gap: 2px; flex: 1; }
.top nav a { color: #b9c6d3; text-decoration: none; padding: 8px 12px; border-radius: var(--r); font-weight: 500; }
.top nav a:hover { color: #fff; }
.top nav a.on { color: #fff; background: rgba(255,255,255,.1); }
.who { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.who .btn { color: #b9c6d3; }
main { padding: 20px; max-width: 1400px; margin: 0 auto; }
@media (max-width: 720px) {
  .top { padding: 0 8px 0 12px; gap: 6px; }
  .top nav { overflow-x: auto; scrollbar-width: none; }
  .top nav a { padding: 8px; font-size: 14px; white-space: nowrap; }
  .brand span, .who > span { display: none; }
  main { padding: 12px; }
}

/* ---------- расписание ---------- */
.toolbar { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px 16px; margin-bottom: 14px; }
.daynav { display: flex; align-items: center; gap: 6px; }
.daynav input[type=date] { width: 160px; }
.daytitle { font-size: 22px; font-weight: 600; }
.daytitle::first-letter { text-transform: uppercase; }
.tb-right { display: flex; gap: 8px; align-items: center; }
.tb-right input[type=search] { width: 230px; }
@media (max-width: 960px) {
  .toolbar { grid-template-columns: 1fr; }
  .daytitle { order: -1; font-size: 19px; }
  .tb-right { flex-wrap: wrap; }
  .tb-right input[type=search] { flex: 1; width: auto; }
}

.sum { display: flex; flex-wrap: wrap; gap: 8px 24px; padding: 12px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 12px; font-size: 14px; color: var(--muted); }
.sum b { font-size: 18px; color: var(--ink); margin-right: 4px; }
.sum .s-open b { color: var(--open); }
.sum .s-done b { color: var(--done); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin: 0 0 10px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; border-left: 3px solid; }
.legend .l-new { background: var(--new-bg); border-color: var(--open); outline: 1px dashed var(--open); outline-offset: -1px; }
.legend .l-open { background: var(--open-bg); border-color: var(--open); }
.legend .l-done { background: var(--done-bg); border-color: var(--done); }
.legend .l-cancel { background: var(--cancel-bg); border-color: var(--cancel); }

.board { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: auto; }
.board-grid { padding-bottom: 14px; display: grid; grid-template-columns: 64px repeat(var(--bays), minmax(200px, 1fr)); min-width: calc(64px + var(--bays) * 200px); }
.bh { position: sticky; top: 0; z-index: 3; background: var(--surface); padding: 10px 12px; font-weight: 600; font-size: 14px; border-bottom: 1px solid var(--line); border-left: 1px solid var(--line-soft); }
.bh:first-child { border-left: 0; }
.rail { position: relative; }
.rail span { position: absolute; right: 10px; transform: translateY(-50%); font-size: 13px; color: var(--muted); }
.rail span:first-child { transform: none; top: 4px !important; }
.bay {
  position: relative; border-left: 1px solid var(--line-soft); cursor: copy;
  background-image: linear-gradient(var(--line-soft) 1px, transparent 1px), linear-gradient(rgba(0,0,0,.025) 1px, transparent 1px);
  background-size: 100% var(--hour), 100% calc(var(--hour) / 2);
}
.bay .off { position: absolute; left: 0; right: 0; background: repeating-linear-gradient(135deg, transparent 0 6px, rgba(24,34,45,.04) 6px 12px); pointer-events: none; }
.now { position: absolute; left: 0; right: 0; height: 0; border-top: 2px solid var(--danger); z-index: 2; pointer-events: none; }
.now::before { content: ''; position: absolute; left: -4px; top: -5px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }

.blk {
  position: absolute; left: 6px; right: 6px; z-index: 1;
  display: flex; flex-direction: column; gap: 1px; overflow: hidden;
  padding: 6px 10px; text-align: left; cursor: pointer;
  border: 0; border-left-width: 4px; border-left-style: solid; border-radius: 4px;
  font-size: 13px; line-height: 1.3;
}
.blk:hover { filter: brightness(.97); }
.blk .t { font-weight: 600; }
.blk .n { font-weight: 600; font-size: 14px; }
.blk .c, .blk .p { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.blk .st { position: absolute; top: 6px; right: 8px; font-size: 11px; font-weight: 600; }
.is-open { background: var(--open-bg); border-color: var(--open); }
.is-open .st { color: var(--open); }
.st-new.is-open { background: var(--new-bg); box-shadow: inset 0 0 0 1px var(--open); border-style: solid; outline: 1px dashed var(--open); outline-offset: -1px; }
.is-done { background: var(--done-bg); border-color: var(--done); }
.is-done .st { color: var(--done); }
.is-cancel { background: var(--cancel-bg); border-color: var(--cancel); color: var(--muted); }
.is-cancel .n { text-decoration: line-through; }

.agenda { display: none; list-style: none; margin: 0; padding: 0; }
.agenda li + li { margin-top: 8px; }
.ag {
  width: 100%; display: grid; grid-template-columns: 58px 1fr auto; gap: 12px; align-items: center;
  padding: 12px; text-align: left; border-width: 0; border-left-width: 4px; border-left-style: solid; border-radius: var(--r); cursor: pointer;
}
.ag-t { font-weight: 700; font-size: 16px; display: grid; }
.ag-t small { font-weight: 400; font-size: 12px; color: var(--muted); }
.ag-m { display: grid; min-width: 0; }
.ag-m span { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: rgba(255,255,255,.7); white-space: nowrap; }
.is-open .pill { color: var(--open); }
.is-done .pill { color: var(--done); }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--r); }
.empty .btn { margin-top: 10px; }
@media (max-width: 720px) {
  .board, .legend { display: none; }
  .agenda { display: block; }
}

/* ---------- модальное окно ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(24,34,45,.45); display: flex; justify-content: flex-end; }
.sheet {
  position: relative; width: min(560px, 100%); height: 100%; overflow-y: auto;
  background: var(--paper); box-shadow: -8px 0 30px rgba(0,0,0,.2);
  animation: slide .18s ease-out;
}
@keyframes slide { from { transform: translateX(24px); opacity: 0; } }
.sheet > .x { position: absolute; top: 10px; right: 10px; z-index: 2; width: 36px; height: 36px; border: 0; border-radius: 50%; background: rgba(0,0,0,.06); font-size: 22px; cursor: pointer; }
.sheet section, .sheet .m-head, .sheet form.bform, .sheet .actions, .sheet details { padding: 16px 20px; }
.m-head { border-left: 6px solid; padding-top: 22px !important; }
.m-head h2 { font-size: 22px; margin: 6px 0 2px; }
.m-head a { font-size: 17px; font-weight: 500; text-decoration: none; }
.m-head .code { font-size: 13px; color: var(--muted); margin-left: 6px; }
.facts { margin: 0; padding: 12px 20px; display: grid; gap: 10px; background: var(--surface); border-block: 1px solid var(--line); }
.facts div { display: grid; grid-template-columns: 130px 1fr; gap: 12px; }
.facts dt { color: var(--muted); font-size: 13px; padding-top: 1px; }
.facts dd { margin: 0; }
.sheet h3 { font-size: 15px; margin-bottom: 10px; }
.money { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; margin-bottom: 12px; }
.money div { background: var(--surface); padding: 10px 12px; font-size: 12px; color: var(--muted); display: grid; }
.money b { font-size: 17px; color: var(--ink); }
.money .left b { color: var(--open); }
.money .left.zero b { color: var(--done); }
.pays { width: 100%; border-collapse: collapse; font-size: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
.pays td { padding: 8px 10px; border-top: 1px solid var(--line-soft); }
.pays tr:first-child td { border-top: 0; }
.pays .amt { text-align: right; font-weight: 600; white-space: nowrap; }
.pays .ps-pending { color: var(--open); }
.pays .ps-paid { color: var(--done); }
.pays .ps-failed, .pays .ps-cancelled { color: var(--cancel); text-decoration: line-through; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; border-top: 1px solid var(--line); background: var(--surface); position: sticky; bottom: 0; }
.panel { width: 100%; display: grid; gap: 12px; }
.panel h3 { margin: 0; }
.panel .note { font-size: 13px; color: var(--muted); margin: 0; }
details summary { cursor: pointer; font-weight: 500; color: var(--muted); }
.smslog { list-style: none; padding: 0; margin: 10px 0 0; font-size: 13px; display: grid; gap: 8px; }
.smslog li { background: var(--surface); padding: 8px 10px; border-radius: var(--r); border: 1px solid var(--line-soft); }
.smslog small { color: var(--muted); display: block; }
.smslog .bad small { color: var(--danger); }
@media (max-width: 560px) {
  .sheet { animation-name: up; }
  @keyframes up { from { transform: translateY(24px); opacity: 0; } }
  .facts div { grid-template-columns: 1fr; gap: 0; }
}

/* ---------- форма заказа ---------- */
.bform { display: grid; gap: 16px; }
.bform h2 { font-size: 20px; padding-right: 40px; }
fieldset { border: 0; margin: 0; padding: 14px; display: grid; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
legend { font-weight: 600; font-size: 14px; padding: 0 4px; margin-left: -4px; float: left; width: 100%; }
legend + * { clear: both; }
.avail { margin: 0; font-size: 14px; padding: 8px 10px; border-radius: var(--r); background: var(--cancel-bg); color: var(--muted); }
.avail.ok { background: var(--done-bg); color: var(--done); }
.avail.bad { background: #fbe4e2; color: var(--danger); }
.avail.warn { background: var(--open-bg); color: var(--open); }
.bform .row { position: sticky; bottom: 0; padding: 12px 0; background: var(--paper); }

/* ---------- отчёты ---------- */
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg a { padding: 6px 12px; border-radius: 4px; text-decoration: none; color: var(--ink); font-weight: 500; font-size: 14px; }
.seg a.on { background: var(--steel); color: #fff; }
.rep-bar { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin-bottom: 16px; }
.rep-bar .custom { display: flex; gap: 8px; align-items: end; }
.rep-bar .custom input { width: 150px; }
.rep-period { color: var(--muted); margin: 0 0 12px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; margin-bottom: 20px; }
.tiles div { box-shadow: 1px 1px 0 var(--line-soft); padding: 14px 16px; display: grid; gap: 2px; font-size: 13px; color: var(--muted); }
.tiles b { font-size: 24px; font-weight: 600; color: var(--ink); line-height: 1.15; }
.tiles .t-done b { color: var(--done); }
.tiles .t-open b { color: var(--open); }
.rep-cols { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .rep-cols { grid-template-columns: 1fr; } }
.tbl { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); font-size: 14px; }
.tbl th, .tbl td { padding: 9px 12px; border-bottom: 1px solid var(--line-soft); text-align: right; }
.tbl th:first-child, .tbl td:first-child { text-align: left; }
.tbl th { font-size: 12px; color: var(--muted); font-weight: 600; background: #f6f8fa; }
.tbl tfoot td { font-weight: 600; border-bottom: 0; }
.tbl .bar { position: relative; }
.tbl .bar i { position: absolute; left: 0; top: 6px; bottom: 6px; background: var(--done-bg); border-radius: 2px; z-index: 0; }
.tbl .bar span { position: relative; }
.tbl-wrap { overflow-x: auto; }

/* ---------- настройки ---------- */
.settings { display: grid; gap: 16px; max-width: 820px; }
.settings h1 { font-size: 22px; }
.settings textarea { font-size: 14px; }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; }

/* ---------- вход ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--ink); }
.login-card { width: min(360px, 100%); display: grid; gap: 14px; background: var(--surface); padding: 28px; border-radius: 10px; }
.login-card .brand { color: var(--ink); flex-direction: column; gap: 2px; margin-bottom: 8px; font-size: 26px; }
.login-card .brand span { color: var(--muted); font-size: 14px; }

/* ---------- уведомления ---------- */
#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 90; display: grid; gap: 8px; }
#toast div { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: var(--r); font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.25); animation: slide .18s ease-out; }
#toast div.bad { background: var(--danger); }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.results { list-style: none; margin: 0; padding: 0 20px 20px; display: grid; gap: 8px; }
@media (max-width: 420px) { .top .brand { display: none; } }
