/* ============================================================
   PingTag — Stylesheet (mobile-first, capped on desktop)
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green:      #1D9E75;
  --green-lt:   #E1F5EE;
  --green-dk:   #0F6E56;
  --red:        #E24B4A;
  --amber:      #BA7517;
  --amber-lt:   #FAEEDA;
  --text:       #1a1a1a;
  --text-muted: #6b7280;
  --text-hint:  #9ca3af;
  --bg:         #ffffff;
  --bg-2:       #f9fafb;
  --bg-3:       #f3f4f6;
  --border:     rgba(0,0,0,0.10);
  --border-md:  rgba(0,0,0,0.18);
  --radius:     10px;
  --radius-lg:  14px;
  --shadow:     0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:  0 4px 12px rgba(0,0,0,0.10);
}

@media (prefers-color-scheme: dark) {
  :root {
    --text:       #f3f4f6;
    --text-muted: #9ca3af;
    --text-hint:  #6b7280;
    --bg:         #111827;
    --bg-2:       #1f2937;
    --bg-3:       #374151;
    --border:     rgba(255,255,255,0.09);
    --border-md:  rgba(255,255,255,0.15);
    --green-lt:   rgba(29,158,117,0.15);
    --amber-lt:   rgba(186,117,23,0.15);
  }
}

/* ── Base ── */
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-2);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

/* ── Screens ── */
.screen { display: none; }
/* Mobile: fixed full-screen — most reliable for PWA */
.screen.active {
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  overflow: hidden;
  background: var(--bg);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}


/* ── Nav ── */
.nav {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  z-index: 10;
  position: relative;
}
.logo { font-size: 20px; font-weight: 700; letter-spacing: -0.5px; color: var(--green); }
.logo span { color: var(--text); }

/* ── Cards ── */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }
.card-title { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.card-sub   { font-size: 13px; color: var(--text-muted); }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 20px; border-radius: var(--radius);
  font-size: 14px; font-weight: 500; cursor: pointer; border: none;
  font-family: inherit; transition: all 0.15s; text-decoration: none;
}
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-dk); }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border-md); }
.btn-ghost:hover { background: var(--bg-2); }
.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn-full { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Inputs ── */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin-bottom: 6px; }
.input { width: 100%; padding: 10px 14px; border: 1px solid var(--border-md); border-radius: var(--radius); font-size: 14px; background: var(--bg); color: var(--text); font-family: inherit; outline: none; transition: border-color 0.15s, box-shadow 0.15s; }
.input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(29,158,117,0.15); }

/* ── Badges ── */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-green { background: var(--green-lt); color: var(--green-dk); }
.badge-amber { background: var(--amber-lt); color: var(--amber); }
.badge-red   { background: #FCEBEB; color: #A32D2D; }
.badge-gray  { background: var(--bg-3); color: var(--text-muted); }

/* ── Info box ── */
.info-box { background: var(--green-lt); border-radius: var(--radius); padding: 10px 14px; display: flex; gap: 10px; align-items: flex-start; font-size: 13px; color: var(--green-dk); }

/* ── Avatar ── */
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--green-lt); display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700; color: var(--green-dk); flex-shrink: 0; }

