/* ══════════════════════════════════════
   PakLaw.online — style.css (v4 FINAL)
   Fully responsive: Mobile / Tablet / Desktop
   ✅ Mobile zoom fix (font-size: 16px)
   ✅ Keyboard-aware layout via JS
   ✅ No overlap with site navbar/footer
   ✅ Safe area support (iPhone notch)
   ✅ Landscape mode handled
══════════════════════════════════════ */

:root {
  --primary-blue: #0842a0;
  --action-blue:  #0b57d0;
  --accent-gold:  #c5a059;
  --bg-surface:   #f0f4fb;
  --blue-dark:    #062e75;
  --gold-light:   #dfc07a;
  --gold-dark:    #9a7a38;
  --white:        #ffffff;
  --border:       #d4dff5;
  --border-lt:    #e8eef8;
  --text:         #07214f;
  --text-mid:     #1a3a7a;
  --text-lt:      #5570a8;
  --shadow-sm:    0 2px 8px rgba(8,66,160,.08);
  --shadow-md:    0 6px 24px rgba(8,66,160,.13);
  --shadow-lg:    0 16px 56px rgba(8,66,160,.18);
  --r:            16px;
  --r-sm:         10px;
}

/* ── RESET ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── ZOOM FIX ─────────────────────────
   16px base prevents iOS Safari from
   auto-zooming when textarea is focused.
   text-size-adjust prevents font scaling.
─────────────────────────────────────── */
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: 'Outfit', sans-serif;
  background: var(--bg-surface);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ══════════════════════════════════════
   APP SHELL
   Height injected by JS (fixAppHeight).
   CSS only sets flex structure + min-height.
══════════════════════════════════════ */
.app {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 480px;
  overflow: hidden;
  background: var(--bg-surface);
  transition: height .12s ease;
}

@media (min-width: 900px) {
  .app {
    max-width: 820px;
    margin: 20px auto;
    border-radius: var(--r);
    box-shadow: var(--shadow-lg), 0 0 0 1px rgba(8,66,160,.12);
    transition: none;
  }
}

/* ══════════════════════════════════════
   CHAT HEADER
══════════════════════════════════════ */
.app-header {
  background: linear-gradient(135deg, var(--blue-dark) 0%, var(--primary-blue) 55%, var(--action-blue) 100%);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid rgba(197,160,89,.25);
  flex-shrink: 0;
  z-index: 10;
  touch-action: manipulation;
  user-select: none;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.header-avatar {
  width: 40px; height: 40px; min-width: 40px;
  background: linear-gradient(135deg, var(--gold-dark), var(--accent-gold));
  border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.15rem;
  box-shadow: 0 2px 12px rgba(197,160,89,.4);
  flex-shrink: 0;
}

.header-text { min-width: 0; }

.header-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-sub {
  font-size: .64rem;
  color: rgba(255,255,255,.5);
  margin-top: 2px;
  white-space: nowrap;
}

.header-right { display: flex; align-items: center; flex-shrink: 0; }

.online-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .68rem;
  color: rgba(255,255,255,.6);
  white-space: nowrap;
}

.online-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 6px #4ade80;
  animation: pulse 2s ease infinite;
  flex-shrink: 0;
}

/* ══════════════════════════════════════
   MESSAGES
══════════════════════════════════════ */
.chat-messages {
  flex: 1;
  min-height: 0; /* CRITICAL for flex scroll */
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--bg-surface);
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

@media (min-width: 600px) {
  .chat-messages::-webkit-scrollbar       { width: 4px; }
  .chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
  .chat-messages::-webkit-scrollbar-track { background: transparent; }
}

.msg {
  display: flex;
  gap: 9px;
  animation: msgIn .22s ease both;
  align-items: flex-end;
}
.msg.user { flex-direction: row-reverse; }

.msg-avatar {
  width: 34px; height: 34px; min-width: 34px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: .88rem;
  background: linear-gradient(135deg, var(--gold-dark), var(--accent-gold));
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}
.msg.user .msg-avatar {
  background: linear-gradient(135deg, var(--primary-blue), var(--action-blue));
}

.msg-bubble {
  max-width: 78%;
  padding: 12px 16px;
  border-radius: 18px 18px 18px 4px;
  font-size: .9rem;
  line-height: 1.7;
  color: var(--text);
  background: var(--white);
  border: 1px solid var(--border);
  word-break: break-word;
  overflow-wrap: anywhere;
  box-shadow: var(--shadow-sm);
}
.msg.user .msg-bubble {
  background: linear-gradient(135deg, var(--primary-blue), var(--action-blue));
  color: #fff;
  border: none;
  border-radius: 18px 18px 4px 18px;
  box-shadow: 0 4px 14px rgba(8,66,160,.28);
}

