:root {
  --bg: #f4f2ee;
  --panel: #ffffff;
  --ink: #1d1b18;
  --muted: #7a746b;
  --line: #e4dfd6;
  --accent: #0a7c66;
  --accent-soft: #e2f2ee;
  --work: #0a7c66;
  --off: #4b4f7a;
  --off-soft: #e8e9f3;
  --warn: #b26a00;
  --warn-soft: #fbf0dc;
  --bad: #b3261e;
  --bad-soft: #fbe5e3;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.45 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.small { font-size: 12px; }

/* --- шапка --- */
header {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 14px 24px; background: var(--ink); color: #f4f2ee;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: .2px; }
.brand-mark {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent); color: #fff; font-weight: 800;
}
.clock { font-family: var(--mono); color: #cfc9be; }
.spacer { flex: 1; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { background: #16352e; color: #6fe0c4; }
.pill.bad { background: #43201d; color: #ff9d94; }
.pill.warn { background: #3f3216; color: #ffcc66; }
header .btn { background: #34312c; color: #f4f2ee; border-color: #4a463f; }
header .btn:hover { background: #45413a; }

nav.tabs { display: flex; gap: 4px; padding: 0 24px; background: var(--ink); }
nav.tabs button {
  border: 0; background: none; color: #a9a296; padding: 10px 14px; font: inherit; font-weight: 600;
  cursor: pointer; border-bottom: 3px solid transparent;
}
nav.tabs button.active { color: #fff; border-bottom-color: var(--accent); }

main { padding: 20px 24px 60px; max-width: 1500px; margin: 0 auto; }
section { display: none; }
section.active { display: block; }

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar h2 { margin: 0; font-size: 18px; }

/* --- кнопки и поля --- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f8f6f2; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 8px; font-size: 12px; }
.btn.wide { width: 100%; justify-content: center; padding: 10px; }
.btn:disabled { opacity: .5; cursor: default; }
input, select, textarea {
  font: inherit; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
label input, label select, label textarea { font-weight: 400; color: var(--ink); font-size: 14px; }

/* --- сводка --- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat .v { font-size: 22px; font-weight: 700; font-family: var(--mono); }
.stat .k { font-size: 12px; color: var(--muted); }

/* --- таблица --- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); background: #faf9f6; font-weight: 700; }
tr:last-child td { border-bottom: 0; }
tr.disabled td { opacity: .5; }
td.num { font-family: var(--mono); text-align: right; white-space: nowrap; }
th.num { text-align: right; }
.title { font-weight: 600; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actions { display: flex; gap: 4px; flex-wrap: nowrap; justify-content: flex-end; }

.mode { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 700; }
.mode.work { background: var(--accent-soft); color: var(--work); }
.mode.off { background: var(--off-soft); color: var(--off); }
.bid-cell.active { font-weight: 800; }
.bid-cell.active.work { color: var(--work); }
.bid-cell.active.off { color: var(--off); }
.actual { display: inline-flex; flex-direction: column; align-items: flex-end; }
.actual .val { font-family: var(--mono); font-weight: 700; padding: 2px 8px; border-radius: 6px; }
.actual .val.match { background: var(--accent-soft); color: var(--accent); }
.actual .val.diff { background: var(--warn-soft); color: var(--warn); }
.actual .val.none { background: #f1efea; color: var(--muted); }
.errtxt { color: var(--bad); font-size: 12px; max-width: 260px; }
.empty { padding: 50px 20px; text-align: center; color: var(--muted); }

/* --- расписания --- */
.sched-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(440px, 1fr)); gap: 16px; }
.sched { padding: 16px; }
.sched-head { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.sched-head input { flex: 1; font-weight: 700; }
.week { display: grid; grid-template-columns: 46px 70px 1fr 1fr; gap: 6px 10px; align-items: center; }
.week .d { font-weight: 700; }
.week input[type=time] { padding: 5px 7px; }
.week .hint { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.timeline { display: grid; grid-template-columns: 46px 1fr; gap: 3px 10px; margin: 14px 0 6px; font-size: 11px; color: var(--muted); }
.bar { position: relative; height: 12px; background: var(--off-soft); border-radius: 4px; overflow: hidden; }
.bar span { position: absolute; top: 0; bottom: 0; background: var(--work); }
.bar .now { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--bad); }
.switch { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 13px; color: var(--ink); flex-direction: row; font-weight: 500; }

/* --- модальные окна --- */
.modal-bg { position: fixed; inset: 0; background: rgba(20,18,15,.45); display: none; align-items: flex-start; justify-content: center; padding: 50px 16px; z-index: 50; overflow: auto; }
.modal-bg.open { display: flex; }
.modal { background: var(--panel); border-radius: 14px; width: 100%; max-width: 640px; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal h3 { margin: 0 0 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-bottom: 14px; }
.seg button { border: 0; background: #fff; padding: 7px 14px; font: inherit; font-weight: 600; cursor: pointer; color: var(--muted); }
.seg button.active { background: var(--ink); color: #fff; }
.pick-list { max-height: 300px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.pick-list label { flex-direction: row; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--line); color: var(--ink); font-weight: 400; font-size: 13px; }
.pick-list label.added { opacity: .45; }
pre.raw { background: #1d1b18; color: #d8d3c8; padding: 12px; border-radius: 8px; font-size: 12px; max-height: 260px; overflow: auto; }

.toast { position: fixed; right: 20px; bottom: 20px; padding: 12px 16px; border-radius: 10px; background: var(--ink); color: #fff; font-weight: 600; box-shadow: 0 10px 30px rgba(0,0,0,.25); opacity: 0; transform: translateY(10px); transition: .2s; z-index: 99; max-width: 420px; }
.toast.show { opacity: 1; transform: none; }
.toast.bad { background: var(--bad); }

.lvl { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 5px; text-transform: uppercase; }
.lvl.ok { background: var(--accent-soft); color: var(--accent); }
.lvl.info { background: #eeece7; color: var(--muted); }
.lvl.error { background: var(--bad-soft); color: var(--bad); }

.settings { max-width: 620px; padding: 20px; display: grid; gap: 14px; }
.notice { background: var(--warn-soft); color: #6d4300; border-radius: 8px; padding: 10px 12px; font-size: 13px; }
.notice.info { background: var(--accent-soft); color: #064d40; }

/* --- вход --- */
.login-body { display: grid; place-items: center; min-height: 100vh; background: var(--ink); }
.login-card { background: var(--panel); padding: 30px; border-radius: 16px; width: 340px; display: grid; gap: 14px; }
.login-card .brand { color: var(--ink); }
.login-card p { margin: -8px 0 4px; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; }

@media (max-width: 900px) {
  .sched-grid { grid-template-columns: 1fr; }
  .table-wrap { overflow-x: auto; }
  table { min-width: 900px; }
  main { padding: 14px; }
}

.modal .stats { grid-template-columns: repeat(4, 1fr); }
.modal .stat .v { font-size: 18px; }

/* ===== v2: таблица с правкой в строке ===== */
main { max-width: 1900px; }
table.items th, table.items td { padding: 8px 10px; }
table.items th .sub { font-size: 10px; font-weight: 500; text-transform: none; letter-spacing: 0; color: var(--muted); }
table.items th.grp-w { background: #eef6f3; }
table.items th.grp-o { background: #eff0f6; }
table.items tr.sel td { background: #f3faf8; }
table.items td.active-cell { background: #f6fbf9; }
.idline { display: flex; align-items: center; gap: 10px; margin-top: 2px; }
.linkbtn { border: 0; background: none; padding: 0; font: inherit; font-size: 12px; color: var(--ink); cursor: pointer; font-weight: 600; }
.linkbtn:hover { color: var(--accent); }
.title a { color: var(--ink); text-decoration: none; }
.title a:hover { color: var(--accent); text-decoration: underline; }
.title { max-width: 260px; }

.cell-in { display: inline-flex; align-items: center; gap: 4px; }
.cell-in input { width: 78px; text-align: right; padding: 5px 7px; font-family: var(--mono); transition: background .3s, border-color .3s; }
.cell-in .cur { color: var(--muted); font-size: 12px; }
.cell-in.low input { border-color: var(--bad); background: var(--bad-soft); }
.cell-in input.saving { background: #fffbe6; }
.cell-in input.saved { background: var(--accent-soft); border-color: var(--accent); }
td.active-cell .cell-in input { border-color: #9fcfc3; font-weight: 700; }

.st { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; white-space: nowrap; }
.st.ok { color: var(--accent); }
.st.bad { color: var(--bad); font-weight: 600; cursor: help; }
.st.off { color: var(--muted); }
.st.load { color: var(--muted); font-size: 12px; }
.spin { width: 11px; height: 11px; border: 2px solid #cfc9be; border-top-color: var(--accent); border-radius: 50%; display: inline-block; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.cmp { color: #2f5bd8; font-weight: 700; font-family: var(--mono); }
.sched-sel { padding: 4px 6px; font-size: 12px; max-width: 170px; margin-bottom: 3px; }

.bulkbar {
  display: none; align-items: center; gap: 10px; flex-wrap: wrap; position: sticky; top: 8px; z-index: 20;
  background: var(--ink); color: #f4f2ee; padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
}
.bulkbar.open { display: flex; }
.bulkbar input, .bulkbar select { padding: 5px 8px; font-size: 13px; }
.bulkbar input { width: 92px; }
.bulkbar .bgroup { display: inline-flex; align-items: center; gap: 6px; }
.bulkbar .blabel { font-size: 12px; color: #a9a296; }
.bulkbar .spacer { flex: 1; }
.bulkbar .btn:not(.primary) { background: #34312c; color: #f4f2ee; border-color: #4a463f; }
.bulkbar .btn.danger { color: #ff9d94; }
.modal.wide { max-width: 820px; }
.nowrap { white-space: nowrap; }

/* ===== v3: режим наблюдения ===== */
.st.watch { color: #2f5bd8; cursor: help; }
.actual .val.neutral { background: #eef1fb; color: #2f3c66; }
.cell-in input::placeholder { color: #b9b2a6; }
#view { padding: 7px 9px; }
.table-wrap { overflow-x: auto; }

/* ===== v3.1: компактная таблица, помещается на экран ноутбука ===== */
main { padding: 16px 14px 60px; }
table.items { font-size: 13px; }
table.items th, table.items td { padding: 7px 6px; }
table.items th { font-size: 10.5px; letter-spacing: .3px; }
table.items th:first-child, table.items td:first-child { padding-left: 12px; }
table.items .c-sel { width: 30px; }
table.items .c-title { max-width: 250px; }
table.items .title { max-width: 250px; font-size: 13.5px; }
table.items .idline { gap: 6px; white-space: nowrap; }
table.items .city { max-width: 140px; overflow: hidden; text-overflow: ellipsis; display: inline-block; vertical-align: bottom; }
table.items .cell-in input { width: 62px; padding: 5px 6px; }
table.items .sched-sel { max-width: 132px; font-size: 12px; }
table.items .c-sched .small { font-size: 11px; }
table.items .mode { font-size: 11px; padding: 1px 6px; }
table.items .actual .val { padding: 1px 6px; }
table.items .actual .small { font-size: 11px; }
table.items .st { font-size: 12.5px; }
table.items .c-act { width: 70px; }
.btn.icon { padding: 4px 8px; min-width: 28px; justify-content: center; }
.menu { position: relative; }
.menu-pop {
  display: none; position: fixed; z-index: 60; width: 200px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 32px rgba(0,0,0,.16); padding: 4px;
}
.menu-pop.open { display: block; }
.menu-pop button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 7px; font: inherit; font-size: 13px; cursor: pointer; color: var(--ink); }
.menu-pop button:hover { background: #f4f2ee; }
.menu-pop button.danger { color: var(--bad); }
.stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat { padding: 10px 12px; }
.stat .v { font-size: 20px; }
table.items .sched-sel { max-width: 146px; }
@media (max-width: 1350px) {
  table.items .c-title, table.items .title { max-width: 230px; }
  table.items .cell-in input { width: 56px; }
}
@media (max-width: 1500px) { .toolbar .hint { display: none; } }

[hidden] { display: none !important; }
.brand-mark { background: linear-gradient(90deg, #23306B 50%, #F2B705 50%) !important; color: transparent !important; border-radius: 50% !important; box-shadow: inset 0 0 0 2px #23306B; }
a.brand { text-decoration: none; color: inherit; }