/* ── Tabs ── */
.tabs { display: flex; gap: 4px; padding: 10px 16px; background: var(--bg); border-bottom: 1px solid var(--border); overflow-x: auto; flex-shrink: 0; position: relative; z-index: 9; }
/* Tab panels must constrain height so overflow-y scroll works */
[id^="dt-"] { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.tabs::-webkit-scrollbar { display: none; }
.tab-btn { padding: 7px 16px; border-radius: 20px; font-size: 13px; font-weight: 500; cursor: pointer; border: none; background: transparent; color: var(--text-muted); font-family: inherit; white-space: nowrap; transition: all 0.15s; }
.tab-btn.active { background: var(--green-lt); color: var(--green-dk); }

/* ── Toggle ── */
.toggle-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.toggle-row:last-child { border-bottom: none; }
.toggle { position: relative; width: 42px; height: 24px; }
.toggle input { display: none; }
.toggle-track { width: 42px; height: 24px; border-radius: 12px; background: var(--bg-3); transition: background 0.2s; cursor: pointer; display: block; }
.toggle input:checked + .toggle-track { background: var(--green); }
.toggle-thumb { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left 0.2s; pointer-events: none; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.toggle input:checked ~ .toggle-thumb { left: 21px; }

/* ── QR box ── */
.qr-box { background: #fff; padding: 16px; border-radius: var(--radius-lg); display: inline-block; box-shadow: var(--shadow); }
.qr-box canvas, .qr-box img { display: block; }

/* ── WhatsApp owner chat ── */
#chat-screen { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 30; flex-direction: column; background: #e5ddd5; overflow: hidden; padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); -webkit-transform: translateZ(0); transform: translateZ(0); backface-visibility: hidden; }
#chat-screen.open { display: flex; }
/* On desktop: constrain to app width */




@media (prefers-color-scheme: dark) { #chat-screen { background: #0b141a; } }
.wa-hdr { background: #1D9E75; padding: 12px 14px; padding-top: max(12px,env(safe-area-inset-top)); display: flex; align-items: center; gap: 12px; color: #fff; flex-shrink: 0; }
.wa-back { background: none; border: none; color: #fff; font-size: 28px; cursor: pointer; padding: 0 4px; line-height: 1; }
.wa-av { width: 40px; height: 40px; border-radius: 50%; background: rgba(255,255,255,.22); display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; }
.wa-info { flex: 1; min-width: 0; }
.wa-info .wn { font-size: 16px; font-weight: 600; }
.wa-info .ws { font-size: 12px; opacity: .8; }
.wa-msgs { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; overscroll-behavior: contain; will-change: transform; }
.wb { display: inline-flex; flex-direction: column; max-width: 78%; padding: 7px 10px 5px; border-radius: 10px; box-shadow: 0 1px 1px rgba(0,0,0,.1); word-break: break-word; }
.wb.out { background: #dcf8c6; color: #111; border-top-right-radius: 2px; align-self: flex-end; }
.wb.in  { background: #fff; color: #111; border-top-left-radius: 2px; align-self: flex-start; }
@media (prefers-color-scheme: dark) { .wb.out { background: #005c4b; color: #e9edef; } .wb.in { background: #202c33; color: #e9edef; } }
.wt { font-size: 11px; color: #8c9194; text-align: right; margin-top: 3px; }
.img-strip { display: none; align-items: center; gap: 10px; padding: 8px 12px; background: #f0f2f5; border-top: 1px solid rgba(0,0,0,.08); flex-shrink: 0; }
.img-strip.on { display: flex; }
.img-strip img { height: 52px; border-radius: 6px; object-fit: cover; }
.wa-bar { display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px; padding-bottom: max(10px,env(safe-area-inset-bottom)); background: #f0f2f5; flex-shrink: 0; position: relative; z-index: 1; }
@media (prefers-color-scheme: dark) { .wa-bar, .img-strip { background: #1f2c34; } }
.wa-ta { flex: 1; padding: 9px 14px; border: none; border-radius: 22px; font-size: 15px; background: #fff; color: #111; font-family: inherit; outline: none; resize: none; max-height: 120px; line-height: 1.5; }
@media (prefers-color-scheme: dark) { .wa-ta { background: #2a3942; color: #e9edef; } }
.wa-send { width: 46px; height: 46px; border-radius: 50%; background: #1D9E75; color: #fff; border: none; cursor: pointer; font-size: 18px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.wa-att { width: 40px; height: 40px; background: transparent; border: none; cursor: pointer; font-size: 22px; display: flex; align-items: center; justify-content: center; color: #54656f; flex-shrink: 0; }
.wa-date-chip { text-align: center; margin: 8px 0; }
.wa-date-chip span { background: rgba(225,245,238,.9); color: #555; font-size: 12px; padding: 4px 12px; border-radius: 8px; }
.conv-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; cursor: pointer; border-bottom: 1px solid var(--border); background: var(--bg); }
.conv-row:active { background: var(--bg-2); }
.conv-av { width: 50px; height: 50px; border-radius: 50%; background: var(--green-lt); display: flex; align-items: center; justify-content: center; font-size: 22px; flex-shrink: 0; }
.unread-dot { min-width: 20px; height: 20px; background: #1D9E75; color: #fff; border-radius: 10px; font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; padding: 0 5px; }

/* ── Call/overlay screens ── */
#incoming { display: none; position: fixed; inset: 0; background: #075e54; z-index: 90; flex-direction: column; align-items: center; justify-content: center; gap: 22px; color: #fff; }
#incoming.show { display: flex; }
#lb { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.95); z-index: 100; flex-direction: column; align-items: center; justify-content: center; }
#lb.open { display: flex; }
.call-screen { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px; padding: 2rem; text-align: center; }
.call-avatar-wrap { position: relative; display: inline-block; }
.call-avatar { width: 96px; height: 96px; border-radius: 50%; background: var(--green-lt); display: flex; align-items: center; justify-content: center; font-size: 36px; }
.call-ring-1, .call-ring-2 { position: absolute; border-radius: 50%; border: 2px solid var(--green); opacity: 0; animation: ring-pulse 2s infinite; }
.call-ring-1 { inset: -12px; animation-delay: 0s; }
.call-ring-2 { inset: -24px; animation-delay: 0.5s; }
@keyframes ring-pulse { 0%{opacity:.5;transform:scale(.9)}100%{opacity:0;transform:scale(1.1)} }
.call-btn { width: 64px; height: 64px; border-radius: 50%; border: none; cursor: pointer; font-size: 24px; display: flex; align-items: center; justify-content: center; transition: transform 0.15s; }
.call-btn:active { transform: scale(0.92); }
.call-btn-end { background: var(--red); }
.call-btn-mute { background: var(--bg-3); }
.wave { display: flex; gap: 3px; align-items: center; height: 32px; }
.wave span { display: inline-block; width: 4px; border-radius: 2px; background: var(--green); animation: wave 1s ease-in-out infinite; }
@keyframes wave { 0%,100%{height:6px}50%{height:28px} }

/* ── Landing ── */
.hero { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2rem 1.25rem; text-align: center; gap: 1.5rem; }
.hero h1 { font-size: 30px; font-weight: 700; letter-spacing: -0.5px; line-height: 1.2; }
.hero p  { font-size: 16px; color: var(--text-muted); max-width: 360px; line-height: 1.6; }
.feature-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; width: 100%; max-width: 480px; }
.feature-card { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 0.75rem; text-align: center; }
.feature-icon { font-size: 22px; margin-bottom: 6px; }
.feature-title { font-size: 13px; font-weight: 600; margin-bottom: 3px; }
.feature-desc { font-size: 12px; color: var(--text-muted); line-height: 1.4; }

/* ── Install bar ── */
#install-bar { display: none; position: fixed; bottom: 0; left: 0; right: 0; background: #1D9E75; color: #fff; padding: 12px 16px; z-index: 200; align-items: center; gap: 12px; box-shadow: 0 -2px 12px rgba(0,0,0,0.2); }

/* ── Toast ── */
.notif { position: fixed; top: 16px; left: 50%; transform: translateX(-50%) translateY(-80px); background: var(--text); color: var(--bg); padding: 10px 20px; border-radius: 22px; font-size: 14px; font-weight: 500; z-index: 9999; transition: transform 0.35s cubic-bezier(0.34,1.56,0.64,1); white-space: nowrap; box-shadow: var(--shadow-md); }
.notif.show { transform: translateX(-50%) translateY(0); }

/* ── Misc ── */
.divider { height: 1px; background: var(--border); margin: 12px 0; }
.mono { font-family: 'SF Mono','Fira Code',monospace; font-size: 13px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 13px; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.flex { display: flex; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.p-body { padding: 1.25rem; }
.scroll-y { overflow-y: auto; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }
.dot-green { background: var(--green); }
.dot-amber { background: var(--amber); }
.dot-red   { background: var(--red); }
.img-upload-btn { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 20px; border: 1px dashed var(--border-md); background: transparent; cursor: pointer; font-size: 13px; color: var(--text-muted); font-family: inherit; }
#file-input { display: none; }
.pulse { animation: pulse 1.5s ease-in-out infinite; }
@keyframes pulse { 0%,100%{transform:scale(1)}50%{transform:scale(1.08)} }

/* ── Owner chat voice bubbles ── */
.ovbub{display:flex;align-items:center;gap:8px;padding:4px 2px;min-width:160px;max-width:220px}
.ovplay{width:36px;height:36px;border-radius:50%;border:none;cursor:pointer;display:flex;align-items:center;justify-content:center;flex-shrink:0;background:#1D9E75;color:#fff}
.wb.out .ovplay{background:rgba(0,0,0,.1);color:#111}
.ovwav{flex:1;display:flex;align-items:center;gap:2px;height:26px}
.ovb{width:3px;border-radius:2px;background:rgba(0,0,0,.2)}.ovb.op{background:#1D9E75}
.wb.in .ovb{background:rgba(29,158,117,.35)}.wb.in .ovb.op{background:#1D9E75}
.ovdur{font-size:11px;color:#8c9194;white-space:nowrap;min-width:28px}

/* ══ Desktop ≥ 860px ══ */
@media (min-width: 860px) {

  /* Nav + tabs full width */
  .nav, .tabs {
    padding-left: max(24px, calc(50% - 500px));
    padding-right: max(24px, calc(50% - 500px));
  }

  /* Screen full width */
  .screen.active {
    position: relative !important;
    top: auto !important; left: auto !important;
    right: auto !important; bottom: auto !important;
    width: 100% !important; height: 100vh !important;
    box-shadow: none !important; border: none !important;
    padding: 0 !important;
    transform: none !important; -webkit-transform: none !important;
  }

  /* QR */
  #dt-qr { overflow-y: auto; }
  #dt-qr > div { max-width: 1000px; margin: 0 auto; }

  /* Settings: centered narrow column */
  #dt-settings {
    padding-left: max(12px, calc(50% - 330px)) !important;
    padding-right: max(12px, calc(50% - 330px)) !important;
  }

  /* Messages: conv-list fixed left strip */
  #dt-messages {
    position: relative;
    overflow: hidden;
  }
  #conv-list {
    position: absolute !important;
    top: 0; left: 0; bottom: 0;
    width: 300px;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    background: var(--bg);
    z-index: 2;
  }
  #no-chat-hint {
    position: absolute !important;
    top: 0; left: 300px; right: 0; bottom: 0;
    display: flex;
    align-items: center; justify-content: center;
    flex-direction: column; gap: 12px;
    color: var(--text-muted); background: var(--bg-2); font-size: 14px;
  }

  /* Chat: absolute within screen, below nav+tabs via dynamic offset */
  #chat-screen {
    position: absolute !important;
    left: 300px !important;
    right: 0 !important;
    width: auto !important;
    top: var(--nav-height, 108px) !important;
    bottom: 0 !important;
    height: auto !important;
    z-index: 5;
  }
  /* Hide chat when not on messages tab */
  .screen.active:not(.on-messages) #chat-screen { display: none !important; }
  /* Input bar visible on desktop */
  .wa-bar { padding-bottom: 12px !important; }
}
