﻿@charset "UTF-8";

/* ========================================================================
 * 01. TOKENS — design system variables
 * ====================================================================== */
:root {
  /* Colors */
  --color-bg: #181818;
  --color-panel: #202020;
  --color-panel-soft: rgba(42, 42, 42, 0.8);
  --color-control: rgba(34, 34, 34, 0.92);
  --color-control-hover: rgba(40, 40, 40, 0.95);
  --color-border: rgba(255, 255, 255, 0.08);
  --color-border-strong: rgba(255, 255, 255, 0.12);
  --color-text: #e8e8e8;
  --color-text-muted: #8f8f8f;
  --color-accent: #CDDC39;
  --color-accent-hover: #D8FF3D;
  --color-accent-rgb: 205, 220, 57;
  --color-on-accent: #151515;
  --color-on-danger: #ffffff;
  --color-danger: #ff6b6b;
  --color-success: #4caf50;
  --color-warning: #ffc107;

  /* Legacy aliases (kept for compatibility with existing rules) */
  --bg: var(--color-bg);
  --surface: var(--color-panel);
  --surface-raised: #252525;
  --surface-soft: rgba(255, 255, 255, 0.04);
  --line: var(--color-border);
  --line-strong: var(--color-border-strong);
  --text: var(--color-text);
  --text-muted: var(--color-text-muted);
  --accent: var(--color-accent);
  --danger: var(--color-danger);
  --success: var(--color-success);
  --warning: var(--color-warning);
  --accent-soft: rgba(var(--color-accent-rgb), 0.12);
  --accent-softer: rgba(var(--color-accent-rgb), 0.07);
  --accent-border: rgba(var(--color-accent-rgb), 0.24);
  --accent-border-strong: rgba(var(--color-accent-rgb), 0.42);
  --focus-ring: rgba(var(--color-accent-rgb), 0.14);
  --danger-soft: rgba(255, 107, 107, 0.12);
  --danger-border: rgba(255, 107, 107, 0.28);
  --success-soft: rgba(76, 175, 80, 0.14);
  --success-border: rgba(76, 175, 80, 0.28);
  --warning-soft: rgba(255, 193, 7, 0.14);
  --warning-border: rgba(255, 193, 7, 0.28);
  --overlay-dark: rgba(0, 0, 0, 0.62);
  --overlay-soft: rgba(0, 0, 0, 0.45);
  --overlay-medium: rgba(0, 0, 0, 0.6);
  --scrollbar-thumb: rgba(255, 255, 255, 0.18);
  --media-bg: #050505;
  --shadow-color-soft: rgba(0, 0, 0, 0.28);
  --shadow-color: rgba(0, 0, 0, 0.5);
  --shadow-color-strong: rgba(0, 0, 0, 0.72);

  /* Radii */
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  --radius-pill: 1000px;

  /* Shadows */
  --shadow-panel: 0 8px 32px rgba(0, 0, 0, 0.3);
  --shadow-control: 0 2px 8px rgba(0, 0, 0, 0.1);
  --shadow-accent-soft: 0 4px 16px rgba(var(--color-accent-rgb), 0.15);

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-base: 0.3s cubic-bezier(0.4, 0, 0.2, 1);

  /* Density */
  --density-gap: 12px;
  --density-panel-pad: 14px;
  --density-control-height: 44px;
  --prompt-textarea-max-height: clamp(140px, 28vh, 280px);
}

@media (max-width: 768px), (max-height: 760px) {
  :root {
    --prompt-textarea-max-height: clamp(120px, 24vh, 220px);
    --prompt-textarea-max-height: clamp(120px, 24dvh, 220px);
  }
}

html[data-theme="neutral-dark"] {
  --color-bg: #151515;
  --color-panel: #202124;
  --color-panel-soft: rgba(44, 45, 48, 0.82);
  --color-control: rgba(36, 37, 40, 0.94);
  --color-control-hover: rgba(48, 49, 52, 0.96);
  --color-border: rgba(255, 255, 255, 0.1);
  --color-border-strong: rgba(255, 255, 255, 0.16);
  --color-text: #f0f1f3;
  --color-text-muted: #9aa0a6;
  --color-accent: #aeb7c2;
  --color-accent-hover: #d4d9df;
  --surface-raised: #28292c;
  --surface-soft: rgba(255, 255, 255, 0.045);
  --shadow-accent-soft: 0 4px 16px rgba(174, 183, 194, 0.14);
}

html[data-theme="high-contrast"] {
  --color-bg: #050505;
  --color-panel: #121212;
  --color-panel-soft: rgba(26, 26, 26, 0.9);
  --color-control: rgba(18, 18, 18, 0.96);
  --color-control-hover: rgba(32, 32, 32, 0.98);
  --color-border: rgba(255, 255, 255, 0.18);
  --color-border-strong: rgba(255, 255, 255, 0.28);
  --color-text: #ffffff;
  --color-text-muted: #b7b7b7;
  --color-accent: #e5ff2d;
  --color-accent-hover: #f2ff8a;
  --surface-raised: #181818;
  --surface-soft: rgba(255, 255, 255, 0.06);
  --shadow-accent-soft: 0 4px 18px rgba(229, 255, 45, 0.18);
}

html[data-theme="soft-gray"] {
  --color-bg: #202020;
  --color-panel: #292a2c;
  --color-panel-soft: rgba(54, 55, 58, 0.82);
  --color-control: rgba(43, 44, 47, 0.94);
  --color-control-hover: rgba(56, 57, 60, 0.96);
  --color-border: rgba(255, 255, 255, 0.1);
  --color-border-strong: rgba(255, 255, 255, 0.16);
  --color-text: #ececec;
  --color-text-muted: #a6a6a6;
  --color-accent: #b7d85b;
  --color-accent-hover: #d0f174;
  --surface-raised: #313236;
  --surface-soft: rgba(255, 255, 255, 0.05);
  --shadow-accent-soft: 0 4px 16px rgba(183, 216, 91, 0.14);
}

html[data-density="compact"] {
  --density-gap: 8px;
  --density-panel-pad: 12px;
  --density-control-height: 38px;
}

html[data-density="spacious"] {
  --density-gap: 16px;
  --density-panel-pad: 18px;
  --density-control-height: 48px;
}

/* ========================================================================
 * 02. RESET — minimal, non-aggressive
 * ====================================================================== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
textarea,
select {
  font-family: inherit;
}

button {
  appearance: none;
  border: 0;
  background: transparent;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

html {
  overflow-x: hidden;
  overflow-y: scroll;          /* always reserve the page scrollbar track... */
  scrollbar-gutter: stable;    /* ...so layout width doesn't jump screen-to-screen */
  width: 100%;
  overscroll-behavior-x: none;
}

body {
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text-muted);
  min-height: 100vh;
  overflow-x: hidden;
  animation: fadeIn 0.6s ease-out;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  overscroll-behavior-x: none;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

/* ========================================================================
 * 03. BASE LAYOUT
 * ====================================================================== */
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 16px 40px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  width: 100%;
  animation: fadeIn 0.6s ease-out;
}

.logo {
  display: block;
  margin: 0 auto 32px;
  max-width: 200px;
  width: 80%;
  height: auto;
  filter: drop-shadow(0 4px 16px var(--accent-border-strong));
  animation: fadeIn 1s ease-out;
}

.logo:hover {
  filter: drop-shadow(0 8px 24px rgba(var(--color-accent-rgb), 0.4));
  transform: translateY(-2px);
}

/* ========================================================================
 * 08. CARDS
 * ====================================================================== */
.card {
  background: var(--color-panel-soft);
  backdrop-filter: blur(20px);
  border-radius: 20px;
  padding: 24px;
  margin-bottom: 24px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-panel);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  animation: slideUp 0.6s ease-out;
  /* overflow: visible so dropdowns (vmodel-list, native select) escape rounded corners */
  overflow: visible;
}

.card:hover {
  box-shadow: var(--shadow-panel);
}

/* ========================================================================
 * 07. TABS
 * ====================================================================== */
.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 12px;
  border: 2px solid transparent;
  background: var(--surface-soft);
  color: var(--text-muted);
  font-family: 'Manrope', sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  width: auto;
}

.tab:hover {
  background: var(--accent-soft);
  color: var(--text);
  transform: none;
  box-shadow: none;
}

.tab::before {
  display: none;
}

.tab.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.tab svg {
  flex-shrink: 0;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.upload-zone-small {
  min-height: 80px;
  padding: 16px;
}

#video-start-zone,
#video-end-zone {
  min-height: 96px;
  padding: 22px 18px;
  gap: 10px;
}

#video-start-zone .upload-icon,
#video-end-zone .upload-icon {
  margin-bottom: 4px;
}

#video-start-zone .upload-text,
#video-end-zone .upload-text {
  line-height: 1.25;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* ========================================================================
 * 09. FORM BASE — textarea, select, labels
 * ====================================================================== */
textarea {
  width: 100%;
  min-height: 100px;
  max-height: var(--prompt-textarea-max-height);
  margin-bottom: 20px;
  border: 2px solid transparent;
  border-radius: 12px;
  background-color: var(--color-control);
  color: var(--text);
  padding: 16px 18px;
  font-family: 'Manrope', sans-serif;
  font-size: 15px;
  font-weight: 400;
  line-height: 1.6;
  transition: border-color 0.3s ease, background-color 0.3s ease, box-shadow 0.3s ease;
  box-shadow: var(--shadow-control);
  resize: none;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

textarea:focus {
  outline: none;
  border-color: var(--accent);
  background-color: var(--color-control-hover);
  box-shadow: var(--shadow-accent-soft), 0 0 0 4px var(--focus-ring);
}

textarea::placeholder {
  color: var(--text-muted);
}

.row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.field {
  display: flex;
  flex-direction: column;
}

select {
  width: 100%;
  border-radius: 12px;
  border: 2px solid transparent;
  background-color: var(--color-control);
  color: var(--text);
  padding: 12px 14px;
  font-family: 'Manrope', sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: var(--shadow-control);
}

select:hover {
  background-color: var(--color-control-hover);
  border-color: var(--accent-border-strong);
}

select:focus {
  outline: none;
  border-color: var(--accent);
  background-color: var(--color-control-hover);
  box-shadow: var(--shadow-accent-soft), 0 0 0 4px var(--focus-ring);
}

/* ----- .cdrop — styled wrapper around native <select> with icon + chevron ----- */
/* Used for aspect_ratio, resolution and any future native dropdowns that need   */
/* visual parity with .vmodel-selected. Native select dropdown still opens.      */
.cdrop {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 44px;
  padding: 0 10px 0 12px;
  border-radius: var(--radius-md);
  border: 2px solid transparent;
  background-color: var(--color-control);
  box-shadow: var(--shadow-control);
  cursor: pointer;
  transition: background-color var(--transition-fast), border-color var(--transition-fast);
  overflow: visible;
}

.cdrop:hover {
  background-color: var(--color-control-hover);
  border-color: var(--accent-border-strong);
}

.cdrop:focus-within {
  border-color: var(--color-accent);
  background-color: var(--color-control-hover);
  box-shadow: var(--shadow-accent-soft), 0 0 0 4px var(--accent-soft);
}

.cdrop-icon,
.cdrop-arrow {
  flex-shrink: 0;
  font-size: 18px;
  color: var(--color-text);
  pointer-events: none;
}

.cdrop-arrow {
  margin-left: auto;
  font-size: 20px;
  color: var(--color-text-muted);
  transition: transform var(--transition-fast);
}

.cdrop:focus-within .cdrop-arrow {
  transform: rotate(180deg);
  color: var(--color-accent);
}

.cdrop-select {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: auto;
}

.cdrop.cdrop-ready .cdrop-select {
  pointer-events: none;
}

.cdrop-select:focus {
  outline: none;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.cdrop-select option {
  background: #1f1f1f;
  color: var(--color-text);
}

.cdrop-value {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--color-text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}

.cdrop-list {
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  z-index: 120;
  display: none;
  width: max-content;
  min-width: 100%;
  max-width: min(360px, calc(100vw - 32px));
  max-height: 300px;
  overflow-y: auto;
  padding: 6px;
  border-radius: 14px;
  border: 1px solid var(--accent-border);
  background: var(--surface);
  box-shadow: 0 18px 42px var(--shadow-color), 0 0 0 1px var(--accent-softer);
}

.cdrop.drop-up .cdrop-list {
  top: auto;
  bottom: calc(100% + 6px);
}

.cdrop.open .cdrop-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cdrop.open .cdrop-arrow {
  transform: rotate(180deg);
  color: var(--color-accent);
}

.cdrop-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 34px;
  padding: 8px 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--color-text);
  font: 700 13px/1 var(--font-main);
  text-align: left;
  cursor: pointer;
}

.cdrop-item:hover,
.cdrop-item.active {
  color: var(--color-accent);
  background: var(--accent-soft);
}

.cdrop-item.active::after {
  content: "check";
  font-family: "Material Icons Outlined";
  font-size: 16px;
  line-height: 1;
}

/* ========================================================================
 * 11. MODEL DROPDOWN — custom selector with icons (image and video)
 * ====================================================================== */
.vmodel-dropdown {
  position: relative;
  width: 100%;
}

.vmodel-selected {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border-radius: 12px;
  border: 2px solid transparent;
  background-color: var(--color-control);
  color: var(--text);
  padding: 10px 14px;
  font-family: 'Manrope', sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: var(--shadow-control);
  user-select: none;
}

.vmodel-selected:hover {
  background-color: var(--color-control-hover);
  border-color: var(--accent-border-strong);
}

.vmodel-selected.open {
  border-color: var(--accent);
  background-color: var(--color-control-hover);
  box-shadow: var(--shadow-accent-soft), 0 0 0 4px var(--focus-ring);
}
.vmodel-selected .vmodel-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}
.vmodel-selected .vmodel-icon svg {
  width: 100%;
  height: 100%;
}
.vmodel-selected .vmodel-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.vmodel-selected .vmodel-badge {
  font-size: 9px;
  text-transform: uppercase;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--accent);
  color: var(--color-on-accent);
  letter-spacing: 0.5px;
  transform: skewX(-8deg);
  line-height: 14px;
}
.vmodel-selected .vmodel-arrow {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--text-muted);
  transition: transform 0.2s ease;
}
.vmodel-selected.open .vmodel-arrow {
  transform: rotate(180deg);
}
.vmodel-list {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 40px var(--shadow-color);
  z-index: 100;
  overflow: hidden;
}

@media (min-width: 901px) {
  .vmodel-list {
    right: auto;
    left: 0;
    width: max-content;
    min-width: 100%;
    max-width: 360px;
  }
}
.vmodel-list.show {
  display: block;
}
.vmodel-list,
.cdrop-list,
.card .tab-content,
.gen-queue,
.upload-zone.has-files {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}
.vmodel-list::-webkit-scrollbar { width: 4px; }
.vmodel-list::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 4px; }
.cdrop-list::-webkit-scrollbar,
.card .tab-content::-webkit-scrollbar,
.gen-queue::-webkit-scrollbar,
.upload-zone.has-files::-webkit-scrollbar {
  width: 4px;
}
.cdrop-list::-webkit-scrollbar-thumb,
.card .tab-content::-webkit-scrollbar-thumb,
.gen-queue::-webkit-scrollbar-thumb,
.upload-zone.has-files::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 4px;
}
.vmodel-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.vmodel-item[hidden],
.vmodel-item.model-disabled {
  display: none !important;
}
.vmodel-item:hover {
  background: var(--accent-softer);
}
.vmodel-item.active {
  background: var(--accent-soft);
}
.vmodel-item .vmodel-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}
.vmodel-item .vmodel-icon svg {
  width: 100%;
  height: 100%;
}
.vmodel-item.active .vmodel-icon {
  color: var(--accent);
}
.vmodel-item .vmodel-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.vmodel-item .vmodel-info-top {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.vmodel-item .vmodel-info-top .vmodel-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.vmodel-item.active .vmodel-info-top .vmodel-name {
  color: var(--accent);
}
.vmodel-item .vmodel-badge {
  font-size: 8px;
  text-transform: uppercase;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 3px;
  background: var(--accent);
  color: var(--color-on-accent);
  letter-spacing: 0.5px;
  transform: skewX(-8deg);
  line-height: 13px;
}
.vmodel-item .vmodel-tags {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}
.vmodel-item .vmodel-tag {
  font-size: 10px;
  color: var(--text-muted);
  background: var(--surface-soft);
  padding: 1px 5px;
  border-radius: 3px;
}
.vmodel-item .vmodel-check {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--accent);
  opacity: 0;
}
.vmodel-item.active .vmodel-check {
  opacity: 1;
}

input[type="file"] {
  display: none;
}

/* ========================================================================
 * 12. UPLOAD ZONE — drag and drop area for images and video
 * ====================================================================== */
.upload-zone {
  width: 100%;
  min-height: 100px;
  padding: 20px 24px;
  border-radius: 16px;
  border: 2px dashed var(--accent-border-strong);
  background: var(--surface-soft);
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
}

.upload-zone:hover {
  border-color: var(--accent);
  background: var(--accent-softer);
  transform: translateY(-2px);
  box-shadow: var(--shadow-accent-soft);
}

.upload-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: scale(1.02);
  box-shadow: 0 12px 32px rgba(var(--color-accent-rgb), 0.25);
}

.upload-zone.has-files {
  min-height: auto;
  padding: 12px 16px;
  gap: 12px;
  align-items: stretch;
}
.upload-zone.has-files .upload-drop-area {
  flex-direction: row;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--accent-border);
}
.upload-zone.has-files .upload-icon {
  width: 18px;
  height: 18px;
  margin-bottom: 0;
  flex-shrink: 0;
}
.upload-zone.has-files .upload-text {
  font-size: 12px;
}
.upload-zone.has-files .upload-hint {
  display: none;
}

.upload-drop-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
}

.upload-zone .image-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
  width: 100%;
}

.upload-icon {
  width: 40px;
  height: 40px;
  color: var(--accent);
  margin-bottom: 4px;
}

.upload-icon svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
}

.upload-text {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.upload-hint {
  font-size: 12px;
  color: var(--text-muted);
}

.preview {
  margin-top: 16px;
  max-width: 280px;
}

.preview img {
  display: block;
  width: 100%;
  border-radius: 16px;
  border: 2px solid var(--accent-border);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  transition: all 0.3s ease;
}

.preview img:hover {
  transform: scale(1.02);
  box-shadow: 0 8px 24px var(--accent-border-strong);
}

.preview-item {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 12px;
  overflow: hidden;
  background: var(--media-bg);
}

.preview-item img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
  border-radius: 12px;
  background: var(--media-bg);
}

.delete-image-btn {
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--overlay-dark);
  border: none;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0;
  transition: all 0.2s ease;
  z-index: 10;
  padding: 0;
  opacity: 0.7;
}
.delete-image-btn .material-icons-outlined {
  font-size: 16px;
}

.preview-item:hover .delete-image-btn {
  opacity: 1;
}

.delete-image-btn:hover {
  background: var(--danger);
  color: #ffffff;
  transform: scale(1.1);
}

.delete-image-btn:active {
  transform: scale(0.95);
}

/* ========================================================================
 * 13. PROVIDER CONTROLS
 * ====================================================================== */
.provider-toggle {
  display: flex;
  gap: 6px;
}
.provider-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1.5px solid var(--line);
  background: var(--surface-soft);
  color: rgba(255,255,255,0.45);
  font-family: 'Manrope', sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}
.provider-btn .provider-logo {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  transition: all 0.2s;
}
.provider-btn[data-provider="replicate"] .provider-logo {
  opacity: 0.4;
}
.provider-btn[data-provider="kie"] .provider-logo {
  opacity: 0.6;
}
.provider-btn:hover {
  border-color: var(--color-border-strong);
  background: rgba(255,255,255,0.07);
  color: var(--text);
}
.provider-btn:hover .provider-logo { opacity: 0.7; }
.provider-btn.active {
  border-color: var(--accent-border-strong);
  background: var(--accent-softer);
  color: var(--accent);
}
.provider-btn.active[data-provider="replicate"] .provider-logo {
  opacity: 1;
  filter: drop-shadow(0 0 3px var(--accent-border-strong));
  color: var(--accent);
}
.provider-btn.active[data-provider="kie"] .provider-logo {
  opacity: 1;
  filter: drop-shadow(0 0 4px rgba(0,140,255,0.35));
}
.provider-btn.disabled {
  opacity: 0.3;
  pointer-events: none;
  cursor: not-allowed;
}

.actions {
  margin-top: 32px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

/* ========================================================================
 * PRIMARY BUTTON SYSTEM
 * Replaces former global button:not(...) chain. Buttons opt-in via class
 * or via specific id (.login-btn, #generate-btn, #video-generate-btn).
 * Rainbow glow is opt-in only via .btn-rainbow-glow.
 * ====================================================================== */

.btn-primary,
#generate-btn,
#video-generate-btn,
.login-btn {
  background: var(--accent, var(--accent));
  color: var(--color-on-accent);
  font-family: 'Manrope', sans-serif;
  font-size: 16px;
  font-weight: 700;
  padding: 16px 32px;
  border-radius: 1000px;
  border: 0;
  cursor: pointer;
  position: relative;
  letter-spacing: -0.02em;
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.btn-primary:hover,
#generate-btn:hover,
#video-generate-btn:hover,
.login-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(var(--color-accent-rgb), 0.4);
}

.btn-primary:active,
#generate-btn:active,
#video-generate-btn:active,
.login-btn:active {
  transform: translateY(0);
}

.btn-primary:disabled,
#generate-btn:disabled,
#video-generate-btn:disabled,
.login-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Opt-in rainbow glow effect (was previously applied to every button) */
.btn-rainbow-glow {
  position: relative;
  isolation: isolate;
  overflow: visible;
}

.btn-rainbow-glow::before {
  content: " ";
  position: absolute;
  inset: -2px;
  background: linear-gradient(
    90deg,
    var(--accent) 0%,
    var(--color-accent-hover) 50%,
    var(--accent) 100%
  );
  background-size: 200% 100%;
  filter: blur(20px);
  border-radius: inherit;
  z-index: -1;
  opacity: 0.6;
  transition: opacity 0.3s ease;
  animation: rainbow 3s linear infinite;
}

.btn-rainbow-glow:hover::before {
  opacity: 1;
}

@keyframes rainbow {
  0%   { background-position: 0% 50%; }
  100% { background-position: 200% 50%; }
}

.status {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  animation: pulse 2s ease-in-out infinite;
}

.loader {
  width: 28px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--accent);
  transform-origin: top;
  display: none;
  animation: l3-0 1s infinite linear;
}

.loader.active {
  display: grid;
}

.loader::before,
.loader::after {
  content: "";
  grid-area: 1/1;
  background: #9CA3AF;
  border-radius: 50%;
  transform-origin: top;
  animation: inherit;
  animation-name: l3-1;
}

.loader::after {
  background: #272727;
  --s: 180deg;
}

@keyframes l3-0 {
  0%, 20% { transform: rotate(0); }
  100% { transform: rotate(360deg); }
}

@keyframes l3-1 {
  50% { transform: rotate(var(--s, 90deg)); }
  100% { transform: rotate(0); }
}

.error {
  color: var(--danger);
  font-weight: 600;
  padding: 12px 16px;
  background: rgba(255, 107, 107, 0.1);
  border-radius: 12px;
  border-left: 4px solid var(--danger);
}

/* ========================================================================
 * 16. HISTORY
 * ====================================================================== */
