/* ===================================================================
   MARKETING AUTOMATION - COMPLETE STYLESHEET
   Updated to match index page (front_md.css) styling
   =================================================================== */

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

:root {
  /* Match front_md.css variables */
  --px-purple: #7B38C2;
  --px-ink: #0f1220;
  --px-ink-2: #171a2b;
  --px-border: #e9e9ef;
  --px-muted: #6b7280;
  --px-bg: #fafbfe;
  
  --radius: 18px;
  --shadow: 0 8px 28px rgba(15,18,32,.08);
  
  /* Keep existing variables for compatibility */
  --purple-primary: #7B38C2;
  --purple-dark: #5a2891;
  --purple-light: #f3f0f9;
  --purple-border: #d4c5e8;
  
  --gray-900: #2b2f42;
  --gray-700: #3b4153;
  --gray-600: #6b7280;
  --gray-400: #9ca3af;
  --gray-200: #e5e7eb;
  --gray-100: #f3f4f6;
  --gray-50: #f8f9fc;
  
  --white: #ffffff;
  --success: #10b981;
  --error: #ef4444;
  --warning: #f59e0b;
  
  --font-family: 'Poppins', -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
  font-family: var(--font-family);
  background: var(--px-bg);
  color: var(--gray-900);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===================================================================
   HEADER (Matching front_md.css style)
   =================================================================== */

.header {
  background: var(--white);
  padding: 14px 40px 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1330px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.topline {
  max-width: 1330px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  margin-top: 6px;
  padding-bottom: 8px;
}

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

.logo-img {
  height: 52px;
  width: auto;
  display: block;
}

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

.title {
  font-weight: 800;
  font-size: 18px;
  color: #2b2f42;
}

.subtitle {
  color: #636a7a;
  font-weight: 500;
  font-size: 13px;
}

/* Purple gradient divider line (from front_md.css) */
.divider {
  height: 3px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--px-purple), #b08be4 70%, #d6c7f2);
  opacity: 0.85;
  max-width: 1330px;
  margin: 0 auto;
}

/* ===================================================================
   STATS BAR (Dark ink style from front_md.css)
   =================================================================== */

.stats {
  max-width: 1330px;
  margin: 14px auto;
  background: var(--px-ink);
  color: #fff;
  border-radius: 14px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.stat {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 160px;
}

.stat b {
  font-size: 18px;
}

/* Badge styling (matching front_md.css) */
.badge {
  background: rgba(123, 56, 194, 0.14);
  color: #2b2f42;
  border: 1px solid rgba(123, 56, 194, 0.25);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  user-select: none;
  font-weight: 600;
}

/* Badge inside dark stats bar */
.stats .badge {
  color: #fff !important;
  background: rgba(255, 255, 255, 0.15) !important;
  border-color: rgba(255, 255, 255, 0.3) !important;
}

/* Page header container */
.page-header {
  max-width: 1330px;
  margin: 0 auto;
  padding: 0 40px;
}

/* ===================================================================
   BUTTONS
   =================================================================== */

.btn-primary,
.btn-primary-alt,
.btn-secondary,
.btn-icon {
  font-family: var(--font-family);
  font-weight: 700;
  font-size: 14px;
  padding: 12px 24px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  line-height: 1;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--purple-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(123, 56, 194, 0.3);
}

.btn-primary:disabled {
  background: var(--gray-200);
  color: var(--gray-400);
  cursor: not-allowed;
}

.btn-primary-alt {
  background: linear-gradient(135deg, #7B38C2 0%, #5a2891 100%);
  color: var(--white);
  box-shadow: 0 4px 12px rgba(123, 56, 194, 0.2);
}

.btn-primary-alt:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(123, 56, 194, 0.3);
}

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

.btn-secondary:hover {
  border-color: var(--purple-primary);
  color: var(--purple-primary);
}

.btn-icon {
  background: var(--purple-light);
  color: var(--purple-primary);
  border: 1px solid var(--purple-border);
}

.icon-btn{
  position:absolute;
  right:10px;
  top:50%;
  transform:translateY(-50%);
  border:none;
  background:transparent;
  cursor:pointer;
  font-size:16px;
  opacity:.85;
}

/* ===================================================================
   PAGE HEADER
   =================================================================== */

.page-header {
  max-width: 1400px;
  margin: 40px auto 30px;
  padding: 0 40px;
  text-align: center;
}

.page-title {
  font-size: 32px;
  font-weight: 900;
  color: var(--gray-900);
  margin-bottom: 8px;
}

.page-subtitle {
  font-size: 16px;
  font-weight: 600;
  color: var(--gray-600);
}

/* ===================================================================
   MAIN CONTENT - TWO COLUMN LAYOUT
   =================================================================== */

.main-content {
  max-width: 1400px;
  margin: 0 auto 60px;
  padding: 0 40px;
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 24px;
  align-items: start;
}

.section-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

/* ===================================================================
   SECTION HEADERS
   =================================================================== */

.section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.section-number {
  background: var(--purple-primary);
  color: var(--white);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 14px;
}

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

/* ===================================================================
   DISEASE SEARCH
   =================================================================== */

.search-box {
  position: relative;
  margin-bottom: 16px;
}

.search-input {
  width: 100%;
  padding: 12px 44px 12px 16px;
  font-family: var(--font-family);
  font-size: 14px;
  font-weight: 600;
  border: 2px solid var(--gray-200);
  border-radius: 8px;
  outline: none;
  transition: all 0.2s ease;
}

.search-input:focus {
  border-color: var(--purple-primary);
  box-shadow: 0 0 0 3px rgba(123, 56, 194, 0.1);
}

.search-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--gray-400);
  cursor: pointer;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease;
}

