/* ==========================================================================
   TELEGRAM POST BUILDER - STUDIO DESIGN SYSTEM
   Professional Telegram UI Dark Theme & Layout
   ========================================================================== */

:root {
  /* Telegram Authentic Palette */
  --tg-dark-bg: #0e1621;
  --tg-panel-bg: #17212b;
  --tg-surface-card: #202b36;
  --tg-surface-hover: #273442;
  --tg-input-bg: #131c26;
  --tg-border: #242f3d;
  --tg-border-light: rgba(255, 255, 255, 0.08);

  /* Telegram Accent Colors */
  --tg-blue: #2481cc;
  --tg-blue-hover: #2aabee;
  --tg-blue-glow: rgba(36, 129, 204, 0.35);
  --tg-green: #31b545;
  --tg-green-hover: #3dd355;
  --tg-red: #e53935;
  --tg-red-hover: #ef5350;
  --tg-yellow: #f5a623;

  /* Typography */
  --tg-text-main: #f5f5f5;
  --tg-text-sub: #7f91a4;
  --tg-text-muted: #5b6a7a;
  --tg-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --tg-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;

  /* Radii & Shadows */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-card: 0 4px 16px rgba(0, 0, 0, 0.35);
  --shadow-popup: 0 12px 36px rgba(0, 0, 0, 0.6);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--tg-font);
  background: var(--tg-dark-bg);
  color: var(--tg-text-main);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Scrollbars */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.16) transparent;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.28);
}

/* App Shell */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* ==========================================================================
   TOP STUDIO HEADER
   ========================================================================== */

.top-header {
  height: 52px;
  background: var(--tg-panel-bg);
  border-bottom: 1px solid var(--tg-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  flex-shrink: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  user-select: none;
}

.brand-logo-img {
  width: 28px;
  height: 28px;
  object-fit: contain;
  border-radius: 6px;
  flex-shrink: 0;
  display: block;
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: -0.015em;
  display: flex;
  align-items: center;
  user-select: none;
}

.header-templates-select {
  background: var(--tg-input-bg);
  color: var(--tg-text-main);
  border: 1px solid var(--tg-border);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  font-size: 12.5px;
  font-family: inherit;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
}

.header-templates-select:hover {
  border-color: var(--tg-blue);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Header Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  outline: none;
  transition: all 0.15s ease;
  user-select: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn-secondary {
  background: var(--tg-surface-card);
  color: var(--tg-text-main);
  border: 1px solid var(--tg-border);
}

.btn-secondary:hover {
  background: var(--tg-surface-hover);
  border-color: rgba(255, 255, 255, 0.15);
}

.btn-primary {
  background: var(--tg-blue);
  color: #ffffff;
  box-shadow: 0 2px 8px var(--tg-blue-glow);
}

.btn-primary:hover {
  background: var(--tg-blue-hover);
}

.btn-danger {
  background: rgba(229, 57, 53, 0.15);
  color: #ff6b6b;
  border: 1px solid rgba(229, 57, 53, 0.3);
}

.btn-danger:hover {
  background: var(--tg-red);
  color: #ffffff;
}

/* User Account Badge */
.user-account-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--tg-input-bg);
  border: 1px solid var(--tg-border);
  border-radius: 20px;
  padding: 3px 10px 3px 4px;
}

.user-avatar-mini {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--tg-blue);
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.user-avatar-mini img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-name-text {
  font-size: 12px;
  font-weight: 600;
  color: var(--tg-text-main);
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-logout {
  background: transparent;
  border: none;
  color: var(--tg-text-sub);
  cursor: pointer;
  padding: 2px;
  display: flex;
  align-items: center;
}

.btn-logout:hover {
  color: #ff6b6b;
}

/* ==========================================================================
   STUDIO BODY & 50/50 EQUAL SPLIT
   ========================================================================== */

.studio-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
  background: var(--tg-dark-bg);
}

