/* ================================================================
   MISTER FAST — MINI CHAT HUB V1 CSS
   Visual Target: 2026-10-07 Reference Implementation
   Palette: MISTER FAST Navy Blue (#003DA5), Yellow (#FFC400), Slate (#0F172A, #64748B, #F1F5F9)
   ================================================================ */

/* Chat Pane container adaptation for Chat Hub */
body.mf-mini[data-mf-workspace="chat"] .mf514-chat-pane,
.mf514-chat-pane {
  background: #F8FAFC !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  -webkit-overflow-scrolling: touch;
}

/* Hide in-room new message floating badges when viewing Chat Hub */
body.mf-mini[data-mf-workspace="chat"] .mf601-new-badge,
body.mf-mini[data-mf-workspace="chat"] .mf632-new-message,
.mf-view-chat-hub:not([hidden]) ~ .mf601-new-badge,
.mf-view-chat-hub:not([hidden]) ~ .mf632-new-message,
.mf-chat-dynamic-content:has(.mf-view-chat-hub:not([hidden])) .mf601-new-badge,
.mf-chat-dynamic-content:has(.mf-view-chat-hub:not([hidden])) .mf632-new-message {
  display: none !important;
}
body.mf-mini[data-mf-workspace="chat"]:has(.mf514-messages:not([hidden])) .mf601-new-badge,
body.mf-mini[data-mf-workspace="chat"]:has(.mf514-messages:not([hidden])) .mf632-new-message {
  display: flex !important;
}

/* Chat Hub Main Wrapper */
.mf-chat-hub-wrap {
  width: 100%;
  max-width: 430px;
  margin: 0 auto;
  padding: 8px 10px calc(72px + env(safe-area-inset-bottom, 0px)) 10px;
  box-sizing: border-box;
}

/* Title Area (Section 4.1) */
.mf-chat-hub-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.mf-chat-hub-title-wrap {
  display: flex;
  flex-direction: column;
}
.mf-chat-hub-title {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  color: #0F172A;
  line-height: 1.2;
  letter-spacing: -0.3px;
}
.mf-chat-hub-sub {
  margin: 1px 0 0 0;
  font-size: 12px;
  color: #64748B;
  font-weight: 500;
}
.mf-chat-hub-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.mf-ch-btn-action {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #FFFFFF;
  border: 1px solid #E2E8F0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #334155;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  transition: all 0.15s ease;
  padding: 0;
}
.mf-ch-btn-action:active {
  transform: scale(0.94);
  background: #F1F5F9;
}

/* Four Primary Chat Entrances — Compact 1-Row Grid (Section 4.2) */
.mf-chat-entrances-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 8px;
}
.mf-ch-entrance-card {
  background: #FFFFFF;
  border: 1.5px solid #E2E8F0;
  border-radius: 12px;
  padding: 6px 2px 5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 1.5px 4px rgba(0, 0, 0, 0.02);
  transition: all 0.15s ease;
  text-decoration: none;
  color: inherit;
  user-select: none;
  min-width: 0;
  height: 54px;
}
.mf-ch-entrance-card.is-active,
.mf-ch-entrance-card:hover {
  border-color: #FFC400;
  box-shadow: 0 3px 10px rgba(255, 196, 0, 0.15);
}
.mf-ch-entrance-card:active {
  transform: scale(0.96);
}
.mf-ch-entrance-icon-box {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 3px;
  transition: transform 0.15s ease;
  flex-shrink: 0;
}
.mf-ch-entrance-icon-box svg {
  width: 15px;
  height: 15px;
}
.mf-ch-entrance-icon-box.is-general {
  background: #EFF6FF;
  color: #2563EB;
}
.mf-ch-entrance-icon-box.is-groups {
  background: #FAF5FF;
  color: #7C3AED;
}
.mf-ch-entrance-icon-box.is-support {
  background: #EEF2FF;
  color: #4F46E5;
}
.mf-ch-entrance-icon-box.is-add {
  background: #ECFDF5;
  color: #059669;
}
.mf-ch-entrance-title {
  font-size: 11px;
  font-weight: 700;
  color: #0F172A;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.mf-ch-entrance-sub {
  display: none;
}

/* Friend Filter Segmented Bar (Section 4.3) */
.mf-chat-filter-chips {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  background: #F1F5F9;
  border-radius: 12px;
  margin-bottom: 8px;
  box-sizing: border-box;
}
.mf-ch-chip {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 2px;
  border-radius: 9px;
  font-size: 11.5px;
  font-weight: 600;
  background: transparent;
  color: #475569;
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  min-width: 0;
}
.mf-ch-chip .mf-ch-chip-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 1px 5px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 800;
  background: #CBD5E1;
  color: #334155;
  line-height: 1;
}
.mf-ch-chip.is-active {
  background: #003DA5 !important;
  color: #FFFFFF !important;
  font-weight: 800 !important;
  box-shadow: 0 2px 6px rgba(0, 61, 165, 0.2);
}
.mf-ch-chip.is-active .mf-ch-chip-badge {
  background: #FFC400 !important;
  color: #001B45 !important;
  font-weight: 900 !important;
}
.mf-ch-chip:active {
  transform: scale(0.96);
}