.history {
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.history-item {
  background: var(--surface-soft);
  border-radius: 20px;
  padding: 24px;
  border: 1px solid var(--surface-soft);
  animation: fadeIn 0.6s ease-out;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
  gap: 16px;
}

.history-prompt {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  flex: 1;
  min-width: 0;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  line-clamp: 4;
  overflow: hidden;
  cursor: pointer;
  transition: color 0.15s;
}

.history-prompt:hover {
  color: #c4cde0;
}

.history-prompt.copied {
  color: var(--accent);
}

.history-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: right;
  flex-shrink: 0;
}

.history-time {
  font-weight: 600;
  color: var(--accent);
}

.history-params {
  display: grid;
  grid-template-columns: repeat(2, auto);
  justify-content: start;
  gap: 6px;
  margin-bottom: 16px;
}

.param-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  background: rgba(255, 255, 255, 0.055);
  color: rgba(218, 222, 226, 0.68);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.param-badge .material-icons-outlined {
  font-size: 13px;
  color: rgba(218, 222, 226, 0.56);
}

/* Unified duration control for video models */
.duration-control {
  display: flex;
  align-items: center;
  width: 100%;
  height: 44px;
  min-height: var(--density-control-height);
  padding: 0 6px;
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  background: var(--color-control);
  box-shadow: var(--shadow-control);
  transition: background-color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.duration-control:hover {
  background: var(--color-control-hover);
  border-color: var(--accent-border-strong);
}

.duration-control:focus-within {
  border-color: var(--color-accent);
  background: var(--color-control-hover);
  box-shadow: var(--shadow-accent-soft), 0 0 0 4px var(--accent-soft);
}

.duration-stepper {
  display: grid;
  grid-template-columns: 36px minmax(48px, 1fr) 36px;
  align-items: center;
  gap: 4px;
  width: 100%;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  border-radius: inherit;
  background: transparent;
}

.duration-step-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--color-accent);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast), opacity var(--transition-fast);
}

.duration-step-btn:hover:not(:disabled) {
  background: var(--accent-soft);
}

.duration-step-btn:disabled {
  color: var(--text-muted);
  cursor: default;
  opacity: 0.35;
}

.duration-step-btn .material-icons-outlined {
  font-size: 17px;
}

.duration-value {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  min-width: 40px;
  font-size: 13px;
  font-weight: 700;
  color: var(--color-text);
  padding: 0 3px;
  background: transparent;
  border: 0;
  border-radius: 0;
  letter-spacing: -0.01em;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
}

/* ========================================================================
 * 15. GALLERY — image cards grid
 * Column count controlled by .history[data-cols="2..4"] parent
 * ====================================================================== */
.history { --gallery-cols: 4; }
.history[data-cols="2"] { --gallery-cols: 2; }
.history[data-cols="3"] { --gallery-cols: 3; }
.history[data-cols="4"] { --gallery-cols: 4; }

.gallery {
  display: grid;
  grid-template-columns: repeat(var(--item-cols, var(--gallery-cols, 4)), minmax(0, 1fr));
  gap: 12px;
}

.image-card {
  position: relative;
  background: var(--surface-soft);
  backdrop-filter: blur(10px);
  border-radius: 20px;
  padding: 12px;
  border: 1px solid var(--surface-soft);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  animation: fadeIn 0.6s ease-out;
}

.image-card:hover {
  box-shadow: 0 12px 32px var(--accent-border);
  border-color: var(--accent-border-strong);
}

.image-card img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 16px;
  transition: all 0.3s ease;
}

/* ===== Image preloader / skeleton ===== */
@keyframes skeleton-shimmer { from { background-position: 220% 0; } to { background-position: -120% 0; } }
@keyframes spin-loader { to { transform: rotate(360deg); } }
/* Shimmer the card background until its image has loaded (graceful: covered once opaque) */
.image-card:not(:has(img.media-loaded)):not(:has(video)) {
  background-image: linear-gradient(100deg, transparent 28%, rgba(255,255,255,0.06) 50%, transparent 72%);
  background-size: 220% 100%;
  animation: skeleton-shimmer 1.25s ease-in-out infinite;
}
.image-card img { opacity: 0; }
.image-card img.media-loaded { opacity: 1; }
/* Full image in the modal: spinner while loading + fade in */
.image-modal-content { opacity: 0; transition: opacity 0.25s ease; }
.image-modal-content.media-loaded { opacity: 1; }
.image-modal.img-loading::after {
  content: ''; position: absolute; top: 50%; left: 50%; width: 40px; height: 40px; margin: -20px 0 0 -20px;
  border: 3px solid rgba(255,255,255,0.18); border-top-color: #fff; border-radius: 50%;
  animation: spin-loader 0.8s linear infinite; pointer-events: none; z-index: 2;
}

.img-wrap {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
}

.image-card .fav-overlay {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: var(--overlay-soft);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all 0.2s ease;
  backdrop-filter: blur(4px);
}

.image-card .fav-overlay .material-icons-outlined {
  font-size: 16px;
}

/* Defensive override no longer needed: rainbow glow is now opt-in via .btn-rainbow-glow */
.image-card .fav-overlay::before,
.image-card .delete-overlay::before {
  content: none;
}

.image-card .fav-overlay:hover {
  background: var(--overlay-dark);
  color: var(--danger);
  transform: scale(1.15);
}

.image-card .fav-overlay.is-fav {
  color: var(--danger);
  background: rgba(244, 67, 54, 0.25);
}

.image-card .fav-overlay.is-fav:hover {
  background: rgba(244, 67, 54, 0.4);
}

.image-card .delete-overlay {
  position: absolute;
  bottom: 8px;
  right: 8px;
  top: auto;
  left: auto;
  z-index: 2;
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: 50%;
  border: 0;
  background: var(--overlay-soft);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex: 0 0 auto;
  transition: all 0.2s ease;
  backdrop-filter: blur(4px);
  overflow: hidden;
}

.image-card .delete-overlay .material-icons-outlined {
  font-size: 16px;
}

.image-card .delete-overlay:hover {
  background: var(--overlay-dark);
  color: var(--danger);
  transform: scale(1.15);
}


.image-card .buttons {
  margin-top: 10px;
  display: flex;
  gap: 6px;
  justify-content: space-between;
  align-items: stretch;
}

.image-card .buttons-left,
.image-card .buttons-right {
  display: flex;
  gap: 6px;
  align-items: stretch;
}

.image-card .buttons-left { flex: 1 1 auto; flex-wrap: wrap; }

.image-card a,
.image-card .remove-bg-btn,
.image-card button.icon-btn {
  font-family: 'Manrope', sans-serif;
  font-size: 11px;
  font-weight: 600;
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 10px;
  border: 1px solid var(--accent-border-strong);
  background-color: var(--surface-soft);
  color: var(--accent);
  cursor: pointer;
  transition: all 0.3s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  line-height: 1;
  white-space: nowrap;
  justify-content: center;
  min-width: 0;
  box-sizing: border-box;
}

.image-card .buttons-left .remove-bg-btn {
  flex: 0 0 auto;
}

.image-card .icon-btn {
  width: 28px;
  min-width: 28px;
  height: 28px;
  padding: 0;
  align-self: center;
}

.image-card a:hover,
.image-card .remove-bg-btn:hover:not(:disabled),
.image-card button.icon-btn:hover {
  background-color: var(--accent);
  color: var(--color-on-accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--accent-border-strong);
}

.image-card .remove-bg-btn:disabled {
  opacity: 0.5;
  cursor: wait;
}


.image-card .btn-icon,
.image-card .icon-btn .material-icons-outlined {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  min-width: 14px;
  max-width: 14px;
  overflow: hidden;
  line-height: 1;
  font-size: 14px;
}

/* ==================== Enhance Prompt Button ==================== */
.textarea-wrapper {
  position: relative;
  margin-bottom: 20px;
}
.textarea-wrapper textarea {
  padding-right: 48px;
  margin-bottom: 0;
}
.prompt-actions {
  position: absolute;
  right: 12px;
  top: 12px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.enhance-prompt-btn {
  position: relative;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: rgba(255,255,255,0.35);
  cursor: pointer;
  transition: all 0.25s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.enhance-prompt-btn .material-icons-outlined { font-size: 17px; }
.enhance-prompt-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent-border-strong);
  color: var(--accent);
  transform: none;
  box-shadow: none;
}
.enhance-prompt-btn:disabled {
  opacity: 0.5;
  cursor: wait;
}
.enhance-prompt-btn.loading {
  border-color: var(--accent-border-strong);
  background: var(--accent-softer);
  color: var(--accent);
}
.enhance-prompt-btn.loading .material-icons-outlined {
  animation: enhanceSpin 1.2s ease-in-out infinite;
}
.prompt-dictate-btn.recording {
  border-color: var(--accent-border-strong);
  background: var(--accent-soft);
  color: var(--accent);
}
.prompt-dictate-btn.recording::after {
  content: "";
  position: absolute;
  inset: -4px;
  border: 1px solid var(--accent-border-strong);
  border-radius: 11px;
  animation: promptRecordPulse 1.4s ease-out infinite;
}
@keyframes promptRecordPulse {
  0% { opacity: 0.8; transform: scale(0.9); }
  100% { opacity: 0; transform: scale(1.16); }
}
@media (max-width: 768px) {
  .prompt-actions {
    top: 6px;
    right: 8px;
    gap: 4px;
  }
}
@keyframes enhanceSpin {
  0% { transform: rotate(0deg); opacity: 1; }
  50% { transform: rotate(180deg); opacity: 0.5; }
  100% { transform: rotate(360deg); opacity: 1; }
}

/* Keep prompt text readable while the enhancement shimmer is running. */
.textarea-wrapper.enhancing textarea {
  color: var(--text);
  -webkit-text-fill-color: currentColor;
  animation: promptTextEnhancing 1.6s ease-in-out infinite;
}
.textarea-wrapper.enhancing::after {
  content: "";
  position: absolute;
  z-index: 1;
  inset: 1px;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(
    105deg,
    transparent 30%,
    var(--accent-softer) 44%,
    var(--accent-soft) 50%,
    var(--accent-softer) 56%,
    transparent 70%
  );
  background-size: 240% 100%;
  animation: promptEnhanceSweep 1.6s linear infinite;
}
@keyframes promptTextEnhancing {
  0%, 100% {
    color: var(--text);
    text-shadow: none;
  }
  50% {
    color: var(--accent);
    text-shadow: 0 0 12px var(--accent-soft);
  }
}
@keyframes promptEnhanceSweep {
  0% { background-position: 160% 50%; }
  100% { background-position: -60% 50%; }
}
.textarea-wrapper.enhanced textarea {
  color: var(--accent);
  -webkit-text-fill-color: currentColor;
  transition: color 0.4s ease, text-shadow 0.4s ease;
  text-shadow: 0 0 12px var(--accent-soft);
}
.textarea-wrapper.enhanced-done textarea {
  color: var(--text);
  -webkit-text-fill-color: currentColor;
  transition: color 0.6s ease, text-shadow 0.6s ease;
  text-shadow: none;
}

/* ========================================================================
 * 18. PROFILE MODAL
 * ====================================================================== */
.profile-modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: var(--overlay-dark);
  backdrop-filter: blur(6px);
  z-index: 10000;
  justify-content: center;
  align-items: center;
  animation: fadeIn 0.25s ease-out;
  overflow-y: auto;
  padding: 20px 10px;
}
.profile-modal-overlay.active { display: flex; }

.profile-modal {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  width: 420px;
  max-width: 94vw;
  max-height: none;
  overflow-y: visible;
  padding: 28px;
  position: relative;
  box-shadow: 0 20px 60px var(--shadow-color);
  margin: auto;
  flex-shrink: 0;
}
.profile-modal::-webkit-scrollbar { width: 4px; }
.profile-modal::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 4px; }

.profile-modal-close {
  position: absolute;
  top: 16px; right: 16px;
  width: 32px; height: 32px;
  min-width: 32px; min-height: 32px;
  border-radius: 50%;
  border: 1px solid var(--scrollbar-thumb);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  padding: 0;
  z-index: 2;
  flex-shrink: 0;
}
.profile-modal-close:hover { background: var(--accent); color: var(--color-on-accent); transform: scale(1.1); }

.profile-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}
.profile-avatar {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, #8BC34A 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: var(--color-on-accent);
  font-weight: 700;
  flex-shrink: 0;
}
.profile-header-info { flex: 1; min-width: 0; }
.profile-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.profile-plan {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
.profile-plan .plan-badge { margin-left: 0; }

/* Balance block */
.profile-balance-block {
  background: var(--accent-softer);
  border: 1px solid var(--accent-border);
  border-radius: 14px;
  padding: 20px;
  text-align: center;
  margin-bottom: 20px;
}
.profile-balance-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}
.profile-balance-value {
  font-size: 36px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.profile-balance-value .token-icon { width: 28px; height: 28px; color: var(--accent); }
.profile-balance-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* Estimates grid */
.profile-estimates {
  margin-bottom: 20px;
}
.profile-section-title {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
  font-weight: 600;
}
.estimates-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}
.estimate-item {
  background: var(--surface-soft);
  border: 1px solid var(--surface-soft);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
}
.estimate-icon {
  color: var(--text-muted);
  font-size: 20px;
  flex-shrink: 0;
}
.estimate-info { min-width: 0; text-align: center; }
.estimate-count {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}
.estimate-label {
  font-size: 9px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Theme settings */
.theme-settings {
  display: grid;
  gap: 12px;
  margin-bottom: 4px;
}

.theme-presets {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.theme-preset-btn {
  min-height: 38px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--color-text-muted);
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  padding: 0 10px;
  transition: border-color var(--transition-fast), background var(--transition-fast), color var(--transition-fast);
}

.theme-preset-btn:hover,
.theme-preset-btn.active {
  border-color: color-mix(in srgb, var(--color-accent) 55%, transparent);
  background: color-mix(in srgb, var(--color-accent) 12%, transparent);
  color: var(--color-text);
}

.theme-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--line);
  flex: 0 0 auto;
}

.theme-dot-lime { background: #cddc39; }
.theme-dot-neutral { background: #aeb7c2; }
.theme-dot-contrast { background: #e5ff2d; }
.theme-dot-soft { background: #b7d85b; }

.theme-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.theme-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  padding: 7px 10px;
  color: var(--color-text-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.theme-control input[type="color"] {
  width: 28px;
  height: 28px;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
}

.theme-control select {
  width: 110px;
  min-width: 0;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--color-control);
  color: var(--color-text);
  font-size: 12px;
  font-weight: 700;
  padding: 0 8px;
}

/* Divider */
.profile-divider {
  height: 1px;
  background: var(--line);
  margin: 20px 0;
}

/* Monthly stats */
.stats-row {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}
.stat-card {
  flex: 1;
  background: var(--surface-soft);
  border: 1px solid var(--surface-soft);
  border-radius: 12px;
  padding: 14px 10px;
  text-align: center;
}
.stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  word-break: break-all;
}
.stat-label {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* Achievements */
.achievements-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.achievement {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-soft);
  border: 1px solid var(--surface-soft);
  border-radius: 20px;
  padding: 6px 12px 6px 8px;
  font-size: 11px;
  color: var(--text-muted);
  transition: all 0.2s;
}
.achievement.unlocked {
  border-color: rgba(var(--color-accent-rgb), 0.25);
  background: rgba(205,220,57,0.06);
  color: #ccc;
}
.achievement .material-icons-outlined {
  font-size: 18px;
  color: var(--scrollbar-thumb);
}
.achievement.unlocked .material-icons-outlined {
  color: var(--accent);
}
.achievement-name { font-weight: 500; }

@media (max-width: 480px) {
  .profile-modal { padding: 18px; border-radius: 16px; }
  .profile-balance-value { font-size: 28px; }
  .estimates-grid { grid-template-columns: 1fr 1fr 1fr; }
  .theme-controls { grid-template-columns: 1fr; }
  .estimate-item { padding: 8px 6px; }
  .estimate-count { font-size: 16px; }
  .estimate-label { font-size: 8px; }
  .stat-card { padding: 10px 6px; }
  .stat-value { font-size: 18px; }
  .stat-label { font-size: 9px; }
}

/* ========================================================================
 * 17. MODALS — image preview modal
 * ====================================================================== */
.image-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.95);
  z-index: 9999;
  justify-content: center;
  align-items: center;
  padding: 20px;
  animation: fadeIn 0.3s ease-out;
  cursor: zoom-out;
}

.image-modal.active {
  display: flex;
}

.image-modal-content {
  max-width: 95%;
  max-height: 95%;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 20px 60px var(--shadow-color);
  animation: zoomIn 0.3s ease-out;
  cursor: default;
}

@keyframes zoomIn {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.image-modal-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background: var(--overlay-dark);
  border: 2px solid var(--accent);
  color: var(--accent);
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  line-height: 1;
  z-index: 10000;
  padding: 0;
  flex-shrink: 0;
}

.image-modal-close:hover {
  background: var(--accent);
  color: var(--color-on-accent);
  transform: scale(1.1) rotate(90deg);
}

.image-modal-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 50%;
  background: var(--overlay-medium);
  border: 1.5px solid var(--color-border-strong);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 0;
  transition: all 0.2s ease;
}
.image-modal-nav svg { width: 22px; height: 22px; }
.image-modal-nav:hover { background: var(--accent-border-strong); border-color: var(--accent); color: var(--accent); }
.image-modal-nav:disabled { opacity: 0; pointer-events: none; }
.image-modal-prev { left: 16px; }
.image-modal-next { right: 16px; }

.image-modal-counter {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 13px;
  color: rgba(255,255,255,0.5);
  background: var(--shadow-color);
  padding: 4px 12px;
  border-radius: 12px;
  z-index: 10000;
}

.image-card img {
  cursor: zoom-in;
}

/* ========================================================================
 * 20. RESPONSIVE — breakpoints: 1200, 900, 768, 560, 420
 * ====================================================================== */
@media (max-width: 768px) {
  .container {
    padding: 16px 12px 32px;
  }

  .card {
    padding: 20px 16px;
    border-radius: 16px;
    margin-bottom: 20px;
  }

  .logo {
    max-width: 160px;
    margin-bottom: 24px;
  }

  h2 {
    font-size: 20px;
    margin-bottom: 16px;
  }

  .row {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .field {
    margin-bottom: 0;
  }

  label {
    font-size: 12px;
    margin-bottom: 6px;
  }

  textarea {
    min-height: 80px;
    padding: 12px;
    font-size: 14px;
    margin-bottom: 16px;
  }

  select,
  input[type="file"] {
    font-size: 14px;
    padding: 10px 12px;
  }

  .btn-primary,
  #generate-btn,
  #video-generate-btn,
  .login-btn {
    font-size: 14px;
    padding: 14px 24px;
  }

  .btn-rainbow-glow::before {
    filter: blur(16px);
    border-radius: 1000px;
  }

  .upload-zone {
    min-height: 80px;
    padding: 12px;
  }

  .upload-zone .image-preview-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  .upload-icon {
    width: 32px;
    height: 32px;
  }

  .upload-text {
    font-size: 14px;
  }

  .upload-hint {
    font-size: 11px;
  }

  /* Cap gallery at 3 cols at <=768px regardless of data-cols */
  .gallery {
    grid-template-columns: repeat(min(var(--gallery-cols, 4), 3), minmax(0, 1fr));
    gap: 10px;
  }

  .image-card {
    padding: 10px;
  }

  .image-card .buttons {
    gap: 4px;
    margin-top: 6px;
  }

  .image-card a,
  .image-card .remove-bg-btn {
    font-size: 12px;
    padding: 6px 9px;
    border-radius: 8px;
    gap: 3px;
  }

  .image-card .icon-btn {
    width: 32px;
    min-width: 32px;
    height: 32px;
    padding: 0;
    align-self: center;
  }

  .image-card .btn-icon {
    font-size: 14px;
  }

  .history-item {
    padding: 16px;
  }

  .history-prompt {
    font-size: 12px;
  }

  .history-meta {
    font-size: 11px;
  }

  .param-badge {
    font-size: 10px;
    padding: 3px 8px;
  }

  .upload-zone {
    min-height: 120px;
    padding: 24px 16px;
  }

  .upload-icon {
    font-size: 40px;
  }

  .upload-text {
    font-size: 14px;
  }

  .upload-hint {
    font-size: 11px;
  }

  .preview {
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 8px;
  }

  /* На мобильных всегда показываем кнопку удаления */
  .delete-image-btn {
    opacity: 1;
  }

  .image-modal {
    padding: 10px;
  }

  .image-modal-close {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    aspect-ratio: 1 / 1;
    top: max(16px, calc(env(safe-area-inset-top) + 8px));
    right: max(12px, calc(env(safe-area-inset-right) + 8px));
    font-size: 24px;
    padding: 0;
    flex-shrink: 0;
  }

  .image-modal-content {
    max-width: 100%;
    max-height: 90%;
  }

  .image-modal-nav { width: 36px; height: 36px; min-width: 36px; min-height: 36px; }
  .image-modal-nav svg { width: 18px; height: 18px; }
  .image-modal-prev { left: 8px; }
  .image-modal-next { right: 8px; }
  .image-modal-counter { font-size: 11px; bottom: 12px; }
}

@media (max-width: 480px) {
  .container {
    padding: 12px 8px 24px;
  }

  .card {
    padding: 16px 12px;
  }

  .logo {
    max-width: 140px;
    margin-bottom: 20px;
  }

  textarea {
    min-height: 70px;
  }

  .btn-rainbow-glow::before {
    filter: blur(6px);
    border-radius: 1000px;
  }

  .upload-zone {
    min-height: 70px;
    padding: 10px;
  }

  .upload-zone .image-preview-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }

  .delete-image-btn {
    width: 22px;
    height: 22px;
  }
  .delete-image-btn .material-icons-outlined {
    font-size: 14px;
  }

  .upload-icon {
    width: 28px;
    height: 28px;
  }

  .upload-text {
    font-size: 13px;
  }

  .upload-hint {
    font-size: 10px;
  }

  .history-header {
    flex-direction: row;
    align-items: flex-start;
    gap: 8px;
  }

  .history-prompt {
    font-size: 11px;
  }

  .history-meta {
    text-align: right;
    font-size: 9px;
  }

  .param-badge {
    font-size: 8px;
    padding: 2px 5px;
  }
}
/* ========================================================================
 * 04. AUTH LOGIN
 * ====================================================================== */
.login-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.login-screen.hidden {
  display: none;
}

.login-card {
  background: rgba(42, 42, 42, 0.95);
  backdrop-filter: blur(20px);
  border-radius: 24px;
  padding: 40px;
  max-width: 400px;
  width: 100%;
  border: 1px solid var(--line);
  box-shadow: 0 20px 60px var(--shadow-color);
}

.login-logo {
  display: block;
  margin: 0 auto 32px;
  max-width: 160px;
  filter: drop-shadow(0 4px 16px var(--accent-border-strong));
}

.login-title {
  color: var(--text);
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 8px;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  margin-bottom: 32px;
}

.login-field {
  margin-bottom: 16px;
}

.login-field label {
  display: block;
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.login-field input {
  width: 100%;
  padding: 14px 16px;
  background: rgba(30, 30, 30, 0.8);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  transition: all 0.2s;
}

.login-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-border);
}

.login-btn {
  width: 100%;
  padding: 16px;
  background: linear-gradient(135deg, var(--accent) 0%, #AFB42B 100%);
  border: none;
  border-radius: 12px;
  color: var(--color-on-accent);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 8px;
}

.login-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px var(--accent-border-strong);
}

.login-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.login-error {
  color: var(--danger);
  font-size: 13px;
  text-align: center;
  margin-top: 16px;
  min-height: 20px;
}

