/* Reset & base */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: #0e1621;
  color: #e4e4e4;
  min-height: 100vh;
  line-height: 1.4;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
}

.page-header {
  text-align: center;
  margin-bottom: 1.5rem;
}
.page-header h1 { font-size: 1.5rem; margin: 0 0 0.25rem 0; }
.page-header p { margin: 0; color: #8b98a5; font-size: 0.9rem; }

.layout {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 1.5rem;
  align-items: start;
}
@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  background: #17212b;
  border-radius: 12px;
  padding: 1.25rem;
  border: 1px solid #242f3d;
}
.panel h2 { margin: 0 0 1rem 0; font-size: 1.1rem; color: #fff; }
.form-panel .form-section { margin-bottom: 1.5rem; }
.form-panel .form-section:last-child { margin-bottom: 0; }
.form-panel h3 { margin: 0 0 0.75rem 0; font-size: 0.95rem; color: #8b98a5; }
.form-panel label {
  display: block;
  margin-bottom: 0.75rem;
}
.form-panel label span {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.85rem;
  color: #8b98a5;
}
.form-panel input[type="text"],
.form-panel input[type="datetime-local"],
.form-panel textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid #242f3d;
  border-radius: 8px;
  background: #242f3d;
  color: #e4e4e4;
  font-size: 0.95rem;
}
.form-panel input[type="file"] {
  width: 100%;
  font-size: 0.85rem;
  color: #8b98a5;
}
.form-panel textarea { resize: vertical; min-height: 60px; }

.form-hint { font-size: 0.85rem; color: #8b98a5; margin: 0 0 0.75rem 0; }
.message-actions { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; flex-wrap: wrap; }
.btn {
  padding: 0.5rem 0.75rem;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  background: #242f3d;
  color: #e4e4e4;
}
.btn-add { background: #2b5278; color: #fff; }
.btn-add:hover { background: #346a96; }
.btn-small {
  padding: 0.25rem 0.4rem;
  font-size: 0.8rem;
  min-width: 28px;
}
.message-list { display: flex; flex-direction: column; gap: 0.5rem; }
.msg-row {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.5rem;
  background: #242f3d;
  border-radius: 8px;
  border: 1px solid #2f3d4d;
}
.msg-row .msg-badge {
  flex-shrink: 0;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
}
.msg-row.msg-contact .msg-badge { background: #182533; color: #6ab2f2; }
.msg-row.msg-mine .msg-badge { background: #2b5278; color: #fff; }
.msg-row .msg-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.msg-row .msg-datetime-wrap { margin: 0; }
.msg-row .msg-datetime {
  width: 100%;
  padding: 0.35rem 0.5rem;
  border: 1px solid #2f3d4d;
  border-radius: 6px;
  background: #17212b;
  color: #e4e4e4;
  font-size: 0.8rem;
  cursor: pointer;
}
.msg-row .msg-datetime::-webkit-calendar-picker-indicator {
  filter: invert(0.8);
  cursor: pointer;
  opacity: 0.8;
}
.msg-row .msg-datetime::-webkit-datetime-edit { color: #e4e4e4; }
.msg-row .msg-datetime::-webkit-datetime-edit-fields-wrapper { color: #e4e4e4; }
.msg-row .msg-text-wrap { margin: 0; }
.msg-row textarea { margin: 0; min-height: 44px; }
.msg-row .msg-actions { margin: 0; display: flex; gap: 2px; flex-shrink: 0; }
.msg-row .msg-actions .btn { padding: 0.25rem; }

.form-section-export .message-actions { margin-bottom: 0; }
.btn-upload { display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.btn-upload input[hidden] { position: absolute; width: 0; height: 0; opacity: 0; }

/* Telegram frame — як у додатку */
.preview-panel h2 { margin-bottom: 0.75rem; }
.telegram-frame {
  background: #0e1621;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid #242f3d;
  max-width: 380px;
  margin: 0 auto;
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
}

.tg-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: #17212b;
  border-bottom: 1px solid #242f3d;
}
.tg-back {
  width: 24px;
  height: 24px;
  border: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%238b98a5'%3E%3Cpath d='M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z'/%3E%3C/svg%3E") center/20px no-repeat;
  cursor: pointer;
  flex-shrink: 0;
}
.tg-avatar-wrap {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  overflow: hidden;
  background: #242f3d;
  flex-shrink: 0;
}
.tg-avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.tg-avatar-wrap:not(.has-img) .tg-avatar { display: none; }
.tg-avatar-wrap:not(.has-img)::after {
  content: '';
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #5288c1 0%, #3d6fa6 100%);
}
.tg-title { flex: 1; min-width: 0; }
.tg-name { display: block; font-weight: 600; font-size: 1rem; color: #fff; }
.tg-status { font-size: 0.8rem; color: #7f8b99; }
.tg-menu {
  width: 24px;
  height: 24px;
  border: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%238b98a5'%3E%3Cpath d='M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z'/%3E%3C/svg%3E") center/20px no-repeat;
  cursor: pointer;
  flex-shrink: 0;
}

.tg-chat {
  padding: 12px;
  min-height: 200px;
  background: #0e1621;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M30 0L0 30L30 60L60 30z' fill='%230e1621' fill-opacity='0.02'/%3E%3C/svg%3E");
}

.tg-date {
  text-align: center;
  font-size: 0.8rem;
  color: #7f8b99;
  margin: 12px 0;
}
.tg-bubbles > .tg-date:first-child { margin-top: 0; }

.tg-bubbles { display: flex; flex-direction: column; gap: 6px; }
.tg-msg { display: flex; gap: 8px; align-items: flex-end; }
.tg-msg.tg-incoming { flex-direction: row; justify-content: flex-start; }
.tg-msg.tg-outgoing { flex-direction: row-reverse; justify-content: flex-start; }
.tg-msg.hidden { display: none; }

.tg-msg-avatar-wrap {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: #242f3d;
}
.tg-msg-avatar { width: 100%; height: 100%; object-fit: cover; }
.tg-msg-avatar-wrap:not(.has-img) .tg-msg-avatar { display: none; }
.tg-msg-avatar-wrap:not(.has-img)::after {
  content: '';
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #5288c1 0%, #3d6fa6 100%);
}

.tg-msg-content { max-width: 75%; min-width: 0; }
.tg-msg-sender { font-size: 0.8rem; color: #6ab2f2; margin-bottom: 2px; display: block; }
.tg-bubble {
  padding: 8px 12px;
  border-radius: 12px;
  position: relative;
  display: inline-block;
  max-width: 100%;
}
.tg-bubble-in {
  background: #182533;
  border-top-left-radius: 4px;
  color: #e4e4e4;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.tg-bubble-out {
  background: #2b5278;
  border-top-right-radius: 4px;
  color: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.tg-bubble-text { word-wrap: break-word; white-space: pre-wrap; }
.tg-bubble-text:empty::before { content: ' '; }
.tg-time {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.6);
  float: right;
  margin-left: 6px;
  margin-top: 2px;
}
.tg-bubble-in .tg-time { color: #7f8b99; }
