@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Plus+Jakarta+Sans:wght@500;600;700;800&display=swap');

:root {
  /* Dark Black + Yellow Premium Theme */
  --bg:        #0a0a0a;
  --surface:   #141414;
  --surface2:  #1c1c1c;
  --border:    #2a2a2a;
  --border2:   #333333;

  --text:      #ffffff;
  --text2:     #a0a0a0;
  --text3:     #606060;

  --accent:    #f5c518;
  --accent-h:  #e0b000;
  --accent-bg: #1f1a00;
  --accent-border: #3d3300;

  --green:     #22c55e;
  --green-bg:  #0a1f12;
  --red:       #ef4444;
  --red-bg:    #1f0a0a;
  --orange:    #f59e0b;
  --orange-bg: #1f1400;
  --blue:      #3b82f6;
  --blue-bg:   #0a1020;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
  --shadow:    0 4px 12px rgba(0,0,0,.5), 0 2px 4px rgba(0,0,0,.3);
  --shadow-lg: 0 12px 32px rgba(0,0,0,.6), 0 4px 8px rgba(0,0,0,.4);

  --radius:    16px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin:0; padding:0; box-sizing:border-box; -webkit-tap-highlight-color:transparent; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow: hidden;
}

/* ─── App Shell ──────────────────────────────────────────────────── */
#app { display:flex; flex-direction:column; height:100vh; height:100dvh; }

/* ─── Top Bar ────────────────────────────────────────────────────── */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .875rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.top-bar-title {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--accent);
  letter-spacing: -.02em;
}

.top-bar-title span {
  color: var(--accent);
}

.top-bar-status {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .72rem;
  font-weight: 500;
  color: var(--text2);
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: .3rem .7rem;
  border-radius: 20px;
}

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--red);
  flex-shrink: 0;
}
.status-dot.online    { background: var(--green); }
.status-dot.connecting { background: var(--orange); animation: pulse 1s infinite; }

@keyframes pulse { 50% { opacity:.4; } }

/* ─── Pages ──────────────────────────────────────────────────────── */
.pages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
}

.page {
  display: none;
  padding: 1.25rem;
  padding-bottom: calc(5.5rem + var(--safe-bottom));
  min-height: 100%;
}
.page.active { display: block; }

.page-title {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 1.1rem;
}

/* ─── Loading ────────────────────────────────────────────────────── */
#global-loading {
  position: fixed; inset: 0;
  background: rgba(10,10,10,.8);
  backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center;
  z-index: 1500;
}
#global-loading.show { display: flex; }

.loading-spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#pull-indicator {
  position: absolute; top:0; left:0; right:0;
  height: 0; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  color: var(--text2); font-size: .75rem;
  transition: height .18s ease; z-index: 12;
  background: linear-gradient(180deg, var(--surface), transparent);
  pointer-events: none;
}
#pull-indicator.show  { height: 40px; }
#pull-indicator.ready { color: var(--accent); font-weight: 600; }

