:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1b1f24;
  --muted: #5f6b7a;
  --line: #dfe3e8;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --accent-soft: #e7f0fe;
  --danger: #c62828;
  --ok: #2e7d32;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 6%);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1b2027;
    --text: #e8ebef;
    --muted: #9aa5b1;
    --line: #2d343d;
    --accent: #4c8dff;
    --accent-text: #0b1020;
    --accent-soft: #1d2a40;
    --danger: #ff6b6b;
    --ok: #66bb6a;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
code { font-size: 0.9em; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.error { color: var(--danger); margin: 0; }
.grow { flex: 1; }

/* Top bar */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px max(16px, env(safe-area-inset-left));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 600; }
.who { display: flex; align-items: center; gap: 12px; min-width: 0; }
.org { font-weight: 600; }
.email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }

main { max-width: 1100px; margin: 0 auto; padding: 16px; }
.screen.narrow { max-width: 480px; margin: 8vh auto 0; }
h1 { font-size: 1.5rem; margin: 0 0 12px; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* Controls */
button {
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 10px; padding: 9px 14px; cursor: pointer; min-height: 40px;
}
button:hover { border-color: var(--muted); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.big { width: 100%; padding: 12px; }
button.link { border: 0; background: none; padding: 4px; min-height: 0; color: var(--accent); }
button.danger { color: var(--danger); }
button.icon { border: 0; background: none; font-size: 1.1rem; padding: 6px 10px; }
button:disabled { opacity: 0.55; cursor: default; }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); font-weight: 400;
}
textarea { resize: vertical; min-height: 120px; }

