/**
 * webhook-modals.css
 *
 * Styling for Webhook modals (Create, Edit, Test, Logs)
 * Pattern: ShareEmbedModal.ts styling (fixed overlay + modal)
 */

/* ========================================
   Modal Overlay & Container
   ======================================== */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  z-index: 100000; /* Same as ProfileModal to stay on top */
  animation: fadeIn 0.2s ease;
  display: none; /* Hidden by default */
}

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

.webhook-create-modal,
.webhook-edit-modal,
.webhook-test-modal,
.webhook-logs-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: white;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  z-index: 100001; /* Higher than ProfileModal (100000) */
  max-width: 700px; /* Increased from 600px for better content fit */
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.3s ease;
}

.webhook-logs-modal {
  max-width: 900px;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translate(-50%, -45%);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%);
  }
}

/* ========================================
   Modal Header
   ======================================== */

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem 2rem;
  border-bottom: 1px solid #e2e8f0;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.5rem;
  color: #1e293b;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #64748b;
  transition: color 0.2s ease;
  padding: 0.5rem;
  line-height: 1;
}

.modal-close:hover {
  color: #1e293b;
}

/* ========================================
   Modal Body
   ======================================== */

.modal-body {
  padding: 2rem;
}

/* ========================================
   Form Groups
   ======================================== */

.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: #1e293b;
  font-size: 0.875rem;
}

.required {
  color: #ef4444;
}

.form-group input[type="text"],
.form-group input[type="url"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 0.875rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-group textarea {
  resize: vertical;
  font-family: inherit;
}

.form-hint {
  display: block;
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: #64748b;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.form-hint.warning {
  color: #ea580c;
  font-weight: 500;
}

/* Info and Success Boxes */
.info-box,
.success-box {
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1.5rem;
}

.success-box {
  background: #f0fdf4;
  border-color: #86efac;
}

.info-box p,
.success-box p {
  margin: 0.5rem 0;
}

.info-box ol,
.info-box ul {
  margin: 0.5rem 0;
  padding-left: 1.5rem;
}

.info-box li {
  margin: 0.25rem 0;
}

/* Copy Input Group */
.copy-input-group {
  display: flex;
  gap: 0.5rem;
}

.copy-input-group input {
  flex: 1;
  min-width: 0; /* Allow input to shrink below content size */
  word-break: break-all;
}

/* ========================================
   Secret Input Wrapper
   ======================================== */

.secret-input-wrapper {
  display: flex;
  gap: 0.5rem;
}

.secret-input-wrapper input {
  flex: 1;
}

.secret-input-wrapper .btn-icon {
  flex-shrink: 0;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 0.75rem;
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.2s ease;
}

.secret-input-wrapper .btn-icon:hover {
  background: #e2e8f0;
  border-color: #cbd5e1;
}

/* ========================================
   Event Types Checkboxes
   ======================================== */

.event-types-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 1rem;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.checkbox-label:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}

.checkbox-label input[type="checkbox"] {
  margin-top: 0.25rem;
  cursor: pointer;
}

.checkbox-icon {
  font-size: 1.5rem;
}

.checkbox-text {
  flex: 1;
}

.checkbox-text strong {
  display: block;
  color: #1e293b;
  margin-bottom: 0.25rem;
}

.checkbox-text small {
  color: #64748b;
}

/* ========================================
   Advanced Settings
   ======================================== */

.advanced-settings {
  margin-top: 2rem;
  padding: 1rem;
  background: #f8fafc;
  border-radius: 6px;
}

.advanced-settings summary {
  font-weight: 600;
  color: #475569;
  cursor: pointer;
  user-select: none;
  margin-bottom: 1rem;
}

.advanced-settings summary:hover {
  color: #1e293b;
}

.advanced-settings[open] summary {
  margin-bottom: 1.5rem;
}

/* ========================================
   Modal Actions (Buttons)
   ======================================== */

.modal-actions {
  display: flex;
  gap: 1rem;
  justify-content: flex-end;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid #e2e8f0;
}

.btn {
  padding: 0.75rem 1.5rem;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
}

.btn-secondary {
  background: #f8fafc;
  color: #475569;
  border: 1px solid #e2e8f0;
}

.btn-secondary:hover {
  background: #e2e8f0;
  border-color: #cbd5e1;
}

.btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.btn-primary:active {
  transform: translateY(0);
}

/* ========================================
   Test Response Display
   ======================================== */

.test-response {
  margin-top: 1.5rem;
  padding: 1.5rem;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
}

.response-loading,
.response-success,
.response-error {
  text-align: center;
}

.response-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.response-loading .spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #e2e8f0;
  border-top-color: #667eea;
  border-radius: 50%;
  margin: 0 auto 1rem;
  animation: spin 1s linear infinite;
}

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

.response-success {
  background: #dcfce7;
  border-color: #22c55e;
}

.response-success h4 {
  color: #15803d;
  margin-bottom: 0.5rem;
}

.response-success p {
  color: #166534;
  margin: 0.25rem 0;
}

