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

:root {
  --bg-app: #F8FAFC;
  --bg-sidebar: #FFFFFF;
  --bg-card: #FFFFFF;
  --border-color: #E2E8F0;
  --border-hover: #CBD5E1;
  --text-main: #0F172A;
  --text-muted: #64748B;
  --text-light: #94A3B8;
  
  --indigo-primary: #4F46E5;
  --indigo-hover: #4338CA;
  --indigo-light: #EEF2FF;
  --indigo-border: #C7D2FE;
  
  --green-primary: #10B981;
  --green-hover: #059669;
  --green-light: #ECFDF5;
  --green-border: #A7F3D0;
  
  --wa-teal: #075E54;
  --wa-green: #128C7E;
  --wa-bubble: #E7FFDB;
  --wa-bg: #EFEAE2;
  
  --sidebar-width: 320px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-card: 0 4px 6px -1px rgba(0, 0, 0, 0.04), 0 2px 4px -1px rgba(0, 0, 0, 0.02);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.06), 0 8px 10px -6px rgba(0, 0, 0, 0.03);
  --font-main: 'Inter', system-ui, -apple-system, sans-serif;
  --font-heading: 'Outfit', 'Inter', sans-serif;
  --font-code: 'Fira Code', monospace;
}

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

body {
  background-color: var(--bg-app);
  color: var(--text-main);
  font-family: var(--font-main);
  line-height: 1.5;
  min-height: 100vh;
}

/* App Layout */
.app-wrapper {
  display: flex;
  width: 100%;
  min-height: 100vh;
}

/* Left Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 1.75rem 1.25rem;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 50;
  overflow-y: auto;
}

.sidebar-logo-container {
  width: 100%;
  display: flex;
  justify-content: center;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 1.25rem;
}

.sidebar-logo {
  width: 100%;
  max-width: 270px;
  height: auto;
  object-fit: contain;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1.5rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.9rem;
  border-radius: var(--radius-md);
  transition: all 0.2s ease;
}

.nav-item:hover {
  background: var(--indigo-light);
  color: var(--indigo-primary);
}

.nav-item.active {
  background: var(--indigo-primary);
  color: #FFFFFF;
  font-weight: 600;
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* Token Controls Box in Left Sidebar */
.sidebar-token-box {
  background: var(--bg-app);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-bottom: 1.5rem;
}

.sidebar-token-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.sidebar-token-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  margin-bottom: 0.5rem;
}

.sidebar-token-hint {
  font-size: 0.725rem;
  color: var(--text-muted);
  line-height: 1.3;
}

/* Sidebar Footer */
.sidebar-footer {
  margin-top: auto;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border-color);
  font-size: 0.78rem;
  color: var(--text-muted);
}

.company-name {
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.2rem;
}

.company-cin {
  font-size: 0.725rem;
  color: var(--text-light);
  margin-bottom: 0.5rem;
}

.support-emails {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.support-emails a {
  color: var(--indigo-primary);
  text-decoration: none;
}

/* Main Workspace Grid */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 2rem 2.5rem;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.page-title {
  font-family: var(--font-heading);
  font-size: 1.6rem;
  font-weight: 700;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--green-light);
  color: var(--green-hover);
  border: 1px solid var(--green-border);
  padding: 0.35rem 0.8rem;
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.status-dot {
  width: 7px;
  height: 7px;
  background: var(--green-primary);
  border-radius: 50%;
}

.messaging-workspace {
  display: grid;
  grid-template-columns: 1fr 420px;
  gap: 2rem;
  align-items: start;
}

/* Form Cards */
.composer-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  box-shadow: var(--shadow-card);
  margin-bottom: 1.5rem;
}

