/* Shared interaction and responsive fixes. Keep the studio's existing visual identity. */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --visible-height: 100vh;
  --visible-top: 0px;
}
@supports (height: 100dvh) {
  :root { --visible-height: 100dvh; }
}
html { scrollbar-gutter: stable; }
html.dialog-open, html.dialog-open body { overflow: hidden; }
body { min-height: 100vh; min-height: 100dvh; }
button, a, summary, .reel-card, .idea-option, .switch-row { touch-action: manipulation; }
button, a.button, summary { min-height: 44px; }
.ui-icon {
  width: 1.25rem;
  height: 1.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  color: currentColor;
}
.ui-icon svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.button-with-icon { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; }
button:disabled { cursor: not-allowed; opacity: .5; }
button:focus-visible, a:focus-visible, summary:focus-visible, .reel-card:focus-visible {
  outline: 3px solid var(--lime);
  outline-offset: 3px;
}
input, select, textarea, fieldset, .idea-option span, .switch-row span { min-width: 0; }
input, select, textarea { scroll-margin-block: 5rem; }
input[type="checkbox"], input[type="radio"] { flex-shrink: 0; }
fieldset { margin-inline: 0; }
legend { max-width: 100%; overflow-wrap: break-word; }
.topbar { gap: 1rem; }
.topbar > div, .topbar-actions, .brand-picker { min-width: 0; }
.topbar-actions { flex-shrink: 0; max-width: 100%; }
.brand-picker { max-width: 24rem; }
.brand-picker select { min-width: 0; min-height: 44px; text-overflow: ellipsis; }
.icon-button, #logout { flex: 0 0 44px; width: 44px; height: 44px; }
#breadcrumb { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-heading > div, .section-head > div { min-width: 0; }
.page-heading, .section-head { flex-wrap: wrap; gap: .75rem; }
.page-heading h2, .section-head h2, .simple-start h2, .editor-head h2,
.generation-banner, .script-text, .publication-block pre, .publication-error,
.notice, .empty-state, .dialog-message, .login-error { overflow-wrap: anywhere; }
.reel-copy h3 { height: auto; min-height: 2.3rem; overflow-wrap: anywhere; }
.reel-copy footer { flex-wrap: wrap; gap: .25rem .5rem; }
.reel-media > .status-chip { max-width: calc(100% - 1.3rem); white-space: normal; }
.reel-media video { pointer-events: none; }
.generation-heading { grid-template-columns: auto minmax(0, 1fr) auto; }
.generation-heading > button { grid-column: 1 / -1; justify-self: start; }
.generation-step summary { grid-template-columns: auto minmax(0, 1fr); }
.generation-details { padding: .25rem 0 0; }
.generation-details > summary { display: flex; align-items: center; gap: .55rem; min-height: 44px; color: #d2c5ff; }
.generation-details > summary small { margin-left: auto; color: var(--muted); }
.generation-details > .generation-steps { margin-top: .6rem; }
.generation-step-icon .ui-icon { width: .9rem; height: .9rem; }
.reel-row > .empty-state { flex: 1 0 100%; }
.media-placeholder-video { align-content: center; gap: .7rem; padding: 1.25rem; text-align: center; }
.media-placeholder-video small { color: #d8dfea; font: 700 .78rem/1.45 Manrope, sans-serif; }
.reel-copy p, .reel-copy footer { color: #aeb6c2; }
.reel-copy footer .button-with-icon { color: var(--ink); font-weight: 700; }

/* A sticky, in-dialog toolbar remains reachable at the bottom of long forms.
   Messages live here too: an ordinary page toast is hidden behind showModal(). */
.form-dialog, #create-brand { padding: 0; }
.form-dialog, #create-brand, .detail-dialog {
  max-height: calc(var(--visible-height) - 2rem);
  overflow: auto;
  overscroll-behavior: contain;
  scroll-padding-block: 5rem 2rem;
}
.dialog-toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: .75rem;
  min-height: 60px;
  padding: .5rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.dialog-toolbar .dialog-close {
  position: static;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  margin-left: auto;
}
.telegram-dialog .dialog-close {
  position: relative;
  color: transparent;
  font-size: 0;
}
.telegram-dialog .dialog-close::before,
.telegram-dialog .dialog-close::after {
  content: "";
  position: absolute;
  left: 12px;
  top: 21px;
  width: 20px;
  height: 2px;
  border-radius: 2px;
  background: var(--ink);
  transform: rotate(45deg);
}
.telegram-dialog .dialog-close::after { transform: rotate(-45deg); }
.dialog-message { margin: 0; font-size: .85rem; color: var(--green); }
.dialog-message.is-error { color: var(--red); }
.dialog-body { padding: 1.25rem 2rem 1.5rem; }
.form-actions { flex-wrap: wrap; }
.form-actions .button { white-space: normal; }
.sticky-actions {
  position: static;
  margin: 1.5rem 0 0;
  padding: 1rem 0 0;
  backdrop-filter: none;
  background: transparent;
}
.preview-column { min-height: 0; top: 60px; }
.preview-column video, .preview-column > img {
  display: block;
  max-height: min(65vh, calc(var(--visible-height) - 10rem));
  object-fit: contain;
}
.publication-block pre { font-size: .875rem; }
.publication-block button { padding: .5rem 0; text-align: left; }
.copy-fallback { width: 100%; min-height: 10rem; margin: .5rem 0; font-size: 16px; }
#flash { max-width: min(28rem, calc(100vw - 2rem)); overflow-wrap: anywhere; }
.login-screen {
  overflow: auto;
  align-items: start;
  padding: max(1rem, var(--safe-top)) max(1rem, var(--safe-right)) max(1rem, var(--safe-bottom)) max(1rem, var(--safe-left));
}
.login-card { margin-block: auto; }

@media (max-width: 1100px) and (min-width: 801px) {
  .workspace { padding-inline: 1.25rem; }
  .topbar { height: auto; min-height: 6.6rem; flex-wrap: wrap; padding-block: 1rem; }
  .topbar-actions { flex: 1 1 100%; }
  .brand-picker { flex: 1; max-width: none; }
}
@media (max-width: 800px) {
  html { scrollbar-gutter: auto; }
  body { padding-bottom: calc(5rem + var(--safe-bottom)); }
  .workspace { padding: 0 max(1rem, var(--safe-right)) 1.5rem max(1rem, var(--safe-left)); }
  .sidebar {
    height: calc(4.6rem + var(--safe-bottom));
    padding: .4rem max(.5rem, var(--safe-right)) calc(.4rem + var(--safe-bottom)) max(.5rem, var(--safe-left));
  }
  .sidebar nav { gap: .5rem; }
  .nav-item { flex: 1; min-height: 48px; font-size: .75rem; }
  .nav-item span { font-size: 1.15rem; }
  .topbar {
    height: auto;
    min-height: 0;
    display: grid;
    gap: .85rem;
    padding: calc(1rem + var(--safe-top)) 0 1rem;
  }
  .topbar h1 { font-size: 1.35rem; }
  .topbar-actions { display: flex; width: 100%; gap: .5rem; }
  .brand-picker { flex: 1 1 0; max-width: none; padding: 0; border: 0; }
  .brand-picker select { min-width: 0; min-height: 44px; max-width: 100%; border: 1px solid var(--line-strong); }
  #logout { display: grid; }
  input, select, textarea, .brand-picker select { font-size: 16px; }
  .simple-start { padding: 1.25rem; }
  .simple-start h2 { font-size: clamp(1.5rem, 6vw, 1.85rem); }
  .hero-action { min-height: 56px; }
  .reel-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow: visible;
    margin-right: 0;
    padding-right: 0;
    gap: .75rem;
  }
  .reel-copy { padding: .75rem; }
  .reel-copy h3 { font-size: .85rem; }
  .reel-copy footer { font-size: .7rem; }
  .section-head h2, .page-heading h2 { font-size: 1.35rem; }
  .page-heading .button { font-size: .875rem; }
  .generation-banner { margin-top: 0; padding: 1rem; }
  .generation-heading > button { justify-self: stretch; }
  .generation-step p { font-size: .8rem; }
  .generation-step summary { font-size: .8rem; }
  .generation-step summary > span:last-child { font-size: .7rem; }
  .form-dialog, #create-brand, .detail-dialog {
    position: fixed;
    inset: var(--visible-top) 0 auto;
    width: 100%;
    max-width: none;
    height: var(--visible-height);
    min-height: var(--visible-height);
    max-height: var(--visible-height);
    margin: 0;
    border: 0;
    border-radius: 0;
    padding: 0;
    background-color: var(--surface);
  }
  dialog::backdrop { background: var(--canvas); backdrop-filter: none; }
  .dialog-toolbar {
    padding-top: max(.5rem, var(--safe-top));
    padding-right: max(1rem, var(--safe-right));
    padding-left: max(1rem, var(--safe-left));
  }
  .dialog-body, .editor-column {
    padding: 1rem max(1rem, var(--safe-right)) calc(1.5rem + var(--safe-bottom)) max(1rem, var(--safe-left));
  }
  .form-dialog h2 { font-size: 1.4rem; }
  fieldset { padding: .85rem; }
  .idea-option { padding: .85rem .7rem; }
  .idea-option small, label small { font-size: .85rem; }
  .switch-row { min-height: 44px; }
  .form-actions { display: grid; grid-template-columns: minmax(0, 1fr); gap: .75rem; }
  .form-actions .button { width: 100%; min-height: 48px; }
  .form-actions .button.primary { grid-row: 1; }
  .preview-column { position: relative; top: auto; padding: 1rem; }
  .preview-column video, .preview-column > img { max-height: calc(var(--visible-height) * .6); }
  .detail-placeholder { max-height: calc(var(--visible-height) * .6); }
  .editor-head { padding-right: 0; }
  .editor-head h2 { font-size: 1.35rem; }
  .preview-meta { flex-wrap: wrap; gap: .5rem 1rem; }
  #flash { left: 1rem; right: 1rem; top: auto; bottom: calc(5.5rem + var(--safe-bottom)); }
  .login-card { padding: 1.5rem; }
  .login-card h1 { font-size: 1.4rem; }
}
@media (max-width: 360px) {
  .reel-row, .content-grid { grid-template-columns: minmax(0, 1fr); }
  .generation-steps { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 480px) {
  .reel-row, .content-grid { grid-template-columns: minmax(0, 1fr); gap: 1rem; }
  .reel-media { aspect-ratio: 9 / 16; background: #080a0d; }
  .reel-media video, .reel-media img { object-fit: contain; }
  .reel-copy { padding: 1rem; }
  .reel-copy h3 { font-size: .95rem; line-height: 1.45; }
  .reel-copy p, .reel-copy footer { font-size: .78rem; }
  .library-heading { display: block; margin-bottom: 1rem; }
  .library-heading > div { display: none; }
  .library-heading .button { width: 100%; min-height: 48px; }
}
@media (hover: none) {
  .reel-card:hover, .reel-card:focus, .hero-action:hover,
  .create-button:hover, .button.primary:hover { transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* Library controls and publication state are usable on narrow screens too. */
.workspace-summary { display:flex; align-items:center; flex-wrap:wrap; gap:12px 24px; margin:20px 0 28px; padding:16px; border:1px solid #2a2e35; border-radius:14px; color:#aab1bd; }
.workspace-summary b { color:#f5f7fa; margin-right:6px; }
.workspace-summary button { margin-left:auto; }
.reel-filters { display:grid; grid-template-columns:minmax(0,1fr) minmax(160px,220px) auto; gap:14px; align-items:end; margin:0 0 24px; }
.reel-filters label { display:flex; flex-direction:column; gap:8px; font-size:13px; color:#aab1bd; min-width:0; }
.reel-filters input,.reel-filters select { width:100%; min-width:0; min-height:44px; background:#15191f; border:1px solid #353b45; border-radius:10px; color:#f5f7fa; padding:10px 12px; font:inherit; }
.load-more { display:block; margin:24px auto; }
.publication-complete { color:#c1dd80; padding:12px 0; }
.publish-zone { display:flex; flex-wrap:wrap; gap:12px; align-items:center; }
@media(max-width:600px) {
 .reel-filters { grid-template-columns:minmax(0,1fr) auto; gap:12px; }
 .reel-filters label:first-child { grid-column:1 / -1; }
 .reel-filters input,.reel-filters select { font-size:16px; }
 .workspace-summary { gap:10px 16px; font-size:12px; }
 .workspace-summary button { flex-basis:100%; text-align:left; }
 .publish-zone > .button { width:100%; }
}
/* Scroll/focus targets must clear the fixed mobile navigation, not sit beneath it. */
@media(max-width:767px) {
 .page button,.page a,.page input,.page select { scroll-margin-block:1rem calc(7rem + var(--safe-bottom)); }
}
