:root{
  --header-h: 56px;
  --footer-h: 56px;
  --menu-w: 220px; /* ширина левой панели вместе с паддингами */
  --gap: 10px;
}

/* ====== базовая нормализация ====== */
*,
*::before,
*::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: Arial, sans-serif;
  background-color: #f4f4f4;
  margin: 0;
  padding: 0 0 var(--footer-h) 0; /* место под fixed-футер */
}

/* ====== шапка/футер ====== */
header {
  background-color: #333;
  color: #fff;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  text-align: center;
  font-size: 20px;
}

footer {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: var(--footer-h);
  background-color: #333;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  text-align: center;
  z-index: 1000;
}

/* ====== макет: меню + контент ====== */
.container {
  display: flex;
  min-height: calc(100vh - var(--header-h)); /* не учитываем футер, мы дали padding-bottom body */
  padding-top: var(--gap);
}

/* левое фикс-меню не перекрывает футер */
.menu {
  position: fixed;
  top: var(--header-h);
  bottom: var(--footer-h);
  left: 0;
  width: var(--menu-w);
  background-color: #444;
  padding: 20px;
  overflow: auto;
  color: #fff;
}

.menu ul { list-style: none; margin: 0; padding: 0; }
.menu ul li { margin-bottom: 10px; }
.menu ul li a {
  display: block;
  padding: 10px;
  background-color: #555;
  color: white;
  text-decoration: none;
  border-radius: 5px;
}
.menu ul li a:hover { background-color: #666; }

/* выпадашки меню — без «рывков» верстки */
.menu ul li ul { display: none; padding-left: 12px; margin-top: 8px; }
.menu ul li:hover > ul { display: block; }
.menu ul li ul li { margin-bottom: 8px; }

.button-container { display: flex; flex-direction: column; gap: 10px; }

/* основной контент сдвинут на ширину меню */
main {
  margin-left: var(--menu-w);
  padding: 20px;
  background-color: #fff;
  flex: 1 1 auto;
  min-width: 0; /* критично для предотвращения переполнения в flex */
}

/* ====== кнопки ====== */
/* единое правило для всех кнопок */
button {
  display: inline-block;
  padding: 10px 16px;
  font-size: 14px;
  line-height: 1.2;
  background-color: #4CAF50;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;   /* не ломать строку внутри */
  max-width: 100%;       /* не шире контейнера */
}
button:hover { background-color: #45a049; }
button:disabled { background-color: #ccc; cursor: not-allowed; }

/* персональный вид для большой GPT-кнопки */
#gpt-button{
  display: block;
  width: 100%;
  max-width: 250px;
  padding: 14px 20px;
  font-size: 18px;
  font-weight: bold;
  text-align: center;
  border: none;
  border-radius: 8px;
  background: #4CAF50;
  color: #fff;
  cursor: pointer;
  transition: background .3s ease-in-out;
  margin-top: 10px;
}
#gpt-button:hover{ background:#45a049; }

/* ====== правый попап загрузки видео ====== */
#video-download-popup {
  position: fixed;
  top: 10px;
  right: 0;
  width: min(90vw, 320px);
  background: #fff;
  box-shadow: -2px 0 5px rgba(0,0,0,.3);
  padding: 10px;
  border-radius: 10px 0 0 10px;
  max-height: 80vh;
  display: flex;
  z-index: 9999;
  transform: translateX(100%); /* скрыт по умолчанию */
  will-change: transform;
  transition: transform .3s ease-in-out;
}
#video-download-popup:hover { transform: translateX(0); }
#video-download-popup.hidden { display: block; } /* сохранить hover-раскрытие */

#popup-content-wrapper {
  max-height: 80%;
  overflow-y: auto;
  flex-grow: 1;
}

/* триггер-полоса */
#video-download-toggle {
  position: absolute;
  left: -15px;
  top: 50%;
  width: 15px;
  height: 50px;
  background: gray;
  cursor: pointer;
  border-radius: 5px 0 0 5px;
  transform: translateY(-50%);
}

/* ====== селекты (кастом) ====== */
.select-wrapper { position: relative; width: 100%; min-width: 0; }

#modelSelect,
#rewriteMethod {
  appearance: none;
  width: 100%;
  padding: 12px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  background: linear-gradient(to bottom, #a000c8, #68008a);
  color: #fff;
  text-align: center;
  cursor: pointer;
  outline: none;
  transition: background .3s ease-in-out;
}
#modelSelect:hover,
#rewriteMethod:hover,
#rewriteMethod:focus { background: linear-gradient(to bottom, #8a00a0, #5a0070); }

.select-wrapper::after{
  content:"▼";
  position:absolute;
  top:50%; right:15px;
  transform:translateY(-50%);
  color:#fff; font-size:14px; pointer-events:none;
}

