/* Базовые стили приложения: фон, типографика, базовая раскладка и reset. */
body {
  margin: 0;
  background:
    radial-gradient(1200px 700px at 10% 0%, var(--bg-2) 0%, rgba(238, 242, 255, 0) 60%),
    radial-gradient(900px 600px at 90% 10%, rgba(47, 125, 246, 0.10) 0%, rgba(47, 125, 246, 0) 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

html,
body {
  height: 100%;
  max-width: 100vw;
  overflow: auto;
}

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

.app {
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: 100vh;
}

.editor {
  border-right: 1px solid #1f2c3a;
}

.right {
  padding: 12px;
}

#preview {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.tg-message {
  position: relative;
  background: #ffffff;
  color: #000000;
  padding: 12px 14px;
  border-radius: 18px 18px 18px 0;
  line-height: 1.3;
  max-width: 360px;
  margin: 12px auto;
  font-size: 14px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition: box-shadow 0.2s ease;

  /* Fixes for preview (WYSIWYG) */
  white-space: pre-wrap;
  /* Preserve whitespace/indentation */
  word-break: break-word;
  /* Break long words like paths */
  overflow-wrap: anywhere;
  /* Ensure everything wraps */
}

.tg-message::before {
  content: '';
  position: absolute;
  left: -16px;
  bottom: 0;
  width: 34px;
  height: 34px;
  background: #ffffff;
  clip-path: path('M 34 0 L 34 34 L 0 34 Q 20 34 26 17 Q 30 4 34 0 Z');
  z-index: -1;
}

.tg-message p {
  margin: 0;
  min-height: 1.3em;
  line-height: 1.3;
}

.tg-message p:empty::before {
  content: '\00a0';
  display: block;
}

/* Пустые строки для пропуска */
.tg-message p.empty-line {
  min-height: 1.3em;
  height: 1.3em;
}

.tg-message a {
  color: #2f7df6;
  text-decoration: none;
}

.tg-message:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.tg-message blockquote {
  position: relative;
  background: linear-gradient(135deg, rgba(47, 125, 246, 0.10) 0%, rgba(79, 195, 220, 0.08) 100%);
  border-left: 3px solid rgba(47, 125, 246, 0.65);
  margin: 8px 0;
  padding: 12px 14px 12px 14px;
  padding-right: 32px;
  border-radius: 6px 12px 12px 6px;
  color: #333;
  font-style: normal;
}

.tg-message blockquote::before {
  content: '"';
  position: absolute;
  top: 6px;
  right: 10px;
  font-size: 28px;
  font-family: Georgia, serif;
  color: rgba(47, 125, 246, 0.65);
  opacity: 0.5;
  line-height: 1;
}

/* Collapsible quotes in preview */
.tg-message blockquote.expandable {
  max-height: 120px;
  overflow: hidden;
  position: relative;
  transition: max-height 0.3s ease;
  cursor: pointer;
}

.tg-message blockquote.expandable.expanded {
  max-height: none;
  overflow: visible;
}

.tg-message blockquote.expandable::after {
  content: '';
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  /* Telegram Blue #3390ec */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%233390ec' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
  pointer-events: none;
  opacity: 1;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.tg-message blockquote.expandable.expanded::after {
  opacity: 1;
  pointer-events: none;
  transform: rotate(180deg);
}



.tg-message blockquote.expandable.short-content::after {
  display: none;
}


.tg-message ul,
.tg-message ol {
  margin: 8px 0;
  padding-left: 24px;
  list-style-position: outside;
}

.tg-message ul {
  list-style-type: disc;
}

.tg-message ol {
  list-style-type: decimal;
}

.tg-message li {
  margin: 4px 0;
  line-height: 1.4;
  padding-left: 4px;
}

/* Списки внутри цитаты */
.tg-message blockquote ul,
.tg-message blockquote ol {
  margin: 4px 0;
  padding-left: 20px;
}

.tg-message blockquote li {
  margin: 2px 0;
}

.tg-message code {
  background: #f4f4f4;
  border-radius: 3px;
  padding: 2px 6px;
  cursor: pointer;
  font-size: 13px;
}

.tg-message pre {
  position: relative;
  background: #e9eef5;
  border-radius: 12px 12px 12px 0;
  padding: 38px 12px 10px 14px;
  box-shadow: inset 4px 0 0 rgba(17, 24, 39, 0.18);
  overflow: hidden;
  cursor: pointer;
  font-size: 13px;
  margin: 8px 0;
}

.tg-message pre::before {
  content: 'копировать';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 28px;
  display: flex;
  align-items: center;
  padding: 0 36px 0 12px;
  font-size: 12px;
  color: rgba(17, 24, 39, 0.55);
  background: #dfe6ef;
  border-radius: 12px 12px 0 0;
  pointer-events: none;
}

.tg-message pre::after {
  content: '⧉';
  position: absolute;
  top: 0;
  right: 10px;
  height: 28px;
  display: flex;
  align-items: center;
  color: rgba(17, 24, 39, 0.55);
  font-size: 13px;
  pointer-events: none;
}

.tg-message pre code {
  background: none;
  padding: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.tg-message img {
  max-width: 100%;
  border-radius: 8px;
}

.tg-link-preview {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 72px;
  gap: 8px;
  margin-top: 10px;
  padding: 10px 12px;
  padding-left: 14px;
  background: linear-gradient(135deg, rgba(47, 125, 246, 0.10) 0%, rgba(79, 195, 220, 0.08) 100%);
  border-left: 3px solid rgba(47, 125, 246, 0.65);
  border-radius: 6px 12px 12px 6px;
  overflow: hidden;
  align-items: start;
}

.tg-link-preview .lp-image {
  width: 72px;
  height: 72px;
  background: #f1f5f9;
  display: block;
  object-fit: cover;
  border-radius: 6px;
  order: 2;
}

.tg-link-preview .lp-content {
  padding: 0;
  order: 1;
  min-width: 0;
}

.tg-link-preview .lp-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 2px;
  color: rgba(0, 52, 116, 0.95);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tg-link-preview .lp-desc {
  color: #000;
  font-size: 14px;
  font-weight: 400;
  margin-bottom: 0;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.3;
}

.tg-link-preview .lp-url {
  display: block;
  font-size: 12px;
  color: rgba(0, 52, 116, 0.6);
  margin-top: 4px;
}

/* Telegram-like large media preview (YouTube, etc.) */
.tg-link-preview.tg-large-media {
  display: flex;
  flex-direction: column;
  padding: 10px 14px;
  /* Restore padding */
  border-left: 3px solid rgba(47, 125, 246, 0.65);
  /* Restore bar for the whole block */
  gap: 10px;
}

.tg-link-preview.tg-large-media .lp-image {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  border-radius: 4px;
  order: 1;
  /* Image on bottom */
}

.tg-link-preview.tg-large-media .lp-content {
  padding: 0;
  order: 0;
  /* Text on top */
  border-left: none;
  margin-bottom: 0;
}

.tg-link-preview.tg-large-media .lp-desc {
  -webkit-line-clamp: 3;
  line-clamp: 3;
}

.tg-inline-keyboard {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 360px;
  margin-left: auto;
  margin-right: auto;
}

.tg-ik-row {
  display: flex;
  gap: 4px;
}

.tg-ik-row .tg-ik-btn {
  flex: 1 1 auto;
  min-width: 80px;
}

.tg-ik-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 28px 10px 16px;
  border: none;
  border-radius: 8px;
  background: rgba(100, 110, 120, 0.45);
  color: #ffffff;
  text-decoration: none;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  transition: background 0.15s ease;
}

.tg-ik-btn:hover {
  background: rgba(100, 110, 120, 0.6);
  color: #ffffff;
}

.tg-ik-btn::after {
  content: "↗";
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
}

/* Закругления: у крайних кнопок нижний крайний угол больше верхнего */
.tg-ik-row .tg-ik-btn:first-child {
  border-radius: 8px 8px 8px 16px;
}

.tg-ik-row .tg-ik-btn:last-child {
  border-radius: 8px 8px 16px 8px;
}

.tg-ik-row .tg-ik-btn:only-child {
  border-radius: 8px 8px 16px 16px;
}

.tg-images {
  margin-bottom: 8px;
  display: grid;
  gap: 2px;
  max-width: 100%;
}

.tg-images.tg-album-abs {
  display: block;
  position: relative;
}

.tg-images .tile {
  position: relative;
  overflow: hidden;
  border-radius: 0;
  background: #f0f0f0;
}

.tg-images.tg-album-abs .tile {
  position: absolute;
}

.tg-images .tile img,
.tg-images .tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  margin: 0;
}

/* 1 фото - полная ширина */
.tg-images.layout-1 {
  grid-template-columns: 1fr;
}

.tg-images.layout-1 .tile {
  aspect-ratio: 4 / 3;
  border-radius: var(--radius-md);
}

/* 2 фото - два столбца */
.tg-images.layout-2 {
  grid-template-columns: 1fr 1fr;
}

.tg-images.layout-2 .tile {
  aspect-ratio: 1 / 1;
}

.tg-images.layout-2 .tile-0 {
  border-radius: var(--radius-md) 0 0 var(--radius-md);
}

.tg-images.layout-2 .tile-1 {
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

/* 3 фото - одно сверху на всю ширину, два снизу */
.tg-images.layout-3 {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto;
}

.tg-images.layout-3 .tile {
  aspect-ratio: 3 / 2;
}

.tg-images.layout-3 .tile-0 {
  grid-column: 1 / 3;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.tg-images.layout-3 .tile-1 {
  border-radius: 0 0 0 var(--radius-md);
}

.tg-images.layout-3 .tile-2 {
  border-radius: 0 0 var(--radius-md) 0;
}

/* 4 фото - сетка 2x2 */
.tg-images.layout-4 {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}

.tg-images.layout-4 .tile {
  aspect-ratio: 1 / 1;
}

.tg-images.layout-4 .tile-0 {
  border-radius: var(--radius-md) 0 0 0;
}

.tg-images.layout-4 .tile-1 {
  border-radius: 0 var(--radius-md) 0 0;
}

.tg-images.layout-4 .tile-2 {
  border-radius: 0 0 0 var(--radius-md);
}

.tg-images.layout-4 .tile-3 {
  border-radius: 0 0 var(--radius-md) 0;
}

/* 5 фото - одно сверху, 2 в середине, 2 снизу */
.tg-images.layout-5 {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto auto;
}

.tg-images.layout-5 .tile {
  aspect-ratio: 3 / 2;
}

.tg-images.layout-5 .tile-0 {
  grid-column: 1 / 3;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.tg-images.layout-5 .tile-3 {
  border-radius: 0 0 0 var(--radius-md);
}

.tg-images.layout-5 .tile-4 {
  border-radius: 0 0 var(--radius-md) 0;
}

/* 6 фото - 2 сверху, 2 в середине, 2 снизу */
.tg-images.layout-6 {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto auto;
}

.tg-images.layout-6 .tile {
  aspect-ratio: 3 / 2;
}

.tg-images.layout-6 .tile-0 {
  border-radius: var(--radius-md) 0 0 0;
}

.tg-images.layout-6 .tile-1 {
  border-radius: 0 var(--radius-md) 0 0;
}

.tg-images.layout-6 .tile-4 {
  border-radius: 0 0 0 var(--radius-md);
}

.tg-images.layout-6 .tile-5 {
  border-radius: 0 0 var(--radius-md) 0;
}

/* 7 фото - одно сверху, 3 в середине, 3 снизу */
.tg-images.layout-7 {
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: auto auto auto;
}

.tg-images.layout-7 .tile {
  aspect-ratio: 3 / 2;
}

.tg-images.layout-7 .tile-0 {
  grid-column: 1 / 4;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.tg-images.layout-7 .tile-4 {
  border-radius: 0 0 0 var(--radius-md);
}

.tg-images.layout-7 .tile-6 {
  border-radius: 0 0 var(--radius-md) 0;
}

/* 8 фото - 2 сверху, 3 в середине, 3 снизу */
.tg-images.layout-8 {
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: auto auto auto;
}

.tg-images.layout-8 .tile {
  aspect-ratio: 3 / 2;
}

.tg-images.layout-8 .tile-0 {
  grid-column: 1 / 2;
  border-radius: var(--radius-md) 0 0 0;
}

.tg-images.layout-8 .tile-1 {
  grid-column: 2 / 4;
  border-radius: 0 var(--radius-md) 0 0;
}

.tg-images.layout-8 .tile-5 {
  border-radius: 0 0 0 var(--radius-md);
}

.tg-images.layout-8 .tile-7 {
  border-radius: 0 0 var(--radius-md) 0;
}

/* 9 фото - 3 сверху, 3 в середине, 3 снизу */
.tg-images.layout-9 {
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: auto auto auto;
}

.tg-images.layout-9 .tile {
  aspect-ratio: 1 / 1;
}

.tg-images.layout-9 .tile-0 {
  border-radius: var(--radius-md) 0 0 0;
}

.tg-images.layout-9 .tile-2 {
  border-radius: 0 var(--radius-md) 0 0;
}

.tg-images.layout-9 .tile-6 {
  border-radius: 0 0 0 var(--radius-md);
}

.tg-images.layout-9 .tile-8 {
  border-radius: 0 0 var(--radius-md) 0;
}

/* 10 фото - одно сверху, 3+3+3 */
.tg-images.layout-10 {
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: auto auto auto auto;
}

.tg-images.layout-10 .tile {
  aspect-ratio: 3 / 2;
}

.tg-images.layout-10 .tile-0 {
  grid-column: 1 / 4;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.tg-images.layout-10 .tile-7 {
  border-radius: 0 0 0 var(--radius-md);
}

.tg-images.layout-10 .tile-9 {
  border-radius: 0 0 var(--radius-md) 0;
}

/* Video tiles in preview */
.tg-images .tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tg-images .tile-video {
  position: relative;
  cursor: pointer;
}

.tile-video-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 2;
}

.tile-video-overlay svg {
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.3));
}

/* Document files preview */
.tg-files {
  margin-bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tg-file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-secondary, #f4f4f5);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.tg-file-icon {
  font-size: 28px;
  flex-shrink: 0;
}

.tg-file-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.tg-file-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tg-file-size {
  font-size: 11px;
  color: var(--text-muted, #71717a);
  margin-top: 2px;
}

.tg-spoiler-wrap {
  position: relative;
  overflow: hidden;
  border-radius: 6px;
}

.tg-spoiler-wrap canvas {
  z-index: 10;
}

/* Hide the clear image before the canvas initializes to prevent flickering */
.tg-spoiler-wrap img,
.tg-spoiler-wrap video {
  filter: blur(20px);
  transform: scale(1.1);
  /* Prevent blur bleed at the edges */
}

/* Hide play button overlay when spoiler is active */
.tg-spoiler-wrap .tile-video-overlay {
  opacity: 0 !important;
  pointer-events: none !important;
}




.tg-spoiler.revealed img,
.tg-spoiler.revealed video,
.tg-spoiler.revealed canvas {
  filter: none;
}

.tg-spoiler.revealed::after,
.tg-spoiler.revealed::before {
  display: none;
}

button {
  margin-right: 0;
  padding: 6px 10px;
}

#editor .tiptap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  height: 100%;
  padding: 16px;
  line-height: 1.3;
  padding-bottom: 120px;
  overflow: auto;
  font-size: 14px;
}

#editor .tiptap p {
  margin: 0;
  min-height: 1.3em;
}