/* =========================================
   Masora — Global Styles (Root static)
   Source of truth for /static/style.css
   With current app.py config:
   static_folder = APP_ROOT (project root)
   ========================================= */

/* ---------- Theme tokens ---------- */
:root{
  --bg:#0f1115;
  --card:#151923;
  --txt:#e9eef7;
  --muted:#98a2b3;
  --elev:#0b0e14;
  --border:#222735;
  --accent:#4f46e5;

  --ok:#10b981;
  --warn:#f59e0b;
  --err:#ef4444;

  --shadow:0 10px 30px rgba(0,0,0,.25);
}

/* Light theme overrides */
html[data-theme="light"]{
  --bg:#f7f8fa;
  --card:#ffffff;
  --txt:#0f172a;
  --muted:#6b7280;
  --elev:#f1f5f9;
  --border:#e5e7eb;
  --accent:#3b82f6;
  --shadow:0 10px 30px rgba(0,0,0,.08);
}

/* ---------- Base layout ---------- */
*{ box-sizing:border-box; }

body{
  margin:0;
  font:14px/1.6 Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial;
  background:var(--bg);
  color:var(--txt);
}

main{ padding:16px; }

/* ---------- Header (main app) ---------- */
.app-header{
  padding:16px 20px;
  border-bottom:1px solid var(--border);
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
}

/* Optional structured header layout used in newer layouts */
.header-row{
  display:flex;
  align-items:baseline;
  justify-content:space-between;
  gap:12px;
}
.header-sub{
  color:var(--muted);
  font-size:12px;
  font-weight:500;
}

h1{
  margin:0;
  font-size:20px;
}

/* Header left/right + auth helpers (if present) */
.header-left h1{
  font-size:18px;
  font-weight:700;
  margin:0;
}
.header-left a{
  color:var(--txt);
  text-decoration:none;
}
.header-left a:hover{
  text-decoration:underline;
}

.header-right{
  display:flex;
  align-items:center;
  gap:10px;
}
.whoami{
  font-size:13px;
  color:var(--muted);
}

.link-btn{
  background:transparent;
  border:1px solid var(--border);
  color:var(--txt);
  padding:6px 10px;
  border-radius:999px;
  font-size:13px;
  cursor:pointer;
}
.link-btn:hover{ background:var(--elev); }

/* ---------- Grid & cards ---------- */
.grid{
  display:grid;
  grid-template-columns:1fr;
  gap:16px;
}

@media (min-width: 980px){
  .grid{ grid-template-columns:1fr 1fr; }
}

/* Single-child full-width helper */
.grid > *:only-child{ grid-column: 1 / -1; }
@supports selector(:has(*)){
  .grid:has(> *:only-child){ grid-template-columns:1fr; }
}

.card{
  background:var(--card);
  border:1px solid var(--border);
  border-radius:16px;
  padding:14px;
  box-shadow:var(--shadow);
}

.card h2{ margin-top:0; }
.card h3{
  margin:8px 0;
  color:var(--muted);
  font-weight:600;
}

/* ---------- Toolbar ---------- */
.toolbar{
  display:flex;
  gap:8px;
  margin-bottom:12px;
  flex-wrap:wrap;
}

.toolbar button{
  display:inline-flex;
  align-items:center;
  gap:8px;
}

/* ---------- Buttons ---------- */
button{
  background:var(--accent);
  color:#fff;
  border:0;
  padding:8px 12px;
  border-radius:10px;
  cursor:pointer;
  line-height:1.15;
}

button:disabled{
  opacity:.5;
  cursor:not-allowed;
}

.btn.danger{ background:var(--err); }

.btn.outline{
  background:transparent;
  color:var(--txt);
  border:1px solid var(--border);
}

.icon-btn{
  background:transparent;
  color:var(--txt);
  border:1px solid var(--border);
  padding:8px 10px;
  border-radius:999px;
  display:inline-flex;
  align-items:center;
  gap:8px;
}
.icon-btn:hover{ background:var(--elev); }