/* Friend Search Bar (Section 4.4) */
.mf-chat-search-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}
.mf-chat-search-input-box {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  background: #FFFFFF;
  border: 1.5px solid #E2E8F0;
  border-radius: 18px;
  padding: 6px 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
  transition: border-color 0.15s ease;
}
.mf-chat-search-input-box:focus-within {
  border-color: #003DA5;
  box-shadow: 0 0 0 3px rgba(0, 61, 165, 0.08);
}
.mf-chat-search-input-box svg {
  color: #94A3B8;
  flex-shrink: 0;
}
.mf-chat-search-input-box input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: 12px;
  color: #0F172A;
  font-family: inherit;
  padding: 0;
}
.mf-chat-search-input-box input::placeholder {
  color: #94A3B8;
}
.mf-ch-clear-search {
  border: none;
  background: none;
  color: #94A3B8;
  font-size: 14px;
  cursor: pointer;
  padding: 0 2px;
  display: none;
}
.mf-ch-sort-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: #FFFFFF;
  border: 1.5px solid #E2E8F0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #334155;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
  transition: all 0.15s ease;
}
.mf-ch-sort-btn:active {
  transform: scale(0.94);
  background: #F1F5F9;
}
.mf-ch-sort-btn:active {
  transform: scale(0.94);
  background: #F1F5F9;
}

/* Section Headers ("เพื่อนของฉัน", "กลุ่มของฉัน") */
.mf-ch-section {
  margin-bottom: 18px;
}
.mf-ch-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  padding: 0 2px;
}
.mf-ch-section-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 15px;
  font-weight: 800;
  color: #0F172A;
}
.mf-ch-section-title svg {
  color: #2563EB;
}
.mf-ch-see-all {
  font-size: 12px;
  font-weight: 600;
  color: #64748B;
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 4px;
}
.mf-ch-see-all:hover {
  color: #003DA5;
}

/* Contact / Friend Cards (Section 8) */
.mf-ch-card-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.mf-ch-friend-card,
.mf-ch-group-card {
  background: #FFFFFF;
  border: 1px solid #F1F5F9;
  border-radius: 16px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.02);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  position: relative;
  cursor: pointer;
}
.mf-ch-friend-card:hover,
.mf-ch-group-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  border-color: #E2E8F0;
}
.mf-ch-friend-card:active,
.mf-ch-group-card:active {
  transform: scale(0.985);
}

/* Avatar with Presence */
.mf-ch-avatar-wrap {
  position: relative;
  width: 48px;
  height: 48px;
  min-width: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.mf-ch-avatar-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  background: #EFF6FF;
}
.mf-ch-avatar-fallback {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  color: #1E40AF;
  background: #DBEAFE;
}
.mf-ch-avatar-fallback.is-merchant {
  background: #FEF3C7;
  color: #92400E;
}
.mf-ch-avatar-fallback.is-general {
  background: #F3E8FF;
  color: #6B21A8;
}
.mf-ch-avatar-fallback.is-group {
  background: #EFF6FF;
  color: #1D4ED8;
}
/* REAL Presence Green Dot Only (Section 8) */
.mf-ch-presence-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #22C55E;
  border: 2px solid #FFFFFF;
  box-sizing: border-box;
}

