:root {
  --wa-green: #00a884;
  --wa-green-dark: #008069;
  --wa-green-light: #d9fdd3;
  --wa-teal: #008069;
  --wa-teal-dark: #005c4b;
  --wa-blue: #53bdeb;
  --wa-bg: #efeae2;
  --wa-bg-pattern: #d1d7db;
  --text-primary: #111b21;
  --text-secondary: #667781;
  --bg-white: #ffffff;
  --bg-light: #f0f2f5;
  --border-color: #e9edef;
  --danger: #dc3545;
  --danger-dark: #c82333;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-light);
  color: var(--text-primary);
  line-height: 1.5;
}

a {
  color: var(--wa-green-dark);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Header */
.header {
  background: var(--wa-teal);
  color: white;
  padding: 15px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-logo {
  font-size: 20px;
  font-weight: bold;
}

.header-nav {
  display: flex;
  gap: 20px;
  align-items: center;
}

.header-nav a {
  color: white;
  opacity: 0.9;
}

.header-nav a:hover {
  opacity: 1;
  text-decoration: none;
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 10px 20px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  transition: background 0.2s;
}

.btn-primary {
  background: var(--wa-green);
  color: white;
}

.btn-primary:hover {
  background: var(--wa-green-dark);
  text-decoration: none;
}

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

.btn-secondary:hover {
  background: var(--border-color);
  text-decoration: none;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  background: var(--danger-dark);
  text-decoration: none;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-block {
  display: block;
  width: 100%;
}

/* Forms */
.form-group {
  margin-bottom: 15px;
}

.form-label {
  display: block;
  margin-bottom: 5px;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 14px;
  transition: border-color 0.2s;
}

.form-input:focus {
  outline: none;
  border-color: var(--wa-green);
}

/* Cards */
.card {
  background: var(--bg-white);
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  padding: 20px;
  margin-bottom: 20px;
}

.card-header {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-color);
}

/* Alerts */
.alert {
  padding: 12px 15px;
  border-radius: 4px;
  margin-bottom: 20px;
}

.alert-success {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.alert-error {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.alert-info {
  background: #d1ecf1;
  color: #0c5460;
  border: 1px solid #bee5eb;
}

/* Auth Layout */
.auth-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, var(--wa-teal) 0%, var(--wa-green-dark) 100%);
}

.auth-box {
  background: white;
  border-radius: 8px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

.auth-logo {
  text-align: center;
  margin-bottom: 30px;
}

.auth-logo h1 {
  color: var(--wa-green);
  font-size: 28px;
}

.auth-footer {
  text-align: center;
  margin-top: 20px;
  color: var(--text-secondary);
}

/* Dashboard Layout */
.dashboard {
  display: flex;
  min-height: calc(100vh - 60px);
}

.sidebar {
  width: 250px;
  background: var(--bg-white);
  border-right: 1px solid var(--border-color);
  padding: 20px 0;
}

.sidebar-menu {
  list-style: none;
}

.sidebar-menu a {
  display: block;
  padding: 12px 20px;
  color: var(--text-primary);
  transition: background 0.2s;
}

.sidebar-menu a:hover,
.sidebar-menu a.active {
  background: var(--bg-light);
  text-decoration: none;
}

.sidebar-menu a.active {
  border-left: 3px solid var(--wa-green);
  font-weight: 500;
}

.sidebar-client {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 10px;
}

.sidebar-client small {
  display: block;
  font-size: 11px;
  margin-bottom: 2px;
}

.main-content {
  flex: 1;
  padding: 30px;
  max-width: 1000px;
}

/* Status Badge */
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}

.status-badge::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}

.status-connected {
  background: #d4edda;
  color: #155724;
}

.status-connected::before {
  background: #28a745;
}

.status-disconnected {
  background: #f8d7da;
  color: #721c24;
}

.status-disconnected::before {
  background: #dc3545;
}

.status-pending {
  background: #fff3cd;
  color: #856404;
}

.status-pending::before {
  background: #ffc107;
}

/* QR Code */
.qr-container {
  text-align: center;
  padding: 30px;
}

.qr-code {
  max-width: 280px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  margin: 20px auto;
}

.qr-instruction {
  color: var(--text-secondary);
  max-width: 400px;
  margin: 0 auto;
}

/* API Key Box */
.api-key-box {
  display: flex;
  align-items: center;
  background: var(--bg-light);
  border-radius: 4px;
  padding: 10px;
  font-family: monospace;
}

.api-key-box code {
  flex: 1;
  word-break: break-all;
}

.api-key-box button {
  margin-left: 10px;
}

/* Chat Layout */
.chat-container {
  display: flex;
  height: 100vh;
  background: var(--bg-white);
}

.chat-sidebar {
  width: 400px;
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  background: var(--bg-white);
}

.chat-sidebar-header {
  padding: 10px 16px;
  background: var(--wa-teal);
  color: white;
  display: flex;
  align-items: center;
  min-height: 60px;
}

.chat-sidebar-header a {
  color: white;
  opacity: 0.9;
}

.chat-sidebar-header a:hover {
  opacity: 1;
  text-decoration: none;
}

.chat-sidebar-header strong {
  font-size: 18px;
  font-weight: 500;
}

.chat-sidebar-header .btn {
  background: rgba(255,255,255,0.2);
  border: none;
}

.chat-sidebar-header .btn:hover {
  background: rgba(255,255,255,0.3);
}

.chat-search {
  padding: 8px 12px;
  background: var(--bg-light);
  border-bottom: 1px solid var(--border-color);
}

.chat-search input {
  width: 100%;
  padding: 8px 12px;
  border: none;
  border-radius: 8px;
  background: var(--bg-white);
  font-size: 14px;
}

.chat-search input:focus {
  outline: none;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
}

.chat-item {
  display: flex;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.15s;
  text-decoration: none;
  color: inherit;
  border-bottom: 1px solid var(--border-color);
}

.chat-item:hover {
  background: var(--bg-light);
  text-decoration: none;
}

.chat-item.active {
  background: #f0f2f5;
}

.chat-avatar {
  width: 49px;
  height: 49px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--wa-green-dark) 0%, var(--wa-teal) 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 500;
  font-size: 18px;
  margin-right: 13px;
  flex-shrink: 0;
  overflow: hidden;
  position: relative;
}