/* ========================================================================
 * 06. HEADER — top user info bar (mobile only)
 * ====================================================================== */
.user-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding: 8px 0;
}

.header-logo {
  height: 28px;
  width: auto;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-name {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 13px;
  white-space: nowrap;
  min-width: 0;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Второстепенные кнопки - простой line стиль */
.btn-subtle {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 400;
  padding: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-subtle:hover {
  color: var(--text-muted);
}

.btn-subtle svg {
  width: 18px;
  height: 18px;
}

.app-content.hidden {
  display: none;
}

/* ==================== Generation Queue ==================== */
.gen-queue {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
}
.gen-queue:empty {
  display: none;
}
.gen-queue-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--surface-soft);
  border: 1px solid var(--surface-soft);
  animation: fadeIn 0.3s ease-out;
}
.gen-queue-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--accent-border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
.gen-queue-card.done .gen-queue-spinner {
  border-color: var(--success-soft);
  border-top-color: var(--success);
  animation: none;
  background: var(--success);
  border: none;
}
.gen-queue-card.done .gen-queue-spinner::after {
  content: '✓';
  color: var(--text);
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}
.gen-queue-info {
  flex: 1;
  min-width: 0;
}
.gen-queue-prompt {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gen-queue-status {
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
}
.gen-queue-card.done .gen-queue-status {
  color: var(--success);
}
.gen-queue-card.warning {
  border-color: var(--warning-border);
  background: var(--warning-soft);
}
.gen-queue-card.warning .gen-queue-spinner {
  border: 0;
  animation: none;
  background: var(--warning);
}
.gen-queue-card.warning .gen-queue-spinner::after {
  content: '!';
  color: var(--bg);
  font-size: 13px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}
.gen-queue-card.warning .gen-queue-status {
  color: var(--warning);
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Сворачиваемая история генераций */
.history-section {
  margin-top: 24px;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  border-top: 1px solid var(--line);
  padding: 8px 0;
  gap: 12px;
}

.history-header .pagination-controls {
  margin-left: auto;
}

.history-section.expanded .history-header {
  border-bottom: 1px solid var(--line);
}

.history-toggle {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  padding: 4px 0;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 400;
  font-family: inherit;
  cursor: default;
  flex-shrink: 0;
  pointer-events: none;
}

.history-toggle:hover {
  color: var(--text-muted);
}

.fav-filter-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
  padding: 0;
}

.fav-filter-btn .material-icons-outlined {
  font-size: 16px;
}

.fav-filter-btn:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.fav-filter-btn.active {
  color: var(--danger);
  border-color: var(--danger);
  background: rgba(244, 67, 54, 0.1);
}

/* Gallery column selector — 2/3/4 cols toggle */
.gallery-cols-selector {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  background: rgba(15, 15, 15, 0.6);
  border: 1px solid var(--line);
  border-radius: 8px;
  flex-shrink: 0;
}

.gallery-cols-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: 24px;
  min-width: 28px;
  padding: 0 4px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.gallery-cols-btn .material-icons-outlined {
  font-size: 14px;
}

.gallery-cols-btn .gallery-cols-label {
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
}

.gallery-cols-btn:hover {
  color: var(--color-text);
  background: var(--accent-soft);
}

.gallery-cols-btn.active {
  color: var(--color-on-accent);
  background: var(--color-accent);
}

@media (max-width: 900px) {
  .gallery-cols-selector { display: none; }
}

.history-toggle-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-logo {
  display: block;
  width: 96px;
  height: auto;
  margin-right: 6px;
  filter: drop-shadow(0 2px 8px var(--accent-border));
}

.history-toggle-left svg {
  width: 16px;
  height: 16px;
}

.history-count {
  color: var(--scrollbar-thumb);
  font-size: 12px;
}

.history-toggle-arrow {
  width: 16px;
  height: 16px;
  color: var(--scrollbar-thumb);
  display: none;
}

.history-section.expanded .history-toggle-arrow {
  transform: rotate(180deg);
}

.history-section.expanded .history-toggle {
  border-bottom: none;
}

.history-content {
  max-height: none;
  overflow: visible;
}

.history-section.expanded .history-content {
  max-height: none;
  overflow: visible;
}

.history-content > .history {
  padding: 16px 0;
}

.history-content > .history:empty::after {
  content: "Введите промт, загрузите референс и нажмите «Сгенерировать»";
  display: block;
  max-width: 420px;
  margin: 0 auto;
  text-align: center;
  line-height: 1.35;
  color: var(--scrollbar-thumb);
  padding: 24px 16px;
}

.history-scroll-sentinel {
  width: 100%;
  height: 1px;
  pointer-events: none;
}

/* ==================== Balance Display ==================== */
.user-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.profile-chip {
  min-width: 0;
  cursor: pointer;
  border-radius: 12px;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.profile-chip:hover {
  background: var(--surface-soft);
}

.profile-user-icon {
  flex: 0 0 auto;
  font-size: 20px;
  line-height: 1;
  color: #6f6f6f;
}

.balance-display {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--accent-softer);
  border: 1px solid var(--accent-border);
  border-radius: 10px;
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  cursor: pointer;
}

.token-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
}
.token-icon--sm { width: 14px; height: 14px; }
.balance-amount { font-variant-numeric: tabular-nums; }

.plan-badge {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 2px;
}
.plan-badge.free { background: rgba(158,158,158,0.2); color: #9e9e9e; }
.plan-badge.pro { background: var(--success-soft); color: var(--success); }
.plan-badge.ultra { background: rgba(var(--color-accent-rgb), 0.25); color: var(--accent); }

/* ==================== Batch Row ==================== */
.batch-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 12px;
}

.batch-row label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0;
  white-space: nowrap;
}

/* ==================== Batch Selector ==================== */
.batch-selector {
  display: inline-flex;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.batch-btn,
.batch-step-btn {
  width: 32px;
  height: 28px;
  border: none;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 0;
  margin: 0;
  outline: none;
  font-family: 'Manrope', sans-serif;
}

.batch-btn:last-child,
.batch-step-btn:last-child { border-right: none; }
.batch-btn:hover:not(:disabled),
.batch-step-btn:hover:not(:disabled) { background: var(--surface-soft); color: var(--text-muted); }
.batch-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.batch-btn:disabled,
.batch-step-btn:disabled {
  opacity: 0.2;
  cursor: not-allowed;
  color: var(--text-muted);
}
.batch-btn:disabled:hover,
.batch-step-btn:disabled:hover { background: transparent; color: var(--text-muted); }

.batch-step-btn {
  color: var(--accent);
  font-size: 16px;
  font-weight: 700;
}

/* ==================== Cost Estimate ==================== */
.cost-estimate {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 10px;
  background: transparent;
  border: 1px solid var(--accent-border);
  border-radius: 8px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.cost-estimate .cost-label {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 12px;
}

.btn-cost {
  font-size: 12px;
  opacity: 0.7;
  margin-left: 6px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  flex: 0 0 auto;
  min-width: 48px;
  justify-content: flex-start;
  white-space: nowrap;
  line-height: 1;
}
.btn-cost:empty { visibility: hidden; }
.btn-cost .token-icon { width: 12px; height: 12px; }

#generate-btn,
#video-generate-btn {
  box-sizing: border-box;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
}

/* ==================== Pagination ==================== */
.pagination-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: nowrap;
}

.pagination-info { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

.pagination-center {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pagination-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pagination-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.pagination-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.pagination-page { font-size: 12px; color: var(--text-muted); min-width: 44px; text-align: center; white-space: nowrap; }

.pagination-limit {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text-muted);
  padding: 4px 6px;
  font-size: 12px;
  cursor: pointer;
  font-family: 'Manrope', sans-serif;
}
.pagination-limit:focus { border-color: var(--accent); outline: none; }

/* ==================== Skeleton Loading ==================== */
@keyframes skeleton-pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}

.skeleton-card {
  background: #222;
  border-radius: 16px;
  aspect-ratio: 1;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}

.skeleton-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

@media (max-width: 768px) {
  .user-header { flex-wrap: nowrap; gap: 8px; }
  .header-logo { height: 22px; }
  .user-header-right { gap: 6px; }
  .balance-display { padding: 3px 8px; font-size: 11px; gap: 4px; }
  .balance-display .token-icon { width: 12px; height: 12px; }
  .balance-amount { font-size: 11px; }
  .plan-badge { font-size: 9px; padding: 1px 5px; letter-spacing: 0.3px; }
  .profile-user-icon { font-size: 18px; }
  .user-name { font-size: 11px; max-width: 112px; }
  .user-info { gap: 6px; }
  .btn-subtle svg { width: 16px; height: 16px; }
  .batch-row { flex-wrap: wrap; gap: 8px; }
  .batch-btn { width: 40px; height: 34px; font-size: 13px; }
  .history-header { flex-wrap: wrap; }
  .pagination-controls { flex-wrap: nowrap; gap: 8px; }
  .pagination-info { font-size: 11px; }
  .pagination-page { font-size: 11px; min-width: 36px; }
  .pagination-btn { width: 24px; height: 24px; font-size: 12px; }
  .pagination-limit { padding: 3px 4px; font-size: 11px; }
}

@media (max-width: 420px) {
  .user-header { gap: 4px; }
  .header-logo { height: 18px; }
  .user-header-right { gap: 4px; }
  .balance-display { padding: 2px 6px; font-size: 10px; gap: 3px; border-radius: 8px; }
  .balance-display .token-icon { width: 10px; height: 10px; }
  .plan-badge { font-size: 8px; padding: 1px 4px; margin-left: 2px; }
  .profile-user-icon { font-size: 16px; }
  .user-name { font-size: 10px; max-width: 72px; overflow: hidden; text-overflow: ellipsis; }
  .user-info { gap: 4px; }
  .btn-subtle svg { width: 14px; height: 14px; }
  .pagination-info { display: none; }
  .pagination-controls { gap: 6px; }
  .pagination-btn { width: 22px; height: 22px; font-size: 11px; }
  .pagination-page { font-size: 10px; min-width: 30px; }
  .pagination-limit { font-size: 10px; padding: 2px 3px; }
}

/* Workspace polish: gallery-first surface without changing existing DOM contracts. */
.is-hidden {
  display: none;
}

.admin-icon {
  font-size: 20px;
}

body {
  background: var(--bg);
  color: var(--text-muted);
}

.app-content {
  min-height: 100vh;
}

.container {
  max-width: 1760px;
  padding: 22px clamp(16px, 2vw, 36px) 44px;
}

.user-header {
  position: sticky;
  top: env(safe-area-inset-top);
  z-index: 50;
  min-height: 58px;
  margin: 0 0 18px;
  padding: 10px 0;
  background: rgba(24, 24, 24, 0.88);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.header-logo {
  height: 30px;
}

.card {
  padding: 0;
  margin: 0;
  overflow: visible;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  backdrop-filter: none;
}

.card:hover {
  box-shadow: none;
}

.tabs,
.card > .tab-content {
  max-width: 980px;
  margin-left: auto;
  margin-right: auto;
}

.tabs {
  margin-bottom: 12px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.03);
}

.tab {
  border-width: 1px;
  border-radius: var(--radius-sm);
}

.card > .tab-content {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: rgba(32, 32, 32, 0.86);
  box-shadow: 0 18px 44px var(--shadow-color-soft);
}

.history-section {
  max-width: none;
  margin: 26px 0 0;
}

.history-section > .history-header {
  position: sticky;
  top: env(safe-area-inset-top);
  z-index: 120;
  min-height: 46px;
  padding: 8px 0;
  border-top: 0;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  backdrop-filter: blur(16px);
}

.history-section.expanded .history-header {
  border-bottom: 1px solid var(--line);
}

.history-content > .history {
  padding: 16px 0 0;
}

.history {
  gap: 18px;
}

.history-item {
  padding: 14px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: none;
}

.history-item > .history-header {
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 8px;
  padding: 0;
  border: 0;
  background: transparent;
  backdrop-filter: none;
}

.history-section.expanded .history-item > .history-header {
  border: 0;
  padding-bottom: 0;
}

