/* Phantom Media Images — тёмная премиум-тема v2 (sidebar shell) */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Space+Grotesk:wght@500;600;700&display=swap');

:root {
  --bg: #05070C;
  --surface: rgba(15, 20, 30, .72);
  --surface-solid: #0E141E;
  --surface-2: #161E2B;
  --surface-3: #1E2938;
  --border: rgba(255, 255, 255, .07);
  --border-strong: rgba(255, 255, 255, .13);
  --text: #EAEEF6;
  --muted: #8D9AAF;
  --primary: #6D8CFF;
  --grad-a: #5B7CFA;
  --grad-b: #8B5CF6;
  --grad-c: #C084FC;
  --grad: linear-gradient(135deg, #5B7CFA 0%, #8B5CF6 100%);
  --green: #34D399;
  --amber: #FBBF24;
  --red: #F87171;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 16px 48px rgba(0, 0, 0, .55);
  --glow: 0 6px 24px rgba(109, 92, 246, .38);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-display: "Space Grotesk", "Inter", sans-serif;
  --sidebar-w: 252px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background:
    linear-gradient(rgba(255, 255, 255, .015) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .015) 1px, transparent 1px),
    var(--bg);
  background-size: 44px 44px, 44px 44px, auto;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; }
::selection { background: rgba(109, 140, 255, .35); }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.center { text-align: center; margin-top: 16px; }
h1, h2, h3 { margin: 0; font-family: var(--font-display); font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 19px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #222c3d; border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Aurora-фон ---------- */
.aurora { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.aurora i {
  position: absolute; display: block; border-radius: 50%;
  filter: blur(90px); opacity: .22; will-change: transform;
}
.aurora i:nth-child(1) {
  width: 640px; height: 640px; left: -160px; top: -220px;
  background: radial-gradient(circle, #4F6EF0, transparent 65%);
  animation: drift1 46s ease-in-out infinite alternate;
}
.aurora i:nth-child(2) {
  width: 560px; height: 560px; right: -140px; top: -160px;
  background: radial-gradient(circle, #8B5CF6, transparent 65%);
  animation: drift2 54s ease-in-out infinite alternate;
}
.aurora i:nth-child(3) {
  width: 480px; height: 480px; left: 38%; bottom: -280px;
  background: radial-gradient(circle, #2E4FC7, transparent 65%);
  opacity: .16; animation: drift1 60s ease-in-out infinite alternate-reverse;
}
@keyframes drift1 { to { transform: translate(70px, 50px) scale(1.08); } }
@keyframes drift2 { to { transform: translate(-60px, 60px) scale(1.05); } }
@media (prefers-reduced-motion: reduce) {
  .aurora i { animation: none !important; }
  * { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

/* ---------- Бренд ---------- */
.brand { display: inline-flex; align-items: center; gap: 11px; }
.brand-word { font-family: var(--font-display); font-weight: 700; letter-spacing: -.02em; }
.brand-word em {
  font-style: normal; font-weight: 700;
  background: linear-gradient(100deg, var(--grad-a), var(--grad-b) 55%, var(--grad-c));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}

/* ---------- Кнопки ---------- */
.btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 8px 14px; font-size: 14px; font-weight: 550;
  cursor: pointer; transition: background .18s, border-color .18s, color .18s, opacity .18s, box-shadow .18s, transform .1s, filter .18s;
  color: var(--text); background: transparent; text-decoration: none; white-space: nowrap;
}
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn-primary { background: var(--grad); color: #fff; box-shadow: var(--glow), inset 0 1px 0 rgba(255, 255, 255, .22); border: none; overflow: hidden; }
.btn-primary::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(105deg, transparent 38%, rgba(255, 255, 255, .28) 50%, transparent 62%);
  transform: translateX(-110%); transition: transform .5s ease;
}
.btn-primary:hover:not(:disabled)::after { transform: translateX(110%); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); box-shadow: 0 8px 30px rgba(109, 92, 246, .5), inset 0 1px 0 rgba(255, 255, 255, .22); }
.btn-secondary { background: var(--surface-2); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-3); }
.btn-ghost { color: var(--muted); }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--surface-2); }
.btn-danger { color: var(--red); }
.btn-danger:hover:not(:disabled) { background: rgba(248, 113, 113, .12); }
.btn-lg { padding: 13px 18px; font-size: 15px; width: 100%; font-weight: 600; border-radius: 12px; }
.btn-icon { padding: 8px; }
.btn-sm { padding: 5px 10px; font-size: 13px; }

/* ---------- Формы ---------- */
.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px; }
.field > span, .field-label { font-size: 12.5px; color: var(--muted); font-weight: 550; letter-spacing: .015em; }
.field-hint { font-weight: 400; opacity: .9; }
input[type="text"], input[type="password"], input[type="number"], input[type="search"], textarea, select {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); padding: 10px 13px; font-size: 15px; font-family: inherit; width: 100%;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
::placeholder { color: var(--muted); opacity: 1; }
input:hover, textarea:hover, select:hover { border-color: var(--border-strong); }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--primary); background: var(--surface-3);
  box-shadow: 0 0 0 3px rgba(109, 140, 255, .16);
}
textarea { resize: vertical; min-height: 100px; line-height: 1.55; }
select { cursor: pointer; }