/* Left Builder Pane */
.builder-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--tg-panel-bg);
  overflow: hidden;
}

.builder-scrollable {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Resizer Divider */
.pane-resizer-divider {
  width: 8px;
  background: var(--tg-dark-bg);
  border-left: 1px solid var(--tg-border);
  border-right: 1px solid var(--tg-border);
  cursor: col-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: background 0.15s ease;
  user-select: none;
  z-index: 20;
}

.pane-resizer-divider:hover,
.pane-resizer-divider.active-drag {
  background: var(--tg-surface-card);
}

.resizer-handle-pill {
  width: 16px;
  height: 38px;
  background: var(--tg-surface-hover);
  border: 1px solid var(--tg-border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--tg-text-sub);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

/* Right Preview Pane */
.preview-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
  overflow: hidden;
  background: var(--tg-dark-bg);
}

.preview-top-controls {
  height: 42px;
  background: var(--tg-panel-bg);
  border-bottom: 1px solid var(--tg-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  font-size: 12px;
  color: var(--tg-text-sub);
  flex-shrink: 0;
  z-index: 15;
}

.preview-controls-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.preview-toggle-btn {
  background: var(--tg-input-bg);
  border: 1px solid var(--tg-border);
  color: var(--tg-text-main);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  transition: all 0.15s;
}

.preview-toggle-btn.active,
.preview-toggle-btn:hover {
  border-color: var(--tg-blue);
  color: var(--tg-blue-hover);
}

/* ==========================================================================
   BUILDER CARDS & FORM CONTROLS
   ========================================================================== */

.builder-card {
  background: var(--tg-surface-card);
  border: 1px solid var(--tg-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-card);
}

.builder-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.builder-card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.1px;
}

.card-title-icon {
  color: var(--tg-blue);
  display: inline-flex;
}

.card-title-badge {
  font-size: 11px;
  font-weight: 500;
  color: var(--tg-text-sub);
  background: var(--tg-input-bg);
  border: 1px solid var(--tg-border);
  padding: 2px 7px;
  border-radius: 10px;
}

/* Form Elements */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.channel-help { color:#b4c2cf; font-size:12px; line-height:1.5; margin:4px 0; }
.channel-discovery-actions { display:flex; align-items:center; flex-wrap:wrap; gap:10px; }
.channel-discovery-actions a { color:#79c7ff; font-size:12px; text-decoration:underline; text-underline-offset:2px; }

.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--tg-text-sub);
}

.input-row {
  display: flex;
  gap: 8px;
}

.form-input {
  flex: 1;
  height: 36px;
  background: var(--tg-input-bg);
  border: 1px solid var(--tg-border);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  color: var(--tg-text-main);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.form-input:focus {
  border-color: var(--tg-blue);
}

.form-input::placeholder {
  color: var(--tg-text-muted);
}

/* Channel Verification Status Banner */
.channel-status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
}

.channel-status-pill.verified {
  background: rgba(49, 181, 69, 0.12);
  border: 1px solid rgba(49, 181, 69, 0.35);
  color: #4ceb65;
}

.channel-status-pill.warning {
  background: rgba(245, 166, 35, 0.12);
  border: 1px solid rgba(245, 166, 35, 0.35);
  color: #ffbc42;
}

.channel-status-pill.error {
  background: rgba(229, 57, 53, 0.12);
  border: 1px solid rgba(229, 57, 53, 0.35);
  color: #ff6b6b;
}

/* Media Items Multi-Container Layout (Matching Screenshots 1 & 2) */
.media-items-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.media-item-card {
  background: #17212b;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  transition: border-color 0.15s, background 0.15s;
}

.media-item-card:hover {
  border-color: rgba(255, 255, 255, 0.15);
}

.media-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.media-item-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #ffffff;
  font-size: 13.5px;
  font-weight: 600;
}

.media-item-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #8a9aa9;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.media-item-card.collapsed .media-item-chevron {
  transform: rotate(-90deg);
}

