/* MessageBotWeb - Site styles with mobile responsiveness */

a.navbar-brand {
  white-space: normal;
  text-align: center;
  word-break: break-all;
}

a { color: #0366d6; }

.btn-primary { color: #fff; background-color: #1b6ec2; border-color: #1861ac; }

.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
  color: #fff; background-color: #1b6ec2; border-color: #1861ac;
}

/* Base font scaling */
html { font-size: 14px; position: relative; min-height: 100%; }
@media (min-width: 768px) { html { font-size: 16px; } }

.border-top { border-top: 1px solid #e5e5e5; }
.border-bottom { border-bottom: 1px solid #e5e5e5; }
.box-shadow { box-shadow: 0 .25rem .75rem rgba(0,0,0,.05); }
button.accept-policy { font-size: 1rem; line-height: inherit; }

body { margin-bottom: 60px; }
.footer { position: absolute; bottom: 0; width: 100%; white-space: nowrap; line-height: 60px; }

/* ============================================
   MOBILE RESPONSIVE STYLES
   ============================================ */

/* --- Navbar mobile --- */
@media (max-width: 991px) {
  .top-navbar .navbar-brand { padding: 10px 12px; font-size: 1rem; }
  .top-navbar .nav-link { padding: 10px 16px; border-bottom: none; }
  .top-navbar .navbar-collapse {
    background: #1a1a2e;
    border-top: 1px solid rgba(255,255,255,0.1);
    padding: 8px 0;
    max-height: calc(100vh - 56px);
    overflow-y: auto;
  }
  .top-navbar .navbar-nav {
    width: 100%;
  }
  .top-navbar .navbar-nav .nav-item {
    width: 100%;
  }
  .top-navbar .navbar-nav .dropdown-menu {
    background: #16213e;
    border: none;
    box-shadow: none;
    padding: 0;
    position: static !important;
    float: none;
    width: 100%;
    margin: 0;
  }
  .top-navbar .navbar-nav .dropdown-item {
    color: rgba(255,255,255,0.75);
    padding: 10px 32px;
  }
  .top-navbar .navbar-nav .dropdown-item:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
  }
  .top-navbar .user-badge { padding: 10px 16px; }
  .top-navbar .ml-auto, .top-navbar .navbar-nav:last-child {
    border-top: 1px solid rgba(255,255,255,0.1);
    padding-top: 8px;
    margin-top: 4px;
  }
  .btn-logout { margin: 8px 16px; }
  .navbar-toggler { padding: 4px 8px; }
  .navbar-toggler-icon {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28255, 255, 255, 0.75%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
  }
}

/* --- Container padding on mobile --- */
@media (max-width: 576px) {
  .container, .container-fluid { padding-left: 10px; padding-right: 10px; }
  h2 { font-size: 1.4rem; }
  h3 { font-size: 1.2rem; }
  h4 { font-size: 1.05rem; }
}

/* --- Cards on mobile --- */
@media (max-width: 576px) {
  .card { border-radius: 8px; margin-left: -2px; margin-right: -2px; }
  .card-header { padding: 10px 12px; font-size: 0.88rem; }
  .card-body { padding: 12px; }
}

/* --- Form layouts on mobile: full width inputs --- */
@media (max-width: 767px) {
  .row > [class*="col-md-"],
  .row > [class*="col-lg-"] {
    flex: 0 0 100%;
    max-width: 100%;
  }
  /* Keep col-6 for intentional 2-col on mobile */
  .row > .col-6 { flex: 0 0 50%; max-width: 50%; }
  /* Buttons stack on mobile */
  .btn-group-mobile > .btn { display: block; width: 100%; margin-bottom: 4px; }
}

/* --- Tables on mobile --- */
@media (max-width: 767px) {
  .table thead th { padding: 8px 10px; font-size: 0.75rem; letter-spacing: 0; }
  .table tbody td { padding: 8px 10px; font-size: 0.82rem; }
  .table th[style*="width"], .table td[style*="width"] { width: auto !important; }
}

/* --- Fixed inline max-widths override on mobile --- */
@media (max-width: 576px) {
  input[style*="max-width"], div[style*="max-width"] { max-width: 100% !important; }
}

/* --- Dashboard stat cards --- */
@media (max-width: 576px) {
  .dashboard-stat { font-size: 2rem !important; }
}

/* --- Messenger / Chats page --- */
@media (max-width: 768px) {
  .messenger-container {
    flex-direction: column;
    height: auto;
    min-height: calc(100vh - 70px);
    border-radius: 0;
    margin: 0 -10px;
  }
  .chat-sidebar {
    width: 100% !important;
    min-width: unset !important;
    max-height: 45vh;
    border-right: none;
    border-bottom: 1px solid #e8e8e8;
  }
  .chat-main {
    min-height: 55vh;
  }
  .msg-bubble {
    max-width: 85% !important;
  }
  .messages-area {
    padding: 12px;
  }
  .send-area {
    padding: 8px 12px;
  }
  .send-area .form-control {
    font-size: 16px; /* Prevents iOS zoom on focus */
  }
  .chat-main-header {
    padding: 10px 12px;
    flex-wrap: wrap;
    gap: 4px;
  }
  .chat-main-header h5 {
    font-size: 0.95rem;
  }
  .chat-avatar {
    width: 40px;
    height: 40px;
    font-size: 0.95rem;
    margin-right: 10px;
  }
  .sidebar-header {
    padding: 10px 12px;
  }
  .sidebar-header h5 {
    font-size: 1rem;
    margin-bottom: 8px;
  }
  .chat-item {
    padding: 10px 12px;
  }
  .attach-panel {
    padding: 8px 12px;
  }
}

/* Chats: show/hide sidebar toggle on mobile */
@media (max-width: 576px) {
  .chat-sidebar {
    max-height: 40vh;
  }
  .chat-search {
    padding: 8px 12px;
  }
  .chat-search input {
    font-size: 16px; /* Prevents iOS zoom */
  }
}

/* --- Account list cards on mobile --- */
@media (max-width: 576px) {
  .account-card .row > .col-6 {
    flex: 0 0 100%;
    max-width: 100%;
  }
}

/* --- Login/Register centered form --- */
@media (max-width: 576px) {
  .auth-form-container {
    padding: 0 8px;
  }
  .auth-form-container .card {
    margin: 0 -4px;
  }
}

/* --- Online chat room --- */
@media (max-width: 767px) {
  .chat-room-messages {
    height: 60vh !important;
    max-height: 60vh !important;
  }
  .ms-5 { margin-left: 1rem !important; }
  .me-5 { margin-right: 1rem !important; }
}

/* --- Admin tables: scroll horizontally --- */
@media (max-width: 767px) {
  .table-responsive {
    font-size: 0.82rem;
  }
  .admin-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
  .admin-actions .btn {
    width: 100%;
    text-align: left;
  }
}

/* --- Webhook URL inputs: full width on mobile --- */
@media (max-width: 767px) {
  .input-group .form-control[readonly] {
    font-size: 0.78rem !important;
  }
}

/* --- Create page: AI settings block --- */
@media (max-width: 767px) {
  #aiBotBlock .row > [class*="col-md-"] {
    flex: 0 0 100%;
    max-width: 100%;
    margin-bottom: 8px;
  }
}

/* --- Trigger edit form --- */
@media (max-width: 767px) {
  .trigger-form .row > [class*="col-md-"] {
    flex: 0 0 100%;
    max-width: 100%;
  }
}

/* --- Print: hide nav --- */
@media print {
  .top-navbar, .footer, .sidebar-header select { display: none !important; }
  .messenger-container { height: auto !important; box-shadow: none !important; }
}

/* --- Touch-friendly targets --- */
@media (max-width: 767px) {
  .btn { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; }
  .btn-sm { min-height: 34px; }
  .form-check-input { width: 2.8em; height: 1.4em; }
  .form-select, .form-control { min-height: 42px; }
  .nav-link { min-height: 44px; display: flex; align-items: center; }
  .dropdown-item { min-height: 44px; display: flex; align-items: center; }
}

/* --- Toggle switch: label left, switch right --- */
.toggle-switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  cursor: pointer;
  user-select: none;
}
.toggle-switch .toggle-label {
  font-size: 0.9rem;
  color: #333;
  line-height: 1.3;
  flex: 1;
  min-width: 0;
}
.toggle-switch .toggle-label small {
  display: block;
  font-size: 0.78rem;
  color: #888;
  margin-top: 2px;
}
/* Button-style toggle with Выкл/Вкл text */
.toggle-switch .form-check-input {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  width: 64px;
  height: 30px;
  background: #e0e0e0;
  border-radius: 6px;
  position: relative;
  cursor: pointer;
  transition: background 0.25s ease;
  border: 1px solid #c0c0c0;
  outline: none;
  flex-shrink: 0;
  margin: 0 0 0 8px;
  float: none;
  font-size: 0;
}
.toggle-switch .form-check-input::after {
  content: 'Выкл';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 600;
  color: #888;
  letter-spacing: 0.3px;
  transition: color 0.25s ease;
}
.toggle-switch .form-check-input:checked {
  background: #0d6efd;
  border-color: #0b5ed7;
}
.toggle-switch .form-check-input:checked::after {
  content: 'Вкл';
  color: #fff;
}
.toggle-switch .form-check-input:hover {
  border-color: #999;
}
.toggle-switch .form-check-input:checked:hover {
  background: #0b5ed7;
  border-color: #0a58ca;
}
.toggle-switch .form-check-input:focus {
  box-shadow: 0 0 0 3px rgba(13,110,253,0.2);
}
.toggle-switch .form-check-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
/* Legacy form-switch override for any remaining instances */
.form-check.form-switch {
  padding-left: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.form-check.form-switch .form-check-input {
  float: none;
  margin-left: 0;
  order: 2;
}
.form-check.form-switch .form-check-label {
  padding-left: 0;
  order: 1;
  flex: 1;
}

/* --- Prevent horizontal overflow --- */
body { overflow-x: hidden; }
.container-fluid { overflow-x: hidden; }
