/* ============================================================
   WABIZ v2.0 — Enterprise Design System ("WhatsApp Comfort")
   Linear / Vercel Precision + WhatsApp Web Pro Messaging UI
   ============================================================ */

@import url('/static/css/wabiz-theme.css');

:root {
  /* Core Surfaces (Light Mode - Clean Slate & Subtle Warm Chat) */
  --bg-root: #f4f5f7;
  --bg-main: #efeae2;
  --bg-white: #ffffff;
  --bg-surface: #ffffff;
  --bg-elevated: #f8fafc;
  --bg-hover: #f1f5f9;
  --bg-active: rgba(0, 128, 105, 0.08);
  --bg-sidebar: #ffffff;
  --bg-nav-hover: #f1f5f9;
  --bg-nav-active: rgba(0, 128, 105, 0.12);
  --bg-input: #ffffff;
  --bg-card: #ffffff;
  --bg-overlay: rgba(15, 23, 42, 0.55);

  /* Typography Colors */
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-inverse: #ffffff;

  /* Brand & Accents */
  --accent: #008069;
  --accent-teal: #008069;
  --accent-hover: #006854;
  --accent-subtle: rgba(0, 128, 105, 0.1);
  --accent-blue: #3b82f6;

  /* Borders & Dividers */
  --border: #e2e8f0;
  --border-color: #e2e8f0;
  --border-subtle: rgba(15, 23, 42, 0.06);

  /* Semantic Status */
  --status-success: #10b981;
  --status-warning: #f59e0b;
  --status-error: #ef4444;
  --status-info: #3b82f6;

  /* Layout & Chrome */
  --header-bg: #f8fafc;
  --scrollbar: #cbd5e1;
  --scrollbar-color: #cbd5e1;

  /* WhatsApp Pro Messaging Tokens */
  --wa-bubble-received: #ffffff;
  --wa-bubble-sent: #d9fdd3;
  --wa-bubble-received-text: #111b21;
  --wa-bubble-sent-text: #111b21;
  --wa-time-received: #667781;
  --wa-time-sent: #54656f;
  --wa-double-check: #53bdeb;

  /* Spacing & Radii */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-12: 48px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-2xl: 24px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 12px -2px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 24px -4px rgba(15, 23, 42, 0.12);
}

[data-theme="dark"] {
  color-scheme: dark;

  --bg-root: #0b141a;
  --bg-main: #0b141a;
  --bg-white: #111b21;
  --bg-surface: #111b21;
  --bg-elevated: #1e2a31;
  --bg-hover: #202c33;
  --bg-active: #2a3942;
  --bg-sidebar: #111b21;
  --bg-nav-hover: #202c33;
  --bg-nav-active: rgba(0, 168, 132, 0.18);
  --bg-input: #202c33;
  --bg-card: #182229;
  --bg-overlay: rgba(0, 0, 0, 0.75);

  --text-primary: #e9edef;
  --text-secondary: #8696a0;
  --text-muted: #64748b;
  --text-inverse: #111b21;

  --accent: #00a884;
  --accent-teal: #00a884;
  --accent-hover: #00c49a;
  --accent-subtle: rgba(0, 168, 132, 0.15);

  --border: #222d34;
  --border-color: #222d34;
  --border-subtle: rgba(255, 255, 255, 0.06);

  --header-bg: #202c33;
  --scrollbar: #374248;
  --scrollbar-color: #374248;

  --wa-bubble-received: #202c33;
  --wa-bubble-sent: #005c4b;
  --wa-bubble-received-text: #e9edef;
  --wa-bubble-sent-text: #e9edef;
  --wa-time-received: #8696a0;
  --wa-time-sent: #99beb7;
  --wa-double-check: #53bdeb;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 28px rgba(0, 0, 0, 0.5);
}

/* ---- Reset & Base Typography ---- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  height: 100dvh;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-root);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
}

.tabular-nums {
  font-variant-numeric: tabular-nums;
}

/* ---- Focus Visibility ---- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
:focus:not(:focus-visible) {
  outline: none;
}

/* ---- Unified Scrollbars ---- */
.custom-scroll, .chat-scroll {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar) transparent;
}
.custom-scroll::-webkit-scrollbar, .chat-scroll::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
.custom-scroll::-webkit-scrollbar-track, .chat-scroll::-webkit-scrollbar-track {
  background: transparent;
}
.custom-scroll::-webkit-scrollbar-thumb, .chat-scroll::-webkit-scrollbar-thumb {
  background-color: var(--scrollbar);
  border-radius: 9999px;
}