.search-btn:hover {
  color: var(--purple-primary);
}

/* ===================================================================
   DISEASE RESULTS (Supports both .disease-item and .result-item from PHP)
   =================================================================== */

.disease-results {
  max-height: 400px;
  overflow-y: auto;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  background: var(--gray-50);
}

.results-hint {
  padding: 40px 20px;
  text-align: center;
  color: var(--gray-400);
  font-size: 14px;
  font-weight: 600;
}

/* Support both class naming conventions */
.disease-item,
.result-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--gray-200);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.disease-item:last-child,
.result-item:last-child {
  border-bottom: none;
}

.disease-item:hover,
.result-item:hover {
  background: var(--white);
}

.disease-item.selected,
.result-item.selected {
  background: var(--purple-light);
  border-left: 3px solid var(--purple-primary);
}

.disease-code,
.result-code {
  font-size: 13px;
  font-weight: 900;
  color: var(--purple-primary);
  min-width: 50px;
}

.disease-info,
.result-body {
  flex: 1;
}

.disease-name,
.result-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--gray-900);
  line-height: 1.4;
  margin-bottom: 4px;
}

.disease-desc,
.result-meta {
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-600);
  line-height: 1.4;
}

/* Muted class for messages */
.muted {
  padding: 40px 20px;
  text-align: center;
  color: var(--gray-400);
  font-size: 14px;
  font-weight: 600;
}

/* ===================================================================
   MATERIALS GRID
   =================================================================== */

.materials-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
}

.material-option {
  cursor: pointer;
  display: block;
}

.material-option input[type="checkbox"] {
  display: none;
}

.material-content {
  border: 2px solid var(--gray-200);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  transition: all 0.2s ease;
  background: var(--white);
}

.material-option:hover .material-content {
  border-color: var(--purple-primary);
  background: var(--purple-light);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(123, 56, 194, 0.1);
}

.material-option input:checked + .material-content {
  border-color: var(--purple-primary);
  background: var(--purple-light);
  box-shadow: 0 0 0 3px rgba(123, 56, 194, 0.1);
}

.material-icon {
  font-size: 24px;
  line-height: 1;
}

.material-text {
  flex: 1;
}

.material-name {
  font-size: 13px;
  font-weight: 900;
  color: var(--gray-900);
  margin-bottom: 4px;
  line-height: 1.3;
}

.material-desc {
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-600);
  line-height: 1.3;
}

/* ===================================================================
   RECIPIENT FORM
   =================================================================== */

.recipient-form {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 24px;
}

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

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

.form-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--gray-700);
}

