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

:root {
  --primary: #1877f2;
  --primary-dark: #1565c0;
  --primary-light: #e3f2fd;
  --success: #25D366;
  --success-light: #e8f5e9;
  --warning: #ff9800;
  --warning-light: #fff3e0;
  --danger: #f44336;
  --danger-light: #ffebee;
  --gray-50: #fafafa;
  --gray-100: #f5f5f5;
  --gray-200: #eeeeee;
  --gray-300: #e0e0e0;
  --gray-400: #bdbdbd;
  --gray-500: #9e9e9e;
  --gray-600: #757575;
  --gray-700: #616161;
  --gray-800: #424242;
  --gray-900: #212121;
  --white: #ffffff;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
  --radius: 8px;
  --radius-lg: 12px;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-100);
  color: var(--gray-900);
  line-height: 1.5;
}

/* ============ APP LAYOUT ============ */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============ HEADER ============ */
.header {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  font-size: 28px;
}

.logo-text {
  font-size: 20px;
  font-weight: 700;
  color: var(--gray-900);
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--success-light);
  border-radius: 20px;
  font-size: 13px;
  color: var(--success);
  font-weight: 500;
}

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

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ============ MAIN ============ */
.main {
  flex: 1;
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* ============ TOOLBAR ============ */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 16px;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--gray-900);
}

.template-count {
  background: var(--gray-200);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 13px;
  color: var(--gray-600);
  font-weight: 500;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.filter-group {
  display: flex;
  gap: 8px;
}

.filter-select {
  padding: 10px 16px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--white);
  color: var(--gray-700);
  cursor: pointer;
  transition: border-color 0.2s;
}

.filter-select:hover {
  border-color: var(--gray-400);
}

.filter-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* ============ BUTTONS ============ */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}

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

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--gray-100);
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
}

.btn-secondary:hover {
  background: var(--gray-200);
}

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

.btn-danger:hover {
  background: #d32f2f;
}

.btn-icon {
  font-size: 18px;
  font-weight: 400;
}

/* ============ DROPDOWN ============ */
.new-template-dropdown {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  min-width: 280px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.2s;
  z-index: 200;
  border: 1px solid var(--gray-200);
  max-height: 400px;
  overflow-y: auto;
}

.new-template-dropdown:hover .dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.dropdown-item {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid var(--gray-100);
}

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

.dropdown-item:hover {
  background: var(--gray-50);
}

.dropdown-item-icon {
  font-size: 20px;
  width: 32px;
  text-align: center;
}

.dropdown-item-content {
  flex: 1;
}

.dropdown-item-name {
  font-weight: 600;
  color: var(--gray-900);
  font-size: 14px;
}

.dropdown-item-desc {
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 2px;
}

/* ============ TEMPLATES LIST ============ */
.templates-container {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.templates-list {
  display: flex;
  flex-direction: column;
}

.template-item {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--gray-100);
  cursor: pointer;
  transition: background 0.15s;
}

.template-item:hover {
  background: var(--gray-50);
}

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

.template-icon {
  width: 48px;
  height: 48px;
  background: var(--primary-light);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

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

.template-name {
  font-weight: 600;
  color: var(--gray-900);
  font-size: 15px;
  margin-bottom: 4px;
}

.template-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--gray-500);
}

.template-category {
  background: var(--gray-100);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
}

.template-language {
  display: flex;
  align-items: center;
  gap: 4px;
}

.template-status {
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
}

.status-approved {
  background: var(--success-light);
  color: #2e7d32;
}

.status-pending {
  background: var(--warning-light);
  color: #e65100;
}

.status-rejected {
  background: var(--danger-light);
  color: #c62828;
}

.status-paused, .status-disabled {
  background: var(--gray-200);
  color: var(--gray-600);
}

/* ============ PAGINATION ============ */
.pagination {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-top: 1px solid var(--gray-100);
}

.pagination-btn {
  padding: 8px 16px;
  background: var(--white);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.pagination-btn:hover:not(:disabled) {
  background: var(--gray-50);
  border-color: var(--gray-400);
}

.pagination-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pagination-info {
  font-size: 14px;
  color: var(--gray-600);
  padding: 0 16px;
}

/* ============ LOADING ============ */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px;
  gap: 16px;
  color: var(--gray-500);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* ============ EMPTY STATE ============ */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.empty-icon {
  font-size: 64px;
  display: block;
  margin-bottom: 16px;
}

.empty-state h3 {
  font-size: 18px;
  color: var(--gray-900);
  margin-bottom: 8px;
}

.empty-state p {
  color: var(--gray-500);
  font-size: 14px;
}

/* ============ MODAL ============ */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal.active {
  display: flex;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: modalIn 0.2s;
}

.modal-large {
  max-width: 720px;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

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

.modal-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--gray-900);
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  font-size: 24px;
  color: var(--gray-500);
  cursor: pointer;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.modal-close:hover {
  background: var(--gray-100);
  color: var(--gray-700);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--gray-200);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

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

.form-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 8px;
}