.media-item-card.collapsed .media-item-body {
  display: none;
}

.media-item-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.media-item-action-btn {
  background: transparent;
  border: none;
  color: #8a9aa9;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.media-item-action-btn:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.08);
}

.media-item-action-btn.delete:hover {
  color: #ff6b6b;
  background: rgba(255, 107, 107, 0.15);
}

.media-item-body {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Media Upload Grid */
.media-input-grid {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

@media (max-width: 600px) {
  .media-input-grid {
    flex-direction: column;
    align-items: stretch;
  }
}

.media-col-url {
  flex: 1;
}

.media-col-upload {
  flex-shrink: 0;
}

.media-label-upper {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: #8a9aa9;
  text-transform: uppercase;
  margin-bottom: 6px;
  display: block;
}

.media-upload-actions {
  display: flex;
  gap: 8px;
}

.btn-upload-file {
  background: #5865f2;
  color: #ffffff;
  height: 36px;
  padding: 0 16px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: none;
  box-shadow: 0 2px 8px rgba(88, 101, 242, 0.35);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn-upload-file:hover {
  background: #4752c4;
}

.btn-upload-file:active {
  transform: translateY(1px);
}

.btn-upload-paste {
  background: var(--tg-surface-card);
  color: var(--tg-text-main);
  border: 1px solid var(--tg-border);
  height: 36px;
  padding: 0 16px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn-upload-paste:hover {
  background: var(--tg-surface-hover);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-add-media-action {
  background: #5865f2;
  color: #ffffff;
  height: 36px;
  padding: 0 16px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: none;
  box-shadow: 0 2px 8px rgba(88, 101, 242, 0.35);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn-add-media-action:hover {
  background: #4752c4;
}

.btn-add-media-action:active {
  transform: translateY(1px);
}

/* Attached Media Preview Chip inside Item */
.media-attached-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}

.media-attached-thumb {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  background: #1e2b38;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.media-attached-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media-attached-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.media-attached-name {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--tg-text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.media-attached-size {
  font-size: 11px;
  color: var(--tg-text-muted);
}

.publish-status {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 110, 110, 0.28);
  border-radius: 8px;
  background: rgba(150, 42, 42, 0.16);
  color: #ffc2bd;
  font-size: 12px;
  line-height: 1.45;
}

.publish-status.sending {
  border-color: rgba(71, 161, 240, 0.3);
  background: rgba(31, 108, 168, 0.16);
  color: #b8ddff;
}

.publish-status[hidden] {
  display: none;
}

/* Formatting Toolbar */
.formatting-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  background: var(--tg-input-bg);
  border: 1px solid var(--tg-border);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  padding: 6px 8px;
  border-bottom: none;
}

.format-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--tg-text-main);
  height: 28px;
  min-width: 28px;
  padding: 0 6px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.12s;
  user-select: none;
}

.format-btn:hover {
  background: var(--tg-surface-hover);
  border-color: var(--tg-border);
}

.format-btn:active {
  background: var(--tg-border);
}

.toolbar-separator {
  width: 1px;
  height: 18px;
  background: var(--tg-border);
  align-self: center;
  margin: 0 4px;
}

/* Textarea */
.editor-textarea-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
}

.editor-textarea {
  width: 100%;
  min-height: 140px;
  background: var(--tg-input-bg);
  border: 1px solid var(--tg-border);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  padding: 10px 12px;
  color: var(--tg-text-main);
  font-size: 13.5px;
  font-family: inherit;
  line-height: 1.5;
  outline: none;
  resize: vertical;
  transition: border-color 0.15s;
}

.editor-textarea:focus {
  border-color: var(--tg-blue);
}

/* Character Counter Progress */
.char-counter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 5px;
  font-size: 11.5px;
  color: var(--tg-text-muted);
}

.char-counter-text {
  font-weight: 500;
}

.char-counter-text.warning {
  color: var(--tg-yellow);
}

