/* ==========================================================================
   StitChat — layout & component styles
   Tailwind handles utility classes; this file handles structural layout,
   the three-pane responsive behavior, and hand-tuned component details
   that are awkward to express purely in utilities.
   ========================================================================== */

* { box-sizing: border-box; }
::selection { background: #BFDBFE; color: #0F172A; }

.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { scrollbar-width: none; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #CBD5E1; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: #94A3B8; }

:focus-visible {
  outline: 2px solid #2563EB;
  outline-offset: 2px;
  border-radius: 6px;
}

.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, #2563EB, #38BDF8);
  color: white; font-weight: 800; font-size: 13px; letter-spacing: -0.02em;
  box-shadow: 0 4px 10px -3px rgba(37,99,235,.55);
}

/* ---------- App shell ---------- */
#app { position: relative; }

.mobile-topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 56px; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 10px; background: #0F172A; color: white;
}
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 9px; color: inherit;
  transition: background-color .15s ease, transform .1s ease;
}
.icon-btn:hover { background: rgba(148,163,184,.14); }
.icon-btn:active { transform: scale(.94); }

/* ---------- Rail (channel sidebar) ---------- */
.rail {
  background: #0F172A;
  width: 232px; flex-shrink: 0; height: 100%;
  position: relative; z-index: 40;
}
.rail-inner { display: flex; flex-direction: column; height: 100%; }