.history-prompt {
  color: var(--text-muted);
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.history-meta {
  gap: 3px;
  color: #737373;
}

.history-time {
  color: var(--accent);
}

/* Desktop dock context: keep grid driven by --gallery-cols variable */

.image-card {
  padding: 8px;
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
  border-color: var(--line);
  box-shadow: none;
}

.image-card:hover {
  border-color: rgba(205, 220, 57, 0.28);
  box-shadow: 0 12px 26px var(--shadow-color-soft);
}

.img-wrap,
.image-card img {
  border-radius: var(--radius-md);
}

.image-card .buttons {
  gap: 6px;
  margin-top: 8px;
}

.image-card .buttons-left,
.image-card .buttons-right {
  gap: 6px;
}

.image-card a,
.image-card .remove-bg-btn,
.image-card button.icon-btn {
  min-height: 28px;
  padding: 0 9px;
  border-radius: var(--radius-sm);
  font-size: 10px;
}

.image-card .icon-btn {
  width: 28px;
  min-width: 28px;
  height: 28px;
}

.image-card .fav-overlay,
.image-card .delete-overlay {
  border-radius: var(--radius-sm);
}

@media (min-width: 901px) {
  .history-content > .history {
    display: grid;
    grid-template-columns: repeat(var(--gallery-cols, 4), minmax(220px, 1fr));
    grid-auto-flow: row;
    gap: 18px;
    align-items: stretch;
  }

  .history-item {
    grid-column: span var(--history-span, 1);
    min-width: 0;
    height: 100%;
  }

  .gallery {
    justify-content: start;
    align-items: stretch;
    gap: 14px;
  }

  .image-card {
    padding: 8px;
    border-radius: 14px;
  }

  .img-wrap,
  .image-card img {
    border-radius: 10px;
  }

  .image-card .buttons {
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: 12px;
  }

  .image-card .buttons-left,
  .image-card .buttons-right {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 6px;
    min-width: 0;
  }

  .image-card .buttons-left {
    flex: 1 1 auto;
  }

  .image-card .buttons-right {
    flex: 0 0 auto;
    justify-content: flex-end;
  }

  .image-card a,
  .image-card .remove-bg-btn,
  .image-card button.icon-btn {
    flex: 0 0 auto;
    height: 28px;
    min-height: 28px;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

.upload-zone {
  border-width: 1px;
  border-radius: var(--radius-md);
  background: rgba(10, 10, 10, 0.54);
}

.upload-zone:hover {
  transform: none;
}

.pagination-controls {
  gap: 10px;
}

.pagination-btn,
.pagination-limit,
.fav-filter-btn,
.batch-selector {
  border-color: var(--line-strong);
}

@media (max-width: 900px) {
  .container {
    padding: 14px 12px 30px;
  }

  .user-header {
    min-height: 50px;
    margin-bottom: 12px;
  }

  .card > .tab-content {
    padding: 14px;
    border-radius: var(--radius-md);
  }

  .history-section > .history-header {
    top: env(safe-area-inset-top);
    gap: 8px;
  }

  /* Cap gallery at 2 cols at <=900px */
  .gallery {
    grid-template-columns: repeat(min(var(--gallery-cols, 4), 2), minmax(0, 1fr));
    gap: 10px;
  }

  .history-item {
    padding: 10px;
    border-radius: var(--radius-md);
  }

  .image-card {
    padding: 6px;
    border-radius: var(--radius-md);
  }

  .image-card .buttons {
    flex-direction: column;
    align-items: stretch;
  }

  .image-card .buttons-left,
  .image-card .buttons-right {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .image-card .buttons-left {
    grid-template-columns: 1fr;
  }

  .image-card a,
  .image-card .remove-bg-btn,
  .image-card button.icon-btn {
    width: 100%;
    min-width: 0;
    min-height: 30px;
    justify-content: center;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

html.ios-standalone body {
  padding-top: 0;
}

@media (max-width: 900px) {
  html.ios-standalone .container,
  html.ios-standalone .tools-screen {
    padding-top: max(14px, calc(env(safe-area-inset-top) + 12px));
  }

  html.ios-standalone .user-header {
    position: relative;
    top: auto;
    z-index: 1;
    margin-bottom: 14px;
    transform: translateZ(0);
  }

  html.ios-standalone .tabs {
    position: relative;
    z-index: 2;
    margin-top: 0;
  }
}

@media (max-width: 420px) {
  .tabs {
    gap: 4px;
    padding: 4px;
  }

  .tab {
    flex: 1 1 0;
    justify-content: center;
    padding: 10px 8px;
    font-size: 12px;
  }

  .gallery {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .history-section > .history-header {
    position: sticky;
    top: env(safe-area-inset-top);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

/* Mobile card polish: keep nested radii proportional and actions compact. */
@media (max-width: 900px) {
  #video-start-zone,
  #video-end-zone {
    min-height: 92px;
    padding: 18px 14px;
    gap: 9px;
  }

  .container {
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
  }

  .history-section {
    margin-top: 18px;
  }

  .history-content > .history {
    padding-top: 10px;
  }

  .history {
    gap: 18px;
  }

  .history-item {
    padding: 12px;
    border-radius: 14px;
  }

  .history-item > .history-header {
    margin: 4px 4px 10px;
  }

  /* Cap gallery at 2 cols at <=900px (mobile card polish) */
  .gallery {
    grid-template-columns: repeat(min(var(--gallery-cols, 4), 2), minmax(0, 1fr));
    gap: 8px;
  }

  .image-card {
    padding: 4px;
    border-radius: 10px;
  }

  .img-wrap,
  .image-card img {
    border-radius: 8px;
  }

  .image-card .buttons {
    flex-direction: row;
    align-items: center;
    gap: 4px;
    margin-top: 5px;
  }

  .image-card .buttons-left,
  .image-card .buttons-right {
    display: flex;
    align-items: center;
    gap: 4px;
  }

  .image-card .buttons-left {
    flex: 1 1 auto;
    flex-wrap: wrap;
  }

  .image-card .buttons-right {
    flex: 0 0 auto;
    justify-content: flex-end;
  }

  .image-card a,
  .image-card .remove-bg-btn,
  .image-card button.icon-btn {
    width: auto;
    min-width: 0;
    min-height: 36px;
    height: 36px;
    padding: 0 12px;
    border-radius: 8px;
    font-size: 12px;
    line-height: 1;
    gap: 5px;
  }

  .image-card .icon-btn {
    width: 36px;
    min-width: 36px;
    padding: 0;
  }

  .image-card .fav-overlay,
  .image-card .delete-overlay {
    width: 34px;
    height: 34px;
    min-width: 34px;
    border-radius: 9px;
    background: rgba(10, 10, 10, 0.64);
    color: rgba(229, 231, 235, 0.82);
    box-shadow: none;
    transform: none;
    transition: background-color 0.16s ease, color 0.16s ease;
  }

  .image-card .fav-overlay:hover,
  .image-card .delete-overlay:hover {
    transform: none;
  }

  .image-card .fav-overlay .material-icons-outlined,
  .image-card .delete-overlay .material-icons-outlined,
  .image-card .btn-icon,
  .image-card .icon-btn .material-icons-outlined {
    width: 13px;
    min-width: 13px;
    font-size: 13px; /* match material-icons class size */
  }

  .tab,
  .provider-btn,
  .batch-selector,
  .cost-estimate,
  .pagination-btn,
  .pagination-limit,
  .fav-filter-btn,
  .vmodel-selected,
  select,
  textarea,
  .upload-zone {
    border-radius: 8px;
  }

  .tabs,
  .card > .tab-content {
    border-radius: 12px;
  }
}

@media (max-width: 420px) {
  .container {
    padding-left: max(6px, env(safe-area-inset-left));
    padding-right: max(6px, env(safe-area-inset-right));
  }

  .card > .tab-content {
    padding: 12px;
  }

  .history-item {
    padding: 5px;
  }

  .gallery {
    grid-template-columns: 1fr;
  }

  .image-card {
    padding: 4px;
  }

  .image-card .remove-bg-btn {
    max-width: 108px;
  }

  .image-card .repeat-btn {
    max-width: 86px;
  }
}

@media (max-width: 900px) {
  .gallery {
    grid-template-columns: 1fr !important;
    gap: 14px !important;
  }

  .history-section > .history-header {
    position: sticky;
    top: env(safe-area-inset-top);
  }

  .history {
    gap: 16px;
  }

  .history-item {
    padding: 10px;
  }

  .image-card {
    width: 100%;
    padding: 6px;
  }

  .image-card .buttons {
    flex-direction: row !important;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: 6px;
  }

  .image-card .buttons-left {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    flex-wrap: nowrap;
    gap: 5px;
  }

  .image-card .buttons-right {
    display: flex;
    flex: 0 0 auto;
    gap: 5px;
  }

  .image-card a,
  .image-card .remove-bg-btn,
  .image-card button.icon-btn {
    width: auto;
    min-width: 0;
    height: 34px;
    min-height: 34px;
    padding: 0 8px;
    border-radius: 8px;
    font-size: 10px;
    justify-content: center;
    white-space: nowrap;
  }

  .image-card .icon-btn,
  .image-card button.icon-btn,
  .image-card a.icon-btn {
    width: 34px;
    min-width: 34px;
    padding: 0;
  }

  .image-card .remove-bg-btn {
    flex: 1 1 0;
    max-width: none;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .image-card .repeat-btn {
    flex: 0 1 76px;
    max-width: none;
  }
}

/* ========================================================================
 * 05. SIDEBAR — desktop navigation
 * ====================================================================== */
.app-sidebar {
  position: fixed;
  top: 24px;
  left: 12px;
  bottom: 24px;
  height: auto;
  max-height: none;
  min-height: 0;
  width: 84px;
  transform: none;
  background: rgba(20, 20, 20, 0.92);
  backdrop-filter: blur(16px);
  border: 1px solid var(--line);
  border-radius: 16px;
  display: none;
  flex-direction: column;
  align-items: center;
  padding: 18px 8px;
  gap: 14px;
  z-index: 50;
}

.app-sidebar.hidden { display: none !important; }

/* ===== Mobile slide-in menu (reuses the sidebar) ===== */
.menu-toggle { display: none; }
.sidebar-backdrop { display: none; }
@media (max-width: 1023px) {
  body.sidebar-open {
    overflow: hidden;
  }

  .menu-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; border-radius: 12px; flex: 0 0 auto;
    background: var(--color-control); border: 1px solid var(--line);
    color: var(--color-text); cursor: pointer;
  }
  .menu-toggle .material-icons-outlined { font-size: 22px; }

  /* Mobile navigation lives only in the side menu — drop the duplicate header tabs */
  .card > .tabs { display: none; }

  /* When the drawer is open, lift the whole header (and its hamburger) above it,
     so tapping the hamburger again closes — instead of hitting the drawer's profile. */
  body.sidebar-open .user-header { z-index: 10033; }
  body.sidebar-open .tools-head { position: relative; z-index: 10033; }

  /* Off-canvas drawer */
  .app-sidebar:not(.hidden) {
    display: flex;
    top: 0; left: 0; bottom: 0; height: 100%;
    width: min(224px, 72vw); max-height: none; min-height: 0;
    border-radius: 0; border-width: 0 1px 0 0;
    align-items: stretch; padding: 92px 14px 18px; gap: 16px; /* top clears the lifted header */
    transform: translateX(calc(-100% - 16px)); transition: transform 0.25s ease;
    animation: none !important;
    z-index: 10030;
  }
  .app-sidebar:not(.hidden):not(.open) {
    pointer-events: none;
    transform: translateX(calc(-100% - 16px)) !important;
  }
  .app-sidebar.open {
    pointer-events: auto;
    transform: translateX(0) !important;
  }
  .app-sidebar .sidebar-top { width: 100%; align-items: flex-start; }
  .app-sidebar .sidebar-nav { width: 100%; gap: 6px; }
  .app-sidebar .sidebar-nav-btn {
    width: 100%; flex-direction: row; justify-content: flex-start;
    gap: 12px; padding: 12px 14px; border-radius: 12px; position: relative;
  }
  .app-sidebar .sidebar-nav-label { display: inline; font-size: 14px; }
  .app-sidebar .sidebar-bottom { width: 100%; margin-top: auto; display: flex; flex-direction: column; gap: 6px; }

  .sidebar-backdrop.open {
    display: block; position: fixed; inset: 0;
    background: rgba(0,0,0,0.5); z-index: 10029;
  }
  .sidebar-backdrop[hidden] {
    display: none !important;
  }
}

.sidebar-top {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.sidebar-logo {
  width: 56px;
  height: auto;
  margin-bottom: 4px;
  filter: drop-shadow(0 2px 8px var(--accent-border));
  display: none;
}

.sidebar-user {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
  width: 100%;
  min-width: 0;
  cursor: pointer;
  border-radius: 12px;
  padding: 4px 2px;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.sidebar-user:hover,
.sidebar-user:focus-visible {
  background: var(--accent-softer);
  outline: 1px solid var(--accent-border);
}

.sidebar-username {
  font-size: 10px;
  font-weight: 600;
  color: var(--text);
  width: 100%;
  max-width: 68px;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.sidebar-balance {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
}
.sidebar-balance .token-icon {
  width: 12px;
  height: 12px;
}

.sidebar-plan {
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  margin-top: 8px;
}

.sidebar-bottom {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
}

.sidebar-nav-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  padding: 10px 4px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
  font-family: 'Manrope', sans-serif;
}
.sidebar-nav-btn .material-icons-outlined {
  font-size: 22px;
}
.sidebar-services-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.sidebar-new-badge {
  position: absolute;
  top: 5px;
  right: 5px;
  z-index: 1;
  font-size: 6px;
  line-height: 9px;
  font-weight: 800;
  letter-spacing: 0.2px;
  text-transform: uppercase;
  padding: 0 3px;
  border-radius: 2px;
  transform: skewX(-8deg);
  pointer-events: none;
}
.sidebar-nav-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.2px;
}
.sidebar-nav-btn:hover {
  background: rgba(255, 255, 255, 0.04);
  color: #ddd;
}
.sidebar-nav-btn.active {
  background: rgba(205, 220, 57, 0.10);
  color: var(--accent);
  border-color: rgba(var(--color-accent-rgb), 0.25);
}

@media (min-width: 1024px) {
  .app-sidebar { display: flex; }

  .app-content { padding-left: 101px; }

  /* Hide top header — info moved to sidebar */
  .user-header { display: none; }

  /* Container is wider on desktop */
  .container {
    max-width: none;
    padding: 24px 32px 200px;
  }

  /* History grows up; takes full width */
  .history-section {
    margin-top: 0;
  }

  /* Generation form becomes fixed bottom dock — centered card */
  .card {
    position: fixed;
    bottom: 16px;
    left: calc(96px + 50%);
    transform: translateX(calc(-50% - 48px));
    width: min(920px, calc(100vw - 96px - 32px));
    margin: 0;
    padding: 14px 16px;
    border-radius: 16px;
    background: var(--surface);
    backdrop-filter: blur(24px);
    box-shadow: 0 16px 48px var(--overlay-medium);
    z-index: 30;
    max-height: 38vh;
    overflow: visible;
    display: flex;
    flex-direction: column;
  }

  /* Hide tabs row inside dock — sidebar replaces it */
  .card > .tabs { display: none; }

  /* Compact form padding */
  .card .tab-content {
    overflow: visible;
    max-height: calc(38vh - 28px);
  }
  .card .tab-content::-webkit-scrollbar { width: 4px; }
  .card .tab-content::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 4px; }

  .card textarea {
    margin-bottom: 12px;
    min-height: 64px;
  }

  .card .row {
    margin-bottom: 12px;
    gap: 10px;
  }

  /* Hide upload zone large preview area in dock — keep functional */
  .card .upload-zone {
    min-height: 60px;
    padding: 10px 14px;
  }

  /* Smaller labels in dock */
  .card label {
    font-size: 11px;
    margin-bottom: 4px;
  }
}

/* Tablet/mid: still show sidebar but narrower main padding */
@media (min-width: 1024px) and (max-width: 1280px) {
  .container { padding: 20px 20px 200px; }
}

/* ========================================================================
 * 10. GENERATION PANEL — gen-shell horizontal layout (>=560px)
 * 14. VIDEO FORM — uses same patterns; specific overrides in this section
 * 19. ADMIN — opens in new window, no styles needed here
 * ====================================================================== */
/* gen-shell horizontal panel (>=560px) */
/* Two-row grid:                                                              */
/*   row 1 (top):    [prompt --------------------]  [upload ------]            */
/*   row 2 (bottom): [model][16:9][4K][count][gap][generate]                   */
@media (min-width: 560px) {
  /* Remove max-width cap on tab-content when form is gen-shell */
  .card > #generate-form.gen-shell {
    max-width: none;
    margin: 0;
    padding: 4px;
    border: 0;
    border-radius: 16px;
    background: transparent;
    box-shadow: none;
    overflow: visible;
  }

  /* Form = grid panel */
  #generate-form.gen-shell.tab-content.active {
    display: grid;
    grid-template-columns: minmax(190px, 220px) minmax(112px, 1fr) minmax(108px, 1fr) 86px minmax(210px, 240px);
    grid-template-rows: var(--image-prompt-row-height, 110px) 60px;
    grid-template-areas:
      "prompt  prompt  prompt     prompt upload"
      "model   aspect  resolution count  actions";
    column-gap: 12px;
    row-gap: 14px;
    align-items: stretch;
    width: 100%;
    max-width: none;
    position: relative;
    overflow: visible;
    box-sizing: border-box;
    transition: grid-template-rows 160ms ease;
  }

  /* Thin horizontal divider between top row and bottom row */
  #generate-form.gen-shell.tab-content.active::before {
    content: "";
    grid-column: 1 / -1;
    grid-row: 2 / 3;
    align-self: start;
    height: 1px;
    margin-top: -7px;
    background: var(--line);
    pointer-events: none;
  }

  /* Hide elements not in reference */
  #generate-shell-hidden,
  #generate-form.gen-shell > label[for="prompt"] { display: none; }
  #generate-form.gen-shell .field:has(#provider),
  #generate-form.gen-shell .field:has(#output_format) { display: none; }

  #generate-form.gen-shell > .gen-queue {
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(100% + 12px);
    display: flex;
    max-height: 118px;
    overflow-y: auto;
    margin: 0;
    padding: 2px;
    z-index: 35;
  }

  #generate-form.gen-shell > .gen-queue:empty {
    display: none;
  }

  #generate-form.gen-shell > .gen-queue .gen-queue-card {
    width: 100%;
    background: var(--surface);
    box-shadow: 0 12px 34px var(--overlay-soft);
  }

  /* Flatten .row containers so .field children become grid items */
  #generate-form.gen-shell > .row {
    display: contents;
  }

  /* All fields in grid: clear margins */
  #generate-form.gen-shell .field {
    margin: 0;
  }
  #generate-form.gen-shell .field > label {
    display: none;
  }

  /* TOP-LEFT — prompt textarea */
  #generate-form.gen-shell > .textarea-wrapper {
    grid-area: prompt;
    margin: 0;
    position: relative;
    height: 100%;
    min-height: 0;
    align-self: stretch;
  }
  #generate-form.gen-shell .textarea-wrapper textarea {
    margin: 0;
    width: 100%;
    height: 100% !important;
    min-height: 0;
    max-height: var(--prompt-textarea-max-height);
    border: 2px solid var(--accent);
    border-radius: 14px;
    background: var(--color-control);
    padding: 14px 50px 14px 18px;
    font-size: 16px;
    line-height: 1.45;
    resize: none;
    overflow-y: auto;
    scrollbar-gutter: auto;
    box-shadow: 0 0 0 4px var(--accent-softer);
  }
  #generate-form.gen-shell .textarea-wrapper textarea.prompt-scrollbar-left,
  #video-form.tab-content.active #video-prompt.prompt-scrollbar-left {
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
  #generate-form.gen-shell .textarea-wrapper textarea::placeholder {
    color: var(--text-muted);
    font-size: 16px;
  }
  #generate-form.gen-shell .textarea-wrapper textarea.prompt-scrollbar-left::-webkit-scrollbar,
  #video-form.tab-content.active #video-prompt.prompt-scrollbar-left::-webkit-scrollbar {
    width: 0;
    height: 0;
  }
  #generate-form.gen-shell .prompt-scrollbar-visual,
  #video-form.tab-content.active .prompt-scrollbar-visual {
    position: absolute;
    left: 16px;
    top: 16px;
    bottom: 16px;
    width: 5px;
    pointer-events: none;
    opacity: 0;
    z-index: 3;
    transition: opacity var(--transition-fast);
  }
  #generate-form.gen-shell .prompt-scrollbar-visual.is-visible,
  #video-form.tab-content.active .prompt-scrollbar-visual.is-visible {
    opacity: 1;
    pointer-events: auto;
  }
  #generate-form.gen-shell .prompt-scrollbar-visual-thumb,
  #video-form.tab-content.active .prompt-scrollbar-visual-thumb {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    min-height: 28px;
    background: var(--scrollbar-thumb);
    border-radius: 999px;
    cursor: grab;
    transform: translateY(0);
  }
  #generate-form.gen-shell .prompt-scrollbar-visual-thumb:active,
  #video-form.tab-content.active .prompt-scrollbar-visual-thumb:active {
    cursor: grabbing;
  }
  #generate-form.gen-shell .prompt-actions,
  #video-form.tab-content.active .prompt-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    gap: 6px;
  }
  #generate-form.gen-shell .enhance-prompt-btn,
  #video-form.tab-content.active .enhance-prompt-btn {
    position: relative;
    width: 34px;
    height: 34px;
    padding: 0;
    border-radius: 10px;
    background: var(--line);
    border: 1px solid var(--line);
    color: var(--text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  #generate-form.gen-shell .enhance-prompt-btn .material-icons-outlined,
  #video-form.tab-content.active .enhance-prompt-btn .material-icons-outlined {
    font-size: 18px;
  }

  /* TOP-RIGHT — upload zone */
  #generate-form.gen-shell > div:has(#upload-zone),
  #generate-form.gen-shell > div[style*="margin-top: 16px"] {
    grid-area: upload;
    margin: 0 !important;
    height: 100%;
    display: flex;
    align-self: stretch;
  }
  #generate-form.gen-shell > div:has(#upload-zone) > label,
  #generate-form.gen-shell > div[style*="margin-top: 16px"] > label {
    display: none;
  }
  #generate-form.gen-shell .upload-zone {
    width: 100%;
    height: 100%;
    min-height: 0;
    padding: 10px 12px;
    border-radius: 14px;
    border: 1px dashed rgba(205, 220, 57, 0.35);
    background: rgba(15, 15, 15, 0.5);
    gap: 6px;
    overflow: hidden;
  }
  #generate-form.gen-shell .upload-zone .upload-icon {
    width: 28px;
    height: 28px;
    margin: 0;
  }
  #generate-form.gen-shell .upload-zone .upload-text {
    font-size: 13px;
    line-height: 1.3;
  }
  #generate-form.gen-shell .upload-zone .upload-hint {
    display: none;
  }
  #generate-form.gen-shell .upload-zone.has-files {
    align-items: stretch;
    justify-content: flex-start;
    padding: 8px;
    overflow-y: auto;
  }
  #generate-form.gen-shell .upload-zone.has-files .upload-drop-area {
    display: none;
  }
  #generate-form.gen-shell .upload-zone .image-preview-grid {
    grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
    gap: 6px;
    width: 100%;
    align-content: start;
  }
  #generate-form.gen-shell .upload-zone .preview-item {
    border-radius: 10px;
  }
  #generate-form.gen-shell .upload-zone .delete-image-btn {
    width: 20px;
    height: 20px;
    border-radius: 6px;
  }

  /* BOTTOM ROW — model dropdown */
  #generate-form.gen-shell .field:has(#imodel-dropdown) {
    grid-area: model;
  }
  #generate-form.gen-shell .vmodel-selected {
    height: 58px;
    padding: 0 14px;
    border-radius: 14px;
    background-color: var(--color-control);
    font-size: 14px;
  }
  /* Open dropdown upward inside dock — !important needed to defeat .vmodel-list base rule */
  #generate-form.gen-shell .vmodel-list {
    top: auto !important;
    bottom: calc(100% + 10px);
    max-height: 320px;
    overflow-y: auto;
    width: max-content;
    min-width: 100%;
    max-width: 300px;
    z-index: 140;
  }

  /* BOTTOM ROW — aspect chip (cdrop wrapper) */
  #generate-form.gen-shell .field:has(#aspect_ratio) {
    grid-area: aspect;
  }
  /* BOTTOM ROW — resolution chip (cdrop wrapper) */
  #generate-form.gen-shell .field:has(#resolution) {
    grid-area: resolution;
  }
  #generate-form.gen-shell .cdrop {
    height: 58px;
    padding: 0 10px;
    border-radius: 14px;
    gap: 7px;
  }
  #generate-form.gen-shell .cdrop-icon {
    width: 20px;
    min-width: 20px;
    font-size: 18px;
    color: var(--color-accent);
    overflow: hidden;
  }
  #generate-form.gen-shell .cdrop-value {
    font-size: 12px;
    font-weight: 700;
    text-align: left;
  }
  #generate-form.gen-shell .cdrop-arrow {
    width: 16px;
    min-width: 16px;
    font-size: 18px;
    margin-left: 0;
  }
  #generate-form.gen-shell .cdrop-list {
    top: auto;
    bottom: calc(100% + 10px);
    z-index: 140;
    max-height: 260px;
  }

  /* BOTTOM ROW — batch (count) */
  #generate-form.gen-shell > .batch-row {
    grid-area: count;
    margin: 0;
    display: flex;
    align-items: center;
    height: 58px;
  }
  #generate-form.gen-shell > .batch-row > label,
  #generate-form.gen-shell > .batch-row > .cost-estimate {
    display: none;
  }
  #generate-form.gen-shell .batch-selector {
    display: flex;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: space-between;
    background: var(--color-control);
    border-radius: 14px;
    padding: 4px;
    gap: 4px;
    overflow: hidden;
  }
  #generate-form.gen-shell .batch-btn,
  #generate-form.gen-shell .batch-step-btn {
    flex: 1 1 0;
    min-width: 0;
    height: 100%;
    padding: 0;
    font-size: 14px;
    font-weight: 600;
    border-radius: 10px;
    border-right: 0;
  }
  #generate-form.gen-shell .batch-btn.active {
    color: var(--color-accent);
    background: var(--accent-soft);
  }
  #generate-form.gen-shell .batch-step-btn {
    color: var(--color-accent);
  }
  #generate-form.gen-shell .batch-step-btn:disabled {
    color: var(--accent);
    opacity: 0.65;
  }

  /* BOTTOM ROW — generate button */
  #generate-form.gen-shell > .actions {
    grid-area: actions;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
  }
  #generate-form.gen-shell #generate-btn {
    width: 100%;
    height: 58px;
    padding: 0 18px;
    border-radius: 14px;
    background: var(--color-accent-hover);
    color: var(--color-on-accent);
    font-size: 14px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    white-space: nowrap;
  }
  #generate-form.gen-shell #generate-btn .btn-cost {
    font-size: 12px;
    font-weight: 600;
    opacity: 0.7;
  }
  /* Hide loader/status inside actions (toast-style elsewhere) */
  #generate-form.gen-shell > .actions > .loader,
  #generate-form.gen-shell > .actions > .status {
    display: none;
  }
}

@media (min-width: 1024px) {
  .card:has(#video-form.active) {
    width: min(1220px, calc(100vw - 128px - 32px));
    max-height: 64vh;
  }

  .card:has(#video-form.active) .tab-content {
    max-height: calc(64vh - 28px);
  }

  #video-form.tab-content.active {
    display: grid;
    --video-frames-min-height: 96px;
    grid-template-columns: minmax(176px, 220px) minmax(132px, 150px) minmax(150px, 1fr) 58px minmax(132px, 150px) minmax(82px, 96px) minmax(168px, 188px);
    grid-template-rows: max(var(--video-prompt-row-height, 96px), var(--video-frames-min-height)) 64px;
    grid-template-areas:
      "prompt prompt prompt frames frames frames frames"
      "model aspect duration audio resolution count actions";
    grid-auto-rows: auto;
    column-gap: 12px;
    row-gap: 14px;
    align-items: stretch;
    width: 100%;
    max-width: none;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    overflow: visible;
    transition: grid-template-rows 160ms ease;
  }

  #video-form.tab-content.active.video-frame-batch {
    --video-frames-min-height: 144px;
  }

  #video-form.tab-content.active > label[for="video-prompt"],
  #video-form.tab-content.active > .field:has(#video-model) > label,
  #video-form.tab-content.active > .row > .field > label,
  #video-form.tab-content.active > .batch-row > label,
  #video-form.tab-content.active > .batch-row > .cost-estimate,
  #video-form.tab-content.active #video-frames-section > label {
    display: none;
  }

  #video-form.tab-content.active > .field:has(#video-model) {
    grid-area: model;
    margin: 0 !important;
    min-width: 0;
  }

  #video-form.tab-content.active > .textarea-wrapper {
    grid-area: prompt;
    margin: 0;
    height: 100%;
    min-height: 0;
    align-self: stretch;
    min-width: 0;
    position: relative;
  }

  #video-form.tab-content.active #video-prompt {
    width: 100%;
    height: 100% !important;
    min-height: 0;
    max-height: var(--prompt-textarea-max-height);
    margin: 0;
    resize: none;
    overflow-y: auto;
    border-radius: 14px;
    background: var(--color-control);
    padding: 14px 46px 14px 18px;
    scrollbar-gutter: auto;
  }

  #video-form.tab-content.active > .row {
    display: contents;
    margin: 0 !important;
    min-width: 0;
  }

  #video-form.tab-content.active .field {
    margin: 0;
    min-width: 0;
  }

  #video-form.tab-content.active .field:has(#video-aspect-ratio) {
    grid-area: aspect;
  }

  #video-form.tab-content.active .field:has(#video-duration) {
    grid-area: duration;
  }

  #video-form.tab-content.active .field:has(#video-audio) {
    grid-area: audio;
  }

  #video-form.tab-content.active #video-resolution-field,
  #video-form.tab-content.active #video-mode-field {
    grid-area: resolution;
  }

  #video-form.tab-content.active select,
  #video-form.tab-content.active .vmodel-selected {
    height: 58px;
    min-height: 0;
    border-radius: 14px;
    background-color: var(--color-control);
  }

  #video-form.tab-content.active .vmodel-selected {
    gap: 8px;
    padding: 0 12px;
  }

  #video-form.tab-content.active .vmodel-selected .vmodel-name {
    font-size: 12px;
    white-space: nowrap;
  }

  #video-form.tab-content.active .vmodel-selected .vmodel-badge {
    padding: 1px 4px;
  }

  #video-form.tab-content.active .vmodel-list {
    top: auto !important;
    bottom: calc(100% + 10px);
    max-height: min(720px, calc(100vh - 96px));
    overflow-y: auto;
    width: max-content;
    min-width: 100%;
    max-width: 320px;
    z-index: 140;
  }

  #video-form.tab-content.active .vmodel-list .vmodel-item {
    padding-block: 8px;
  }

  #video-form.tab-content.active .duration-control {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 58px;
    padding: 0 6px;
    border-radius: 14px;
    background: var(--color-control);
  }

  #video-form.tab-content.active .duration-value {
    min-width: 0;
    font-size: 12px;
  }

  #video-form.tab-content.active .cdrop--video {
    height: 58px;
    padding: 0 10px;
    border-radius: 14px;
    gap: 7px;
    background: var(--color-control);
  }

  #video-form.tab-content.active .cdrop--video .cdrop-icon {
    width: 20px;
    min-width: 20px;
    font-size: 18px;
    color: var(--color-accent);
    overflow: hidden;
  }

  #video-form.tab-content.active .cdrop--video .cdrop-value {
    font-size: 12px;
    font-weight: 700;
  }

  #video-form.tab-content.active .cdrop--video .cdrop-arrow {
    width: 16px;
    min-width: 16px;
    font-size: 18px;
    margin-left: 0;
  }

  #video-form.tab-content.active .cdrop--video .cdrop-list {
    top: auto;
    bottom: calc(100% + 10px);
    z-index: 150;
    max-height: 260px;
  }

  #video-form.tab-content.active .audio-toggle-select {
    display: none !important;
  }

  #video-form.tab-content.active .audio-toggle-btn {
    width: 100%;
    height: 58px;
    padding: 0;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: var(--color-control);
    color: rgba(205, 220, 57, 0.72);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: none;
  }

  #video-form.tab-content.active .audio-toggle-btn .material-icons-outlined {
    font-size: 20px;
  }

  #video-form.tab-content.active .audio-toggle-btn.active {
    color: var(--color-on-accent);
    background: var(--color-accent);
    border-color: var(--color-accent);
  }

  #video-form.tab-content.active .audio-toggle-btn:hover {
    border-color: rgba(205, 220, 57, 0.42);
  }

  #video-form.tab-content.active > .batch-row {
    grid-area: count;
    margin: 0;
    display: flex;
    align-items: stretch;
    height: 64px;
    min-width: 0;
  }

  #video-form.tab-content.active .batch-selector {
    display: flex;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: space-between;
    padding: 4px;
    border-radius: 14px;
    background: var(--color-control);
    border: 1px solid var(--line);
    overflow: hidden;
  }

  #video-form.tab-content.active .batch-btn,
  #video-form.tab-content.active .batch-step-btn {
    flex: 1 1 0;
    min-width: 0;
    height: 100%;
    padding: 0;
    border-right: 0;
    border-radius: 10px;
    color: var(--color-accent);
    font-size: 14px;
    font-weight: 600;
  }

  #video-form.tab-content.active .batch-btn.active {
    color: var(--color-accent);
    background: var(--accent-soft);
  }

  #video-form.tab-content.active .batch-step-btn:disabled {
    color: var(--accent);
    opacity: 0.65;
  }

  #video-form.tab-content.active #video-frames-section {
    grid-area: frames;
    display: grid;
    grid-template-columns: minmax(190px, 220px) minmax(0, 1fr);
    gap: 10px;
    align-items: stretch;
    margin: 0 !important;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
  }

  #video-form.tab-content.active #video-frame-mode-field {
    display: flex;
    height: 100%;
    min-height: 0;
    margin: 0 !important;
    overflow: hidden;
  }

  #video-form.tab-content.active #video-frame-mode-field > label {
    display: none;
  }

  #video-form.tab-content.active .video-frame-mode-toggle {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    height: 100%;
    gap: 4px;
  }

  #video-form.tab-content.active .video-frame-mode-toggle[data-option-count="2"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #video-form.tab-content.active .video-frame-mode-toggle .video-frame-mode-btn {
    flex-direction: column;
    gap: 3px;
    min-width: 0;
    height: 100%;
    padding: 5px 3px;
    border-radius: 12px;
    font-size: 10px;
  }

  #video-form.tab-content.active .video-frame-mode-btn .material-icons-outlined {
    font-size: 17px;
  }

  #video-form.tab-content.active #video-frames-section > .row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 10px;
    height: 100%;
    min-height: 0;
    margin: 0 !important;
    overflow: hidden;
  }

  #video-form.tab-content.active #video-frames-section .field {
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }

  #video-form.tab-content.active .upload-zone-small {
    height: 100%;
    max-height: 100%;
    min-height: 0;
    padding: 10px 12px;
    border-radius: 14px;
    overflow: hidden;
  }

  #video-form.tab-content.active #video-start-zone.has-files,
  #video-form.tab-content.active #video-end-zone.has-files {
    display: block;
    height: 100%;
    min-height: 0;
    max-height: 100%;
    padding: 6px;
    overflow: hidden;
  }

  #video-form.tab-content.active #video-start-zone.has-files .upload-inline-preview,
  #video-form.tab-content.active #video-end-zone.has-files .upload-inline-preview {
    display: block !important;
    width: 100%;
    height: 100%;
    max-height: 100%;
    min-height: 0;
    overflow: hidden;
  }

  #video-form.tab-content.active #video-start-zone.has-files .video-ref-preview-item,
  #video-form.tab-content.active #video-end-zone.has-files .video-ref-preview-item {
    width: 100%;
    height: 100%;
    min-height: 0;
    aspect-ratio: auto;
  }

  #video-form.tab-content.active #video-start-zone.has-files .video-ref-preview-item img,
  #video-form.tab-content.active #video-end-zone.has-files .video-ref-preview-item img {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important;
    object-position: center;
  }

  #video-form.tab-content.active #mc-video-section,
  #video-form.tab-content.active #avatar-audio-section,
  #video-form.tab-content.active #seedance2-ref-images-section,
  #video-form.tab-content.active #seedance2-ref-videos-section,
  #video-form.tab-content.active #kling-v3-advanced-section,
  #video-form.tab-content.active #seedance2-ref-audio-section {
    grid-column: 1 / -1;
    margin-top: 0 !important;
    min-height: 0;
  }

  #video-form.tab-content.active #mc-video-section > label,
  #video-form.tab-content.active #avatar-audio-section > label,
  #video-form.tab-content.active #seedance2-ref-videos-section > label,
  #video-form.tab-content.active #kling-v3-advanced-section > label,
  #video-form.tab-content.active #seedance2-ref-audio-section > label {
    display: block;
    margin-bottom: 6px;
    color: rgba(176, 190, 197, 0.9);
    font-size: 10px;
    line-height: 1.2;
  }

  #video-form[data-video-state="seedance2"].tab-content.active #seedance2-ref-videos-section > label,
  #video-form[data-video-state="seedance2"].tab-content.active #seedance2-ref-audio-section > label {
    display: none;
  }

  #video-form.tab-content.active #seedance2-ref-images-section > label {
    display: none;
  }

  #video-form.tab-content.active #seedance2-ref-images-zone::before {
    content: "Референс-изображения";
    display: block;
    margin-bottom: 5px;
    color: rgba(176, 190, 197, 0.86);
    font-size: 10px;
    font-weight: 800;
    line-height: 1.1;
    text-transform: uppercase;
    letter-spacing: 0.02em;
  }

  #video-form.tab-content.active #seedance2-ref-images-zone::after {
    content: "Опционально, до 9 шт.";
    display: block;
    margin-top: 4px;
    color: rgba(176, 190, 197, 0.66);
    font-size: 10px;
    line-height: 1.2;
  }

  #video-form.tab-content.active #seedance2-ref-images-zone.has-files::before,
  #video-form.tab-content.active #seedance2-ref-images-zone.has-files::after {
    display: none;
  }

  #video-form.tab-content.active #mc-video-section .upload-zone-small,
  #video-form.tab-content.active #avatar-audio-section .upload-zone-small,
  #video-form.tab-content.active #seedance2-ref-images-section .upload-zone-small,
  #video-form.tab-content.active #seedance2-ref-videos-section .upload-zone-small,
  #video-form.tab-content.active #seedance2-ref-audio-section .upload-zone-small {
    min-height: 64px;
  }

  #video-form.tab-content.active #seedance2-ref-images-section .upload-zone-small {
    min-height: 72px;
    padding-top: 9px;
    padding-bottom: 9px;
  }

  #video-form.tab-content.active .upload-zone-small .upload-hint {
    margin-top: 4px;
    font-size: 10px;
    line-height: 1.2;
    color: var(--text-muted);
  }

  #video-form.tab-content.active #seedance2-ref-images-preview,
  #video-form.tab-content.active #seedance2-ref-videos-preview,
  #video-form.tab-content.active #seedance2-ref-audio-preview {
    max-height: 82px;
    overflow-y: auto;
  }

  #video-form[data-video-state="seedance2"].tab-content.active #seedance2-ref-images-section {
    grid-column: 1 / 3;
    align-self: start;
  }

  #video-form[data-video-state="seedance2"].tab-content.active #seedance2-ref-videos-section {
    grid-column: 3 / 4;
  }

  #video-form[data-video-state="seedance2"].tab-content.active #seedance2-ref-audio-section {
    grid-column: 4 / -1;
  }

  #video-form[data-video-state="kling-v3"].tab-content.active #kling-v3-advanced-section {
    grid-column: 1 / -1;
  }

  #video-form.tab-content.active .kling-advanced {
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--color-control);
    padding: 0;
  }

  /* Свернуто — компактная строка; развернуто — растём до лимита и скроллим внутри */
  #video-form.tab-content.active .kling-advanced[open] {
    max-height: 380px;
    overflow-y: auto;
    scrollbar-width: thin;
  }

  #video-form.tab-content.active .kling-advanced summary {
    min-height: 44px;
    padding: 0 12px !important;
    display: flex;
    align-items: center;
    gap: 8px;
    color: rgba(229, 231, 235, 0.92);
    cursor: pointer;
    list-style: none;
  }

  #video-form.tab-content.active .kling-advanced summary::-webkit-details-marker {
    display: none;
  }

  #video-form.tab-content.active .kling-advanced summary > .material-icons-outlined {
    font-size: 18px;
    color: var(--color-accent);
  }

  #video-form.tab-content.active .kling-advanced-summary-meta {
    margin-left: 4px;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
  }

  #video-form.tab-content.active .kling-advanced-chevron {
    margin-left: auto;
    color: var(--text-muted) !important;
    transition: transform var(--transition-fast);
  }

  #video-form.tab-content.active .kling-advanced[open] .kling-advanced-chevron {
    transform: rotate(180deg);
  }

  #video-form.tab-content.active .kling-advanced > div {
    padding: 12px !important;
    border-top: 1px solid var(--line);
  }

  #video-form.tab-content.active > .actions {
    grid-area: actions;
    margin: 0;
    display: flex;
    align-items: stretch;
  }

  #video-form.tab-content.active #video-generate-btn {
    width: 100%;
    height: 58px;
    min-height: 58px;
    padding: 0 16px;
    border-radius: 14px;
    white-space: nowrap;
    font-size: 13px;
  }

  #video-form.tab-content.active > .actions > .loader,
  #video-form.tab-content.active > .actions > .status {
    display: none;
  }

  #video-form.tab-content.active > .gen-queue {
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(100% + 12px);
    display: flex;
    max-height: 118px;
    overflow-y: auto;
    margin: 0;
    padding-right: 4px;
  }

  #video-form.tab-content.active > .gen-queue:empty {
    display: none;
  }
}

