/* =====================================================================
   app.css — additions on top of the original styles.css (kept verbatim).
   1) New components: client switcher, login, WhatsApp linking, toasts,
      empty states, setup cards.
   2) Mobile-first hardening for the web app and the Android app shell:
      safe areas, 100dvh, bottom-sheet modals, 44px tap targets,
      no horizontal scroll, keyboard-aware chat.
   ===================================================================== */

:root {
  --wa-green: #00A884;
  --wa-green-dark: #008069;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --mobile-nav-h: 68px;
}

html { -webkit-text-size-adjust: 100%; }
body { overscroll-behavior-y: none; }
button, a, select, input { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
body.modal-open { overflow: hidden; }
.page-subtitle { font-size: .82rem; color: var(--text-muted); margin-top: 2px; font-weight: 500; }

/* ---------- small primitives ---------- */
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; text-align: left; }
.customer-name.link-btn:hover { color: var(--fareworks-blue); text-decoration: underline; text-underline-offset: 3px; }
.wa-link-switch .link-btn, .wa-qr-box .link-btn { color: var(--wa-green-dark); font-weight: 700; font-size: .88rem; text-decoration: underline; text-underline-offset: 3px; }
.btn-xs { padding: .3rem .65rem !important; font-size: .75rem !important; }
.btn-sm { padding: .45rem .9rem !important; font-size: .8rem !important; }
.btn-wa-green { background: var(--wa-green) !important; border-color: var(--wa-green) !important; }
.btn-wa-green:hover { background: var(--wa-green-dark) !important; }
.btn-danger { background: #DC2626 !important; border-color: #DC2626 !important; }
.btn-danger-outline { color: #DC2626 !important; border-color: #FECACA !important; background: #FEF2F2 !important; font-weight: 700 !important; }
.btn-delete-left { margin-right: auto; color: #DC2626 !important; border-color: #FECACA !important; }
.btn-add-lead { display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; }
.btn-quick-schedule { font-size: .78rem !important; padding: .35rem .8rem !important; font-weight: 700 !important; color: var(--fareworks-blue) !important; border-color: #BFDBFE !important; background: #EFF6FF !important; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.muted-xs { font-size: .74rem; color: #64748B; }
.card-h { font-size: .95rem; font-weight: 700; color: #0F172A; margin: 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-sub { font-size: .78rem; color: #64748B; margin: 2px 0 0; }
.card-lines { font-size: .8rem; color: #475569; display: flex; flex-direction: column; gap: 4px; }
.card-foot { display: flex; gap: 8px; margin-top: auto; padding-top: 8px; border-top: 1px solid #F1F5F9; justify-content: flex-end; }
.strike { font-size: .82rem; color: #94A3B8; font-weight: 400; }
.hint, .field-hint { font-weight: 500; color: #94A3B8; font-size: .72rem; }
.field-hint { display: block; margin-top: 4px; }

/* forms */
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid-2 .full { grid-column: 1 / -1; }
.form-section-title { font-size: .8rem; font-weight: 800; color: #0F172A; margin-top: 6px; padding-top: 10px; border-top: 1px solid #F1F5F9; }
.form-section-title span { color: #94A3B8; font-weight: 600; }
textarea.form-control { resize: vertical; font-family: inherit; font-size: .88rem; padding: .6rem .85rem; min-height: 64px; height: auto; }
.form-control[readonly] { background: #F8FAFD; color: #64748B; }
.check-row { display: flex; align-items: center; gap: 10px; font-size: .86rem; font-weight: 600; color: #334155; cursor: pointer; min-height: 40px; }
.check-row input { width: 18px; height: 18px; accent-color: var(--fareworks-blue); }
.info-banner { background: #EEF2FF; border: 1px solid #C7D2FE; color: #3730A3; border-radius: 10px; padding: 10px 14px; font-size: .8rem; font-weight: 600; line-height: 1.45; }
.info-banner.green { background: #F0FDF4; border-color: #BBF7D0; color: #166534; }
.info-banner.amber { background: #FFFBEB; border-color: #FDE68A; color: #92400E; margin-bottom: 14px; }

/* empty / loading */
.list-loading { padding: 40px 12px; text-align: center; color: #94A3B8; font-weight: 600; font-size: .88rem; }
.empty-inline { padding: 28px 12px; text-align: center; color: #64748B; font-size: .88rem; background: #fff; border: 1px dashed #CBD5E1; border-radius: 12px; }
.empty-block { background: #fff; border: 1px dashed #CBD5E1; border-radius: 16px; padding: 44px 20px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty-block.compact { padding: 32px 18px; }
.empty-block .empty-icon { font-size: 2.2rem; line-height: 1; }
.empty-block h2 { font-size: 1.1rem; font-weight: 800; color: var(--navy-dark); }
.empty-block p { max-width: 440px; color: #64748B; font-size: .88rem; line-height: 1.5; }
.empty-block .btn-add-lead { margin-top: 6px; }

/* toast */
.app-toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translate(-50%, 16px); opacity: 0; background: #0F172A; color: #fff; padding: 11px 18px; border-radius: 10px; font-size: .85rem; font-weight: 700; z-index: 100000; box-shadow: 0 10px 25px rgba(0,0,0,.3); transition: opacity .2s, transform .2s; max-width: min(92vw, 520px); text-align: center; pointer-events: none; }
.app-toast.show { opacity: 1; transform: translate(-50%, 0); }
.app-toast.err { background: #B91C1C; }

/* ---------- header: client switcher ---------- */
.client-switcher { position: relative; flex-shrink: 1; min-width: 0; }
.client-switch-btn { display: flex; align-items: center; gap: 8px; background: #fff; border: 1px solid var(--border-card); border-radius: 9999px; padding: 5px 12px 5px 6px; cursor: pointer; max-width: 280px; min-height: 44px; box-shadow: 0 1px 3px rgba(10,13,49,.04); transition: all .2s; }
.client-switch-btn:hover, .client-switch-btn[aria-expanded="true"] { border-color: var(--fareworks-blue); background: var(--fareworks-blue-light); }
.client-switch-icon { width: 32px; height: 32px; border-radius: 50%; background: #EEF2FF; color: var(--fareworks-blue); display: grid; place-items: center; flex-shrink: 0; }
.client-switch-icon svg { width: 17px; height: 17px; }
.client-switch-text { display: flex; flex-direction: column; min-width: 0; text-align: left; line-height: 1.15; }
.client-switch-kicker { font-size: .62rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: #94A3B8; }
.client-switch-name { font-size: .85rem; font-weight: 800; color: var(--navy-dark); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.client-switch-btn[aria-expanded="true"] .dropdown-chevron { transform: rotate(180deg); }
.wa-dot { width: 9px; height: 9px; border-radius: 50%; background: #CBD5E1; flex-shrink: 0; box-shadow: 0 0 0 2px #fff; }
.wa-dot.on { background: #22C55E; }
.wa-dot.pending { background: #F59E0B; animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .4; } }
.client-dropdown { width: 300px; left: 0; right: auto; padding: 8px 0 6px; }
.client-dd-search { padding: 4px 10px 8px; }
.client-dd-search input { width: 100%; height: 38px; border: 1px solid #E2E8F0; border-radius: 8px; padding: 0 12px; font: inherit; font-size: .85rem; outline: none; }
.client-dd-search input:focus { border-color: var(--fareworks-blue); }
.client-dd-list { max-height: 300px; overflow-y: auto; }
.client-dd-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 14px; background: none; border: 0; cursor: pointer; text-align: left; font: inherit; min-height: 48px; }
.client-dd-item:hover { background: #F8FAFD; }
.client-dd-item.active { background: #EEF2FF; }
.client-dd-avatar { width: 32px; height: 32px; border-radius: 50%; background: #F1F5F9; color: var(--navy-dark); font-weight: 800; font-size: .78rem; display: grid; place-items: center; flex-shrink: 0; }
.client-dd-item.active .client-dd-avatar { background: var(--fareworks-blue); color: #fff; }
.client-dd-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.client-dd-text strong { font-size: .86rem; color: var(--navy-dark); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.client-dd-text small { font-size: .74rem; color: #64748B; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.client-dd-empty { padding: 14px; text-align: center; color: #94A3B8; font-size: .85rem; }
.notif-empty { padding: 22px 16px; text-align: center; color: #94A3B8; font-size: .85rem; }
a.notif-item { text-decoration: none; color: inherit; }
.desktop-inline { display: inline-flex; }

/* ---------- mobile FAB (primary action on each page) ---------- */
.mobile-fab { display: none; }

/* ---------- login ---------- */
body.login-page { min-height: 100dvh; display: flex; align-items: center; justify-content: center; background: radial-gradient(1200px 600px at 10% -10%, #E0E7FF 0%, transparent 60%), radial-gradient(900px 500px at 110% 110%, #DCFCE7 0%, transparent 55%), var(--bg-page); padding: 20px 16px calc(20px + var(--safe-bottom)); }
.login-wrap { width: 100%; max-width: 420px; display: flex; flex-direction: column; align-items: center; gap: 18px; }
.login-card { width: 100%; background: #fff; border: 1px solid var(--border-card); border-radius: 20px; padding: 32px 28px; box-shadow: 0 20px 50px -12px rgba(10,13,49,.15); }
.login-logo { height: 36px; width: auto; display: block; margin-bottom: 22px; }
.login-card h1 { font-size: 1.45rem; font-weight: 800; color: var(--navy-dark); }
.login-sub { color: #64748B; font-size: .88rem; margin: 6px 0 22px; line-height: 1.45; }
.login-card .input-label { margin-top: 12px; display: block; }
.login-card .form-control { height: 48px; font-size: 1rem; }
.pw-wrap { position: relative; }
.pw-wrap .form-control { padding-right: 64px; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: #F1F5F9; color: #334155; font: inherit; font-size: .75rem; font-weight: 700; border-radius: 6px; padding: 6px 10px; cursor: pointer; }
.login-error { margin-top: 12px; background: #FEF2F2; border: 1px solid #FECACA; color: #B91C1C; border-radius: 8px; padding: 9px 12px; font-size: .84rem; font-weight: 600; }
.login-btn { width: 100%; height: 48px; margin-top: 20px; font-size: 1rem !important; }
.login-btn:disabled { opacity: .7; }
.login-foot { font-size: .78rem; color: #94A3B8; }
.login-foot a { color: var(--fareworks-blue); font-weight: 700; text-decoration: none; }

/* ---------- bookings extras ---------- */
.slot-time-pill.live { background: #FEF3C7 !important; color: #B45309 !important; border-color: #FCD34D !important; }
.cal-day-cell { font: inherit; border: 0; background: transparent; cursor: pointer; }
.no-client-slot { margin-top: 4px; }

/* ---------- WhatsApp page ---------- */
body.wa-page { height: 100dvh; overflow: hidden; }
.wa-shell { height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
.wa-shell > .wa-web-container, .wa-shell > .wa-link-screen, .wa-shell > .wa-noclient { flex: 1 1 0; min-height: 0; }
.wa-noclient { padding: 24px 16px; overflow: auto; }
.wa-chat-placeholder { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 10px; padding: 24px; background: #F0F2F5; border-bottom: 6px solid var(--wa-green); color: #54656F; }
.wa-chat-placeholder h2 { font-size: 1.35rem; font-weight: 700; color: #41525D; }
.wa-chat-placeholder p { max-width: 420px; font-size: .9rem; line-height: 1.5; }
.wa-ph-icon { width: 72px; height: 72px; border-radius: 50%; background: #DCF8C6; color: var(--wa-green); display: grid; place-items: center; }
.wa-ph-icon svg { width: 38px; height: 38px; }
.wa-list-empty { padding: 28px 18px; text-align: center; color: #667781; font-size: .85rem; display: flex; flex-direction: column; gap: 6px; line-height: 1.45; }
.wa-list-empty strong { color: #111B21; font-size: .95rem; }
.wa-chat-avatar { background: #DFE5E7; color: #54656F; }
.wa-meta-phone { font-size: .7rem; color: #64748B; }
.wa-chat-preview-text .tick { color: #53BDEB; font-size: .72rem; letter-spacing: -2px; }
.wa-msg-bubble { white-space: normal; word-wrap: break-word; overflow-wrap: anywhere; }
.wa-msg-bubble a { color: #027EB5; }
.wa-msg-bubble.pending { opacity: .7; }
.msg-clock { font-size: .7rem; }
.qr-label { font-size: .7rem; font-weight: 800; color: #64748B; flex-shrink: 0; text-transform: uppercase; }
.wa-menu-wrap { position: relative; }
.wa-menu { right: 0; width: 230px; }
.wa-input-row { display: flex; align-items: flex-end; gap: 8px; }
textarea.wa-message-input { resize: none; height: 44px; min-height: 44px; max-height: 120px; padding: 11px 16px; line-height: 1.4; overflow-y: auto; }
.wa-send-btn { flex-shrink: 0; }
.wa-send-btn svg { width: 20px; height: 20px; }
.btn-wa-make-lead, .btn-wa-book-appt { display: inline-flex; }

/* Link-a-device screen */
.wa-link-screen { background: linear-gradient(#00A884 0 190px, #F0F2F5 190px); overflow-y: auto; padding: 36px 20px calc(28px + var(--safe-bottom)); }
.wa-link-card { max-width: 1000px; margin: 0 auto; background: #fff; border-radius: 16px; box-shadow: 0 17px 50px rgba(11,20,26,.19), 0 12px 15px rgba(11,20,26,.12); display: grid; grid-template-columns: 1fr auto; gap: 40px; padding: 48px 52px; }
.wa-link-kicker { display: inline-flex; align-items: center; gap: 8px; font-size: .75rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--wa-green-dark); background: #E7F8F3; padding: 6px 10px; border-radius: 999px; }
.wa-link-logo svg { width: 16px; height: 16px; display: block; }
.wa-link-title { font-size: 1.7rem; font-weight: 600; color: #41525D; margin: 16px 0 8px; line-height: 1.25; }
.wa-link-title span { color: #111B21; font-weight: 800; }
.wa-link-sub { color: #667781; font-size: .95rem; line-height: 1.5; margin-bottom: 22px; }
.wa-link-steps { counter-reset: s; list-style: none; display: flex; flex-direction: column; gap: 16px; margin: 0 0 22px; padding: 0; }
.wa-link-steps li { counter-increment: s; display: flex; gap: 14px; align-items: flex-start; font-size: 1rem; color: #3B4A54; line-height: 1.45; }
.wa-link-steps li::before { content: counter(s); width: 28px; height: 28px; border-radius: 50%; border: 1.5px solid #8696A0; color: #54656F; font-size: .85rem; font-weight: 700; display: grid; place-items: center; flex-shrink: 0; }
.wa-link-foot { color: #8696A0; font-size: .82rem; margin-top: 22px; line-height: 1.5; }
.wa-link-right { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.wa-qr-box { width: 280px; min-height: 280px; display: flex; flex-direction: column; align-items: center; justify-content: center; position: relative; border-radius: 12px; }
.wa-qr-img { width: 264px; height: 264px; display: block; image-rendering: pixelated; }
.wa-qr-logo { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 52px; height: 52px; border-radius: 50%; background: var(--wa-green); border: 5px solid #fff; display: grid; place-items: center; }
.wa-qr-logo svg { width: 24px; height: 24px; }
.wa-qr-caption { max-width: 280px; text-align: center; color: #667781; font-size: .82rem; line-height: 1.45; }
.wa-qr-state { display: flex; flex-direction: column; align-items: center; gap: 14px; color: #54656F; font-weight: 600; font-size: .9rem; text-align: center; }
.wa-qr-placeholder { width: 200px; height: 200px; border-radius: 12px; background: repeating-linear-gradient(45deg, #F0F2F5 0 10px, #E9EDEF 10px 20px); display: grid; place-items: center; color: #C9D2D7; }
.wa-qr-placeholder svg { width: 64px; height: 64px; }
.wa-qr-error { background: #FEF2F2; border: 1px solid #FECACA; color: #B91C1C; border-radius: 8px; padding: 8px 12px; font-size: .8rem; font-weight: 600; max-width: 260px; }
.wa-spinner { width: 46px; height: 46px; border-radius: 50%; border: 4px solid #E9EDEF; border-top-color: var(--wa-green); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.wa-pair-form { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.wa-pair-form .form-control { height: 48px; font-size: 1.05rem; }
.wa-pair-form .btn-add-lead { height: 46px; }
.wa-pair-code { display: flex; gap: 6px; align-items: center; justify-content: center; flex-wrap: nowrap; }
.wa-pair-code span { width: 30px; height: 44px; border: 1.5px solid #D1D7DB; border-radius: 8px; display: grid; place-items: center; font-size: 1.35rem; font-weight: 800; color: #111B21; font-family: ui-monospace, Menlo, Consolas, monospace; }
.wa-pair-code span.dash { border: 0; width: 12px; color: #8696A0; }

/* ---------- Setup hub ---------- */
.setup-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.setup-h3 { font-size: 1rem; font-weight: 700; color: #0F172A; margin: 22px 0 12px; }
.setup-h3.first { margin-top: 0; }
.setup-h3.danger { color: #B91C1C; }
.bar-list { display: flex; flex-direction: column; gap: 10px; background: #fff; border: 1px solid #E2E8F0; border-radius: 12px; padding: 16px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 220px) 1fr 40px; gap: 12px; align-items: center; font-size: .84rem; }
.bar-name { font-weight: 700; color: #0F172A; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { height: 10px; background: #F1F5F9; border-radius: 99px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: linear-gradient(90deg, #010ED0, #6366F1); border-radius: 99px; }
.bar-val { text-align: right; font-weight: 800; color: #334155; }
.client-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.client-card { background: #fff; border: 1px solid #E2E8F0; border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow-card); }
.client-card.current { border-color: var(--fareworks-blue); box-shadow: 0 0 0 3px rgba(1,14,208,.08); }
.client-card-top { display: flex; align-items: center; gap: 12px; }
.client-card-title { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.client-card-title strong { font-size: .95rem; color: #0F172A; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.client-card-title small { font-size: .76rem; color: #64748B; }
.client-wa-row { display: flex; align-items: center; gap: 8px; font-size: .8rem; font-weight: 600; color: #64748B; background: #F8FAFC; border-radius: 8px; padding: 8px 10px; }
.client-wa-row.on { background: #F0FDF4; color: #166534; }
.client-card-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.settings-card { background: #fff; border: 1px solid #E2E8F0; border-radius: 12px; padding: 24px; max-width: 820px; }
.wa-settings-row, .danger-row { display: flex; justify-content: space-between; align-items: center; gap: 14px; border-radius: 10px; padding: 14px 16px; background: #F8FAFC; border: 1px solid #E2E8F0; }
.wa-settings-row.on { background: #F0FDF4; border-color: #BBF7D0; }
.wa-settings-row p, .danger-row p { margin: 2px 0 0; font-size: .78rem; color: #64748B; }
.danger-row { background: #FEF2F2; border-color: #FECACA; }
.workflow-card { margin-bottom: 12px; }
.workflow-card.disabled { opacity: .65; }
.tpl-name { font-size: .88rem; color: #0F172A; }
.sidebar-menu-badge:empty { display: none; }
.sidebar-menu-badge.warn { background: #FEF3C7; color: #D97706; }
.sidebar-menu-badge.ok { background: #DCFCE7; color: #15803D; }
.setup-table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* =====================================================================
   TABLET
   ===================================================================== */
@media (max-width: 1100px) {
  .client-switch-btn { max-width: 210px; }
}
@media (max-width: 900px) {
  .wa-link-card { grid-template-columns: 1fr; padding: 32px 28px; gap: 24px; }
  .wa-link-right { order: -1; }
}

/* =====================================================================
   PHONE (web + Android app)
   ===================================================================== */
@media (max-width: 768px) {
  /* Normal pages scroll; only the WhatsApp page is a fixed-height app view.
     (The original stylesheet locked every page's container on mobile.) */
  body:not(.wa-page) .dashboard-container { height: auto !important; max-height: none !important; overflow: visible !important; }
  body { padding-bottom: calc(var(--mobile-nav-h) + var(--safe-bottom)) !important; }
  body.login-page { padding-bottom: calc(20px + var(--safe-bottom)) !important; }
  header.app-header { padding-top: calc(10px + var(--safe-top)) !important; height: auto !important; min-height: calc(56px + var(--safe-top)) !important; }

  .mobile-bottom-nav { padding-bottom: var(--safe-bottom) !important; height: calc(var(--mobile-nav-h) + var(--safe-bottom)) !important; }
  .mobile-nav-badge { display: flex; }

  /* header: logo · client · bell · avatar */
  .header-right-actions { gap: 6px !important; min-width: 0; flex: 1 1 auto; justify-content: flex-end; }
  .client-switch-btn { padding: 4px 8px 4px 4px; gap: 6px; max-width: 46vw; min-height: 40px; }
  .client-switch-icon { width: 30px; height: 30px; }
  .client-switch-kicker { display: none; }
  .client-switch-name { font-size: .8rem; }
  .client-switch-btn .dropdown-chevron { display: none; }
  .client-dropdown { position: fixed !important; left: 10px !important; right: 10px !important; top: calc(60px + var(--safe-top)) !important; width: auto !important; }
  .user-dropdown-menu, .notification-dropdown { max-width: calc(100vw - 20px); }
  .notification-dropdown { position: fixed !important; left: 10px !important; right: 10px !important; top: calc(60px + var(--safe-top)) !important; width: auto !important; }
  .user-profile-btn { padding: 3px !important; }
  .user-profile-btn .dropdown-chevron { display: none; }
  .desktop-inline { display: none !important; }

  /* primary action floats above the bottom nav (the desktop dock is hidden on phones) */
  .mobile-fab { display: grid; place-items: center; position: fixed; right: 16px; bottom: calc(var(--mobile-nav-h) + 16px + var(--safe-bottom)); width: 56px; height: 56px; border-radius: 18px; border: 0; background: var(--fareworks-blue); color: #fff; box-shadow: 0 10px 24px rgba(1,14,208,.35); z-index: 900; cursor: pointer; transition: transform .15s; }
  .mobile-fab:active { transform: scale(.94); }
  .mobile-fab svg { width: 24px; height: 24px; }
  body.modal-open .mobile-fab { display: none; }
  .workspace-card, main.workspace-card { padding-bottom: 96px !important; }

  /* Modals become bottom sheets: thumb-reachable, keyboard friendly */
  .modal-overlay { align-items: flex-end !important; padding: 0 !important; }
  .modal-overlay .modal-card { width: 100% !important; max-width: 100% !important; max-height: 92dvh; border-radius: 18px 18px 0 0 !important; display: flex; flex-direction: column; animation: sheetUp .22s cubic-bezier(.16,1,.3,1); margin: 0 !important; }
  .modal-overlay .modal-card form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
  .modal-overlay .modal-body { overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1 1 auto; }
  .modal-overlay .modal-footer { padding-bottom: calc(14px + var(--safe-bottom)) !important; position: sticky; bottom: 0; background: #fff; }
  .modal-overlay .modal-footer .btn-add-lead { flex: 1; min-height: 46px; }
  .modal-overlay .modal-footer .btn-cancel { min-height: 46px; }
  .modal-header::before { content: ''; position: absolute; left: 50%; top: 6px; transform: translateX(-50%); width: 40px; height: 4px; border-radius: 4px; background: #E2E8F0; }
  .modal-header { position: relative; }
  @keyframes sheetUp { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
  .form-grid-2 { grid-template-columns: 1fr; gap: 10px; }
  /* 16px inputs stop mobile browsers from zooming on focus */
  .form-control, .search-input, .wa-search-input, .wa-message-input, .client-dd-search input, select.filter-select { font-size: 16px !important; }
  .form-control { min-height: 44px; }

  /* comfortable tap targets on list rows */
  .status-select-pill { min-height: 36px; }
  .btn-phone-pill, .btn-whatsapp-pill, .btn-phone-sm, .btn-whatsapp-sm { min-height: 36px; display: inline-flex; align-items: center; }
  .lead-card .customer-name.link-btn { font-size: .95rem; }

  /* Setup hub: sidebar turns into a sticky horizontal tab strip */
  body.setup-page .setup-layout-wrapper { display: block !important; height: auto !important; margin-bottom: 0 !important; overflow: visible !important; }
  body.setup-page .setup-sticky-sidebar { position: sticky !important; top: calc(56px + var(--safe-top)); z-index: 50; width: 100% !important; height: auto !important; max-height: none !important; border-right: 0 !important; border-bottom: 1px solid #E2E8F0 !important; background: #fff !important; padding: 8px 0 !important; overflow: visible !important; display: block !important; transform: none !important; }
  body.setup-page .sidebar-nav-menu { display: flex !important; flex-direction: row !important; gap: 6px !important; overflow-x: auto !important; padding: 0 12px !important; scrollbar-width: none; }
  body.setup-page .sidebar-nav-menu::-webkit-scrollbar { display: none; }
  body.setup-page .sidebar-section-title { display: none !important; }
  body.setup-page .sidebar-menu-btn { flex: 0 0 auto !important; width: auto !important; white-space: nowrap; border-radius: 999px !important; padding: 8px 14px !important; border: 1px solid #E2E8F0 !important; min-height: 38px; }
  body.setup-page .sidebar-menu-btn.active { border-color: var(--fareworks-blue) !important; }
  body.setup-page .setup-main-content { padding: 14px 12px 110px !important; height: auto !important; overflow: visible !important; }
  .setup-view-header { flex-direction: column; align-items: stretch !important; gap: 10px; }
  .setup-view-title { font-size: 1.2rem !important; }
  .setup-actions .btn-add-lead { width: 100%; min-height: 44px; }
  .setup-actions input { max-width: none !important; }
  .setup-metrics-grid { grid-template-columns: 1fr 1fr !important; gap: 10px !important; }
  .settings-card { padding: 16px; }
  .wa-settings-row, .danger-row { flex-direction: column; align-items: stretch; }
  .client-cards { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 1fr 34px; }
  .bar-row .bar-track { grid-column: 1 / -1; grid-row: 2; }

  /* ---------- WhatsApp: native-app feel ---------- */
  body.wa-page { padding-bottom: 0 !important; }
  body.wa-page .dashboard-container { height: calc(100dvh - var(--mobile-nav-h) - var(--safe-bottom)) !important; max-height: none !important; }
  body.wa-page .wa-web-container { height: auto !important; flex: 1 1 0 !important; }
  /* inside a conversation: hide app header + bottom nav, chat takes the whole screen */
  body.wa-page:has(.wa-web-container.show-chat) header.app-header,
  body.wa-page:has(.wa-web-container.show-chat) .mobile-bottom-nav { display: none !important; }
  body.wa-page:has(.wa-web-container.show-chat) .dashboard-container { height: 100dvh !important; padding-top: var(--safe-top); }
  .wa-chat-footer { bottom: auto !important; position: relative !important; padding: 6px 8px calc(8px + var(--safe-bottom)) !important; }
  body.wa-page:not(:has(.show-chat)) .wa-chat-footer { padding-bottom: 8px !important; }
  textarea.wa-message-input { height: 42px; min-height: 42px; border-radius: 22px; }
  .wa-send-btn { width: 44px !important; height: 44px !important; border-radius: 50% !important; }
  .btn-wa-make-lead span, .btn-wa-book-appt span { display: none; }
  .btn-wa-make-lead, .btn-wa-book-appt { width: 32px; height: 32px; padding: 0 !important; justify-content: center; border-radius: 50% !important; }
  .btn-wa-make-lead svg, .btn-wa-book-appt svg { width: 16px; height: 16px; margin: 0 !important; }
  .wa-lead-status-pill { max-width: 108px; }
  .wa-chat-item { min-height: 72px; }
  .wa-floating-btn { bottom: 18px !important; }
  .wa-chat-placeholder { display: none; }

  .wa-link-screen { padding: 14px 12px 24px; background: linear-gradient(#00A884 0 120px, #F0F2F5 120px); }
  .wa-link-card { padding: 22px 18px; border-radius: 14px; gap: 18px; }
  .wa-link-title { font-size: 1.25rem; margin-top: 12px; }
  .wa-link-sub { font-size: .88rem; margin-bottom: 16px; }
  .wa-link-steps li { font-size: .92rem; }
  .wa-qr-box { width: 100%; min-height: 240px; }
  .wa-qr-img { width: min(264px, 72vw); height: auto; aspect-ratio: 1; }
  .wa-pair-code span { width: 28px; height: 42px; font-size: 1.2rem; }
}

@media (max-width: 380px) {
  .client-switch-btn { max-width: 40vw; }
  .metric-box .metric-label { font-size: .7rem !important; }
  .wa-lead-status-pill { max-width: 92px; }
}

/* Respect users who prefer less motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Modals must sit above the dock (9999) and the mobile bottom nav (9999 !important) */
.modal-overlay { z-index: 10050 !important; }

/* Phone fixes found in testing */
@media (max-width: 768px) {
  /* body is a flex column: stop the WhatsApp shell from growing under the bottom nav */
  body.wa-page .dashboard-container { flex: 0 0 auto !important; }
  /* one-row header: logo · client · bell · avatar */
  header.app-header { flex-wrap: nowrap !important; }
  header.app-header .logo-container { flex: 0 0 auto; }
  header.app-header .logo-img { height: 24px !important; max-height: 24px !important; }
}
@media (max-width: 360px) {
  header.app-header .logo-img { height: 20px !important; }
}
@media (max-width: 768px) {
  header.app-header { padding-left: 12px !important; padding-right: 12px !important; gap: 8px !important; }
  .header-right-actions { overflow: visible; }
  .client-switcher { flex: 0 1 auto; min-width: 0; }
  .client-switch-btn { max-width: 100%; width: 100%; }
  .notification-wrapper, .user-menu-wrapper { flex: 0 0 auto; }
  .notification-btn, .user-profile-btn { width: 40px; height: 40px; }
}
@media (max-width: 768px) {
  header.app-header .header-right-actions { flex: 1 1 0 !important; min-width: 0 !important; }
  .client-switch-text { flex: 1 1 auto; min-width: 0; }
}
@media (max-width: 768px) {
  /* keep "+ Lead" and "Book" reachable in the phone chat header (icon-only) */
  .wa-chat-crm-toolbar .btn-wa-book-appt, .wa-chat-crm-toolbar .btn-wa-make-lead { display: inline-flex !important; align-items: center; flex: 0 0 32px; }
  .wa-chat-crm-toolbar { gap: 5px !important; }
  .wa-lead-status-pill { max-width: 84px !important; padding: 0 4px !important; }
  .wa-chat-topbar { padding: 6px 8px !important; gap: 6px !important; }
}

/* WhatsApp → Leads: latest message on each lead card */
.lead-wa-last { display: flex; align-items: center; gap: 6px; min-width: 0; max-width: 100%; background: #F0FDF4; border: 1px solid #BBF7D0; color: #166534; border-radius: 8px; padding: 6px 10px; font-size: .8rem; font-weight: 600; text-decoration: none; }
.lead-wa-last:hover { border-color: #22C55E; }
.lead-wa-text { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lead-wa-time { flex-shrink: 0; font-size: .7rem; color: #15803D; opacity: .8; font-weight: 500; }
@keyframes leadFlash { from { box-shadow: 0 0 0 3px rgba(34,197,94,.55); } to { box-shadow: var(--shadow-card); } }
.lead-card.lead-flash { animation: leadFlash 1.6s ease-out; }
