/* 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 — statuses fixed above; messages flow from top of scroll area */
.client-chat-messages {
  display: flex;
  flex-direction: column;
}

.client-chat-statuses,
.client-chat-status-bar,
.client-chat-mgr {
  flex-shrink: 0;
  width: 100%;
}

.client-chat-status {
  flex-shrink: 0;
  width: 100%;
}

@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-mgr,
  .client-chat-page .client-chat-status-bar,
  .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-mgr,
  .client-chat-page .client-chat-status-bar,
  .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-mgr,
  .client-chat-page .client-chat-status-bar,
  .client-chat-page .client-chat-messages,
  .client-chat-page .client-chat-compose {
    max-width: 780px;
  }
}

/* Gosuslugi auth modal — input highlight like original */
.gs-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: #333333;
  margin-bottom: 6px;
}

.gs-restore-link {
  display: block;
  margin-top: 8px;
  padding: 0;
  border: none;
  background: none;
  color: #0d4cd3 !important;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}

.gs-restore-link:hover {
  text-decoration: underline;
}

input.gs-input,
[role="dialog"] input.gs-input {
  display: block;
  height: 48px;
  width: 100%;
  box-sizing: border-box;
  font-size: 16px;
  line-height: 1.2;
  color: #1a1a1a;
  background-color: #f5f7fa !important;
  border: 1px solid #e8ebf2 !important;
  border-radius: 8px !important;
  padding: 0 16px;
  outline: none !important;
  box-shadow: none !important;
  appearance: none;
  -webkit-appearance: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

input.gs-input::placeholder {
  color: #8e8e93;
  opacity: 1;
}

input.gs-input:focus,
input.gs-input:focus-visible {
  background-color: #ffffff !important;
  border-color: #0d4cd3 !important;
  box-shadow: 0 0 0 4px rgba(13, 76, 211, 0.12) !important;
}

/* Gosuslugi password restore screens */
.gs-restore-title {
  font-size: 22px;
  font-weight: 700;
  color: #0b1f33;
  text-align: center;
  margin: 4px 0 28px;
  line-height: 1.25;
}

input.gs-restore-input,
[role="dialog"] input.gs-restore-input {
  display: block;
  width: 100%;
  height: 52px;
  box-sizing: border-box;
  padding: 0 16px;
  font-size: 16px;
  color: #1a1a1a;
  background-color: #f2f5f7 !important;
  border: none !important;
  border-radius: 8px !important;
  outline: none !important;
  box-shadow: none !important;
  appearance: none;
  -webkit-appearance: none;
}

input.gs-restore-input:focus,
input.gs-restore-input:focus-visible {
  background-color: #eef1f5 !important;
  box-shadow: none !important;
}

.gs-restore-btn {
  display: block;
  width: 100%;
  height: 56px;
  margin-top: 12px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.gs-restore-btn:disabled {
  background-color: #e5edf5;
  color: #828a99;
  cursor: default;
}

.gs-restore-btn:not(:disabled) {
  background-color: #0d4cd3;
  color: #ffffff;
}

.gs-restore-links {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 28px;
  margin-top: 36px;
}

.gs-restore-links button {
  background: none;
  border: none;
  padding: 0;
  color: #0d4cd3;
  font-size: 15px;
  line-height: 1.2;
  cursor: pointer;
}

.gs-restore-links button:hover {
  text-decoration: underline;
}

.gs-restore-link-active {
  font-weight: 600;
  text-decoration: underline;
}