/* ─── Badge HOT / WARM / COLD ────────────────────────────────────── */
.badge-hot  { background: #ef4444; color: #fff; border-radius: 4px; padding: .15rem .5rem; font-size: .65rem; font-weight: 700; }
.badge-warm { background: #f59e0b; color: #000; border-radius: 4px; padding: .15rem .5rem; font-size: .65rem; font-weight: 700; }
.badge-cold { background: #3b82f6; color: #fff; border-radius: 4px; padding: .15rem .5rem; font-size: .65rem; font-weight: 700; }

/* ─── Bottom Nav ─────────────────────────────────────────────────── */
.bottom-nav {
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  padding-bottom: var(--safe-bottom);
  box-shadow: 0 -2px 12px rgba(0,0,0,.06);
}

.nav-btn {
  flex: 1;
  display: flex; flex-direction: column; align-items: center;
  padding: .65rem 0;
  cursor: pointer;
  color: var(--text3);
  font-size: .62rem;
  font-weight: 600;
  transition: .2s;
  position: relative;
  letter-spacing: .01em;
}
.nav-btn .nav-icon { font-size: 1.25rem; margin-bottom: .2rem; }
.nav-btn.active { color: var(--accent); }
.nav-btn.active .nav-icon { filter: drop-shadow(0 0 8px rgba(245,197,24,.5)); }

.nav-badge {
  position: absolute; top: 4px; right: calc(50% - 18px);
  background: var(--red); color: #fff;
  font-size: .55rem; padding: 1px 5px;
  border-radius: 10px; font-weight: 700;
}

/* ─── Stats Grid ─────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .75rem;
  margin-bottom: 1.1rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  display: flex; align-items: center; gap: .85rem;
  box-shadow: var(--shadow-sm);
}
.stat-icon { font-size: 1.4rem; }
.stat-value { font-size: 1.5rem; font-weight: 700; display: block; color: var(--text); }
.stat-label { font-size: .68rem; color: var(--text2); font-weight: 500; margin-top: 1px; }

/* ─── Cards ──────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin-bottom: .65rem;
  cursor: pointer;
  transition: box-shadow .15s, transform .15s;
  box-shadow: var(--shadow-sm);
}
.card:active { transform: scale(.99); box-shadow: none; }
.card:hover  { box-shadow: var(--shadow); }

.card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: .45rem;
}
.card-title    { font-weight: 600; font-size: .9rem; color: var(--text); }
.card-subtitle { font-size: .72rem; color: var(--text2); }
.card-body     { font-size: .82rem; color: var(--text2); line-height: 1.5; }
.card-footer {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: .5rem; padding-top: .5rem;
  border-top: 1px solid var(--border);
  font-size: .72rem; color: var(--text3);
}

/* ─── Section Title ──────────────────────────────────────────────── */
.section-title {
  font-size: .7rem; font-weight: 700;
  color: var(--text3);
  margin: 1.25rem 0 .6rem;
  text-transform: uppercase; letter-spacing: .06em;
}

/* ─── Badges ─────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .2rem .55rem;
  border-radius: var(--radius-xs);
  font-size: .68rem; font-weight: 600;
}
.badge-new       { background: var(--accent-bg); color: var(--accent); border: 1px solid var(--accent-border); }
.badge-contacted { background: var(--blue-bg);   color: var(--blue);   border: 1px solid #bfdbfe; }
.badge-converted { background: var(--green-bg);  color: var(--green);  border: 1px solid #a7f3d0; }
.badge-critical  { background: var(--red-bg);    color: var(--red);    border: 1px solid #fecaca; }
.badge-high      { background: var(--orange-bg); color: var(--orange); border: 1px solid #fde68a; }
.badge-medium    { background: var(--blue-bg);   color: var(--blue);   border: 1px solid #bfdbfe; }
.badge-low       { background: var(--green-bg);  color: var(--green);  border: 1px solid #a7f3d0; }

/* ─── Buttons ────────────────────────────────────────────────────── */
.btn {
  padding: .6rem 1.1rem;
  border: none; border-radius: var(--radius-sm);
  font-size: .83rem; font-weight: 600;
  cursor: pointer; transition: .15s;
  display: inline-flex; align-items: center; gap: .4rem;
  font-family: inherit;
}
.btn-accent  { background: var(--accent); color: #000; font-weight: 700; box-shadow: 0 2px 12px rgba(245,197,24,.3); }
.btn-accent:hover { background: var(--accent-h); }
.btn-outline { background: var(--surface); border: 1px solid var(--border2); color: var(--text); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }
.btn-danger  { background: var(--red); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-sm      { padding: .35rem .75rem; font-size: .75rem; border-radius: var(--radius-xs); }
.btn-block   { width: 100%; justify-content: center; }
.btn-lg      { padding: .8rem 1.5rem; font-size: .95rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ─── Forms ──────────────────────────────────────────────────────── */
.input {
  width: 100%;
  padding: .65rem .9rem;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: .875rem;
  outline: none;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(245,197,24,.12);
}
.input::placeholder { color: var(--text3); }

select.input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23606060' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-color: var(--surface);
  padding-right: 28px;
  color-scheme: dark;
}
textarea.input { resize: vertical; min-height: 64px; }

.form-group { margin-bottom: .8rem; }
.form-group label {
  display: block; font-size: .73rem; font-weight: 600;
  color: var(--text2); margin-bottom: .3rem; letter-spacing: .01em;
}

/* ─── Toggle ─────────────────────────────────────────────────────── */
.toggle { position:relative; width:42px; height:22px; display:inline-block; flex-shrink:0; }
.toggle input { display:none; }
.toggle-slider {
  position:absolute; inset:0;
  background: var(--border2); border-radius:11px;
  cursor:pointer; transition:.2s;
}
.toggle-slider::before {
  content:''; position:absolute;
  width:16px; height:16px; background:#fff;
  border-radius:50%; top:3px; left:3px;
  transition:.2s; box-shadow: var(--shadow-sm);
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ─── Setting Row ────────────────────────────────────────────────── */
.setting-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: .8rem 0; border-bottom: 1px solid var(--border);
}
.setting-row label { font-size: .85rem; flex:1; color: var(--text); }

/* ─── Inbox / Chat List ──────────────────────────────────────────── */
.chat-item {
  display: flex; align-items: center; gap: .85rem;
  padding: .85rem 0; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: .15s;
}
.chat-item:active { opacity: .7; }

.chat-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: linear-gradient(135deg, #f5c518, #e07b00);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .95rem; flex-shrink: 0; color: #000;
  box-shadow: 0 2px 8px rgba(245,197,24,.2);
}

.chat-info { flex:1; min-width:0; }
.chat-name {
  font-weight: 600; font-size: .88rem; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-preview {
  font-size: .73rem; color: var(--text2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px;
}
.chat-meta { text-align: right; flex-shrink: 0; }
.chat-time { font-size: .63rem; color: var(--text3); }

/* ─── Chat View ──────────────────────────────────────────────────── */
#page-chat {
  padding: 0 !important; display: none;
  flex-direction: column; height: 100%;
}
#page-chat.active { display: flex !important; }

.chat-top {
  display: flex; align-items: center; gap: .75rem;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.chat-back {
  cursor: pointer; font-size: 1.2rem; padding: .3rem .5rem;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-xs); color: var(--text);
}
.chat-top-name { font-weight: 600; font-size: .9rem; color: var(--text); }
.chat-top-sub  { font-size: .68rem; color: var(--text2); }

.chat-messages {
  flex: 1; overflow-y: auto; padding: 1rem;
  display: flex; flex-direction: column; gap: .5rem;
  background: var(--bg);
}

.msg-bubble {
  max-width: 80%; padding: .6rem .9rem;
  border-radius: 14px; font-size: .83rem; line-height: 1.45;
  word-wrap: break-word;
}
.msg-bubble.customer {
  background: var(--surface); border: 1px solid var(--border);
  align-self: flex-start; border-bottom-left-radius: 4px;
  color: var(--text); box-shadow: var(--shadow-sm);
}
.msg-bubble.ai {
  background: var(--accent); color: #000;
  align-self: flex-end; border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(245,197,24,.25);
}
.msg-bubble.agent {
  background: var(--green); color: #fff;
  align-self: flex-end; border-bottom-right-radius: 4px;
}
.msg-time  { font-size: .58rem; opacity: .55; margin-top: .2rem; display: block; }
.msg-tag   { font-size: .55rem; opacity: .5; text-transform: uppercase; }

.chat-input-bar {
  display: flex; gap: .5rem;
  padding: .75rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding-bottom: calc(.75rem + var(--safe-bottom));
  box-shadow: 0 -2px 8px rgba(0,0,0,.04);
}
.chat-input-bar input { flex: 1; }

/* ─── Filter Bar ─────────────────────────────────────────────────── */
.filter-bar { display: flex; gap: .5rem; margin-bottom: 1rem; }
.filter-bar .input { font-size: .8rem; padding: .5rem .75rem; }

/* ─── Keyword Tag ────────────────────────────────────────────────── */
.kw-tag {
  display: inline-flex; align-items: center; gap: .3rem;
  background: var(--surface2); border: 1px solid var(--border);
  padding: .25rem .6rem; border-radius: var(--radius-xs);
  font-size: .73rem; margin: .2rem;
}
.kw-tag .kw-del { cursor: pointer; color: var(--red); font-weight: 700; margin-left: .2rem; }

/* ─── Group Item ─────────────────────────────────────────────────── */
.group-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: .65rem 0; border-bottom: 1px solid var(--border); font-size: .84rem;
}

/* ─── Empty State ────────────────────────────────────────────────── */
.empty { text-align: center; padding: 3rem 1rem; color: var(--text2); }
.empty-icon { font-size: 2.5rem; margin-bottom: .75rem; opacity: .5; }
.empty-text { font-size: .88rem; }

/* ─── Toast ──────────────────────────────────────────────────────── */
#toast {
  position: fixed; top: 1rem; left: 50%;
  transform: translateX(-50%) translateY(-120%);
  background: var(--text); color: #fff;
  padding: .7rem 1.4rem; border-radius: 10px;
  font-size: .82rem; font-weight: 500;
  z-index: 2000; opacity: 0; transition: .25s;
  box-shadow: var(--shadow-lg); pointer-events: none;
  white-space: nowrap;
}
#toast.show    { transform: translateX(-50%) translateY(0); opacity: 1; }
#toast.success { background: var(--green); }
#toast.error   { background: var(--red); }
#toast.accent  { background: var(--accent); }

/* ─── Modal ──────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(6px);
  z-index: 200; display: none;
  align-items: flex-end; justify-content: center;
}
.modal-overlay.show { display: flex; }

.modal {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  width: 100%; max-width: 520px;
  max-height: 88vh; overflow-y: auto;
  padding: 1.5rem;
  animation: slideUp .28s cubic-bezier(.22,1,.36,1);
  box-shadow: var(--shadow-lg);
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1.1rem;
}
.modal-header h3 { font-size: 1.05rem; font-weight: 700; color: var(--text); }
.modal-close {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text2); font-size: 1.1rem; cursor: pointer;
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}

/* ─── Paywall ────────────────────────────────────────────────────── */
.paywall { text-align: center; padding: 1.5rem .5rem; }
.paywall h2 { font-size: 1.3rem; font-weight: 700; margin-bottom: .4rem; }
.paywall-price {
  font-size: 2.4rem; font-weight: 800; color: var(--accent); margin: 1rem 0;
}
.paywall-price small { font-size: .85rem; color: var(--text2); font-weight: 400; }
.paywall-features { text-align: left; margin: 1.25rem auto; max-width: 260px; }
.paywall-features li {
  padding: .35rem 0; font-size: .83rem; list-style: none; color: var(--text2);
}
.paywall-features li::before { content: '✓ '; color: var(--green); font-weight: 700; }

/* ─── Scrollbar ──────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

/* ─── Utilities ──────────────────────────────────────────────────── */
.flex         { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-sm       { gap: .5rem; }
.mt-1         { margin-top: 1rem; }
.mb-1         { margin-bottom: 1rem; }
.mb-05        { margin-bottom: .5rem; }
.text-center  { text-align: center; }
.text-sm      { font-size: .78rem; }
.text-muted   { color: var(--text2); }
