:root {
  --bg: #0f1419;
  --surface: #1a222d;
  --border: #2a3544;
  --text: #e8edf4;
  --muted: #8b98a8;
  --accent: #3d9cf0;
  --accent-dim: #2563a8;
  --ok: #34c759;
  --warn: #f5a623;
  --danger: #ff453a;
  --font: "Segoe UI", system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 10% -10%, #1e2a3d 0%, var(--bg) 55%);
  color: var(--text);
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

.top {
  border-bottom: 1px solid var(--border);
  background: rgba(26, 34, 45, 0.85);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.85rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
}

.brand-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-auth {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  font-size: 0.88rem;
}

.header-user-name {
  color: var(--muted);
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

a.header-link {
  color: var(--accent);
  font-weight: 500;
}

.header-btn {
  font-size: 0.85rem;
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.2);
  color: var(--text);
  cursor: pointer;
}

.header-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.panel-narrow {
  max-width: 420px;
  margin: 0 auto;
}

.mytasks-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.mytasks-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

.mytasks-item a {
  font-weight: 600;
}

.trash-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem;
  border-radius: 8px;
  color: var(--muted);
  line-height: 0;
}

.trash-link:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.trash-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 0.2rem;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1.1rem;
  text-align: center;
}

.user-pick {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.user-pick-label {
  white-space: nowrap;
}

.user-pick select {
  min-width: 180px;
  font-size: 0.85rem;
}

.logo {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.pcard-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
}

.pcard-delete {
  flex-shrink: 0;
  padding: 0.2rem;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-radius: 6px;
  line-height: 0;
}

.pcard-delete:hover {
  color: var(--danger);
  background: rgba(255, 69, 58, 0.12);
}

.trash-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  justify-content: flex-end;
}

.pcard-kind {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--warn);
  margin-right: 0.25rem;
}

.pcard-sub {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
  margin-top: 0.25rem;
}

.pcard-meta {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.35rem;
  line-height: 1.35;
  max-width: 42ch;
}

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem;
}

.panel h1 {
  margin: 0 0 1rem;
  font-size: 1.5rem;
  font-weight: 650;
}

.panel h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.err {
  color: var(--danger);
  margin: 0.5rem 0;
}

.meta {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 1rem;
  white-space: pre-line;
}

.meta-compact {
  white-space: normal;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  line-height: 1.4;
}

.meta-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.55rem;
}

.meta-item {
  color: var(--text);
}

.meta-item .meta-k {
  color: var(--muted);
  font-size: 0.82em;
}

.meta-sep {
  color: var(--border);
  user-select: none;
  font-weight: 300;
}

.meta-coord-link {
  color: var(--accent);
  text-decoration: none;
}

.meta-coord-link:hover {
  text-decoration: underline;
}

.back {
  margin: 0 0 0.5rem;
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
}