/* Theme button visuals (if #btnTheme exists) */
#btnTheme .icon-label{ font-size:12px; opacity:.7; }
html[data-theme="dark"]  #btnTheme .icon-sun{ display:none; }
html[data-theme="dark"]  #btnTheme .icon-moon{ display:inline; }
html[data-theme="light"] #btnTheme .icon-sun{ display:inline; }
html[data-theme="light"] #btnTheme .icon-moon{ display:none; }

/* Toolbar icon labels (used in newer Run/Stop buttons) */
.btn-ico{
  font-size:13px;
  line-height:1;
  opacity:.95;
}
.btn-label{ display:inline-block; }

#btnRun{ font-weight:700; }
#btnStop{ background:var(--accent); filter:saturate(.85); }

/* ---------- Forms ---------- */
label{ display:block; margin:6px 0; }

.checkbox{
  display:flex;
  align-items:center;
  gap:8px;
}

input, select{
  width:100%;
  padding:10px 12px;
  border-radius:10px;
  border:1px solid var(--border);
  background:var(--elev);
  color:var(--txt);
}

input:focus, select:focus, .toolbar button:focus{
  outline:2px solid rgba(147,197,253,.55);
  outline-offset:2px;
  box-shadow:none;
}

.row{
  display:flex;
  gap:12px;
  align-items:flex-end;
  flex-wrap:wrap;
}
.row > label{ flex:1 1 260px; }

/* ---------- Badges ---------- */
.badge{
  display:inline-block;
  padding:4px 8px;
  border-radius:999px;
  font-size:12px;
  background:#222735;
  color:#e9eef7;
}
.badge.success{ background:var(--ok); color:#fff; }
.badge.warn{ background:var(--warn); color:#111827; }

/* ---------- Video options disabled overlay ---------- */
#videoOptionsSection.disabled,
#videoOptionsSection[style*="opacity: 0.5"]{
  position:relative;
}
#videoOptionsSection.disabled::after,
#videoOptionsSection[style*="opacity: 0.5"]::after{
  content:"Video options disabled in audio-only mode";
  position:absolute;
  top:50%;
  left:50%;
  transform:translate(-50%, -50%);
  background:var(--card);
  padding:8px 16px;
  border-radius:8px;
  font-size:12px;
  color:var(--muted);
  border:1px solid var(--border);
  white-space:nowrap;
}

/* ---------- Details / collapsibles ---------- */
.details summary,
details summary{
  cursor:pointer;
  user-select:none;
  padding:10px 12px;
  margin:8px 0 12px;
  background:#0e131b;
  border:1px solid #2a3143;
  border-radius:10px;
  list-style:none;
}
.details[open] summary,
details[open] summary{
  background:#0c1118;
  border-color:#30384f;
}
details summary::-webkit-details-marker{ display:none; }

html[data-theme="light"] .details summary,
html[data-theme="light"] details summary{
  background:#eef2f7;
  border-color:#dbe2ea;
}
html[data-theme="light"] .details[open] summary,
html[data-theme="light"] details[open] summary{
  background:#e9eff8;
  border-color:#cfd9e6;
}