/* Friend Card Info */
.mf-ch-card-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.mf-ch-card-top {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.mf-ch-card-name {
  font-size: 14px;
  font-weight: 700;
  color: #0F172A;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}
.mf-ch-role-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  flex-shrink: 0;
  line-height: 1.2;
}
.mf-ch-role-badge.is-driver {
  background: #DBEAFE;
  color: #1D4ED8;
}
.mf-ch-role-badge.is-merchant {
  background: #FEF3C7;
  color: #B45309;
}
.mf-ch-role-badge.is-general {
  background: #F3E8FF;
  color: #7E22CE;
}
.mf-ch-card-snippet {
  font-size: 12px;
  color: #64748B;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}
.mf-ch-group-meta-sub {
  font-size: 11px;
  color: #64748B;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mf-ch-group-online-tag {
  color: #16A34A;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.mf-ch-group-online-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22C55E;
  display: inline-block;
}

/* Friend Card Meta Right */
.mf-ch-card-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
  min-width: 50px;
}
.mf-ch-card-time {
  font-size: 11px;
  color: #94A3B8;
  font-weight: 500;
}
.mf-ch-card-badges {
  display: flex;
  align-items: center;
  gap: 6px;
}
.mf-ch-unread-badge {
  background: #EF4444;
  color: #FFFFFF;
  font-size: 11px;
  font-weight: 800;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  line-height: 1;
}
.mf-ch-more-menu-btn {
  background: none;
  border: none;
  padding: 2px;
  color: #94A3B8;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}
.mf-ch-more-menu-btn:hover {
  color: #0F172A;
  background: #F1F5F9;
}

/* Empty State (Section 5 Compact Specification) */
.mf-ch-empty-card {
  background: #FFFFFF;
  border: 1.5px dashed #CBD5E1;
  border-radius: 14px;
  padding: 12px 14px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 95px;
  box-sizing: border-box;
}
.mf-ch-empty-text {
  font-size: 12px;
  color: #64748B;
  font-weight: 600;
}
.mf-ch-empty-btn {
  background: #003DA5;
  color: #FFFFFF;
  border: none;
  border-radius: 16px;
  padding: 5px 16px;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}
.mf-ch-empty-btn:active {
  transform: scale(0.96);
}

/* Back navigation button when viewing conversation room */
.mf-chat-room-nav-header {
  background: #FFFFFF;
  border-bottom: 1px solid #E2E8F0;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.mf-chat-room-back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  font-weight: 700;
  color: #003DA5;
  text-decoration: none;
  background: none;
  border: none;
  padding: 4px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.mf-chat-room-back-link:hover {
  background: #EFF6FF;
}

/* Interactive Modal / Action Sheet */
.mf-ch-modal-backdrop[hidden] {
  display: none !important;
}
.mf-ch-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(2px);
  z-index: 9999;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.mf-ch-modal-sheet {
  background: #FFFFFF;
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 16px 18px calc(24px + env(safe-area-inset-bottom, 0px));
  box-sizing: border-box;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.15);
  animation: mfSheetSlideUp 0.22s ease-out;
}
@keyframes mfSheetSlideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.mf-ch-modal-bar {
  width: 40px;
  height: 4px;
  background: #CBD5E1;
  border-radius: 2px;
  margin: 0 auto 14px;
}
.mf-ch-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.mf-ch-modal-title {
  font-size: 17px;
  font-weight: 800;
  color: #0F172A;
  margin: 0;
}
.mf-ch-modal-close {
  background: #F1F5F9;
  border: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #64748B;
}

/* Modal Options List */
.mf-ch-modal-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.mf-ch-modal-option-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  background: #F8FAFC;
  border: 1px solid #E2E8F0;
  border-radius: 14px;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
  width: 100%;
  text-align: left;
  box-sizing: border-box;
}
.mf-ch-modal-option-btn:hover {
  background: #EFF6FF;
  border-color: #BFDBFE;
}
.mf-ch-modal-opt-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.mf-ch-modal-opt-title {
  font-size: 14px;
  font-weight: 700;
  color: #0F172A;
  display: block;
}
.mf-ch-modal-opt-sub {
  font-size: 12px;
  color: #64748B;
  display: block;
  margin-top: 2px;
}

/* ──────────────── Responsive Fine-Tuning ──────────────── */
@media (max-width: 430px) {
  .mf-chat-entrances-grid {
    gap: 6px;
  }
  .mf-ch-entrance-card {
    padding: 8px 3px 6px;
  }
  .mf-ch-entrance-icon-box {
    width: 38px;
    height: 38px;
    border-radius: 10px;
  }
  .mf-ch-entrance-title {
    font-size: 11.5px;
  }
  .mf-ch-entrance-sub {
    font-size: 9.5px;
  }
}

@media (max-width: 390px) {
  .mf-chat-hub-wrap {
    padding-left: 10px;
    padding-right: 10px;
  }
  .mf-chat-entrances-grid {
    gap: 5px;
  }
  .mf-ch-entrance-card {
    padding: 7px 2px 5px;
  }
  .mf-ch-entrance-icon-box {
    width: 36px;
    height: 36px;
  }
  .mf-ch-entrance-title {
    font-size: 11px;
  }
  .mf-ch-entrance-sub {
    font-size: 9px;
  }
  .mf-ch-chip {
    padding: 5px 11px;
    font-size: 12px;
  }
  .mf-ch-friend-card,
  .mf-ch-group-card {
    padding: 10px 10px;
    gap: 10px;
  }
  .mf-ch-avatar-wrap {
    width: 44px;
    height: 44px;
    min-width: 44px;
  }
}

@media (max-width: 360px) {
  .mf-chat-hub-wrap {
    padding-left: 8px;
    padding-right: 8px;
  }
  .mf-chat-entrances-grid {
    gap: 4px;
  }
  .mf-ch-entrance-card {
    padding: 6px 1px 4px;
    border-radius: 10px;
  }
  .mf-ch-entrance-icon-box {
    width: 32px;
    height: 32px;
    border-radius: 8px;
  }
  .mf-ch-entrance-icon-box svg {
    width: 18px;
    height: 18px;
  }
  .mf-ch-entrance-title {
    font-size: 10.5px;
  }
  .mf-ch-entrance-sub {
    font-size: 8.5px;
  }
  .mf-ch-chip {
    padding: 4px 9px;
    font-size: 11.5px;
    gap: 4px;
  }
  .mf-ch-avatar-wrap {
    width: 40px;
    height: 40px;
    min-width: 40px;
  }
  .mf-ch-card-name {
    font-size: 13px;
  }
  .mf-ch-card-snippet {
    font-size: 11px;
  }
}
