/* ---------- токены ---------- */
:root {
  color-scheme: light;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --board-bg: linear-gradient(160deg, #2b7d98 0%, #1f5684 48%, #2c3d72 100%);
  --bar-bg: rgba(0, 0, 0, .24);
  --bar-hover: rgba(255, 255, 255, .16);
  --bar-active: rgba(255, 255, 255, .26);
  --on-bar: #fff;
  --on-bar-muted: rgba(255, 255, 255, .8);
  --list-bg: #e2e6e9;
  --list-hover: #cfd5da;
  --list-text: #17394d;
  --card-bg: #fff;
  --card-hover: #f4f6f7;
  --card-text: #17394d;
  --card-shadow: 0 1px 0 rgba(9, 30, 66, .22);
  --muted: #6b808c;
  --line: #d4d9dd;
  --input-bg: #fff;
  --primary: #3f8f43;
  --primary-hover: #357a39;
  --on-primary: #fff;
  --focus: #2185d0;
  --danger: #c8333f;
  --modal-bg: #f2f4f5;
  --panel: #fff;
  --side-btn: #e2e6e9;
  --side-btn-hover: #d3d9de;
  --overdue: #e5534b;
  --soon: #e8a317;
  --done: #4f9d50;
  --ghost: rgba(9, 30, 66, .12);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --board-bg: linear-gradient(160deg, #173f52 0%, #132f4d 48%, #1a2142 100%);
    --bar-bg: rgba(0, 0, 0, .35);
    --list-bg: #1d2329;
    --list-hover: #2a323a;
    --list-text: #d8e0e6;
    --card-bg: #2a3138;
    --card-hover: #323a42;
    --card-text: #e1e7ec;
    --card-shadow: 0 1px 0 rgba(0, 0, 0, .45);
    --muted: #93a3ae;
    --line: #3a434c;
    --input-bg: #20262c;
    --modal-bg: #1d2329;
    --panel: #252c33;
    --side-btn: #2f373f;
    --side-btn-hover: #3a434c;
    --ghost: rgba(255, 255, 255, .08);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --board-bg: linear-gradient(160deg, #173f52 0%, #132f4d 48%, #1a2142 100%);
  --bar-bg: rgba(0, 0, 0, .35);
  --list-bg: #1d2329;
  --list-hover: #2a323a;
  --list-text: #d8e0e6;
  --card-bg: #2a3138;
  --card-hover: #323a42;
  --card-text: #e1e7ec;
  --card-shadow: 0 1px 0 rgba(0, 0, 0, .45);
  --muted: #93a3ae;
  --line: #3a434c;
  --input-bg: #20262c;
  --modal-bg: #1d2329;
  --panel: #252c33;
  --side-btn: #2f373f;
  --side-btn-hover: #3a434c;
  --ghost: rgba(255, 255, 255, .08);
}

/* палитра меток и аватаров — имена как у Planka */
.c-berry-red      { background: #e04556; }
.c-pumpkin-orange { background: #e8892a; }
.c-lagoon-blue    { background: #109dc0; }
.c-pink-tulip     { background: #e0629b; }
.c-bright-moss    { background: #6f9a37; }
.c-midnight-blue  { background: #2a4f86; }
.c-egg-yellow     { background: #c99a06; }
.c-wet-moss       { background: #3f8f6b; }
.c-light-mud      { background: #9a7b5b; }
.c-gun-metal      { background: #4f6475; }

/* обложки-пресеты */
.cover-dawn {
  background:
    radial-gradient(circle at 75% 30%, #ffd59a 0 18%, transparent 19%),
    linear-gradient(180deg, #f6a96b 0%, #e86f6f 45%, #7a4f9a 100%);
}

/* ---------- база ---------- */
*, *::before, *::after { box-sizing: border-box; }

:root {
  height: 100%;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--board-bg) fixed;
}

body {
  height: 100%;
  margin: 0;
  display: flex;
  flex-direction: column;
  font: 14px/1.43 var(--font);
  color: var(--card-text);
  background: transparent;
  overflow: hidden;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.i { width: 16px; height: 16px; flex: none; }
.spacer { flex: 1; }
.muted { color: var(--muted); font-weight: 400; }

/* ---------- верхняя панель ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 48px;
  padding: 0 10px 0 16px;
  background: var(--bar-bg);
  color: var(--on-bar);
}

.logo {
  color: var(--on-bar);
  text-decoration: none;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -.01em;
  margin-right: 10px;
}

.crumb { min-width: 0; max-width: 40vw; color: var(--on-bar-muted); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
a.crumb:hover { color: var(--on-bar); text-decoration: underline; }
.crumb-sep { color: var(--on-bar-muted); opacity: .6; margin: 0 2px; }

.bar-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--on-bar);
}
.bar-btn:hover { background: var(--bar-hover); }
.bar-btn.icon-only { width: 32px; padding: 0; justify-content: center; }
.call-btn { background: var(--bar-active); font-weight: 600; }

/* ---------- панель доски ---------- */
.boardbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  color: var(--on-bar);
}

.tabs { display: flex; gap: 2px; overflow-x: auto; }

.tab {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--on-bar-muted);
  text-decoration: none;
  white-space: nowrap;
}
.tab:hover { background: var(--bar-hover); color: var(--on-bar); }
.tab.active { background: var(--bar-active); color: var(--on-bar); font-weight: 600; }
.tab-add { padding: 0 8px; }

/* ---------- аватары ---------- */
.avatar {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  flex: none;
  user-select: none;
}
.avatar-sm { width: 24px; height: 24px; font-size: 10px; }
.avatar-lg { width: 32px; height: 32px; font-size: 12px; margin-left: 4px; }

.avatars { display: flex; gap: 4px; }
.avatars.stacked { gap: 0; }
.avatars.stacked .avatar + .avatar { margin-left: -5px; }
.boardbar .avatars.stacked .avatar { box-shadow: 0 0 0 2px rgba(0, 0, 0, .18); }
.card .avatars.stacked .avatar { box-shadow: 0 0 0 2px var(--card-bg); }

/* ---------- доска и колонки ---------- */
.board {
  flex: 1;
  min-height: 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 12px 12px;
}

.lists {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  height: 100%;
}

.list {
  flex: 0 0 272px;
  display: flex;
  flex-direction: column;
  max-height: 100%;
  background: var(--list-bg);
  color: var(--list-text);
  border-radius: 6px;
}

.list-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 6px 2px 12px;
  cursor: grab;
}

.list-title-text {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 3px 0;
  font-size: 14px;
  font-weight: 700;
  line-height: 24px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.list-title-form { display: none; flex: 1; min-width: 0; }
.list-header.editing .list-title-form { display: block; }
.list-header.editing .list-title-text { display: none; }
.list-title {
  display: block;
  width: 100%;
  margin: 0;
  padding: 2px 6px;
  margin-left: -6px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: inherit;
  font-size: 14px;
  font-weight: 700;
  line-height: 24px;
  text-overflow: ellipsis;
  cursor: pointer;
  -webkit-user-select: text;
  user-select: text;
}
.list-title:focus { cursor: text; background: var(--input-bg); border-color: var(--focus); outline: none; }

.list-count { color: var(--muted); font-size: 12px; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  list-style: none;
}
.icon-btn:hover { background: var(--list-hover); color: var(--list-text); }
summary::-webkit-details-marker { display: none; }

/* меню колонки на <details> */
.menu { position: relative; }
.menu > summary { cursor: pointer; }
.menu-pop {
  position: absolute;
  top: 32px;
  right: 0;
  z-index: 20;
  width: 220px;
  padding: 6px;
  background: var(--panel);
  color: var(--card-text);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(9, 30, 66, .28);
}
.menu-pop > button,
.menu-pop > form > button {
  display: block;
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  text-align: left;
}
.menu-pop > button:hover,
.menu-pop > form > button:hover { background: var(--side-btn); }
.menu-pop .danger { color: var(--danger); }

/* ---------- карточки ---------- */
.cards {
  flex: 1 1 auto;
  min-height: 6px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px 8px;
}

.card {
  padding: 6px 8px 4px;
  background: var(--card-bg);
  color: var(--card-text);
  border-radius: 4px;
  box-shadow: var(--card-shadow);
  cursor: pointer;
}
.card:hover { background: var(--card-hover); }

/* не выделять текст при перетаскивании */
.card, .list-header, .add-card > summary, .add-list > summary { -webkit-user-select: none; user-select: none; }
body.is-dragging, body.is-dragging * { -webkit-user-select: none !important; user-select: none !important; cursor: grabbing !important; }

.card-cover {
  height: 104px;
  margin: -6px -8px 6px;
  border-radius: 4px 4px 0 0;
}

.card-labels { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 4px; }

.label {
  padding: 0 6px;
  border-radius: 3px;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
}
.label-lg { font-size: 12px; line-height: 24px; padding: 0 10px; }

.card-title {
  margin-bottom: 4px;
  font-size: 14px;
  line-height: 20px;
  overflow-wrap: anywhere;
}

.card-footer {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 2px;
}
.card-footer .avatars { margin-left: auto; padding-bottom: 2px; }

.badges { display: flex; flex-wrap: wrap; gap: 2px 6px; padding-bottom: 2px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 4px;
  border-radius: 3px;
  color: var(--muted);
  font-size: 12px;
}
.badge .i { width: 14px; height: 14px; }
.badge-lg { height: 30px; padding: 0 10px; font-size: 13px; background: var(--side-btn); color: var(--card-text); }
.due-soon { background: var(--soon); color: #fff; }
.due-overdue { background: var(--overdue); color: #fff; }
.due-done, .tasks-done { background: var(--done); color: #fff; }

/* перетаскивание */
.is-ghost { opacity: .35; }
.card.is-ghost { background: var(--ghost); box-shadow: none; }
.card.is-ghost > * { visibility: hidden; }
.is-drag { transform: rotate(3deg); box-shadow: 0 10px 22px rgba(9, 30, 66, .35) !important; }
.list.is-drag { transform: rotate(2deg); }

/* ---------- формы добавления ---------- */
.add-card > summary,
.add-list > summary {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  list-style: none;
}

.add-card > summary {
  margin: 2px 8px 8px;
  padding: 6px 8px;
  border-radius: 4px;
  color: var(--muted);
}
.add-card > summary:hover { background: var(--list-hover); color: var(--list-text); }
.add-card[open] > summary,
.add-list[open] > summary { display: none; }
.add-card form { padding: 2px 8px 8px; }

.add-list {
  flex: 0 0 272px;
  border-radius: 6px;
  background: rgba(255, 255, 255, .2);
  color: var(--on-bar);
}
.add-list > summary { padding: 10px 12px; border-radius: 6px; }
.add-list > summary:hover { background: rgba(255, 255, 255, .3); }
.add-list[open] { background: var(--list-bg); color: var(--list-text); }
.add-list form { padding: 8px; }

textarea, input[type="text"], input[type="email"], input[type="password"], input[type="date"], input:not([type]) {
  display: block;
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--input-bg);
  color: var(--card-text);
  resize: vertical;
}
textarea:focus, input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 1px var(--focus); }

.form-row { display: flex; align-items: center; gap: 6px; margin-top: 6px; }

.btn-primary {
  height: 32px;
  padding: 0 14px;
  border: 0;
  border-radius: 4px;
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 600;
}
.btn-primary:hover { background: var(--primary-hover); }

/* ---------- модалка карточки ---------- */
.modal {
  width: min(768px, calc(100vw - 24px));
  max-height: calc(100% - 48px);
  margin: 24px auto auto;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: var(--modal-bg);
  color: var(--card-text);
  box-shadow: 0 16px 48px rgba(0, 0, 0, .4);
}
.modal { overflow-x: hidden; } /* никакой горизонтальной прокрутки внутри карточки */
.modal::backdrop { background: rgba(0, 0, 0, .55); }

.cm-cover { height: 140px; border-radius: 8px 8px 0 0; }

.cm-head {
  display: grid;
  grid-template-columns: 20px 1fr 32px;
  gap: 10px;
  align-items: start;
  padding: 18px 16px 6px 20px;
}
.cm-head > .i { margin-top: 5px; color: var(--muted); }
.cm-title-form { margin: 0; }
textarea.cm-title {
  display: block;
  width: 100%;
  margin: -4px 0 0 -7px;
  padding: 3px 6px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--card-text);
  font-size: 20px;
  line-height: 26px;
  font-weight: 700;
  resize: none;
  overflow: hidden;
  field-sizing: content;
}
textarea.cm-title:hover { background: var(--side-btn); }
textarea.cm-title:focus { background: var(--input-bg); border-color: var(--focus); box-shadow: none; }
.cm-sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.cm-sub b { color: var(--card-text); font-weight: 600; }
.cm-close { width: 32px; height: 32px; }

.cm-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 168px;
  gap: 20px;
  padding: 6px 20px 22px 50px;
}

.cm-meta { display: flex; flex-wrap: wrap; gap: 16px 24px; margin-bottom: 18px; }

.cm h4 {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.cm-section { margin-bottom: 22px; }
.cm-section h3 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 10px -30px;
  font-size: 15px;
  font-weight: 700;
}
.cm-section h3 .i { width: 20px; height: 20px; color: var(--muted); }

.cm-desc {
  padding: 10px 12px;
  background: var(--panel);
  border-radius: 6px;
  white-space: pre-wrap;
}
.cm-desc.empty { color: var(--muted); background: var(--side-btn); }

.checklist progress {
  display: block;
  width: 100%;
  height: 8px;
  margin-bottom: 8px;
  border: 0;
  border-radius: 4px;
  overflow: hidden;
  background: var(--side-btn);
  accent-color: var(--done);
}
.checklist progress::-webkit-progress-bar { background: var(--side-btn); }
.checklist progress::-webkit-progress-value { background: var(--done); }
.checklist progress::-moz-progress-bar { background: var(--done); }

.tasks { list-style: none; margin: 0; padding: 0; }
.task {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 6px 8px;
  margin-left: -8px;
  border-radius: 4px;
  cursor: pointer;
}
.task:hover { background: var(--side-btn); }
.task input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--done); }
.task.done span { color: var(--muted); text-decoration: line-through; }

.comment-form { display: grid; gap: 6px; justify-items: start; margin-bottom: 14px; }
.comments { display: grid; gap: 14px; }
.comment { display: grid; grid-template-columns: 28px 1fr; gap: 10px; }
.comment-meta { font-size: 13px; margin-bottom: 4px; }
.comment-text {
  padding: 8px 10px;
  background: var(--panel);
  border-radius: 6px;
  box-shadow: var(--card-shadow);
  overflow-wrap: anywhere;
}

.cm-side { display: flex; flex-direction: column; gap: 6px; }
.cm-side h4:not(:first-child) { margin-top: 14px; }
.side-btn {
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 4px;
  background: var(--side-btn);
  text-align: left;
}
.side-btn:hover { background: var(--side-btn-hover); }
.side-btn.danger { color: var(--danger); }

/* ---------- меню пользователя и участников ---------- */
.user-menu > summary, .members-menu > summary { list-style: none; cursor: pointer; border-radius: 50%; }
.members-menu > summary { border-radius: 16px; padding: 2px; }
.members-menu > summary:hover { background: var(--bar-hover); }
.menu-head { padding: 6px 10px 8px; font-weight: 600; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.user-menu .menu-pop { width: 260px; }
[data-push][aria-pressed="true"]::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 50%;
  background: #3fb950;
  vertical-align: 1px;
}
.push-hint { margin: 0 10px 8px; font-size: 12px; line-height: 1.4; color: var(--muted); }
.members-pop { width: 280px; padding: 12px; }
.members-pop h4 { margin: 0 0 8px; font-size: 12px; font-weight: 600; color: var(--muted); }
.member-list { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 8px; }
.member-list li { display: flex; align-items: center; gap: 8px; }
.members-pop > .btn-primary { width: 100%; }
.invite-link { margin-top: 10px; display: grid; gap: 6px; }
.invite-link input { font-size: 12px; }
.field-hint { font-size: 12px; color: var(--muted); }

/* кто сейчас на доске */
.members-menu .avatar { position: relative; }
.members-menu .avatar.is-online::after {
  content: "";
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #3fb950;
  box-shadow: 0 0 0 2px var(--panel);
}
.members-menu > summary .avatar.is-online::after { box-shadow: 0 0 0 2px #1f4f7a; }

/* ---------- звонки ---------- */
.member-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-call { color: var(--primary); }
.member-call:hover { background: var(--side-btn); color: var(--primary); }

.callbar {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 30;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 18px;
  max-width: calc(100vw - 24px);
  padding: 10px 12px 10px 16px;
  background: var(--panel);
  color: var(--card-text);
  border-radius: 14px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, .35);
}
.callbar[hidden], .incoming[hidden] { display: none; }

.callbar-info { display: flex; align-items: center; gap: 12px; min-width: 0; }
.callbar-title { font-weight: 700; white-space: nowrap; }
.callbar-people { display: flex; gap: 6px; overflow-x: auto; padding: 3px; }
.callbar-actions { display: flex; align-items: center; gap: 8px; }

.call-person { position: relative; display: inline-flex; border-radius: 50%; }
.call-person .avatar { transition: box-shadow .12s; }
.call-person.is-speaking .avatar { box-shadow: 0 0 0 3px #3fb950; }
.call-person.is-ringing .avatar { opacity: .45; animation: ring-pulse 1.6s ease-in-out infinite; }
.call-person.is-muted::after {
  content: "";
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--danger)
    linear-gradient(135deg, transparent 44%, #fff 44% 56%, transparent 56%);
  box-shadow: 0 0 0 2px var(--panel);
}

@keyframes ring-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(63, 185, 80, .55); }
  50% { box-shadow: 0 0 0 6px rgba(63, 185, 80, 0); }
}

.call-round {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: var(--side-btn);
  color: var(--card-text);
  cursor: pointer;
  list-style: none;
}
.call-round:hover { background: var(--side-btn-hover); }
.call-round .i { width: 18px; height: 18px; }
.call-round .ico-off,
.call-round[aria-pressed="true"] .ico-on { display: none; }
.call-round[aria-pressed="true"] .ico-off { display: inline; }
.call-round[aria-pressed="true"] { background: var(--danger); color: #fff; }
.call-round.hangup { background: var(--danger); color: #fff; }
.call-round.accept { background: #2f9e44; color: #fff; }
.call-round.hangup:hover, .call-round.accept:hover { filter: brightness(1.1); }

/* выбор, кого позвать — открывается вверх */
.call-add .menu-pop { top: auto; bottom: 50px; right: -8px; width: 240px; }
.call-add-pop h4 { margin: 2px 10px 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
.call-add-pop > button { display: flex; align-items: center; gap: 8px; }
.call-add-pop > button[hidden] { display: none; }

/* входящий звонок */
.incoming {
  position: fixed;
  top: calc(60px + env(safe-area-inset-top, 0px));
  right: 16px;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 20px;
  width: min(340px, calc(100vw - 32px));
  padding: 16px 16px 16px 18px;
  background: var(--panel);
  color: var(--card-text);
  border-radius: 14px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, .4);
}
#incoming-who { flex: 1; min-width: 0; }
.incoming-who { display: flex; align-items: center; gap: 12px; }
.incoming-who .avatar { animation: ring-pulse 1.6s ease-in-out infinite; }
.avatar-xl { width: 44px; height: 44px; font-size: 15px; }
.incoming-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.incoming-sub { font-size: 13px; color: var(--muted); }
.incoming-actions { display: flex; gap: 10px; }
.incoming-actions .call-round { width: 44px; height: 44px; }

@media (max-width: 640px) {
  .callbar { left: 12px; right: 12px; transform: none; justify-content: space-between; gap: 10px; }
  .incoming { left: 16px; right: 16px; width: auto; }
}

@media (prefers-reduced-motion: reduce) {
  .call-person .avatar { transition: none; }
  .call-person.is-ringing .avatar, .incoming-who .avatar { animation: none; }
}

/* ---------- страницы входа ---------- */
body.auth { overflow: auto; }
.auth-wrap {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.auth-logo { color: var(--on-bar); font-size: 26px; font-weight: 800; letter-spacing: -.01em; margin-bottom: 18px; }
.auth-card {
  width: min(400px, 100%);
  padding: 26px 28px 24px;
  background: var(--panel);
  color: var(--card-text);
  border-radius: 10px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, .3);
}
.auth-card h1 { margin: 0 0 8px; font-size: 20px; line-height: 1.3; }
.auth-lead { margin: 0 0 16px; color: var(--muted); }
.auth-lead b { color: var(--card-text); }
.auth-form { display: grid; gap: 14px; margin-top: 8px; }
.auth-form label { display: grid; gap: 5px; font-size: 13px; font-weight: 600; }
.auth-form input { font-weight: 400; font-size: 14px; }
.auth-form .btn-primary { height: 38px; margin-top: 4px; }
.auth-note { margin: 18px 0 0; font-size: 13px; color: var(--muted); }
.auth-note a, .auth-card a { color: var(--focus); }
.form-error {
  margin: 0 0 8px;
  padding: 8px 10px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
  font-size: 13px;
}

/* ---------- проекты и доски ---------- */
.page-title {
  margin: 0;
  color: var(--on-bar);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.home > .page-title { margin: 6px 0 16px; }

.home {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 16px 32px;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
  max-width: 1200px;
}

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 112px;
  padding: 12px 14px;
  border-radius: 8px;
  color: #fff;
  text-decoration: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .18);
}
a.tile:hover { filter: brightness(1.08); }
.tile-title { font-size: 16px; font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; }
.tile-foot { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; }
.tile-meta { font-size: 13px; opacity: .85; }
.tile .avatars.stacked .avatar { box-shadow: 0 0 0 2px rgba(0, 0, 0, .2); }

.bg-0 { background: linear-gradient(135deg, #2b7d98, #1f5684); }
.bg-1 { background: linear-gradient(135deg, #8e44ad, #c0507a); }
.bg-2 { background: linear-gradient(135deg, #3f8f43, #2b7d6a); }
.bg-3 { background: linear-gradient(135deg, #d9772b, #c0392b); }
.bg-4 { background: linear-gradient(135deg, #34495e, #4f6475); }
.bg-5 { background: linear-gradient(135deg, #b8860b, #d96c2b); }

.tile-new {
  justify-content: center;
  background: rgba(255, 255, 255, .18);
  box-shadow: none;
}
.tile-new > summary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 88px;
  color: var(--on-bar);
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
.tile-new > summary:hover { opacity: .85; }
.tile-new[open] { background: var(--panel); color: var(--card-text); justify-content: flex-start; }
.tile-new[open] > summary { display: none; }
.tile-form { display: grid; gap: 4px; }

/* меню «новая доска» и «⋯» у доски и проекта */
.new-board-menu, .board-menu { position: relative; }
.new-board-menu > summary, .board-menu > summary { list-style: none; cursor: pointer; }
.boardbar .page-title + .board-menu { margin-left: 4px; }
.form-pop { left: 0; right: auto; width: 280px; padding: 12px; }
.form-pop h4 { margin: 0 0 8px; font-size: 12px; font-weight: 600; color: var(--muted); }
.inline-form { display: grid; gap: 8px; }
.danger-link {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 8px 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--danger);
  text-align: left;
}
.danger-link:hover { background: var(--side-btn); }

/* ---------- редактирование в модалке ---------- */
.desc-view { cursor: pointer; }
.desc-view:hover { box-shadow: inset 0 0 0 1px var(--line); }
.cm-section:has(> .desc-edit[open]) > .desc-view { display: none; }
.desc-edit > summary {
  display: inline-block;
  margin: 6px 0 0 -6px;
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--muted);
  font-size: 13px;
  text-decoration: underline;
  cursor: pointer;
  list-style: none;
}
.desc-edit > summary:hover { background: var(--side-btn); color: var(--card-text); }
.desc-edit[open] > summary { display: none; }
.desc-edit textarea { min-height: 140px; }
.md-hint { font-size: 12px; color: var(--muted); }

/* панель кнопок Markdown */
.md-editor .md-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  margin-bottom: 4px;
}
.md-toolbar button {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
}
.md-toolbar button:hover { background: var(--side-btn); color: var(--card-text); }
.md-toolbar .i { width: 15px; height: 15px; }
.md-glyph { font: 700 15px/1 Georgia, "Times New Roman", serif; }
.md-small { font: 700 12px/1 var(--font); }
.md-strike { text-decoration: line-through; }
.md-sep { width: 1px; height: 18px; margin: 0 4px; background: var(--line); }
.comment-form .md-toolbar { width: 100%; }

/* текст в Markdown: описание и комментарии */
.cm-desc.md { white-space: normal; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md blockquote, .md pre, .md table { margin: 0 0 8px; }
.md ul, .md ol { padding-left: 22px; }
.md h1, .md h2, .md h3, .md h4 { margin: 12px 0 6px; font-size: 15px; line-height: 1.3; }
.md h1 { font-size: 18px; }
.md h2 { font-size: 16px; }
.md a { color: var(--focus); overflow-wrap: anywhere; }
.md img { display: block; max-width: 100%; max-height: 320px; margin: 6px 0; border-radius: 6px; }
.md code {
  padding: 1px 4px;
  border-radius: 3px;
  background: var(--side-btn);
  font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.md pre { padding: 8px 10px; border-radius: 6px; background: var(--side-btn); overflow-x: auto; }
.md pre code { padding: 0; background: none; }
.md blockquote { padding-left: 10px; border-left: 3px solid var(--line); color: var(--muted); }
.md table { display: block; overflow-x: auto; border-collapse: collapse; }
.md th, .md td { padding: 4px 8px; border: 1px solid var(--line); }
.md input[type="checkbox"] { margin: 0 6px 0 0; vertical-align: -2px; }
.md li:has(> input[type="checkbox"]) { list-style: none; margin-left: -18px; }

.side-menu { position: relative; }
.side-menu > summary { list-style: none; display: flex; align-items: center; cursor: pointer; }
.side-menu .menu-pop {
  top: 36px;
  left: auto;
  right: 0; /* колонка у правого края окна — раскрываемся влево, внутрь */
  width: min(260px, calc(100vw - 48px));
  max-height: 60vh;
  overflow-y: auto;
}
.picker h4 { margin: 4px 4px 8px !important; }
.picker h4 + form, .picker form + h4 { margin-top: 0; }
.picker form { display: grid; gap: 2px; }
.picker form + h4 { margin-top: 12px !important; }
.pick-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 6px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  text-align: left;
  font-size: 14px;
  cursor: pointer;
}
.pick-row:hover { background: var(--side-btn); }
.pick-row input { flex: none; width: 16px; height: 16px; margin: 0; accent-color: var(--primary); }
.pick-row.current { color: var(--muted); cursor: default; }
.pick-row.current:hover { background: transparent; }
.pick-label { flex: 1; }
.picker input[type="date"] { margin-bottom: 6px; }

.new-label { display: grid; gap: 8px; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch {
  position: relative;
  width: 28px;
  height: 22px;
  border-radius: 4px;
  cursor: pointer;
}
.swatch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.swatch:has(input:checked) { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--focus); }
.swatch:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 3px; }

.task-row { display: flex; align-items: flex-start; gap: 4px; }
.task-row .task { flex: 1; }
.task-delete { opacity: 0; flex: none; margin-top: 2px; }
.task-row:hover .task-delete, .task-delete:focus-visible { opacity: 1; }

.add-task > summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 6px 0 0 -8px;
  padding: 6px 8px;
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
}
.add-task > summary:hover { background: var(--side-btn); color: var(--card-text); }
.add-task[open] > summary { display: none; }
.add-task form { margin-top: 6px; }

@media (hover: none) {
  .task-delete { opacity: 1; }
}

/* ---------- вложения и обложки ---------- */
.card-cover-img {
  display: block;
  width: calc(100% + 16px);
  height: auto;
  max-height: 220px;
  object-fit: cover;
  background: var(--side-btn);
}
.cm-cover-img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 280px;
  object-fit: contain;
  background: var(--side-btn);
}

.att-list { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 10px; }
.att { display: flex; gap: 12px; align-items: flex-start; }
.att-thumb {
  flex: none;
  display: grid;
  place-items: center;
  width: 112px;
  height: 80px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--side-btn);
  text-decoration: none;
}
.att-thumb img { width: 100%; height: 100%; object-fit: cover; }
.att-ext { font-size: 15px; font-weight: 800; color: var(--muted); letter-spacing: .02em; }
.att-info { min-width: 0; flex: 1; padding-top: 2px; }
.att-name {
  display: block;
  color: var(--card-text);
  font-weight: 600;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.att-name:hover { text-decoration: underline; }
.att-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 2px; font-size: 13px; color: var(--muted); }
.att-badge { padding: 0 6px; border-radius: 3px; background: var(--side-btn); color: var(--card-text); font-size: 11px; font-weight: 600; }
.att-actions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; margin-left: -6px; }
.att-actions button {
  padding: 2px 6px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  text-decoration: underline;
}
.att-actions button:hover { background: var(--side-btn); color: var(--card-text); }
.att-actions .danger:hover { color: var(--danger); }

.att-upload { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.att-pick, .side-file { position: relative; }
.att-pick {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: -8px;
  padding: 6px 8px;
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
}
.att-pick:hover { background: var(--side-btn); color: var(--card-text); }
.att-pick input, .side-file input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
}
.att-pick:focus-within, .side-file:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
.side-file { display: flex; align-items: center; cursor: pointer; }
.att-hint { font-size: 12px; color: var(--muted); }
.att-progress { font-size: 13px; font-weight: 600; color: var(--primary); }

/* файлы тащат над карточкой */
#modal-body.is-drop { outline: 3px dashed var(--focus); outline-offset: -10px; border-radius: 8px; }
.md-editor textarea.is-drop-target,
.desc-view.is-drop-target { outline: 2px dashed var(--focus); outline-offset: 2px; background: color-mix(in srgb, var(--focus) 6%, var(--input-bg)); }

@media (hover: none) {
  .att-hint { display: none; }
}

/* ---------- мобильные ---------- */
@media (max-width: 640px) {
  /* iOS увеличивает страницу при фокусе на поле с шрифтом меньше 16px */
  textarea, input, select { font-size: 16px !important; }
  .crumb { max-width: 45vw; }
  .call-btn span, .boardbar .bar-btn span { display: none; }
  /* карточка на телефоне — во весь экран */
  .modal {
    width: 100vw;
    max-width: 100vw;
    height: 100%;
    max-height: 100%;
    margin: 0;
    border-radius: 0;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .cm-cover, .cm-cover-img { border-radius: 0; }
  .cm-head { position: sticky; top: 0; z-index: 2; background: var(--modal-bg); }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .tile { min-height: 96px; }
  .home { padding: 8px 12px 24px; }
  .att-thumb { width: 84px; height: 64px; }
  .list, .add-list { flex-basis: 85vw; }
  .modal { margin-top: 8px; max-height: calc(100% - 16px); }
  .cm-body { grid-template-columns: 1fr; padding: 6px 16px 18px; }
  .cm-section h3 { margin-left: 0; }
  .cm-side { display: grid; grid-template-columns: 1fr 1fr; position: relative; }
  .side-menu { position: static; }
  .side-menu .menu-pop { left: 0; right: 0; width: auto; }
  .cm-side h4 { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  .is-drag, .list.is-drag { transform: none; }
}
