/* WhatsApp Coexistence Hub - Arabic RTL & Modern Design System */
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700;800;900&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  --bg-main: #0b141a;
  --bg-card: #111b21;
  --bg-card-hover: #182229;
  --bg-sidebar: #0e161c;
  --bg-input: #202c33;
  --bg-badge: #1f2c34;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-focus: #25d366;
  
  --wa-green: #25d366;
  --wa-green-hover: #1fa855;
  --wa-teal: #128c7e;
  --wa-teal-dark: #075e54;
  --wa-blue: #34b7f1;
  --wa-blue-read: #53bdeb;
  --wa-bubble-out: #005c4b;
  --wa-bubble-in: #202c33;
  --wa-bubble-echo: #163e36;

  --text-primary: #e9edef;
  --text-secondary: #8696a0;
  --text-muted: #667781;
  --text-accent: #00a884;

  --danger: #f15c5c;
  --warning: #f59e0b;
  --success: #22c55e;
  --info: #38bdf8;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --font-arabic: 'Cairo', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Consolas', monospace;
}

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

body {
  background-color: var(--bg-main);
  color: var(--text-primary);
  font-family: var(--font-arabic);
  min-height: 100vh;
  overflow-x: hidden;
  direction: rtl;
  text-align: right;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-main);
}
::-webkit-scrollbar-thumb {
  background: #2a3942;
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #374751;
}

/* App Container */
.app-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* Sidebar Navigation (In RTL: right side of the screen) */
.app-sidebar {
  width: 280px;
  background: var(--bg-sidebar);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 20;
}

.brand-header {
  padding: 22px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.brand-icon {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--wa-green), var(--wa-teal-dark));
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 4px 14px rgba(37, 211, 102, 0.3);
  flex-shrink: 0;
}

.brand-text h1 {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand-text p {
  font-size: 0.74rem;
  color: var(--text-secondary);
}

.sidebar-nav {
  padding: 16px 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

.nav-link:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.nav-link.active {
  background: rgba(37, 211, 102, 0.12);
  color: var(--wa-green);
  border-color: rgba(37, 211, 102, 0.25);
  font-weight: 700;
}

.nav-link .badge {
  margin-right: auto;
  margin-left: 0;
  background: var(--bg-badge);
  color: var(--text-secondary);
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
}

.nav-link.active .badge {
  background: var(--wa-green);
  color: #0b141a;
  font-weight: 700;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border-subtle);
  background: rgba(0, 0, 0, 0.15);
}

.coexistence-pill-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--wa-green);
  box-shadow: 0 0 10px var(--wa-green);
  animation: pulse-green 2s infinite;
  flex-shrink: 0;
}

.status-dot.warning {
  background: var(--warning);
  box-shadow: 0 0 10px var(--warning);
}