.form-label-hint {
  font-weight: 400;
  color: var(--gray-500);
  font-size: 12px;
  margin-left: 4px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  transition: all 0.2s;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.form-textarea {
  resize: vertical;
  min-height: 120px;
}

.form-help {
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 6px;
}

.form-error {
  font-size: 12px;
  color: var(--danger);
  margin-top: 6px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* ============ VARIABLES BUILDER ============ */
.variables-info {
  background: var(--primary-light);
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--primary-dark);
}

.variables-info code {
  background: rgba(0,0,0,0.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
}

/* ============ PREVIEW ============ */
.template-preview {
  background: var(--gray-100);
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 16px;
}

.preview-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  margin-bottom: 12px;
}

.preview-message {
  background: var(--white);
  padding: 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.preview-variable {
  background: var(--warning-light);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--warning);
  font-weight: 500;
}

/* ============ TOAST ============ */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.toast {
  background: var(--gray-900);
  color: var(--white);
  padding: 14px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  animation: toastIn 0.3s;
  max-width: 400px;
}

.toast-success {
  background: var(--success);
}

.toast-error {
  background: var(--danger);
}

.toast-warning {
  background: var(--warning);
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============ BUTTONS GROUP ============ */
.buttons-builder {
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 8px;
}

.button-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--gray-50);
  border-radius: var(--radius);
  margin-bottom: 8px;
}

.button-item:last-child {
  margin-bottom: 0;
}

.btn-add-button {
  width: 100%;
  padding: 12px;
  background: none;
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius);
  color: var(--gray-500);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-add-button:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

/* ============ COMPONENT DETAILS ============ */
.component-section {
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.component-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-600);
  text-transform: uppercase;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.component-type {
  background: var(--gray-200);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
}

/* ============ UPLOAD AREA ============ */
.upload-container {
  margin-top: 8px;
}

.upload-area {
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius);
  padding: 32px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--gray-50);
}

.upload-area:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.upload-area.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
  border-style: solid;
}

.upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.upload-placeholder .upload-icon {
  font-size: 48px;
  opacity: 0.6;
}

.upload-placeholder .upload-text {
  font-size: 14px;
  color: var(--gray-600);
}

.upload-placeholder .upload-text strong {
  color: var(--primary);
  cursor: pointer;
}

.upload-placeholder .upload-hint {
  font-size: 12px;
  color: var(--gray-500);
}

.upload-progress {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px 0;
}

.upload-progress.active {
  display: flex;
}

.upload-progress .progress-bar-container {
  width: 100%;
  height: 8px;
  background: var(--gray-200);
  border-radius: 4px;
  overflow: hidden;
}

.upload-progress .progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  transition: width 0.3s ease;
  width: 0%;
}

.upload-progress .progress-text {
  font-size: 13px;
  color: var(--gray-600);
}

.upload-preview {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--success-light);
  border: 2px solid var(--success);
  border-radius: var(--radius);
}

.upload-preview.active {
  display: flex;
}

.upload-preview .preview-icon {
  font-size: 36px;
}

.upload-preview .preview-filename {
  font-size: 14px;
  font-weight: 500;
  color: var(--gray-800);
  word-break: break-all;
}

.upload-preview .preview-url {
  font-size: 12px;
  color: var(--gray-600);
  word-break: break-all;
  max-width: 100%;
  padding: 8px 12px;
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
}

.upload-preview .btn-remove-upload {
  padding: 6px 12px;
  font-size: 12px;
  background: var(--white);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  color: var(--gray-600);
  cursor: pointer;
  transition: all 0.2s;
}

.upload-preview .btn-remove-upload:hover {
  background: var(--danger-light);
  border-color: var(--danger);
  color: var(--danger);
}

/* ============ TEMPLATE NAME ROW (with copy button) ============ */
.template-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.template-name-row .template-name {
  margin-bottom: 0;
}

.btn-copy-url {
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 500;
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid var(--primary);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.btn-copy-url:hover {
  background: var(--primary);
  color: var(--white);
}

.btn-copy-url .copy-icon {
  font-size: 12px;
}

/* ============ TEMPLATE HAS MEDIA INDICATOR ============ */
.template-has-media {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: var(--primary-light);
  border-radius: 4px;
  font-size: 11px;
  color: var(--primary);
  font-weight: 500;
}

.template-has-media .media-icon {
  font-size: 12px;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-right {
    flex-wrap: wrap;
  }

  .filter-group {
    width: 100%;
  }

  .filter-select {
    flex: 1;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .modal-content {
    max-height: 100vh;
    border-radius: 0;
  }
}
