/* =========================================
   RESET & BASE
   ========================================= */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-base:       #080c14;
  --bg-card:       rgba(13, 20, 38, 0.75);
  --bg-card-hover: rgba(18, 28, 52, 0.85);
  --border:        rgba(99, 120, 180, 0.18);
  --border-active: rgba(124, 77, 255, 0.6);

  --text-primary:  #eef2ff;
  --text-secondary:#8a9bbf;
  --text-muted:    #4a5680;

  --accent-1:  #7c4dff;
  --accent-2:  #448fff;
  --accent-wa: #25d366;

  --success: #22c55e;
  --error:   #f43f5e;
  --warn:    #f59e0b;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;

  --shadow-card: 0 8px 32px rgba(0,0,0,0.45), 0 1px 0 rgba(255,255,255,0.04) inset;
  --shadow-btn:  0 4px 24px rgba(124, 77, 255, 0.45);

  --font: 'Inter', sans-serif;
  --transition: 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* =========================================
   BACKGROUND ORBS
   ========================================= */
.bg-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(100px);
  pointer-events: none;
  z-index: 0;
  animation: orbFloat 12s ease-in-out infinite;
}
.orb-1 {
  width: 600px; height: 600px;
  background: radial-gradient(circle, rgba(124,77,255,0.2) 0%, transparent 70%);
  top: -200px; left: -150px;
  animation-delay: 0s;
}
.orb-2 {
  width: 500px; height: 500px;
  background: radial-gradient(circle, rgba(68,143,255,0.15) 0%, transparent 70%);
  bottom: -100px; right: -100px;
  animation-delay: -4s;
}
.orb-3 {
  width: 400px; height: 400px;
  background: radial-gradient(circle, rgba(37,211,102,0.1) 0%, transparent 70%);
  top: 50%; right: 30%;
  animation-delay: -8s;
}

@keyframes orbFloat {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-40px) scale(1.05); }
}

/* =========================================
   APP WRAPPER
   ========================================= */
.app-wrapper {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px 48px;
}

/* =========================================
   HEADER
   ========================================= */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 0 32px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 36px;
}

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

.brand-icon {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, var(--accent-wa), #1aab55);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 4px 16px rgba(37,211,102,0.4);
}

.brand-icon svg {
  width: 24px; height: 24px;
}

.brand-title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #fff 30%, var(--accent-1));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.brand-subtitle {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Connection Status */
.header-status {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 8px 16px;
  backdrop-filter: blur(12px);
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--warn);
  animation: pulse-dot 2s ease-in-out infinite;
}

.header-status.online .status-dot { background: var(--success); }
.header-status.offline .status-dot { background: var(--error); animation: none; }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}

.status-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

/* =========================================
   MAIN LAYOUT
   ========================================= */
.main-content {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 28px;
  align-items: start;
}

/* =========================================
   GLASS CARD MIXIN (shared)
   ========================================= */
.compose-panel,
.preview-card,
.history-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

/* =========================================
   COMPOSE PANEL
   ========================================= */
.compose-panel {
  padding: 32px;
}

.panel-header {
  margin-bottom: 28px;
}

.panel-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.4px;
  margin-bottom: 4px;
}

.panel-desc {
  font-size: 14px;
  color: var(--text-secondary);
}

/* =========================================
   FORM ELEMENTS
   ========================================= */
.compose-form {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.form-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.label-icon {
  width: 15px; height: 15px;
  opacity: 0.7;
  flex-shrink: 0;
}

.char-count {
  margin-left: auto;
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  text-transform: none;
  letter-spacing: 0;
}

.form-input,
.form-textarea {
  width: 100%;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  padding: 14px 16px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--text-muted);
}

.form-input:focus,
.form-textarea:focus {
  border-color: var(--accent-1);
  background: rgba(124,77,255,0.07);
  box-shadow: 0 0 0 3px rgba(124,77,255,0.15);
}

