:root {
  --bg: #f3f4f7; --card: #ffffff; --text: #171a21; --muted: #6b7280; --line: #e3e6ec;
  --accent: #2563eb; --accent-soft: #e6eefe; --on-accent: #ffffff;
  --ok: #14804a; --ok-soft: #e0f5e9; --warn: #a15c00; --warn-soft: #fdf0d5; --bad: #c0271f; --bad-soft: #fde7e5;
  --grey-soft: #eceef2; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .05);
  --radius: 14px; --tab-h: 60px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #111318; --card: #1b1e25; --text: #eceef2; --muted: #9aa3b2; --line: #2b303a;
  --accent: #6d9bff; --accent-soft: #1d2a47; --on-accent: #0c1220;
  --ok: #5fd08f; --ok-soft: #153223; --warn: #f0b860; --warn-soft: #3a2c10; --bad: #ff8a80; --bad-soft: #41201d;
  --grey-soft: #262a33; --shadow: none;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; overflow-wrap: anywhere; }
h1 { font-size: 22px; margin: 0; line-height: 1.2; }
h2 { font-size: 17px; margin: 22px 0 8px; }
h3 { font-size: 15px; margin: 0; }
p { margin: 0 0 8px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.pre { white-space: pre-wrap; }
.grow { flex: 1; min-width: 0; }
.right { text-align: right; }
.hidden { display: none !important; }

/* каркас */
.shell { min-height: 100%; display: flex; }
.main { flex: 1; min-width: 0; padding: 16px 16px calc(var(--tab-h) + 28px + env(safe-area-inset-bottom)); max-width: 760px; margin: 0 auto; width: 100%; }
.main.wide { max-width: 1180px; }
.head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.head h1 { flex: 1; min-width: 140px; }
.back { border: 0; background: none; color: var(--accent); font: inherit; padding: 6px 0; cursor: pointer; }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--card); border-top: 1px solid var(--line); display: flex; z-index: 5; }
.tab { flex: 1; border: 0; background: none; color: var(--muted); font: inherit; font-size: 11px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; cursor: pointer; padding: 0 2px; position: relative; text-decoration: none; }
.tab svg { width: 22px; height: 22px; }
.tab.on { color: var(--accent); font-weight: 600; }
.side { display: none; }
.dot { position: absolute; top: 8px; left: calc(50% + 8px); min-width: 16px; height: 16px; border-radius: 8px; background: var(--bad); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; padding: 0 4px; }
:root[data-theme="dark"] .dot { color: #1b1e25; }
.devbar { background: var(--warn-soft); color: var(--warn); font-size: 13px; padding: 6px 12px; display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; }
.devbar button { border: 0; background: none; color: inherit; text-decoration: underline; font: inherit; cursor: pointer; padding: 0; }

@media (min-width: 960px) {
  .tabs { display: none; }
  .side { display: flex; flex-direction: column; gap: 2px; width: 230px; flex: none; padding: 18px 12px; background: var(--card); border-right: 1px solid var(--line); position: sticky; top: 0; height: 100vh; overflow: auto; }
  .side .brand { font-weight: 700; font-size: 17px; padding: 4px 10px 14px; }
  .side a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; color: var(--text); text-decoration: none; font-size: 15px; }
  .side a svg { width: 19px; height: 19px; color: var(--muted); flex: none; }
  .side a:hover { background: var(--grey-soft); }
  .side a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
  .side a.on svg { color: var(--accent); }
  .side .count { margin-left: auto; background: var(--bad); color: #fff; border-radius: 9px; font-size: 11px; font-weight: 700; padding: 1px 6px; }
  .main { padding: 26px 30px 40px; }
}

/* карточки и списки */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 10px; }
.card.tap { cursor: pointer; }
.card.tap:active { opacity: .8; }
.row { display: flex; align-items: center; gap: 10px; }
.row.top { align-items: flex-start; }
.row.wrap { flex-wrap: wrap; }
.stack > * + * { margin-top: 8px; }
.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 10px; overflow: hidden; }
.item { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--line); width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; font: inherit; color: inherit; text-align: left; text-decoration: none; }
.item:first-child { border-top: 0; }
button.item, a.item { cursor: pointer; }
button.item:hover, a.item:hover { background: var(--grey-soft); }
.chev { color: var(--muted); flex: none; }
.grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); margin-bottom: 10px; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; text-decoration: none; color: inherit; display: block; }
.stat b { display: block; font-size: 24px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat span { font-size: 13px; color: var(--muted); }
.stat.alert b { color: var(--bad); }
a.stat:hover { outline: 2px solid var(--accent-soft); }

/* метки статусов */
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 20px; background: var(--grey-soft); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.note { border-radius: 10px; padding: 10px 12px; font-size: 14px; background: var(--grey-soft); margin-bottom: 10px; }
.note.warn { background: var(--warn-soft); color: var(--warn); }
.note.bad { background: var(--bad-soft); color: var(--bad); }
.note.ok { background: var(--ok-soft); color: var(--ok); }
.note.info { background: var(--accent-soft); color: var(--accent); }

/* кнопки и поля */
.btn { border: 0; border-radius: 11px; padding: 11px 16px; font: inherit; font-weight: 600; cursor: pointer; background: var(--grey-soft); color: var(--text); display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; min-height: 44px; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.sm { padding: 6px 12px; min-height: 34px; font-size: 14px; border-radius: 9px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.btns.end { justify-content: flex-end; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
label.field > small { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; min-height: 44px; }
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type="checkbox"] { width: 20px; height: 20px; min-height: 0; flex: none; accent-color: var(--accent); }
.check { display: flex; align-items: center; gap: 10px; padding: 8px 0; cursor: pointer; }
.checks { max-height: 260px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; padding: 2px 12px; }
.seg { display: flex; background: var(--grey-soft); border-radius: 11px; padding: 3px; margin-bottom: 12px; }
.seg button { flex: 1; border: 0; background: none; font: inherit; font-size: 14px; padding: 8px 6px; border-radius: 9px; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--card); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters > * { flex: 1 1 140px; }
.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; background: var(--line); border-radius: 14px; transition: background .15s; }
.switch i::after { content: ""; position: absolute; width: 22px; height: 22px; border-radius: 50%; background: #fff; top: 3px; left: 3px; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked + i { background: var(--ok); }
.switch input:checked + i::after { transform: translateX(18px); }
.switch input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }

/* состояния */
.center { display: grid; place-items: center; min-height: 40vh; text-align: center; padding: 24px; }
.spinner { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; color: var(--muted); padding: 28px 16px; }
.empty b { display: block; color: var(--text); margin-bottom: 4px; }

/* всплывающие окна */
.backdrop { position: fixed; inset: 0; background: rgba(10, 12, 18, .5); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 560px; max-height: 92vh; border-radius: 18px 18px 0 0; display: flex; flex-direction: column; }
.sheet-head { display: flex; align-items: center; padding: 14px 16px 8px; gap: 10px; }
.sheet-head h3 { flex: 1; font-size: 18px; }
.sheet-x { border: 0; background: var(--grey-soft); color: var(--muted); width: 32px; height: 32px; border-radius: 50%; font-size: 18px; line-height: 1; cursor: pointer; }
.sheet-body { padding: 6px 16px 12px; overflow: auto; }
.sheet-foot { padding: 10px 16px calc(14px + env(safe-area-inset-bottom)); display: flex; gap: 8px; flex-wrap: wrap; border-top: 1px solid var(--line); }
.sheet-foot .btn { flex: 1 1 auto; }
.sheet img.preview { max-width: 100%; border-radius: 10px; display: block; margin: 0 auto; }
.sheet iframe { width: 100%; height: 62vh; border: 0; border-radius: 10px; background: #fff; }
@media (min-width: 640px) { .backdrop { align-items: center; } .sheet { border-radius: 18px; } }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + 22px + env(safe-area-inset-bottom)); background: #1f2430; color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 40; max-width: calc(100% - 32px); font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.toast.bad { background: #b3261e; }

/* график */
.daybar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.daybar .title { font-weight: 600; flex: 1; text-align: center; min-width: 150px; }
.week { display: grid; gap: 10px; }
.day-col h3 { padding: 2px 2px 8px; display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.day-col h3.today { color: var(--accent); }
.shift { background: var(--card); border-radius: 12px; box-shadow: var(--shadow); padding: 10px 12px; margin-bottom: 8px; border-left: 4px solid var(--line); cursor: pointer; }
.shift.new { border-left-color: var(--warn); }
.shift.changed { border-left-color: var(--warn); }
.shift.published { border-left-color: var(--ok); }
.shift.deleted { border-left-color: var(--bad); opacity: .65; }
.shift .time { font-weight: 700; font-variant-numeric: tabular-nums; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 20px; background: var(--grey-soft); }
.chip.wish { background: none; border: 1px dashed var(--muted); color: var(--muted); }
.chip.conflict { background: var(--bad-soft); color: var(--bad); }
@media (min-width: 1100px) { .week.seven { grid-template-columns: repeat(7, minmax(0, 1fr)); align-items: start; } .week.seven .shift { padding: 8px; font-size: 14px; } }

/* таблицы */
.table-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 10px 12px; text-align: left; border-top: 1px solid var(--line); vertical-align: top; }
thead th { border-top: 0; font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.tap { cursor: pointer; }
tr.tap:hover td { background: var(--grey-soft); }

/* переписка */
.msg { max-width: 86%; padding: 9px 12px; border-radius: 14px; background: var(--card); box-shadow: var(--shadow); margin-bottom: 8px; }
.msg.mine { margin-left: auto; background: var(--accent-soft); }
.msg .who { font-size: 12px; color: var(--muted); margin-bottom: 2px; }

/* выбор смены на день */
.opts { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.opt { border: 1.5px solid var(--line); background: var(--card); color: var(--text); border-radius: 12px; padding: 8px 6px; min-height: 56px; font: inherit; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; }
.opt b { font-size: 16px; }
.opt .small { color: var(--muted); font-variant-numeric: tabular-nums; }
.opt.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.opt.on .small { color: inherit; opacity: .85; }
.opt.off.on { background: var(--ok); border-color: var(--ok); color: var(--card); }
.opt:disabled { opacity: .6; cursor: default; }
.opt:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.userbar { display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--card); border-bottom: 1px solid var(--line); font-size: 14px; }

/* график столбиками: столбец — смена, под ней имена */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(104px, 1fr); gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 4px; }
.bcol { background: var(--card); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; min-width: 0; }
.bhead { border: 0; border-bottom: 1px solid var(--line); border-top: 3px solid var(--line); background: var(--grey-soft); color: inherit; font: inherit; width: 100%; padding: 6px 4px 7px; display: flex; flex-direction: column; align-items: center; gap: 1px; text-align: center; }
button.bhead { cursor: pointer; }
.bhead b { font-size: 16px; }
.bhead .small { color: var(--muted); font-size: 12px; }
.bcol.new .bhead, .bcol.changed .bhead { border-top-color: var(--warn); }
.bcol.published .bhead { border-top-color: var(--ok); }
.bcol.deleted { opacity: .6; }
.bcol.deleted .bhead { border-top-color: var(--bad); }
.bbody { padding: 6px; display: flex; flex-direction: column; gap: 4px; min-height: 40px; }
.bname { border: 0; background: var(--grey-soft); color: inherit; border-radius: 8px; padding: 6px 8px; font: inherit; font-size: 14px; line-height: 1.25; text-align: left; width: 100%; }
button.bname { cursor: pointer; }
button.bname:hover { outline: 2px solid var(--accent-soft); }
.bname.me { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.bname.conflict { background: var(--bad-soft); color: var(--bad); }
.bname.ghost { background: none; border: 1px dashed var(--muted); color: var(--muted); }
.bnone { color: var(--muted); text-align: center; padding: 6px 0; }
.day-block { margin-bottom: 16px; }
.day-block > .row { margin-bottom: 6px; }
.day-block h3.today { color: var(--accent); }

/* выбор смен таблицей: строка — день, столбец — смена */
table.pick { border-collapse: separate; border-spacing: 4px; table-layout: fixed; width: 100%; font-size: 13px; }
table.pick th, table.pick td { padding: 0; border: 0; text-align: center; vertical-align: middle; }
table.pick thead th { font-size: 12px; color: var(--text); font-weight: 700; line-height: 1.15; padding-bottom: 2px; white-space: normal; }
table.pick thead th span { display: block; font-weight: 400; color: var(--muted); font-size: 10px; }
table.pick td.day { text-align: left; white-space: nowrap; width: 64px; font-variant-numeric: tabular-nums; }
.cell { width: 100%; height: 42px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--card); color: var(--on-accent); font: inherit; font-size: 18px; cursor: pointer; padding: 0; }
.cell.on { background: var(--accent); border-color: var(--accent); }
.cell.off.on { background: var(--ok); border-color: var(--ok); color: var(--card); }
.cell:disabled { opacity: .55; cursor: default; }
.cell:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