.msg-bubble strong { color: var(--primary-blue); font-weight: 700; }
.msg.user .msg-bubble strong { color: var(--gold-light); }
.msg-bubble p + p { margin-top: 6px; }
.msg-bubble ul { margin: 6px 0 0 16px; }
.msg-bubble li { margin-bottom: 4px; }

.legal-stamp {
  display: inline-block;
  font-size: .6rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--gold-dark);
  border: 1px solid rgba(197,160,89,.35);
  background: rgba(197,160,89,.09);
  padding: 2px 8px;
  border-radius: 20px;
  margin-bottom: 8px;
}

.msg-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  padding-left: 2px;
}
.msg.user .msg-footer { flex-direction: row-reverse; padding-left: 0; padding-right: 2px; }

.msg-meta {
  font-size: .6rem;
  color: var(--text-lt);
}

.dl-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: .6rem;
  font-weight: 600;
  color: var(--text-lt);
  background: none;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 9px;
  cursor: pointer;
  transition: all .15s;
  font-family: 'Outfit', sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.dl-btn:hover, .dl-btn:active {
  background: var(--primary-blue);
  color: #fff;
  border-color: var(--primary-blue);
}

.typing-indicator { display: flex; gap: 5px; padding: 6px 2px; align-items: center; }
.typing-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-lt);
  animation: typingBounce .9s ease infinite;
}
.typing-dot:nth-child(2) { animation-delay: .15s; }
.typing-dot:nth-child(3) { animation-delay: .3s; }

/* ══════════════════════════════════════
   INPUT AREA
══════════════════════════════════════ */
.input-area {
  background: var(--white);
  border-top: 1px solid var(--border-lt);
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
  flex-shrink: 0;
}

.input-hint {
  font-size: .6rem;
  color: var(--text-lt);
  margin-bottom: 7px;
  display: none;
}

@media (min-width: 900px) {
  .input-hint { display: block; }
}

.input-row {
  display: flex;
  gap: 9px;
  align-items: flex-end;
}

/* ── TEXTAREA ──────────────────────────
   font-size: 16px is the MOST IMPORTANT
   mobile fix. iOS Safari zooms in on any
   input with font-size < 16px. Keep it
   at 16px on ALL mobile breakpoints.
─────────────────────────────────────── */
.chat-textarea {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  padding: 11px 14px;
  font-family: 'Outfit', sans-serif;
  font-size: 16px;        /* ZOOM FIX — do not reduce on mobile */
  color: var(--text);
  background: var(--bg-surface);
  outline: none;
  resize: none;
  min-height: 46px;
  max-height: 120px;
  line-height: 1.5;
  transition: border .18s, box-shadow .18s;
  -webkit-appearance: none;
  appearance: none;
  touch-action: manipulation;
}
.chat-textarea:focus {
  border-color: var(--action-blue);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(11,87,208,.1);
}
.chat-textarea::placeholder { color: var(--text-lt); font-size: 15px; }

.send-btn {
  width: 46px; height: 46px; min-width: 46px;
  border-radius: var(--r-sm);
  border: none;
  background: linear-gradient(135deg, var(--gold-dark), var(--accent-gold));
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  transition: transform .18s, box-shadow .18s, opacity .18s;
  box-shadow: 0 3px 14px rgba(197,160,89,.4);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  flex-shrink: 0;
}
.send-btn:hover  { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(197,160,89,.5); }
.send-btn:active { transform: scale(.93); }
.send-btn:disabled { opacity: .4; cursor: not-allowed; transform: none; box-shadow: none; }

/* ══════════════════════════════════════
   DOWNLOAD BOTTOM SHEET
══════════════════════════════════════ */
.dl-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(6,46,117,.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 800;
}
.dl-overlay.show { display: block; }

.dl-menu {
  position: fixed;
  bottom: 0; left: 50%;
  transform: translateX(-50%) translateY(100%);
  width: min(460px, 100%);
  background: var(--white);
  border-radius: 20px 20px 0 0;
  padding: 8px 18px;
  padding-bottom: max(24px, env(safe-area-inset-bottom, 24px));
  z-index: 900;
  box-shadow: 0 -8px 40px rgba(8,66,160,.2);
  border-top: 2px solid var(--primary-blue);
  transition: transform .3s cubic-bezier(.32,.72,0,1);
}
.dl-menu.show { transform: translateX(-50%) translateY(0); }

.dl-menu::before {
  content: '';
  display: block;
  width: 38px; height: 4px;
  background: var(--border);
  border-radius: 3px;
  margin: 10px auto 14px;
}

.dl-menu-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--blue-dark);
  margin-bottom: 12px;
  text-align: center;
}

