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

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

:root {
  /* Meta Business Suite Light Theme */
  --bg:        #f0f2f5;
  --s1:        #ffffff;
  --s2:        #f0f2f5;
  --s3:        #e4e6eb;
  --s4:        #1877f2;
  --border:    #ccd0d5;
  --border2:   #bec3c9;
  --text:      #050505;
  --text2:     #1c1e21;
  --text3:     #606770;
  --text4:     #8d949e;
  --font:      'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius:    8px;
  --radius-lg: 12px;
  --sidebar-w: 240px;
  --header-h:  60px;
  
  /* specific meta shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
}

html, body { height: 100%; font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }

/* ── SCROLLBAR ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #bcc0c4; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #8a8d91; }

/* ── LAYOUT ─────────────────────────────────────────────────────────────── */
.app { display: flex; height: 100vh; overflow: hidden; background: var(--bg); }

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--s1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  z-index: 10;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* ── SIDEBAR ─────────────────────────────────────────────────────────────── */
.sidebar-logo {
  padding: 24px 20px 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo .name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  display: flex; align-items: center; gap: 8px;
}
.sidebar-logo .name::before {
  content: '∞'; /* Placeholder logo icon */
  display: inline-block;
  background: var(--s4);
  color: white;
  width: 24px; height: 24px;
  border-radius: 6px;
  text-align: center;
  line-height: 24px;
  font-size: 14px;
}
.sidebar-logo .sub {
  font-size: 12px;
  color: var(--text3);
  margin-top: 4px;
  margin-left: 32px;
}

.nav { padding: 16px 12px; flex: 1; overflow-y: auto; }
.nav-section { margin-bottom: 24px; }
.nav-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text3);
  padding: 0 12px;
  margin-bottom: 8px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.2s;
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--s2); }
.nav-item.active { background: var(--s3); font-weight: 600; }
.nav-item .icon { width: 18px; height: 18px; color: var(--text3); flex-shrink: 0; }
.nav-item.active .icon { color: var(--s4); }
.badge {
  margin-left: auto;
  background: #fa3e3e; /* Meta Red */
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 12px;
  line-height: 1;
}

.sidebar-user {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--s1);
}
.user-avatar {
  width: 32px; height: 32px;
  background: var(--s4);
  color: white;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600;
  flex-shrink: 0;
}
.user-info { flex: 1; overflow: hidden; }
.user-info .name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-info .role { font-size: 11px; color: var(--text3); }
.logout-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text3); padding: 4px;
}
.logout-btn:hover { color: var(--text); }

/* ── HEADER ──────────────────────────────────────────────────────────────── */
.header {
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  background: var(--s1);
  box-shadow: var(--shadow-sm);
  z-index: 9;
}
.header-title { font-size: 18px; font-weight: 700; color: var(--text); }
.header-sub { font-size: 13px; color: var(--text3); margin-left: 8px; font-weight: 400; }
.header-right { margin-left: auto; display: flex; align-items: center; gap: 16px; }