/* ==================== Bottom Dock positioning (≥1024px) ==================== */
/* Keep .card fixed at bottom on desktop while internal layout = gen-shell      */
@media (min-width: 1024px) {
  .card .gen-queue {
    width: 100%;
  }
}

/* Final product-grid pass: remove masonry holes and normalize media cards. */
.history-content > .history {
  align-items: stretch;
}

.history-item {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.history-item > .gallery {
  flex: 1 1 auto;
}

.image-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.image-card .img-wrap,
.image-card.video-card > video {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #111;
}

.image-card .img-wrap {
  position: relative;
  overflow: hidden;
}

.image-card .img-wrap > img,
.image-card .img-wrap > video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: center;
}

.image-card .buttons {
  flex: 0 0 auto;
}

.history-section > .history-header {
  background: var(--bg);
}

.history-mobile-limit {
  grid-column: 1 / -1;
  display: flex;
  justify-content: center;
  padding: 10px 0 18px;
}

.upload-zone .upload-inline-preview {
  display: none;
}

.upload-zone.has-files {
  align-items: stretch;
  justify-content: flex-start;
  overflow: hidden;
}

.upload-zone.has-files > .upload-icon,
.upload-zone.has-files > .upload-text,
.upload-zone.has-files > .upload-hint {
  display: none;
}

.upload-zone.has-files .upload-inline-preview {
  display: grid !important;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0 !important;
  grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
  gap: 8px;
  align-content: stretch;
  overflow-y: auto;
}

.upload-zone.has-files .upload-inline-preview .preview-item,
.upload-zone.has-files .upload-inline-preview > div {
  width: 100%;
  height: 100%;
  min-height: 64px;
  border-radius: 10px;
  overflow: hidden;
}

.upload-zone.has-files .upload-inline-preview img,
.upload-zone.has-files .upload-inline-preview video {
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  display: block;
  object-fit: contain;
  object-position: center;
  background: var(--media-bg);
  border-radius: 0 !important;
}

.video-ref-preview-item,
.upload-preview-item {
  position: relative;
  width: 100%;
  min-height: 64px;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--media-bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-ref-preview-item img,
.upload-preview-item--image img,
.upload-preview-item--video video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  object-position: center;
  background: var(--media-bg);
}

.upload-preview-item--audio {
  aspect-ratio: auto;
  min-height: 42px;
  justify-content: flex-start;
}

.upload-zone.has-files .upload-inline-preview .video-ref-preview-item img,
.upload-zone.has-files .upload-inline-preview .video-ref-preview-item video,
.upload-zone.has-files .upload-inline-preview .upload-preview-item--image img,
.upload-zone.has-files .upload-inline-preview .upload-preview-item--video video {
  object-fit: contain !important;
  background: var(--media-bg);
}

#video-form.tab-content.active #video-start-zone.has-files.video-frame-batch-zone .upload-inline-preview.video-frame-batch-preview,
#video-form.tab-content.active #video-end-zone.has-files.video-frame-batch-zone .upload-inline-preview.video-frame-batch-preview {
  display: grid !important;
  grid-template-columns: repeat(var(--video-frame-batch-cols, 3), minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
  gap: 5px;
  align-content: stretch;
  overflow: hidden;
}

#video-form .video-frame-batch-zone .video-frame-batch-item {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  aspect-ratio: auto;
  border-radius: 7px;
}

#video-start-zone,
#video-end-zone {
  position: relative;
}

#video-form #video-start-zone.has-files > .upload-text,
#video-form #video-end-zone.has-files > .upload-text {
  display: block;
  position: absolute;
  left: 4px;
  bottom: 4px;
  z-index: 12;
  max-width: calc(100% - 8px);
  padding: 2px 5px;
  overflow: hidden;
  border-radius: var(--radius-xs);
  background: var(--overlay-dark);
  color: var(--text);
  font-size: 8px !important;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}

.video-frame-index-badge {
  position: absolute;
  top: 2px;
  left: 2px;
  z-index: 11;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 15px;
  height: 15px;
  padding: 0 3px;
  border: 1px solid var(--accent-border-strong);
  border-radius: var(--radius-xs);
  background: var(--overlay-dark);
  color: var(--accent);
  font-size: 8px;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}

#video-form .video-frame-batch-zone .video-frame-batch-item img {
  object-fit: contain !important;
}

#video-form .video-frame-batch-zone .delete-image-btn {
  width: 16px;
  height: 16px;
  top: 2px;
  right: 2px;
  opacity: 0;
}

#video-form .video-frame-batch-item:hover .delete-image-btn {
  opacity: 1;
}

@media (max-width: 1023px) {
  #video-form .video-frame-batch-zone.has-files {
    height: 180px;
    min-height: 180px;
    max-height: 180px;
    padding: 6px;
    overflow: hidden;
  }
}

@media (max-width: 900px) {
  #video-form .video-frame-batch-zone .delete-image-btn {
    opacity: 1;
  }
}

.video-frame-mode-field {
  margin-bottom: 12px;
}

.video-frame-mode-toggle {
  width: 100%;
}

.video-frame-mode-toggle .video-frame-mode-btn {
  flex: 1 1 0;
  justify-content: center;
  min-width: 0;
}

.video-frame-mode-btn .material-icons-outlined {
  flex: 0 0 auto;
  font-size: 18px;
}

.video-frame-mode-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.1;
}

.video-frame-mode-title {
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.video-frame-mode-hint {
  margin-top: 3px;
  color: var(--text-muted);
  font-size: 8.5px;
  font-weight: 500;
  white-space: nowrap;
}

.video-frame-mode-btn.active .video-frame-mode-hint {
  color: currentColor;
  opacity: 0.72;
}

#video-form.video-frame-batch #seedance2-ref-images-section,
#video-form.video-frame-batch #seedance2-ref-videos-section,
#video-form.video-frame-batch #seedance2-ref-audio-section,
#video-form.video-frame-batch #kling-v3-advanced-section {
  display: none !important;
}

#seedance2-ref-images-preview,
#seedance2-ref-videos-preview,
#seedance2-ref-audio-preview {
  display: grid !important;
  grid-template-columns: repeat(auto-fill, minmax(74px, 1fr));
  gap: 8px !important;
  width: 100%;
}

@media (min-width: 901px) {
  .history-content > .history {
    grid-auto-flow: row !important;
    align-items: stretch;
  }
}

@media (min-width: 1024px) {
  .history-section > .history-header {
    position: sticky;
    top: 0;
    z-index: 140;
    background: var(--bg);
    box-shadow: 0 1px 0 var(--line), 0 14px 28px var(--shadow-color-strong);
    backdrop-filter: none;
  }
}

@media (max-width: 900px) {
  .history-logo {
    display: none;
  }

  .history-section > .history-header {
    background: var(--bg);
    backdrop-filter: none;
  }

  .image-card .img-wrap {
    aspect-ratio: 4 / 3;
  }

  #video-form.tab-content.active > .row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin: 0 0 8px !important;
  }

  #video-form.tab-content.active > .row .field {
    min-width: 0;
  }

  #video-form.tab-content.active select,
  #video-form.tab-content.active .cdrop--video,
  #video-form.tab-content.active .audio-toggle-btn,
  #video-form.tab-content.active .duration-control {
    min-height: 42px;
    height: 42px;
    border-radius: 10px;
  }

  #video-form.tab-content.active .duration-control {
    padding: 0 4px;
  }

  #video-form.tab-content.active .duration-stepper {
    grid-template-columns: 30px minmax(38px, 1fr) 30px;
    width: 100%;
    min-width: 0;
    height: 100%;
    padding: 0;
  }

  #video-form.tab-content.active .duration-step-btn {
    width: 30px;
    height: 30px;
  }
}

/* Video cards should preview in a stable standard frame and never stretch in fullscreen. */
.image-card .video-wrap {
  aspect-ratio: 16 / 9;
  background: var(--media-bg);
}

.image-card .video-wrap > video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  background: var(--media-bg);
}

video:fullscreen,
video:-webkit-full-screen {
  width: 100vw !important;
  height: 100vh !important;
  max-width: 100vw !important;
  max-height: 100vh !important;
  object-fit: contain !important;
  background: #000 !important;
}

@media (max-width: 768px) {
  .header-logo {
    height: 18px;
  }
}

@media (max-width: 420px) {
  .header-logo {
    height: 14px;
  }
}

@media (min-width: 901px) {
  .history-section {
    padding-top: 54px;
  }

  .history-section > .history-header {
    position: fixed !important;
    top: 0 !important;
    left: calc(101px + 32px);
    right: 32px;
    z-index: 620;
    min-height: 46px;
    margin: 0;
    background: var(--bg);
    box-shadow: 0 1px 0 var(--line), 0 14px 28px var(--shadow-color-strong);
    backdrop-filter: none;
  }
}

@media (min-width: 1024px) and (max-width: 1280px) {
  .history-section > .history-header {
    left: calc(101px + 20px);
    right: 20px;
  }
}

@media (min-width: 901px) {
  .history-section {
    padding-top: 82px;
  }

  .history-section > .history-header {
    left: calc(101px + 24px);
    right: 24px;
    padding-top: 32px;
    padding-bottom: 10px;
    box-shadow: 0 18px 18px -18px var(--shadow-color-strong);
  }
}

@media (min-width: 1024px) and (max-width: 1280px) {
  .history-section > .history-header {
    left: calc(101px + 14px);
    right: 14px;
  }
}

@keyframes appShellIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes sidebarSoftIn {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes topBarSoftIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes genDockSoftIn {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes bottomDockPanelIn {
  from {
    opacity: 0;
    transform: translateX(calc(-50% - 48px)) translateY(24px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateX(calc(-50% - 48px)) translateY(0) scale(1);
  }
}

@keyframes historyItemSoftIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.app-content:not(.hidden) {
  animation: appShellIn 260ms ease-out both;
}

.app-sidebar:not(.hidden) {
  animation: sidebarSoftIn 320ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.history-section > .history-header {
  animation: topBarSoftIn 240ms ease-out both;
}

.history-item {
  animation: historyItemSoftIn 220ms ease-out both;
}

.tab-content.active.gen-shell {
  animation: genDockSoftIn 260ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@media (min-width: 1024px) {
  .app-content:not(.hidden) .card {
    animation: bottomDockPanelIn 460ms cubic-bezier(0.16, 1, 0.3, 1) 90ms both;
    will-change: transform, opacity;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-content:not(.hidden) .card,
  .tab-content.active.gen-shell {
    animation: none !important;
  }
}

.gallery,
#video-form.tab-content.active > .row,
.theme-settings {
  gap: var(--density-gap);
}

.history-item,
.image-card,
.card > .tab-content {
  padding: var(--density-panel-pad);
}

.vmodel-selected,
.cdrop,
.custom-select,
.audio-toggle-btn,
.duration-control {
  min-height: var(--density-control-height);
}

/* Theme coverage layer: keeps old component styles aligned with current tokens. */
html,
body,
.app-content {
  background: var(--bg);
  color: var(--text);
}

.card,
.profile-modal,
.login-card,
.history-item,
.app-sidebar,
.tabs,
.card > .tab-content,
.vmodel-list,
.cdrop-list,
.gen-queue-card,
.theme-settings {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
}

.image-card,
.stat-card,
.estimate-item,
.theme-control,
.theme-preset-btn,
.profile-balance-block,
.achievement,
.token-pack,
.audio-toggle-btn,
.batch-selector,
.pagination-btn,
.pagination-limit {
  background: var(--surface-raised);
  border-color: var(--line);
  color: var(--text);
}

textarea,
select,
input,
.cdrop,
.vmodel-selected,
.custom-select,
.model-select-trigger {
  background: var(--color-control);
  color: var(--text);
  border-color: transparent;
}

textarea::placeholder,
input::placeholder {
  color: var(--text-muted);
}

textarea:hover,
select:hover,
.cdrop:hover,
.vmodel-selected:hover,
.custom-select:hover,
.model-select-trigger:hover {
  background: var(--color-control-hover);
  border-color: var(--accent-border);
}

textarea:focus,
select:focus,
input:focus,
.cdrop.open,
.cdrop:focus-within,
.vmodel-selected.open,
.custom-select:focus,
.model-select-trigger.open {
  background: var(--color-control-hover);
  border-color: var(--accent);
  box-shadow: var(--shadow-accent-soft), 0 0 0 4px var(--focus-ring);
}

.cdrop-list,
.vmodel-list,
.model-select-dropdown {
  background: var(--surface);
  border-color: var(--accent-border);
  box-shadow: 0 18px 42px var(--shadow-color), 0 0 0 1px var(--accent-softer);
  scrollbar-color: var(--scrollbar-thumb) transparent;
}

.cdrop-item:hover,
.cdrop-item.active,
.vmodel-item:hover,
.vmodel-item.active,
.model-option:hover,
.model-option.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.vmodel-check,
.vmodel-item.active .vmodel-icon,
.vmodel-item.active .vmodel-name,
.cdrop-check,
.cdrop.open .cdrop-arrow,
.profile-balance-value,
.profile-balance-value .token-icon,
.balance-display,
.sidebar-balance,
.achievement.unlocked .material-icons-outlined {
  color: var(--accent);
}

.vmodel-badge,
.model-new-badge,
.plan-badge.ultra,
.gallery-cols-btn.active,
.batch-btn.active,
.batch-value,
.theme-preset-btn.active {
  background: var(--accent);
  color: var(--color-on-accent);
  border-color: var(--accent);
}

.balance-display,
.plan-badge.ultra,
.achievement.unlocked,
.profile-balance-block,
.sidebar-user:hover,
.sidebar-user:focus-visible {
  background: var(--accent-softer);
  border-color: var(--accent-border);
}

.tab:hover,
.tab.active,
.sidebar-nav-btn:hover,
.sidebar-nav-btn.active,
.gallery-cols-btn:hover,
.provider-btn.active,
.provider-btn:hover,
.batch-step-btn:hover:not(:disabled),
.pagination-btn:hover:not(:disabled),
.theme-preset-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent-border-strong);
  color: var(--accent);
}

#generate-btn,
#video-generate-btn,
.login-btn,
.save-settings-btn,
.buy-btn {
  background: var(--accent);
  color: var(--color-on-accent);
  border-color: var(--accent);
}

#generate-btn:hover,
#video-generate-btn:hover,
.login-btn:hover,
.save-settings-btn:hover,
.buy-btn:hover {
  box-shadow: 0 8px 24px rgba(var(--color-accent-rgb), 0.34);
}

.upload-zone,
.upload-zone-small,
.video-upload-zone,
.video-upload-zone-small {
  background: var(--surface-soft);
  border-color: var(--accent-border);
  color: var(--text-muted);
}

.upload-zone:hover,
.upload-zone.dragover,
.upload-zone-small:hover,
.video-upload-zone:hover,
.video-upload-zone.dragover,
.video-upload-zone-small:hover {
  background: var(--accent-softer);
  border-color: var(--accent);
  box-shadow: var(--shadow-accent-soft);
}

.upload-icon,
.upload-zone .material-icons-outlined,
.upload-zone-small .material-icons-outlined,
.video-upload-zone .material-icons-outlined,
.video-upload-zone-small .material-icons-outlined {
  color: var(--accent);
}

.image-card {
  background: var(--surface-raised);
  border-color: var(--line);
}

.image-card:hover {
  border-color: var(--accent-border-strong);
  box-shadow: 0 12px 26px var(--shadow-color-soft), 0 0 0 1px var(--accent-softer);
}

.image-card a,
.image-card button,
.image-card .remove-bg-btn,
.image-card .icon-btn,
.video-card a,
.video-card button {
  color: var(--accent);
  border-color: var(--accent-border);
}

.image-card a:hover,
.image-card button:hover,
.image-card .remove-bg-btn:hover:not(:disabled),
.image-card .icon-btn:hover,
.video-card a:hover,
.video-card button:hover {
  background: var(--accent);
  color: var(--color-on-accent);
  border-color: var(--accent);
}

.fav-btn,
.delete-overlay {
  background: var(--overlay-dark);
  color: var(--text);
}

.delete-overlay:hover {
  background: var(--danger);
  color: var(--color-on-danger);
}

.history-section > .history-header {
  background: var(--bg);
  border-color: var(--line);
  box-shadow: 0 18px 18px -18px var(--shadow-color-strong);
}

.profile-avatar {
  background: linear-gradient(135deg, var(--accent) 0%, var(--color-accent-hover) 100%);
  color: var(--color-on-accent);
}

.profile-modal-close:hover {
  background: var(--accent);
  color: var(--color-on-accent);
}

.param-badge,
.model-tag,
.vmodel-meta,
.prompt-preview,
.muted,
.history-count,
.history-meta {
  color: var(--text-muted);
}

@media (max-width: 900px) {
  #generate-form.gen-shell .image-provider-field,
  #generate-form.gen-shell .image-output-format-field {
    display: none !important;
  }

  #generate-form.gen-shell .upload-zone .upload-drop-area {
    gap: 10px;
  }

  #generate-form.gen-shell .upload-zone .upload-icon {
    margin-bottom: 2px;
  }

  #generate-form.gen-shell > .actions,
  #generate-form.gen-shell .actions {
    width: 100%;
  }

  #generate-form.gen-shell #generate-btn {
    width: 100%;
    min-width: 0;
  }
}