.form-textarea {
  min-height: 160px;
  resize: vertical;
  line-height: 1.6;
}

.form-hint {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* =========================================
   SEGMENT GRID
   ========================================= */
.segment-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.segment-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 8px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font);
  text-align: center;
}

.segment-btn:hover {
  background: rgba(124,77,255,0.1);
  border-color: rgba(124,77,255,0.4);
  color: var(--text-primary);
  transform: translateY(-2px);
}

.segment-btn.active {
  background: rgba(124,77,255,0.18);
  border-color: var(--accent-1);
  color: var(--text-primary);
  box-shadow: 0 0 16px rgba(124,77,255,0.25);
}

.segment-icon {
  font-size: 22px;
  line-height: 1;
}

.segment-name {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.3;
}

.segment-count {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-1);
  background: rgba(124,77,255,0.15);
  border-radius: 100px;
  padding: 2px 7px;
  min-width: 24px;
  text-align: center;
}

/* =========================================
   IMAGE TOGGLE
   ========================================= */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.toggle-switch {
  cursor: pointer;
  position: relative;
}

.toggle-switch input {
  position: absolute;
  opacity: 0;
  width: 0; height: 0;
}

.toggle-track {
  display: block;
  width: 48px; height: 26px;
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--border);
  border-radius: 100px;
  position: relative;
  transition: background var(--transition), border-color var(--transition);
}

.toggle-thumb {
  position: absolute;
  top: 3px; left: 3px;
  width: 18px; height: 18px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: transform var(--transition), background var(--transition);
}

.toggle-switch input:checked + .toggle-track {
  background: rgba(124,77,255,0.3);
  border-color: var(--accent-1);
}

.toggle-switch input:checked + .toggle-track .toggle-thumb {
  transform: translateX(22px);
  background: var(--accent-1);
}

.image-field {
  display: none;
  flex-direction: column;
  gap: 10px;
  animation: fadeSlideDown 0.25s ease forwards;
}

.image-field.visible {
  display: flex;
}

@keyframes fadeSlideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.image-preview-wrapper {
  display: none;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border);
  max-height: 200px;
}

.image-preview-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* =========================================
   UPLOAD AREA
   ========================================= */
.upload-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 28px 20px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
}

.upload-area:hover,
.upload-area.drag-over {
  border-color: var(--accent-1);
  background: rgba(124,77,255,0.07);
}

.upload-icon {
  width: 44px; height: 44px;
  background: rgba(124,77,255,0.12);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-1);
  transition: background var(--transition);
}

.upload-icon svg {
  width: 22px; height: 22px;
}

.upload-area:hover .upload-icon {
  background: rgba(124,77,255,0.25);
}

.upload-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
}

.upload-hint {
  font-size: 12px;
  color: var(--text-muted);
}

.image-preview-wrapper {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border);
  display: none;
}

.image-preview-wrapper img {
  width: 100%;
  display: block;
  object-fit: cover;
  max-height: 220px;
}

.btn-remove-image {
  position: absolute;
  top: 10px; right: 10px;
  width: 30px; height: 30px;
  background: rgba(0,0,0,0.65);
  border: none;
  border-radius: 50%;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}

.btn-remove-image:hover { background: var(--error); }

.btn-remove-image svg {
  width: 15px; height: 15px;
}

/* =========================================
   SEND BUTTON
   ========================================= */
.btn-send {
  position: relative;
  width: 100%;
  padding: 17px;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  border: none;
  border-radius: var(--radius-md);
  color: white;
  font-family: var(--font);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: var(--shadow-btn);
  overflow: hidden;
}

.btn-send::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.15), transparent);
  opacity: 0;
  transition: opacity var(--transition);
}

.btn-send:hover::before { opacity: 1; }
.btn-send:hover { transform: translateY(-2px); box-shadow: 0 8px 32px rgba(124,77,255,0.55); }
.btn-send:active { transform: translateY(0); }
.btn-send:disabled { opacity: 0.6; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-idle,
.btn-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.btn-idle svg {
  width: 18px; height: 18px;
}

/* =========================================
   SPINNER
   ========================================= */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* =========================================
   SIDE PANEL
   ========================================= */
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
  position: sticky;
  top: 24px;
}