/* ── STATS GRID ──────────────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--s1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.stat-label { font-size: 12px; font-weight: 600; color: var(--text3); margin-bottom: 8px; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--text); }
.stat-sub { font-size: 12px; color: var(--text3); margin-top: 6px; }

/* ── TABLE ───────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; background: var(--s1); border-radius: var(--radius-lg); border: 1px solid var(--border); box-shadow: var(--shadow-sm); }
table { width: 100%; border-collapse: collapse; }
thead tr { border-bottom: 1px solid var(--border); background: #f5f6f7; }
tbody tr { border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.1s; }
tbody tr:hover { background: var(--s2); }
th { font-size: 12px; font-weight: 600; color: var(--text3); padding: 12px 16px; text-align: left; }
td { padding: 14px 16px; font-size: 14px; color: var(--text); }
td.primary { font-weight: 600; }

/* ── BADGE / STATUS ──────────────────────────────────────────────────────── */
.status {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600;
  padding: 4px 10px; border-radius: 12px;
  color: var(--text); background: var(--s3);
}
.status.new      { background: #e7f3ff; color: var(--s4); }
.status.active   { background: #e4f2eb; color: #00a400; } /* WhatsApp Greenish */
.status.ordered  { background: #1877f2; color: white; }
.status.cold     { background: #f0f2f5; color: var(--text3); }
.status.paid     { background: #31a24c; color: white; } /* Meta Success */
.status.pending  { background: #f7b928; color: #fff; }

/* ── CHANNEL DOT ─────────────────────────────────────────────────────────── */
.ch { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; }
.ch.ig::before { content: '📷'; font-size: 12px; }
.ch.wa::before { content: '💬'; font-size: 12px; }

/* ── CARDS / SECTIONS ────────────────────────────────────────────────────── */
.card {
  background: var(--s1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: 24px;
}
.card-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  background: #fcfcfc;
}
.card-title { font-size: 16px; font-weight: 600; }
.card-body { padding: 24px; }

/* ── FILTERS ─────────────────────────────────────────────────────────────── */
.filters {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--s1);
  flex-wrap: wrap;
}
.filter-btn {
  padding: 6px 14px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 600;
  border: none;
  background: var(--s3);
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
}
.filter-btn:hover { background: #d8dadf; }
.filter-btn.active { background: #e7f3ff; color: var(--s4); }
.search-input {
  margin-left: auto;
  background: var(--s2);
  border: none;
  border-radius: 20px;
  padding: 8px 16px;
  color: var(--text);
  font-size: 14px;
  width: 240px;
  outline: none;
}
.search-input:focus { background: var(--s3); }
.search-input::placeholder { color: var(--text3); }

/* ── FORMS ───────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 20px; }
.form-label { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.form-input, .form-select, .form-textarea {
  width: 100%;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.2s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--s4); box-shadow: 0 0 0 2px #e7f3ff; }
.form-input::placeholder { color: var(--text3); }
.form-textarea { resize: vertical; min-height: 100px; }

/* ── BUTTONS ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 14px; font-weight: 600;
  cursor: pointer; border: none;
  transition: all 0.2s;
  font-family: var(--font);
}
.btn-primary { background: var(--s4); color: #fff; }
.btn-primary:hover { background: #166fe5; }
.btn-secondary { background: var(--s3); color: var(--text); }
.btn-secondary:hover { background: #d8dadf; }
.btn-ghost { background: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--s2); }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ── CONVERSATION VIEW (META BUSINESS SUITE CLONE) ───────────────────────── */
.convo-wrap {
  display: flex; height: calc(100vh - var(--header-h));
  overflow: hidden; background: var(--s1);
}
.convo-sidebar {
  width: 320px; min-width: 320px;
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  background: var(--s1);
}
.convo-sidebar-header {
  padding: 16px; border-bottom: 1px solid var(--border);
}
.convo-list {
  flex: 1; overflow-y: auto;
}
.convo-item {
  display: flex; gap: 12px; padding: 12px 16px;
  cursor: pointer; transition: background 0.2s;
  border-bottom: 1px solid #f0f2f5;
}
.convo-item:hover { background: var(--s2); }
.convo-item.active { background: #e7f3ff; position: relative; }
.convo-item.active::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--s4);
}
.convo-item-avatar {
  width: 48px; height: 48px; border-radius: 50%; background: var(--s3); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 16px;
}
.convo-item-content { flex: 1; overflow: hidden; }
.convo-item-head { display: flex; justify-content: space-between; margin-bottom: 4px; }
.convo-item-name { font-weight: 600; font-size: 14px; color: var(--text); }
.convo-item-time { font-size: 12px; color: var(--text3); }
.convo-item-snippet { font-size: 13px; color: var(--text3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convo-item.unread .convo-item-name { font-weight: 700; color: #000; }
.convo-item.unread .convo-item-snippet { font-weight: 600; color: var(--text); }

.convo-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: #f0f2f5; }
.convo-main-header {
  padding: 16px 24px; background: var(--s1); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; box-shadow: var(--shadow-sm); z-index: 2;
}

.msg-thread { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.msg-bubble {
  max-width: 65%;
  padding: 12px 16px;
  font-size: 14px;
  line-height: 1.5;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.msg-bubble.in { 
  background: var(--s1); 
  border-radius: 18px 18px 18px 4px; 
  align-self: flex-start; 
  color: var(--text);
}
.msg-bubble.out { 
  background: var(--s4); 
  color: #fff;
  border-radius: 18px 18px 4px 18px; 
  align-self: flex-end; 
}
.msg-bubble.gemini { 
  background: #e7f3ff;
  color: var(--text);
  border-radius: 18px 18px 4px 18px; 
  align-self: flex-end; 
}
.msg-meta { font-size: 11px; color: var(--text3); margin-top: 4px; padding: 0 8px; }

.msg-composer {
  padding: 16px 24px;
  background: var(--s1);
  display: flex; gap: 12px; align-items: flex-end;
  border-top: 1px solid var(--border);
}
.msg-composer textarea {
  flex: 1; background: var(--s2);
  border: none; border-radius: 20px;
  padding: 12px 16px; color: var(--text); font-size: 14px; outline: none; resize: none;
  min-height: 44px; max-height: 120px;
}

/* ── RIGHT PANEL (CONTACT DETAILS) ───────────────────────────────────────── */
.convo-info {
  width: 300px; min-width: 300px;
  border-left: 1px solid var(--border);
  background: var(--s1);
  overflow-y: auto;
  padding: 24px 20px;
}
.info-profile { text-align: center; margin-bottom: 24px; }
.info-profile .avatar { width: 80px; height: 80px; border-radius: 50%; background: var(--s2); margin: 0 auto 12px; display: flex; align-items: center; justify-content: center; font-size: 24px; }
.info-profile .name { font-size: 18px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.info-profile .status { margin-bottom: 12px; }

.info-section { margin-bottom: 24px; border-bottom: 1px solid var(--border); padding-bottom: 24px; }
.info-section h3 { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 12px; }
.crm-field { display: flex; justify-content: space-between; margin-bottom: 12px; align-items: center; }
.crm-key { font-size: 13px; color: var(--text3); }
.crm-val { font-size: 13px; font-weight: 500; color: var(--text); text-align: right; }
.crm-val.empty { color: var(--text4); font-style: italic; font-weight: 400; }

/* ── PIPELINE ─────────────────────────────────────────────────────────────── */
.pipeline { display: flex; gap: 4px; margin-bottom: 24px; }
.pipe-stage {
  flex: 1; padding: 12px 8px;
  background: var(--s1); border: 1px solid var(--border); border-radius: var(--radius);
  text-align: center; transition: all 0.2s;
}
.pipe-stage.active { background: #e7f3ff; border-color: var(--s4); }
.pipe-stage .count { font-size: 20px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.pipe-stage.active .count { color: var(--s4); }
.pipe-stage .label { font-size: 11px; font-weight: 600; color: var(--text3); text-transform: uppercase; }

/* ── UTILITIES ───────────────────────────────────────────────────────────── */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.w-full { width: 100%; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.text-muted { color: var(--text3); }
.font-bold { font-weight: 700; }
.hidden { display: none !important; }

/* ── EMPTY STATE ─────────────────────────────────────────────────────────── */
.empty { text-align: center; padding: 60px 20px; color: var(--text3); }
.empty-title { font-size: 18px; font-weight: 600; color: var(--text); margin-bottom: 8px; }

/* ── LOGIN PAGE ──────────────────────────────────────────────────────────── */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: #f0f2f5; }
.login-box { width: 400px; background: #fff; border-radius: 8px; padding: 40px; box-shadow: 0 2px 4px rgba(0,0,0,0.1), 0 8px 16px rgba(0,0,0,0.1); text-align: center; }
.login-logo { margin-bottom: 24px; }
.login-logo .name { font-size: 24px; font-weight: 800; color: var(--s4); }
.login-box h2 { font-size: 18px; font-weight: 600; margin-bottom: 24px; color: var(--text); }