/* ---------- Outputs list ---------- */
.outputs-list{
  display:flex;
  flex-wrap:wrap;
  gap:10px;
}
.outputs-list a{
  display:inline-flex;
  align-items:center;
  gap:8px;
  padding:8px 10px;
  background:#0e131b;
  border:1px solid #242a39;
  border-radius:10px;
  text-decoration:none;
  color:#60a5fa;
}
.outputs-list a:hover{ border-color:#2e3a54; }

html[data-theme="light"] .outputs-list a{
  background:#f1f5f9;
  border-color:#e5e7eb;
  color:#2563eb;
}

/* ---------- Log view ---------- */
.log-view{
  background:var(--elev);
  padding:12px;
  border-radius:10px;
  min-height:220px;
  white-space:pre-wrap;
  overflow:auto;
  font-family:ui-monospace, SFMono-Regular, Consolas, Monaco, monospace;
}

/* ---------- Toasts ---------- */
.toasts{
  position:fixed;
  right:16px;
  bottom:16px;
  z-index:100;
  display:flex;
  flex-direction:column;
  gap:8px;
}
.toast{
  background:#0e131b;
  border:1px solid #2a3143;
  color:var(--txt);
  padding:10px 12px;
  border-radius:10px;
  box-shadow:var(--shadow);
  animation:slideIn .2s ease-out;
}
.toast.ok{ border-color:rgba(16,185,129,.6); }
.toast.warn{ border-color:rgba(245,158,11,.7); }
.toast.err{ border-color:rgba(239,68,68,.7); }

@keyframes slideIn{
  from{ transform:translateY(8px); opacity:0; }
  to{ transform:translateY(0); opacity:1; }
}

html[data-theme="light"] .toast{
  background:#ffffff;
  border-color:#e5e7eb;
}

/* ---------- Result card (latest output) ---------- */
.result-card{
  position:fixed;
  left:50%;
  transform:translateX(-50%);
  bottom:18px;
  z-index:110;
  background:var(--card);
  border:1px solid var(--border);
  box-shadow:var(--shadow);
  border-radius:14px;
  padding:10px 12px;
  min-width:260px;
}
.result-card.hidden{ display:none; }

.result-body{ display:flex; flex-direction:column; align-items:flex-start; gap:8px; }
.result-title{ font-weight:700; margin-bottom:2px; }
.result-body a{ 
  text-decoration:none; 
  font-weight:600; 
  color:#60a5fa; 
  display:block;
  padding:4px 0;
}
.result-body a:hover{ text-decoration:underline; }
html[data-theme="light"] .result-body a{ color:#2563eb; }

#rcLrcLink{
  font-size:0.9em;
  color:#a78bfa;
}
html[data-theme="light"] #rcLrcLink{ color:#7c3aed; }
#rcLrcLink.hidden{ display:none; }

.rc-body{ display:flex; align-items:center; gap:12px; }
.rc-title{ font-weight:700; margin-bottom:2px; }
.rc-link{ text-decoration:none; font-weight:600; color:#60a5fa; }
html[data-theme="light"] .rc-link{ color:#2563eb; }
.rc-close{ margin-left:auto; }

/* ---------- Busy overlay ---------- */
.busy{
  position:fixed;
  inset:0;
  display:grid;
  place-items:center;
  background:rgba(0,0,0,.55);
  z-index:200;
}
.busy.hidden{ display:none; }

.busy-panel{
  background:var(--card);
  border:1px solid var(--border);
  border-radius:16px;
  padding:22px;
  width:min(92vw, 420px);
  box-shadow:var(--shadow);
}

.ring{
  position:relative;
  width:120px;
  height:120px;
  margin:0 auto 10px;
}
.ring svg{
  width:120px;
  height:120px;
  transform:rotate(-90deg);
}
.ring .track{
  fill:none;
  stroke:rgba(255,255,255,.10);
  stroke-width:12;
  stroke-linecap:round;
}
html[data-theme="light"] .ring .track{ stroke:rgba(0,0,0,.08); }

.ring .fill{
  --p:0;
  fill:none;
  stroke:#4f46e5;
  stroke-width:12;
  stroke-linecap:round;
  stroke-dasharray:339;
  stroke-dashoffset:calc(339 * (1 - var(--p)/100));
  transition:stroke-dashoffset .25s ease;
  transform-box: fill-box;
  transform-origin: center;
}
.ring-center{
  position:absolute;
  inset:0;
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight:700;
  font-size:20px;
}

.busy-text{
  font-size:14px;
  color:#cbd5e1;
  display:flex;
  align-items:center;
  gap:6px;
  justify-content:center;
  margin-bottom:6px;
}
html[data-theme="light"] .busy-text{ color:#475569; }

/* Time remaining display */
.busy-time{
  font-size:12px;
  color:#94a3b8;
  text-align:center;
  margin-bottom:10px;
  min-height:18px;
  font-weight:500;
}
html[data-theme="light"] .busy-time{ color:#64748b; }

.dots b{ display:inline-block; animation:blink 1.2s infinite; }
.dots b:nth-child(2){ animation-delay:.15s; }
.dots b:nth-child(3){ animation-delay:.3s; }

@keyframes blink{
  0%,80%,100%{ opacity:.25; }
  40%{ opacity:1; }
}

/* Linear progress */
.progress{
  width:100%;
  height:8px;
  background:#121826;
  border:1px solid #2a3143;
  border-radius:999px;
  overflow:hidden;
}
.progress .bar{
  width:0%;
  height:100%;
  background:linear-gradient(90deg,#4f46e5,#6366f1);
  transition:width .25s ease;
}
html[data-theme="light"] .progress{
  background:#eef2f7;
  border-color:#e5e7eb;
}

.busy-actions{
  display:flex;
  gap:8px;
  margin-top:6px;
  justify-content:center !important;
}
.busy-actions .btn{
  margin:0 auto;
  min-width:112px;
}

/* ---------- Generic helpers ---------- */
.hidden{ display:none !important; }

/* ---------- Hamburger + Sheet menu (if used) ---------- */
.icon-btn.hamburger .ham{
  position:relative;
  width:18px;
  height:14px;
  display:inline-block;
}
.icon-btn.hamburger .ham i{
  position:absolute;
  left:0; right:0;
  height:2px;
  background:currentColor;
  border-radius:2px;
  transition:.2s transform, .2s opacity, .2s top;
}
.icon-btn.hamburger .ham i:nth-child(1){ top:0; }
.icon-btn.hamburger .ham i:nth-child(2){ top:6px; }
.icon-btn.hamburger .ham i:nth-child(3){ top:12px; }

.icon-btn.hamburger[aria-expanded="true"] .ham i:nth-child(1){
  top:6px; transform:rotate(45deg);
}
.icon-btn.hamburger[aria-expanded="true"] .ham i:nth-child(2){ opacity:0; }
.icon-btn.hamburger[aria-expanded="true"] .ham i:nth-child(3){
  top:6px; transform:rotate(-45deg);
}

.sheet-backdrop{
  position:fixed;
  inset:0;
  background:rgba(0,0,0,.35);
  z-index:250;
  -webkit-backdrop-filter:blur(2px);
  backdrop-filter:blur(2px);
}

.sheet{
  position:fixed;
  top:64px;
  right:16px;
  z-index:260;
  width:300px;
  background:var(--card);
  border:1px solid var(--border);
  border-radius:14px;
  box-shadow:var(--shadow);
  padding:10px 10px 12px;
  animation:menuIn .14s ease-out;
}

@keyframes menuIn{
  from{ opacity:0; transform:translateY(-6px); }
  to{ opacity:1; transform:none; }
}

.sheet-sec{
  padding:8px 8px 10px;
  border-bottom:1px solid var(--border);
}
.sheet-sec:last-of-type{ border-bottom:0; }

.sheet-title{
  font-weight:700;
  font-size:13px;
  color:var(--muted);
  margin:2px 2px 6px;
  text-transform:uppercase;
  letter-spacing:.4px;
}

.sheet-item{
  width:100%;
  text-align:left;
  display:flex;
  gap:10px;
  align-items:center;
  padding:10px 12px;
  border-radius:10px;
  background:transparent;
  border:0;
  color:var(--txt);
  cursor:pointer;
}
.sheet-item:hover{ background:var(--elev); }

.sheet-hint{
  padding:6px 10px 2px;
  font-size:12px;
  color:var(--muted);
  text-align:right;
}

html[data-theme="light"] .sheet{ background:#fff; }
html[data-theme="light"] .sheet-item:hover{ background:#f2f5fb; }

@media (max-width: 640px){
  .sheet{
    right:10px;
    left:10px;
    width:auto;
    top:56px;
  }
}

/* ---------- Pretty switches (only two specific checkboxes) ---------- */
input[type="checkbox"]#items_override,
input[type="checkbox"]#enable_bilingual{
  appearance:none;
  -webkit-appearance:none;
  width:44px;
  height:24px;
  background:var(--elev);
  border:1px solid var(--border);
  border-radius:999px;
  position:relative;
  vertical-align:middle;
  cursor:pointer;
  transition:background .2s ease, border-color .2s ease, box-shadow .2s ease;
  outline:none;
  margin-right:8px;
}

input#items_override::after,
input#enable_bilingual::after{
  content:"";
  position:absolute;
  top:2px; left:2px;
  width:20px; height:20px;
  border-radius:50%;
  background:#fff;
  box-shadow:0 1px 2px rgba(0,0,0,.35);
  transition:transform .2s ease;
}

input#items_override:checked,
input#enable_bilingual:checked{
  background:linear-gradient(90deg, var(--accent), #6366f1);
  border-color:#6366f1;
}

input#items_override:checked::after,
input#enable_bilingual:checked::after{
  transform:translateX(20px);
}

input#items_override:focus-visible,
input#enable_bilingual:focus-visible{
  box-shadow:0 0 0 3px rgba(147,197,253,.55);
}

input#items_override:disabled,
input#enable_bilingual:disabled{
  opacity:.55;
  filter:grayscale(.35);
  cursor:not-allowed;
}

label.checkbox{
  display:inline-flex;
  align-items:center;
  gap:10px;
  cursor:pointer;
}

html[data-theme="light"] input#items_override,
html[data-theme="light"] input#enable_bilingual{
  background:#eef2f7;
  border-color:#dbe2ea;
}

/* Align switch rows nicer if browser supports :has */
@supports selector(:has(*)){
  .row:has(#items_override),
  .row:has(#enable_bilingual){
    align-items:center !important;
  }
}

/* ---------- Auth & Account layouts (if used) ---------- */
#page-main{ margin-top:16px; }
#page-auth, #page-account{ margin-top:24px; }

.auth-wrapper{
  max-width:720px;
  margin:0 auto 32px;
}
.auth-card{ padding:24px; }

.auth-header h2{ margin:0 0 4px; }
.auth-subtitle{
  margin:0 0 16px;
  font-size:13px;
  color:var(--muted);
}

.auth-tabs{
  display:inline-flex;
  padding:4px;
  border-radius:999px;
  background:var(--elev);
  margin-bottom:16px;
}
.auth-tab{
  background:transparent;
  border:0;
  padding:6px 14px;
  border-radius:999px;
  font-size:13px;
  cursor:pointer;
  color:var(--muted);
}
.auth-tab.active{
  background:var(--accent);
  color:#fff;
}
.auth-back{
  margin-top:16px;
  font-size:13px;
}

.account-wrapper{
  max-width:960px;
  margin:0 auto 32px;
}
.account-card{ padding:24px; }

.account-header h2{ margin:0 0 4px; }
.account-header p{
  margin:0 0 16px;
  color:var(--muted);
}

.account-grid{
  display:grid;
  grid-template-columns:1.1fr 1.2fr;
  gap:20px;
}
@media (max-width: 800px){
  .account-grid{ grid-template-columns:1fr; }
}

.acc-usage{
  background:var(--elev);
  padding:10px 12px;
  border-radius:10px;
  font-size:12px;
  max-height:220px;
  overflow:auto;
}

.acc-videos{
  list-style:none;
  padding:0;
  margin:0;
}
.acc-videos li{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:6px 0;
  border-bottom:1px solid rgba(148,163,184,.25);
}
.acc-videos li:last-child{ border-bottom:0; }

.acc-videos a{
  color:#60a5fa;
  text-decoration:none;
  font-size:13px;
}
.acc-videos a:hover{ text-decoration:underline; }

/* ---------- Desktop compact tuning (non-mobile only) ---------- */
@media (min-width: 641px){
  .toolbar button{
    min-height:34px;
    padding:6px 10px;
    font-size:13px;
    border-radius:8px;
  }

  #btnActivate{
    background:transparent;
    color:var(--txt);
    border:1px solid var(--border);
  }
  #btnActivate:hover{ background:var(--elev); }

  input, select{
    height:38px;
    padding:6px 10px;
    border-radius:10px;
  }

  #llm_items_basic{ max-width:140px; }
}

/* ---------- Responsive (tablet & mobile) ---------- */
@media (max-width: 1024px){
  .grid{ grid-template-columns:1fr !important; }
  .row > label{ flex:1 1 100% !important; }
  .card{ padding:16px !important; }
}

@media (max-width: 640px){
  .row{
    flex-direction:column !important;
    align-items:stretch !important;
  }

  button{
    min-height:44px;
    padding:12px 14px;
  }

  input, select{
    padding:12px 14px;
    font-size:16px;
  }

  .toolbar button{ flex:1 1 48%; }

  .log-view{
    min-height:140px;
    max-height:50vh;
  }

  .busy-panel{
    width:min(96vw, 360px);
    padding:16px;
  }
  .ring{ width:100px; height:100px; }
  .ring svg{ width:100px; height:100px; }
}

@media (max-width: 480px){
  /* keep very small phones stable */
}

@media (max-width: 380px){
  body{ overflow-x:hidden; }
  .toolbar{ gap:6px; }
}


/* ===== Toolbar: Start/Stop icon-only big buttons ===== */
.toolbar{
  display:flex;
  align-items:center;
  gap:12px;
  margin: 8px 0 16px;
}

/* base button */
.toolbar-btn.icon-only{
  width: 58px;
  height: 58px;
  border-radius: 16px;
  display:inline-flex;
  align-items:center;
  justify-content:center;

  border: 1px solid rgba(0,0,0,0.08);
  background: rgba(255,255,255,0.92);

  cursor:pointer;
  transition: transform .08s ease, box-shadow .12s ease, background .12s ease, opacity .12s ease;
}

/* icon size */
.toolbar-btn.icon-only .btn-ico{
  font-size: 28px;
  line-height: 1;
}

/* START (green) */
.toolbar-btn.run-btn{
  background: rgba(16,185,129,0.12);
  border-color: rgba(16,185,129,0.38);
}
.toolbar-btn.run-btn .btn-ico{
  color: #10b981;
}

/* STOP (red) */
.toolbar-btn.stop-btn{
  background: rgba(239,68,68,0.12);
  border-color: rgba(239,68,68,0.38);
}
.toolbar-btn.stop-btn .btn-ico{
  color: #ef4444;
}

/* hover/active */
.toolbar-btn.icon-only:hover{
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(0,0,0,0.08);
}
.toolbar-btn.icon-only:active{
  transform: translateY(0);
  box-shadow: 0 6px 14px rgba(0,0,0,0.06);
}

/* disabled */
.toolbar-btn.icon-only:disabled{
  opacity: .5;
  cursor: not-allowed;
  box-shadow: none;
}


/* ===== Toolbar: icon-only Start/Stop (final fix) ===== */
.toolbar{
  display:flex;
  align-items:center;
  gap:12px;
  margin: 8px 0 16px;
}

/* اگر از نسخه‌های قبلی btn-label باقی موند، فقط در toolbar مخفی شود */
.toolbar .btn-label{
  display:none !important;
}

/* base icon-only button */
.toolbar-btn.icon-only{
  width: 60px;
  height: 60px;
  border-radius: 16px;

  display:inline-flex;
  align-items:center;
  justify-content:center;

  padding: 0;
  border: 1px solid rgba(0,0,0,0.08);
  background: rgba(255,255,255,0.92);

  cursor:pointer;
  transition: transform .08s ease, box-shadow .12s ease, background .12s ease, opacity .12s ease;
}

/* آیکن دقیقاً وسط */
.toolbar-btn.icon-only .btn-ico{
  display:flex;
  align-items:center;
  justify-content:center;
  width: 100%;
  height: 100%;
  line-height: 1;
  font-size: 30px;
}

/* مثلث کمی بصری بهتر وسط می‌نشیند */
.toolbar-btn.icon-only .play-ico{
  transform: translateX(1px);
}

/* START (green - بهتر و شیک‌تر) */
.toolbar-btn.run-btn{
  background: rgba(34,197,94,0.14);
  border-color: rgba(34,197,94,0.45);
}
.toolbar-btn.run-btn .btn-ico{
  color: #22c55e;
}

/* STOP (red) */
.toolbar-btn.stop-btn{
  background: rgba(239,68,68,0.14);
  border-color: rgba(239,68,68,0.45);
}
.toolbar-btn.stop-btn .btn-ico{
  color: #ef4444;
}

/* hover/active */
.toolbar-btn.icon-only:hover{
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(0,0,0,0.08);
}
.toolbar-btn.icon-only:active{
  transform: translateY(0);
  box-shadow: 0 6px 14px rgba(0,0,0,0.06);
}

/* disabled */
.toolbar-btn.icon-only:disabled{
  opacity: .5;
  cursor: not-allowed;
  box-shadow: none;
}


/* ===== Final, unbeatable Start/Stop toolbar styling ===== */
.toolbar{
  display:flex;
  align-items:center;
  gap: 12px;
  margin: 8px 0 16px;
}

/* Nuclear text-kill: اگر app.js متن تزریق کند، دیده نشود */
#btnRun, #btnStop{
  font-size: 0 !important;
  color: transparent !important;
}

/* Base icon-only button */
.toolbar-btn.icon-only{
  width: 60px !important;
  height: 60px !important;
  border-radius: 16px;
  padding: 0 !important;

  display:inline-flex !important;
  align-items:center !important;
  justify-content:center !important;

  border: 1px solid rgba(0,0,0,0.08);
  background: rgba(255,255,255,0.92);

  cursor:pointer;
  transition: transform .08s ease, box-shadow .12s ease, background .12s ease, opacity .12s ease;
}

/* Icon wrapper همیشه وسط */
.toolbar-btn.icon-only .btn-ico{
  display:inline-flex !important;
  align-items:center !important;
  justify-content:center !important;
  width: 100%;
  height: 100%;
}

/* START */
.toolbar-btn.run-btn{
  background: rgba(34,197,94,0.14) !important;
  border-color: rgba(34,197,94,0.48) !important;
}
.toolbar-btn.run-btn .ico-play{
  fill: #22c55e !important;
}

/* STOP */
.toolbar-btn.stop-btn{
  background: rgba(239,68,68,0.14) !important;
  border-color: rgba(239,68,68,0.48) !important;
}
.toolbar-btn.stop-btn .ico-stop{
  fill: #ef4444 !important;
}

/* Hover/Active */
.toolbar-btn.icon-only:hover{
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(0,0,0,0.08);
}
.toolbar-btn.icon-only:active{
  transform: translateY(0);
  box-shadow: 0 6px 14px rgba(0,0,0,0.06);
}

/* Disabled */
.toolbar-btn.icon-only:disabled{
  opacity: .5;
  cursor: not-allowed;
  box-shadow: none;
}


/* ===== Sticky header + toolbar ===== */

/* Header sticks to top */
.app-header{
  position: sticky;
  top: 0;
  z-index: 1000;
  background: inherit; /* اگر theme داری */
}

/* Toolbar sticks right under header */
.toolbar{
  position: sticky;
  top: 64px; /* ارتفاع تقریبی header */
  z-index: 999;
  background: inherit;
  padding-top: 6px;
  padding-bottom: 6px;
}

/* اگر پس‌زمینه theme گاهی transparent است، این کمک می‌کند */
.app-header,
.toolbar{
  backdrop-filter: blur(6px);
}

/* جلوگیری از اینکه محتوا زیر sticky ها بره */
#page-main{
  scroll-margin-top: 120px;
}