.char-counter-text.danger {
  color: var(--tg-red);
}

/* ==========================================================================
   INLINE KEYBOARD ROW BUILDER
   ========================================================================== */

.keyboard-rows-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.keyboard-row-box {
  background: var(--tg-input-bg);
  border: 1px solid var(--tg-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.keyboard-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--tg-text-sub);
}

.row-actions-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-icon-subtle {
  background: transparent;
  border: none;
  color: var(--tg-text-muted);
  width: 24px;
  height: 24px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-icon-subtle:hover {
  background: var(--tg-surface-card);
  color: var(--tg-text-main);
}

.btn-icon-subtle.delete:hover {
  color: #ff6b6b;
}

.buttons-grid-in-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
}

.button-card-editor {
  background: var(--tg-surface-card);
  border: 1px solid var(--tg-border);
  border-radius: var(--radius-sm);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

/* Card Left Accent Line based on active color */
.button-card-editor.card-color-blue {
  border-left: 3px solid #3390ec;
}
.button-card-editor.card-color-green {
  border-left: 3px solid #31b545;
}
.button-card-editor.card-color-red {
  border-left: 3px solid #e53935;
}
.button-card-editor.card-color-default {
  border-left: 3px solid rgba(142, 152, 168, 0.4);
}

.button-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.button-card-label-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.button-num-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--tg-blue);
}

.button-color-indicator-badge {
  font-size: 9px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  line-height: 1.3;
}

.button-color-indicator-badge.badge-default {
  background: rgba(142, 152, 168, 0.15);
  color: #9ba7b5;
  border: 1px solid rgba(142, 152, 168, 0.25);
}

.button-color-indicator-badge.badge-blue {
  background: rgba(51, 144, 236, 0.18);
  color: #64b5f6;
  border: 1px solid rgba(51, 144, 236, 0.35);
}

.button-color-indicator-badge.badge-green {
  background: rgba(49, 181, 69, 0.18);
  color: #81c784;
  border: 1px solid rgba(49, 181, 69, 0.35);
}

.button-color-indicator-badge.badge-red {
  background: rgba(229, 57, 53, 0.18);
  color: #ef5350;
  border: 1px solid rgba(229, 57, 53, 0.35);
}

.btn-mini-delete {
  background: transparent;
  border: none;
  color: var(--tg-text-muted);
  cursor: pointer;
  padding: 2px;
  display: flex;
}

.btn-mini-delete:hover {
  color: #ff6b6b;
}

.input-mini {
  height: 28px;
  background: var(--tg-input-bg);
  border: 1px solid var(--tg-border);
  border-radius: 4px;
  padding: 0 8px;
  color: var(--tg-text-main);
  font-size: 12px;
  font-family: inherit;
  outline: none;
}

.input-mini:focus {
  border-color: var(--tg-blue);
}

/* Button Color Picker Section Inside Card */
.btn-color-picker-container {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 2px;
  padding-top: 5px;
  border-top: 1px dashed rgba(255, 255, 255, 0.08);
}

.btn-color-picker-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 500;
  color: var(--tg-text-muted);
  user-select: none;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.btn-color-chips-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.btn-color-chip {
  height: 25px;
  padding: 0 3px;
  background: var(--tg-input-bg);
  border: 1px solid var(--tg-border);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  overflow: hidden;
}

.btn-color-chip:hover {
  border-color: var(--tg-blue);
  background: rgba(255, 255, 255, 0.05);
  transform: translateY(-1px);
}

.btn-color-chip .color-chip-name {
  font-size: 10.5px;
  font-weight: 500;
  color: var(--tg-text-muted);
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  pointer-events: none;
}

.btn-color-chip .color-swatch-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  pointer-events: none;
}

.color-swatch-dot.dot-gray {
  background: #8e98a8;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.color-swatch-dot.dot-blue {
  background: #3390ec;
  box-shadow: 0 0 4px rgba(51, 144, 236, 0.5);
}