@media (max-width: 559px) {
  #generate-form.gen-shell .image-model-row {
    margin-bottom: 14px !important;
  }

  #generate-form.gen-shell .image-options-row {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 14px;
  }

  #generate-form.gen-shell .image-options-row .field {
    min-width: 0;
    margin-bottom: 0;
  }

  #generate-form.gen-shell .image-options-row .cdrop {
    width: 100%;
    min-width: 0;
  }

  #generate-form.gen-shell .image-options-row .cdrop-value {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #generate-form.gen-shell .image-options-row .cdrop-icon {
    flex: 0 0 20px;
    width: 20px;
    min-width: 20px;
  }
}

/* Tablet adaptive pass: the desktop sidebar starts at 1024px, so 901-1023px
   must not keep desktop header offsets or a second logo in history. */
@media (min-width: 901px) and (max-width: 1023px) {
  .history-logo {
    display: none !important;
  }

  .history-section {
    padding-top: 0;
  }

  .history-section > .history-header {
    position: sticky !important;
    top: env(safe-area-inset-top) !important;
    left: auto !important;
    right: auto !important;
    width: auto !important;
    min-height: 46px;
    padding: 12px 0 10px;
    margin: 0;
    background: var(--bg);
    box-shadow: 0 16px 16px -18px var(--shadow-color-strong);
  }
}

/* Mid-width generation layout: the full horizontal dock needs ~750px of inner
   width, so between mobile and tablet we switch to a two-column product grid. */
@media (min-width: 560px) and (max-width: 900px) {
  .card > #generate-form.gen-shell {
    padding: 0;
    overflow: visible;
  }

  #generate-form.gen-shell.tab-content.active {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: minmax(92px, min(24vh, var(--prompt-textarea-max-height))) minmax(92px, auto) 52px 52px 54px;
    grid-template-areas:
      "prompt prompt"
      "upload upload"
      "model model"
      "aspect resolution"
      "count actions";
    column-gap: 10px;
    row-gap: 10px;
    min-width: 0;
  }

  #generate-form.gen-shell.tab-content.active::before {
    display: none;
  }

  /* Unified prompt height on mobile — image was 112px, video used the base ~70-80px,
     which looked inconsistent when switching tabs. Both now share 92px. */
  #generate-form.gen-shell .textarea-wrapper textarea,
  #video-form.tab-content.active .textarea-wrapper textarea {
    min-height: 92px;
    max-height: var(--prompt-textarea-max-height);
    padding: 13px 44px 13px 14px;
    font-size: 14px;
  }

  #generate-form.gen-shell .textarea-wrapper textarea::placeholder,
  #video-form.tab-content.active .textarea-wrapper textarea::placeholder {
    font-size: 14px;
  }

  #generate-form.gen-shell .upload-zone {
    min-height: 92px;
  }

  #generate-form.gen-shell .vmodel-selected,
  #generate-form.gen-shell .cdrop,
  #generate-form.gen-shell > .batch-row,
  #generate-form.gen-shell #generate-btn {
    height: 52px;
    min-height: 52px;
    border-radius: 12px;
  }

  #generate-form.gen-shell .vmodel-selected {
    width: 100%;
  }

  #generate-form.gen-shell .vmodel-list,
  #generate-form.gen-shell .cdrop-list {
    top: auto;
    bottom: calc(100% + 8px);
    max-width: min(320px, calc(100vw - 24px));
  }

  #generate-form.gen-shell .cdrop {
    width: 100%;
    min-width: 0;
  }

  #generate-form.gen-shell .cdrop-value {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #generate-form.gen-shell > .actions {
    min-width: 0;
  }

  #generate-form.gen-shell #generate-btn {
    min-width: 0;
    padding: 0 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-content:not(.hidden),
  .app-sidebar:not(.hidden),
  .history-section > .history-header,
  .history-item,
  .tab-content.active.gen-shell {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
 * Кнопки действий на карточках истории — адаптивные.
 * Пока карточка достаточно широкая — кнопки с подписями
 * ("Убрать фон" / "Upscale" / "Повтор"). Когда подписи перестают
 * умещаться (узкие карточки в режиме 3–4 колонок), кнопки
 * сворачиваются в иконки (текст скрыт, остаётся tooltip через
 * title). Реализовано через container query по ширине карточки.
 * "Скачать" в видео-карточках — отдельный <a>, не задет.
 * ========================================================== */
.image-card {
  container-type: inline-size;
}

@container (max-width: 360px) {
  .image-card .buttons .remove-bg-btn {
    font-size: 0;
    gap: 0;
    padding-left: 0;
    padding-right: 0;
    width: 30px;
    min-width: 30px;
    max-width: 30px;
    flex: 0 0 auto;
    overflow: visible;
    justify-content: center;
  }
  .image-card .buttons .remove-bg-btn .btn-icon,
  .image-card .buttons .remove-bg-btn .material-icons-outlined {
    font-size: 18px;
    margin: 0;
  }
}

/* ============================================================
 * Раздел «Сервисы» — оверлей поверх контента. Использует общие
 * дизайн-токены: карточки как .card, кнопка как #generate-btn,
 * зона загрузки как .upload-zone, контролы — как нативные селекты.
 * ========================================================== */
/* Рендерится в контентной области (как .app-content), не как fixed-попап.
   Виден, когда активен таб «Сервисы»; при этом #app-content скрывается. */
.tools-screen {
  min-height: 100vh;
  background: var(--color-bg);
  padding: 22px clamp(16px, 2vw, 36px) 60px;
  /* opacity-only entrance: a translate here would create a transform containing
     block and break the sticky shared header during the animation. */
  animation: appShellIn 0.4s ease-out;
  /* Own stacking context so the moved .user-header (lifted to z 10033 while the
     mobile drawer is open) stays confined here — same as the main shell. Without
     it the header floated above the drawer and it looked like the menu slid out
     below the header. */
  position: relative;
  z-index: 0;
}
.tools-screen.hidden { display: none; }
.tools-screen > * { max-width: 1760px; margin-left: auto; margin-right: auto; }
@media (min-width: 1024px) {
  .tools-screen { padding-left: 101px; }
}
.tools-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 22px;
}
.tools-head.history-header {
  margin-bottom: 22px;
  min-height: 46px;
  padding: 8px 0;
  border-top: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
}
/* The bespoke topbar is replaced at runtime by the shared .user-header
   (moved in via openToolsScreen), so the static logo-only bar is hidden. */
.tools-topbar { display: none; }
.tools-screen > .user-header { margin-bottom: 18px; }
.tools-head .tools-close { margin-left: auto; }
.tools-title {
  font-family: 'Manrope', sans-serif; font-size: 22px; font-weight: 800;
  letter-spacing: 0; color: var(--color-text);
  display: flex; align-items: center; gap: 10px;
}
.tools-new-badge {
  flex-shrink: 0;
  font-size: 9px;
  text-transform: uppercase;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  letter-spacing: 0.5px;
  line-height: 14px;
  transform: skewX(-8deg);
}
.tools-close {
  width: 38px; height: 38px; border-radius: var(--radius-md);
  border: 1px solid var(--line); background: var(--color-control);
  color: var(--color-text); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.tools-close:hover { background: var(--color-control-hover); border-color: var(--line-strong); }
.tools-grid {
  position: relative; z-index: 2; overflow: visible;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px; margin-bottom: 28px;
}
.tools-card {
  position: relative; z-index: 0; overflow: visible;
  background: var(--color-panel-soft);
  backdrop-filter: blur(20px);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-panel);
  padding: 20px;
  display: flex; flex-direction: column; gap: 12px;
}
.tools-card:has(.cdrop.open) { z-index: 1000; }
.tools-card-title {
  font-family: 'Manrope', sans-serif; font-size: 14px; font-weight: 700;
  color: var(--color-text); display: flex; align-items: center; gap: 8px;
}
.tools-card-title .material-icons-outlined { font-size: 17px; color: var(--accent); }
.tools-cost {
  margin-left: auto; display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 700;
  color: var(--color-text-muted); background: var(--surface-soft);
  border: 1px solid var(--line); border-radius: var(--radius-pill); padding: 3px 9px 3px 7px;
}
.tools-cost:empty { display: none; }
.tools-cost-icon { width: 12px; height: 12px; color: var(--accent); flex-shrink: 0; }
.tools-card-desc {
  font-size: 10px; color: var(--color-text-muted); margin: -3px 0 2px;
  line-height: 1.25; min-height: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* Dropzone reuses .upload-zone / .upload-zone-small look; only minor tweaks. */
.tools-drop {
  min-height: 118px; padding: 14px 16px; gap: 6px;
  border-radius: var(--radius-md); overflow: visible;
}
.tools-drop .upload-icon { display: flex; align-items: center; justify-content: center; }
.tools-drop .upload-icon,
.tools-drop .upload-icon .material-icons-outlined {
  width: 26px; height: 26px; margin: 0; font-size: 26px;
}
.tools-drop .upload-text {
  font-size: 12px; font-weight: 700; line-height: 1.2;
  margin: 0; text-transform: none; letter-spacing: 0;
}
.tools-drop .tools-preview {
  width: 100%; max-width: 100%; margin-top: 10px;
  display: flex; align-items: center; justify-content: center;
}
.tools-drop .tools-preview:empty { display: none; }
/* Override global ".preview img { width:100% }" which, combined with a max-height,
   squishes the preview. Keep aspect ratio inside the dropzone. */
.tools-drop .tools-preview img {
  width: auto; height: auto; max-width: 100%; max-height: 180px;
  object-fit: contain; object-position: center; border: 0; box-shadow: none;
  border-radius: var(--radius-sm);
}
.tools-drop .tools-preview img:hover { transform: none; box-shadow: none; }
.tools-drop.has-files .upload-icon,
.tools-drop.has-files .upload-text { display: none; }
.tools-card[data-batch-max] .tools-drop.has-files {
  min-height: 118px;
  height: 118px;
  padding: 10px 12px;
  align-items: center;
  overflow: hidden;
}
.tools-card[data-batch-max] .tools-drop .tools-preview {
  margin-top: 0;
  flex-direction: column;
  gap: 7px;
}
.tools-drop.is-running { pointer-events: none; opacity: 0.72; }
.tools-batch-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-width: 0;
}
.tools-batch-thumb,
.tools-batch-more {
  position: relative;
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--media-bg);
  overflow: hidden;
}
.tools-batch-thumb img {
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  max-height: none !important;
  margin: 0 !important;
  border-radius: 0 !important;
  object-fit: cover !important;
}
.tools-batch-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 16px;
  height: 16px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  background: var(--color-panel);
  color: var(--color-text);
  display: grid;
  place-items: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease;
}
.tools-batch-thumb:hover .tools-batch-remove,
.tools-batch-remove:focus-visible { opacity: 1; }
.tools-batch-remove:hover { background: var(--color-control-hover); }
.tools-batch-remove .material-icons-outlined { width: auto !important; height: auto !important; font-size: 11px !important; }
.tools-batch-more {
  display: grid;
  place-items: center;
  color: var(--color-text-muted);
  font-size: 11px;
  font-weight: 700;
}
.tools-batch-summary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--color-text-muted);
  font-size: 10px;
  font-weight: 700;
  line-height: 18px;
}
.tools-batch-clear {
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-muted);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.tools-batch-clear:hover { color: var(--color-text); background: var(--color-control-hover); }
.tools-batch-clear .material-icons-outlined { width: auto !important; height: auto !important; font-size: 14px !important; }
.tools-aud-name { font-size: 13px; color: var(--color-text); font-weight: 600; word-break: break-word; }
.tools-select {
  width: 100%;
  background: var(--color-control); border: 1px solid var(--line);
  border-radius: var(--radius-md); color: var(--color-text);
  padding: 12px 14px; font-size: 14px; font-family: 'Manrope', sans-serif; outline: none;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.tools-select:focus { border-color: var(--accent-border); background: var(--color-control-hover); }
/* Calm secondary look (5 cards on screen — avoid a wall of bright buttons).
   Fills with accent only on hover / when ready. */
.tools-run {
  background: transparent; color: var(--color-text);
  font-family: 'Manrope', sans-serif; font-size: 14px; font-weight: 600;
  border: 1px solid var(--line-strong); border-radius: var(--radius-md);
  height: 46px; min-height: 46px; max-height: 46px;
  padding: 0 20px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  white-space: nowrap; overflow: hidden;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
.tools-run:not(:disabled):hover { background: var(--accent); color: var(--color-on-accent); border-color: var(--accent); }
.tools-run:disabled { opacity: 0.45; cursor: not-allowed; }

.tools-params {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  gap: 12px; width: 100%;
}
.tools-param {
  display: flex; flex-direction: column; gap: 5px;
  font-size: 10px; color: var(--color-text-muted); font-weight: 700;
  letter-spacing: 0; margin: 0; text-transform: none; min-width: 0;
}
.tools-param .tools-select { padding: 8px 10px; font-size: 13px; }
.tools-param .cdrop--tools {
  position: relative; z-index: 1;
  height: 34px; min-width: 0; width: 100%;
  border-width: 1px; padding: 0 9px 0 10px; gap: 7px;
}
.tools-param .cdrop--tools.open { z-index: 1001; }
.tools-param .cdrop--tools .cdrop-icon,
.tools-param .cdrop--tools .cdrop-arrow { font-size: 16px; }
.tools-param .cdrop--tools .cdrop-value { font-size: 12px; font-weight: 700; }
.tools-param .cdrop--tools .cdrop-list {
  top: calc(100% + 6px); bottom: auto; z-index: 1002;
  width: 100%; min-width: 100%; max-width: 220px; max-height: 190px;
  border-radius: var(--radius-md);
}
.tools-param .cdrop--tools.drop-up .cdrop-list {
  top: auto;
  bottom: calc(100% + 6px);
}
.tools-param .cdrop--tools.open .cdrop-list { display: flex; }
.tools-param .cdrop--tools .cdrop-item {
  min-height: 30px; padding: 7px 9px; font-size: 12px; border-radius: var(--radius-sm);
}
.tools-tts-copy { min-height: 0; }
.tools-tts-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tools-tts-count { color: var(--color-text-muted); font-weight: 500; white-space: nowrap; }
.tools-tts-text {
  width: 100%; min-height: 118px; max-height: 180px; resize: vertical;
  padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-md);
  background: var(--color-control); color: var(--color-text);
  font: 500 13px/1.45 'Manrope', sans-serif; outline: none;
  scrollbar-width: thin; scrollbar-color: var(--scrollbar-thumb) transparent;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.tools-tts-text:hover { background: var(--color-control-hover); border-color: var(--line-strong); }
.tools-tts-text:focus {
  background: var(--color-control-hover); border-color: var(--color-accent);
  box-shadow: var(--shadow-accent-soft), 0 0 0 4px var(--focus-ring);
}
.tools-tts-text::placeholder { color: var(--color-text-muted); opacity: 0.72; }
.tools-tts-text::-webkit-scrollbar { width: 4px; }
.tools-tts-text::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 4px; }
.tools-result { font-size: 13px; color: var(--color-text-muted); }
.tools-result img { max-width: 100%; max-height: 360px; object-fit: contain; border-radius: var(--radius-md); margin-top: 8px; background: var(--media-bg); }
.tools-audio-result { width: 100%; }
.tools-audio-result audio { display: block; width: 100%; height: 38px; accent-color: var(--accent); }
.tools-audio-result .tools-result-actions { justify-content: flex-start; }
.tools-batch-status { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.tools-batch-status-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  color: var(--color-text-muted);
}
.tools-batch-status-line > :first-child { color: var(--color-text); font-weight: 700; }
.tools-batch-progress {
  width: 100%;
  height: 3px;
  border-radius: var(--radius-pill);
  background: var(--line);
  overflow: hidden;
}
.tools-batch-progress > span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.25s ease;
}
.tools-result-text {
  background: var(--color-control); border: 1px solid var(--line);
  border-radius: var(--radius-md); padding: 14px; color: var(--color-text);
  font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-break: break-word;
  max-height: 260px; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: var(--scrollbar-thumb) transparent;
}
/* Unified thin scrollbar (matches .cdrop-list / prompt areas) across the section */
.tools-screen, .tools-result, .tools-history {
  scrollbar-width: thin; scrollbar-color: var(--scrollbar-thumb) transparent;
}
.tools-screen::-webkit-scrollbar,
.tools-result-text::-webkit-scrollbar,
.tools-result::-webkit-scrollbar,
.tools-history::-webkit-scrollbar { width: 4px; height: 4px; }
.tools-screen::-webkit-scrollbar-thumb,
.tools-result-text::-webkit-scrollbar-thumb,
.tools-result::-webkit-scrollbar-thumb,
.tools-history::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 4px; }
.tools-screen::-webkit-scrollbar-track,
.tools-result-text::-webkit-scrollbar-track,
.tools-result::-webkit-scrollbar-track,
.tools-history::-webkit-scrollbar-track { background: transparent; }
.tools-result-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.tools-mini-btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: 'Manrope', sans-serif; font-size: 12px; font-weight: 600;
  background: var(--color-control); border: 1px solid var(--line);
  border-radius: var(--radius-sm); color: var(--color-text);
  padding: 8px 12px; cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.tools-mini-btn:hover { background: var(--color-control-hover); border-color: var(--accent-border); }
.tools-mini-btn .material-icons-outlined { font-size: 15px; }

