  :root {
    --bg: #0f1117; --surface: #1a1d27; --border: #2a2d3a;
    --text: #e4e4e7; --muted: #71717a; --accent: #6366f1;
    --accent-hover: #818cf8; --green: #22c55e; --red: #ef4444;
    --yellow: #eab308; --blue: #3b82f6;
  }
  * { box-sizing: border-box; margin: 0; padding: 0; }
  body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg); color: var(--text); min-height: 100vh; }

  .container { max-width: 1200px; margin: 0 auto; padding: 20px; }

  header { display: flex; justify-content: space-between; align-items: center;
    padding: 16px 0; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
  header h1 { font-size: 1.4em; }
  header h1 span { color: var(--accent); }

  .tabs { display: flex; gap: 4px; margin-bottom: 20px; }
  .tab { padding: 8px 20px; border: 1px solid var(--border); background: var(--surface);
    color: var(--muted); cursor: pointer; border-radius: 6px 6px 0 0; font-size: 0.9em; }
  .tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

  .panel { display: none; }
  .panel.active { display: block; }

  /* Search Panel */
  .search-bar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
  .search-bar input, .search-bar select { padding: 10px 14px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); border-radius: 6px; font-size: 0.95em; }
  .search-bar input { flex: 1; min-width: 200px; }
  .search-bar select { min-width: 120px; }
  button { padding: 10px 20px; border: none; background: var(--accent); color: #fff;
    border-radius: 6px; cursor: pointer; font-size: 0.95em; font-weight: 500; }
  button:hover { background: var(--accent-hover); }
  button:disabled { opacity: 0.5; cursor: not-allowed; }
  button.secondary { background: var(--surface); border: 1px solid var(--border); color: var(--text); }
  button.secondary:hover { border-color: var(--accent); }

  .stats { display: flex; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
  .stat { padding: 10px 16px; background: var(--surface); border: 1px solid var(--border);
    border-radius: 6px; font-size: 0.85em; }
  .stat strong { color: var(--accent); font-size: 1.2em; }

  .results { display: flex; flex-direction: column; gap: 10px; }
  .result-card { padding: 16px; background: var(--surface); border: 1px solid var(--border);
    border-radius: 8px; transition: border-color 0.2s; }
  .result-card:hover { border-color: var(--accent); }
  .result-card .title { font-weight: 600; font-size: 1.05em; margin-bottom: 6px; }
  .result-card .title a { color: var(--text); text-decoration: none; }
  .result-card .title a:hover { color: var(--accent); }
  .result-card .meta { display: flex; flex-wrap: wrap; gap: 12px; font-size: 0.85em; color: var(--muted); }
  .result-card .meta span { display: flex; align-items: center; gap: 4px; }
  .tag { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 0.78em;
    font-weight: 500; background: rgba(99,102,241,0.15); color: var(--accent); margin: 2px; }
  .tag.neg { background: rgba(239,68,68,0.15); color: var(--red); }
  .tag.warn { background: rgba(234,179,8,0.15); color: var(--yellow); }
  .tag.match { background: rgba(34,197,94,0.15); color: var(--green); }
  .keywords-row { margin-top: 8px; }

  .frist-ok { color: var(--green); }
  .frist-warn { color: var(--yellow); }
  .frist-urgent { color: var(--red); font-weight: 600; }

  /* Keywords Panel */
  .kw-section { margin-bottom: 24px; }
  .kw-section h3 { margin-bottom: 8px; font-size: 1em; }
  .kw-section p { font-size: 0.85em; color: var(--muted); margin-bottom: 10px; }
  .kw-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
  .kw-item { padding: 4px 10px; background: var(--surface); border: 1px solid var(--border);
    border-radius: 4px; font-size: 0.85em; transition: all 0.15s; display: inline-flex; align-items: center; gap: 6px; }
  .kw-item .kw-remove { cursor: pointer; color: var(--muted); font-size: 1.1em; line-height: 1; }
  .kw-item .kw-remove:hover { color: var(--red); }
  .kw-item.wb { border-color: var(--yellow); }
  .kw-add { display: flex; gap: 6px; }
  .kw-add input { padding: 6px 10px; border: 1px solid var(--border); background: var(--surface);
    color: var(--text); border-radius: 4px; font-size: 0.85em; flex:1; max-width: 300px; }

  .loading { text-align: center; padding: 40px; color: var(--muted); }
  .spinner { display: inline-block; width: 20px; height: 20px; border: 2px solid var(--border);
    border-top-color: var(--accent); border-radius: 50%; animation: spin 0.6s linear infinite; }
  @keyframes spin { to { transform: rotate(360deg); } }

  #toast { position: fixed; bottom: 20px; right: 20px; padding: 12px 20px; background: var(--green);
    color: #000; border-radius: 6px; font-weight: 500; opacity: 0; transition: opacity 0.3s;
    pointer-events: none; z-index: 100; }
  #toast.show { opacity: 1; }

  .card-actions { display: flex; gap: 6px; margin-top: 8px; }
  .card-actions button { padding: 4px 12px; font-size: 0.8em; border-radius: 4px; }
  .btn-star { background: transparent; border: 1px solid var(--yellow); color: var(--yellow); }
  .btn-star:hover { background: rgba(234,179,8,0.15); }
  .btn-star.starred { background: var(--yellow); color: #000; }
  .btn-similar { background: transparent; border: 1px solid var(--blue); color: var(--blue); }
  .btn-similar:hover { background: rgba(59,130,246,0.15); }
  .fav-empty { text-align: center; padding: 40px; color: var(--muted); }
  .fav-badge { background: var(--yellow); color: #000; border-radius: 50%; font-size: 0.7em;
    padding: 1px 6px; margin-left: 4px; font-weight: 700; }

  /* Pipeline */
  .pipeline-cols { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 8px; -webkit-overflow-scrolling: touch; }
  .pipeline-col { flex: 0 0 auto; width: calc((100% - 50px) / 6); min-width: 160px; max-width: 280px; }
  .pipeline-col-header { padding: 8px 12px; border-radius: 6px 6px 0 0; font-weight: 600;
    font-size: 0.85em; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .pipeline-col-body { min-height: 100px; padding: 6px; background: var(--surface);
    border: 1px solid var(--border); border-radius: 0 0 6px 6px; }
  .pipeline-card { padding: 10px; background: var(--bg); border: 1px solid var(--border);
    border-radius: 6px; margin-bottom: 6px; font-size: 0.85em; cursor: pointer; transition: border-color 0.2s; }
  .pipeline-card:hover { border-color: var(--accent); }
  .pipeline-card .p-title { font-weight: 600; margin-bottom: 4px; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis; }
  .pipeline-card .p-meta { color: var(--muted); font-size: 0.8em; }
  .pipeline-card .p-score { float: right; font-weight: 700; font-size: 0.9em; }
  .stage-btns { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
  .stage-btns button { padding: 2px 8px; font-size: 0.75em; border-radius: 3px;
    background: var(--surface); border: 1px solid var(--border); color: var(--text); cursor: pointer; }
  .stage-btns button:hover { border-color: var(--accent); color: var(--accent); }
  .btn-remove { color: var(--red) !important; border-color: var(--red) !important; }

  /* Profil */
  .profil-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
  @media (max-width: 768px) {
    .profil-grid { grid-template-columns: 1fr; }
    .pipeline-cols { flex-direction: column; gap: 8px; overflow-x: visible; }
    .pipeline-col { width: 100%; min-width: unset; max-width: unset; }
    .pipeline-col-body { min-height: auto; }
    .tabs { flex-wrap: wrap; }
    .tab { padding: 6px 12px; font-size: 0.82em; }
  }
  .profil-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 16px; }
  .profil-card h3 { margin-bottom: 12px; font-size: 1em; }
  .profil-field { display: flex; justify-content: space-between; padding: 6px 0;
    border-bottom: 1px solid var(--border); font-size: 0.85em; }
  .profil-field:last-child { border-bottom: none; }
  .profil-field .label { color: var(--muted); min-width: 120px; }
  .profil-field .value { text-align: right; }
  .profil-field .missing { color: var(--red); font-style: italic; }
  .profil-field input { background: var(--bg); border: 1px solid var(--border); color: var(--text);
    padding: 4px 8px; border-radius: 4px; text-align: right; width: 200px; font-size: 0.85em; }
  .warning-box { background: rgba(234,179,8,0.1); border: 1px solid var(--yellow); border-radius: 6px;
    padding: 12px; margin-bottom: 16px; font-size: 0.85em; color: var(--yellow); }
  .dna-section { margin-top: 8px; }
  .dna-accordion { cursor: pointer; padding: 8px; background: var(--bg); border: 1px solid var(--border);
    border-radius: 4px; margin-bottom: 4px; font-size: 0.85em; color: var(--muted); }
  .dna-accordion:hover { border-color: var(--accent); }
  .dna-content { display: none; padding: 8px; font-size: 0.82em; white-space: pre-wrap;
    max-height: 300px; overflow-y: auto; color: var(--muted); }
  .dna-content.open { display: block; }

  /* Detail overlay */
  .detail-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.7);
    z-index: 200; display: none; justify-content: center; align-items: flex-start; padding: 40px 20px; overflow-y:auto; }
  .detail-overlay.open { display: flex; }
  .detail-panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
    padding: 24px; max-width: 700px; width: 100%; max-height: 80vh; overflow-y: auto; }
  .detail-panel h2 { margin-bottom: 12px; font-size: 1.1em; }
  .detail-panel .close-btn { float: right; cursor: pointer; font-size: 1.3em; color: var(--muted); }
  .detail-panel .close-btn:hover { color: var(--text); }
  .match-bar { height: 8px; border-radius: 4px; background: var(--border); margin: 8px 0; }
  .match-bar-fill { height: 100%; border-radius: 4px; transition: width 0.3s; }
  .match-good { background: var(--green); }
  .match-ok { background: var(--yellow); }
  .match-low { background: var(--red); }
  .ref-suggestion { padding: 8px; background: var(--bg); border: 1px solid var(--border);
    border-radius: 4px; margin: 4px 0; font-size: 0.85em; }
  .ref-suggestion .ref-score { color: var(--green); font-weight: 600; float: right; }
  textarea.notes { width: 100%; min-height: 80px; background: var(--bg); border: 1px solid var(--border);
    color: var(--text); border-radius: 6px; padding: 8px; font-size: 0.85em; resize: vertical; }

  /* Platform info box */
  .platform-box { background: rgba(59,130,246,0.1); border: 1px solid var(--blue); border-radius: 8px;
    padding: 14px; margin: 12px 0; }
  .platform-box h4 { margin-bottom: 8px; font-size: 0.95em; color: var(--blue); }
  .platform-box .platform-link { display: inline-block; padding: 8px 16px; background: var(--blue);
    color: #fff; border-radius: 6px; font-weight: 600; text-decoration: none; font-size: 0.9em; margin: 4px 4px 4px 0; }
  .platform-box .platform-link:hover { background: #2563eb; }
  .platform-box .platform-name { font-weight: 600; color: var(--text); font-size: 1.05em; }
  .platform-box .platform-hint { font-size: 0.82em; color: var(--muted); margin-top: 6px; }
  .buyer-info { margin: 8px 0; font-size: 0.85em; }
  .buyer-info .bi-row { display: flex; gap: 8px; padding: 3px 0; }
  .buyer-info .bi-label { color: var(--muted); min-width: 80px; }
  .description-box { background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
    padding: 10px; margin: 8px 0; font-size: 0.82em; color: var(--muted); max-height: 200px;
    overflow-y: auto; white-space: pre-wrap; }
  .value-badge { display: inline-block; padding: 4px 12px; background: rgba(34,197,94,0.15);
    color: var(--green); border-radius: 4px; font-weight: 600; font-size: 0.9em; margin: 4px 0; }
  .detail-loading { text-align: center; padding: 16px; color: var(--muted); font-size: 0.85em; }

  /* Document management */
  .docs-section { margin-top: 16px; }
  .docs-section h4 { font-size: 0.9em; margin-bottom: 8px; }
  .docs-upload-zone { border: 2px dashed var(--border); border-radius: 8px; padding: 20px;
    text-align: center; color: var(--muted); font-size: 0.85em; cursor: pointer; transition: all 0.2s; }
  .docs-upload-zone:hover, .docs-upload-zone.drag-over { border-color: var(--accent); background: rgba(59,130,246,0.05); color: var(--accent); }
  .docs-upload-zone input[type=file] { display: none; }
  .docs-category-select { display: flex; gap: 6px; margin: 8px 0; flex-wrap: wrap; }
  .docs-category-select button { padding: 4px 10px; border: 1px solid var(--border); background: var(--bg);
    color: var(--muted); border-radius: 4px; font-size: 0.8em; cursor: pointer; }
  .docs-category-select button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
  .docs-file-list { margin-top: 8px; }
  .docs-cat-group { margin-bottom: 10px; }
  .docs-cat-label { font-size: 0.8em; color: var(--muted); font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.5px; padding: 4px 0; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
  .docs-file { display: flex; align-items: center; gap: 8px; padding: 5px 8px; font-size: 0.82em;
    border-radius: 4px; }
  .docs-file:hover { background: var(--bg); }
  .docs-file .df-name { flex: 1; color: var(--text); }
  .docs-file .df-size { color: var(--muted); font-size: 0.85em; }
  .docs-file .df-action { color: var(--accent); cursor: pointer; text-decoration: none; font-size: 0.85em; }
  .docs-file .df-action:hover { text-decoration: underline; }
  .docs-count-badge { display: inline-block; background: var(--accent); color: #fff; font-size: 0.75em;
    padding: 1px 6px; border-radius: 10px; margin-left: 4px; }
  .docs-text-preview { background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
    padding: 10px; margin: 6px 0; font-size: 0.8em; color: var(--muted); max-height: 200px;
    overflow-y: auto; white-space: pre-wrap; display: none; }
  .docs-text-preview.open { display: block; }
  .docs-upload-progress { color: var(--accent); font-size: 0.82em; padding: 8px 0; }

  /* Analysis results */
  .analyse-section { margin-top: 16px; }
  .analyse-section h4 { font-size: 0.9em; margin-bottom: 8px; }
  .analyse-card { background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
    padding: 12px; margin: 8px 0; }
  .analyse-card h5 { font-size: 0.85em; margin-bottom: 6px; color: var(--accent); }
  .analyse-empfehlung { display: inline-block; padding: 6px 16px; border-radius: 6px;
    font-weight: 700; font-size: 1em; margin: 8px 0; }
  .analyse-empfehlung.go { background: rgba(34,197,94,0.2); color: var(--green); border: 1px solid var(--green); }
  .analyse-empfehlung.nogo { background: rgba(239,68,68,0.2); color: var(--red); border: 1px solid var(--red); }
  .analyse-empfehlung.pruefen { background: rgba(234,179,8,0.2); color: var(--yellow); border: 1px solid var(--yellow); }
  .analyse-eignung { display: flex; align-items: center; gap: 6px; padding: 3px 0; font-size: 0.82em; }
  .analyse-eignung .ae-icon { font-size: 1em; }
  .analyse-eignung .ae-name { font-weight: 600; color: var(--text); }
  .analyse-eignung .ae-detail { color: var(--muted); }
  .analyse-list { font-size: 0.82em; color: var(--muted); padding-left: 16px; margin: 4px 0; }
  .analyse-list li { padding: 2px 0; }
  .analyse-unterlagen { font-size: 0.82em; }
  .analyse-unterlagen .au-row { display: flex; align-items: center; gap: 6px; padding: 3px 0; }
  .analyse-unterlagen .au-pflicht { color: var(--red); font-weight: 600; font-size: 0.85em; }
  .analyse-unterlagen .au-optional { color: var(--muted); font-size: 0.85em; }
  .btn-analyse { background: linear-gradient(135deg, #7c3aed, #3b82f6); color: #fff; border: none;
    padding: 10px 20px; border-radius: 6px; font-weight: 600; cursor: pointer; font-size: 0.9em; }
  .btn-analyse:hover { opacity: 0.9; }
  .btn-analyse:disabled { opacity: 0.5; cursor: not-allowed; }
  .analyse-loading { text-align: center; padding: 16px; color: var(--accent); font-size: 0.85em; }
  .apikey-input { width: 100%; padding: 8px; background: var(--bg); border: 1px solid var(--border);
    color: var(--text); border-radius: 6px; font-size: 0.85em; font-family: monospace; }

  /* Chat UI */
  .chat-section { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
  .chat-section h5 { margin: 0 0 8px; color: var(--accent); font-size: 0.9em; }
  .chat-messages { max-height: 400px; overflow-y: auto; padding: 8px; background: var(--bg);
    border-radius: 6px; border: 1px solid var(--border); margin-bottom: 8px; }
  .chat-msg { margin-bottom: 10px; line-height: 1.5; font-size: 0.85em; }
  .chat-msg.user { text-align: right; }
  .chat-msg.user .chat-bubble { display: inline-block; background: #1e3a5f; color: #e0e0e0;
    padding: 8px 12px; border-radius: 12px 12px 2px 12px; max-width: 85%; text-align: left; }
  .chat-msg.assistant .chat-bubble { display: inline-block; background: var(--card); color: var(--text);
    padding: 8px 12px; border-radius: 12px 12px 12px 2px; max-width: 90%; text-align: left;
    border: 1px solid var(--border); }
  .chat-msg.assistant .chat-bubble p { margin: 4px 0; }
  .chat-msg.assistant .chat-bubble ul, .chat-msg.assistant .chat-bubble ol { margin: 4px 0; padding-left: 20px; }
  .chat-msg.assistant .chat-bubble strong { color: var(--accent); }
  .chat-msg.assistant .chat-bubble code { background: rgba(255,255,255,0.05); padding: 1px 4px; border-radius: 3px; font-size: 0.92em; }
  .chat-input-row { display: flex; gap: 8px; }
  .chat-input { flex: 1; padding: 8px 12px; background: var(--bg); border: 1px solid var(--border);
    color: var(--text); border-radius: 6px; font-size: 0.85em; outline: none; }
  .chat-input:focus { border-color: var(--accent); }
  .chat-send { background: var(--accent); color: #fff; border: none; padding: 8px 16px;
    border-radius: 6px; font-weight: 600; cursor: pointer; font-size: 0.85em; white-space: nowrap; }
  .chat-send:hover { opacity: 0.9; }
  .chat-send:disabled { opacity: 0.5; cursor: not-allowed; }
  .chat-tokens { font-size: 0.72em; color: var(--muted); text-align: right; margin-top: 2px; }
  .chat-suggestions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
  .chat-suggestion { background: var(--card); border: 1px solid var(--border); color: var(--muted);
    padding: 4px 10px; border-radius: 12px; font-size: 0.78em; cursor: pointer; }
  .chat-suggestion:hover { border-color: var(--accent); color: var(--accent); }
</style>
</head>
<body>
<div class="container">
  <header>
    <h1>🔍 <span>Vergabe</span>-Suche</h1>
    <span style="color:var(--muted);font-size:0.85em">Streampark Media Networks</span>
  </header>

  <div class="tabs">
    <div class="tab" onclick="switchTab('profil')">👤 Profil</div>
    <div class="tab active" onclick="switchTab('search')">🔍 Suche</div>
    <div class="tab" id="tab-pipeline" onclick="switchTab('pipeline')">📋 Pipeline <span id="pipe-count" class="fav-badge" style="display:none">0</span></div>
    <div class="tab" onclick="switchTab('keywords')">Keywords</div>
    <div class="tab" onclick="switchTab('cpv')">CPV-Codes</div>
  </div>

  <!-- PROFIL PANEL -->
  <div id="panel-profil" class="panel">
    <div id="profil-warnings"></div>