@keyframes pulse-green {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(37, 211, 102, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(37, 211, 102, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(37, 211, 102, 0); }
}

.coexistence-pill-status .info {
  flex: 1;
}
.coexistence-pill-status .title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-primary);
}
.coexistence-pill-status .subtitle {
  font-size: 0.72rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* Main Content Area */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* Top App Header */
.top-header {
  height: 68px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(17, 27, 33, 0.75);
  backdrop-filter: blur(12px);
  z-index: 10;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-title h2 {
  font-size: 1.25rem;
  font-weight: 800;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mode-toggle {
  display: flex;
  align-items: center;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  padding: 3px;
  font-size: 0.8rem;
  cursor: pointer;
}

.mode-btn {
  padding: 6px 14px;
  border-radius: 16px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-weight: 700;
  font-size: 0.78rem;
  font-family: inherit;
  transition: all 0.2s;
}

.mode-btn.active {
  background: var(--wa-green);
  color: #0b141a;
  box-shadow: 0 2px 8px rgba(37, 211, 102, 0.4);
}

/* Page Views */
.view-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  display: none;
}

.view-container.active {
  display: block;
}

/* Grid Layouts */
.grid-studio {
  display: grid;
  grid-template-columns: 1fr 420px;
  gap: 28px;
  align-items: start;
}

@media (max-width: 1150px) {
  .grid-studio {
    grid-template-columns: 1fr;
  }
}

/* Card Component */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-subtitle {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* Form Controls */
.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.form-control {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.92rem;
  transition: border-color 0.2s, box-shadow 0.2s;
  text-align: right;
  direction: rtl;
}

.form-control.ltr {
  direction: ltr;
  text-align: left;
}

.form-control:focus {
  outline: none;
  border-color: var(--wa-green);
  box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.15);
}

.input-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  font-size: 0.9rem;
  font-weight: 700;
  font-family: inherit;
  border-radius: var(--radius-md);
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  text-decoration: none;
}

.btn-primary {
  background: var(--wa-green);
  color: #0b141a;
  box-shadow: 0 4px 14px rgba(37, 211, 102, 0.3);
}

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

.btn-secondary {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.8rem;
}

.btn-full {
  width: 100%;
}

/* Template Cards Grid */
.template-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.template-card-choice {
  background: var(--bg-input);
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  padding: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.template-card-choice:hover {
  background: var(--bg-card-hover);
  border-color: rgba(37, 211, 102, 0.3);
}

.template-card-choice.selected {
  border-color: var(--wa-green);
  background: rgba(37, 211, 102, 0.1);
}

.template-card-choice .name {
  font-size: 0.9rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: 6px;
  direction: ltr;
  text-align: right;
}

.template-card-choice .category-pill {
  font-size: 0.7rem;
  padding: 2px 7px;
  border-radius: 6px;
  font-weight: 700;
  text-transform: uppercase;
  display: inline-block;
}

.category-UTILITY { background: rgba(56, 189, 248, 0.15); color: var(--info); }
.category-MARKETING { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.category-AUTHENTICATION { background: rgba(34, 197, 94, 0.15); color: var(--success); }

/* Realistic WhatsApp Smartphone Simulator */
.phone-mockup-wrapper {
  position: sticky;
  top: 10px;
}

.phone-mockup {
  width: 100%;
  max-width: 390px;
  height: 640px;
  margin: 0 auto;
  background: #0b141a;
  border: 12px solid #232d36;
  border-radius: 46px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.7), inset 0 0 0 2px rgba(255, 255, 255, 0.1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  direction: rtl;
}

.phone-notch {
  width: 140px;
  height: 22px;
  background: #232d36;
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  border-bottom-left-radius: 14px;
  border-bottom-right-radius: 14px;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.notch-speaker {
  width: 40px;
  height: 4px;
  background: #111b21;
  border-radius: 2px;
}
.notch-camera {
  width: 8px;
  height: 8px;
  background: #111b21;
  border-radius: 50%;
}

.phone-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #0b141a;
  background-image: radial-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 0);
  background-size: 16px 16px;
  overflow: hidden;
  margin-top: 10px;
}

.wa-chat-header {
  padding: 12px 14px;
  background: #202c33;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.wa-chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--wa-teal);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
  position: relative;
}

.wa-chat-avatar .verified-badge {
  position: absolute;
  bottom: -2px;
  left: -2px;
  width: 14px;
  height: 14px;
  background: var(--wa-green);
  color: #0b141a;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  border: 1px solid #202c33;
}

.wa-chat-meta .name {
  font-size: 0.9rem;
  font-weight: 700;
  color: #e9edef;
  display: flex;
  align-items: center;
  gap: 6px;
}

.wa-chat-meta .status {
  font-size: 0.72rem;
  color: var(--wa-green);
}

.wa-chat-body {
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.wa-chat-date-pill {
  align-self: center;
  background: #182229;
  color: #8696a0;
  font-size: 0.7rem;
  padding: 4px 12px;
  border-radius: 8px;
  margin-bottom: 8px;
  font-weight: 600;
}

/* WhatsApp Message Bubble */
.wa-bubble {
  max-width: 88%;
  border-radius: 12px;
  padding: 10px 14px;
  position: relative;
  font-size: 0.88rem;
  line-height: 1.5;
  box-shadow: 0 1px 2px rgba(0,0,0,0.3);
  text-align: right;
}

.wa-bubble-out {
  align-self: flex-start; /* in RTL outgoing is on the left or styled out */
  background: var(--wa-bubble-out);
  color: #e9edef;
  border-top-left-radius: 2px;
}

.wa-bubble-in {
  align-self: flex-end;
  background: var(--wa-bubble-in);
  color: #e9edef;
  border-top-right-radius: 2px;
}

.wa-bubble-echo {
  align-self: flex-start;
  background: var(--wa-bubble-echo);
  border: 1px solid rgba(37, 211, 102, 0.35);
  color: #e9edef;
  border-top-left-radius: 2px;
}

.bubble-origin-tag {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.bubble-origin-api { color: var(--wa-green); }
.bubble-origin-echo { color: #53bdeb; }

.wa-bubble-header {
  font-weight: 800;
  margin-bottom: 6px;
  font-size: 0.95rem;
  color: #ffffff;
}

.wa-bubble-text {
  word-break: break-word;
  white-space: pre-wrap;
}

.wa-bubble-footer-text {
  font-size: 0.74rem;
  color: rgba(255, 255, 255, 0.65);
  margin-top: 8px;
  font-style: italic;
}

.wa-bubble-meta {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  margin-top: 4px;
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.6);
  direction: ltr;
}

.wa-ticks-blue {
  color: var(--wa-blue-read);
}

.wa-bubble-buttons {
  margin-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  display: flex;
  flex-direction: column;
  margin-left: -14px;
  margin-right: -14px;
  margin-bottom: -10px;
}

.wa-bubble-btn {
  padding: 9px 12px;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--wa-blue);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.02);
}

/* Dual-Channel Inbox View */
.inbox-container {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 20px;
  height: calc(100vh - 140px);
}

.inbox-threads-list {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.threads-header {
  padding: 16px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.threads-scroll {
  flex: 1;
  overflow-y: auto;
}

.thread-item {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  transition: background 0.15s;
}

.thread-item:hover {
  background: var(--bg-card-hover);
}

.thread-item.active {
  background: rgba(37, 211, 102, 0.1);
  border-right: 3px solid var(--wa-green);
  border-left: none;
}

.thread-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #2a3942;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  font-weight: 600;
  flex-shrink: 0;
}

.thread-content {
  flex: 1;
  min-width: 0;
}

.thread-name {
  font-size: 0.92rem;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.thread-time {
  font-size: 0.72rem;
  color: var(--text-secondary);
  direction: ltr;
}

.thread-preview {
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 3px;
}

.inbox-chat-view {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-view-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0,0,0,0.1);
}

.chat-history {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background-image: radial-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 0);
  background-size: 20px 20px;
}

.chat-input-bar {
  padding: 16px 20px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sim-actions-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
}

/* API Docs / Code Snippets Tab */
.api-tabs-header {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 16px;
  padding-bottom: 8px;
}

.api-tab-btn {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.api-tab-btn.active {
  background: var(--wa-green);
  color: #0b141a;
  border-color: var(--wa-green);
}

.code-container {
  position: relative;
  margin: 12px 0;
}

.code-block {
  background: #060a0d;
  color: #a5d6ff;
  padding: 16px;
  border-radius: 10px;
  font-family: var(--font-mono);
  font-size: 0.84rem;
  overflow-x: auto;
  border: 1px solid rgba(255, 255, 255, 0.08);
  direction: ltr;
  text-align: left;
  line-height: 1.5;
}

.btn-copy-code {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: white;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-copy-code:hover {
  background: var(--wa-green);
  color: #0b141a;
}

/* Coexistence Diagram */
.coexistence-diagram {
  display: grid;
  grid-template-columns: 1fr 80px 1fr;
  align-items: center;
  gap: 16px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin: 20px 0;
}

.diagram-node {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 18px;
  text-align: center;
}

.diagram-node.highlight {
  border-color: var(--wa-green);
  box-shadow: 0 0 20px rgba(37, 211, 102, 0.15);
}

.diagram-node .icon {
  font-size: 2.2rem;
  margin-bottom: 10px;
}

.diagram-arrow {
  text-align: center;
  font-size: 1.8rem;
  color: var(--wa-green);
  font-weight: bold;
}

.json-code {
  background: #060a0d;
  color: #a5d6ff;
  padding: 12px;
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  overflow-x: auto;
  border: 1px solid rgba(255, 255, 255, 0.05);
  direction: ltr;
  text-align: left;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 24px; /* in RTL, toast on bottom left */
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: #fff;
  padding: 14px 20px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 12px;
  animation: slide-in-rtl 0.3s ease;
  min-width: 320px;
}

.toast.success { border-right: 4px solid var(--wa-green); }
.toast.error { border-right: 4px solid var(--danger); }
.toast.info { border-right: 4px solid var(--wa-blue); }

@keyframes slide-in-rtl {
  from { transform: translateX(-100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
