:root {
  --primary: #4F46E5;
  --primary-hover: #4338CA;
  --bg: #F3F4F6;
  --panel-bg: #FFFFFF;
  --text: #1F2937;
  --border: #E5E7EB;
}

* {
  box-sizing: border-box;
  font-family: 'Inter', sans-serif;
}

body, html {
  margin: 0;
  padding: 0;
  height: 100%;
  background-color: var(--bg);
  color: var(--text);
}

.app-container {
  display: flex;
  height: calc(100vh - 58px);
  overflow: hidden;
}

.admin-panel {
  width: 400px;
  min-width: 400px;
  background: var(--panel-bg);
  padding: 16px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  box-shadow: 2px 0 10px rgba(0,0,0,0.05);
  z-index: 10;
}

.admin-panel::-webkit-scrollbar {
  width: 6px;
}
.admin-panel::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

.admin-panel h1 {
  font-size: 20px;
  margin-top: 0;
  margin-bottom: 16px;
}

.control-group {
  background: #FAFAFA;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
}

.control-group h3 {
  margin: 0 0 8px 0;
  font-size: 13px;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.control-group label {
  display: block;
  font-size: 13px;
  margin-bottom: 8px;
  font-weight: 600;
  color: #4B5563;
}

.control-group input[type="text"],
.control-group input[type="file"] {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 8px;
  font-size: 13px;
  transition: border-color 0.2s;
}

.control-group input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* --- Модальное окно кадрирования --- */
.crop-modal {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.crop-modal-content {
  background: white;
  padding: 30px;
  border-radius: 12px;
  width: 90%;
  max-width: 600px;
  display: flex;
  flex-direction: column;
}

.crop-img-container {
  width: 100%;
  height: 400px;
  background: #f3f4f6;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 20px;
}

.crop-img-container img {
  display: block;
  max-width: 100%;
}

.crop-actions {
  display: flex;
  justify-content: flex-end;
  gap: 15px;
}

.image-preview {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.image-preview img {
  max-width: 100%;
  max-height: 100px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.small-btn {
  background: #FEE2E2;
  color: #DC2626;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 13px;
}

.settings-row input[type="range"] {
  width: 60%;
}

.settings-row input[type="color"] {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  padding: 0;
}

.settings-row label {
  margin-bottom: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 400;
}

.primary-btn, .secondary-btn {
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 8px;
}

.primary-btn {
  background: var(--primary);
  color: white;
}

.primary-btn:hover {
  background: var(--primary-hover);
}

/* Floating Add Button */
.floating-add-btn {
  position: absolute;
  left: 400px; /* Right on the border of admin-panel */
  top: 50%;
  transform: translate(-50%, -50%);
  width: 52px;
  height: 52px;
  background-color: var(--primary);
  color: white;
  border: none;
  border-radius: 50%;
  box-shadow: 0 4px 15px rgba(79, 70, 229, 0.4);
  cursor: pointer;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.floating-add-btn:hover {
  transform: translate(-50%, -50%) scale(1.1);
  background-color: var(--primary-hover);
}

.floating-add-btn:active {
  transform: translate(-50%, -50%) scale(0.95);
}

.floating-add-btn svg {
  width: 28px;
  height: 28px;
}

.secondary-btn {
  background: white;
  border: 2px solid var(--primary);
  color: var(--primary);
}

.secondary-btn:hover {
  background: #EEF2FF;
}

.preview-panel {
  flex: 1;
  overflow-y: auto;
  padding: 40px;
  display: flex;
  flex-direction: column;
  gap: 40px;
}

#pagesContainer {
  display: flex;
  flex-direction: column;
  gap: 40px;
  margin: 0 auto;
}

.page {
  width: 793px;
  height: 1122px;
  max-height: 1122px;
  background: white;
  box-shadow: 0 10px 25px rgba(0,0,0,0.1);
  padding: 24px 20px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
}

.card {
  border-right: 1px dashed #D1D5DB;
  border-bottom: 1px dashed #D1D5DB;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px;
  text-align: center;
  position: relative;
  overflow: hidden;
  background: white;
  min-height: 0;
  height: 100%;
  box-sizing: border-box;
}

/* Замыкание контура реза для обычных карточек */
.card:nth-child(3n+1) {
  border-left: 1px dashed #D1D5DB;
}
.card:nth-child(-n+3) {
  border-top: 1px dashed #D1D5DB;
}

/* Тёмная тема для Shorts */
.card.dark-theme {
  justify-content: center;
}
.card.dark-theme .card-img-container {
  display: none;
}

/* --- РЕЖИМ ЦВЕТНЫХ РАМОК --- */
.page.colored-borders {
  gap: 12px;
  padding: 32px 28px; /* Безопасные симметричные поля отступов (равномерно слева, справа, сверху, снизу) */
  box-sizing: border-box;
}

.page.colored-borders .card {
  border: 5px solid var(--card-border-color, #E2E8F0) !important;
  border-radius: 16px;
  box-sizing: border-box;
}

.page.colored-borders .card.empty {
  border: 2px dashed #E2E8F0 !important;
  border-radius: 16px;
  background: #FAFAFA;
}

  /* 9 гармоничных цветов для рамок */
  .border-color-1 { --card-border-color: #FB7185; } /* Розовый */
  .border-color-2 { --card-border-color: #38BDF8; } /* Голубой */
  .border-color-3 { --card-border-color: #4ADE80; } /* Салатовый */
  .border-color-4 { --card-border-color: #FBBF24; } /* Солнечный */
  .border-color-5 { --card-border-color: #A78BFA; } /* Лавандовый */
  .border-color-6 { --card-border-color: #FB923C; } /* Оранжевый */
  .border-color-7 { --card-border-color: #2DD4BF; } /* Бирюзовый */
  .border-color-8 { --card-border-color: #F43F5E; } /* Малиновый */
  .border-color-9 { --card-border-color: #818CF8; } /* Индиго */

.card-img-container {
  width: 100%;
  height: 180px; /* Уменьшили высоту контейнера для картинки чтобы дать больше места тексту */
  flex: none; /* Фиксируем контейнер, чтобы фото не распирало 3-й ряд */
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

.card-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.card-text-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding-bottom: 8px;
}

  .card.editing {
    border: 2px dashed #4F46E5 !important;
    background-color: #EEF2FF !important;
  }
  
  .card.editing::after {
    content: 'РЕЖИМ РЕДАКТИРОВАНИЯ';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: #4F46E5;
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 4px 0;
    z-index: 10;
  }

.delete-card-btn, .edit-card-btn {
  position: absolute;
  top: 6px;
  color: white;
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.2s, transform 0.1s;
  z-index: 5;
}

.delete-card-btn {
  right: 6px;
  background: #EF4444;
}

.edit-card-btn {
  right: 36px;
  background: #3B82F6;
  font-size: 12px;
}

.card:hover .delete-card-btn,
.card:hover .edit-card-btn {
  opacity: 1;
}

.delete-card-btn:active,
.edit-card-btn:active {
  transform: scale(0.9);
}

/* Для пустых слотов */
.card.empty {
  background: #F9FAFB;
}

/* Для печати */
@media print {
  @page {
    size: A4 portrait;
    margin: 0;
  }
  
  body {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    background: white;
  }
  
  .app-container {
    height: auto;
    overflow: visible;
    display: block;
  }
  
  .admin-panel,
  .site-header,
  #notepadDrawer,
  .floating-add-btn {
    display: none !important;
  }
  
  .preview-panel {
    padding: 0;
    overflow: visible;
    display: block;
  }
  
  .page {
    box-shadow: none;
    margin: 0;
    page-break-after: always; /* Каждый лист на новой странице */
    border: none;
  }
  
  .delete-card-btn {
    display: none !important;
  }
  
  #livePreviewCard {
    visibility: hidden;
  }
  
  .notepad-drawer {
    display: none !important;
  }
}

/* Notepad Drawer */
.notepad-drawer {
  position: fixed;
  top: 0;
  right: -400px;
  width: 400px;
  height: 100vh;
  background: #1E1E2D;
  color: #fff;
  box-shadow: -5px 0 25px rgba(0,0,0,0.2);
  transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 100;
  display: flex;
  flex-direction: column;
}

.notepad-drawer.open {
  right: 0;
}

.notepad-toggle {
  position: absolute;
  top: 50%;
  left: -48px;
  transform: translateY(-50%) rotate(-90deg);
  transform-origin: left top;
  background: #D9381E;
  color: white;
  padding: 10px 20px;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.5px;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.15);
  user-select: none;
}

.notepad-header {
  padding: 20px;
  background: #171722;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #2B2B40;
}

.notepad-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.save-indicator {
  font-size: 12px;
  color: #A1A5B7;
  display: flex;
  align-items: center;
  gap: 6px;
}

.save-indicator span {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: #10B981;
  border-radius: 50%;
}

.notepad-tools {
  padding: 20px;
  border-bottom: 1px solid #2B2B40;
}

.tools-label {
  font-size: 13px;
  color: #A1A5B7;
  margin-bottom: 12px;
}

.tools-buttons {
  display: flex;
  gap: 8px;
}

.tool-btn {
  flex: 1;
  background: #2B2B40;
  border: 1px solid #3F4254;
  color: white;
  padding: 10px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  transition: all 0.2s;
}

.tool-btn:hover {
  background: #3F4254;
  border-color: #565674;
}

.tool-btn:active {
  transform: translateY(1px);
}

#notepadTextarea {
  flex: 1;
  background: #1E1E2D;
  border: none;
  color: #E4E6EF;
  padding: 20px;
  font-size: 14px;
  line-height: 1.6;
  resize: none;
}

#notepadTextarea:focus {
  outline: none;
}

#notepadTextarea::placeholder {
  color: #565674;
  font-style: italic;
}

.top-nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: white;
  padding: 10px 20px;
  border-bottom: 1px solid #E5E7EB;
  z-index: 10;
  position: relative;
}

.mode-switcher {
  display: flex;
  gap: 10px;
  flex: 1;
}

.project-actions {
  display: flex;
  gap: 8px;
  flex: 1;
  justify-content: flex-end;
  align-items: center;
}

.project-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid transparent;
  outline: none;
}

.project-btn.save {
  background: #F0FDF4;
  color: #15803D;
  border-color: #BBF7D0;
}

.project-btn.save:hover {
  background: #DCFCE7;
  border-color: #86EFAC;
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(22, 163, 74, 0.15);
}

.project-btn.load {
  background: #F8FAFC;
  color: #334155;
  border-color: #CBD5E1;
}

.project-btn.load:hover {
  background: #F1F5F9;
  border-color: #94A3B8;
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

.project-btn:active {
  transform: translateY(0);
}

.mode-btn {
  background: none;
  border: none;
  padding: 10px 20px;
  font-weight: 600;
  color: #6B7280;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s;
}

.mode-btn:hover {
  background: #F3F4F6;
}

.mode-btn.active {
  background: var(--primary);
  color: white;
}

/* Video Container */
.video-container {
  display: flex;
  height: calc(100vh - 58px);
  overflow: hidden;
}

.video-admin-panel {
  width: 400px;
  background: var(--panel-bg);
  padding: 20px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  box-shadow: 2px 0 10px rgba(0,0,0,0.05);
  display: flex;
  flex-direction: column;
}

.video-subtitle {
  font-size: 13px;
  color: #6B7280;
  margin-top: 0;
  margin-bottom: 20px;
}

.video-cards-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.video-card-item {
  border: 1px solid #E5E7EB;
  padding: 15px;
  border-radius: 8px;
  background: #F9FAFB;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.video-card-item h4 {
  margin: 0;
  font-size: 14px;
}

.video-preview-panel {
  flex: 1;
  background: #111827;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  gap: 20px;
}

.canvas-wrapper {
  height: 70vh;
  aspect-ratio: 9/16;
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

#videoCanvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.video-controls {
  display: flex;
  gap: 15px;
  width: 100%;
  max-width: 400px;
}

/* --- Плеер управления видео --- */
.video-player-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 320px;
  background: #1F2937;
  padding: 8px 14px;
  border-radius: 12px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.action-icon-btn {
  background: var(--primary);
  border: none;
  color: white;
  font-size: 16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.action-icon-btn:hover {
  transform: scale(1.05);
}

#videoSeekbar {
  flex: 1;
  cursor: pointer;
  accent-color: var(--primary);
}

#videoTimeDisplay {
  font-size: 13px;
  font-weight: 600;
  color: #F3F4F6;
  min-width: 85px;
  text-align: right;
}

/* --- Оверлей Экспорта --- */
.export-overlay {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.85);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.export-box {
  background: white;
  padding: 40px;
  border-radius: 12px;
  text-align: center;
  max-width: 400px;
}

.export-box h2 {
  margin: 20px 0 10px 0;
  color: var(--text);
}

.export-box p {
  color: #6B7280;
  font-size: 14px;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 5px solid #E5E7EB;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- Шапка сайта (логотип теперь внутри top-nav-bar) --- */
.site-header {
  display: none; /* Удалено */
}

.site-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.site-logo img {
  width: 36px;
  height: 36px;
  border-radius: 8px; /* Небольшое скругление для квадрата */
}

.site-title {
  font-size: 28px;
  font-weight: 800;
  color: #1F2937;
  letter-spacing: -0.5px;
}

/* --- Заглушка для мобильных устройств --- */
.mobile-stub {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #111827;
  color: #ffffff;
  z-index: 999999;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  box-sizing: border-box;
}

.mobile-stub-content {
  max-width: 400px;
}

.mobile-stub h2 {
  font-size: 24px;
  margin-bottom: 15px;
  color: #F9FAFB;
}

.mobile-stub p {
  font-size: 15px;
  color: #9CA3AF;
  line-height: 1.6;
}

@media (max-width: 1024px) {
  .top-nav-bar,
  .app-container,
  #exportOverlay,
  .floating-add-btn {
    display: none !important;
  }
  
  .mobile-stub {
    display: flex;
  }
}

/* --- Update Banner --- */
.update-banner {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background-color: #10B981;
  color: white;
  padding: 12px 24px;
  border-radius: 50px;
  box-shadow: 0 10px 25px rgba(16, 185, 129, 0.4);
  display: flex;
  align-items: center;
  gap: 15px;
  z-index: 1000000;
  font-weight: 600;
  font-size: 14px;
  animation: slideUp 0.5s ease-out forwards;
}

.update-banner button {
  background: white;
  color: #10B981;
  border: none;
  padding: 6px 16px;
  border-radius: 20px;
  font-weight: bold;
  cursor: pointer;
  transition: transform 0.1s;
}

.update-banner button:active {
  transform: scale(0.95);
}

@keyframes slideUp {
  from { bottom: -100px; opacity: 0; }
  to { bottom: 20px; opacity: 1; }
}

 / *   C u s t o m   T o g g l e   S w i t c h   * / 
 . t o g g l e - s w i t c h   { 
     p o s i t i o n :   r e l a t i v e ; 
     d i s p l a y :   i n l i n e - b l o c k ; 
     w i d t h :   4 4 p x ; 
     h e i g h t :   2 4 p x ; 
 } 
 
 . t o g g l e - s w i t c h   i n p u t   { 
     o p a c i t y :   0 ; 
     w i d t h :   0 ; 
     h e i g h t :   0 ; 
 } 
 
 . t o g g l e - s w i t c h   . s l i d e r   { 
     p o s i t i o n :   a b s o l u t e ; 
     c u r s o r :   p o i n t e r ; 
     t o p :   0 ; 
     l e f t :   0 ; 
     r i g h t :   0 ; 
     b o t t o m :   0 ; 
     b a c k g r o u n d - c o l o r :   # 4 B 5 5 6 3 ; 
     t r a n s i t i o n :   . 2 s ; 
 } 
 
 . t o g g l e - s w i t c h   . s l i d e r : b e f o r e   { 
     p o s i t i o n :   a b s o l u t e ; 
     c o n t e n t :   " " ; 
     h e i g h t :   1 8 p x ; 
     w i d t h :   1 8 p x ; 
     l e f t :   3 p x ; 
     b o t t o m :   3 p x ; 
     b a c k g r o u n d - c o l o r :   w h i t e ; 
     t r a n s i t i o n :   . 2 s ; 
 } 
 
 . t o g g l e - s w i t c h   i n p u t : c h e c k e d   +   . s l i d e r   { 
     b a c k g r o u n d - c o l o r :   v a r ( - - p r i m a r y ) ; 
 } 
 
 . t o g g l e - s w i t c h   i n p u t : c h e c k e d   +   . s l i d e r : b e f o r e   { 
     t r a n s f o r m :   t r a n s l a t e X ( 2 0 p x ) ; 
 } 
 
 . t o g g l e - s w i t c h   . s l i d e r . r o u n d   { 
     b o r d e r - r a d i u s :   2 4 p x ; 
 } 
 
 . t o g g l e - s w i t c h   . s l i d e r . r o u n d : b e f o r e   { 
     b o r d e r - r a d i u s :   5 0 % ; 
 } 
  
 