input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: transparent; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 5px; border-radius: 3px; background: var(--surface-3); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 19px; height: 19px; border-radius: 50%;
  background: var(--grad); margin-top: -7px; box-shadow: 0 2px 10px rgba(109, 92, 246, .55); border: 2px solid rgba(255, 255, 255, .25);
}
input[type="range"]::-moz-range-track { height: 5px; border-radius: 3px; background: var(--surface-3); }
input[type="range"]::-moz-range-thumb { width: 17px; height: 17px; border-radius: 50%; background: var(--grad-a); border: none; }
input[type="range"]:focus-visible { outline: 2px solid var(--primary); outline-offset: 4px; border-radius: 4px; }

.form-error {
  background: rgba(248, 113, 113, .1); border: 1px solid rgba(248, 113, 113, .3);
  color: #FCA5A5; border-radius: var(--radius-sm); padding: 9px 12px; font-size: 13px; margin-bottom: 12px;
}
.segmented {
  display: flex; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 3px; gap: 2px;
}
.segmented button {
  flex: 1; border: none; background: transparent; color: var(--muted); padding: 7px 4px;
  border-radius: 7px; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background .15s, color .15s, box-shadow .15s; font-family: inherit;
}
.segmented button:hover:not(.active) { color: var(--text); }
.segmented button.active { background: var(--grad); color: #fff; box-shadow: 0 2px 12px rgba(109, 92, 246, .4); }
.segmented button:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.select-inline { width: auto; padding: 7px 10px; font-size: 14px; }

/* ---------- Референсы ---------- */
.refs-row { display: flex; gap: 9px; flex-wrap: wrap; }
/* мультигенерация: до 50 креативов — компактные чипы, лента скроллится */
.mr-refs { gap: 7px; max-height: 260px; overflow-y: auto; padding: 2px; }
.mr-refs .ref-chip, .mr-refs .ref-add { width: 46px; height: 46px; }
.mr-refs .ref-chip img { border-radius: 10px; }
.ref-add {
  width: 58px; height: 58px; border-radius: 12px; cursor: pointer;
  border: 1.5px dashed var(--border-strong); background: transparent; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
  transition: border-color .15s, color .15s, background .15s;
}
.ref-add:hover { border-color: var(--primary); color: var(--primary); background: rgba(109, 140, 255, .07); }
.ref-add:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.ref-chip { position: relative; width: 58px; height: 58px; border-radius: 12px; overflow: visible; }
.ref-chip img {
  width: 100%; height: 100%; object-fit: cover; border-radius: 12px;
  border: 1px solid var(--border-strong); display: block;
}
.ref-chip .ref-del {
  position: absolute; top: -9px; right: -9px; width: 24px; height: 24px;
  border-radius: 50%; border: none; cursor: pointer;
  background: #2A3547; color: #fff; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .5); transition: background .15s;
}
/* расширенная зона нажатия для тача */
.ref-chip .ref-del::before { content: ""; position: absolute; inset: -10px; }
.ref-chip .ref-del:hover { background: var(--red); }
.gen-form.dragover textarea, .gen-form.dragover .ref-add { border-color: var(--primary); }
.refs-strip {
  display: flex; align-items: center; gap: 9px; flex-wrap: wrap;
  margin-bottom: 16px; font-size: 12.5px; color: var(--muted);
}
.refs-strip a { display: block; width: 52px; height: 52px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border-strong); }
.refs-strip a:hover { border-color: var(--primary); }
.refs-strip img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---------- Логин ---------- */
.login-view { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  position: relative;
  background: linear-gradient(180deg, rgba(255, 255, 255, .03), rgba(255, 255, 255, 0) 45%), var(--surface-solid);
  border: 1px solid var(--border-strong); border-radius: 22px;
  padding: 38px 34px 34px; width: 100%; max-width: 420px; box-shadow: var(--shadow);
}
.login-logo { display: flex; align-items: center; gap: 15px; margin-bottom: 26px; }
.login-logo h1 { font-size: 26px; }
.login-sub { color: var(--muted); font-size: 13px; margin: 3px 0 0; }