/* =========================================
   PREVIEW CARD
   ========================================= */
.preview-card {
  padding: 20px;
}

.preview-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.preview-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-wa), #1aab55);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.preview-avatar svg {
  width: 20px; height: 20px;
  fill: white;
}

.preview-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.preview-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.preview-bubble {
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-radius: 4px 14px 14px 14px;
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 80px;
}

.preview-placeholder {
  color: var(--text-muted);
  font-style: italic;
  font-size: 13px;
}

.preview-image-container {
  margin-top: 10px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border);
}

.preview-image-container img {
  width: 100%;
  display: block;
  object-fit: cover;
  max-height: 180px;
}

/* =========================================
   SAVE TEMPLATE BUTTON
   ========================================= */
.btn-save-template {
  padding: 17px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}
.btn-save-template:hover {
  background: rgba(124,77,255,0.15);
  border-color: var(--accent-1);
}

/* =========================================
   GLOBAL TEMPLATES CARD
   ========================================= */
.templates-card {
  padding: 20px;
  margin-bottom: 20px;
}

.templates-header {
  margin-bottom: 16px;
}

.templates-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.templates-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 250px;
  overflow-y: auto;
}

.templates-list::-webkit-scrollbar { width: 4px; }
.templates-list::-webkit-scrollbar-track { background: transparent; }
.templates-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.templates-empty {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  padding: 16px 0;
  font-style: italic;
}

.template-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}

.template-item:hover {
  background: rgba(124,77,255,0.1);
  border-color: rgba(124,77,255,0.4);
  transform: translateY(-1px);
}

.template-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow: hidden;
}

.template-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.template-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.btn-delete-template {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  transition: color var(--transition);
}

.btn-delete-template:hover {
  color: var(--error);
}

/* =========================================
   HISTORY CARD
   ========================================= */
.history-card {
  padding: 20px;
}

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

.history-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.btn-clear {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  padding: 4px 8px;
  border-radius: 6px;
  transition: color var(--transition), background var(--transition);
}
.btn-clear:hover { color: var(--error); background: rgba(244,63,94,0.08); }

.history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 300px;
  overflow-y: auto;
}

.history-list::-webkit-scrollbar { width: 4px; }
.history-list::-webkit-scrollbar-track { background: transparent; }
.history-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.history-empty {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  padding: 16px 0;
  font-style: italic;
}

.history-item {
  display: flex;
  gap: 10px;
  padding: 12px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  animation: fadeSlideDown 0.25s ease;
}

.history-item.success { border-color: rgba(34,197,94,0.25); }
.history-item.error { border-color: rgba(244,63,94,0.25); }

.history-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 4px;
}

.history-item.success .history-dot { background: var(--success); }
.history-item.error .history-dot { background: var(--error); }

.history-info {
  flex: 1;
  min-width: 0;
}

.history-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* =========================================
   TOAST
   ========================================= */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(18, 28, 52, 0.95);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  backdrop-filter: blur(16px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  opacity: 0;
  pointer-events: none;
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1000;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.success { border-color: rgba(34,197,94,0.4); }
.toast.error   { border-color: rgba(244,63,94,0.4); }

.toast-icon { font-size: 18px; }

/* =========================================
   RESPONSIVE
   ========================================= */
@media (max-width: 900px) {
  .main-content {
    grid-template-columns: 1fr;
  }
  .side-panel {
    position: static;
  }
  .segment-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 600px) {
  .app-wrapper { padding: 0 16px 32px; }
  .header { flex-direction: column; gap: 16px; align-items: flex-start; }
  .segment-grid { grid-template-columns: repeat(2, 1fr); }
  .compose-panel { padding: 20px; }
}