.chat-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.chat-avatar .avatar-initials {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-avatar.small {
  width: 40px;
  height: 40px;
  font-size: 15px;
}

.chat-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.chat-info-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 2px;
}

.chat-name {
  font-weight: 400;
  font-size: 16px;
  color: var(--text-primary);
}

.chat-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  margin-left: 10px;
  flex-shrink: 0;
}

.chat-time {
  font-size: 12px;
  color: var(--text-secondary);
}

.chat-time.unread {
  color: var(--wa-green);
  font-weight: 500;
}

.chat-preview-row {
  display: flex;
  align-items: center;
}

.chat-preview {
  color: var(--text-secondary);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.chat-preview-status {
  color: var(--text-secondary);
  margin-right: 4px;
  font-size: 16px;
}

.chat-preview-status.read {
  color: #53bdeb;
}

.chat-unread-badge {
  background: var(--wa-green);
  color: white;
  font-size: 11px;
  font-weight: 500;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  margin-top: 4px;
}

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

.chat-header {
  padding: 10px 16px;
  background: var(--wa-teal);
  color: white;
  display: flex;
  align-items: center;
  min-height: 60px;
}

.chat-header .btn-secondary {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
}

.chat-header .btn-secondary:hover {
  background: rgba(255,255,255,0.3);
}

.chat-header .chat-avatar {
  margin-right: 12px;
  margin-left: 0;
  background: rgba(255,255,255,0.2);
}

.chat-header-info {
  flex: 1;
}

.chat-header-name {
  font-weight: 500;
  font-size: 16px;
}

.chat-header-status {
  font-size: 13px;
  opacity: 0.85;
}

.chat-header-status.online {
  color: #82fab2;
}

.chat-header-actions {
  display: flex;
  gap: 8px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 40px;
  background: var(--wa-bg);
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23d4cdc4' fill-opacity='0.4'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.message {
  max-width: 65%;
  padding: 6px 12px 8px;
  border-radius: 8px;
  margin-bottom: 3px;
  position: relative;
  box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
  display: flex;
  flex-direction: column;
}

.message-out {
  background: var(--wa-green-light);
  margin-left: auto;
  border-top-right-radius: 0;
}

.message-out::before {
  content: '';
  position: absolute;
  top: 0;
  right: -8px;
  width: 8px;
  height: 13px;
  background: var(--wa-green-light);
  clip-path: polygon(0 0, 0% 100%, 100% 0);
}

.message-in {
  background: var(--bg-white);
  margin-right: auto;
  border-top-left-radius: 0;
}

.message-in::before {
  content: '';
  position: absolute;
  top: 0;
  left: -8px;
  width: 8px;
  height: 13px;
  background: var(--bg-white);
  clip-path: polygon(100% 0, 0 0, 100% 100%);
}

.message-media {
  margin: -6px -12px 6px -12px;
  border-radius: 8px 8px 0 0;
  overflow: hidden;
}

.message-media img {
  display: block;
  max-width: 100%;
  max-height: 300px;
  width: auto;
  cursor: pointer;
  border-radius: 8px 8px 0 0;
}

.message-out .message-media {
  border-radius: 0 8px 0 0;
}

.message-in .message-media {
  border-radius: 8px 0 0 0;
}

.message-text {
  word-wrap: break-word;
  font-size: 14.2px;
  line-height: 1.4;
  white-space: pre-wrap;
}

/* Media viewer overlay */
.media-viewer {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  cursor: pointer;
}

.media-viewer img {
  max-width: 90%;
  max-height: 90%;
  object-fit: contain;
}

.media-viewer-close {
  position: absolute;
  top: 20px;
  right: 20px;
  color: white;
  font-size: 32px;
  cursor: pointer;
  background: none;
  border: none;
  padding: 10px;
}

.message-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
}

