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

:root {
  --bg-primary: #f5f5f5;
  --bg-secondary: #fff;
  --bg-tertiary: #f9f9f9;
  --bg-hover: #f0f0f0;
  --text-primary: #333;
  --text-secondary: #666;
  --text-tertiary: #888;
  --border-color: #e0e0e0;
  --border-color-hover: #25D366;
  --whatsapp-green: #25D366;
  --whatsapp-dark: #128C7E;
  --shadow: rgba(0, 0, 0, 0.1);
  --shadow-hover: rgba(0, 0, 0, 0.15);
  --input-bg: #fff;
  --modal-overlay: rgba(0, 0, 0, 0.5);
}

body.dark-mode {
  --bg-primary: #1a1a1a;
  --bg-secondary: #2d2d2d;
  --bg-tertiary: #363636;
  --bg-hover: #404040;
  --text-primary: #e0e0e0;
  --text-secondary: #b0b0b0;
  --text-tertiary: #888;
  --border-color: #444;
  --border-color-hover: #25D366;
  --shadow: rgba(0, 0, 0, 0.3);
  --shadow-hover: rgba(0, 0, 0, 0.4);
  --input-bg: #363636;
  --modal-overlay: rgba(0, 0, 0, 0.7);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  transition: background-color 0.3s, color 0.3s;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

header {
  background: var(--bg-secondary);
  padding: 20px;
  border-radius: 8px;
  margin-bottom: 20px;
  box-shadow: 0 2px 4px var(--shadow);
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background-color 0.3s, box-shadow 0.3s;
}

header h1 {
  font-size: 24px;
  color: var(--whatsapp-green);
}

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

.theme-toggle {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  padding: 8px 16px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 20px;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-toggle:hover {
  background: var(--bg-hover);
  transform: scale(1.05);
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: #ccc;
}

.status-dot.connected {
  background-color: #25D366;
}

.status-dot.connecting {
  background-color: #FFA500;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  background: var(--bg-secondary);
  padding: 10px;
  border-radius: 8px;
  box-shadow: 0 2px 4px var(--shadow);
  transition: background-color 0.3s, box-shadow 0.3s;
}

.tab-btn {
  padding: 10px 20px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.3s;
}

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

.tab-btn.active {
  background: var(--whatsapp-green);
  color: #fff;
}

/* Tab Content */
.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Card */
.card {
  background: var(--bg-secondary);
  border-radius: 8px;
  box-shadow: 0 2px 4px var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
  transition: background-color 0.3s, box-shadow 0.3s;
}

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

.card h2 {
  font-size: 20px;
  color: var(--text-primary);
  margin-bottom: 15px;
}

/* Buttons */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.3s;
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--whatsapp-green);
  color: #fff;
}

.btn-secondary {
  background: var(--whatsapp-dark);
  color: #fff;
}

.btn-danger {
  background: #dc3545;
  color: #fff;
}

/* QR Code */
.auth-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.qr-container {
  min-height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed #ddd;
  border-radius: 8px;
  padding: 20px;
}

.qr-container img {
  max-width: 300px;
  max-height: 300px;
}

.auth-buttons {
  display: flex;
  gap: 10px;
}

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

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

.input {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background: var(--input-bg);
  color: var(--text-primary);
  transition: all 0.3s;
}

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

/* Flows List */
.flows-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.flow-item {
  padding: 15px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.3s;
  background: var(--bg-secondary);
}

.flow-item:hover {
  border-color: var(--border-color-hover);
  background: var(--bg-tertiary);
}

.flow-item.default-flow {
  border: 2px solid var(--whatsapp-green);
  background: var(--bg-tertiary);
}

.badge-default {
  padding: 4px 10px;
  background: #25D366;
  color: #fff;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.flow-info h3 {
  font-size: 16px;
  margin-bottom: 5px;
}

.flow-info p {
  font-size: 13px;
  color: #666;
}

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

.flow-actions button {
  padding: 6px 12px;
  font-size: 12px;
}

/* Flow Steps */
.flow-steps {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.step-item {
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-tertiary);
  transition: all 0.3s;
}

.step-item .form-group {
  margin-bottom: 8px;
}

.step-item .form-group label {
  margin-bottom: 4px;
  font-size: 12px;
}

.step-item .input {
  padding: 6px 8px;
  font-size: 13px;
}

.step-item textarea.input {
  min-height: 50px;
}

.step-item small {
  font-size: 11px !important;
}

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

.step-header strong {
  font-size: 13px;
}

.step-type {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  background: #128C7E;
  color: #fff;
}

.remove-step {
  background: #dc3545;
  color: #fff;
  border: none;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}

/* Leads List */
.leads-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 15px;
}

.lead-item {
  padding: 15px;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  transition: all 0.3s;
}

.lead-item:hover {
  border-color: #25D366;
  background: #f9f9f9;
}

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

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