.response-success code {
  background: rgba(255, 255, 255, 0.5);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.875rem;
}

.response-error {
  background: #fee2e2;
  border-color: #ef4444;
}

.response-error h4 {
  color: #dc2626;
  margin-bottom: 0.5rem;
}

.response-error p {
  color: #991b1b;
  margin: 0.25rem 0;
}

.response-error code {
  background: rgba(255, 255, 255, 0.5);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.875rem;
}

.test-response small {
  display: block;
  margin-top: 0.75rem;
  font-size: 0.875rem;
  opacity: 0.8;
}

/* Webhook Info Header */
.webhook-info {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid #e2e8f0;
}

.webhook-info h3 {
  margin: 0 0 0.5rem 0;
  font-size: 1.25rem;
  color: #1e293b;
}

.webhook-url {
  color: #667eea;
  font-size: 0.875rem;
  word-break: break-all;
}

/* ========================================
   Logs Controls
   ======================================== */

.logs-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: #f8fafc;
  border-radius: 6px;
  gap: 1rem;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.filter-group label {
  font-weight: 600;
  font-size: 0.875rem;
  color: #475569;
}

.filter-group select {
  padding: 0.5rem;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  font-size: 0.875rem;
}

.refresh-group {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.btn-small {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
}

.auto-refresh-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: #64748b;
  cursor: pointer;
  user-select: none;
}

.auto-refresh-toggle input[type="checkbox"] {
  cursor: pointer;
}

/* ========================================
   Webhook Logs Table
   ======================================== */

.logs-table-wrapper {
  max-height: 400px;
  overflow-y: auto;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  margin-top: 1rem;
}

.logs-table {
  width: 100%;
  border-collapse: collapse;
}

.logs-table thead {
  background: #f8fafc;
  position: sticky;
  top: 0;
  z-index: 1;
}

.logs-table th {
  padding: 0.75rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.75rem;
  color: #475569;
  border-bottom: 1px solid #e2e8f0;
}

.logs-table td {
  padding: 0.75rem;
  font-size: 0.75rem;
  border-bottom: 1px solid #e2e8f0;
}

.logs-table tbody tr:hover {
  background: #f8fafc;
}

.log-status {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.7rem;
}

.log-status-success {
  background: #dcfce7;
  color: #15803d;
}

.log-status-failed {
  background: #fee2e2;
  color: #dc2626;
}

.log-status-retrying {
  background: #fef3c7;
  color: #ca8a04;
}

.log-status-pending {
  background: #e0e7ff;
  color: #4338ca;
}

/* ========================================
   Pagination
   ======================================== */

.logs-pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1rem;
}

.pagination-info {
  font-size: 0.875rem;
  color: #64748b;
}

.pagination-controls {
  display: flex;
  gap: 0.5rem;
}

.pagination-controls button {
  padding: 0.5rem 1rem;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.875rem;
  transition: all 0.2s ease;
}

.pagination-controls button:hover:not(:disabled) {
  background: #f8fafc;
  border-color: #cbd5e1;
}

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

/* ========================================
   Responsive Design
   ======================================== */

@media (max-width: 640px) {
  .webhook-create-modal,
  .webhook-edit-modal,
  .webhook-test-modal,
  .webhook-logs-modal {
    width: 95%;
    max-height: 95vh;
  }

  .modal-body {
    padding: 1.5rem;
  }

  .modal-header {
    padding: 1rem 1.5rem;
  }

  .modal-actions {
    flex-direction: column;
  }

  .modal-actions .btn {
    width: 100%;
  }

  .secret-input-wrapper {
    flex-wrap: wrap;
  }

  .secret-input-wrapper input {
    width: 100%;
  }

  .secret-input-wrapper .btn-icon {
    flex: 1;
  }
}

/* ========================================
   Dark Mode Support (Optional)
   ======================================== */

@media (prefers-color-scheme: dark) {
  .webhook-create-modal,
  .webhook-edit-modal,
  .webhook-test-modal,
  .webhook-logs-modal {
    background: #1e293b;
  }

  .modal-header {
    border-color: #334155;
  }

  .modal-header h2 {
    color: #e2e8f0;
  }

  .modal-close {
    color: #cbd5e1;
  }

  .modal-close:hover {
    color: #e2e8f0;
  }

  .form-group label {
    color: #e2e8f0;
  }

  .form-group input,
  .form-group textarea,
  .form-group select {
    background: #0f172a;
    border-color: #334155;
    color: #e2e8f0;
  }

  .form-hint {
    color: #94a3b8;
  }

  .checkbox-label {
    border-color: #334155;
  }

  .checkbox-label:hover {
    background: #0f172a;
  }

  .checkbox-text strong {
    color: #e2e8f0;
  }

  .checkbox-text small {
    color: #94a3b8;
  }

  .advanced-settings {
    background: #0f172a;
    border-color: #334155;
  }

  .modal-actions {
    border-color: #334155;
  }

  .btn-secondary {
    background: #0f172a;
    color: #cbd5e1;
    border-color: #334155;
  }

  .btn-secondary:hover {
    background: #334155;
  }
}