#modelSelect option,
#rewriteMethod option{
  background:#3bb9ff;
  color:#fff;
  font-size:14px;
  font-weight:bold;
}

/* ====== статусы, таймеры, результаты ====== */
/* общая строка: кнопка + таймер + результат — адаптивно и без фикс-ширин */
.button-wrapper{
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  min-width: 0;
}

.timer-block,
.result-block{
  padding: 10px;
  border-radius: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  /* вместо фикс ширин — ограничиваемся контейнером */
  flex: 0 1 260px;       /* можно сжать до ~260px */
  max-width: 100%;
}

.timer-block{
  border:2px solid #FF9800;
  background-color:#FFE0B2;
  color:#333;
}

.result-block{
  border:2px solid #4CAF50;
  background-color:#C8E6C9;
  color:#333;
}

.result-block p{ margin:0; white-space:nowrap; }
.completion-time{ margin-left:5px; white-space:nowrap; }

/* ====== плавающие статусы ====== */
#statusDiv{
  position: fixed;
  top: 10px; right: 10px;
  width: min(90vw, 320px);
  height: 40px;
  background-color: rgba(76,175,80,.85);
  color:#fff; font-size:14px;
  padding:10px;
  overflow:auto;
  border-radius:5px;
  box-shadow:2px 2px 10px rgba(0,0,0,.2);
  z-index: 10000;
}

/* ====== гриды превью/фото ====== */
#previewContainer{
  display:flex; flex-wrap:wrap; gap:10px; margin-top:20px;
}
.image-container{ position:relative; width:100px; height:100px; }
.image-container img{ width:100%; height:100%; object-fit:cover; }

.hidden{ display:none !important; }

/* панель загрузки фото — занимает доступную высоту, не вылезая под футер */
#photo-upload-panel{
  padding:20px;
  border:1px solid #ccc;
  background-color:#fff;
  width: 100%;
  max-width: 100%;
  height: calc(100vh - var(--header-h) - var(--footer-h) - 40px);
  box-sizing:border-box;
  display:flex; flex-direction:column;
}

#header{ display:flex; align-items:center; gap:10px; margin-bottom:15px; }
#urlInput, #urlInputR{
  width: 100%;
  max-width: 420px;
  padding: 5px;
  font-size: 14px;
}

.savefoto{ width:150px; }
#copyLinksBtn{ width:230px; }
.deleteall{ width:130px; }

/* маленькие кнопки – без отрицательных отступов */
.small-add-btn,
.small-add-btnr,
.small-add-btnrv{
  height: 30px;
  font-size: 16px;
  padding: 0 10px;
  background-color:#28a745;
  color:#fff;
  border:none; cursor:pointer;
  margin-left: 0;
  width: auto; max-width: 100%;
}

/* сетка фото — резиновая */
#photo-grid{
  display:grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap:10px;
  max-height: 450px;
  padding:10px;
  box-sizing:border-box;
  height: 100%;
  overflow-y:auto;
}