.lead-status {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
}

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

.lead-status.completed {
  background: #cce5ff;
  color: #004085;
}

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

.lead-phone {
  color: #666;
  font-size: 13px;
  margin-bottom: 8px;
}

.lead-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.lead-actions button {
  padding: 6px 12px;
  font-size: 12px;
}

/* Messages Container */
.messages-container {
  max-height: 500px;
  overflow-y: auto;
  padding: 20px;
  background: #f5f5f5;
  border-radius: 6px;
}

.message-item {
  margin-bottom: 15px;
  display: flex;
  flex-direction: column;
}

.message-item.sent {
  align-items: flex-end;
}

.message-item.received {
  align-items: flex-start;
}

.message-bubble {
  max-width: 70%;
  padding: 10px 15px;
  border-radius: 8px;
  position: relative;
}

.message-item.sent .message-bubble {
  background: #DCF8C6;
  color: #000;
}

.message-item.received .message-bubble {
  background: #fff;
  color: #000;
}

.message-time {
  font-size: 11px;
  color: #666;
  margin-top: 5px;
}

/* Logs List */
.logs-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 600px;
  overflow-y: auto;
}

.log-item {
  padding: 12px;
  border-left: 4px solid #ccc;
  background: #f9f9f9;
  border-radius: 4px;
}

.log-item.info {
  border-left-color: #17a2b8;
}

.log-item.warning {
  border-left-color: #ffc107;
}

.log-item.error {
  border-left-color: #dc3545;
}

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

.log-level {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
}

.log-level.info {
  background: #d1ecf1;
  color: #0c5460;
}

.log-level.warning {
  background: #fff3cd;
  color: #856404;
}

.log-level.error {
  background: #f8d7da;
  color: #721c24;
}

.log-time {
  font-size: 12px;
  color: #666;
}

.log-message {
  font-size: 13px;
  color: #333;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: var(--modal-overlay);
  transition: background-color 0.3s;
}

.modal.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-content {
  background-color: var(--bg-secondary);
  padding: 30px;
  border-radius: 8px;
  max-width: 600px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  transition: background-color 0.3s;
}

.conversation-modal {
  max-width: 800px;
}

.flow-modal-content {
  max-width: 96vw;
  width: 96vw;
  height: 96vh;
  max-height: 96vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 20px;
}

.flow-modal-content h2 {
  margin-bottom: 15px;
  flex-shrink: 0;
  font-size: 20px;
}

.flow-modal-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 10px;
  min-height: 0;
}

.flow-modal-content .modal-actions {
  flex-shrink: 0;
}

.flow-modal-body::-webkit-scrollbar {
  width: 8px;
}

.flow-modal-body::-webkit-scrollbar-track {
  background: var(--bg-tertiary);
  border-radius: 4px;
}

.flow-modal-body::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.flow-modal-body::-webkit-scrollbar-thumb:hover {
  background: var(--whatsapp-green);
}

.close {
  position: absolute;
  right: 20px;
  top: 20px;
  font-size: 28px;
  font-weight: bold;
  color: #aaa;
  cursor: pointer;
}

.close:hover {
  color: #000;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  justify-content: flex-end;
}

/* Tags List */
.tags-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 15px;
}

.tag-item {
  padding: 15px;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.3s;
}

.tag-item:hover {
  border-color: #25D366;
  background: #f9f9f9;
}

.tag-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.tag-color-circle {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex-shrink: 0;
}

.tag-name {
  font-weight: 500;
  font-size: 14px;
}

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

.tag-actions button {
  padding: 6px 12px;
  font-size: 12px;
}

/* Step Controls */
.step-controls {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed #ddd;
}

.step-controls button {
  padding: 4px 8px;
  font-size: 11px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.3s;
}

.step-control-move {
  background: #17a2b8;
  color: #fff;
}

.step-control-add {
  background: #28a745;
  color: #fff;
}

.step-control-delete {
  background: #dc3545;
  color: #fff;
}

.step-controls button:hover {
  opacity: 0.8;
}

/* Flow Editor Visual */
.flow-editor-container {
  background: var(--bg-tertiary);
  border: 2px solid var(--border-color);
  border-radius: 8px;
  min-height: 600px;
  position: relative;
  overflow: auto;
  width: 100%;
}

.flow-modal-content .flow-editor-container {
  min-height: calc(96vh - 200px);
  max-height: calc(96vh - 200px);
  overflow: auto;
}

.flow-editor-canvas {
  position: relative;
  width: 125%;
  min-width: 1750px;
  min-height: 750px;
  height: auto;
  background-image:
    linear-gradient(var(--border-color) 1px, transparent 1px),
    linear-gradient(90deg, var(--border-color) 1px, transparent 1px);
  background-size: 20px 20px;
  transform-origin: top left;
}

.flow-modal-content .flow-editor-canvas {
  min-height: calc((96vh - 200px) * 1.25);
  min-width: 2250px;
  width: 125%;
}