/* ---- Single Vector Wallpaper Definition (No Duplication) ---- */
.wa-chat-bg, #crmChatWindow {
  background-color: var(--bg-main) !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='360' height='360' viewBox='0 0 360 360' fill='none' stroke='%23667781' stroke-width='1.3' stroke-linecap='round' stroke-linejoin='round' opacity='0.045'%3E%3Cpath d='M25 45h22v16a8 8 0 0 1-8 8h-6a8 8 0 0 1-8-8V45z M47 48h5a4 4 0 0 1 4 4v2a4 4 0 0 1-4 4h-5 M20 72h32'/%3E%3Cpath d='M115 35h24a8 8 0 0 1 8 8v12a8 8 0 0 1-8 8h-14l-8 7v-7h-2a8 8 0 0 1-8-8V43a8 8 0 0 1 8-8z'/%3E%3Ccircle cx='230' cy='52' r='14'/%3E%3Cpath d='M225 56a6 6 0 0 0 10 0'/%3E%3Cpath d='M310 42c-4-6-12-3-12 3 0 7 12 14 12 14s12-7 12-14c0-6-8-9-12-3z'/%3E%3Cpath d='M75 102l3 7h7l-5.5 4.5 2 7-6.5-4.5-6.5 4.5 2-7-5.5-4.5h7z'/%3E%3Cpath d='M260 130l26-14-10 24-5-8-11-2z'/%3E%3Ccircle cx='135' cy='195' r='13'/%3E%3Cpath d='M135 187v8l5 4'/%3E%3Cpath d='M255 268l4 4 9-10 M262 268l4 4 9-10'/%3E%3C/svg%3E") !important;
  background-repeat: repeat !important;
  background-size: 360px 360px !important;
}

/* ---- WhatsApp Web Pro Chat Bubbles ---- */
.wa-bubble-received, .wa-bubble-sent {
  position: relative;
  border-radius: 10px;
  box-shadow: 0 1px 1.5px rgba(11, 20, 26, 0.12);
  max-width: 72%;
  word-break: break-word;
  transition: outline 0.2s ease, background-color 0.2s ease;
}

.wa-bubble-received {
  background-color: var(--wa-bubble-received);
  color: var(--wa-bubble-received-text);
}
.wa-bubble-received.has-tail {
  border-top-left-radius: 0;
}
.wa-bubble-received.has-tail::before {
  content: '';
  position: absolute;
  top: 0;
  left: -8px;
  width: 8px;
  height: 13px;
  background: var(--wa-bubble-received);
  clip-path: polygon(100% 0, 0 0, 100% 100%);
}

.wa-bubble-sent {
  background-color: var(--wa-bubble-sent);
  color: var(--wa-bubble-sent-text);
}
.wa-bubble-sent.has-tail {
  border-top-right-radius: 0;
}
.wa-bubble-sent.has-tail::before {
  content: '';
  position: absolute;
  top: 0;
  right: -8px;
  width: 8px;
  height: 13px;
  background: var(--wa-bubble-sent);
  clip-path: polygon(0 0, 100% 0, 0 100%);
}

/* Float-based metadata footer inside bubbles (prevents awkward blank gaps) */
.wa-bubble-meta {
  float: right;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 10px;
  margin-top: 4px;
  margin-bottom: -2px;
  line-height: 1;
  user-select: none;
}

.wa-message-text a {
  color: #0284c7;
  text-decoration: underline;
  text-underline-offset: 2px;
}
[data-theme="dark"] .wa-message-text a {
  color: #38bdf8;
}

/* ---- Skeleton Shimmer Loading States ---- */
@keyframes sfShimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.sf-skeleton {
  background: linear-gradient(90deg, var(--bg-hover) 25%, var(--border) 50%, var(--bg-hover) 75%);
  background-size: 200% 100%;
  animation: sfShimmer 1.5s infinite linear;
  border-radius: var(--radius-md);
}

/* ---- Voice Note Sound Wave ---- */
.voice-wave-bar {
  width: 3px;
  height: 6px;
  background-color: #10b981;
  border-radius: 3px;
  animation: soundWave 1.1s ease-in-out infinite;
}
@keyframes soundWave {
  0%, 100% { height: 4px; }
  50% { height: 22px; }
}