.dl-item {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  padding: 12px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--bg-surface);
  cursor: pointer;
  margin-bottom: 8px;
  transition: background .14s, border-color .14s;
  font-family: 'Outfit', sans-serif;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.dl-item:hover, .dl-item:active {
  background: var(--primary-blue);
  border-color: var(--primary-blue);
}
.dl-item:hover .dl-label, .dl-item:active .dl-label { color: #fff; }
.dl-item:hover .dl-desc,  .dl-item:active .dl-desc  { color: rgba(255,255,255,.65); }

.dl-icon  { font-size: 1.4rem; flex-shrink: 0; }
.dl-label { font-size: .86rem; font-weight: 700; color: var(--text-mid); line-height: 1.3; }
.dl-desc  { font-size: .7rem;  color: var(--text-lt); margin-top: 1px; }

.dl-cancel {
  width: 100%;
  padding: 11px;
  border: none;
  background: none;
  color: var(--text-lt);
  font-size: .83rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--r-sm);
  font-family: 'Outfit', sans-serif;
  margin-top: 2px;
  transition: background .14s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.dl-cancel:hover, .dl-cancel:active { background: var(--bg-surface); color: var(--text); }

/* ══════════════════════════════════════
   TOAST
══════════════════════════════════════ */
.ca-toast {
  position: fixed;
  bottom: 24px; right: 16px;
  background: var(--primary-blue);
  color: #fff;
  padding: 10px 16px;
  border-radius: 9px;
  font-size: .78rem;
  font-weight: 600;
  border-left: 3px solid var(--accent-gold);
  box-shadow: var(--shadow-lg);
  transform: translateY(12px);
  opacity: 0;
  transition: all .28s ease;
  pointer-events: none;
  z-index: 9999;
  max-width: calc(100vw - 32px);
  font-family: 'Outfit', sans-serif;
}
.ca-toast.show { transform: translateY(0); opacity: 1; }

/* ══════════════════════════════════════
   LINK STYLES
══════════════════════════════════════ */
.msg-bubble a, .legal-link {
  color: var(--accent-gold) !important;
  background-color: rgba(197,160,89,.1);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  font-weight: 500;
  transition: all .18s;
  border-radius: 3px;
  padding: 1px 3px;
}
.msg-bubble a:hover, .legal-link:hover {
  color: var(--gold-light) !important;
  background-color: rgba(197,160,89,.18);
  text-decoration-thickness: 2px;
}

/* ══════════════════════════════════════
   ANIMATIONS
══════════════════════════════════════ */
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .35; }
}
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%           { transform: translateY(-5px); }
}

/* ══════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════ */

/* Tablet */
@media (min-width: 600px) and (max-width: 899px) {
  .app-header    { padding: 13px 18px; }
  .chat-messages { padding: 18px 16px; gap: 14px; }
  .msg-bubble    { max-width: 76%; }
  .input-area    { padding: 12px 16px; padding-bottom: max(12px, env(safe-area-inset-bottom,12px)); }
}

/* Mobile portrait */
@media (max-width: 599px) {
  .app-header    { padding: 10px 13px; }
  .header-avatar { width: 35px; height: 35px; min-width: 35px; font-size: .98rem; border-radius: 9px; }
  .header-title  { font-size: .96rem; }
  .header-sub    { display: none; }

  .chat-messages { padding: 13px 11px; gap: 12px; }

  .msg           { gap: 7px; }
  .msg-avatar    { width: 30px; height: 30px; min-width: 30px; font-size: .75rem; border-radius: 8px; }
  .msg-bubble    {
    max-width: 87%;
    font-size: .875rem;
    padding: 10px 13px;
    border-radius: 16px 16px 16px 4px;
  }
  .msg.user .msg-bubble { border-radius: 16px 16px 4px 16px; }

  .input-area    { padding: 10px 11px; padding-bottom: max(10px, env(safe-area-inset-bottom,10px)); }
  .chat-textarea {
    font-size: 16px; /* KEEP AT 16px — zoom prevention */
    min-height: 44px;
    padding: 10px 12px;
  }
  .send-btn      { width: 44px; height: 44px; min-width: 44px; }
  .dl-menu       { width: 100%; }
  .ca-toast      { bottom: 12px; right: 10px; left: 10px; max-width: 100%; text-align: center; }
}

/* Small phones */
@media (max-width: 390px) {
  .header-title  { font-size: .86rem; }
  .msg-bubble    { max-width: 91%; font-size: .84rem; }
  .chat-messages { padding: 11px 9px; }
  .chat-textarea { padding: 9px 11px; }
}

/* Landscape mobile — reduced vertical padding */
@media (max-height: 500px) and (max-width: 900px) {
  .app-header    { padding: 7px 13px; }
  .header-avatar { width: 30px; height: 30px; min-width: 30px; font-size: .84rem; }
  .chat-messages { padding: 9px 11px; gap: 8px; }
  .input-area    { padding: 7px 11px; padding-bottom: max(7px, env(safe-area-inset-bottom,7px)); }
  .chat-textarea { min-height: 38px; padding: 7px 11px; }
  .send-btn      { width: 38px; height: 38px; min-width: 38px; }
}