:root {
  --bg: #f4f5f2;
  --panel: #ffffff;
  --ink: #1d2320;
  --muted: #66706b;
  --line: #dfe3df;
  --accent: #2f6f5e;
  --accent-ink: #ffffff;
  --accent-soft: #e3efe9;
  --free: #2f8f5b;
  --free-soft: #e6f4ec;
  --busy: #b6452c;
  --busy-soft: #fbebe6;
  --late: #c98a00;
  --late-soft: #fff4d6;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --r: 12px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  font-size: 16px;
  color: var(--ink);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151917; --panel: #1f2522; --ink: #e8ece9; --muted: #9aa49f; --line: #333b37;
    --accent: #5fb49a; --accent-ink: #0f1412; --accent-soft: #23352f;
    --free-soft: #1d3327; --busy-soft: #3a2420; --late-soft: #3a3118;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); min-height: 100vh; }
[hidden] { display: none !important; }
button {
  font: inherit; color: inherit; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 16px; transition: background .12s, border-color .12s, transform .05s;
}
button:hover { border-color: var(--accent); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--danger); }
button.primary.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.ghost { background: transparent; border-color: transparent; }
button.ghost:hover { background: var(--accent-soft); }
button.sel { background: var(--accent-soft); border-color: var(--accent); font-weight: 600; }
input, textarea, select {
  font: inherit; color: inherit; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
h2 { font-size: 18px; margin: 28px 0 12px; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; }

/* вход */
.login { display: grid; place-items: center; min-height: 100vh; }
.login-card { background: var(--panel); padding: 32px 36px; border-radius: 20px; box-shadow: var(--shadow); text-align: center; width: 340px; }
.login .brand { font-size: 34px; }
.pin-dots { display: flex; gap: 12px; justify-content: center; margin: 12px 0 20px; height: 18px; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; background: var(--line); }
.pin-dots i.on { background: var(--accent); }
.pinpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pinpad button { font-size: 24px; padding: 16px 0; border-radius: 14px; }

/* шапка */
.brand { font-weight: 800; letter-spacing: .5px; color: var(--accent); font-size: 22px; }
.top {
  display: flex; align-items: center; gap: 20px; padding: 10px 20px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.shift { color: var(--muted); font-size: 14px; white-space: nowrap; }
.tabs { display: flex; gap: 4px; margin-left: 8px; }
.tabs button { border: none; background: transparent; border-radius: 8px; padding: 8px 14px; color: var(--muted); }
.tabs button.active { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.clock { font-variant-numeric: tabular-nums; color: var(--muted); margin-right: 8px; }
main { padding: 20px; max-width: 1280px; margin: 0 auto; }
.banner {
  background: var(--late-soft); border: 1px solid var(--late); border-radius: var(--r);
  padding: 16px 20px; margin-bottom: 20px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.banner input { width: 180px; }

/* номера */
.legend { display: flex; gap: 18px; color: var(--muted); font-size: 14px; margin-bottom: 12px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.dot.free { background: var(--free); } .dot.busy { background: var(--busy); } .dot.late { background: var(--late); }
.rooms { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.room {
  text-align: left; padding: 16px; border-radius: var(--r); border: 2px solid transparent;
  box-shadow: var(--shadow); min-height: 130px; display: flex; flex-direction: column; gap: 4px;
}
.room .num { font-size: 30px; font-weight: 800; line-height: 1; }
.room .cat { font-size: 13px; color: var(--muted); }
.room .status { margin-top: auto; font-weight: 600; }
.room .sub { font-size: 13px; color: var(--muted); }
.room.free { background: var(--free-soft); } .room.free .status { color: var(--free); }
.room.busy { background: var(--busy-soft); } .room.busy .status { color: var(--busy); }
.room.late { background: var(--late-soft); border-color: var(--late); animation: pulse 2s infinite; }
.room.late .status { color: var(--late); }
@keyframes pulse { 50% { border-color: transparent; } }

/* бар */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.group-title { font-size: 14px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 20px 0 10px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.tile { text-align: left; padding: 14px; border-radius: var(--r); box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; min-height: 104px; }
.tile .t { font-weight: 600; }
.tile .p { color: var(--muted); font-size: 14px; }
.tile .q { margin-top: auto; font-size: 13px; font-weight: 600; }
.tile.low { box-shadow: inset 0 0 0 2px var(--late); }
.tile.low .q { color: var(--late); }
.tile.out { opacity: .55; }
.tile.out .q { color: var(--danger); }

/* касса */
.cash-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.big { padding: 22px; font-size: 18px; text-align: left; border-radius: var(--r); box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; }
.big small { font-size: 13px; color: var(--muted); }

/* модальные окна */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: grid; place-items: center; z-index: 20; padding: 16px; }
.modal { background: var(--panel); border-radius: 18px; width: min(560px, 100%); max-height: 92vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-head { display: flex; align-items: center; padding: 18px 20px 4px; }
.modal-head h3 { margin: 0; font-size: 20px; }
.modal-head .x { margin-left: auto; font-size: 18px; padding: 6px 10px; }
.modal-body { padding: 12px 20px 20px; display: flex; flex-direction: column; gap: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button { padding: 9px 14px; }
.chips button small { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.total { font-size: 26px; font-weight: 800; }
.total small { font-size: 14px; color: var(--muted); font-weight: 400; margin-left: 8px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button { width: 44px; height: 44px; padding: 0; font-size: 22px; }
.stepper span { min-width: 40px; text-align: center; font-size: 22px; font-weight: 700; }
pre.report { white-space: pre-wrap; font-family: inherit; line-height: 1.45; margin: 0; background: var(--bg); padding: 16px; border-radius: 12px; }
.inv-table { width: 100%; border-collapse: collapse; }
.inv-table td { padding: 6px 4px; border-bottom: 1px solid var(--line); }
.inv-table input { width: 90px; text-align: right; }
.info { background: var(--bg); border-radius: 10px; padding: 12px 14px; line-height: 1.5; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; gap: 8px; align-items: center; }
.check input { width: auto; }

/* уведомления */
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 30; }
.toast { background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 12px; max-width: 420px; box-shadow: var(--shadow); white-space: pre-line; }
.toast.err { background: var(--danger); color: #fff; }

/* телефон и узкие окна */
@media (max-width: 760px) {
  .top { flex-wrap: wrap; gap: 8px 12px; padding: 10px 12px; }
  .shift { order: 3; width: 100%; font-size: 13px; white-space: normal; }
  .tabs { order: 4; width: 100%; margin: 0; overflow-x: auto; }
  .tabs button { flex: 1; white-space: nowrap; padding: 8px 10px; }
  .clock { display: none; }
  main { padding: 12px; }
  .rooms { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .room { min-height: 112px; padding: 12px; }
  .room .num { font-size: 26px; }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .cash-grid { grid-template-columns: 1fr; }
  .banner input { width: 100%; }
  .modal-back { padding: 0; place-items: end stretch; }
  .modal { width: 100%; max-height: 94vh; border-radius: 18px 18px 0 0; }
  .row2 { grid-template-columns: 1fr; }
  .actions button { flex: 1; }
  .toasts { left: 12px; right: 12px; bottom: 12px; }
  .toast { max-width: none; }
  .login-card { width: min(340px, calc(100vw - 32px)); padding: 24px; }
}

/* панель владельца */
.periods { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 18px; }
.periods .custom { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); }
.periods input[type=date] { width: auto; padding: 8px 10px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { background: var(--panel); border-radius: var(--r); box-shadow: var(--shadow); padding: 14px 16px; }
.kpi .k { font-size: 13px; color: var(--muted); }
.kpi .v { font-size: 24px; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .d { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi .d.up { color: var(--free); } .kpi .d.down { color: var(--danger); }
.kpi.warn { box-shadow: inset 0 0 0 2px var(--late); }
.card { background: var(--panel); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px; margin-bottom: 20px; }
.card h2 { margin: 0 0 12px; font-size: 17px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.card h2 .sp { margin-left: auto; font-weight: 400; }
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
table.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.tbl td { padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.tbl td.n, table.tbl th.n { text-align: right; }
table.tbl tr.click { cursor: pointer; }
table.tbl tr.click:hover td { background: var(--accent-soft); }
.bad { color: var(--danger); font-weight: 600; }
.okc { color: var(--free); }
.legend2 { display: flex; gap: 16px; font-size: 13px; color: var(--muted); margin-bottom: 8px; flex-wrap: wrap; }
.legend2 i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.chart { position: relative; }
.chart svg { width: 100%; height: 240px; display: block; }
.chart .tip { position: absolute; pointer-events: none; background: var(--ink); color: var(--bg); font-size: 13px; padding: 8px 10px; border-radius: 8px; white-space: nowrap; transform: translate(-50%, -110%); line-height: 1.45; }
.viz { --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --grid: #e6e8e5; }
@media (prefers-color-scheme: dark) { .viz { --s1: #3987e5; --s2: #d95926; --s3: #199e70; --grid: #2c3330; } }
@media (max-width: 760px) {
  .periods .custom { width: 100%; }
  .periods input[type=date] { flex: 1; min-width: 0; }
  .kpi .v { font-size: 20px; }
}

/* настройки */
.subtabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
table.tbl.edit td { padding: 5px 6px; vertical-align: middle; }
table.tbl.edit input, table.tbl.edit select { padding: 7px 9px; border-radius: 8px; min-width: 0; }
table.tbl.edit input.num { width: 96px; text-align: right; }
table.tbl.edit input.wide { min-width: 200px; }
table.tbl.edit td.win input { width: 110px; }
table.tbl.edit .pin { display: flex; gap: 4px; align-items: center; }
table.tbl.edit .pin input { width: 130px; letter-spacing: 1px; }
table.tbl.edit input.grp-in { min-width: 130px; }
table.tbl.edit select { min-width: 160px; }
table.tbl.edit tr.grp td { background: var(--bg); font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 600; padding: 8px; }
table.tbl.edit tr.warnrow input.num[data-k$=".price"] { border-color: var(--late); }
.x-del { padding: 6px 10px; color: var(--danger); }
.small { font-size: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.hist { padding: 10px 0; border-bottom: 1px solid var(--line); line-height: 1.5; }
.hist:last-child { border-bottom: none; }
ul.changes { margin: 0; padding-left: 20px; line-height: 1.6; }
.savebar {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 15;
  display: flex; align-items: center; gap: 10px; padding: 10px 12px 10px 18px;
  background: var(--panel); border: 1px solid var(--accent); border-radius: 14px; box-shadow: 0 8px 30px rgba(0,0,0,.18);
}
.savebar span { font-weight: 600; white-space: nowrap; }
#settings { padding-bottom: 80px; }
@media (max-width: 760px) {
  .savebar { left: 12px; right: 12px; transform: none; bottom: 12px; flex-wrap: wrap; }
  .savebar span { width: 100%; }
  .savebar button { flex: 1; }
  table.tbl.edit input.wide { min-width: 150px; }
}

/* связь с сервером */
.pill { border-radius: 999px; padding: 6px 12px; margin-right: 6px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.pill.ok { color: var(--free); background: transparent; border-color: transparent; font-weight: 500; }
.pill.busy { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.pill.warn { color: #7a5200; background: var(--late-soft); border-color: var(--late); }
.pill.bad { color: #fff; background: var(--danger); border-color: var(--danger); }
@media (prefers-color-scheme: dark) { .pill.warn { color: var(--late); } }
@media (max-width: 760px) { .pill { order: 5; } .top-right { flex-wrap: wrap; justify-content: flex-end; } }
.card.danger-zone { box-shadow: inset 0 0 0 1px var(--danger), var(--shadow); }

/* операции смены */
.ops-card { margin-top: 20px; }
table.tbl.ops td.what { white-space: normal; min-width: 220px; }
table.tbl.ops tr.voided td { color: var(--muted); }
table.tbl.ops tr.voided .w { text-decoration: line-through; }
.small-btn { padding: 5px 10px; font-size: 13px; }

/* сдача */
.change { background: var(--bg); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.change .field { margin: 0; }
.change-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.change-row input { width: 170px; font-size: 18px; }
.change-row .chips button { padding: 8px 12px; }
.change-out { font-size: 18px; min-height: 1.3em; }
.change-out b { font-size: 22px; }

.migrate-link { width: 100%; text-align: left; background: var(--late-soft); border-color: var(--late); font-weight: 600; }
.row2 > * { min-width: 0; } .row2 input[type=datetime-local] { min-width: 0; font-size: 15px; }
