/* ═══════════════════════════════════════════════════════
   MELISSOPAL CRM – Stylesheet
   Labor Susanne Böhrs
═══════════════════════════════════════════════════════ */

:root {
  --primary:     #2e7d32;
  --primary-light: #4caf50;
  --primary-dark:  #1b5e20;
  --secondary:   #f5f5f5;
  --accent:      #ff8f00;
  --n8n-color:   #ea4b71;
  --bg:          #f0f4f0;
  --card-bg:     #ffffff;
  --text:        #212121;
  --text-light:  #757575;
  --border:      #e0e0e0;
  --shadow:      0 2px 8px rgba(0,0,0,0.10);
  --radius:      10px;
  --header-h:    70px;
  --nav-h:       50px;
}

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

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* ── HEADER ── */
.crm-header {
  height: var(--header-h);
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-left { display: flex; align-items: center; gap: 12px; }
.header-left .logo { font-size: 32px; }
.header-left .logo-img, .logo-img { height: 40px; width: auto; display: block; }
.login-logo-img { height: 64px; width: auto; margin: 0 auto 8px auto; display: block; }

/* ── Reiter (Tabs) im Analyse-Modal und in den Einstellungen ── */
.modal-tabs .tab-btn,
.settings-tabs .settings-tab {
  color: var(--text-light);
  transition: all 0.15s ease;
}
.modal-tabs .tab-btn:hover,
.settings-tabs .settings-tab:hover {
  background: rgba(46,125,50,0.08) !important;
  color: var(--primary-dark);
}
.modal-tabs .tab-btn.active,
.settings-tabs .settings-tab.active {
  background: var(--card-bg) !important;
  color: var(--primary-dark) !important;
  border: 1px solid var(--border) !important;
  border-bottom: 2px solid var(--card-bg) !important;
  box-shadow: 0 -2px 4px rgba(0,0,0,0.04);
  position: relative;
  top: 1px;
}
.header-left h1 { font-size: 20px; font-weight: 700; }
.header-left p { font-size: 12px; opacity: 0.85; }
.header-right { display: flex; align-items: center; gap: 12px; }

/* ── NAV ── */
.crm-nav {
  height: var(--nav-h);
  background: var(--primary-dark);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 4px;
  overflow-x: auto;
  position: sticky;
  top: var(--header-h);
  z-index: 99;
}
.nav-btn {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.75);
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
  transition: all 0.2s;
}
.nav-btn:hover { background: rgba(255,255,255,0.1); color: white; }
.nav-btn.active { background: var(--primary-light); color: white; font-weight: 600; }

/* ── MAIN ── */
.crm-main {
  padding: 24px;
  min-height: calc(100vh - var(--header-h) - var(--nav-h));
}

/* ── TABS ── */
.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn 0.25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ── CARDS ── */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  margin-bottom: 16px;
}
.card h3 { margin-bottom: 14px; color: var(--primary-dark); font-size: 15px; }

/* ── KPI ── */
.kpi-grid {
  display: grid;
  grid-template-columns: 320px 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}
.kpi-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  box-shadow: var(--shadow);
  border-top: 4px solid var(--primary);
}
.kpi-icon { font-size: 28px; margin-bottom: 8px; }
.kpi-value { font-size: 28px; font-weight: 700; color: var(--primary-dark); }
.kpi-label { font-size: 12px; color: var(--text-light); margin-top: 4px; }

/* ── GRIDS ── */
.dashboard-grid {
  display: grid;
  grid-template-columns: 320px 1fr 1fr;
  gap: 16px;
}
/* Freigaben-Tab: breiteres Feld für "Neue Kunden Registrierungen",
   ohne die 320px-Spalte des Dashboard-Grids (Schnellaktionen) zu verändern */
