:root {
  --bg: #f3f7fb;
  --surface: #ffffff;
  --surface-2: #f6f9fc;
  --border: #dde5ee;
  --text: #17293d;
  --muted: #5f7186;
  --primary: #1a6fd4;
  --primary-dark: #1257ad;
  --primary-soft: #e3eefb;
  --ok: #1f9d55;
  --ok-soft: #e2f5ea;
  --warn: #d98a00;
  --warn-soft: #fff3dc;
  --danger: #d6404b;
  --danger-soft: #fde7e9;
  --grey-soft: #eef1f5;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(23,41,61,.06), 0 4px 14px rgba(23,41,61,.06);
  --nav-h: 64px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Heebo', 'Assistant', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 700; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.bold { font-weight: 700; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.col { display: flex; flex-direction: column; gap: 8px; }
.grow { flex: 1; }
.mt { margin-top: 12px; } .mb { margin-bottom: 12px; }
.hide { display: none !important; }

/* ---- Layout ---- */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 10px 16px; display: flex; align-items: center; gap: 12px;
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; }
.topbar .logo { width: 34px; height: 34px; border-radius: 10px; background: var(--primary); color: #fff; display: grid; place-items: center; font-size: 18px; }
.topbar .who { margin-inline-start: auto; text-align: left; line-height: 1.2; }
.topbar .who .name { font-weight: 600; font-size: .9rem; }
.topbar .who .role { font-size: .75rem; color: var(--muted); }
.main { flex: 1; padding: 16px; padding-bottom: calc(var(--nav-h) + 24px); max-width: 1180px; width: 100%; margin: 0 auto; }
.nav {
  position: fixed; bottom: 0; right: 0; left: 0; height: var(--nav-h); background: var(--surface); border-top: 1px solid var(--border);
  display: flex; z-index: 20; padding-bottom: env(safe-area-inset-bottom);
}
.nav button {
  flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: .72rem; cursor: pointer; padding: 6px 2px;
}
.nav button .ico { font-size: 20px; line-height: 1; }
.nav button.active { color: var(--primary); font-weight: 700; }
@media (min-width: 900px) {
  .nav { position: sticky; top: 55px; bottom: auto; height: auto; border-top: 0; border-bottom: 1px solid var(--border); justify-content: center; gap: 4px; padding: 0 16px; }
  .nav button { flex: 0 0 auto; flex-direction: row; gap: 8px; font-size: .95rem; padding: 12px 18px; border-bottom: 3px solid transparent; }
  .nav button.active { border-bottom-color: var(--primary); }
  .nav button .ico { font-size: 18px; }
  .main { padding: 24px; padding-bottom: 40px; }
}

/* ---- Cards ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 12px; }
.card.flat { box-shadow: none; }
.card.open { border-inline-start: 5px solid var(--danger); }
.card.covered { border-inline-start: 5px solid var(--ok); }
.card.nocover { border-inline-start: 5px solid #b8c2cf; opacity: .85; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 20px 0 10px; }
.section-title:first-child { margin-top: 0; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border); background: var(--surface);
  border-radius: 10px; padding: 9px 14px; cursor: pointer; font-weight: 600; font-size: .92rem; transition: background .15s, transform .05s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.btn.ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.btn.wa { background: #25d366; border-color: #25d366; color: #fff; }
.btn.sm { padding: 5px 10px; font-size: .82rem; border-radius: 8px; }
.btn.lg { padding: 13px 20px; font-size: 1rem; border-radius: 12px; }
.btn.block { width: 100%; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--primary); }
.fab {
  position: fixed; bottom: calc(var(--nav-h) + 16px); left: 16px; z-index: 15; background: var(--danger); color: #fff; border: 0; border-radius: 999px;
  padding: 14px 20px; font-weight: 700; font-size: 1rem; box-shadow: 0 6px 20px rgba(214,64,75,.4); cursor: pointer; display: flex; gap: 8px; align-items: center;
}
@media (min-width: 900px) { .fab { bottom: 24px; } }

/* ---- Chips / badges ---- */
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; background: var(--grey-soft); color: var(--muted); }
.chip.morning { background: #fff5d6; color: #8a5a00; }
.chip.evening { background: #e6e6fb; color: #3d3d9c; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.primary { background: var(--primary-soft); color: var(--primary-dark); }
.chip.sub { background: var(--ok-soft); color: #14703c; }
.chip.absent { background: var(--danger-soft); color: var(--danger); text-decoration: line-through; }
.chip.clickable { cursor: pointer; }
.chip.clickable:hover { filter: brightness(.95); }

.suggest { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.suggest .s {
  border: 1px solid var(--border); border-radius: 12px; padding: 8px 12px; cursor: pointer; background: var(--surface-2); display: flex; flex-direction: column; gap: 3px; min-width: 150px;
}
.suggest .s:hover { border-color: var(--primary); background: var(--primary-soft); }
.suggest .s .n { font-weight: 700; }
.suggest .s .t { font-size: .74rem; color: var(--muted); }
.suggest .s.na { opacity: .55; cursor: default; }
.suggest .s.na:hover { border-color: var(--border); background: var(--surface-2); }

/* ---- Forms ---- */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field label { font-size: .85rem; font-weight: 600; color: var(--muted); }
.input, select.input, textarea.input {
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; background: var(--surface); width: 100%; outline: none;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea.input { min-height: 70px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 8px 14px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button.active { background: var(--primary); color: #fff; }

/* ---- Modal / sheet ---- */
.overlay { position: fixed; inset: 0; background: rgba(23,41,61,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 18px 18px 28px; animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 700px) { .overlay { align-items: center; } .sheet { border-radius: 18px; } }
.sheet h3 { margin-bottom: 12px; }
.sheet .actions { display: flex; gap: 8px; justify-content: flex-start; margin-top: 16px; flex-wrap: wrap; }

/* ---- Toast ---- */
.toast { position: fixed; bottom: calc(var(--nav-h) + 20px); right: 50%; transform: translateX(50%); background: #17293d; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 100; box-shadow: var(--shadow); font-weight: 600; }
.toast.err { background: var(--danger); }

/* ---- Week board ---- */
.weeknav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.board-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.board { border-collapse: collapse; width: 100%; min-width: 640px; }
.board th, .board td { border-bottom: 1px solid var(--border); border-inline-start: 1px solid var(--border); vertical-align: top; padding: 0; }
.board th { background: var(--surface-2); padding: 8px 6px; font-size: .85rem; position: sticky; top: 0; z-index: 2; }
.board th:first-child, .board td:first-child { border-inline-start: 0; position: sticky; right: 0; background: var(--surface); z-index: 1; min-width: 120px; padding: 8px; font-weight: 700; }
.board th.today { background: var(--primary-soft); color: var(--primary-dark); }
.cell { padding: 6px; min-height: 40px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; min-width: 100px; }
.cell:hover { background: var(--primary-soft); }
.cell.closed { background: repeating-linear-gradient(45deg, #f7f9fb, #f7f9fb 6px, #eef2f6 6px, #eef2f6 12px); cursor: default; }
.cell.closed:hover { background: repeating-linear-gradient(45deg, #f7f9fb, #f7f9fb 6px, #eef2f6 6px, #eef2f6 12px); }
.cell .lbl { font-size: .7rem; color: var(--muted); font-weight: 700; }
.cell .name { font-size: .8rem; padding: 2px 6px; border-radius: 6px; background: var(--grey-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell .name.absent { background: var(--danger-soft); color: var(--danger); text-decoration: line-through; }
.cell .name.sub { background: var(--ok-soft); color: #14703c; }
.cell .name.need { background: var(--danger); color: #fff; font-weight: 700; }
.cell .name.nocover { background: var(--grey-soft); color: var(--muted); }
.cell .name.empty { background: transparent; color: #b8c2cf; }
.daytabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 10px; }
.daytabs button { border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 6px 10px; cursor: pointer; white-space: nowrap; font-size: .85rem; }
.daytabs button.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---- Month calendar (constraints) ---- */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .dh { text-align: center; font-size: .75rem; color: var(--muted); font-weight: 700; padding: 4px 0; }
.cal .d { border: 1px solid var(--border); border-radius: 10px; min-height: 64px; padding: 4px; background: var(--surface); display: flex; flex-direction: column; gap: 3px; }
.cal .d.off { background: var(--surface-2); opacity: .5; }
.cal .d.past { opacity: .5; }
.cal .d .num { font-size: .75rem; font-weight: 700; color: var(--muted); }
.cal .d.today .num { color: var(--primary); }
.cal .d .sh { font-size: .7rem; border-radius: 6px; padding: 2px 4px; text-align: center; cursor: pointer; background: var(--ok-soft); color: #14703c; border: 1px solid transparent; }
.cal .d .sh.na { background: var(--danger-soft); color: var(--danger); text-decoration: line-through; }
.cal .d .sh.asg { background: var(--primary); color: #fff; cursor: default; }
.cal .d .sh.lock { cursor: default; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); margin: 8px 0; }
.legend span::before { content: ''; display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-inline-end: 5px; vertical-align: -1px; }
.legend .l-ok::before { background: var(--ok-soft); border: 1px solid #bfe6cf; }
.legend .l-na::before { background: var(--danger-soft); border: 1px solid #f3c2c6; }
.legend .l-asg::before { background: var(--primary); }

/* ---- Tables ---- */
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: 8px 6px; border-bottom: 1px solid var(--border); text-align: right; }
.table th { color: var(--muted); font-weight: 600; font-size: .8rem; }
.tw { overflow-x: auto; }
.avail-grid { border-collapse: collapse; font-size: .75rem; }
.avail-grid th, .avail-grid td { border: 1px solid var(--border); padding: 2px; text-align: center; min-width: 26px; }
.avail-grid th { background: var(--surface-2); font-weight: 600; }
.avail-grid td.na { background: var(--danger-soft); color: var(--danger); }
.avail-grid td.asg { background: var(--primary); color: #fff; font-weight: 700; }
.avail-grid td.off { background: var(--surface-2); }
.avail-grid td.today { outline: 2px solid var(--primary); outline-offset: -2px; }
.avail-grid td:first-child { text-align: right; white-space: nowrap; padding: 2px 6px; font-weight: 600; position: sticky; right: 0; background: var(--surface); }

/* ---- Stats ---- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; text-align: center; }
.stat .v { font-size: 1.6rem; font-weight: 800; }
.stat .l { font-size: .78rem; color: var(--muted); }
.stat.danger .v { color: var(--danger); } .stat.ok .v { color: var(--ok); } .stat.primary .v { color: var(--primary); }

/* ---- Login ---- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #e9f1fb 0%, #f3f7fb 60%); }
.login { width: 100%; max-width: 400px; }
.login .logo-big { width: 64px; height: 64px; border-radius: 18px; background: var(--primary); color: #fff; display: grid; place-items: center; font-size: 32px; margin: 0 auto 12px; box-shadow: 0 8px 24px rgba(26,111,212,.3); }
.demo-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px; }
.demo-list button { text-align: right; font-size: .8rem; padding: 7px 10px; }

/* ---- Schedule editor ---- */
.sched-grid { display: grid; grid-template-columns: 60px repeat(2, 1fr); gap: 6px; align-items: center; }
.sched-grid .hd { font-size: .8rem; color: var(--muted); font-weight: 700; text-align: center; }
.sched-grid .dl { font-weight: 700; font-size: .9rem; }
.hours-grid { display: grid; grid-template-columns: 50px repeat(6, 1fr); gap: 4px; align-items: center; text-align: center; font-size: .8rem; }
.hours-grid .tg { border: 1px solid var(--border); border-radius: 8px; padding: 6px 2px; cursor: pointer; background: var(--surface-2); color: var(--muted); }
.hours-grid .tg.on { background: var(--primary-soft); color: var(--primary-dark); border-color: #b9d2f3; font-weight: 700; }
.hours-grid .tg.dis { opacity: .35; cursor: default; }

.list-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-dark); display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.avatar.sub, .avatar.technician { background: var(--ok-soft); color: #14703c; }
.avatar.admin { background: #fde9c8; color: #8a5a00; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.empty .big { font-size: 40px; margin-bottom: 8px; }
.spinner { text-align: center; padding: 40px; color: var(--muted); }

/* ---- Month board ---- */
.month-board .d { min-height: 78px; }
.month-board .d.has-open { border-color: #f3c2c6; background: #fffafa; }
.month-board .d:hover:not(.off) { border-color: var(--primary); }
.mb-line { font-size: .68rem; line-height: 1.25; padding: 1px 4px; border-radius: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mb-line.sub { background: var(--ok-soft); color: #14703c; }
.mb-line.need { background: var(--danger); color: #fff; font-weight: 700; }
.mb-line.nocover { background: var(--grey-soft); color: var(--muted); }
.mb-line.more { color: var(--muted); }
.mb-dot { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px; font-size: .72rem; font-weight: 700; background: var(--grey-soft); color: var(--muted); }
.mb-dot.danger { background: var(--danger); color: #fff; }
.mb-dot.ok { background: var(--ok-soft); color: #14703c; }

/* ---- System picker ---- */
.sys-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .sys-grid { grid-template-columns: 1fr; } }
.sys-card { background: var(--surface); border: 2px solid var(--border); border-radius: 16px; padding: 22px 14px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; box-shadow: var(--shadow); transition: border-color .15s, transform .05s; }
.sys-card:hover { border-color: var(--primary); }
.sys-card:active { transform: translateY(1px); }
.sys-card .big { font-size: 40px; }
