* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #14161c;
  --panel: #1d2029;
  --panel2: #252936;
  --border: #323748;
  --text: #e8eaf0;
  --muted: #8b91a3;
  --accent: #4f7df9;
  --accent-h: #6890ff;
  --danger: #e05656;
  --ok: #3dbd7d;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Golos Text', 'Segoe UI', sans-serif;
  min-height: 100vh;
}

.loading { padding: 60px; text-align: center; color: var(--muted); }

/* ---------- шапка ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 28px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg); z-index: 10;
}
.topbar .brand { font-weight: 700; font-size: 18px; cursor: pointer; }
main { padding: 24px 28px; max-width: 1500px; margin: 0 auto; }

/* ---------- общие ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 20px 22px; margin-bottom: 20px;
}
.panel.center { text-align: center; padding: 48px; }
.panel.disabled { opacity: 0.45; pointer-events: none; }
.panel h2 { font-size: 17px; font-weight: 600; margin-bottom: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.hidden { display: none !important; }
.row { display: flex; align-items: center; gap: 14px; margin-top: 12px; }
.row.spread { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }

.btn {
  background: var(--panel2); color: var(--text); border: 1px solid var(--border);
  border-radius: 9px; padding: 9px 16px; font-size: 14px; cursor: pointer;
  font-family: inherit; transition: background 0.15s;
}
.btn:hover { background: #2e3342; }
.btn.primary { background: var(--accent); border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-h); }
.btn.primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.btn.big { padding: 12px 26px; font-size: 15px; }
.btn.danger { color: var(--danger); }
.btn.tab.active { background: var(--accent); border-color: var(--accent); }

input[type=text], input[type=password], textarea, select {
  background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  border-radius: 9px; padding: 9px 12px; font-size: 14px; font-family: inherit;
  width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 1px solid var(--accent); }
label { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 5px; }
label.check { flex-direction: row; align-items: center; color: var(--text); font-size: 14px; }

/* ---------- логин ---------- */
.login-wrap { display: flex; justify-content: center; align-items: center; min-height: 100vh; }
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 40px; width: 360px; text-align: center; display: flex; flex-direction: column; gap: 14px;
}
.login-card h1 { font-size: 24px; }

/* ---------- главная ---------- */
.home-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.home-grid .wide { grid-column: 1 / -1; }

.dropzone {
  border: 2px dashed var(--border); border-radius: 12px; padding: 36px;
  text-align: center; cursor: pointer; transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: rgba(79,125,249,0.06); }
.or { text-align: center; color: var(--muted); margin: 12px 0; font-size: 13px; }
.path-row { display: flex; gap: 10px; }
.path-row input { flex: 1; }

.progress {
  height: 8px; border-radius: 4px; background: var(--panel2);
  overflow: hidden; margin: 14px 0 8px;
}
.progress.big { height: 12px; max-width: 480px; margin: 22px auto 12px; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 4px; transition: width 0.4s; }