.color-swatch-dot.dot-green {
  background: #31b545;
  box-shadow: 0 0 4px rgba(49, 181, 69, 0.5);
}

.color-swatch-dot.dot-red {
  background: #e53935;
  box-shadow: 0 0 4px rgba(229, 57, 53, 0.5);
}

/* Active State for each color chip */
.btn-color-chip.chip-default.active {
  background: rgba(142, 152, 168, 0.22);
  border-color: #8e98a8;
}
.btn-color-chip.chip-default.active .color-chip-name {
  color: #e2e8f0;
  font-weight: 600;
}

.btn-color-chip.chip-blue.active {
  background: rgba(51, 144, 236, 0.24);
  border-color: #3390ec;
  box-shadow: 0 0 6px rgba(51, 144, 236, 0.3);
}
.btn-color-chip.chip-blue.active .color-chip-name {
  color: #64b5f6;
  font-weight: 600;
}

.btn-color-chip.chip-green.active {
  background: rgba(49, 181, 69, 0.24);
  border-color: #31b545;
  box-shadow: 0 0 6px rgba(49, 181, 69, 0.3);
}
.btn-color-chip.chip-green.active .color-chip-name {
  color: #81c784;
  font-weight: 600;
}

.btn-color-chip.chip-red.active {
  background: rgba(229, 57, 53, 0.24);
  border-color: #e53935;
  box-shadow: 0 0 6px rgba(229, 57, 53, 0.3);
}
.btn-color-chip.chip-red.active .color-chip-name {
  color: #ef5350;
  font-weight: 600;
}

/* Checkbox Switch Options */
.checkbox-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
}

.checkbox-label-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.checkbox-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--tg-text-main);
}

.checkbox-desc {
  font-size: 11px;
  color: var(--tg-text-muted);
}

/* Switch Toggle Styling */
.switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 22px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: var(--tg-input-bg);
  border: 1px solid var(--tg-border);
  transition: 0.2s;
  border-radius: 22px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: var(--tg-text-sub);
  transition: 0.2s;
  border-radius: 50%;
}

input:checked+.slider {
  background-color: var(--tg-blue);
  border-color: var(--tg-blue);
}

input:checked+.slider:before {
  transform: translateX(16px);
  background-color: #ffffff;
}

/* Primary Broadcast Button */
.btn-publish-big {
  height: 44px;
  font-size: 14.5px;
  font-weight: 700;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 14px var(--tg-blue-glow);
}

/* ==========================================================================
   MODAL WINDOWS & TOAST NOTIFICATIONS
   ========================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-container {
  background: var(--tg-panel-bg);
  border: 1px solid var(--tg-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-popup);
  width: 90%;
  max-width: 600px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(12px) scale(0.98);
  transition: transform 0.2s ease;
}

.modal-backdrop.open .modal-container {
  transform: translateY(0) scale(1);
}

.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--tg-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.modal-title {
  font-size: 15px;
  font-weight: 700;
  color: #ffffff;
}

.btn-modal-close {
  background: transparent;
  border: none;
  color: var(--tg-text-sub);
  cursor: pointer;
  padding: 4px;
  display: flex;
}

.btn-modal-close:hover {
  color: #ffffff;
}

.modal-body {
  padding: 18px;
  overflow-y: auto;
  max-height: calc(90vh - 120px);
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-body::-webkit-scrollbar {
  width: 6px;
}

.modal-body::-webkit-scrollbar-track {
  background: transparent;
}

.modal-body::-webkit-scrollbar-thumb {
  background: var(--tg-border);
  border-radius: 4px;
}

.modal-footer {
  flex-shrink: 0;
  padding: 12px 18px;
  border-top: 1px solid var(--tg-border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.json-textarea {
  width: 100%;
  height: 240px;
  background: var(--tg-input-bg);
  border: 1px solid var(--tg-border);
  border-radius: var(--radius-sm);
  padding: 10px;
  color: var(--tg-text-main);
  font-family: var(--tg-mono);
  font-size: 12.5px;
  outline: none;
  resize: vertical;
}

/* Toast Notice */
.toast-notice {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--tg-panel-bg);
  border: 1px solid var(--tg-border);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  z-index: 2000;
  animation: slideToast 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast-notice.success {
  border-color: rgba(49, 181, 69, 0.5);
}