.freigaben-grid {
  grid-template-columns: 1fr 1fr;
}
.kpi-group-double {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.berichte-grid, .n8n-grid, .db-info {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 16px;
}

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s;
  text-decoration: none;
}
.btn:hover { opacity: 0.88; transform: translateY(-1px); }
.btn:active { transform: none; }
.btn-primary { background: var(--primary); color: white; }
.btn-secondary { background: #e0e0e0; color: var(--text); }
.btn-settings { background: rgba(255,255,255,0.15); color: white; border: 1px solid rgba(255,255,255,0.3); }
.btn-n8n { background: var(--n8n-color); color: white; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-danger { background: #c62828; color: white; }
.mt-1 { margin-top: 10px; }

.quick-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.quick-actions .btn { width: 100%; text-align: left; }

.quick-actions-card { max-width: 320px; position: relative; }
.quick-actions-edit-btn {
  position: absolute; top: 14px; right: 16px;
  background: none; border: 1px solid var(--border); border-radius: 6px;
  padding: 4px 8px; cursor: pointer; font-size: 13px; color: var(--text-light);
}
.quick-actions-edit-btn:hover { background: rgba(0,0,0,0.04); color: var(--primary-dark); }

.qa-picker-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 6px; margin-bottom: 6px;
  background: #fff; cursor: grab;
}
.qa-picker-item.dragging { opacity: 0.4; }
.qa-picker-item .qa-handle { cursor: grab; color: var(--text-light); font-size: 16px; }
.qa-picker-item label { display: flex; align-items: center; gap: 8px; flex: 1; cursor: pointer; font-weight: normal; }

/* ── BADGES ── */
.badge {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  background: #bdbdbd;
  color: white;
}
.badge-ok { background: #388e3c; }
.badge-warn { background: var(--accent); }
.badge-error { background: #c62828; }
.badge-info { background: #1565c0; }

/* ── TABLES ── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card-bg);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.data-table th {
  background: var(--primary-dark);
  color: white;
  padding: 11px 12px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:hover td { background: #f1f8f1; }
.data-table tr:last-child td { border-bottom: none; }
.empty { color: var(--text-light); font-style: italic; text-align: center; padding: 24px !important; }

.mini-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.mini-table th { background: var(--secondary); padding: 8px; text-align: left; font-size: 12px; color: var(--text-light); }
.mini-table td { padding: 7px 8px; border-bottom: 1px solid var(--border); }

/* ── FORMS ── */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; margin-bottom: 5px; font-weight: 500; font-size: 13px; color: var(--text); }
.form-control {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  transition: border-color 0.2s;
  background: white;
}
.form-control:focus { outline: none; border-color: var(--primary-light); box-shadow: 0 0 0 3px rgba(76,175,80,0.15); }
textarea.form-control { resize: vertical; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

/* ── SECTION HEADER ── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}
.section-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.search-input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  min-width: 200px;
}
.filter-select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: white;
}
.filter-row { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }

/* ── STATUS ── */
.status-grid { display: flex; flex-direction: column; gap: 10px; }
.status-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }

/* ── PFADE ── */
.pfad-liste { display: flex; flex-direction: column; gap: 10px; }
.pfad-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px;
  background: var(--secondary);
  border-radius: 6px;
}
.pfad-icon { font-size: 20px; margin-top: 2px; }
.pfad-item code {
  display: block;
  font-size: 12px;
  color: var(--primary-dark);
  background: #e8f5e9;
  padding: 2px 6px;
  border-radius: 4px;
  margin-top: 2px;
}

/* ── MODALS ── */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}
.modal.open { display: flex; }
.modal-content {
  background: white;
  border-radius: var(--radius);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
  width: 90%;
  max-width: 600px;
}
.modal-lg { max-width: 820px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--primary-dark);
  color: white;
  border-radius: var(--radius) var(--radius) 0 0;
}
.modal-header h3 { color: white; font-size: 16px; }
.close-btn { background: transparent; border: none; color: white; font-size: 20px; cursor: pointer; padding: 0 4px; }
.modal-body { padding: 22px; }
.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: var(--secondary);
  border-radius: 0 0 var(--radius) var(--radius);
}

/* ── SETTINGS TABS ── */
.settings-tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 2px solid var(--border); padding-bottom: 0; }
.settings-tab {
  padding: 8px 16px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-light);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
}
.settings-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.settings-panel { display: none; }
.settings-panel.active { display: block; animation: fadeIn 0.2s; }