.upload-list { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow-y: auto; }
.upload-card {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px;
  background: var(--panel2); border-radius: 10px; cursor: pointer;
}
.upload-card:hover { background: #2c3140; }
.upload-card-main { flex: 1; min-width: 0; }
.upload-name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chip { font-size: 11.5px; padding: 3px 9px; border-radius: 20px; white-space: nowrap; }
.chip.ok { background: rgba(61,189,125,0.15); color: var(--ok); }
.chip.err { background: rgba(224,86,86,0.15); color: var(--danger); }
.chip.busy { background: rgba(79,125,249,0.15); color: var(--accent-h); }

.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.project-card {
  background: var(--panel2); border-radius: 10px; padding: 10px; cursor: pointer; position: relative;
}
.project-card:hover { background: #2c3140; }
.project-card img { width: 100%; border-radius: 7px; display: block; }
.project-card .noimg { aspect-ratio: 1; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; }
.project-title { font-size: 13px; margin: 8px 0 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.project-card .del-project, .upload-card .del-upload { opacity: 0; transition: opacity 0.15s; }
.project-card:hover .del-project, .upload-card:hover .del-upload { opacity: 1; }
.project-card .del-project { position: absolute; top: 6px; right: 6px; }

/* ---------- ИИ-помощник ---------- */
.ai-panel { border-color: #3a4a7a; background: linear-gradient(180deg, rgba(79,125,249,0.08), var(--panel)); }
.ai-row { display: flex; gap: 12px; align-items: stretch; }
.ai-row textarea { flex: 1; resize: vertical; }
.ai-btns { display: flex; flex-direction: column; gap: 8px; justify-content: center; }
.ai-btns .btn { white-space: nowrap; }
#aiStatus { display: inline-block; margin-top: 8px; }

/* ---------- кадры ---------- */
.frames-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.frame-card {
  border: 2px solid transparent; border-radius: 10px; overflow: hidden; cursor: pointer;
  background: var(--panel2); transition: border-color 0.15s;
}
.frame-card:hover { border-color: var(--border); }
.frame-card.selected { border-color: var(--accent); }
.frame-card img { width: 100%; display: block; aspect-ratio: 16/9; object-fit: cover; }
.frame-info { display: flex; justify-content: space-between; padding: 7px 10px; font-size: 12.5px; }

/* ---------- настройки ---------- */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.settings-grid .full { grid-column: 1 / -1; }
.opt-group { display: flex; align-items: center; gap: 8px; }
.opt-label { color: var(--muted); font-size: 13px; }
.swatch {
  width: 34px; height: 34px; border-radius: 50%; border: 2px solid transparent;
  cursor: pointer; font-size: 15px; display: inline-flex; align-items: center; justify-content: center;
}
.swatch.active { border-color: #fff; }
.swatch.random { background: var(--panel2); }

/* ---------- варианты ---------- */
.variant-label { font-size: 14px; color: var(--muted); margin: 16px 0 10px; }
.variants-row { display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap; }
.variant-card {
  cursor: pointer; border: 2px solid transparent; border-radius: 10px;
  padding: 6px; background: var(--panel2); text-align: center; transition: border-color 0.15s;
}
.variant-card:hover { border-color: var(--accent); }
.variant-card img { display: block; border-radius: 6px; }
.variant-card.square img { width: 220px; }
.variant-card.vertical img { width: 150px; }
.variant-card.horizontal img { width: 320px; }
.variant-card .small { margin-top: 6px; }

/* ---------- редактор ---------- */
.editor-canvas-wrap { display: flex; justify-content: center; }
.canvas-holder {
  display: flex; justify-content: center; padding: 10px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
}
.canvas-holder canvas { border-radius: 6px; }
#toggleRow { gap: 16px; }

/* ---------- библиотека логотипов ---------- */
.logo-grid { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.logo-item {
  position: relative; width: 56px; height: 56px; border-radius: 8px;
  background: repeating-conic-gradient(#3a3f4d 0% 25%, #2b303c 0% 50%) 50% / 14px 14px;
  border: 1px solid var(--border); cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.logo-item:hover { border-color: var(--accent); }
.logo-item img { max-width: 48px; max-height: 48px; object-fit: contain; }
.logo-del {
  position: absolute; top: -6px; right: -6px; width: 18px; height: 18px; border-radius: 50%;
  border: none; background: var(--danger); color: #fff; font-size: 11px; line-height: 1; cursor: pointer;
  opacity: 0; transition: opacity 0.15s; padding: 0;
}
.logo-item:hover .logo-del { opacity: 1; }

/* ---------- шаблоны: библиотека ---------- */
.tpl-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-top: 16px; }
.tpl-col h2 { font-size: 15px; }
.tpl-list { display: flex; flex-direction: column; gap: 12px; margin-top: 10px; }
.tpl-card { background: var(--panel2); border: 2px solid transparent; border-radius: 10px; padding: 10px; }
.tpl-card.active { border-color: var(--ok); }
.tpl-thumb { width: 100%; height: auto; border-radius: 6px; background: #1d2029; display: block; }
.tpl-name { font-size: 13px; margin: 8px 0 6px; display: flex; gap: 6px; align-items: center; }
.tpl-actions { display: flex; flex-wrap: wrap; gap: 5px; }
.tpl-name-input { max-width: 360px; font-size: 16px; }

/* ---------- шаблоны: редактор ---------- */
.tpl-editor { display: grid; grid-template-columns: 280px 1fr; gap: 16px; margin-top: 14px; align-items: start; }
.tpl-toolbar { display: flex; flex-direction: column; gap: 8px; position: sticky; top: 80px; }
.tpl-toolbar h3 { font-size: 13px; color: var(--muted); margin-top: 4px; }
.tpl-toolbar hr { border: none; border-top: 1px solid var(--border); width: 100%; }
.tpl-toolbar label { font-size: 12.5px; }
.tpl-toolbar select, .tpl-toolbar input[type=text], .tpl-toolbar #pText { width: 100%; }
.tpl-canvas-wrap { display: flex; justify-content: center; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 14px; }
.tpl-canvas-wrap canvas { border-radius: 6px; }
.tpl-logo-pick { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 200; }
.tpl-logo-pick-inner { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 22px; width: 420px; max-width: 90vw; display: flex; flex-direction: column; gap: 12px; }

@media (max-width: 1000px) { .tpl-grid { grid-template-columns: 1fr; } .tpl-editor { grid-template-columns: 1fr; } }

/* ---------- тосты ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  padding: 12px 22px; border-radius: 10px; opacity: 0; transition: all 0.3s; z-index: 100;
  max-width: 80vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--danger); }

@media (max-width: 900px) {
  .home-grid { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
}
