/* MaqolaAI shared responsive layer.
   Loaded after each page's inline styles so these rules remain the final word. */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-width: 0;
}

img,
video,
iframe,
canvas,
svg {
  max-width: 100%;
}

button,
a,
input,
select,
textarea {
  touch-action: manipulation;
}

@media (max-width: 900px) {
  /* Landing page */
  .page-home {
    padding-top: 58px;
  }

  .page-home .nav {
    height: 58px;
  }

  .page-home .nav-c {
    padding-inline: 16px;
  }

  .page-home section {
    padding: 68px 18px;
  }

  .page-home .hero {
    min-height: auto;
    padding: 54px 18px 46px;
  }

  .page-home .hero-content {
    transform: none;
  }

  .page-home .hero-title {
    margin-bottom: 22px !important;
  }

  .page-home .how-header {
    margin-bottom: 38px;
  }

  .page-home .feat-grid {
    gap: 14px;
    margin-top: 36px;
  }

  .page-home .feat-card,
  .page-home .step {
    padding: 26px 22px;
  }

  .page-home .footer-top {
    gap: 34px;
  }

  /* Login / registration */
  html.page-auth-root,
  .page-auth {
    min-height: 100%;
    height: auto;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .page-auth .wrapper {
    min-height: 100dvh;
    height: auto;
  }

  .page-auth .form-side {
    min-height: 100dvh;
    justify-content: flex-start;
    padding: 94px 24px 36px;
  }

  .page-auth .auth-container {
    margin-block: auto;
  }

  /* Profile editor */
  .page-profile-edit .auth-shell,
  .page-profile-edit .form-panel {
    min-height: 100dvh;
  }

  /* Studio: on a phone, writing and preview are two real tabs. */
  html.page-studio-root,
  .page-studio {
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }

  .page-studio .topbar {
    height: auto;
    min-height: 96px;
    padding: 8px 12px 7px;
    gap: 6px;
    flex-wrap: wrap;
    align-content: center;
  }

  .page-studio .tb-logo {
    font-size: 15px;
    gap: 6px;
  }

  .page-studio .tb-logo-icon {
    width: 30px;
    height: 30px;
  }

  .page-studio .tb-sep,
  .page-studio .tb-title {
    display: none;
  }

  .page-studio .tb-right {
    margin-left: auto;
    gap: 5px;
    min-width: 0;
  }

  .page-studio .tb-token {
    max-width: 112px;
    padding: 5px 8px;
    font-size: 10px;
    gap: 4px;
  }

  .page-studio .tb-token span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .page-studio .tb-buy-btn {
    width: 34px;
    height: 34px;
    padding: 0;
    justify-content: center;
    font-size: 0;
    border-radius: 9px;
  }

  .page-studio .tb-buy-btn i {
    font-size: 13px;
  }

  .page-studio .tb-user {
    width: 34px;
    height: 34px;
  }

  .page-studio .tb-mid {
    order: 3;
    flex: 0 0 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .page-studio .tb-tab {
    justify-content: center;
    min-height: 34px;
    padding: 7px 12px;
  }

  .page-studio .app-body {
    display: block;
    min-height: 0;
    overflow: hidden;
  }

  .page-studio .left-panel,
  .page-studio .right-panel {
    width: 100%;
    height: 100%;
    max-width: none;
    border: 0;
    animation: none;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .page-studio .left-panel {
    display: flex;
  }

  .page-studio .right-panel {
    display: none;
  }

  .page-studio .lp-body {
    padding: 16px;
  }

  .page-studio .fld-input,
  .page-studio .m-field input {
    font-size: 16px;
  }

  .page-studio textarea.fld-input {
    min-height: 132px;
  }

  .page-studio .preview-top {
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 10px 14px;
    gap: 8px;
  }

  .page-studio .pt-label {
    min-width: 0;
    font-size: 11px;
  }

  .page-studio .pt-label span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .page-studio .pt-actions {
    flex-shrink: 0;
    gap: 5px;
  }

  .page-studio .btn-exp {
    min-height: 36px;
    padding: 7px 11px;
    font-size: 10px;
  }

  .page-studio .lang-tabs {
    overflow-x: auto;
    scrollbar-width: none;
  }

  .page-studio .lang-tabs::-webkit-scrollbar {
    display: none;
  }

  .page-studio .lang-tab {
    min-width: 118px;
    min-height: 44px;
    flex: 1 0 auto;
  }

  .page-studio .preview-body {
    padding: 14px 10px 32px;
  }

  .page-studio .empty-state {
    min-height: calc(100dvh - 190px);
    padding: 24px 12px;
  }

  .page-studio #paper-wrapper,
  .page-studio #paper-wrapper-ru,
  .page-studio #paper-wrapper-en {
    width: 100%;
    min-height: 0;
    padding: 26px 20px 40px;
    font-size: 16px;
    line-height: 1.65;
    overflow-wrap: anywhere;
    box-shadow: 0 5px 24px rgba(0, 0, 0, .1);
  }

  .page-studio .m-overlay {
    align-items: flex-end;
    padding: 8px;
  }

  .page-studio .m-box {
    min-height: 0;
    max-height: calc(100dvh - 16px);
    padding: 30px 18px 22px;
    border-radius: 22px 22px 14px 14px;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .page-studio .m-icon {
    width: 52px;
    height: 52px;
    margin-bottom: 12px;
    font-size: 23px;
  }

  .page-studio .m-sub {
    margin-bottom: 18px;
  }

  .page-studio .p-grid {
    gap: 6px !important;
    margin-bottom: 16px !important;
  }

  .page-studio .p-card {
    min-width: 0;
    padding: 13px 4px 11px;
  }

  .page-studio .p-tok {
    font-size: 14px !important;
  }

  .page-studio .p-lbl {
    font-size: 8px;
    letter-spacing: 0;
  }

  .page-studio .m-sum {
    padding: 11px 12px;
    margin-bottom: 14px;
  }

  .page-studio #sum-som {
    font-size: 23px !important;
  }

  .page-studio #toast-container {
    top: 104px;
    right: 10px;
    left: 10px;
  }

  .page-studio .toast {
    width: 100%;
    padding: 12px 14px;
    transform: translateY(-8px) !important;
  }

  .page-studio .toast.show {
    transform: translateY(0) !important;
  }

  /* Admin dashboard */
  html.page-admin-root,
  .page-admin {
    height: 100%;
    overflow: hidden;
  }

  .page-admin .app {
    height: 100dvh;
    flex-direction: column;
  }

  .page-admin .sidebar {
    width: 100%;
    min-width: 0;
    height: auto;
    flex: 0 0 auto;
    overflow: visible;
    animation: none;
  }

  .page-admin .sb-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 12px 7px;
  }

  .page-admin .sb-header .logo {
    margin: 0;
  }

  .page-admin .logo-mark {
    width: 30px;
    height: 30px;
  }

  .page-admin .logo-text {
    font-size: 16px;
  }

  .page-admin .admin-badge {
    padding: 3px 9px;
    font-size: 8px;
  }

  .page-admin .sidebar nav {
    flex: none;
    flex-direction: row;
    gap: 5px;
    padding: 5px 8px 8px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
  }

  .page-admin .sidebar nav::-webkit-scrollbar {
    display: none;
  }

  .page-admin .nav-sec,
  .page-admin .nav-sep,
  .page-admin .sb-footer {
    display: none;
  }

  .page-admin .nav-btn {
    min-width: 86px;
    width: auto;
    min-height: 58px;
    padding: 5px 7px;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    overflow: visible;
    text-align: center;
  }

  .page-admin .nav-btn::after {
    left: 50%;
    top: auto;
    bottom: -1px;
    width: 0;
    height: 3px;
    transform: translateX(-50%);
    transition: width .2s;
  }

  .page-admin .nav-btn.active::after {
    width: 28px;
    height: 3px;
  }

  .page-admin .nb-icon {
    width: 26px;
    height: 26px;
  }

  .page-admin .nb-label {
    flex: none;
    width: 100%;
    font-size: 9px;
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .page-admin .nb-cnt {
    position: absolute;
    top: 3px;
    right: 5px;
    padding: 1px 5px;
    font-size: 8px;
  }

  .page-admin main {
    min-width: 0;
    min-height: 0;
  }

  .page-admin .topbar {
    position: sticky;
    padding: 10px 12px;
    gap: 8px;
    flex-wrap: wrap;
  }

  .page-admin .page-title {
    font-size: 16px;
  }

  .page-admin .tb-right {
    width: 100%;
  }

  .page-admin .tb-clock {
    display: none;
  }

  .page-admin .tb-right .tb-btn {
    flex: 1;
    min-height: 40px;
    justify-content: center;
  }

  .page-admin .content {
    padding: 12px;
  }

  .page-admin .tab-pane {
    gap: 12px;
  }

  .page-admin .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }

  .page-admin .stat-card {
    padding: 14px;
  }

  .page-admin .stat-val {
    font-size: 22px;
  }

  .page-admin .card-head {
    padding: 12px 14px;
    gap: 8px;
  }

  .page-admin .chart-pad {
    padding: 12px;
  }

  .page-admin .tbl-wrap {
    max-width: calc(100vw - 24px);
    -webkit-overflow-scrolling: touch;
  }

  .page-admin table {
    min-width: 720px;
    table-layout: auto;
  }

  .page-admin th,
  .page-admin td {
    padding-inline: 12px;
    max-width: none;
  }

  .page-admin .req-card {
    align-items: stretch;
    flex-direction: column;
    margin-inline: 0;
    padding: 14px;
  }

  .page-admin .req-actions {
    width: 100%;
  }

  .page-admin .req-actions button {
    flex: 1;
    min-height: 40px;
    justify-content: center;
  }

  .page-admin .modal-bg {
    align-items: flex-end;
    padding: 8px;
  }

  .page-admin .modal {
    max-height: calc(100dvh - 16px);
    padding: 22px 18px;
    overflow-y: auto;
    border-radius: 18px 18px 12px 12px;
  }

  .page-admin #toast {
    top: 10px;
    right: 10px;
    left: 10px;
    width: auto;
    max-width: none;
  }

  /* Profile */
  .page-profile .modal-box {
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
  }

  .page-profile #toast-container {
    top: 10px;
    right: 10px;
    left: 10px;
  }

  .page-profile .toast {
    width: 100%;
    min-width: 0;
  }
}