/* Tabs, toolbar, stage chips */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; overflow-x: auto; }
.tabs button {
  border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: none;
  padding: 10px 14px; font-weight: 600; color: var(--muted); white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.note {
  margin: 0 0 12px; padding: 10px 12px; border-radius: 10px;
  background: var(--accent-soft); font-size: 0.925rem;
}
.toolbar { display: flex; gap: 8px; margin-bottom: 10px; }
.toolbar input { flex: 1; min-width: 0; }
.toolbar button { white-space: nowrap; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 10px; scrollbar-width: thin; }
.chips button {
  border-radius: 999px; padding: 5px 12px; min-height: 34px; white-space: nowrap; font-size: 0.925rem;
}
.chips button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chips .count { opacity: 0.75; margin-left: 4px; }

/* Template list */
.list { display: flex; flex-direction: column; gap: 18px; }
.group h3 { font-size: 0.95rem; margin: 0 0 8px; color: var(--muted); font-weight: 600; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.card {
  display: flex; gap: 12px; text-align: left; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; box-shadow: var(--shadow); width: 100%; min-height: 0;
}
.card:disabled { opacity: 1; cursor: default; }
.card-row { display: flex; gap: 4px; align-items: stretch; }
.card-row .card { flex: 1; min-width: 0; }
.card-row .order { display: flex; flex-direction: column; justify-content: center; }
.card-row .order button:disabled { opacity: 0.25; }
.card .thumb {
  width: 64px; height: 64px; flex: none; border-radius: 8px; object-fit: cover; background: var(--bg);
}
.card .body { min-width: 0; flex: 1; }
.card .name { font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .text {
  color: var(--muted); font-size: 0.9rem; margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card .meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; font-size: 0.8rem; color: var(--muted); }
.badge { border: 1px solid var(--line); border-radius: 999px; padding: 0 8px; }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }

/* Editor dialog */
dialog {
  border: 0; padding: 0; border-radius: 16px; width: min(760px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px); background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgb(0 0 0 / 45%); }
.editor { display: flex; flex-direction: column; max-height: calc(100dvh - 32px); }
.editor-head, .editor-foot {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-color: var(--line);
}
.editor-head { border-bottom: 1px solid var(--line); }
.editor-head h2 { margin: 0; font-size: 1.15rem; flex: 1; }
.editor-foot { border-top: 1px solid var(--line); flex-wrap: wrap; }
.editor-foot .error { flex-basis: 100%; order: -1; }
.editor-body { overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > label { min-width: 180px; }
.seg { display: flex; gap: 8px; border: 0; padding: 0; margin: 0; flex-wrap: wrap; }
.seg label {
  flex-direction: row; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; cursor: pointer; flex: 1; min-width: 200px;
}
.seg label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.seg input, .check input { width: auto; }
.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }

.photos-head { display: flex; flex-direction: column; gap: 2px; font-weight: 500; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.photo, .add-photo {
  position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden;
  border: 1px solid var(--line); background: var(--bg);
}
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.photo[draggable="true"] { cursor: grab; }
.photo.dragging { opacity: 0.4; }
.photo.over { outline: 3px solid var(--accent); outline-offset: -3px; }
.photo .n {
  position: absolute; top: 4px; left: 4px; background: rgb(0 0 0 / 60%); color: #fff;
  border-radius: 6px; padding: 0 6px; font-size: 0.8rem;
}
.photo .tools { position: absolute; inset: auto 0 0 0; display: flex; justify-content: space-between; padding: 4px; gap: 4px; }
.photo .tools button {
  min-height: 30px; padding: 2px 8px; border: 0; border-radius: 8px;
  background: rgb(0 0 0 / 60%); color: #fff; font-size: 0.85rem;
}
.photo .busy {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgb(0 0 0 / 45%); color: #fff; font-size: 0.85rem; text-align: center; padding: 6px;
}
.add-photo {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  border: 2px dashed var(--line); color: var(--muted); cursor: pointer; font-size: 0.85rem; text-align: center; padding: 6px;
}
.add-photo.over, .photos.over .add-photo { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.add-photo b { font-size: 1.6rem; line-height: 1; }

/* Photos from the catalog (platform/docs/22 §2.2) */
.photo .flag {
  position: absolute; top: 4px; right: 4px; border-radius: 6px; padding: 0 6px; font-size: 0.75rem;
  background: var(--danger); color: #fff;
}
.photo .flag.cat { background: rgb(0 0 0 / 60%); }
.photo.stale { outline: 3px solid var(--danger); outline-offset: -3px; }
.photo.stale img { opacity: 0.5; }
#picker { width: min(960px, calc(100vw - 32px)); }
.picks { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.pick {
  position: relative; aspect-ratio: 1; padding: 0; border-radius: 10px; overflow: hidden; min-height: 0;
  border: 2px solid var(--line); background: var(--bg); display: block; text-align: left;
}
.pick img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.pick .cap {
  position: absolute; inset: auto 0 0 0; padding: 4px 6px; font-size: 0.75rem; line-height: 1.25;
  background: rgb(0 0 0 / 62%); color: #fff; max-height: 3.9em; overflow: hidden;
}
.pick .n {
  position: absolute; top: 4px; left: 4px; background: var(--accent); color: var(--accent-text);
  border-radius: 999px; min-width: 24px; text-align: center; font-weight: 700;
}
.pick.on { border-color: var(--accent); outline: 3px solid var(--accent); outline-offset: -3px; }
.pick:disabled { opacity: 0.45; cursor: default; }

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 20;
  max-width: calc(100vw - 32px);
}

/* Phone: the editor takes the whole screen, buttons stay reachable */
@media (max-width: 640px) {
  main { padding: 12px; }
  .brand .muted { display: none; }
  .toolbar { flex-wrap: wrap; }
  .toolbar button { flex: 1; }
  .cards { grid-template-columns: 1fr; }
  dialog { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; margin: 0; }
  .editor { height: 100dvh; max-height: 100dvh; }
  .editor-body { flex: 1; }
  .editor-foot { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .photos { grid-template-columns: repeat(3, 1fr); }
}

/* Company keys on the server (17-proxy.md §5): under the list, admins only. */
.keys { margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--line); }
.keys h2 { font-size: 1.125rem; margin: 0 0 8px; }
.keys input[type=password] { flex: 1; min-width: 0; }
.keys .key { gap: 6px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.keys .key p, .keys .key .toolbar { margin: 0; }
.key-hint ol { margin: 6px 0; padding-left: 22px; }
.key-hint summary { cursor: pointer; color: var(--accent); }
.key-status { font-size: 0.925rem; }
.key-status.ok { color: var(--ok); }
.key-status.bad { color: var(--danger); }

/* Company languages (19-company-languages.md): a row per language, admins only. */
.langs { display: flex; flex-direction: column; gap: 12px; max-width: 760px; }
.lang-list { display: flex; flex-direction: column; gap: 8px; }
.lang-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 8px 8px 14px;
}
.lang-row .check { display: inline-flex; white-space: nowrap; }
.lang-move { display: inline-flex; }
.lang-move button:disabled { opacity: .3; }
.langs select { flex: 1; min-width: 0; }
@media (max-width: 640px) {
  .lang-row strong { flex-basis: 100%; }
}

/* «💬 Відгук»: a short form, not the full-width editor */
#feedback { width: min(560px, 100vw); }
#feedback .seg label { flex: 1 1 auto; }

/* The menu (nav.js, Oleg 11.10 «как в CRM»): a rail on a laptop, a tab bar on a phone. */
.rail {
  position: fixed; left: 0; top: 0; bottom: 0; z-index: 4; width: 88px;
  display: flex; flex-direction: column; gap: 2px; padding: 64px 6px 12px;
  background: var(--surface); border-right: 1px solid var(--line);
}
.rail-items { display: flex; flex-direction: column; gap: 2px; }
.rail .spacer { flex: 1; }
.rail-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 8px 2px; min-height: 0; border: 0; border-radius: 10px; background: none;
  color: var(--muted); font-size: 0.72rem; line-height: 1.15; text-align: center; text-decoration: none;
}
.rail-item:hover { background: var(--bg); color: var(--text); }
.rail-item.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.ico { display: inline-flex; }
body.with-menu .bar { padding-left: 104px; }
body.with-menu main { padding-left: 104px; max-width: none; }
body.with-menu main > .screen { max-width: 1100px; margin-left: auto; margin-right: auto; }
.tabbar { display: none; }

.home .lead { margin: 0 0 16px; color: var(--muted); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left;
  padding: 16px; min-height: 84px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow); color: var(--text); text-decoration: none;
}
.tile:hover { border-color: var(--accent); }
#section-title { margin-bottom: 8px; }

dialog.sheet { width: min(420px, 100vw); padding: 0; border: 0; border-radius: var(--radius); background: var(--surface); color: var(--text); }
dialog.sheet::backdrop { background: rgb(0 0 0 / 35%); }
.more-items { display: flex; flex-direction: column; padding: 4px 8px 8px; }
.more-item {
  display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 0 12px;
  border: 0; border-radius: 10px; background: none; color: var(--text); text-decoration: none; text-align: left;
}
.more-item:hover { background: var(--bg); }
.more-item.on { color: var(--accent); font-weight: 600; }
.more-item.danger { color: var(--danger); }

@media (max-width: 900px) {
  .rail { display: none; }
  body.with-menu .bar { padding-left: max(16px, env(safe-area-inset-left)); }
  body.with-menu main { padding-left: 16px; padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
  .tabbar:not([hidden]) {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--line);
  }
  .tab-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    min-height: 54px; padding: 6px 2px; border: 0; background: none; border-radius: 10px;
    color: var(--muted); font-size: 0.7rem; text-decoration: none;
  }
  .tab-item.on { color: var(--accent); font-weight: 600; }
  dialog.sheet { margin: auto 0 0; width: 100vw; max-width: 100vw; height: auto; max-height: 85dvh; border-radius: var(--radius) var(--radius) 0 0; padding-bottom: env(safe-area-inset-bottom); }
  body.with-menu .toast { bottom: calc(76px + env(safe-area-inset-bottom)); }
}

/* «Працівники» (team.js) */
.invite { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.invite h2 { font-size: 1.05rem; margin: 0; }
.invite ol { margin: 0; padding-left: 1.3rem; color: var(--muted); }
.team-qr { margin: 0; display: flex; align-items: center; gap: 12px; }
.team-qr img { width: 231px; height: 231px; image-rendering: pixelated; background: #fff; border-radius: 8px; flex: none; }
#team-link { flex: 1; min-width: 200px; font-size: 0.85rem; }
a.button {
  display: inline-flex; align-items: center; border: 1px solid var(--line); background: var(--surface);
  border-radius: 10px; padding: 9px 14px; min-height: 40px; color: var(--text); text-decoration: none;
}
.team-add input[type="email"] { flex: 2; min-width: 200px; }
.team-add input[type="text"] { flex: 1; min-width: 140px; }
.people { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.person { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.person.is-off { opacity: 0.7; }
.person-head {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; width: 100%;
  border: 0; background: none; text-align: left; padding: 12px 14px;
}
.person-name { font-weight: 600; }
.badges { display: inline-flex; gap: 6px; }
.badge { font-size: 0.75rem; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.badge.off { background: var(--bg); color: var(--danger); }
.person-edit { padding: 0 14px 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.person-edit label:not(.check) { display: flex; flex-direction: column; gap: 4px; }
.person-edit label .small { font-weight: 400; }

/* «Пакет компанії» (package.js, 72 R6) and the D12 switch on «Швидкі відповіді компанії» */
.package .card { flex-direction: column; gap: 8px; }
.package .card p { margin: 0; }
.package .card .toolbar { margin: 4px 0 0; flex-wrap: wrap; }
.package h2 { font-size: 1.125rem; margin: 22px 0 0; }
.package .note.warn, .package .badge.warn { color: var(--danger); }
.package .person-head { flex-wrap: wrap; }
a.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.override { margin: 0 0 12px; }
.override .small { display: block; margin-top: 2px; }