/* ---------- Каркас: сайдбар + контент ---------- */
.app-view { display: flex; min-height: 100dvh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 50;
  display: flex; flex-direction: column; gap: 6px;
  padding: 20px 14px 14px;
  background: rgba(9, 12, 19, .82);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-right: 1px solid var(--border);
}
.sidebar-brand { padding: 2px 10px 18px; font-size: 17px; }
.side-nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-label {
  font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); opacity: .7; padding: 6px 12px 4px;
}
.nav-sep { height: 1px; background: var(--border); margin: 8px 10px; }
.side-nav .tab {
  display: flex; align-items: center; gap: 11px;
  border: none; background: transparent; color: var(--muted);
  font-size: 14px; font-weight: 550; text-align: left; font-family: inherit;
  padding: 10px 12px; border-radius: 10px; cursor: pointer;
  transition: color .15s, background .15s; position: relative;
}
.side-nav .tab:hover { color: var(--text); background: rgba(255, 255, 255, .04); }
.side-nav .tab.active { color: #fff; background: linear-gradient(90deg, rgba(91, 124, 250, .16), rgba(139, 92, 246, .08)); }
.side-nav .tab.active::before {
  content: ""; position: absolute; left: 0; top: 9px; bottom: 9px; width: 3px;
  border-radius: 2px; background: var(--grad);
}
.side-nav .tab.active svg { color: var(--primary); }
.side-nav .tab:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }

.sidebar-foot { border-top: 1px solid var(--border); padding-top: 12px; }
.user-card { display: flex; align-items: center; gap: 10px; padding: 4px 6px; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  background: var(--grad); color: #fff; font-weight: 700; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); box-shadow: 0 2px 10px rgba(109, 92, 246, .4);
}
.user-chip { flex: 1; min-width: 0; }
.user-name { display: block; font-size: 13.5px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-budget { display: block; font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.budget-bar { height: 4px; background: var(--surface-2); border-radius: 2px; margin-top: 4px; overflow: hidden; }
.budget-bar-fill { height: 100%; background: var(--green); border-radius: 2px; transition: width .3s; }
.budget-bar-fill.warn { background: var(--amber); }
.budget-bar-fill.over { background: var(--red); }

.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); padding: 26px 30px 40px; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.panel {
  background: linear-gradient(180deg, rgba(255, 255, 255, .022), rgba(255, 255, 255, 0) 50%), var(--surface);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; margin-bottom: 18px;
}
.gen-layout { display: grid; grid-template-columns: 360px 1fr; gap: 18px; align-items: start; }
/* grid-итем по умолчанию не ужимается меньше содержимого (min-width:auto):
   длинное имя файла в истории распирало колонку и уводило страницу в горизонтальный скролл */
.gen-layout > * { min-width: 0; }
.gen-form-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 18px; }
/* кнопки под формой: «Сгенерировать» на всю ширину, «Очистить» — компактная под ней справа */
.gen-submit-row { display: flex; flex-direction: column; gap: 8px; }
.gen-submit-row .form-clear { align-self: flex-end; }
.model-chip {
  font-size: 11px; color: var(--muted); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 20px; padding: 3px 9px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46%;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.gen-estimate { font-size: 13px; color: var(--muted); margin-bottom: 14px; font-variant-numeric: tabular-nums; }
.gen-estimate b { color: var(--green); font-weight: 650; }
.gen-results { min-height: 460px; }

.gen-status { margin-bottom: 16px; }
.gen-status-row { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 8px; font-weight: 550; }
.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--grad); border-radius: 3px; transition: width .4s; width: 0; }