/* ===== Meeting analysis (tabs / tasks / minutes) ===== */
.meeting-root { width: 100%; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; align-self: stretch; }
.meeting-tabs { flex: 0 0 auto; display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.meeting-tab {
  font-family: 'Manrope', sans-serif; font-size: 13px; font-weight: 600;
  background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--color-text-muted, #888); padding: 8px 14px; cursor: pointer; margin-bottom: -1px;
  transition: color 0.2s ease, border-color 0.2s ease;
}
.meeting-tab:hover { color: var(--color-text); }
.meeting-tab.active { color: var(--color-text); border-bottom-color: var(--accent-border, currentColor); }
/* Single scroll container — fills available height; inner blocks must NOT cap height,
   otherwise content overflows the centered modal body and becomes unreachable. */
.meeting-content {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; padding-right: 4px;
  scrollbar-width: thin; scrollbar-color: var(--scrollbar-thumb) transparent;
}
.meeting-content::-webkit-scrollbar { width: 4px; }
.meeting-content::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 4px; }
.tools-result-modal-body .meeting-content .tools-result-text { max-height: none; overflow: visible; width: 100%; }
.tools-result-modal-body .meeting-content .meeting-tasks-list { max-height: none; overflow: visible; }
.meeting-actions-dock {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  border-top: 1px solid var(--line);
  margin-top: 10px;
  padding: 10px 4px 0;
  background: var(--surface);
}
.meeting-actions-dock[hidden] { display: none; }
.meeting-actions-dock .tools-result-actions {
  margin-top: 0;
  justify-content: center;
}
.meeting-gen { margin: 8px auto; display: flex; }
.meeting-empty { color: var(--color-text-muted, #888); font-size: 13px; padding: 16px; text-align: center; }
.meeting-auto-status { margin-top: 8px; font-size: 12px; color: var(--color-text-muted, #888); }
.meeting-brand-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}
.meeting-org-select {
  height: 32px;
  min-width: 140px;
  max-width: 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--color-control);
  color: var(--color-text);
  font: inherit;
  font-size: 12px;
  padding: 0 28px 0 10px;
}
.meeting-brand-color {
  width: 32px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--color-control);
}
.meeting-pdf-transcript {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--color-text-muted, #888);
  font-size: 12px;
  white-space: nowrap;
}
.meeting-pdf-transcript input { margin: 0; }
.meeting-tasks-list { display: flex; flex-direction: column; gap: 8px; }
.meeting-task {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--color-control); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 10px 12px;
}
.meeting-task-pri { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; background: #9aa0a6; }
.meeting-task-pri.pri-high { background: #e5484d; }
.meeting-task-pri.pri-medium { background: #f5a623; }
.meeting-task-pri.pri-low { background: #30a46c; }
.meeting-task-body { flex: 1 1 auto; min-width: 0; }
.meeting-task-text { font-size: 14px; color: var(--color-text); line-height: 1.4; }
.meeting-task-meta { font-size: 12px; color: var(--color-text-muted, #888); margin-top: 3px; }
.meeting-minutes { white-space: normal; }
.meeting-minutes h4 { font-size: 14px; font-weight: 700; margin: 14px 0 6px; color: var(--color-text); }
.meeting-minutes h4:first-child { margin-top: 0; }
.meeting-minutes p { margin: 6px 0; }
.meeting-minutes ul { margin: 6px 0; padding-left: 20px; }
.meeting-minutes li { margin: 3px 0; }
@keyframes mtg-spin { to { transform: rotate(360deg); } }
.material-icons-outlined.spin { animation: mtg-spin 0.9s linear infinite; }
.tools-history { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 14px; margin-top: 14px; }
.tools-history-section {
  margin-top: 28px;
  padding-top: 0 !important;
}
.tools-history-section > .history-header {
  position: relative !important;
  top: auto !important;
  left: auto !important;
  right: auto !important;
  width: auto !important;
  z-index: auto;
  margin: 0;
  min-height: 46px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: transparent;
  backdrop-filter: none;
  box-shadow: none;
}
.tools-history-item {
  background: var(--color-panel-soft); border: 1px solid var(--line);
  border-radius: var(--radius-md); padding: 8px; font-size: 11px; color: var(--color-text-muted);
  cursor: pointer; transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}
.tools-history-item:hover { border-color: var(--accent-border); background: var(--color-control-hover); transform: translateY(-1px); }
.tools-history-item img { width: 100%; aspect-ratio: 1; object-fit: contain; border-radius: var(--radius-sm); margin-bottom: 6px; background: var(--media-bg); }
.tools-history-text { min-height: 60px; max-height: 90px; overflow: hidden; color: var(--color-text); }
.tools-history-audio-icon {
  display: flex; align-items: center; justify-content: center; width: 100%; aspect-ratio: 1;
  margin-bottom: 6px; border-radius: var(--radius-sm); background: var(--media-bg); color: var(--accent);
}
.tools-history-audio-icon .material-icons-outlined { font-size: 34px; }
.tools-history-audio-title {
  min-height: 30px; max-height: 44px; margin-bottom: 4px; overflow: hidden;
  color: var(--color-text); line-height: 1.35;
}

.tools-result-modal.hidden { display: none; }
.tools-result-modal {
  position: fixed; inset: 0; z-index: 10020;
  display: flex; align-items: center; justify-content: center;
  padding: 24px; background: rgba(0,0,0,0.78); backdrop-filter: blur(16px);
}
.tools-result-modal-card {
  position: relative; width: min(960px, calc(100vw - 48px)); height: min(88vh, 820px);
  max-height: min(88vh, 820px);
  display: flex; flex-direction: column; align-items: stretch;
  padding: 22px; border: 1px solid var(--line-strong); border-radius: var(--radius-xl);
  background: var(--surface); box-shadow: var(--shadow-panel); overflow: hidden;
}
.tools-result-modal-body {
  flex: 1 1 auto; min-height: 0; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 8px 48px 46px;
}
.tools-result-modal-body .tools-result-text { width: 100%; max-height: calc(88vh - 210px); }
.tools-result-modal-body > img {
  flex: 1 1 auto; min-height: 0;
  width: auto; height: auto; max-width: 100%; max-height: calc(100% - 48px);
  object-fit: contain;
}
.tools-result-modal-body .tools-result-actions { flex: 0 0 auto; justify-content: center; margin-top: 10px; }
.tools-result-modal-body.tools-audio-result { width: min(620px, 100%); margin: 0 auto; }
.tools-result-modal-body.tools-audio-result audio { height: 44px; }
.tools-result-modal-card.meeting-modal-card {
  width: min(1120px, calc(100vw - 48px));
  height: auto;
  min-height: min(560px, calc(100vh - 48px));
  max-height: min(92vh, 900px);
}
.tools-result-modal-card.meeting-modal-card .tools-result-modal-body {
  align-items: stretch;
  justify-content: flex-start;
  max-height: calc(92vh - 44px);
  padding: 8px 56px 46px;
}
.tools-result-modal-close,
.tools-result-modal-nav {
  position: absolute; display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--line-strong); background: var(--color-control);
  color: var(--color-text); cursor: pointer; transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}
.tools-result-modal-close {
  top: 14px; right: 14px; width: 38px; height: 38px; border-radius: var(--radius-pill);
}
.tools-result-modal-nav {
  top: 50%; transform: translateY(-50%); width: 42px; height: 42px; border-radius: var(--radius-pill); z-index: 1;
}
.tools-result-modal-prev { left: 14px; }
.tools-result-modal-next { right: 14px; }
.tools-result-modal-close:hover,
.tools-result-modal-nav:hover:not(:disabled) { background: var(--color-control-hover); border-color: var(--accent-border); color: var(--accent); }
.tools-result-modal-nav:disabled { opacity: 0.25; cursor: default; }
.tools-result-modal-info {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  max-width: calc(100% - 48px); padding: 5px 12px; border-radius: var(--radius-pill);
  background: var(--color-control); color: var(--color-text-muted);
  font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

@media (max-width: 640px) {
  .tools-result-modal { padding: 12px; }
  .tools-result-modal-card { width: 100%; height: min(92vh, 720px); max-height: 92vh; padding: 16px; }
  .tools-result-modal-body { padding: 44px 6px 58px; min-height: 0; }
  .tools-result-modal-card.meeting-modal-card {
    width: 100%;
    height: auto;
    min-height: min(520px, calc(100vh - 24px));
    max-height: 94vh;
  }
  .tools-result-modal-card.meeting-modal-card .tools-result-modal-body {
    max-height: calc(94vh - 32px);
    padding: 44px 8px 58px;
  }
  .tools-result-modal-nav { top: auto; bottom: 12px; transform: none; width: 38px; height: 38px; }
  .tools-result-modal-prev { left: 16px; }
  .tools-result-modal-next { right: 16px; }
  .tools-result-modal-info { bottom: 18px; max-width: calc(100% - 128px); }

  /* Compact Services layout on phones — 2-column grid so all cards fit one screen */
  .tools-screen { padding: max(10px, env(safe-area-inset-top)) 10px 32px; }
  .tools-screen > .user-header { margin-bottom: 8px; }
  .tools-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: minmax(255px, auto);
    gap: 8px;
    margin-bottom: 14px;
    align-items: stretch;
  }
  .tools-card {
    height: 100%;
    min-height: 255px;
    padding: 10px;
    gap: 6px;
    border-radius: var(--radius-lg);
  }
  .tools-card-title { min-width: 0; font-size: 11px; line-height: 1.2; gap: 4px; white-space: nowrap; }
  .tools-card-title .material-icons-outlined { font-size: 15px; }
  .tools-cost { flex-shrink: 0; gap: 2px; padding: 2px 5px 2px 4px; font-size: 9px; }
  .tools-cost-icon { width: 10px; height: 10px; }
  .tools-card-desc { display: none; } /* hide one-line desc to save vertical space */
  .tools-drop { flex: 0 0 70px; min-height: 70px; height: 70px; padding: 8px; gap: 3px; }
  .tools-drop .upload-icon,
  .tools-drop .upload-icon .material-icons-outlined { width: 18px; height: 18px; font-size: 18px; }
  .tools-drop .upload-text { font-size: 10px; }
  .tools-drop .tools-preview img { max-height: 96px; }
  .tools-card[data-batch-max] .tools-drop.has-files {
    min-height: 70px;
    height: 70px;
    padding: 5px 6px;
  }
  .tools-card[data-batch-max] .tools-drop .tools-preview { gap: 3px; }
  .tools-batch-preview { gap: 3px; }
  .tools-batch-thumb,
  .tools-batch-more { flex-basis: 26px; width: 26px; height: 26px; }
  .tools-batch-remove { width: 14px; height: 14px; opacity: 1; }
  .tools-batch-summary { font-size: 9px; line-height: 14px; }
  .tools-batch-clear { width: 16px; height: 16px; }
  .tools-batch-status-line { font-size: 10px; }
  .tools-run { margin-top: auto; height: 36px; min-height: 36px; max-height: 36px; font-size: 13px; padding: 0 10px; }
  .tools-params { height: 45px; min-height: 45px; gap: 6px; flex: 0 0 45px; }
  .tools-param .tools-select { padding: 6px 8px; font-size: 12px; }
  .tools-param .cdrop--tools { height: 30px; }
  .tools-tts-text { min-height: 70px; height: 70px; max-height: 96px; padding: 8px; font-size: 11px; resize: none; }
  .tools-tts-copy { flex: 0 0 88px; height: 88px; }
  .tools-tts-label { font-size: 9px; }
  .tools-tts-count { font-size: 8px; }
  #text-to-speech-card .tools-result:not(:empty) { margin-top: 2px; }
  #text-to-speech-card .tools-audio-result audio { height: 32px; }
  #text-to-speech-card .tools-result-actions { margin-top: 5px; }
  #text-to-speech-card .tools-mini-btn { min-height: 30px; height: 30px; font-size: 10px; }
  .meeting-rec-compat { max-height: 52px; overflow: hidden; }
  .meeting-rec-idle { margin-top: auto; gap: 8px; }
  .tools-card .tools-mini-btn { min-height: 36px; justify-content: center; padding: 0 10px; }
  .tools-history-section { margin-top: 14px; }
  .tools-history { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
}

/* ==================== MEETING RECORDER (admin-only card) ==================== */
.meeting-rec-compat {
  font-size: 11px; color: var(--color-text-muted, #888);
  line-height: 1.35; margin: 2px 0 4px;
}
.meeting-rec-idle { display: flex; flex-direction: column; gap: 8px; }
.meeting-rec-start .material-icons-outlined { font-size: 16px; color: #e5484d; }
.meeting-rec-mic { justify-content: center; }
.meeting-rec-live { display: flex; flex-direction: column; gap: 10px; }
.meeting-rec-live.hidden { display: none; }
.meeting-rec-status {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 700; color: var(--color-text);
}
.meeting-rec-dot {
  width: 10px; height: 10px; border-radius: 50%; background: #e5484d;
  animation: meeting-rec-pulse 1.2s ease-in-out infinite;
}
@keyframes meeting-rec-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }
.meeting-rec-source {
  font-weight: 500; font-size: 11px; color: var(--color-text-muted, #888);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.meeting-rec-levels { display: flex; flex-direction: column; gap: 6px; }
.meeting-rec-level { display: flex; align-items: center; gap: 8px; }
.meeting-rec-level > span { flex: 0 0 64px; font-size: 11px; color: var(--color-text-muted, #888); }
.meeting-rec-bar {
  flex: 1; height: 6px; border-radius: 3px; overflow: hidden;
  background: var(--color-control); border: 1px solid var(--line);
}
.meeting-rec-bar > div {
  height: 100%; width: 0; border-radius: 3px;
  background: #30a46c; transition: width 0.1s linear;
}
.meeting-rec-warn {
  font-size: 11px; line-height: 1.35; color: #b54708;
  background: rgba(247, 144, 9, 0.08); border: 1px solid rgba(247, 144, 9, 0.35);
  border-radius: var(--radius-sm); padding: 8px 10px;
}
.meeting-rec-warn.hidden { display: none; }
.meeting-rec-stop .material-icons-outlined { font-size: 16px; }

/* Meeting card: task source quote */
.meeting-task-quote {
  font-size: 11px; font-style: italic; color: var(--color-text-muted, #888);
  margin-top: 4px; padding-left: 8px; border-left: 2px solid var(--line);
}

/* Meeting card: structured context */
.meeting-ctx { white-space: normal; }
.meeting-ctx-head { font-size: 15px; font-weight: 700; margin-bottom: 10px; color: var(--color-text); }
.meeting-ctx-block { margin-bottom: 12px; }
.meeting-ctx-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--color-text-muted, #888); margin-bottom: 4px;
}
.meeting-ctx-block p { margin: 0; }
.meeting-ctx-block ul { margin: 0; padding-left: 18px; }
.meeting-ctx-block li { margin: 2px 0; }

/* Meeting card: participants (SPEAKER_XX -> name) */
.meeting-parts-list { display: flex; flex-direction: column; gap: 8px; }
.meeting-part {
  display: flex; align-items: center; gap: 10px;
  background: var(--color-control); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 8px 10px;
}
.meeting-part-label {
  flex: 0 0 auto; font-size: 11px; font-weight: 700;
  color: var(--color-text-muted, #888); min-width: 92px;
}
.meeting-part-name {
  flex: 1; min-width: 0; height: 30px; padding: 0 10px;
  font-family: 'Manrope', sans-serif; font-size: 13px;
  color: var(--color-text); background: var(--color-bg);
  border: 1px solid var(--line); border-radius: var(--radius-sm); outline: none;
}
.meeting-part-name:focus { border-color: var(--accent-border, #888); }
.meeting-part-role { flex: 0 0 auto; font-size: 11px; color: var(--color-text-muted, #888); }

/* ==================== KLING 3.0 ADVANCED (multi-shot + elements) ==================== */
.kv3-body { display: flex; flex-direction: column; gap: 12px; padding-top: 12px; }

/* Toggle-переключатель в стиле компактных контролов */
.kv3-toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.kv3-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.kv3-toggle-track {
  flex: 0 0 auto; width: 34px; height: 20px; border-radius: 10px;
  background: var(--surface-soft); border: 1px solid var(--line);
  position: relative; transition: background 0.15s ease, border-color 0.15s ease;
}
.kv3-toggle-thumb {
  position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--color-text-muted, #888); transition: transform 0.15s ease, background 0.15s ease;
}
.kv3-toggle input:checked + .kv3-toggle-track { background: var(--color-accent, #6c5ce7); border-color: transparent; }
.kv3-toggle input:checked + .kv3-toggle-track .kv3-toggle-thumb { transform: translateX(14px); background: #fff; }
.kv3-toggle-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.kv3-toggle-title { font-size: 13px; font-weight: 700; color: var(--color-text); line-height: 1.2; }
.kv3-toggle-hint { font-size: 11px; color: var(--color-text-muted, #888); line-height: 1.25; }

/* Блоки секций */
.kv3-block { display: flex; flex-direction: column; gap: 8px; }
.kv3-block-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-text-muted, #888); }
.kv3-block-hint { font-size: 11px; color: var(--color-text-muted, #888); line-height: 1.35; }
.kv3-block-hint code {
  font-size: 10px; padding: 1px 4px; border-radius: 4px;
  background: var(--surface-soft); border: 1px solid var(--line);
}
.kv3-list { display: flex; flex-direction: column; gap: 8px; }
.kv3-list:empty { display: none; }

/* Карточка сцены */
.kv3-shot {
  background: var(--surface-soft); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 8px 10px;
  display: flex; flex-direction: column; gap: 6px;
}
.kv3-shot-head { display: flex; align-items: center; gap: 8px; }
.kv3-shot-num { font-size: 11px; font-weight: 700; color: var(--color-text-muted, #888); text-transform: uppercase; letter-spacing: 0.04em; }
.kv3-dur { margin-left: auto; display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--color-text-muted, #888); }
.kv3-dur-input {
  width: 44px; height: 24px; padding: 0 6px; text-align: center;
  font-family: 'Manrope', sans-serif; font-size: 12px; color: var(--color-text);
  background: var(--color-control); border: 1px solid var(--line); border-radius: 6px; outline: none;
  -moz-appearance: textfield;
}
.kv3-dur-input::-webkit-outer-spin-button, .kv3-dur-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.kv3-textarea {
  width: 100%; resize: vertical; min-height: 40px; padding: 6px 8px;
  font-family: 'Manrope', sans-serif; font-size: 13px; line-height: 1.35; color: var(--color-text);
  background: var(--color-control); border: 1px solid var(--line); border-radius: 6px; outline: none;
  scrollbar-width: thin;
}
.kv3-textarea:focus, .kv3-input:focus, .kv3-dur-input:focus { border-color: var(--color-accent, #888); }
.kv3-textarea::placeholder, .kv3-input::placeholder { color: var(--color-text-muted, #777); opacity: 0.7; }

/* Карточка element */
.kv3-element {
  background: var(--surface-soft); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 8px 10px;
  display: flex; flex-direction: column; gap: 6px;
}
.kv3-el-head { display: flex; align-items: center; gap: 6px; }
.kv3-el-at { font-size: 13px; font-weight: 700; color: var(--color-accent, #888); }
.kv3-input {
  flex: 1; min-width: 0; height: 28px; padding: 0 8px;
  font-family: 'Manrope', sans-serif; font-size: 12px; color: var(--color-text);
  background: var(--color-control); border: 1px solid var(--line); border-radius: 6px; outline: none;
}
.kv3-el-previews { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.kv3-el-previews:empty { display: none; }
.kv3-el-thumb { position: relative; width: 48px; height: 48px; }
.kv3-el-thumb img {
  width: 100%; height: 100%; object-fit: cover;
  border-radius: 6px; border: 1px solid var(--line); background: var(--color-control);
}
.kv3-el-thumb-remove {
  position: absolute; top: -5px; right: -5px; width: 16px; height: 16px;
  border-radius: 50%; border: none; cursor: pointer;
  background: var(--color-control); color: var(--color-text-muted, #888);
  border: 1px solid var(--line); font-size: 10px; line-height: 1; padding: 0;
  display: flex; align-items: center; justify-content: center;
}
.kv3-el-thumb-remove:hover { color: #e5484d; border-color: #e5484d; }
.kv3-el-add-img {
  width: 48px; height: 48px; border-radius: 6px; cursor: pointer;
  border: 1px dashed var(--line); background: transparent; color: var(--color-text-muted, #888);
  display: flex; align-items: center; justify-content: center; transition: color 0.15s ease, border-color 0.15s ease;
}
.kv3-el-add-img:hover { color: var(--color-text); border-color: var(--color-text-muted, #888); }
.kv3-el-add-img .material-icons-outlined { font-size: 18px; }

/* Кнопки добавления */
.kv3-add {
  align-self: flex-start; display: inline-flex; align-items: center; gap: 4px;
  height: 28px; padding: 0 10px; cursor: pointer;
  font-family: 'Manrope', sans-serif; font-size: 12px; font-weight: 600; color: var(--color-text-muted, #888);
  background: transparent; border: 1px dashed var(--line); border-radius: 6px;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.kv3-add:hover { color: var(--color-text); border-color: var(--color-text-muted, #888); }
.kv3-add .material-icons-outlined { font-size: 14px; }

/* Кнопка удаления (ghost) */
.kv3-remove {
  flex: 0 0 auto; width: 24px; height: 24px; padding: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: 6px; color: var(--color-text-muted, #888);
  transition: color 0.15s ease, background 0.15s ease;
}
.kv3-remove:hover { color: #e5484d; background: var(--surface-soft); }
.kv3-remove .material-icons-outlined { font-size: 16px; }

/* Внутри label-переключателя наследуется uppercase от form-лейблов — возвращаем обычный текст */
.kv3-toggle-title, .kv3-toggle-hint, .kv3-block-hint,
.kv3-textarea, .kv3-input, .kv3-dur, .kv3-add {
  text-transform: none;
  letter-spacing: normal;
}

/* ==================== TASKS SECTION ==================== */
.tasks-wrap { max-width: 860px; margin: 0 auto; padding: 8px 16px 48px; width: 100%; }
.tasks-toolbar { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.tasks-add-row { display: flex; gap: 8px; }
.tasks-quick-input {
  flex: 1; min-width: 0; height: 38px; padding: 0 14px;
  font-family: 'Manrope', sans-serif; font-size: 14px; color: var(--color-text);
  background: var(--color-control); border: 1px solid var(--line);
  border-radius: var(--radius-md); outline: none;
}
.tasks-quick-input:focus { border-color: var(--accent-border, #888); }
.tasks-quick-input::placeholder { color: var(--color-text-muted, #777); opacity: 0.7; }
.tasks-filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tasks-filter-btn {
  height: 30px; padding: 0 14px; cursor: pointer;
  font-family: 'Manrope', sans-serif; font-size: 12px; font-weight: 600;
  color: var(--color-text-muted, #888); background: var(--color-control);
  border: 1px solid var(--line); border-radius: 15px;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.tasks-filter-btn:hover { color: var(--color-text); }
.tasks-filter-btn.active { color: var(--color-text); border-color: var(--accent-border, currentColor); }
.tasks-assignee-filter { margin-left: auto; }

.tasks-sections { display: flex; flex-direction: column; gap: 14px; }
.tasks-section-head {
  display: flex; align-items: center; gap: 8px; width: 100%;
  background: none; border: none; cursor: pointer; padding: 4px 0;
  font-family: 'Manrope', sans-serif; font-size: 13px; font-weight: 700; color: var(--color-text);
}
.tasks-section-arrow { font-size: 20px; color: var(--color-text-muted, #888); transition: transform 0.15s ease; }
.tasks-section.collapsed .tasks-section-arrow { transform: rotate(-90deg); }
.tasks-section.collapsed .tasks-section-body { display: none; }
.tasks-section-body { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.tasks-empty { color: var(--color-text-muted, #888); font-size: 12px; padding: 8px 12px; }

.task-row {
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  background: var(--color-control); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 9px 12px;
  transition: border-color 0.15s ease;
}
.task-row:hover { border-color: var(--color-text-muted, #666); }
.task-row.done .task-row-title { text-decoration: line-through; color: var(--color-text-muted, #888); }
.task-check {
  flex: 0 0 auto; width: 26px; height: 26px; padding: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: none; color: var(--color-text-muted, #888);
  transition: color 0.15s ease;
}
.task-check:hover { color: #30a46c; }
.task-check.checked { color: #30a46c; }
.task-check .material-icons-outlined { font-size: 20px; }
.task-row .meeting-task-pri { margin-top: 0; }
.task-row .meeting-task-pri.pri-none { background: transparent; border: 1px solid var(--line); }
.task-row-title {
  flex: 1; min-width: 0; font-size: 13px; color: var(--color-text);
  white-space: normal; overflow: visible; text-overflow: clip;
  line-height: 1.35; overflow-wrap: anywhere; word-break: normal;
}
.task-row-chips { display: flex; gap: 6px; flex: 0 0 auto; }
.task-chip {
  display: inline-flex; align-items: center; gap: 4px;
  height: 22px; padding: 0 8px; border-radius: 11px;
  font-size: 11px; color: var(--color-text-muted, #888);
  background: var(--surface-soft); border: 1px solid var(--line);
  white-space: nowrap;
}
.task-chip .material-icons-outlined { font-size: 13px; }

/* Модалка задачи */
.task-modal-card {
  max-width: 680px;
  width: calc(100% - 32px);
  height: auto;
  max-height: min(88vh, 820px);
}
.task-modal-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 8px 4px 8px 8px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}
.task-modal-body::-webkit-scrollbar,
.task-m-title::-webkit-scrollbar,
#task-m-desc::-webkit-scrollbar,
.task-m-sub-title::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}
.task-modal-body::-webkit-scrollbar-track,
.task-m-title::-webkit-scrollbar-track,
#task-m-desc::-webkit-scrollbar-track,
.task-m-sub-title::-webkit-scrollbar-track {
  background: transparent;
}
.task-modal-body::-webkit-scrollbar-thumb,
.task-m-title::-webkit-scrollbar-thumb,
#task-m-desc::-webkit-scrollbar-thumb,
.task-m-sub-title::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 4px;
}
.task-m-title {
  width: calc(100% - 54px);
  min-height: 30px;
  max-height: 112px;
  padding: 0;
  margin: 0 0 2px;
  resize: none;
  overflow: hidden;
  line-height: 1.22;
  font-family: 'Manrope', sans-serif; font-size: 20px; font-weight: 800; color: var(--color-text);
  background: transparent;
  border: 0;
  border-radius: 0;
  outline: none;
}
.task-m-title:hover,
.task-m-title:focus {
  background: transparent;
  box-shadow: none;
}
.task-m-title::placeholder { color: var(--color-text-muted); opacity: 0.55; }
#task-m-desc {
  min-height: 86px;
  max-height: 260px;
  padding: 0;
  margin: 0;
  resize: none;
  overflow-y: auto;
  line-height: 1.5;
  font-size: 14px;
  color: var(--color-text);
  background: transparent;
  border: 0;
  border-radius: 0;
  outline: none;
  box-shadow: none;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}
#task-m-desc:hover,
#task-m-desc:focus {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}
#task-m-desc::placeholder { color: var(--color-text-muted); opacity: 0.55; }

/* Задача открывается не попапом, а правой рабочей панелью. */
#task-modal.tools-result-modal {
  align-items: stretch;
  justify-content: flex-end;
  padding: 0;
  pointer-events: none;
  background: transparent;
  backdrop-filter: none;
}
#task-modal .task-modal-card {
  width: clamp(460px, 30vw, 610px);
  max-width: calc(100vw - 72px);
  height: 100dvh;
  max-height: 100dvh;
  padding: 0;
  border-top: 0;
  border-right: 0;
  border-bottom: 0;
  border-left: 1px solid var(--line-strong);
  border-radius: 0;
  overflow: hidden;
  pointer-events: auto;
  box-shadow: -14px 0 28px rgba(0, 0, 0, 0.28);
  animation: task-drawer-in 180ms ease-out both;
}
@keyframes task-drawer-in {
  from { transform: translateX(28px); opacity: 0.72; }
  to { transform: translateX(0); opacity: 1; }
}
#task-modal .tools-result-modal-close {
  top: 16px;
  right: 16px;
  z-index: 5;
}
#task-modal .task-modal-body {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  max-height: 100dvh;
  gap: 12px;
  padding: 54px 24px 18px;
  overflow-y: auto;
}
#task-modal .task-modal-body > * {
  flex-shrink: 0;
}
#task-modal .task-m-title {
  width: 100%;
  min-height: 34px;
  max-height: none;
  height: auto;
  padding: 2px 44px 6px 0;
  margin-bottom: 0;
  overflow: hidden;
  font-size: 21px;
  line-height: 1.25;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: normal;
}
#task-modal .task-desc-label {
  margin-top: 10px;
  color: var(--color-text-muted);
  font-size: 12px;
  font-weight: 700;
}
#task-modal #task-m-desc {
  display: block;
  width: 100%;
  min-height: 72px;
  max-height: none;
  overflow-y: hidden;
  line-height: 1.55;
  color: var(--color-text);
  overflow-wrap: anywhere;
  word-break: normal;
}
#task-modal .task-m-grid {
  margin-top: 12px;
  padding: 12px 0 14px;
  border-bottom: 1px solid var(--line);
}
#tasks-screen.task-inspector-open .tasks-wrap {
  padding-right: calc(clamp(460px, 30vw, 610px) + 18px);
  transition: padding-right 0.18s ease;
}

@media (max-width: 768px) {
  #task-modal .task-modal-card {
    width: 100%;
    max-width: 100%;
    border-left: 0;
    border-radius: 0;
  }
  #tasks-screen.task-inspector-open .tasks-wrap {
    padding-right: 0;
  }
  #task-modal .task-modal-body {
    padding: 24px 16px 14px;
  }
  #task-modal .task-m-title {
    padding-right: 52px;
    font-size: 20px;
  }
  #task-modal #task-m-desc {
    min-height: clamp(112px, 24dvh, 190px);
  }
  #task-modal .task-comment-dock {
    padding: 8px 10px max(10px, env(safe-area-inset-bottom));
  }
  .task-comment-line {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 5px;
  }
  .task-comment-tools { gap: 4px; }
  .task-comment-icon {
    width: 30px;
    height: 30px;
  }
  .task-comment-send {
    width: 34px;
    height: 34px;
  }
}

.task-m-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.task-m-due {
  height: 34px; padding: 0 10px; width: 100%;
  font-family: 'Manrope', sans-serif; font-size: 13px; color: var(--color-text);
  background: var(--color-control); border: 1px solid var(--line);
  border-radius: var(--radius-sm); outline: none; color-scheme: dark;
}
.task-m-meta { font-size: 11px; color: var(--color-text-muted, #888); }
.task-m-actions { justify-content: flex-start; }
.task-modal-card .cdrop { z-index: 1; }
.task-modal-card .cdrop.open { z-index: 30; }
.task-modal-card .cdrop-list {
  width: 100%;
  min-width: 100%;
  max-width: min(260px, calc(100vw - 48px));
}
.task-modal-card .task-m-grid .tools-param:nth-child(5) .cdrop-list {
  top: auto;
  bottom: calc(100% + 6px);
}
.task-modal-card .tools-param { min-width: 0; }
#task-modal .task-m-grid {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
#task-modal .task-m-grid .tools-param {
  display: grid;
  grid-template-columns: 118px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 34px;
  color: var(--color-text-muted);
  font-size: 12px;
  font-weight: 600;
}
#task-modal .task-m-grid .cdrop--tools,
#task-modal .task-m-grid .task-m-due {
  background: var(--color-control);
  border-color: var(--line);
  box-shadow: var(--shadow-control);
}
#task-modal .task-m-grid .cdrop--tools:hover,
#task-modal .task-m-grid .cdrop--tools.open,
#task-modal .task-m-grid .task-m-due:hover,
#task-modal .task-m-grid .task-m-due:focus {
  background: var(--color-control-hover);
  border-color: var(--accent-border-strong);
}
#task-modal .task-m-grid .cdrop--tools:focus-within,
#task-modal .task-m-grid .task-m-due:focus {
  border-color: var(--color-accent);
  background: var(--color-control-hover);
  box-shadow: var(--shadow-accent-soft), 0 0 0 4px var(--focus-ring);
}
.task-modal-card .task-m-actions {
  position: relative;
  z-index: 2;
  padding: 10px 0 14px;
  margin-top: 0;
  border-top: 1px solid var(--line);
}
.task-m-delete:hover { color: #e5484d; border-color: #e5484d; }
.task-m-err { color: #e5484d; font-size: 12px; min-height: 14px; }
@media (max-width: 560px) { .task-m-grid { grid-template-columns: 1fr; } }

/* Колокольчик уведомлений */
.notif-wrap { position: relative; display: inline-flex; }
.notif-bell {
  position: relative; width: 34px; height: 34px; padding: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: none; color: var(--color-text-muted, #888); border-radius: 50%;
  transition: color 0.15s ease;
}
.notif-bell:hover { color: var(--color-text); }
.notif-badge {
  position: absolute; top: 1px; right: 0;
  min-width: 15px; height: 15px; padding: 0 4px; border-radius: 8px;
  background: #e5484d; color: #fff; font-size: 9px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; line-height: 1;
}
.notif-badge.hidden { display: none; }
.notif-dropdown {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 300;
  width: 300px; max-height: 380px; overflow-y: auto; scrollbar-width: thin;
  background: var(--color-control); border: 1px solid var(--line);
  border-radius: var(--radius-md); box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  padding: 6px;
}
.notif-dropdown.hidden { display: none; }
.notif-item {
  padding: 9px 10px; border-radius: var(--radius-sm); cursor: pointer;
  font-size: 12px; line-height: 1.4; color: var(--color-text);
}
.notif-item:hover { background: var(--surface-soft); }
.notif-item.unread { background: var(--surface-soft); }
.notif-item b { font-weight: 700; }
.notif-time { margin-top: 2px; font-size: 10px; color: var(--color-text-muted, #888); }
.notif-empty { padding: 16px; text-align: center; font-size: 12px; color: var(--color-text-muted, #888); }

/* ==================== TASKS: KANBAN BOARD (Asana-style) ==================== */
.tasks-wrap { max-width: none; }
.tasks-board {
  display: flex; gap: 12px; align-items: stretch;
  min-height: calc(100dvh - 178px);
  overflow-x: auto; padding-bottom: 24px; scrollbar-width: thin;
}
.tasks-col {
  flex: 0 0 268px; max-width: 268px; display: flex; flex-direction: column; gap: 8px;
  background: var(--color-control); border: 0;
  border-radius: var(--radius-sm); padding: 8px;
  max-height: calc(100dvh - 178px);
}
.tasks-col.drag-over { border-color: var(--accent-border, #888); }
.tasks-col-head { display: flex; align-items: flex-start; gap: 8px; min-height: 34px; padding: 0 4px; }
.tasks-col-name {
  flex: 1; min-width: 0; font-size: 13px; font-weight: 700; color: var(--color-text);
  white-space: normal; overflow: visible; text-overflow: clip;
  line-height: 1.25; overflow-wrap: anywhere; word-break: normal;
}
.tasks-col-head .history-count,
.tasks-col-menu {
  flex: 0 0 auto;
  margin-top: 1px;
}
.tasks-col-menu { opacity: 0.6; }
.tasks-col-menu:hover { opacity: 1; color: var(--color-text); }
.tasks-col-body {
  display: flex; flex-direction: column; gap: 8px;
  overflow-y: auto; scrollbar-width: thin; min-height: 20px;
  padding: 6px 8px 14px;
  margin: -6px -8px 0;
  scrollbar-gutter: stable;
}
.task-card {
  background: var(--color-panel-soft); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 10px; cursor: pointer;
  display: flex; flex-direction: column; gap: 7px;
  transition: border-color 0.15s ease, transform 0.1s ease;
  -webkit-touch-callout: none;
}
.task-card:hover { border-color: var(--accent-border); }
.task-card.selected {
  border-color: var(--accent-border);
  box-shadow: inset 0 0 0 1px var(--accent-border);
  background: var(--color-control-hover);
}
.task-card.dragging { opacity: 0; }
.task-card.done .task-card-title { text-decoration: line-through; color: var(--color-text-muted, #888); }
.task-card-cover {
  width: 100%;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--color-control);
}
.task-card-cover img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  -webkit-user-drag: none;
  user-select: none;
}
.task-card img,
.task-drag-float img {
  -webkit-user-drag: none;
  user-select: none;
}
.task-card-top { display: flex; align-items: flex-start; gap: 8px; }
.task-card-title {
  flex: 1; min-width: 0;
  font-size: 13px; font-weight: 600; line-height: 1.35; color: var(--color-text);
  overflow-wrap: anywhere;
  word-break: normal;
  hyphens: auto;
}
.task-card-desc {
  font-size: 11px; color: var(--color-text-muted, #888); line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.task-card-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.task-chip i { font-style: normal; }
.task-chip-assignee { gap: 6px; }
.task-chip-pri.pri-high { color: #e5484d; border-color: rgba(229, 72, 77, 0.4); }
.task-chip-pri.pri-medium { color: #f5a623; border-color: rgba(245, 166, 35, 0.4); }
.task-chip-pri.pri-low { color: #30a46c; border-color: rgba(48, 164, 108, 0.4); }
.tasks-col-add-input {
  width: 100%; height: 32px; padding: 0 10px;
  font-family: 'Manrope', sans-serif; font-size: 12px; color: var(--color-text);
  background: transparent; border: 1px dashed var(--line);
  border-radius: var(--radius-sm); outline: none;
  transition: border-color 0.15s ease;
}
.tasks-col-add-input:focus { border-color: var(--color-text-muted, #888); border-style: solid; background: var(--color-control); }
.tasks-col-add-input::placeholder { color: var(--color-text-muted, #777); opacity: 0.7; }
.tasks-col-done-toggle {
  display: flex; align-items: center; gap: 6px; width: 100%;
  background: none; border: none; cursor: pointer; padding: 4px 2px;
  font-family: 'Manrope', sans-serif; font-size: 11px; font-weight: 600; color: var(--color-text-muted, #888);
}
.tasks-col-done.collapsed .tasks-col-done-body { display: none; }
.tasks-col-done.collapsed .tasks-section-arrow { transform: rotate(-90deg); }
.tasks-col-done-body { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.tasks-col-done.just-opened .tasks-col-done-toggle { color: var(--accent); }
.tasks-col-new { background: transparent; border-style: dashed; padding: 0; max-height: none; }
.tasks-col-new-btn {
  width: 100%; height: 44px; display: flex; align-items: center; justify-content: center; gap: 6px;
  background: none; border: none; cursor: pointer; border-radius: var(--radius-md);
  font-family: 'Manrope', sans-serif; font-size: 13px; font-weight: 600; color: var(--color-text-muted, #888);
  transition: color 0.15s ease;
}
.tasks-col-new-btn:hover { color: var(--color-text); }

/* Кнопка диктовки */
.task-dictate-btn { margin-left: auto; }
.tasks-assignee-filter { margin-left: 0; }
.task-dictate-btn.recording { color: #fff; background: #e5484d; border-color: #e5484d; }

/* Черновик задач из диктовки */
.task-dictate-card { max-width: 640px; }
.task-dictate-head { font-size: 15px; font-weight: 700; color: var(--color-text); display: flex; align-items: center; gap: 8px; }
.task-dictate-hint { font-size: 11px; color: var(--color-text-muted, #888); }
.task-dictate-list { display: flex; flex-direction: column; gap: 10px; max-height: 46vh; overflow-y: auto; scrollbar-width: thin; }
.task-dict-item {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--color-panel-soft); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 10px;
  transition: opacity 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.task-dict-item.excluded {
  opacity: 0.48;
  background: var(--color-control);
}
.task-dict-check { padding-top: 6px; }
.task-dict-check input { width: 15px; height: 15px; cursor: pointer; accent-color: var(--color-accent, #6c5ce7); }
.task-dict-fields { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.task-dict-title {
  height: auto;
  min-height: 30px;
  max-height: none;
  font-weight: 600;
  line-height: 1.35;
  overflow-wrap: anywhere;
  word-break: normal;
}
.task-dict-row { display: flex; gap: 6px; flex-wrap: wrap; }
.task-dict-row .kv3-input, .task-dict-row .task-m-due { flex: 1; min-width: 120px; height: 30px; }
.task-dict-assignee.low-conf { border-color: #f5a623; }
.task-dict-warn { font-size: 11px; color: #f5a623; }

/* ==================== TASKS: subtasks, attachments, animations, mobile ==================== */
/* Подзадачи в модалке */
.task-m-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.task-m-block-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--color-text-muted, #888); display: flex; align-items: center; gap: 8px;
}
.task-m-subtasks { display: flex; flex-direction: column; gap: 4px; }
.task-m-sub { display: flex; align-items: flex-start; gap: 6px; }
.task-m-sub .task-check { width: 24px; height: 24px; }
.task-m-sub .task-check .material-icons-outlined { font-size: 18px; }
.task-m-sub-title {
  flex: 1; min-width: 0; min-height: 28px; max-height: none; padding: 4px 8px;
  resize: none; overflow: hidden; line-height: 1.35;
  font-family: 'Manrope', sans-serif; font-size: 13px; color: var(--color-text);
  background: transparent; border: 1px solid transparent; border-radius: 6px; outline: none;
  overflow-wrap: anywhere;
  word-break: normal;
}
.task-m-sub-title:hover, .task-m-sub-title:focus { background: var(--color-control); border-color: var(--line); }
.task-m-sub.done .task-m-sub-title { text-decoration: line-through; color: var(--color-text-muted, #888); }
.task-m-sub-add { height: 30px; }

/* Вложения в модалке */
.task-m-attachments { display: flex; flex-direction: column; gap: 4px; }
.task-m-attachments:empty { display: none; }
.task-m-att {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px;
  background: var(--color-panel-soft); border: 1px solid var(--line); border-radius: 6px;
}
.task-m-att.image {
  align-items: center;
  padding: 6px;
}
.task-m-att-ico { font-size: 16px; color: var(--color-text-muted, #888); flex: 0 0 auto; }
.task-m-att-preview {
  flex: 0 0 52px;
  width: 52px;
  height: 40px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--color-control);
}
.task-m-att-preview img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.task-m-att-name {
  flex: 1; min-width: 0; font-size: 12px; color: var(--color-text); text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.task-m-att-name:hover { text-decoration: underline; }
.task-m-att-size { flex: 0 0 auto; font-size: 10px; color: var(--color-text-muted, #888); }

/* Комментарии задачи */
.task-comments-block {
  gap: 8px;
  margin-top: 0;
  padding-bottom: 0;
}
.task-comments { display: flex; flex-direction: column; gap: 8px; }
.task-comment-empty {
  padding: 4px 0 8px;
  border: 0;
  color: var(--color-text-muted);
  font-size: 11px;
}
.task-comment {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.task-comment-avatar {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-control);
  border: 1px solid var(--line);
  color: var(--color-text);
  font-size: 11px;
  font-weight: 800;
}
.task-comment-main {
  flex: 1;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--color-panel-soft);
}
.task-comment-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 18px;
  color: var(--color-text-muted);
  font-size: 11px;
}
.task-comment-meta b { color: var(--color-text); font-size: 12px; }
.task-comment-delete {
  margin-left: auto;
  width: 20px;
  height: 20px;
}
.task-comment-delete .material-icons-outlined { font-size: 15px; }
.task-comment-text {
  margin-top: 5px;
  color: var(--color-text);
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.task-comment-atts,
.task-comment-files {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.task-comment-files {
  margin: 0 0 6px;
}
.task-comment-files:empty {
  display: none;
}
.task-comment-att,
.task-comment-file {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 26px;
  max-width: 100%;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--color-control);
  color: var(--color-text);
  font-size: 11px;
  font-weight: 600;
  text-decoration: none;
}
.task-comment-att span,
.task-comment-file span.material-icons-outlined { flex: 0 0 auto; font-size: 14px; color: var(--color-text-muted); }
.task-comment-att.image {
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 4px 8px 4px 4px;
  border-radius: var(--radius-sm);
}
.task-comment-att.image img {
  flex: 0 0 42px;
  width: 42px;
  height: 30px;
  border-radius: 5px;
  object-fit: cover;
  background: var(--color-control);
}
.task-comment-att.image span {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--color-text);
}
.task-comment-file {
  cursor: pointer;
  font-family: 'Manrope', sans-serif;
}
.task-comment-file span:not(.material-icons-outlined) {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.task-comment-file i {
  flex: 0 0 auto;
  color: var(--color-text-muted);
  font-style: normal;
  font-weight: 500;
}
.task-comment-composer {
  position: static;
  z-index: 1;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0;
  box-shadow: none;
}
.task-comment-dock {
  flex: 0 0 auto;
  padding: 10px 22px max(12px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
  box-shadow: 0 -8px 20px rgba(0, 0, 0, 0.16);
}
.task-comment-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 36px;
  grid-template-rows: minmax(48px, auto) 34px;
  grid-template-areas:
    "input input"
    "tools send";
  align-items: end;
  gap: 8px 10px;
  min-height: 104px;
  padding: 11px 10px 8px 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--color-control);
  transition: background var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.task-comment-line:hover {
  border-color: var(--line-strong);
}
.task-comment-line:focus-within {
  border-color: var(--accent-border-strong);
  box-shadow: inset 0 0 0 1px var(--accent-softer);
}
.task-comment-composer.has-error .task-comment-line {
  border-color: #e5484d;
  box-shadow: inset 0 0 0 1px rgba(229, 72, 77, 0.18);
}
.task-comment-input {
  grid-area: input;
  align-self: stretch;
  width: 100%;
  min-height: 48px;
  max-height: 160px;
  margin: 0;
  padding: 0 2px;
  resize: none;
  overflow: hidden;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--color-text);
  font-family: 'Manrope', sans-serif;
  font-size: 13px;
  line-height: 1.45;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}
.task-comment-input::placeholder {
  color: var(--color-text-muted);
  opacity: 0.78;
}
.task-comment-input:focus {
  border: 0;
  outline: none;
  box-shadow: none;
}
.task-comment-input::-webkit-scrollbar { width: 4px; }
.task-comment-input::-webkit-scrollbar-track { background: transparent; }
.task-comment-input::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 4px; }
.task-comment-tools {
  grid-area: tools;
  display: flex;
  align-items: center;
  gap: 2px;
}
.task-comment-icon,
.task-comment-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.12s ease;
}
.task-comment-icon {
  width: 32px;
  height: 32px;
  border-color: transparent;
  background: transparent;
}
.task-comment-icon .material-icons-outlined,
.task-comment-send .material-icons-outlined { font-size: 18px; }
.task-comment-icon:hover,
.task-comment-send:hover:not(:disabled) {
  color: var(--accent);
  border-color: var(--accent-border);
  background: var(--color-control-hover);
}
.task-comment-icon.recording {
  color: #fff;
  background: #e5484d;
  border-color: #e5484d;
  width: auto;
  padding: 0 8px;
  gap: 5px;
}
.task-comment-icon.recording b {
  font-size: 11px;
  font-weight: 800;
}
.task-comment-send {
  grid-area: send;
  width: 34px;
  height: 34px;
  color: var(--color-text-muted);
  background: var(--surface);
  border-color: var(--line);
}
.task-comment-composer.has-content .task-comment-send {
  color: var(--surface);
  background: var(--color-text);
  border-color: var(--color-text);
}
.task-comment-send:hover:not(:disabled) {
  color: var(--surface);
  background: var(--accent);
  transform: translateY(-1px);
}
.task-comment-send:disabled,
.task-comment-icon:disabled {
  opacity: 0.62;
  cursor: default;
}
.task-comment-composer.is-sending .task-comment-send {
  transform: none;
  opacity: 0.75;
}
.task-comment-err {
  min-height: 14px;
  color: #e5484d;
  font-size: 12px;
}

@media (max-width: 768px) {
  #task-modal .task-comment-dock {
    padding: 8px 10px max(10px, env(safe-area-inset-bottom));
  }
  .task-comment-line {
    min-height: 100px;
    padding: 10px 8px 7px 10px;
    border-radius: 14px;
  }
}

/* Чип прогресса подзадач */
.task-chip-sub.all-done { color: #30a46c; border-color: rgba(48, 164, 108, 0.4); }

/* Режим диктовки */
.task-dictate-mode { display: flex; gap: 8px; }
.task-dict-parent { height: 34px; font-weight: 600; }

/* Анимации доски */
.task-card { position: relative; will-change: transform; }
@keyframes task-card-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.task-card:hover { transform: translateY(-1px); box-shadow: 0 8px 18px rgba(0, 0, 0, 0.34); }
.task-card:active { transform: scale(0.99); }
.task-card.dragging { opacity: 0; transform: none; box-shadow: none; cursor: grabbing; }
.task-card.just-moved {
  animation: task-card-land 0.44s cubic-bezier(.18,.9,.2,1) both;
  border-color: var(--accent-border);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.32), inset 0 0 0 1px var(--accent-softer);
}
@keyframes task-card-land {
  0% { opacity: 0.68; transform: translateY(-10px) scale(0.985); }
  62% { opacity: 1; transform: translateY(2px) scale(1.006); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}
.task-drag-float {
  position: fixed;
  top: 0;
  left: 0;
  pointer-events: none;
  opacity: 0.98;
  transform-origin: 0 0;
  box-shadow: 0 14px 30px var(--shadow-color);
  z-index: 100000;
  cursor: grabbing;
  box-sizing: border-box;
  overflow: hidden;
  transition: none !important;
  animation: none !important;
  will-change: transform;
  contain: layout style;
}
.task-drag-float,
.task-drag-float:hover,
.task-drag-float:active {
  background: var(--color-control);
  border-color: var(--accent-border);
  transform-origin: 0 0;
}
.task-drop-marker {
  flex: 0 0 var(--task-drop-height, 52px);
  height: var(--task-drop-height, 52px);
  min-height: var(--task-drop-height, 52px);
  border: 1px dashed var(--accent-border);
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent-softer);
  animation: task-drop-marker-in 0.16s ease-out both;
}
@keyframes task-drop-marker-in {
  from { opacity: 0; transform: scaleY(0.82); }
  to { opacity: 1; transform: scaleY(1); }
}
.tasks-col { transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease; }
.task-dragging-active,
.task-dragging-active * {
  cursor: grabbing !important;
}
.task-dragging-active {
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: contain;
}
.task-dragging-active .tasks-board {
  scroll-snap-type: none;
}
.tasks-col.drag-over {
  background: var(--color-control-hover);
  box-shadow: inset 0 0 0 1px var(--accent-border);
}
.task-check .material-icons-outlined { transition: transform 0.12s ease; }
.task-check:active .material-icons-outlined { transform: scale(1.25); }

/* Мобильная адаптация доски (iPhone) */
@media (max-width: 768px) {
  .tasks-wrap { padding: 8px 10px 32px; }
  .task-card { touch-action: manipulation; }
  .tasks-board {
    gap: 10px; margin: 0 -10px; padding: 0 10px 20px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
  }
  .tasks-col {
    flex: 0 0 82vw; max-width: 82vw;
    scroll-snap-align: center;
    max-height: calc(100dvh - 230px);
  }
  .tasks-col-new { flex: 0 0 44vw; max-width: 44vw; }
  .tasks-toolbar { gap: 8px; }
  .tasks-filters { width: 100%; }
  .task-dictate-btn { margin-left: auto; }
  .tasks-assignee-filter { display: none; } /* на телефоне хватает Все/Мои */
  .task-modal-card, .task-dictate-card {
    max-width: none; width: 100%; height: 100%; max-height: 100dvh;
    border-radius: 0; overflow-y: auto;
  }
  .task-modal-card { overflow: hidden; }
  .task-modal-body { padding: 14px 12px 32px; }
  .task-dict-row .kv3-input, .task-dict-row .task-m-due { min-width: 100%; }
  .task-card { animation: none; } /* меньше репейнтов при скролле колонок */
  .notif-dropdown { position: fixed; top: 60px; left: 10px; right: 10px; width: auto; }
}