/* Mobile fine-tune */
@media (max-width: 640px){
  .toolbar{
    top: 58px;
  }
}

/* =========================
   HERO (Google-like)
   ========================= */
.hero{
  display:flex;
  justify-content:center;
  padding:42px 16px 20px;
}
.hero-inner{
  width:min(920px, 100%);
  text-align:center;
}
.brand{
  font-size:56px;
  font-weight:800;
  letter-spacing:2px;
  margin:10px 0 22px;
}
.search-row{
  display:flex;
  gap:12px;
  align-items:center;
  justify-content:center;
  flex-wrap:wrap;
}

.search-wrap{
  flex: 1 1 520px;
  display:flex;
  align-items:center;
  background:var(--card);
  border:1px solid var(--border);
  border-radius:999px;
  padding:10px 14px;
  box-shadow:var(--shadow);
}
.search-wrap:focus-within{
  border-color:#30384f;
}

.search-input{
  width:100%;
  border:none;
  outline:none;
  background:transparent;
  color:var(--txt);
  font-size:16px;
  padding:6px 4px;
}

.search-actions{
  display:flex;
  gap:10px;
}

.hero-filters{
  margin-top:16px;
  display:grid;
  grid-template-columns:repeat(4, minmax(0, 1fr));
  gap:10px;
}
.hero-filters label{
  text-align:left;
}