.card-title {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.phone-split-container {
  display: flex;
  gap: 0.6rem;
}

.country-select {
  width: 130px;
  flex-shrink: 0;
  font-weight: 600;
}

.phone-input {
  flex: 1;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-group.full-width {
  grid-column: 1 / -1;
}

label {
  font-size: 0.825rem;
  font-weight: 600;
  color: var(--text-main);
}

input, select, textarea {
  background: var(--bg-app);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.9rem;
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s ease;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--indigo-primary);
  background: #FFFFFF;
}

/* Tabs */
.flow-tabs {
  display: flex;
  gap: 0.5rem;
  background: var(--bg-app);
  padding: 0.35rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  margin-bottom: 1.5rem;
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.7rem 0.75rem;
  font-family: var(--font-main);
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn.active {
  background: var(--bg-card);
  color: var(--indigo-primary);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* Send Button */
.btn-send {
  background: var(--green-primary);
  color: #FFFFFF;
  border: none;
  padding: 0.9rem 1.75rem;
  border-radius: var(--radius-md);
  font-family: var(--font-main);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  transition: background-color 0.2s ease, transform 0.15s ease;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.2);
}

.btn-send:hover {
  background: var(--green-hover);
  transform: translateY(-1px);
}

/* Meta API Webhook & Event Logs Container */
.logs-container-card {
  margin-top: 1.5rem;
  background: #0F172A;
  border: 1px solid #1E293B;
  border-radius: var(--radius-md);
  overflow: hidden;
}

.logs-header {
  background: #1E293B;
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logs-title {
  font-family: var(--font-code);
  font-size: 0.78rem;
  color: #38BDF8;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logs-pulse {
  width: 6px;
  height: 6px;
  background: #10B981;
  border-radius: 50%;
  box-shadow: 0 0 8px #10B981;
}

.btn-clear-logs {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #94A3B8;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.725rem;
  cursor: pointer;
}

.btn-clear-logs:hover {
  background: rgba(255, 255, 255, 0.18);
  color: #FFFFFF;
}

.logs-body {
  padding: 1rem;
  max-height: 240px;
  overflow-y: auto;
  font-family: var(--font-code);
  font-size: 0.78rem;
  color: #E2E8F0;
  line-height: 1.45;
}

.log-entry-item {
  padding: 0.4rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.log-entry-item:last-child {
  border-bottom: none;
}

.log-time {
  color: #64748B;
  font-size: 0.725rem;
}

.log-type-tag {
  color: #F59E0B;
  font-weight: 600;
}

/* Right Column: Clean Messages Display Pane */
.phone-pane-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 650px;
  position: sticky;
  top: 2rem;
}

/* Header with Title 'Messages' & Clear Button */
.phone-header {
  background: var(--wa-teal);
  color: #FFFFFF;
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.phone-header-title {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 700;
  color: #FFFFFF;
  letter-spacing: -0.01em;
}

.btn-clear-messages {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #FFFFFF;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.3rem 0.75rem;
  border-radius: 9999px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-clear-messages:hover {
  background: rgba(255, 255, 255, 0.28);
}

/* Chat Discussion Feed */
.chat-discussion-feed {
  flex: 1;
  background-color: var(--wa-bg);
  background-image: radial-gradient(rgba(0,0,0,0.04) 1px, transparent 1px);
  background-size: 16px 16px;
  padding: 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.chat-date-divider {
  text-align: center;
  margin: 0.2rem 0 0.5rem 0;
}

.chat-date-divider span {
  background: rgba(255, 255, 255, 0.85);
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  text-transform: uppercase;
}

/* Outgoing Message Bubble (Business -> Customer) */
.chat-bubble-outgoing {
  align-self: flex-end;
  max-width: 88%;
  background: var(--wa-bubble);
  border-radius: 8px 0px 8px 8px;
  padding: 0.75rem 0.85rem;
  box-shadow: 0 1px 2px rgba(0,0,0,0.12);
  position: relative;
}

.template-badge-pill {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--indigo-primary);
  background: rgba(79, 70, 229, 0.1);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  display: inline-block;
  margin-bottom: 0.4rem;
}

.msg-header-title {
  font-weight: 700;
  font-size: 0.875rem;
  color: var(--text-main);
  margin-bottom: 0.3rem;
}

.msg-body-text {
  font-size: 0.85rem;
  color: #1E293B;
  white-space: pre-wrap;
  line-height: 1.45;
}

.msg-footer-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.3rem;
  margin-top: 0.35rem;
  font-size: 0.675rem;
  color: var(--text-muted);
}

.double-check {
  color: #38BDF8;
  font-weight: 700;
}

/* Incoming Message Bubble (Customer -> Business) */
.chat-bubble-incoming {
  align-self: flex-start;
  max-width: 85%;
  background: #FFFFFF;
  border-radius: 0px 8px 8px 8px;
  padding: 0.75rem 0.85rem;
  box-shadow: 0 1px 2px rgba(0,0,0,0.12);
}

.incoming-sender-title {
  font-size: 0.725rem;
  font-weight: 700;
  color: #0284C7;
  margin-bottom: 0.2rem;
}

/* Legal Pages Styling */
.legal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  box-shadow: var(--shadow-card);
}

.legal-card h1 {
  font-family: var(--font-heading);
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.legal-meta {
  color: var(--text-muted);
  font-size: 0.85rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 1.5rem;
}

.legal-card h2 {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  color: var(--indigo-primary);
  margin: 1.75rem 0 0.75rem 0;
}

.legal-card p, .legal-card ul {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 1rem;
}

.legal-card ul {
  padding-left: 1.5rem;
}

/* Responsive Grid */
@media (max-width: 1024px) {
  .messaging-workspace { grid-template-columns: 1fr; }
  .phone-pane-card { height: 500px; position: static; }
}

@media (max-width: 768px) {
  .app-wrapper { flex-direction: column; }
  .sidebar { width: 100%; position: relative; border-right: none; }
  .main-content { margin-left: 0; padding: 1.25rem; }
}