.toast-notice.error {
  border-color: rgba(229, 57, 53, 0.5);
}

@keyframes slideToast {
  from {
    opacity: 0;
    transform: translateY(16px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Spinner */
.spinner-icon {
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

/* ==========================================================================
   CHANNELS LIST & SEND MODAL STYLES
   ========================================================================== */
.modal-user-identity-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--tg-surface-card);
  border: 1px solid var(--tg-border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
}

.modal-user-identity-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--tg-blue);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
  overflow: hidden;
}

.modal-user-identity-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.modal-user-identity-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.modal-user-identity-name {
  font-size: 13px;
  font-weight: 600;
  color: #ffffff;
}

.modal-user-identity-meta {
  font-size: 11px;
  color: var(--tg-text-muted);
}

.channels-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.channels-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.channels-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--tg-text-main);
}

.channels-count-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 10px;
  background: rgba(51, 144, 236, 0.15);
  color: #64b5f6;
  border: 1px solid rgba(51, 144, 236, 0.3);
}

.btn-refresh-subtle {
  background: transparent;
  border: 1px solid var(--tg-border);
  color: var(--tg-text-muted);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-refresh-subtle:hover {
  background: var(--tg-surface-hover);
  color: #ffffff;
  border-color: var(--tg-blue);
}

.channels-cards-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 2px;
}

.channel-card-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  background: var(--tg-surface-card);
  border: 1px solid var(--tg-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.channel-card-item:hover {
  background: var(--tg-surface-hover);
  border-color: rgba(51, 144, 236, 0.5);
  transform: translateY(-1px);
}

.channel-card-item.selected {
  background: rgba(51, 144, 236, 0.14);
  border-color: var(--tg-blue);
  box-shadow: 0 0 10px rgba(51, 144, 236, 0.22);
}

.channel-card-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.channel-card-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2481cc, #19588c);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.channel-card-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.channel-card-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.channel-card-title {
  font-size: 13px;
  font-weight: 600;
  color: #ffffff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.channel-card-sub {
  font-size: 11px;
  color: var(--tg-text-muted);
}

.channel-role-tag {
  font-size: 9.5px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.2px;
}

.channel-role-tag.creator {
  background: rgba(245, 158, 11, 0.18);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.channel-role-tag.admin {
  background: rgba(16, 185, 129, 0.18);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.channel-radio-indicator {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--tg-border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.channel-card-item.selected .channel-radio-indicator {
  border-color: var(--tg-blue);
  background: var(--tg-blue);
}

.channel-card-item.selected .channel-radio-indicator::after {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #ffffff;
}

/* Empty Channels Box */
.channels-empty-box {
  background: rgba(0, 0, 0, 0.2);
  border: 1px dashed var(--tg-border);
  border-radius: var(--radius-sm);
  padding: 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.channels-empty-box-title {
  font-size: 12.5px;
  font-weight: 600;
  color: #ffffff;
}

.channels-empty-box-desc {
  font-size: 11.5px;
  color: var(--tg-text-sub);
  line-height: 1.4;
}

/* Link Channel Details Accordion */
.link-channel-details {
  border: 1px solid var(--tg-border);
  border-radius: var(--radius-sm);
  background: var(--tg-surface-card);
  overflow: hidden;
}

.link-channel-summary {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--tg-text-sub);
  display: flex;
  align-items: center;
  justify-content: space-between;
  list-style: none;
  user-select: none;
}

.link-channel-summary::-webkit-details-marker {
  display: none;
}

.link-channel-details[open] .details-chevron {
  transform: rotate(180deg);
}

.link-channel-body {
  padding: 10px 12px;
  border-top: 1px solid var(--tg-border);
  background: var(--tg-input-bg);
}

.input-row {
  display: flex;
  gap: 8px;
  align-items: center;
  width: 100%;
}

.input-row .form-input {
  flex: 1;
  min-width: 0;
}

/* Selected Channel Status Banner */
.channel-selected-banner {
  background: rgba(51, 144, 236, 0.1);
  border: 1px solid rgba(51, 144, 236, 0.25);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 12px;
  color: #93c5fd;
  display: flex;
  align-items: center;
  gap: 8px;
}

.channel-selected-banner.none-selected {
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.25);
  color: #fca5a5;
}

.broadcast-options-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 0;
}

.broadcast-option-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--tg-text-sub);
  cursor: pointer;
}