.message-time {
  font-size: 11px;
  color: rgba(0, 0, 0, 0.45);
}

.message-status {
  font-size: 14px;
  color: rgba(0, 0, 0, 0.45);
  line-height: 1;
}

.message-status.read {
  color: #53bdeb;
}

/* Date separator */
.date-separator {
  display: flex;
  justify-content: center;
  margin: 15px 0;
}

.date-separator span {
  background: rgba(255, 255, 255, 0.9);
  padding: 5px 12px;
  border-radius: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
}

.chat-input-container {
  padding: 15px 20px;
  background: var(--bg-light);
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: 10px;
}

.chat-input {
  flex: 1;
  padding: 12px 15px;
  border: 1px solid var(--border-color);
  border-radius: 25px;
  font-size: 14px;
  outline: none;
}

.chat-input:focus {
  border-color: var(--wa-green);
}

.chat-send-btn {
  width: 45px;
  height: 45px;
  border-radius: 50%;
  background: var(--wa-green);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-send-btn:hover {
  background: var(--wa-green-dark);
}

/* Landing Page */
.landing-hero {
  background: linear-gradient(135deg, var(--wa-teal) 0%, var(--wa-green-dark) 100%);
  color: white;
  padding: 80px 20px;
  text-align: center;
}

.landing-hero h1 {
  font-size: 42px;
  margin-bottom: 20px;
}

.landing-hero p {
  font-size: 18px;
  opacity: 0.9;
  max-width: 600px;
  margin: 0 auto 30px;
}

.landing-features {
  padding: 60px 20px;
  max-width: 1000px;
  margin: 0 auto;
}

.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 30px;
}

.feature-card {
  text-align: center;
  padding: 30px;
}

.feature-icon {
  width: 60px;
  height: 60px;
  background: var(--wa-green);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  margin: 0 auto 15px;
}

.feature-card h3 {
  margin-bottom: 10px;
}

.feature-card p {
  color: var(--text-secondary);
}

/* Language Selector */
.lang-selector {
  position: relative;
  display: inline-block;
}

.lang-selector select {
  appearance: none;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.3);
  color: white;
  padding: 5px 25px 5px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}

.lang-selector select option {
  color: var(--text-primary);
}

/* Utility */
.text-center { text-align: center; }
.text-muted { color: var(--text-secondary); }
.mt-10 { margin-top: 10px; }
.mt-20 { margin-top: 20px; }
.mb-10 { margin-bottom: 10px; }
.mb-20 { margin-bottom: 20px; }

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    display: none;
  }

  .chat-sidebar {
    width: 100%;
  }

  .chat-main {
    display: none;
  }

  .chat-container.chat-open .chat-sidebar {
    display: none;
  }

  .chat-container.chat-open .chat-main {
    display: flex;
  }

  .landing-hero h1 {
    font-size: 28px;
  }
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.modal-content {
  background: var(--bg-white);
  border-radius: 8px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.modal-header {
  padding: 15px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-secondary);
  line-height: 1;
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  padding: 15px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