.form-input {
  padding: 10px 14px;
  font-family: var(--font-family);
  font-size: 14px;
  font-weight: 600;
  border: 2px solid var(--gray-200);
  border-radius: 8px;
  outline: none;
  transition: all 0.2s ease;
}

.form-input:focus {
  border-color: var(--purple-primary);
  box-shadow: 0 0 0 3px rgba(123, 56, 194, 0.1);
}

/* ===================================================================
   ACTION BUTTONS
   =================================================================== */

.action-buttons {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.action-buttons button {
  flex: 1;
  justify-content: center;
  min-width: 200px;
}

/* ===================================================================
   STATUS MESSAGES
   =================================================================== */

.status-message {
  margin-top: 16px;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.5;
}

.status-message.success {
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #10b981;
}

.status-message.error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #ef4444;
}

.status-message.info {
  background: #dbeafe;
  color: #1e40af;
  border: 1px solid #3b82f6;
}

/* ===================================================================
   LOADING OVERLAY
   =================================================================== */

.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading-spinner {
  background: var(--white);
  border-radius: 16px;
  padding: 40px 60px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--gray-200);
  border-top-color: var(--purple-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

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

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

/* ===================================================================
   SCROLLBAR STYLING
   =================================================================== */

.disease-results::-webkit-scrollbar {
  width: 8px;
}

.disease-results::-webkit-scrollbar-track {
  background: var(--gray-100);
  border-radius: 4px;
}

.disease-results::-webkit-scrollbar-thumb {
  background: var(--gray-400);
  border-radius: 4px;
}

.disease-results::-webkit-scrollbar-thumb:hover {
  background: var(--purple-primary);
}

/* ===================================================================
   MODALS
   =================================================================== */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.modal-content {
  background: var(--white);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 700px;
}

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

.modal-xlarge {
  max-width: 1200px;
}

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

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

.modal-close {
  background: none;
  border: none;
  font-size: 32px;
  color: var(--gray-400);
  cursor: pointer;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: all 0.2s ease;
  line-height: 1;
  padding: 0;
}

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

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

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

/* Email Editor Specific */
.email-meta {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 20px;
}

.email-meta-row {
  display: flex;
  gap: 12px;
  font-size: 14px;
}

.email-meta-label {
  font-weight: 700;
  color: var(--gray-700);
  min-width: 40px;
}

.email-meta-value {
  color: var(--gray-900);
  font-weight: 600;
}

.email-editor,
.linkedin-editor {
  width: 100%;
  padding: 14px 16px;
  font-family: var(--font-family);
  font-size: 14px;
  font-weight: 500;
  border: 2px solid var(--gray-200);
  border-radius: 8px;
  outline: none;
  transition: all 0.2s ease;
  resize: vertical;
  line-height: 1.6;
}

.email-editor:focus,
.linkedin-editor:focus {
  border-color: var(--purple-primary);
  box-shadow: 0 0 0 3px rgba(123, 56, 194, 0.1);
}

.email-stats {
  display: flex;
  gap: 20px;
  margin-top: 12px;
  padding: 12px 16px;
  background: var(--gray-50);
  border-radius: 8px;
}

.email-stat {
  display: flex;
  gap: 6px;
  font-size: 12px;
}

.email-stat-label {
  font-weight: 700;
  color: var(--gray-600);
}

.email-stat span:last-child {
  font-weight: 900;
  color: var(--purple-primary);
}

/* LinkedIn Preview */
.linkedin-preview {
  margin-top: 20px;
  padding: 20px;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  color: var(--gray-900);
}

/* LinkedIn Images Grid */
.linkedin-images-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
}

.linkedin-image-option {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.linkedin-image-preview {
  border: 2px solid var(--gray-200);
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 1200/628;
  background: var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: center;
}

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

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

/* ===================================================================
   RESPONSIVE
   =================================================================== */

@media (max-width: 1200px) {
  .main-content {
    grid-template-columns: 1fr;
  }
  
  .section-disease {
    max-width: 600px;
  }
}

@media (max-width: 768px) {
  .materials-grid {
    grid-template-columns: 1fr;
  }
  
  .form-grid {
    grid-template-columns: 1fr;
  }
  
  .header {
    padding: 12px 20px;
  }
  
  .page-header,
  .main-content {
    padding: 0 20px;
  }
}