.broadcast-option-item input[type="checkbox"] {
  accent-color: var(--tg-blue);
  cursor: pointer;
}

/* Official Telegram OAuth Modal Styling */
.oauth-modal-header-emblem {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}

.oauth-emblem-cluster {
  display: flex;
  align-items: center;
  justify-content: center;
}

.oauth-emblem-circle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.oauth-emblem-circle.tg-blue {
  background: #2481cc;
  color: #ffffff;
  z-index: 2;
  margin-right: -10px;
}

.oauth-emblem-circle.sparkie-red {
  background: #e53935;
  color: #ffffff;
  font-weight: 800;
  font-size: 18px;
  z-index: 1;
}

.btn-telegram-oauth-continue {
  background: #2481cc;
  color: #ffffff;
  border: none;
  border-radius: 8px;
  height: 44px;
  font-size: 14.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: 0 4px 14px rgba(36, 129, 204, 0.4);
  width: 100%;
}

.btn-telegram-oauth-continue:hover {
  background: #2c8de2;
  box-shadow: 0 6px 18px rgba(36, 129, 204, 0.5);
  transform: translateY(-1px);
}

.btn-telegram-oauth-continue:active {
  transform: translateY(1px);
}

/* ==========================================================================
   MOBILE RESPONSIVE & PREVIEW TOGGLE ARCHITECTURE
   ========================================================================== */

/* Desktop defaults: hide mobile switcher & bottom bar */
.mobile-segmented-switch {
  display: none;
}

.mobile-bottom-bar {
  display: none;
}

.mobile-back-to-editor-btn {
  display: none;
}