/* ── N8N ── */
.workflow-liste { display: flex; flex-direction: column; gap: 12px; }
.workflow-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  background: var(--secondary);
  border-radius: 8px;
  gap: 12px;
}
.workflow-item p { font-size: 12px; color: var(--text-light); margin-top: 3px; }
.workflow-controls { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.webhook-liste { display: flex; flex-direction: column; gap: 12px; }
.webhook-item { padding: 10px; background: var(--secondary); border-radius: 6px; }
.webhook-item label { font-weight: 600; font-size: 12px; display: block; margin-bottom: 5px; }
.webhook-url { display: flex; gap: 6px; align-items: center; }
.webhook-url code { font-size: 12px; flex: 1; background: #e8f5e9; padding: 4px 8px; border-radius: 4px; word-break: break-all; }

/* ── POLLEN ── */
.pollen-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.pollen-art { flex: 2; }
.pollen-prozent { flex: 1; max-width: 80px; }

/* ── TABELLEN STATS ── */
.tabellen-stats { display: flex; flex-direction: column; gap: 10px; }
.tabelle-item { display: flex; justify-content: space-between; padding: 8px 12px; background: var(--secondary); border-radius: 6px; font-size: 13px; }

/* ── INFO BOX ── */
.info-box {
  background: #e3f2fd;
  border-left: 4px solid #1565c0;
  padding: 12px 14px;
  border-radius: 4px;
  margin: 14px 0;
  font-size: 13px;
  line-height: 1.6;
}

/* ── CODE EDITOR ── */
.code-editor { font-family: 'Consolas', monospace; font-size: 13px; background: #1e1e1e; color: #d4d4d4; border-color: #333; }
.query-result { margin-top: 10px; background: #1e1e1e; color: #4ec9b0; padding: 12px; border-radius: 6px; font-family: monospace; font-size: 12px; min-height: 60px; white-space: pre-wrap; }

/* ── ANHAENGE ── */
.anhaenge-box { border: 1px dashed var(--border); border-radius: 6px; padding: 10px; min-height: 50px; }

/* ── TOAST ── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #323232;
  color: white;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  transform: translateY(80px);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 9999;
  max-width: 380px;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { border-left: 4px solid #4caf50; }
.toast.error { border-left: 4px solid #f44336; }
.toast.info { border-left: 4px solid #2196f3; }

/* ── INFO TABLE ── */
.info-table { width: 100%; font-size: 13px; }
.info-table td { padding: 7px 8px; border-bottom: 1px solid var(--border); }
.info-table td:first-child { font-weight: 600; color: var(--text-light); width: 140px; }
.info-table code { background: #e8f5e9; padding: 2px 6px; border-radius: 4px; font-size: 12px; color: var(--primary-dark); }

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--secondary); }
::-webkit-scrollbar-thumb { background: #bdbdbd; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9e9e9e; }

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  .crm-main { padding: 12px; }
  .dashboard-grid, .berichte-grid, .n8n-grid, .kpi-grid { grid-template-columns: 1fr; }
  .kpi-group-double { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .section-header { flex-direction: column; align-items: flex-start; }
}

/* ── ANALYSE MODAL GRID & LAYOUT ── */
.modal-xl { max-width: 1100px; width: 90%; }
.analyse-layout-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 24px;
}
.analyse-col-form {
  border-right: 1px solid var(--border);
  padding-right: 24px;
}
.analyse-col-suggestions {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 70vh;
  overflow-y: auto;
  padding-right: 8px;
}
.suggestions-header h4 {
  margin-top: 0;
  margin-bottom: 12px;
  color: var(--primary-dark);
  font-weight: 600;
  font-size: 15px;
  border-bottom: 2px solid var(--primary);
  padding-bottom: 6px;
}
.suggestion-section {
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.suggestion-section h5 {
  margin-top: 0;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dark);
}
.spinner-container {
  font-size: 13px;
  color: var(--text-light);
  margin: 10px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #ccc;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Template Kacheln */
.templates-list-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}
.no-templates-text {
  font-size: 12px;
  color: var(--text-light);
  font-style: italic;
  text-align: center;
  padding: 10px 0;
}
.template-tile {
  background: white;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  transition: all 0.2s ease;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-dark);
  cursor: pointer;
}
.template-tile:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 6px rgba(0,0,0,0.05);
  background: #fffdf5;
}
.template-tile-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  border-bottom: 1px dashed var(--border);
  padding-bottom: 4px;
}
.template-tile-code {
  font-family: monospace;
  font-weight: bold;
  color: var(--primary-dark);
}
.template-tile-meta {
  font-size: 10px;
  color: var(--text-light);
  background: var(--secondary);
  padding: 2px 6px;
  border-radius: 10px;
}
.template-tile-body {
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  max-height: 4.5em;
}
.template-tile-btn {
  width: 100%;
  text-align: center;
  padding: 4px;
  font-size: 11px;
}

@media (max-width: 992px) {
  .analyse-layout-grid {
    grid-template-columns: 1fr;
  }
  .analyse-col-form {
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding-right: 0;
    padding-bottom: 24px;
  }
}