.rail-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 9px 10px; border-radius: 10px;
  color: rgba(255,255,255,.62); font-size: 13.5px; font-weight: 500;
  transition: background-color .15s ease, color .15s ease;
}
.rail-item:hover { background: rgba(255,255,255,.06); color: #fff; }

.channel-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 9px 10px; border-radius: 10px;
  color: rgba(255,255,255,.72); transition: background-color .15s ease, color .15s ease;
  position: relative;
}
.channel-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.channel-item.active { background: #2563EB; color: #fff; box-shadow: 0 4px 14px -4px rgba(37,99,235,.65); }
.channel-item.active .channel-sub { color: rgba(255,255,255,.75); }
.channel-icon {
  width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; color: white;
}
.channel-label { font-size: 13.5px; font-weight: 600; line-height: 1.15; }
.channel-sub { font-size: 11px; color: rgba(255,255,255,.4); }
.channel-count {
  margin-left: auto; font-size: 11px; font-weight: 700; color: #fff;
  background: #DC2626; border-radius: 99px; min-width: 19px; height: 19px;
  display: flex; align-items: center; justify-content: center; padding: 0 5px;
}
.channel-item.active .channel-count { background: rgba(255,255,255,.25); }
.channel-nav-label {
  font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: rgba(255,255,255,.32); padding: 14px 10px 6px;
}
.channel-nav-label:first-child { padding-top: 4px; }

.rail-user {
  display: flex; align-items: center; gap: 9px; margin-top: 10px; padding: 8px 8px;
  border-radius: 10px; background: rgba(255,255,255,.05);
}

.scrim {
  display: none; position: fixed; inset: 0; background: rgba(15,23,42,.55);
  z-index: 35; backdrop-filter: blur(1px);
}

/* ---------- Avatars ---------- */
.avatar {
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 700; flex-shrink: 0; position: relative;
}
.avatar-sm { width: 30px; height: 30px; font-size: 11.5px; }
.avatar-md { width: 40px; height: 40px; font-size: 13.5px; }
.avatar-lg { width: 56px; height: 56px; font-size: 17px; }

.platform-dot {
  width: 15px; height: 15px; border-radius: 50%; display: inline-flex;
  align-items: center; justify-content: center; border: 2px solid white;
  flex-shrink: 0;
}
.avatar .platform-dot { position: absolute; bottom: -2px; right: -2px; width: 14px; height: 14px; border-width: 2px; }
.platform-dot svg { width: 8px; height: 8px; }

/* ---------- Conversation list pane ---------- */
.list-pane {
  width: 360px; flex-shrink: 0; background: #F8FAFC;
  border-right: 1px solid #E2E8F0; height: 100%;
  display: flex; flex-direction: column; z-index: 20;
}
.list-header { padding: 14px 14px 10px; border-bottom: 1px solid #E2E8F0; background: #F8FAFC; flex-shrink: 0; }

.search-box {
  display: flex; align-items: center; gap: 8px; margin-top: 12px;
  background: #fff; border: 1px solid #E2E8F0; border-radius: 10px; padding: 8px 10px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.search-box:focus-within { border-color: #2563EB; box-shadow: 0 0 0 3px #EFF6FF; }
.search-box input { border: none; outline: none; font-size: 13.5px; width: 100%; background: transparent; }
.search-box input::placeholder { color: #94A3B8; }

.chip {
  flex-shrink: 0; font-size: 12px; font-weight: 600; padding: 6px 11px; border-radius: 99px;
  background: #fff; border: 1px solid #E2E8F0; color: #475569;
  transition: all .15s ease; white-space: nowrap;
}
.chip:hover { border-color: #CBD5E1; }
.chip-active { background: #0F172A; border-color: #0F172A; color: #fff; }

.thread-list { flex: 1; overflow-y: auto; }

.thread-item {
  display: flex; gap: 10px; width: 100%; text-align: left;
  padding: 12px 14px; border-bottom: 1px solid #EEF2F7; position: relative;
  transition: background-color .12s ease;
}
.thread-item:hover { background: #F1F5F9; }
.thread-item.selected { background: #EFF6FF; }
.thread-item.selected::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: #2563EB;
}
.thread-item .avatar-wrap { position: relative; flex-shrink: 0; }

.thread-top { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.thread-name { font-size: 13.5px; font-weight: 600; color: #0F172A; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-time { font-size: 11px; color: #94A3B8; flex-shrink: 0; }
.thread-preview { font-size: 12.5px; color: #64748B; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.thread-item.unread .thread-preview { color: #1E293B; font-weight: 500; }
.thread-item.unread .thread-name { font-weight: 700; }

.thread-badges { display: flex; align-items: center; gap: 5px; margin-top: 5px; }
.unread-badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px; background: #DC2626;
  color: #fff; font-size: 10.5px; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.tag-pill {
  font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 99px;
  background: #F1F5F9; color: #475569; letter-spacing: .01em;
}
.tag-pill.sla { background: #FEE2E2; color: #DC2626; }
.tag-pill.assigned { background: #EFF6FF; color: #2563EB; }

/* ---------- Chat pane ---------- */
.chat-pane { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; background: #fff; }
.chat-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px; }
.empty-badge {
  width: 64px; height: 64px; border-radius: 20px; background: #EFF6FF; color: #2563EB;
  display: flex; align-items: center; justify-content: center; margin-bottom: 14px;
}
.chat-active { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-active.hidden, .chat-empty.hidden { display: none; }

.chat-header {
  display: flex; align-items: center; gap: 10px; padding: 11px 16px;
  border-bottom: 1px solid #E2E8F0; flex-shrink: 0; background: #fff;
}

.sla-banner {
  display: flex; align-items: center; gap: 8px; padding: 8px 16px;
  background: #FEE2E2; color: #B91C1C; font-size: 12.5px; font-weight: 600; flex-shrink: 0;
}
.sla-banner.hidden { display: none; }

.messages {
  flex: 1; overflow-y: auto; padding: 18px 16px; display: flex; flex-direction: column; gap: 4px;
  background:
    radial-gradient(circle at 1px 1px, #EEF2F7 1px, transparent 0) 0 0 / 22px 22px,
    #F8FAFC;
}

.msg-row { display: flex; gap: 8px; max-width: 78%; animation: fadeUp .2s ease-out both; }
.msg-row.out { align-self: flex-end; flex-direction: row-reverse; }
.msg-row.in { align-self: flex-start; }
.msg-row + .msg-row.same { margin-top: -2px; }

.bubble {
  padding: 9px 12px; border-radius: 16px; font-size: 13.5px; line-height: 1.45;
  box-shadow: 0 1px 1px rgba(15,23,42,.03);
}
.msg-row.in .bubble { background: #fff; border: 1px solid #E2E8F0; color: #1E293B; border-bottom-left-radius: 5px; }
.msg-row.out .bubble { background: #2563EB; color: #fff; border-bottom-right-radius: 5px; }
.msg-meta { font-size: 10.5px; color: #94A3B8; margin-top: 3px; padding: 0 3px; display: flex; gap: 5px; align-items: center; }
.msg-row.out .msg-meta { justify-content: flex-end; }

.day-divider { display: flex; align-items: center; gap: 10px; margin: 14px 0 10px; }
.day-divider span { font-size: 11px; font-weight: 700; color: #94A3B8; background: #F8FAFC; padding: 0 8px; }
.day-divider::before, .day-divider::after { content: ''; flex: 1; height: 1px; background: #E2E8F0; }

.system-note {
  align-self: center; font-size: 11.5px; color: #94A3B8; background: #EEF2F7;
  padding: 5px 12px; border-radius: 99px; margin: 6px 0;
}

/* ---------- Composer ---------- */
.composer { border-top: 1px solid #E2E8F0; padding: 10px 14px 12px; flex-shrink: 0; background: #fff; }
.composer-toolbar { display: flex; align-items: center; gap: 2px; margin-bottom: 6px; color: #64748B; }
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.composer-row textarea {
  flex: 1; resize: none; border: 1px solid #E2E8F0; border-radius: 12px; padding: 10px 12px;
  font-size: 13.5px; font-family: inherit; outline: none; max-height: 120px; line-height: 1.4;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.composer-row textarea:focus { border-color: #2563EB; box-shadow: 0 0 0 3px #EFF6FF; }
.send-btn {
  width: 38px; height: 38px; border-radius: 11px; background: #2563EB; color: #fff;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: background-color .15s ease, transform .1s ease;
}
.send-btn:hover { background: #1D4ED8; }
.send-btn:active { transform: scale(.93); }
.send-btn:disabled { background: #CBD5E1; cursor: not-allowed; }

/* ---------- Details pane ---------- */
.details-pane {
  width: 300px; flex-shrink: 0; border-left: 1px solid #E2E8F0; background: #fff;
  height: 100%; overflow-y: auto; z-index: 40;
}
.details-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px; }
.details-body { padding: 4px 16px 24px; }

.detail-section { padding: 14px 0; border-top: 1px solid #F1F5F9; }
.detail-section:first-child { border-top: none; }
.detail-label { font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: #94A3B8; margin-bottom: 8px; }
.detail-row { display: flex; align-items: center; justify-content: space-between; font-size: 12.5px; padding: 5px 0; color: #475569; }
.detail-row b { color: #0F172A; font-weight: 600; }
.kv-pill { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 99px; }

/* ==========================================================================
   Responsive: three panes collapse to a single-pane mobile flow
   ========================================================================== */
@media (min-width: 768px) {
  .mobile-topbar { display: none; }
  .scrim { display: none !important; }
}

@media (max-width: 767.98px) {
  #app { padding-top: 56px; }

  .rail {
    position: fixed; top: 0; bottom: 0; left: 0; width: 78vw; max-width: 300px;
    transform: translateX(-100%); transition: transform .25s ease;
  }
  .rail.open { transform: translateX(0); animation: slideIn .25s ease-out; }
  .rail.open ~ #railScrim, #railScrim.show { display: block; }

  .list-pane {
    position: fixed; inset: 56px 0 0 0; width: 100%; border-right: none;
    transform: translateX(0); transition: transform .25s ease; z-index: 25;
  }
  .list-pane.hide-mobile { transform: translateX(-100%); pointer-events: none; }

  .chat-pane { position: fixed; inset: 56px 0 0 0; z-index: 15; width: 100%; }

  .details-pane {
    position: fixed; top: 0; bottom: 0; right: 0; width: 84vw; max-width: 320px;
    transform: translateX(100%); transition: transform .25s ease; z-index: 45;
  }
  .details-pane.open { transform: translateX(0); }
  .details-pane.open ~ #detailsScrim, #detailsScrim.show { display: block; }

  .msg-row { max-width: 88%; }
}

@media (min-width: 768px) and (max-width: 1023.98px) {
  .details-pane { display: none; }
  .list-pane { width: 320px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