.flow-editor-toolbar {
  display: flex;
  gap: 10px;
  padding: 15px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
}

.flow-node {
  position: absolute;
  background: var(--bg-secondary);
  border: 2px solid var(--whatsapp-green);
  border-radius: 12px;
  padding: 15px;
  min-width: 200px;
  cursor: move;
  box-shadow: 0 4px 8px var(--shadow);
  transition: all 0.3s;
  user-select: none;
  z-index: 10;
}

.flow-node:hover {
  box-shadow: 0 6px 12px var(--shadow-hover);
  transform: translateY(-2px);
}

.flow-node.dragging {
  opacity: 0.7;
  cursor: grabbing;
  transition: none;
}

.flow-node.selected {
  border-color: #ffc107;
  box-shadow: 0 0 0 3px rgba(255, 193, 7, 0.3);
}

.flow-node-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
}

.flow-node-type {
  font-weight: 600;
  font-size: 13px;
  color: var(--whatsapp-green);
  display: flex;
  align-items: center;
  gap: 5px;
}

.flow-node-delete {
  background: #dc3545;
  color: white;
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  transition: all 0.2s;
}

.flow-node-delete:hover {
  transform: scale(1.1);
}

.flow-node-content {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 10px;
  max-width: 250px;
  word-wrap: break-word;
}

.flow-node-ports {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
}

.flow-node-port {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--whatsapp-green);
  border: 2px solid var(--bg-secondary);
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}

.flow-node-port:hover {
  transform: scale(1.3);
  box-shadow: 0 0 8px var(--whatsapp-green);
}

.flow-node-port.input {
  background: #17a2b8;
}

.flow-node-port.output {
  background: var(--whatsapp-green);
}

.flow-node-port.active {
  transform: scale(1.5);
  box-shadow: 0 0 12px var(--whatsapp-green);
  animation: pulse-port 0.5s infinite;
}

@keyframes pulse-port {
  0%, 100% { box-shadow: 0 0 8px var(--whatsapp-green); }
  50% { box-shadow: 0 0 16px var(--whatsapp-green); }
}

.flow-node.connecting {
  border-color: #ffc107;
  box-shadow: 0 0 12px rgba(255, 193, 7, 0.5);
}

.flow-connections {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  overflow: visible;
  min-width: 100%;
  min-height: 100%;
}

.flow-connection {
  stroke: var(--whatsapp-green);
  stroke-width: 3;
  fill: none;
  filter: drop-shadow(0 2px 4px var(--shadow));
}

.flow-connection.temp {
  stroke: var(--text-tertiary);
  stroke-dasharray: 5, 5;
}

.add-node-menu {
  position: absolute;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px;
  box-shadow: 0 4px 12px var(--shadow);
  z-index: 100;
  max-height: 400px;
  overflow-y: auto;
  min-width: 200px;
}

.add-node-item {
  padding: 10px;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
}

.add-node-item:hover {
  background: var(--bg-hover);
  color: var(--whatsapp-green);
}

.flow-editor-minimap {
  position: absolute;
  bottom: 20px;
  right: 20px;
  width: 200px;
  height: 150px;
  background: var(--bg-secondary);
  border: 2px solid var(--border-color);
  border-radius: 8px;
  opacity: 0.8;
  pointer-events: none;
}

.zoom-controls {
  position: absolute;
  top: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.zoom-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  width: 36px;
  height: 36px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  color: var(--text-primary);
}

.zoom-btn:hover {
  background: var(--whatsapp-green);
  color: white;
  transform: scale(1.1);
}

.zoom-level {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  width: 36px;
  height: 30px;
  border-radius: 6px;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  font-weight: 600;
  user-select: none;
}

/* Responsive */
@media (max-width: 768px) {
  .container {
    padding: 10px;
  }

  header {
    flex-direction: column;
    gap: 15px;
  }

  .tabs {
    flex-wrap: wrap;
  }

  .leads-list {
    grid-template-columns: 1fr;
  }

  .tags-list {
    grid-template-columns: 1fr;
  }

  .modal-content {
    width: 95%;
    padding: 20px;
  }

  .flow-modal-content {
    width: 98vw;
    height: 98vh;
    padding: 15px;
  }

  .flow-modal-content .flow-editor-canvas {
    height: calc(98vh - 380px);
    min-width: 100%;
  }

  .flow-editor-canvas {
    height: 400px;
    min-width: 100%;
  }

  .flow-connections {
    min-width: 100%;
  }

  .flow-modal-content .flow-connections {
    min-width: 100%;
  }

  .flow-node {
    min-width: 150px;
  }

  .flow-editor-toolbar {
    flex-wrap: wrap;
  }

  .flow-modal-body > div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }
}

.flow-modal-body > div[style*="grid-template-columns"] {
  display: grid;
}