/* Premium locked visuals */
.premium-locked{
  opacity:0.55;
  filter:grayscale(0.2);
}
.premium-locked .search-input,
.search-input:disabled{
  cursor:not-allowed;
}

/* Mobile */
@media (max-width: 720px){
  .brand{ font-size:40px; }
  .hero-filters{ grid-template-columns:repeat(2, minmax(0, 1fr)); }
  .search-wrap{ flex-basis: 100%; }
  .search-actions{ width:100%; justify-content:center; }
}


/* Hide legacy Run button (Generate replaces it) */
.hidden {
  display: none !important;
}

/* Fix: hidden must always win even against toolbar icon-only !important rules */
.toolbar-btn.hidden,
.toolbar-btn.icon-only.hidden,
button.hidden {
  display: none !important;
}


/* =========================
   Centered app content (Advanced + Outputs)
   ========================= */

.app-center {
  display: flex;
  justify-content: center;
  padding: 0 16px 32px;
}

.app-center-inner {
  width: min(920px, 100%);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Account dropdown */
.account-dd{
  position: relative;
  display: inline-flex;
  align-items: center;
}

.avatar-btn{
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.avatar-btn:hover{ background: var(--elev); }

.avatar-img{
  width: 32px;
  height: 32px;
  border-radius: 999px;
  object-fit: cover;
  display: block;
}

.avatar-fallback{
  width: 32px;
  height: 32px;
  border-radius: 999px;
  display: none; /* فقط وقتی img لود نشه */
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.account-menu{
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  min-width: 180px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 8px;
  z-index: 2000;
}

.account-item{
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--txt);
  padding: 10px 10px;
  border-radius: 10px;
  cursor: pointer;
  display: block;
}
.account-item:hover{ background: var(--elev); }

.account-sep{
  border: 0;
  border-top: 1px solid var(--border);
  margin: 6px 0;
}

/* Modal */
.modal{
  position: fixed;
  inset: 0;
  z-index: 5000;
}

.modal.hidden{ display: none; }

.modal-backdrop{
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.35);
  backdrop-filter: blur(6px);
}

.modal-dialog{
  position: relative;
  margin: 72px auto;
  width: min(920px, calc(100vw - 24px));
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  max-height: calc(100vh - 120px);
  display: flex;
  flex-direction: column;
}

.modal-header{
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px;
  border-bottom: 1px solid var(--border);
}

.modal-title{
  font-size: 14px;
  font-weight: 600;
  color: var(--txt);
}

.modal-close{
  border: 1px solid var(--border);
  background: transparent;
  color: var(--txt);
  width: 34px;
  height: 34px;
  border-radius: 10px;
  cursor: pointer;
}

.modal-body{
  padding: 14px;
  overflow: auto;
}

/* وقتی مودال بازه، اسکرول صفحه قفل شود */
body.modal-open{
  overflow: hidden;
}

/* موبایل */
@media (max-width: 520px){
  .modal-dialog{
    margin: 18px auto;
    max-height: calc(100vh - 36px);
  }
}

.hero .search-wrap{
  border: 1px solid rgba(255,255,255,0.20);
  border-radius: 999px;
  padding: 2px;
}

html[data-theme="light"] .hero .search-wrap{
  border-color: rgba(0,0,0,0.20);
}

.hero .search-wrap:focus-within{
  border-color: rgba(59,130,246,0.75);
}

/* Prevent horizontal scroll caused by long whoami text */
.app-header,
.header-left,
.header-right,
.brand,
.brand-link{
  min-width: 0; /* critical for flex items to shrink */
}

.brand-link{
  max-width: 100%;
}

/* Make whoami shrink + truncate instead of pushing layout */
#whoami.whoami{
  display: inline-block;
  max-width: 160px;          /* می‌تونی 120/180 تنظیم کنی */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 0 1 auto;
}

/* Optional: if header-right buttons are many, allow it to shrink too */
.header-right{
  flex: 0 1 auto;
}
.header-left{
  flex: 1 1 auto;
}