.empty-state { text-align: center; color: var(--muted); padding: 72px 20px; font-size: 14px; }
.empty-orb {
  width: 84px; height: 84px; margin: 0 auto 18px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; color: #A9B8FF;
  background: radial-gradient(circle at 35% 30%, rgba(109, 140, 255, .28), rgba(139, 92, 246, .10) 70%);
  border: 1px solid rgba(109, 140, 255, .25);
  box-shadow: 0 0 40px rgba(109, 92, 246, .25);
}

/* ---------- Сетка превью ---------- */
.thumb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(152px, 1fr)); gap: 12px; }
.thumb {
  position: relative; border-radius: 13px; overflow: hidden; background: var(--surface-2);
  border: 1px solid var(--border); cursor: pointer; padding: 0; display: block; width: 100%;
  transition: border-color .18s, transform .18s, box-shadow .18s;
}
.thumb:hover {
  border-color: rgba(109, 140, 255, .5); transform: translateY(-3px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5), 0 0 0 1px rgba(109, 140, 255, .2);
}
.thumb img { display: block; width: 100%; height: 100%; object-fit: cover; transition: transform .3s; animation: fade-in .3s ease-out; }
.thumb:hover img { transform: scale(1.03); }
.thumb:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.thumb .thumb-tag {
  position: absolute; top: 7px; left: 7px; z-index: 1;
  font-size: 10.5px; font-weight: 650; letter-spacing: .03em;
  background: rgba(5, 8, 14, .72); backdrop-filter: blur(6px);
  color: #C4B5FD; border: 1px solid rgba(139, 92, 246, .35);
  border-radius: 6px; padding: 2px 7px; pointer-events: none;
}
.gp-note { font-size: 13px; color: var(--muted); margin: -6px 0 16px; }

