/**
 * Mobile polish for DMreach Web tool — sequential steps, console only when running.
 */

html.is-web-app,
html.is-web-app body {
  height: 100%;
  min-height: 100dvh;
}

body.is-web-app {
  overflow: hidden;
}

body.is-web-app .app-shell {
  height: calc(100dvh - var(--chrome-h, 44px));
  max-height: calc(100dvh - var(--chrome-h, 44px));
}

.ig-mobile-runbar {
  display: none;
}

@media (max-width: 900px) {
  body.is-web-app {
    --chrome-h: 48px;
  }

  body.is-web-app .window-chrome {
    height: var(--chrome-h);
    flex-basis: var(--chrome-h);
  }

  body.is-web-app .app-main {
    padding: 0.45rem 0.5rem 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
  }

  body.is-web-app #panel-instagram.studio-tab-panel.is-active {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1;
    overflow: hidden;
  }

  body.is-web-app .studio-layout {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  body.is-web-app .studio-layout > .studio-notice--alert:not(.hidden) {
    flex-shrink: 0;
    margin: 0 0.15rem;
    border-radius: 12px;
  }

  body.is-web-app .studio-columns {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    gap: 0;
    overflow: hidden;
    height: auto !important;
    grid-template-columns: none !important;
    grid-template-rows: none !important;
  }

  /* Console hidden until campaign runs */
  body.is-web-app:not(.is-ig-console) .studio-sidebar {
    display: none !important;
  }

  body.is-web-app.is-ig-console .studio-main {
    display: none !important;
  }

  body.is-web-app.is-ig-console .studio-sidebar {
    display: flex !important;
    flex: 1;
    flex-direction: column;
    min-height: 0;
    max-height: none !important;
    height: auto !important;
    overflow: hidden;
  }

  body.is-web-app.is-ig-console .renox-ig-log-panel {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    border-radius: 14px;
    margin: 0 0.1rem;
  }

  body.is-web-app.is-ig-console .renox-ig-log {
    flex: 1 !important;
    max-height: none !important;
    min-height: 0 !important;
    font-size: 0.78rem;
  }

  body.is-web-app .studio-main {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 14px;
    max-width: 520px;
    width: 100%;
    margin-inline: auto;
  }

  body.is-web-app .renox-ig-wizard,
  body.is-web-app .renox-ig-stage {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    height: auto !important;
    overflow: hidden;
  }

  body.is-web-app .renox-ig-pane.is-active:not([hidden]) {
    flex: 1;
    min-height: 0;
    display: flex !important;
    flex-direction: column;
    overflow: hidden;
    height: auto !important;
  }

  body.is-web-app .renox-ig-pane-head {
    flex-shrink: 0;
    padding: 0.85rem 0.95rem 0.35rem;
    text-align: center;
  }

  body.is-web-app .renox-ig-pane-head h3 {
    font-size: 1.1rem;
    margin: 0;
  }

  body.is-web-app .renox-ig-pane-head p {
    font-size: 0.8rem;
    margin: 0.25rem 0 0;
  }

  body.is-web-app .studio-pane-body {
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 0.85rem;
    display: flex;
    flex-direction: column;
  }

  /* Vertically center short step content — not for message/grow panes */
  body.is-web-app .studio-pane-body:not(.studio-pane-body--message):not(.studio-pane-body--grow)::before,
  body.is-web-app .studio-pane-body:not(.studio-pane-body--message):not(.studio-pane-body--grow)::after {
    content: '';
    flex: 1 1 0.75rem;
    min-height: 0.5rem;
  }

  body.is-web-app .studio-pane-body--message {
    justify-content: flex-start;
    padding: 0.35rem 0.85rem 0.85rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  body.is-web-app .renox-ig-pane-foot {
    flex-shrink: 0;
    display: flex;
    gap: 0.5rem;
    padding: 0.7rem 0.85rem calc(0.7rem + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(8, 8, 8, 0.96);
    backdrop-filter: blur(14px);
    z-index: 8;
  }

  body.is-web-app .renox-ig-pane-foot .renox-ig-btn {
    flex: 1;
    min-height: 46px;
    width: auto;
    justify-content: center;
  }

  /* One card at a time */
  body.is-web-app.is-mstep-session .ig-setup-card--target,
  body.is-web-app.is-mstep-target .ig-setup-card--session {
    display: none !important;
  }

  body.is-web-app .ig-setup-grid {
    display: block !important;
    grid-template-columns: none !important;
  }

  body.is-web-app .ig-setup-card {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding: 0.9rem;
    margin: 0;
    border-radius: 14px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.025);
  }

  body.is-web-app .ig-setup-card__head {
    margin-bottom: 0.75rem;
  }

  body.is-web-app .ig-session-block,
  body.is-web-app .ig-session-card,
  body.is-web-app .ig-target-preview,
  body.is-web-app .ig-pause-modes {
    max-width: 100%;
    overflow: hidden;
  }

  body.is-web-app .ig-message-stack {
    max-width: 100%;
    overflow: visible;
    gap: 0.75rem;
    flex: none;
    width: 100%;
    margin: 0;
  }

  body.is-web-app .ig-message-block {
    flex: none;
    width: 100%;
  }

  body.is-web-app #ig-message,
  body.is-web-app .ig-message-stack .renox-ig-textarea {
    display: block;
    width: 100%;
    min-height: 9.5rem;
    height: auto;
    max-height: none;
    flex: none;
    resize: vertical;
    font-size: 0.95rem;
    line-height: 1.5;
    padding: 0.85rem 0.95rem;
    box-sizing: border-box;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.04);
    color: #f4f4f5;
    -webkit-appearance: none;
    appearance: none;
  }

  body.is-web-app #ig-message:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.28);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.06);
  }

  body.is-web-app .ig-message-link-card {
    width: 100%;
    box-sizing: border-box;
    overflow: visible;
    padding: 0.85rem 0.9rem 0.95rem;
    border-radius: 12px;
  }

  body.is-web-app .ig-message-link-card__head {
    gap: 0.65rem;
    margin-bottom: 0.65rem;
  }

  body.is-web-app .ig-message-link-card__head p {
    font-size: 0.72rem;
  }

  body.is-web-app .msg-meta {
    font-size: 0.68rem;
    gap: 0.5rem;
  }

  body.is-web-app .ig-cookie-json,
  body.is-web-app textarea.ig-cookie-json {
    min-height: 28vh;
    max-height: 36vh;
    width: 100%;
    box-sizing: border-box;
    font-size: 0.8rem;
    line-height: 1.4;
    resize: vertical;
  }

  body.is-web-app .ig-session-block:has(#ig-session-account:not(.hidden)) .ig-cookie-json,
  body.is-web-app .ig-session-block:has(#ig-session-account:not(.hidden)) textarea.ig-cookie-json {
    min-height: 14vh;
    max-height: 20vh;
  }

  /* Keep save button reachable */
  body.is-web-app .ig-session-card__foot {
    position: sticky;
    bottom: 0;
    padding-top: 0.65rem;
    margin-top: 0.5rem;
    background: linear-gradient(180deg, transparent, rgba(14, 14, 14, 0.95) 30%);
  }

  body.is-web-app .ig-session-save-btn {
    width: 100%;
    min-height: 44px;
    justify-content: center;
  }

  body.is-web-app .ig-session-account,
  body.is-web-app .ig-target-preview__body,
  body.is-web-app .ig-summary-profile__body {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    max-width: 100%;
    overflow: hidden;
  }

  body.is-web-app .ig-session-account__meta,
  body.is-web-app .ig-target-preview__meta,
  body.is-web-app .ig-summary-profile__meta {
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
  }

  body.is-web-app .ig-session-account__bio,
  body.is-web-app .ig-target-preview__bio,
  body.is-web-app .ig-summary-profile__bio,
  body.is-web-app .ig-session-account__fullname,
  body.is-web-app .ig-target-preview__fullname {
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  body.is-web-app .ig-session-account__stats,
  body.is-web-app .ig-target-preview__stats,
  body.is-web-app .ig-summary-profile__stats {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.35rem;
    width: 100%;
  }

  body.is-web-app .ig-session-account__stats > div,
  body.is-web-app .ig-target-preview__stats > div,
  body.is-web-app .ig-summary-profile__stats > div {
    min-width: 0;
    text-align: center;
    padding: 0.4rem 0.2rem;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
  }

  body.is-web-app .ig-target-preview {
    width: 100%;
    box-sizing: border-box;
    border-radius: 12px;
    overflow: hidden;
  }

  body.is-web-app .ig-target-preview__avatar-wrap,
  body.is-web-app .ig-session-account__avatar-wrap {
    flex-shrink: 0;
  }

  body.is-web-app .ig-pause-modes {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 0.75rem;
  }

  body.is-web-app .ig-pause-mode {
    width: 100%;
    box-sizing: border-box;
    padding: 0.95rem;
  }

  body.is-web-app .renox-ig-summary,
  body.is-web-app .ig-summary-profile {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
  }

  body.is-web-app .renox-ig-pane-foot--start {
    flex-wrap: wrap;
  }

  body.is-web-app .renox-ig-pane-foot--start .renox-ig-btn {
    flex: 1 1 calc(50% - 0.25rem);
  }

  body.is-web-app .renox-ig-pane-foot--start .renox-ig-btn--accent,
  body.is-web-app .renox-ig-pane-foot--start .renox-ig-btn--danger {
    flex: 1 1 100%;
  }

  /* Floating stop bar when console is up */
  body.is-web-app.is-ig-console .ig-mobile-runbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-shrink: 0;
    padding: 0.7rem 0.85rem calc(0.7rem + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(8, 8, 8, 0.97);
    backdrop-filter: blur(14px);
    z-index: 20;
  }

  body.is-web-app .ig-mobile-runbar__meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    font-size: 0.88rem;
  }

  body.is-web-app .ig-mobile-runbar__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: none;
    animation: none;
  }

  body.is-web-app .ig-mobile-runbar .renox-ig-btn {
    flex-shrink: 0;
    min-width: 110px;
    min-height: 42px;
    justify-content: center;
  }

  body.is-web-app .ig-mobile-runbar .renox-ig-btn[hidden] {
    display: none !important;
  }

  body.is-web-app:not(.is-ig-running) .ig-mobile-runbar__dot {
    background: #a1a1aa;
    animation: none;
    box-shadow: none;
  }

  body.is-web-app .studio-run-stats {
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
  }

  body.is-web-app .auth-side { display: none; }

  /* —— Premium tool chrome & surfaces —— */
  body.is-web-app {
    font-family: var(--font);
  }

  body.is-web-app .window-chrome {
    background: rgba(0, 0, 0, 0.92);
    border-bottom-color: rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(16px);
  }

  body.is-web-app .window-chrome-title strong {
    font-family: var(--display);
    font-weight: 650;
    letter-spacing: -0.03em;
    font-size: 0.95rem;
  }

  body.is-web-app .window-chrome-mark {
    width: 1.4rem;
    height: 1.4rem;
    border-radius: 0.4rem;
  }

  body.is-web-app .win-ctrl {
    width: 2.15rem;
    height: 2.15rem;
    border-radius: 0.55rem;
  }

  body.is-web-app .app-main {
    padding: 0.55rem 0.55rem 0;
  }

  body.is-web-app .studio-main {
    border-radius: 18px;
    border: 1px solid rgba(255, 255, 255, 0.09);
    background:
      linear-gradient(180deg, rgba(255, 255, 255, 0.045) 0%, rgba(255, 255, 255, 0.012) 28%, rgba(8, 8, 8, 0.92) 100%);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
    max-width: 540px;
  }

  body.is-web-app .renox-ig-pane-head {
    padding: 1.05rem 1.05rem 0.45rem;
    text-align: left;
  }

  body.is-web-app .renox-ig-pane-head h3 {
    font-family: var(--display);
    font-size: 1.28rem;
    font-weight: 650;
    letter-spacing: -0.035em;
  }

  body.is-web-app .renox-ig-pane-head p {
    font-size: 0.82rem;
    line-height: 1.4;
    color: var(--text-muted);
    margin-top: 0.3rem;
  }

  body.is-web-app .studio-pane-body {
    padding-inline: 1rem;
  }

  body.is-web-app .renox-ig-pane-foot {
    padding: 0.8rem 1rem calc(0.85rem + env(safe-area-inset-bottom, 0px));
    border-top-color: rgba(255, 255, 255, 0.07);
    background: rgba(6, 6, 6, 0.94);
    gap: 0.55rem;
  }

  body.is-web-app .renox-ig-pane-foot .renox-ig-btn {
    min-height: 48px;
    border-radius: 12px;
    font-weight: 650;
    font-size: 0.92rem;
  }

  body.is-web-app .renox-ig-btn--primary,
  body.is-web-app .renox-ig-btn--accent {
    box-shadow: 0 8px 24px rgba(255, 255, 255, 0.08);
  }

  body.is-web-app .ig-pause-mode {
    border-radius: 14px;
    border-color: rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.03);
  }

  body.is-web-app .ig-session-card,
  body.is-web-app .ig-target-preview,
  body.is-web-app .ig-setup-card {
    border-radius: 14px;
    border-color: rgba(255, 255, 255, 0.09);
  }

  body.is-web-app .renox-ig-field > span {
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
  }

  body.is-web-app .renox-ig-input-wrap,
  body.is-web-app .renox-ig-textarea {
    border-radius: 12px;
    border-color: rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.035);
  }

  body.is-web-app .ig-message-link-card {
    border-radius: 14px;
    border-color: rgba(255, 255, 255, 0.09);
    background: rgba(255, 255, 255, 0.03);
  }

  body.is-web-app.is-ig-console .renox-ig-log-panel {
    border-radius: 18px;
    border: 1px solid rgba(255, 255, 255, 0.09);
    background: rgba(8, 8, 8, 0.95);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
  }

  body.is-web-app.is-ig-console .ig-mobile-runbar {
    margin: 0 0.35rem calc(0.35rem + env(safe-area-inset-bottom, 0px));
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(10, 10, 10, 0.96);
    padding: 0.75rem 0.9rem;
  }

  /* —— Settings (in-tool) —— */
  body.is-web-app .settings-view {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: flex;
    flex-direction: column;
    background:
      radial-gradient(ellipse 80% 40% at 50% 0%, rgba(255, 255, 255, 0.05), transparent 55%),
      #050505;
    overflow: hidden;
  }

  body.is-web-app .settings-view[hidden] {
    display: none !important;
  }

  body.is-web-app .settings-view__nav {
    flex-shrink: 0;
    border-right: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    padding: 0.85rem 1rem 0.75rem;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(16px);
  }

  body.is-web-app .settings-view__brand {
    padding: 0.15rem 0.15rem 0.85rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
  }

  body.is-web-app .settings-view__kicker {
    margin: 0;
    font-size: 0.68rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-dim);
  }

  body.is-web-app .settings-view__title {
    margin: 0.2rem 0 0;
    font-family: var(--display);
    font-size: 1.35rem;
    font-weight: 650;
    letter-spacing: -0.035em;
  }

  body.is-web-app .settings-view__tabs {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 0.35rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 0.15rem;
  }

  body.is-web-app .settings-view__tabs::-webkit-scrollbar {
    display: none;
  }

  body.is-web-app .settings-view__tab {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 0.55rem 0.85rem;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: transparent;
    font-size: 0.78rem;
    font-weight: 600;
  }

  body.is-web-app .settings-view__tab.is-active {
    background: #fff;
    color: #0a0a0a;
    border-color: #fff;
  }

  body.is-web-app .settings-view__back {
    margin-top: 0.75rem;
    width: 100%;
    min-height: 44px;
    border-radius: 12px;
    justify-content: center;
    font-weight: 600;
  }

  body.is-web-app .settings-view__main {
    flex: 1;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding: 1rem 1rem calc(1.25rem + env(safe-area-inset-bottom, 0px));
  }

  body.is-web-app .settings-panel__head h3 {
    font-family: var(--display);
    font-size: 1.15rem;
    letter-spacing: -0.03em;
  }

  body.is-web-app .settings-panel__head p {
    font-size: 0.84rem;
    color: var(--text-muted);
  }

  body.is-web-app .settings-rows,
  body.is-web-app .settings-cards {
    gap: 0.65rem;
  }

  body.is-web-app .settings-row,
  body.is-web-app .settings-info-card {
    border-radius: 14px;
    border-color: rgba(255, 255, 255, 0.09);
    background: rgba(255, 255, 255, 0.03);
    padding: 0.95rem 1rem;
  }

  body.is-web-app .settings-btn {
    min-height: 42px;
    border-radius: 11px;
    font-weight: 600;
  }

  body.is-web-app .settings-danger-box {
    border-radius: 14px;
  }
  body.is-web-app .auth-layout { grid-template-columns: 1fr; }
  body.is-web-app .auth-panel {
    padding: 1.4rem 1.1rem calc(1.4rem + env(safe-area-inset-bottom, 0px));
    width: 100%;
    max-width: none;
  }
}

@keyframes ig-run-pulse {
  0% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.4); }
  70% { box-shadow: 0 0 0 8px rgba(74, 222, 128, 0); }
  100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); }
}

@media (max-width: 560px) {
  body.is-web-app .ig-cookie-json,
  body.is-web-app textarea.ig-cookie-json {
    min-height: 32vh;
    max-height: 40vh;
  }
}
