/* Responsive & touch layer — loaded last on every page.
   DC templates keep their inline styles (locked by studio.test.mjs), so layout fixes live here. */

html{-webkit-text-size-adjust:100%;text-size-adjust:100%}
:is(button,a,select,summary,[role=button],[role=tab]){-webkit-tap-highlight-color:transparent;touch-action:manipulation}

/* ---------- Desktop / shared polish ---------- */
.ava-shell [role=tablist][aria-label="بخش‌های تنظیم"],.ava-shell [role=tablist][aria-label="ابزارهای متن"]{scroll-behavior:smooth}
.portal-footer a{padding-block:6px}
.side-nav{scrollbar-width:none}
.side-nav::-webkit-scrollbar{display:none}
/* The sticky TTS inspector scrolls internally; leave room so the support button never covers its last controls. */
@media (min-width:960px){.ava-shell aside:is([aria-label="تنظیمات"],.tts-project-settings)>div:last-child{padding-bottom:88px!important}}

/* ---------- Tablet & phone ---------- */
@media (max-width:959px){
  /* iOS zooms into fields under 16px; keep every editable field at 16px+. */
  :is(input:not([type=range],[type=checkbox],[type=radio],[type=color],[type=file],[aria-label="نام پروژه"],[aria-label="نام تازه"]),select){font-size:16px!important}
  :is(.portal-page,.support-chat) textarea{font-size:16px!important}

  /* Header (studio) */
  .ava-header{height:64px!important;gap:8px!important}
  .ava-header .appearance-toggle{width:40px;height:40px}
  .ava-header .header-account-link{display:inline-flex!important;align-items:center;min-height:40px;padding:8px 12px!important;font-size:12.5px!important}
  .ava-header .header-account-user span{font-size:12.5px}

  /* Portal header: brand · theme · account · menu (same order as the studio header) */
  .portal-header>.appearance-toggle{order:2}
  .portal-header>.header-account-user,.portal-header>#plans-account-link{order:3;min-height:40px;display:inline-flex;align-items:center}
  .portal-header>.mobile-menu-toggle{order:4}

  /* Panels: keep section navigation visible as a scrollable chip bar */
  .panel-shell{display:block!important;margin-top:12px!important;padding:0 16px!important}
  .panel-sidebar{display:block!important;position:sticky;top:0;z-index:20;margin:0 -16px 20px!important;padding:8px 16px;background:color-mix(in srgb,var(--appearance-bg,#0b0b0d) 88%,transparent);backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px);border-bottom:1px solid var(--appearance-border)}
  .panel-sidebar>:not(.side-nav){display:none!important}
  .panel-sidebar .side-nav{display:flex;flex-direction:row;gap:6px;overflow-x:auto;padding:2px 0;-webkit-mask-image:linear-gradient(to left,transparent 0,#000 24px);mask-image:linear-gradient(to left,transparent 0,#000 24px)}
  .panel-sidebar .side-nav a{flex:none;white-space:nowrap;font-size:13px;min-height:40px;padding:8px 14px;border-radius:999px;display:inline-flex;align-items:center;gap:6px}
  .panel-sidebar .side-nav a[aria-current=page]{box-shadow:none;background:color-mix(in srgb,var(--acc,var(--coral,#ff6b4a)) 16%,var(--appearance-surface));color:var(--appearance-text)}
  .panel-sidebar .side-nav .icon{width:16px;height:16px}

  /* Floating support: smaller, never hides the last lines of a page */
  .floating-support{width:48px!important;height:48px!important}
  .floating-support svg{width:22px!important;height:22px!important}
  .portal-page main{padding-bottom:72px}
  
  /* Generic touch targets inside the studio */
  .ava-shell main button:not([title]):not(.stt-vocab-chip button):not([aria-hidden=true] button){min-height:40px}
  .ava-shell main [role=tab]{min-height:40px}
  .ava-shell input[type=range]{height:32px;margin-block:0}
  .ava-shell .tts-speaker-pill{min-height:40px}
  .ava-shell .tts-speaker-pill .tts-speaker-select{min-height:34px}
  .ava-shell .stt-vocab-chip button{position:relative;min-width:24px;min-height:24px}
  .ava-shell .stt-vocab-chip button::after{content:'';position:absolute;inset:-10px}

  /* Horizontal tab strips: fade the clipped edge so it reads as scrollable */
  .ava-shell [role=tablist][aria-label="بخش‌های تنظیم"],.ava-shell [role=tablist][aria-label="ابزارهای متن"]{-webkit-mask-image:linear-gradient(to left,transparent 0,#000 32px);mask-image:linear-gradient(to left,transparent 0,#000 32px);padding-inline-end:28px!important}

  /* Sticky players: one compact row instead of a quarter of the screen */
  .ava-shell section:is([aria-label="پخش و خط زمان"],[aria-label="پخش صدا"]){top:70px!important;padding:10px 12px!important;gap:8px!important;border-radius:18px!important}
  .ava-shell section:is([aria-label="پخش و خط زمان"],[aria-label="پخش صدا"])>div:first-child{gap:10px!important}
  .ava-shell section[aria-label="پخش و خط زمان"]>div:first-child>div[style*="flex: 1 1 40px"]{flex:1 1 0!important}
  .ava-shell section[aria-label="پخش و خط زمان"]>div:first-child>button:first-child{width:44px!important;height:44px!important}
  .ava-shell section[aria-label="پخش و خط زمان"]>div:first-child>button:last-child{padding:11px 18px!important;font-size:14.5px!important}
  .ava-shell section[aria-label="پخش و خط زمان"] div[style*="height: 34px"]{height:28px!important}

  /* Studio title row: status on its own line, actions share the next one */
  .ava-shell div[style*="padding: 22px clamp(12px, 2.5vw, 32px) 130px"]>div:first-child>div[role=status]{flex:1 1 100%}
  .ava-shell div[style*="padding: 22px clamp(12px, 2.5vw, 32px) 130px"]>div:first-child>button{flex:1 1 auto;justify-content:center;min-height:48px}

  /* Projects: tidy action grid, primary action full width */
  .ava-shell article>div[style*="margin-top: auto"]{display:grid!important;grid-template-columns:repeat(2,minmax(0,1fr))}
  .ava-shell article>div[style*="margin-top: auto"]>button{width:100%;justify-content:center;text-align:center}
  .ava-shell article>div[style*="margin-top: auto"]>button:first-child{grid-column:1/-1}

  /* History: narrower badge, actions as a two-column grid */
  .ava-shell ol>li[style*="grid-template-columns: auto minmax("]{grid-template-columns:40px minmax(0,1fr)!important;gap:12px!important;padding:16px!important}
  .ava-shell ol>li[style*="grid-template-columns: auto minmax("]>span:first-child{width:40px!important;height:40px!important;border-radius:12px!important}
  .ava-shell ol>li[style*="grid-template-columns: auto minmax("]>div>div:last-child:has(>button){display:grid!important;grid-template-columns:repeat(2,minmax(0,1fr))}
  .ava-shell ol>li[style*="grid-template-columns: auto minmax("]>div>div:last-child>button{width:100%;white-space:normal;line-height:1.5}
  .ava-shell ol>li[style*="grid-template-columns: auto minmax("]>div>div:last-child>button:last-child:nth-child(odd){grid-column:1/-1}
}

/* ---------- Phone ---------- */
@media (max-width:640px){
  /* Home: hero content starts at the top instead of under an empty canvas */
  .ava-shell main>div[style*="max-width: 1320px"]{gap:56px!important;padding-top:12px!important}
  .ava-shell main section:has(>canvas){min-height:0!important;align-items:flex-start!important;padding:32px 20px 20px!important;border-radius:24px!important}
  .ava-shell main section:has(>canvas)>div:last-child{gap:28px!important}
  .ava-shell main section:has(>canvas) h1{font-size:clamp(38px,11.5vw,54px)!important;line-height:1.2!important}
  .ava-shell main section:has(>canvas) h1+p{font-size:15.5px!important;line-height:1.9!important}
  .ava-shell main section:has(>canvas) div:has(>button[data-site-feature=tts]){display:grid!important;grid-template-columns:1fr;gap:10px!important}
  .ava-shell main section:has(>canvas) div:has(>button[data-site-feature=tts])>button{justify-content:center;width:100%;padding:14px 20px!important}
  .ava-shell main section:has(>canvas)>div:last-child>div:last-child{max-width:none!important;flex-basis:100%!important;padding:16px!important;border-radius:20px!important}
  .ava-shell main section:has(>canvas)>div:last-child>div:last-child>p{font-size:17px!important}
  .ava-shell main section:has(>canvas) span[style*="margin-inline-start: auto"]{flex:1 1 100%;margin-inline-start:0!important;white-space:normal!important;text-align:center;line-height:1.7}

  /* Home: tool cards */
  .ava-shell main section div[style*="minmax(min(100%, 460px), 1fr)"]>button>span:first-child{height:170px!important}
  .ava-shell main section div[style*="minmax(min(100%, 460px), 1fr)"]>button>span:last-child{padding:20px!important;gap:12px!important}
  .ava-shell main section div[style*="minmax(min(100%, 460px), 1fr)"]>button{border-radius:22px!important}

  /* Home: voices as a two-column grid */
  .ava-shell main section div[style*="minmax(min(100%, 190px), 1fr)"]{grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:10px!important}
  .ava-shell main section div[style*="minmax(min(100%, 190px), 1fr)"]>button{padding:14px!important;gap:10px!important;border-radius:18px!important}

  /* Portal: readable sizes (portal.css drops several labels to 10–11px) */
  .portal-header{margin:0 16px!important;gap:8px!important}
  .metric-grid{grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:10px!important}
  .metric-grid>.metric:last-child:nth-child(odd){grid-column:1/-1}
  .metric{padding:14px!important}
  .metric-label,.metric-hint,.metric-value small{font-size:12px!important}
  .page-heading p,.setting-row p,.admin-banner,.activity-row .status,.art-footer span{font-size:12.5px!important}
  .activity-info strong,.setting-row strong{font-size:14px!important}
  .page-heading .btn{font-size:13px!important;min-height:40px}
  .portal-footer{font-size:13px!important;flex-wrap:wrap;justify-content:center;row-gap:4px}
  .portal-footer a{display:inline-flex;align-items:center;min-height:40px;padding-inline:4px}
  .portal-page main :is(small,.status,.table-foot span,.integration-card small){font-size:12px!important}
  .portal-page main summary{padding-block:10px}
  .portal-page main .table-action{min-height:40px}
  .quota-card>p{max-width:none!important;flex:1 1 140px}
  .btn{min-height:40px}

  /* Tables become labeled cards (labels set by mobile-navigation.js) */
  :is(.table-wrap,.subscription-table-wrap):has(>.portal-table){overflow:visible}
  .portal-table{white-space:normal!important;font-size:13px!important;min-width:0!important}
  .portal-table thead{display:none}
  .portal-table,.portal-table tbody,.portal-table tr,.portal-table td{display:block;width:100%}
  .portal-table tr{padding:6px 14px;margin-bottom:10px;border:1px solid var(--appearance-border);border-radius:16px;background:var(--appearance-surface)}
  .portal-table td{display:flex;align-items:center;justify-content:space-between;gap:12px;min-height:44px;padding:8px 0!important;border-bottom:1px solid var(--appearance-border)!important;text-align:left;overflow-wrap:anywhere}
  .portal-table td:last-child{border-bottom:0!important}
  .portal-table td[data-label]::before{content:attr(data-label);flex:none;color:var(--appearance-muted);font-size:12.5px;text-align:right}
  .portal-table td:first-child{justify-content:flex-start;text-align:right}
  .portal-table td:first-child::before{display:none}
  .portal-table td:empty{display:none}

  /* Plans */
  .public-plans .page-heading,.subscription-page .page-heading{flex-direction:column;align-items:flex-start!important}
  .subscription-plan ul{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));column-gap:12px}
}

/* ---------- Phone polish (second pass) ---------- */
@media (max-width:640px){
  /* Header: the guest login link was 11px (an inline <style> rule ties on specificity); logo and tool buttons reach 40px */
  .ava-header a.header-account-link{font-size:12.5px!important;min-height:40px}
  .ava-header>.ava-home-button{min-height:40px;padding-inline:4px}
  .ava-shell main select{min-height:40px}
  /* Studio micro-labels sat at 11–11.5px; raise to a readable 12px */
  .ava-shell main :is(span,small,p,label,button)[style*="font-size: 11px"],.ava-shell main :is(span,small,p,label,button)[style*="font-size: 11.5px"]{font-size:12px!important}
  .ava-shell main input:not([type=range],[type=checkbox],[type=radio],[type=file]){min-height:40px}

  /* Home: eight voices are enough on a phone; the full list is one tap away ("همهٔ گوینده‌ها در استودیو") */
  .ava-shell main section div[style*="minmax(min(100%, 190px), 1fr)"]>button:nth-child(n+9){display:none!important}

  /* Quota ring: its caption overflowed the circle */
  .quota-ring .ring-value{inset:14%;line-height:1.1;text-align:center}
  .quota-ring .ring-value small{display:block;max-width:100%;font-size:11px!important;line-height:1.35;white-space:normal;overflow-wrap:anywhere}

  /* Support button never sits on top of a page's primary action while a field is focused */
  body:has(input:focus,textarea:focus,select:focus) .floating-support{opacity:0;pointer-events:none}
}

/* ---------- Phone polish (third pass) ---------- */
@media (max-width:640px){
  /* Home plans: a swipeable row with the next card peeking, instead of three screen-tall cards stacked */
  .home-plan-grid{display:flex!important;gap:12px;overflow-x:auto;overscroll-behavior-x:contain;scroll-snap-type:x mandatory;scroll-padding-inline:16px;margin-inline:calc(-1 * clamp(14px,3vw,32px));padding:4px clamp(14px,3vw,32px) 14px;scrollbar-width:none}
  .home-plan-grid::-webkit-scrollbar{display:none}
  .home-plan-grid>.home-plan-card{flex:0 0 min(84%,320px);scroll-snap-align:center}
  .home-plan-grid>.home-plan-card:only-child{flex-basis:100%}
  .home-plan-card:hover{transform:none}

  /* Home speech-to-text card: the typed lines end in an ellipsis instead of a hard cut */
  .ava-shell main section button span[style*="ava-type"]{font-size:12.5px!important;text-overflow:ellipsis}
  .ava-shell main section button div:has(>span[style*="ava-type"])>span:first-child{display:none}
  .ava-shell main section button div:has(>div[style*="flex: 0 0 30%"]){gap:12px!important;padding-inline:20px!important}
  .ava-shell main section button div[style*="flex: 0 0 30%"]{flex-basis:22%!important}

  /* Inline links in short notices and form footers get a finger-sized hit area without moving the text */
  .portal-page main :is(p,.notice,.form-footer,.status-note) a:not(.btn){display:inline-block;padding-block:9px;margin-block:-9px}
  .demo-note{font-size:12.5px!important;line-height:1.8}
  .form-footer{font-size:13.5px!important}

  /* Charts: weekday labels were 10px */
  .chart-labels{font-size:11.5px!important}

  /* Portal footers clear the floating support button */
  .portal-footer{padding-bottom:calc(76px + env(safe-area-inset-bottom))!important}

  /* Mobile menu: account and support shortcuts under the page links (added by mobile-navigation.js) */
  .mobile-menu-extra{display:flex;flex-direction:column;gap:8px;margin-top:auto;padding-top:16px;border-top:1px solid var(--appearance-border)}
}
.mobile-menu-extra :is(a,button){box-sizing:border-box;display:flex;align-items:center;gap:12px;width:100%;min-height:46px;padding:12px 14px;border:1px solid var(--appearance-border);border-radius:12px;background:transparent;color:var(--appearance-text,#f3f2ef);font:inherit;text-align:right;text-decoration:none;cursor:pointer}
.mobile-menu-extra svg{width:20px;height:20px;flex:none;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round}
.mobile-menu-extra .mobile-menu-primary{background:var(--acc,var(--coral,#ff6b4a));border-color:transparent;color:var(--accent-ink,#140c09);font-weight:600;justify-content:center}
@media (min-width:960px){.mobile-menu-extra{display:none}}

/* Desktop header quota line was 10.5px */
@media (min-width:960px){.header-split-quota{font-size:11.5px}}

@media (max-width:340px){
  .ava-header .header-account-user{max-width:44px;padding:8px!important;justify-content:center}
  .ava-header .header-account-user span{display:none}
  .ava-shell main section div[style*="minmax(min(100%, 190px), 1fr)"]{grid-template-columns:1fr!important}
}

/* Support chat: a card on tablets, a full-screen sheet on phones (sized to the visible area, so the composer clears the keyboard) */
@media (min-width:641px) and (max-width:959px){
  .support-chat{left:max(12px,env(safe-area-inset-left))!important;right:max(12px,env(safe-area-inset-right));width:auto!important;max-width:none!important;bottom:max(76px,calc(env(safe-area-inset-bottom) + 68px))!important}
}
@media (max-width:640px){
  .support-chat{top:var(--chat-top,0)!important;left:0!important;right:0!important;bottom:auto!important;width:100%!important;max-width:none!important;height:var(--chat-vh,100dvh)!important;max-height:none!important;border:0!important;border-radius:0!important}
}

/* Short landscape phones: sticky players would cover everything */
@media (max-width:959px) and (max-height:540px){
  .panel-sidebar{position:static}
}

/* Touch feedback: phones have no hover, so give taps a visible press state */
@media (hover:none) and (pointer:coarse){
  :is(button,[role=button],[role=tab],a.btn,.side-nav a,.mobile-site-menu nav a):active{opacity:.82;transition:opacity .08s}
  :is(.floating-support):active{transform:scale(.94)}
}

/* Plans: the last notice clears the floating support button (bottom-left) on wide screens too */
@media (min-width:960px){.public-plans{margin-bottom:112px}}

/* Plans: the per-minute price under each paid plan's allowances */
.subscription-rate{margin:0 0 4px;font-size:13px;line-height:1.8;color:var(--appearance-muted)}
/* Header quota: the two allowances sit side by side in one compact pill instead of stacked */
.ava-header .header-quota{flex-direction:row;align-items:center;gap:0;inline-size:auto;block-size:44px;padding:5px 12px}
.ava-header .header-quota .header-quota-row{inline-size:150px}
.ava-header .header-quota .header-quota-row+.header-quota-row{margin-inline-start:12px;padding-inline-start:12px;border-inline-start:1px solid var(--appearance-border)}