.form-row input[type="text"] {
  flex: 1 1 200px;
  min-width: 0;
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.form-stack textarea {
  resize: vertical;
  min-height: 72px;
}

input,
select,
textarea,
button {
  font: inherit;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 0.5rem 0.65rem;
}

button {
  cursor: pointer;
  border-color: var(--accent-dim);
  background: linear-gradient(180deg, #3a7ec4 0%, var(--accent-dim) 100%);
  color: #fff;
  font-weight: 600;
}

button:hover {
  filter: brightness(1.08);
}

button.primary {
  background: linear-gradient(180deg, #3ecf7a 0%, #248a4f 100%);
  border-color: #1d6b3e;
}

.plist {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.plist .pcard {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) auto minmax(200px, 1.1fr);
  gap: 0.75rem 1rem;
  align-items: center;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  transition: border-color 0.15s;
}

.plist .pcard:hover {
  border-color: var(--accent);
}

@media (max-width: 720px) {
  .plist .pcard {
    grid-template-columns: 1fr;
    align-items: stretch;
  }
}

.pcard-left {
  min-width: 0;
}

.pcard-title {
  display: block;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  word-break: break-word;
}

.pcard-title:hover {
  text-decoration: underline;
}

.pcard-title-static {
  display: block;
  font-weight: 600;
  color: var(--text);
  word-break: break-word;
}

.pcard-mid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.5rem;
  justify-content: center;
}

.out-pill {
  font-size: 0.78rem;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.2);
  color: var(--muted);
  white-space: nowrap;
}

.out-pill .out-name {
  font-weight: 700;
  color: var(--text);
}

.out-2 {
  border-color: rgba(61, 156, 240, 0.35);
}

.out-3 {
  border-color: rgba(245, 166, 35, 0.35);
}

.pcard-right {
  min-width: 0;
  font-size: 0.85rem;
  text-align: right;
}

.pcard-st-hdr {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.pcard-st-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.35rem 0.65rem;
  margin-top: 0.2rem;
}

.pcard-st-k {
  color: var(--muted);
}

.pcard-st-v {
  color: var(--text);
  font-weight: 500;
  max-width: 100%;
  word-break: break-word;
}

@media (max-width: 720px) {
  .pcard-right {
    text-align: left;
  }
  .pcard-st-row {
    justify-content: flex-start;
  }
}

.grid {
  display: grid;
  gap: 1rem;
}

@media (min-width: 800px) {
  .grid {
    grid-template-columns: 1fr 1fr;
  }
  .span2 {
    grid-column: 1 / -1;
  }
  .project-grid .project-chain-card,
  .project-grid .project-msg-card {
    min-height: min(65vh, 560px);
  }
}

.project-msg-card {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 0;
}

.project-sync-heading {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.project-chat-object {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.project-object-chat {
  display: flex;
  flex-direction: column;
  height: clamp(10.5rem, 28vh, 17.5rem);
  max-height: 17.5rem;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.12);
}

.object-msg-feed {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 0.5rem 0.55rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.object-msg-row {
  max-width: 92%;
  padding: 0.4rem 0.6rem 0.45rem;
  border-radius: 12px;
  line-height: 1.35;
}

.object-msg-in {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.object-msg-out {
  align-self: flex-end;
  background: rgba(61, 156, 240, 0.18);
  border: 1px solid rgba(61, 156, 240, 0.35);
}

.object-msg-meta {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.2rem;
  letter-spacing: 0.02em;
}

.object-msg-text {
  font-size: 0.88rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.object-msg-compose {
  display: flex;
  flex-direction: row;
  gap: 0.4rem;
  align-items: flex-end;
  padding: 0.45rem 0.5rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: rgba(0, 0, 0, 0.2);
}

.object-msg-compose textarea {
  flex: 1 1 auto;
  min-height: 2.4rem;
  max-height: 5rem;
  resize: none;
  margin: 0;
}

.object-msg-send {
  flex-shrink: 0;
  width: 2.35rem;
  height: 2.35rem;
  padding: 0;
  border-radius: 50%;
  font-size: 0.95rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 1px solid var(--border);
  background: rgba(61, 156, 240, 0.25);
  color: var(--text, #e8e8e8);
}

.object-msg-send:hover {
  background: rgba(61, 156, 240, 0.4);
}

.project-stage-stack {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-top: 0.35rem;
  border-top: 1px solid var(--border);
}

.project-stage-stack .msg-section-hdr {
  margin-top: 0.35rem;
}

.mlist-msg-panel {
  max-height: min(36vh, 320px);
  overflow-y: auto;
  margin-bottom: 0.75rem;
  flex: 1 1 auto;
  min-height: 0;
}

.form-msg-stage {
  flex-shrink: 0;
}

@media (max-width: 799px) {
  .wrap {
    padding: 0.8rem;
  }

  .grid.project-grid {
    gap: 0.75rem;
  }

  .project-grid .project-chain-card,
  .project-grid .project-msg-card,
  .project-grid .card.span2 {
    min-height: auto;
    padding: 0.8rem;
  }

  .project-sync-heading {
    font-size: 0.95rem;
    margin-bottom: 0.45rem;
  }

  .chain-progress {
    margin-bottom: 1rem;
  }

  .tlist.tlist-chain {
    max-height: none;
  }

  .project-object-chat {
    height: clamp(11rem, 42vh, 15.5rem);
    max-height: 15.5rem;
  }

  .object-msg-feed {
    padding: 0.45rem 0.45rem;
  }

  .object-msg-row {
    max-width: 96%;
  }

  .object-msg-meta {
    font-size: 0.66rem;
  }

  .project-stage-stack {
    padding-top: 0.5rem;
  }

  .stage-actions-wrap .btn-mini {
    flex: 1 1 calc(50% - 0.25rem);
    text-align: center;
  }

  .mlist-msg-panel {
    max-height: min(45vh, 300px);
    margin-bottom: 0.55rem;
  }

  .form-msg-stage textarea {
    min-height: 62px;
  }

  .form-msg-stage button {
    width: 100%;
  }

  .project-grid .span2 .form-row {
    align-items: stretch;
    gap: 0.45rem;
  }

  .project-grid .span2 .form-row input[type="file"] {
    width: 100%;
  }

  .project-grid .span2 .form-row button {
    width: 100%;
  }
}

@media (max-width: 520px) {
  .panel h1 {
    font-size: 1.22rem;
    margin-bottom: 0.75rem;
  }

  .card {
    padding: 0.72rem;
    border-radius: 10px;
  }

  .chain-progress {
    padding: 0.55rem 0.6rem;
    margin-bottom: 0.8rem;
  }

  .chain-progress-top {
    font-size: 0.9rem;
  }

  .chain-progress-subtitle {
    font-size: 0.78rem;
    margin-bottom: 0.42rem;
  }

  .chain-progress-legend {
    font-size: 0.72rem;
  }

  .task-row-inner-compact {
    padding: 0.32rem 0.45rem;
  }

  .task-row-overview .task-row-main {
    font-size: 0.82rem;
  }

  .object-msg-compose {
    padding: 0.35rem 0.38rem;
    gap: 0.35rem;
  }

  .object-msg-compose textarea {
    min-height: 2.1rem;
  }

  .object-msg-send {
    width: 2.1rem;
    height: 2.1rem;
    font-size: 0.9rem;
  }

  .stage-actions-wrap .btn-mini {
    flex-basis: 100%;
  }
}

.chain-progress {
  margin: 0 0 2rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(61, 156, 240, 0.06);
}

.chain-progress-top {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text, #e8e8e8);
  margin-bottom: 0.25rem;
}

.chain-progress-subtitle {
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.35;
  margin-bottom: 0.5rem;
  word-break: break-word;
}

.chain-progress-bar-wrap {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  margin-bottom: 0.35rem;
}

.chain-progress-bar {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(61, 156, 240, 0.5), var(--accent, #3d9cf0));
  transition: width 0.2s ease;
}

.chain-progress-legend {
  font-size: 0.75rem;
  color: var(--muted);
}

.stage-detail {
  padding-bottom: 0.75rem;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.stage-detail-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0 0 0.65rem;
  line-height: 1.35;
  word-break: break-word;
}

.stage-field {
  margin-bottom: 0.65rem;
}

.stage-field-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.3rem;
}

.stage-assign-wrap .task-assignee {
  max-width: 100%;
  width: 100%;
}

.stage-actions-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.msg-section-hdr {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0 0.45rem;
}

.task-row-inner-compact {
  padding: 0.35rem 0.55rem;
  gap: 0;
}

.task-row-head-compact {
  align-items: center;
  margin: 0;
}

.task-row-actions-compact {
  flex-shrink: 0;
  justify-content: flex-end;
}

.task-row-overview .st {
  font-size: 0.68rem;
  padding: 0.1rem 0.38rem;
}

.task-row-overview .task-row-main {
  font-size: 0.86rem;
  line-height: 1.3;
}

.task-row-is-active {
  border-color: rgba(61, 156, 240, 0.55);
  box-shadow: inset 0 0 0 1px rgba(61, 156, 240, 0.2);
}

.card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  background: var(--surface);
}

.tlist,
.mlist,
.flist {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  max-height: 320px;
  overflow: auto;
}

.tlist.tlist-chain {
  max-height: min(70vh, 720px);
  overflow-y: auto;
}

.tlist > li.out-block {
  list-style: none;
  margin: 0 0 0.65rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.12);
}

.tlist > li.out-block > .collapsible {
  width: 100%;
  margin: 0;
  padding: 0.55rem 0.75rem;
  border: none;
  border-bottom: 1px solid var(--border);
  background: rgba(61, 156, 240, 0.08);
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}

.tlist > li.out-block > .collapsible:hover {
  background: rgba(61, 156, 240, 0.14);
}

.tlist > li.out-block > .collapsible .collapse-icon {
  display: inline-block;
  width: 1.1em;
}

.nested-tlist {
  list-style: none;
  margin: 0;
  padding: 0;
}

.nested-tlist .task-row {
  list-style: none;
  margin: 0 0 0.5rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-size: 0.92rem;
}

.nested-tlist .task-row:last-child {
  margin-bottom: 0.5rem;
}

.out-block.collapsed .nested-tlist .task-row[data-hide-when-collapsed="1"] {
  display: none;
}

.tlist > li.task-row {
  list-style: none;
  margin: 0 0 0.5rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-size: 0.92rem;
}

.task-row-inner {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
  padding: 0.5rem 0.65rem;
}

.task-row-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem 0.75rem;
}

.task-row-title-wrap {
  flex: 1;
  min-width: 0;
}

.task-row-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  justify-content: flex-end;
}

.task-row-assign {
  display: flex;
  align-items: center;
}

.task-row-assign .task-assignee {
  width: 100%;
  max-width: 320px;
}

.task-row-main {
  min-width: 0;
  cursor: pointer;
  outline: none;
}

.tlist-chain .task-row-main {
  word-break: break-word;
  line-height: 1.35;
}

.task-row-main:hover {
  color: var(--accent);
}

.task-row-selected {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: 10px;
}

.task-assignee {
  min-width: 140px;
  max-width: 200px;
  font-size: 0.8rem;
  padding: 0.25rem 0.4rem;
}

.btn-mini {
  font-size: 0.78rem;
  padding: 0.25rem 0.55rem;
  border-radius: 6px;
  font-weight: 600;
}

.btn-mini.primary {
  background: linear-gradient(180deg, #3ecf7a 0%, #248a4f 100%);
  border-color: #1d6b3e;
}

.btn-mini.warn {
  background: linear-gradient(180deg, #e8a84a 0%, #b8731a 100%);
  border-color: #8a5a12;
  color: #1a1208;
}

.idx {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.tlist .col {
  color: var(--accent);
  font-weight: 600;
  margin-right: 0.15rem;
}

.tlist .st {
  font-size: 0.75rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.st-pending {
  background: #333;
  color: #bbb;
}
.st-active {
  background: rgba(61, 156, 240, 0.25);
  color: var(--accent);
}
.st-done {
  background: rgba(52, 199, 89, 0.2);
  color: var(--ok);
}

.st-skipped {
  background: rgba(232, 168, 74, 0.22);
  color: #e8a84a;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-end;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.controls label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.controls select {
  min-width: 200px;
}

.mlist li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.mlist .when {
  color: var(--muted);
  font-size: 0.75rem;
}

.flist li {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  padding: 0.35rem 0;
  font-size: 0.9rem;
}

/* Атрибут hidden не должен перебиваться display у .modal-panel — иначе окно видно до открытия */
.modal-backdrop[hidden],
.modal-panel[hidden] {
  display: none !important;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 100;
}

.modal-panel {
  position: fixed;
  inset: 0;
  z-index: 101;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 1rem;
  overflow-y: auto;
  pointer-events: none;
}

.modal-inner {
  pointer-events: auto;
  position: relative;
  width: min(520px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.25rem 1rem;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
}

.modal-close {
  position: absolute;
  top: 0.5rem;
  right: 0.65rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.modal-close:hover {
  color: var(--text);
}

.kind-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.kind-btn {
  flex: 1 1 120px;
  padding: 0.65rem 1rem;
  font-weight: 600;
  border-radius: 8px;
}

.modal-kind-label {
  font-weight: 600;
  margin: 0 0 0.75rem;
  color: var(--accent);
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.65rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.msg-item {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.msg-head .when {
  color: var(--muted);
  font-size: 0.75rem;
}

.msg-body {
  margin-top: 0.35rem;
}

.msg-edit {
  width: 100%;
  font: inherit;
  resize: vertical;
  min-height: 48px;
}

.msg-actions {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.35rem;
}

/* Личные чаты (Telegram-like) */
.chat-page.panel,
.chat-thread.panel {
  max-width: 720px;
  margin: 0 auto;
}

.chat-page-head,
.chat-thread-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0 1rem;
  border-bottom: 1px solid var(--border);
}

.chat-page-title {
  flex: 1;
  margin: 0;
  font-size: 1.15rem;
}

.chat-back {
  font-size: 1.25rem;
  color: var(--accent);
  text-decoration: none;
  line-height: 1;
}

.chat-head-action {
  font-size: 0.85rem;
  padding: 0.35rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.2);
  color: var(--text);
  cursor: pointer;
}

.chat-head-action:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.chat-contacts-panel {
  margin-bottom: 1rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.15);
}

.chat-contacts-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.chat-contacts-list a {
  display: block;
  padding: 0.45rem 0.25rem;
  border-radius: 6px;
}

.chat-contacts-list a:hover {
  background: rgba(255, 255, 255, 0.04);
}

.chat-inbox-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.chat-inbox-row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 0.15rem 0.75rem;
  padding: 0.75rem 0.5rem;
  border-bottom: 1px solid var(--border);
  color: inherit;
  text-decoration: none;
  border-radius: 8px;
}

.chat-inbox-row:hover {
  background: rgba(255, 255, 255, 0.04);
}

.chat-inbox-name {
  font-weight: 600;
  color: var(--text);
}

.chat-inbox-time {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
}

.chat-inbox-preview {
  grid-column: 1 / -1;
  font-size: 0.85rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-inbox-empty {
  padding: 1rem 0;
  color: var(--muted);
  list-style: none;
}

.chat-thread {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 5.5rem);
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
}

.chat-peer-name {
  font-weight: 600;
  font-size: 1.05rem;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 10px;
  margin: 0.5rem 0;
  min-height: 200px;
}

.chat-msg {
  display: flex;
  max-width: 100%;
}

.chat-msg-mine {
  justify-content: flex-end;
}

.chat-msg-theirs {
  justify-content: flex-start;
}

.chat-bubble {
  max-width: min(78%, 420px);
  padding: 0.45rem 0.65rem 0.35rem;
  border-radius: 12px;
  font-size: 0.92rem;
  line-height: 1.35;
}

.chat-msg-mine .chat-bubble {
  background: linear-gradient(145deg, #2a4a6f 0%, #1e3a55 100%);
  border: 1px solid rgba(61, 156, 240, 0.35);
  border-bottom-right-radius: 4px;
}

.chat-msg-theirs .chat-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.chat-bubble-reply {
  font-size: 0.78rem;
  color: var(--muted);
  border-left: 2px solid var(--accent);
  padding-left: 0.4rem;
  margin-bottom: 0.35rem;
  opacity: 0.95;
}

.chat-bubble-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-bubble-file {
  margin-top: 0.25rem;
  font-size: 0.88rem;
}

.chat-bubble-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.35rem;
  margin-top: 0.25rem;
  font-size: 0.68rem;
  color: var(--muted);
  opacity: 0.85;
}

.chat-reply-bar {
  margin-bottom: 0.35rem;
}

.chat-reply-inner {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem 0.35rem 0.65rem;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.chat-reply-quote {
  flex: 1;
  min-width: 0;
  border-left: 3px solid var(--accent);
  padding-left: 0.5rem;
}

.chat-reply-author {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.15rem;
}

.chat-reply-snippet {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.3;
  max-height: 2.6em;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}

.chat-reply-cancel {
  flex-shrink: 0;
  align-self: flex-start;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.15rem;
  line-height: 1;
  padding: 0.1rem 0.25rem;
  border-radius: 4px;
}

.chat-reply-cancel:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.chat-ctx-menu {
  position: fixed;
  z-index: 3000;
  min-width: 180px;
  padding: 0.25rem 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.chat-ctx-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.55rem 1rem;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.chat-ctx-item:hover {
  background: rgba(61, 156, 240, 0.15);
}

.chat-ctx-danger {
  color: var(--danger);
}

.chat-ctx-danger:hover {
  background: rgba(255, 69, 58, 0.12);
}

.chat-compose {
  display: flex;
  align-items: flex-end;
  gap: 0.35rem;
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  z-index: 30;
  width: min(720px, calc(100vw - 1.6rem));
  padding: 0.5rem 0.75rem calc(0.5rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
  background: var(--surface);
}

@media (max-width: 799px) {
  .chat-thread {
    padding-bottom: calc(78px + env(safe-area-inset-bottom));
  }

  .chat-compose {
    width: calc(100vw - 1rem);
    padding: 0.45rem 0.5rem calc(0.45rem + env(safe-area-inset-bottom));
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
  }
}

.chat-input-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.chat-compose textarea {
  width: 100%;
  min-height: 40px;
  max-height: 160px;
  resize: none;
  font: inherit;
  padding: 0.5rem 0.65rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
}

.chat-icon-btn {
  border: none;
  background: transparent;
  font-size: 1.25rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.35rem;
  border-radius: 8px;
  opacity: 0.85;
}

.chat-icon-btn:hover {
  background: rgba(255, 255, 255, 0.06);
}

.chat-send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  flex-shrink: 0;
}

.chat-send-btn:hover {
  filter: brightness(1.08);
}
