/* Mobile adaptations — client SPA, admin, manager */

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

body {
  overflow-x: hidden;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
}

#root {
  min-height: 100dvh;
  min-height: -webkit-fill-available;
}

/* iOS: avoid auto-zoom on focus */
@media (max-width: 640px) {
  input,
  select,
  textarea {
    font-size: 16px !important;
  }
}

/* Radix / generic dialogs on small screens */
@media (max-width: 640px) {
  [role="dialog"]:not([data-mobile-dialog="off"]) {
    width: calc(100vw - 1rem) !important;
    max-width: calc(100vw - 1rem) !important;
    max-height: min(
      95dvh,
      calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px))
    ) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }
}

/* Touch targets */
@media (max-width: 640px) {
  button,
  [role="button"],
  a.btn,
  .btn {
    min-height: 44px;
  }
}

/* Admin: full-screen chat on phones */
@media (max-width: 860px) {
  .page {
    padding: 12px 10px calc(24px + env(safe-area-inset-bottom, 0px));
  }

  .header {
    padding: 16px 14px 8px;
  }

  .header h1 {
    font-size: 22px;
    line-height: 1.2;
  }

  .header > div {
    flex-direction: column;
    align-items: stretch !important;
    gap: 10px !important;
  }

  .header .btn-outline {
    align-self: flex-start;
  }

  .panel {
    min-height: 280px;
    padding: 12px;
  }

  .item-top {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .actions {
    width: 100%;
  }

  .actions .btn {
    flex: 1 1 calc(50% - 5px);
    min-width: 0;
    text-align: center;
    justify-content: center;
  }

  #app-root #chat-panel:not(.hidden) {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: grid !important;
    grid-template-columns: 1fr !important;
    min-height: 100dvh;
    min-height: 100dvh;
    background: #fff;
    border-radius: 0;
  }

  #app-root #chat-panel:not(.hidden) .chat-sidebar {
    display: none;
  }

  #app-root #chat-panel:not(.hidden) .chat-main {
    min-height: 0;
    height: 100%;
    max-height: 100dvh;
  }

  #app-root #chat-panel:not(.hidden) .chat-messages {
    padding-bottom: 8px;
  }

  #app-root #chat-panel:not(.hidden) .chat-compose {
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .message {
    max-width: 88%;
  }

  .telegram-head {
    flex-direction: column;
    align-items: stretch;
  }

  .telegram-actions .btn {
    flex: 1 1 100%;
  }
}

@media (max-width: 480px) {
  .chat-compose {
    align-items: stretch;
  }

  .chat-compose textarea {
    flex: 1 1 100%;
    width: 100%;
    min-height: 44px;
    height: auto;
  }

  .chat-compose .compose-actions {
    width: 100%;
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .tabs {
    padding-left: 10px;
    padding-right: 10px;
  }

  .tab {
    padding: 8px 10px;
    font-size: 13px;
  }

  .login-wrap {
    padding: 16px;
    align-items: flex-start;
    padding-top: max(16px, env(safe-area-inset-top, 0px));
  }

  .login-card {
    margin-top: 8vh;
  }
}

/* Manager form page */
@media (max-width: 640px) {
  body:has(.manager-page) {
    background: #fff;
  }

  .manager-page {
    max-width: none;
    padding: 0;
    min-height: 100dvh;
  }

  .manager-page .card {
    border-radius: 0;
    box-shadow: none;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
  }

  .manager-page .header {
    padding-top: max(20px, env(safe-area-inset-top, 0px));
  }

  .manager-page .panel {
    flex: 1;
    min-height: 0;
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  }
}

/* MNC landing */
@media (max-width: 768px) {
  .diag-modal-box {
    width: calc(100vw - 24px);
    max-width: none;
    margin: 12px;
  }
}

/* Client chat — comfortable width on desktop / large tablets */
@media (min-width: 900px) {
  .client-chat-page {
    background: #eef1f5;
  }

  .client-chat-page .client-chat-header,
  .client-chat-page .client-chat-banner,
  .client-chat-page .client-chat-actions,
  .client-chat-page .client-chat-messages,
  .client-chat-page .client-chat-compose {
    width: 100%;
    max-width: 720px;
    margin-left: auto;
    margin-right: auto;
    box-sizing: border-box;
  }

  .client-chat-page .client-chat-header,
  .client-chat-page .client-chat-messages,
  .client-chat-page .client-chat-compose {
    border-left: 1px solid hsl(var(--border));
    border-right: 1px solid hsl(var(--border));
  }

  .client-chat-page .client-chat-messages {
    background: hsl(var(--background));
  }

  .client-chat-messages [class*="max-w-[75%]"],
  .client-chat-messages [class*="max-w-[85%]"] {
    max-width: min(420px, 85%) !important;
    width: fit-content !important;
  }

  .client-chat-messages .max-w-xs {
    max-width: 22rem !important;
    width: fit-content !important;
  }

  .client-chat-messages > div.flex.justify-center {
    width: 100%;
  }

  .client-chat-messages > div.flex.justify-center > div {
    width: fit-content;
    max-width: min(420px, 90%) !important;
  }
}

@media (min-width: 1200px) {
  .client-chat-page .client-chat-header,
  .client-chat-page .client-chat-banner,
  .client-chat-page .client-chat-actions,
  .client-chat-page .client-chat-messages,
  .client-chat-page .client-chat-compose {
    max-width: 780px;
  }
}