/* таблица */
.table{ width:100%; border-collapse:collapse; table-layout: fixed; }
.table th, .table td{
  border:1px solid #ddd; padding:12px; text-overflow:ellipsis; overflow:hidden; white-space:nowrap;
}
.table th{ background:#f2f2f2; font-weight:bold; }
.table tr:nth-child(even){ background-color:#f9f9f9; }
.table tr:hover{ background-color:#ddd; }

/* уведомление */
.notification{
  position:fixed; top:20px; right:20px;
  background-color:#4caf50; color:#fff;
  padding:10px 20px; border-radius:5px;
  box-shadow:0 4px 8px rgba(0,0,0,.2);
  opacity:1; transition:opacity .5s ease;
  z-index:1000;
}
.notification.hidden{ opacity:0; visibility:hidden; }

/* logout */
.logout-container{ margin-left:auto; }
.logout-button{
  text-decoration:none; color:#fff; background:#d9534f;
  padding:8px 16px; border-radius:4px; font-weight:bold; transition:background-color .3s;
}
.logout-button:hover{ background:#c9302c; }

/* слоты фото */
.photo-slot{
  height: 220px; min-height:220px;
  background-color:#f0f0f0;
  display:flex; align-items:center; justify-content:center;
  border:1px dashed #ccc; cursor:pointer; position:relative;
  background-size: contain; background-position:center; background-repeat:no-repeat;
}
.photo-slot.small{ font-size:24px; cursor:pointer; }
.photo-slot.small img{
  max-width:100%; max-height:100%; object-fit:contain;
  display:block; margin:auto; position:absolute; inset:0;
}
.photo-slot.filled p{ display:none; position:relative; overflow:hidden; }
.photo-slot .plus-icon{ font-size:28px; color:#aaa; z-index:1; }
.plus-icon{ color:#aaa; font-size:32px; }
.photo-slot .photo-actions{ display:none; position:absolute; top:5px; right:5px; z-index:2; }
.photo-slot.filled:hover::before{
  content:""; position:absolute; inset:0; background-color:rgba(0,0,0,.4); z-index:1;
}
.photo-actions{
  position:absolute; left:3px; right:3px; bottom:3px;
  display:flex; justify-content:space-between;
  opacity:0; transition:opacity .3s; z-index:2;
}
.photo-slot:not(.filled) .photo-actions{ display:none; }
.photo-slot:hover{ background-color:#e0e0e0; cursor:default; }
.photo-slot:hover .photo-actions{ display:flex; opacity:1; background-color:rgba(0,0,0,.3); }
.action-btn{ background:none; border:none; padding:0; cursor:pointer; font-size:12px; color:#fff; text-shadow:0 0 1px rgba(0,0,0,.5); }
.action-btn:hover{ color:#000; }
.action-btn.copy-btn[disabled]{ color:#ccc; cursor:default; pointer-events:none; }
.photo-slot.filled .plus-icon{ display:none; }

/* модал */
#modal{
  display:flex; align-items:center; justify-content:center;
  position:fixed; inset:0;
  background-color:rgba(0,0,0,.8); z-index: 2000;
  overflow-y:auto;
}
#modal img{
  max-width: 90vw; max-height: 85vh;
  background:#fff; padding:20px; box-shadow:0 0 15px rgba(0,0,0,.5); border-radius:10px;
}
#modalControls{
  display:flex; justify-content:space-between; align-items:center;
  position:absolute; inset-inline:0; top:50%; transform:translateY(-50%);
  padding:0 20px;
}
#modalPrev, #modalNext{
  background:#333; color:#fff; padding:10px; border:none; cursor:pointer; font-size:16px; border-radius:5px;
}
#modalPrev:hover, #modalNext:hover{ background:#555; }
.close{
  position:absolute; top:20px; right:20px; color:#555; font-size:24px; cursor:pointer; font-weight:bold;
}
#modalTitle{
  position:absolute; top:10px; left:0; right:0; text-align:center;
  font-size:20px; font-weight:bold; color:#fff;
}
#modalDeleteButtons{
  position:absolute; left:0; right:0; bottom:20px;
  display:flex; justify-content:space-around; padding:10px;
}
#deleteImageButton, #deleteAllImagesButton{
  background:#ff4d4d; color:#fff; padding:10px 20px; border:none; cursor:pointer; font-size:14px; border-radius:5px;
}
#deleteImageButton:hover, #deleteAllImagesButton:hover{ background:#e60000; }

/* прочее */
.url-input{ display:flex; align-items:center; gap:5px; margin-top:15px; }
.url-input input{ flex:1 1 auto; min-width:0; padding:5px; font-size:14px; }
.url-input button{ padding:6px 12px; font-size:14px; }

/* радиогруппа */
.radio-group{ display:flex; flex-direction:column; gap:.5em; }
.radio-group label{ display:flex; align-items:center; }

#gpt-label, #gpt-label-chats, #gpt-label-chats-url{
  font-size:18px; font-weight:bold; text-align:center;
}

/* ввод кода подтверждения */
#confirmationCode{ height:30px; width: 100%; max-width: 420px; }
#confirmationBlock button{ height:30px; width: auto; }

/* чекбокс включения */
#includeOption{
  width:18px; height:18px; accent-color:#2563eb; cursor:pointer;
  margin: 12px 8px;
}

/* контейнеры для кнопок */
.button-wrapper-container{
  display:flex; flex-direction:column; gap:10px;
  height: 70%; overflow-y:auto; padding-right:10px;
}

.button-yml{ display:flex; align-items:center; gap:10px; margin-bottom:10px; }
.button-yml-container{
  display:flex; align-items:center; justify-content:center;
  min-height:50px; padding:10px 20px; font-size:18px; font-weight:bold;
  text-align:center; border:none; color:#fff; border-radius:5px;
}

/* адаптив */
@media (max-width: 992px){
  :root{ --menu-w: 200px; }
  main{ padding: 16px; }
  #video-download-popup{ width: min(92vw, 320px); }
}
@media (max-width: 640px){
  :root{ --menu-w: 0px; }   /* скрыть отступ под меню, если делаешь бургер */
  .menu{ display:none; }
  main{ margin-left: 0; }
  .button-wrapper{ gap:8px; }
  #statusDiv{ width: min(94vw, 320px); }
}