@media (max-width: 850px) {
  /* Top Studio Header responsive styling */
  .top-header {
    height: 48px;
    padding: 0 10px;
    gap: 6px;
  }

  .brand-badge {
    gap: 7px;
  }

  .brand-logo-img {
    width: 24px;
    height: 24px;
  }

  .brand-title {
    font-size: 0.95rem;
    font-weight: 700;
  }

  /* Compact secondary buttons in header: show icons only, prevent text squishing */
  .header-right {
    gap: 5px;
  }

  .header-right .btn-secondary {
    width: 32px;
    height: 32px;
    padding: 0;
    min-width: 32px;
    border-radius: 6px;
    justify-content: center;
  }

  .header-right .btn-secondary span {
    display: none;
  }

  /* On mobile header, hide the desktop Send Post text to prevent clipping */
  .header-right .send-btn {
    display: none;
  }

  #btn-quick-login span {
    display: none;
  }

  #btn-quick-login {
    width: 32px;
    height: 32px;
    padding: 0;
    min-width: 32px;
    justify-content: center;
  }

  .user-name-text {
    display: none;
  }

  /* Segmented View Switcher: Editor / Preview */
  .mobile-segmented-switch {
    display: flex;
    align-items: center;
    background: #0d1520;
    border: 1px solid var(--tg-border);
    border-radius: 20px;
    padding: 2px;
    gap: 2px;
    flex-shrink: 0;
  }

  .mobile-segment-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 16px;
    border: none;
    background: transparent;
    color: var(--tg-text-sub);
    font-size: 11.5px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s ease;
  }

  .mobile-segment-btn.active {
    background: var(--tg-blue);
    color: #ffffff;
    box-shadow: 0 1px 6px var(--tg-blue-glow);
  }

  .mobile-segment-btn:not(.active):hover {
    color: var(--tg-text-main);
  }

  /* Workspace 100% Full Width Switching */
  .studio-body {
    flex-direction: column;
    overflow: hidden;
    position: relative;
  }

  .pane-resizer-divider {
    display: none !important;
  }

  /* DEFAULT: Editor is 100% full width, Preview is hidden */
  .studio-body:not(.mobile-show-preview) .builder-panel {
    display: flex !important;
    width: 100% !important;
    height: 100% !important;
    flex: 1;
  }

  .studio-body:not(.mobile-show-preview) .preview-panel {
    display: none !important;
  }

  /* PREVIEW ACTIVE: Preview is 100% full width, Editor is hidden */
  .studio-body.mobile-show-preview .builder-panel {
    display: none !important;
  }

  .studio-body.mobile-show-preview .preview-panel {
    display: flex !important;
    width: 100% !important;
    height: 100% !important;
    flex: 1;
  }

  /* Back to Editor button inside Preview Channel Header */
  .mobile-back-to-editor-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #ffffff;
    padding: 5px 9px;
    border-radius: 6px;
    font-size: 11.5px;
    font-weight: 600;
    cursor: pointer;
    margin-right: 6px;
    flex-shrink: 0;
    transition: background 0.15s;
  }

  .mobile-back-to-editor-btn:hover {
    background: rgba(255, 255, 255, 0.16);
  }

  .tg-preview-container.light-theme .mobile-back-to-editor-btn {
    background: rgba(0, 0, 0, 0.06);
    border-color: rgba(0, 0, 0, 0.1);
    color: #050505;
  }

  /* Touch-friendly Editor Scrollable area */
  .builder-scrollable {
    padding: 12px 10px 88px !important;
    gap: 12px;
  }

  .builder-card {
    padding: 14px 12px;
    border-radius: var(--radius-sm);
  }

  .builder-card-header {
    margin-bottom: 12px;
  }

  /* Formatting Toolbar: smooth horizontal scroll without ugly wrapping */
  .formatting-toolbar {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    padding: 5px;
    gap: 4px;
    scrollbar-width: none;
  }

  .formatting-toolbar::-webkit-scrollbar {
    display: none;
  }

  .format-btn {
    flex-shrink: 0;
    height: 28px;
    padding: 0 8px;
  }

  .char-counter-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  /* Telegram Chat Viewport on Mobile */
  .tg-chat-viewport {
    padding: 14px 10px 88px !important;
  }

  .tg-message-stream {
    max-width: 100% !important;
  }

  .tg-message-bubble {
    max-width: 100% !important;
  }

  .tg-bubble-photo-container {
    max-width: 100% !important;
  }

  .tg-channel-subscribers {
    font-size: 11px;
  }

  /* Mobile Floating Bottom Action Bar */
  .mobile-bottom-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    padding: 0 12px;
    background: rgba(14, 22, 33, 0.94);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--tg-border);
    z-index: 90;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
  }

  .mobile-bottom-toggle-btn {
    flex: 1.1;
    height: 42px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 8px;
    background: var(--tg-surface-card);
    color: var(--tg-text-main);
    border: 1px solid var(--tg-border);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    cursor: pointer;
  }

  .mobile-bottom-send-btn {
    flex: 0.9;
    height: 42px;
    font-size: 13px;
    font-weight: 700;
    border-radius: 8px;
    background: var(--tg-blue);
    color: #ffffff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    cursor: pointer;
    box-shadow: 0 2px 10px var(--tg-blue-glow);
  }
}

@media (max-width: 420px) {
  .brand-title {
    display: none;
  }
}