/* апскейл видео */
.up-drop {
  border: 1.5px dashed var(--border-strong); border-radius: 12px; padding: 20px;
  cursor: pointer; transition: border-color .15s, background .15s; text-align: center;
}
.up-drop:hover, .up-drop.dragover { border-color: var(--primary); background: rgba(109, 140, 255, .06); }
.up-drop-empty { display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.up-files { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; max-height: 220px; overflow-y: auto; }
.up-files.hidden { display: none; }
.up-file {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; font-size: 13px;
}
.up-file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-file-size { color: var(--muted); font-size: 12px; white-space: nowrap; }
.up-file-x {
  border: none; background: none; color: var(--muted); cursor: pointer; font-size: 14px;
  line-height: 1; padding: 2px 4px; border-radius: 6px; transition: color .15s, background .15s;
}
.up-file-x:hover { color: var(--red); background: rgba(255,255,255,.05); }
.up-err { color: var(--red); }
/* подвкладки «Генерации»: Обычная | Серия | Мультиген */
.sub-tabs {
  display: inline-flex; gap: 4px; margin-bottom: 16px; padding: 4px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
}
.sub-tabs button {
  border: none; background: transparent; color: var(--muted); cursor: pointer;
  padding: 7px 16px; font-size: 13.5px; font-weight: 550; border-radius: 9px; font-family: inherit;
  transition: color .15s, background .15s;
}
.sub-tabs button:hover { color: var(--text); }
.sub-tabs button.active { background: var(--grad); color: #fff; box-shadow: 0 2px 10px rgba(109, 92, 246, .35); }
/* чекбокс звука в форме видео */
.vp-sound-field .field-label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.vp-sound-field input[type="checkbox"] { width: 16px; height: 16px; accent-color: #8b5cf6; cursor: pointer; }
/* тумблеры доступов в админ-таблице */
.cell-features { white-space: nowrap; }
.feature-pill {
  display: inline-block; margin: 0 4px 2px 0; padding: 3px 10px; font-size: 12px; font-weight: 550;
  border-radius: 20px; border: 1px solid var(--border-strong); background: transparent;
  color: var(--muted); cursor: pointer; transition: color .15s, border-color .15s, background .15s;
}
.feature-pill:hover:not(:disabled) { border-color: var(--primary); color: var(--text); }
.feature-pill.on { background: rgba(139, 92, 246, .16); border-color: #8b5cf6; color: var(--text); }
.feature-pill:disabled { opacity: .5; cursor: default; }
/* логотип Phantom Media */
.phantom-logo { color: var(--text); display: block; }
.login-logo-phantom { flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.sidebar-brand .phantom-logo { margin: 2px auto 0; }
.hist-item.static { cursor: default; }
.hist-item.static:hover { transform: none; border-color: var(--border); }
/* строки истории апскейла, доступные для выбора в ZIP */
.up-hist-item.selectable { cursor: pointer; }
.up-hist-item.selectable:hover { transform: none; border-color: var(--border-strong); }
.up-hist-item.selected,
.up-hist-item.selected:hover { border-color: rgba(109, 140, 255, .55); background: rgba(91, 124, 250, .07); }
.up-zip-n { font-variant-numeric: tabular-nums; }
.settings-form { display: flex; flex-direction: column; gap: 14px; max-width: 560px; }
.settings-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.settings-actions .muted { font-size: 13px; }
.thumb .thumb-dl {
  position: absolute; right: 7px; bottom: 7px; opacity: 0;
  background: rgba(5, 8, 14, .74); backdrop-filter: blur(6px);
  border-radius: 8px; padding: 7px; color: #fff;
  display: inline-flex; transition: opacity .15s, background .15s; text-decoration: none;
}
.thumb .thumb-dl:hover { background: rgba(5, 8, 14, .92); }
.thumb:hover .thumb-dl, .thumb .thumb-dl:focus-visible { opacity: 1; }
@media (pointer: coarse) { .thumb .thumb-dl { opacity: 1; } }
.thumb.skeleton { cursor: default; }
.thumb.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, .07) 50%, transparent 70%);
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* ---------- История ---------- */
.hist-list { display: flex; flex-direction: column; gap: 10px; }
.view-head-right { display: flex; align-items: center; gap: 12px; }
.view-head-right .muted { white-space: nowrap; }
.search-input { width: 230px; padding: 8px 12px; font-size: 14px; }
.gen-status-actions { margin-top: 12px; display: flex; justify-content: flex-end; }
@media (max-width: 940px) {
  .search-input { width: 100%; }
  .view-head { flex-wrap: wrap; }
}
.hist-check {
  position: relative; width: 22px; height: 22px; border-radius: 7px; flex: none;
  border: 1.5px solid var(--border-strong); background: transparent; color: transparent;
  display: flex; align-items: center; justify-content: center; cursor: pointer; padding: 0;
  transition: border-color .15s, background .15s, color .15s;
}
.hist-check::after { content: ""; position: absolute; inset: -11px; } /* тач-цель 44px */
.hist-check:hover { border-color: var(--primary); }
.hist-check.checked { background: var(--grad); border-color: transparent; color: #fff; }
.hist-check:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.hist-check-spacer { width: 22px; flex: none; }
.hist-item.selected { border-color: rgba(109, 140, 255, .55); background: rgba(91, 124, 250, .07); }

#view-history.bulk-active { padding-bottom: 104px; }

.bulk-bar {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 90;
  display: flex; align-items: center; gap: 12px;
  background: rgba(21, 28, 40, .93); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border-strong); border-radius: 14px; padding: 9px 10px 9px 18px;
  box-shadow: var(--shadow); animation: toast-in .2s ease-out;
  max-width: calc(100vw - 24px);
}
#bulk-count { font-size: 14px; font-weight: 650; white-space: nowrap; font-variant-numeric: tabular-nums; }
.hist-item {
  display: flex; gap: 14px; align-items: center;
  height: 82px; box-sizing: border-box;                 /* фикс. высота — все карточки одинаковые */
  background: linear-gradient(180deg, rgba(255, 255, 255, .018), rgba(255, 255, 255, 0) 60%), var(--surface);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0 16px;
  cursor: pointer; transition: border-color .15s, transform .15s; text-align: left; width: 100%; color: var(--text);
  font-family: inherit; font-size: inherit;
}
.hist-item:hover { border-color: rgba(109, 140, 255, .4); transform: translateY(-1px); }
.hist-item:hover .hist-chevron { color: var(--primary); transform: translateX(2px); }
.hist-item:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.hist-cover {
  position: relative; width: 50px; height: 66px; border-radius: 9px; overflow: hidden;
  background: var(--surface-2); flex: none; border: 1px solid var(--border-strong);
}
.hist-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hist-cover.ph { display: flex; align-items: center; justify-content: center; color: var(--muted); }
.hist-cover-count {
  position: absolute; right: 3px; bottom: 3px; font-size: 10px; font-weight: 700;
  background: rgba(5, 8, 14, .72); color: #fff; border-radius: 5px; padding: 1px 5px;
  font-variant-numeric: tabular-nums;
}

.hist-body { flex: 1; min-width: 0; }
.hist-prompt { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-meta {
  font-size: 12px; color: var(--muted); margin-top: 6px; display: flex; gap: 10px;
  align-items: center; white-space: nowrap; overflow: hidden; font-variant-numeric: tabular-nums;
}
.hist-meta > span { flex: none; }
.meta-ref { display: inline-flex; align-items: center; gap: 4px; }
.hist-status { flex: none; }                             /* статус всегда в одном месте — справа */
.hist-chevron { flex: none; color: var(--muted); display: flex; transition: color .15s, transform .15s; }

.hist-item { animation: rise-in .3s ease-out backwards; }
@keyframes rise-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.hist-skel { height: 82px; pointer-events: none; position: relative; overflow: hidden; animation: none; }
.hist-skel::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, .05) 50%, transparent 70%);
  animation: shimmer 1.4s infinite;
}
@media (max-width: 940px) {
  .hist-chevron { display: none; }                       /* на узком экране прячем стрелку ради места */
}
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2.5px 9px; border-radius: 20px; letter-spacing: .01em; }
.badge-done { background: rgba(52, 211, 153, .13); color: #4ADE9F; }
.badge-running { background: rgba(109, 140, 255, .14); color: #97ADFF; }
.badge-running::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor;
  animation: pulse-dot 1.2s ease-in-out infinite;
}
@keyframes pulse-dot { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.75); } }
.badge-partial { background: rgba(251, 191, 36, .13); color: #FCD34D; }
.badge-error { background: rgba(248, 113, 113, .13); color: #FCA5A5; }
.badge-off { background: rgba(141, 154, 175, .15); color: var(--muted); }
.badge-gplay { background: rgba(139, 92, 246, .16); color: #C4B5FD; }

/* ---------- Админка ---------- */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 13px; margin-bottom: 18px; }
.stat-card {
  display: flex; align-items: center; gap: 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .022), rgba(255, 255, 255, 0) 55%), var(--surface);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 17px 18px;
  transition: border-color .15s;
}
.stat-card:hover { border-color: rgba(109, 140, 255, .35); }
.stat-icon {
  width: 42px; height: 42px; border-radius: 12px; flex: none;
  display: flex; align-items: center; justify-content: center; color: #B4C4FF;
  background: linear-gradient(135deg, rgba(91, 124, 250, .2), rgba(139, 92, 246, .12));
  border: 1px solid rgba(109, 140, 255, .25);
}
.stat-card .stat-value { font-family: var(--font-display); font-size: 23px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; line-height: 1.2; }
.stat-card .stat-label { font-size: 12px; color: var(--muted); margin-top: 1px; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; color: var(--muted); font-size: 10.5px; font-weight: 650;
  text-transform: uppercase; letter-spacing: .05em;
  padding: 8px 8px; border-bottom: 1px solid var(--border-strong); white-space: nowrap;
}
.table td { padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: rgba(255, 255, 255, .02); }
.table tr:last-child td { border-bottom: none; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table td.actions { text-align: right; white-space: nowrap; }
.cell-limitbar { min-width: 130px; }
.limit-mini { width: 100%; max-width: 140px; height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; margin-top: 5px; margin-left: auto; }
.limit-mini div { height: 100%; background: var(--green); }
.limit-mini div.warn { background: var(--amber); }
.limit-mini div.over { background: var(--red); }
.td-prompt { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Оверлеи ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(2, 4, 9, .78); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center; padding: 36px 16px; overflow-y: auto;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  animation: fade-in .18s ease-out;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.overlay-panel {
  background: linear-gradient(180deg, rgba(255, 255, 255, .025), rgba(255, 255, 255, 0) 40%), var(--surface-solid);
  border: 1px solid var(--border-strong); border-radius: 20px;
  width: 100%; max-width: 1000px; padding: 24px; box-shadow: var(--shadow);
  animation: slide-up .22s ease-out;
}
@keyframes slide-up { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.overlay-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.overlay-actions { display: flex; gap: 8px; }
.detail-prompt-wrap { position: relative; margin-bottom: 14px; }
.detail-prompt {
  font-size: 13.5px; color: var(--muted); background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 11px 44px 11px 13px; white-space: pre-wrap; word-break: break-word;
}
.detail-copy { position: absolute; top: 5px; right: 5px; }
.modal-panel {
  background: linear-gradient(180deg, rgba(255, 255, 255, .03), rgba(255, 255, 255, 0) 45%), var(--surface-solid);
  border: 1px solid var(--border-strong); border-radius: 20px;
  width: 100%; max-width: 440px; padding: 26px; box-shadow: var(--shadow); margin: auto;
  animation: slide-up .22s ease-out;
}
.modal-panel h3 { margin-bottom: 16px; font-size: 17px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.password-box {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 17px; letter-spacing: 1px;
  background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: var(--radius-sm);
  padding: 13px; text-align: center; user-select: all; margin: 12px 0; color: #B4C6FF;
}

/* ---------- Лайтбокс ---------- */
.lightbox {
  position: fixed; inset: 0; background: rgba(1, 3, 7, .94); z-index: 200;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  animation: fade-in .18s ease-out;
}
.lightbox img { max-width: calc(100vw - 150px); max-height: calc(100dvh - 116px); border-radius: 12px; box-shadow: 0 24px 70px rgba(0, 0, 0, .7); }
.lb-btn {
  position: absolute; background: rgba(255, 255, 255, .07); border: 1px solid rgba(255, 255, 255, .1);
  color: #fff; border-radius: 50%; width: 46px; height: 46px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background .15s;
}
.lb-btn:hover { background: rgba(255, 255, 255, .17); }
.lb-btn:focus-visible { outline: 2px solid var(--primary); }
.lb-close { top: 18px; right: 18px; }
.lb-prev { left: 16px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 16px; top: 50%; transform: translateY(-50%); }
.lb-bottom { position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 14px; }
.lb-counter { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

/* ---------- Тосты ---------- */
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 300; }
.toast {
  background: rgba(22, 30, 43, .94); backdrop-filter: blur(10px);
  border: 1px solid var(--border-strong); border-left: 3px solid var(--grad-a);
  color: var(--text); border-radius: var(--radius-sm); padding: 11px 14px; font-size: 14px;
  max-width: min(380px, calc(100vw - 40px)); box-shadow: var(--shadow); animation: toast-in .25s ease-out;
}
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Широкие экраны ---------- */
@media (min-width: 1600px) {
  .gen-layout { grid-template-columns: 400px 1fr; }
  .thumb-grid { grid-template-columns: repeat(auto-fill, minmax(185px, 1fr)); }
  .main { padding: 30px 38px 48px; }
}

/* ---------- Адаптив ---------- */
@media (max-width: 940px) {
  .sidebar {
    position: sticky; inset: auto; top: 0; width: 100%;
    flex-direction: row; align-items: center; gap: 12px;
    padding: 10px 14px; border-right: none; border-bottom: 1px solid var(--border);
  }
  .sidebar-brand { padding: 0; font-size: 14px; }
  .sidebar-brand svg { width: 26px; height: 26px; }
  .side-nav { flex-direction: row; flex: 1; gap: 2px; overflow-x: auto; scrollbar-width: none; align-items: center; }
  .side-nav::-webkit-scrollbar { display: none; }
  .nav-label { display: none; }                          /* на мобильном секции-заголовки прячем */
  .nav-sep { width: 1px; height: 20px; margin: 0 6px; flex: none; }
  .side-nav .tab { padding: 7px 9px; white-space: nowrap; font-size: 13px; gap: 7px; }
  .avatar { width: 32px; height: 32px; font-size: 14px; }
  .side-nav .tab.active::before { display: none; }
  .sidebar-foot { border-top: none; padding-top: 0; }
  .user-card { padding: 0; gap: 8px; }
  .user-name { display: none; }
  .user-chip { flex: 0 0 auto; min-width: 76px; }
  .user-budget { font-size: 10.5px; }
  .app-view { flex-direction: column; }
  .main { margin-left: 0; padding: 14px; }
  .gen-layout { grid-template-columns: 1fr; }
  .gen-results { min-height: 0; }
  .thumb-grid { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); }
  .lightbox img { max-width: calc(100vw - 24px); max-height: calc(100dvh - 136px); }
  .lb-prev { left: 8px; bottom: 74px; top: auto; transform: none; }
  .lb-next { right: 8px; bottom: 74px; top: auto; transform: none; }
  .overlay { padding: 16px 10px; }
}