/* ---- In-Chat Search Marks ---- */
mark.chat-search-mark {
  background-color: rgba(234, 179, 8, 0.45);
  color: inherit;
  border-radius: 3px;
  padding: 0 2px;
  font-weight: 600;
}
mark.chat-search-mark.active-match {
  background-color: #10b981;
  color: #ffffff;
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.6);
}
.search-focused-bubble {
  outline: 2.5px solid #10b981 !important;
  outline-offset: 3px;
}

/* ---- Navigation Sidebar & Instant Tooltips ---- */
.nav-item {
  position: relative;
  transition: background-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
  color: var(--text-secondary);
}
.nav-item:hover {
  background-color: var(--bg-hover) !important;
  color: var(--accent-teal);
}
.nav-item.active {
  background-color: var(--bg-nav-active);
  color: var(--accent-teal);
}
.nav-item::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  background-color: #0f172a;
  color: #f8fafc;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 6px;
  box-shadow: var(--shadow-md);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  z-index: 1000;
}
.nav-item:hover::after {
  opacity: 1;
}

/* ---- Shared Cards, Buttons, Inputs & Badges ---- */
.sf-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
}

.sf-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background-color 0.15s ease, opacity 0.15s ease, transform 0.1s ease;
}
.sf-btn:active { transform: scale(0.98); }
.sf-btn-primary { background-color: var(--accent); color: #fff; }
.sf-btn-primary:hover:not(:disabled) { background-color: var(--accent-hover); }
.sf-btn-secondary { background-color: transparent; color: var(--text-primary); border: 1px solid var(--border); }
.sf-btn-secondary:hover:not(:disabled) { background-color: var(--bg-hover); }
.sf-btn-danger { background-color: rgba(239, 68, 68, 0.1); color: #ef4444; border: 1px solid rgba(239, 68, 68, 0.3); }

.sf-input {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background-color: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.875rem;
}
.sf-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
  outline: none;
}

.sf-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
}
.sf-badge-success { background-color: rgba(16, 185, 129, 0.15); color: #10b981; }
.sf-badge-warning { background-color: rgba(245, 158, 11, 0.15); color: #f59e0b; }
.sf-badge-error   { background-color: rgba(239, 68, 68, 0.15); color: #ef4444; }
.sf-badge-info    { background-color: rgba(59, 130, 246, 0.15); color: #3b82f6; }

.sf-toast {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  z-index: 150;
  box-shadow: var(--shadow-lg);
}

.no-scrollbar::-webkit-scrollbar { display: none !important; }
.no-scrollbar { -ms-overflow-style: none !important; scrollbar-width: none !important; }

/* ---- Lead Card Responsive Drawer (<1280px overlays smoothly instead of crushing chat) ---- */
@media (max-width: 1279px) {
  #leadCardPanel {
    position: fixed !important;
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: min(360px, 92vw) !important;
    z-index: 80 !important;
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.35) !important;
  }
}

/* ---- Mobile Navigation & Virtual Keyboard Resilience ---- */
@media (max-width: 768px) {
  #crm-content {
    flex-direction: column !important;
    height: var(--app-height, 100dvh) !important;
    overflow: hidden !important;
    padding-bottom: 58px !important;
  }
  #crm-content.chat-open-mobile {
    padding-bottom: 0 !important;
  }
  #crmNavbar {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    height: 58px !important;
    flex-direction: row !important;
    border-right: none !important;
    border-top: 1px solid var(--border) !important;
    padding: 0 4px !important;
    padding-bottom: env(safe-area-inset-bottom, 0px) !important;
    background-color: var(--bg-surface) !important;
    z-index: 70 !important;
  }
  #crmNavbar > .h-16 { display: none !important; }
  #crmNavbar > .flex-1 {
    flex-direction: row !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    padding: 0 4px !important;
    gap: 4px !important;
    justify-content: flex-start !important;
  }
  #crmNavbar > .mt-auto {
    flex-direction: row !important;
    border-top: none !important;
    border-left: 1px solid var(--border) !important;
    padding: 0 6px !important;
    margin-top: 0 !important;
  }
  #crmNavbar .nav-item::after { display: none !important; }
  .wa-bubble-sent, .wa-bubble-received { max-width: 86% !important; }
}