@media (max-width: 600px) {
  input,
  select,
  textarea {
    font-size: 16px !important;
  }

  /* Landing page, narrow phones */
  .page-home .logo {
    gap: 7px;
    font-size: 16px;
  }

  .page-home .logo-icon {
    width: 30px;
    height: 30px;
  }

  .page-home .nav-right {
    gap: 6px;
  }

  .page-home .btn-nav-ghost,
  .page-home .btn-nav-solid {
    padding: 8px 13px;
    font-size: 12px;
  }

  .page-home .hero {
    padding: 42px 14px 38px;
  }

  .page-home .hero-title {
    font-size: clamp(28px, 10vw, 38px) !important;
    line-height: 1.14;
  }

  .page-home .hero-textarea {
    min-height: 142px;
    padding: 17px;
  }

  .page-home .hero-card-footer {
    padding: 10px 12px;
    gap: 8px;
  }

  .page-home .btn-submit-round {
    padding: 10px 14px;
    font-size: 12px;
  }

  .page-home .hero p {
    margin-block: 24px 26px !important;
    font-size: 14px;
    line-height: 1.65;
  }

  .page-home .hero p br {
    display: none;
  }

  .page-home .hero-btns,
  .page-home .cta-btns {
    width: 100%;
    gap: 9px;
  }

  .page-home .hero-btns > *,
  .page-home .cta-btns > * {
    flex: 1 1 100%;
    justify-content: center;
  }

  .page-home .stats {
    padding: 24px 10px;
  }

  .page-home .stats-c {
    gap: 0;
  }

  .page-home .si {
    padding: 14px 5px;
  }

  .page-home .si-num {
    font-size: 29px;
  }

  .page-home section {
    padding: 58px 15px;
  }

  .page-home .sec-h {
    font-size: 28px;
    letter-spacing: -.6px;
  }

  .page-home .feat-card,
  .page-home .step {
    padding: 22px 18px;
  }

  .page-home .footer-bot {
    flex-direction: column;
    gap: 8px;
  }

  .page-home .footer-topics {
    overflow-wrap: anywhere;
  }

  /* Authentication */
  .page-auth .form-side {
    padding: 82px 16px 26px;
  }

  .page-auth .brand-top {
    top: 18px;
    left: 16px;
    font-size: 18px;
  }

  .page-auth .auth-title {
    margin-bottom: 22px;
    font-size: 27px;
    line-height: 1.2;
  }

  .page-auth .auth-sub {
    margin-bottom: 22px;
  }

  .page-auth .fgrp {
    margin-bottom: 15px;
  }

  .page-auth .finput,
  .page-auth .btn-submit {
    height: 50px;
  }

  /* Studio */
  .page-studio .fld-grid {
    gap: 8px;
  }

  .page-studio .status-area {
    padding: 11px 16px;
  }

  /* Profile */
  .page-profile .page {
    padding: 16px 12px 48px;
    gap: 14px;
  }

  .page-profile .nav-c {
    padding-inline: 12px;
  }

  .page-profile .prof-banner-logo {
    right: 14px;
    font-size: 13px;
  }

  .page-profile .act-card,
  .page-profile .r-col > div:last-child {
    padding: 16px;
  }

  .page-profile .hi {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .page-profile .hi-body {
    width: calc(100% - 52px);
  }

  .page-profile .hi-actions {
    width: 100%;
    padding-left: 50px;
  }

  .page-profile .hi-btn {
    flex: 1;
    height: 38px;
  }

  .page-profile .modal-overlay {
    align-items: flex-end;
    padding: 8px;
  }

  .page-profile .modal-box {
    border-radius: 20px 20px 12px 12px;
  }

  .page-profile .modal-head,
  .page-profile .modal-body,
  .page-profile .modal-footer {
    padding-inline: 16px;
  }

  /* Profile editor */
  .page-profile-edit .form-panel {
    padding: 18px 14px 24px;
  }

  .page-profile-edit .form-wrap {
    padding: 38px 0 24px;
  }

  .page-profile-edit h1 {
    font-size: 28px;
    line-height: 1.18;
  }

  .page-profile-edit .brand {
    font-size: 16px;
  }

  .page-profile-edit .brand-icon {
    width: 32px;
    height: 32px;
  }

  .page-profile-edit .panel-foot {
    line-height: 1.5;
  }

  /* Demo */
  .page-demo {
    padding-top: 58px;
  }

  .page-demo .nav {
    height: 58px;
    padding-inline: 16px;
  }

  .page-demo .header-section {
    padding: 42px 16px 34px;
  }

  .page-demo .sec-h {
    font-size: 34px;
    letter-spacing: -1px;
  }

  .page-demo .sec-p {
    font-size: 15px;
  }

  .page-demo .text-section {
    padding: 42px 16px 18px;
  }

  .page-demo .text-section h3 {
    font-size: 27px;
  }

  .page-demo .text-section p,
  .page-demo .text-section li {
    font-size: 15px;
    line-height: 1.7;
  }

  .page-demo .pdf-section {
    padding: 0 16px 54px;
  }

  .page-demo .btn-green {
    width: 100%;
    padding: 15px 18px;
    justify-content: center;
    text-align: center;
  }
}

@media (max-width: 420px) {
  .page-home .btn-nav-ghost {
    display: none;
  }

  .page-home .char-count {
    font-size: 10px;
  }

  .page-home .btn-submit-round {
    padding-inline: 12px;
  }

  .page-studio .tb-logo {
    font-size: 14px;
  }

  .page-studio .tb-token {
    max-width: 92px;
  }

  .page-admin .stat-grid {
    grid-template-columns: 1fr;
  }

  .page-admin .modal-actions {
    flex-direction: column-reverse;
  }

  .page-profile .stat-pair {
    gap: 8px;
  }

  .page-profile .stat-card {
    padding: 13px;
  }

  .page-profile .sc-num {
    font-size: 22px;
  }
}

@media (max-width: 340px) {
  .page-auth .sel-grid,
  .page-studio .fld-grid {
    grid-template-columns: 1fr;
  }

  .page-studio .tb-logo {
    font-size: 0;
  }

  .page-studio .tb-logo span {
    font-size: 0;
  }

  .page-studio .p-grid {
    grid-template-columns: 1fr !important;
  }
}

@media (max-height: 560px) and (orientation: landscape) {
  .page-auth .form-side,
  .page-profile-edit .form-panel {
    min-height: 100%;
  }

  .page-studio .topbar {
    min-height: 84px;
  }

  .page-studio .m-overlay,
  .page-profile .modal-overlay,
  .page-admin .modal-bg {
    align-items: flex-start;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
