/* ── Reset & Variablen ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f1117;
  --bg2:       #1a1d27;
  --bg3:       #23273a;
  --border:    #2e3350;
  --accent:    #4f8ef7;
  --accent2:   #7c5cbf;
  --success:   #3ecf8e;
  --warn:      #f0a04b;
  --danger:    #e05c5c;
  --text:      #e8eaf0;
  --text2:     #8892b0;
  --text3:     #4a5270;
  --radius:    8px;
  --sidebar-w: 320px;
}

body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; }

/* ── Layout ─────────────────────────────────────────────────────────── */
#app { display: flex; height: 100vh; }

#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#main {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  position: relative;
}

/* ── Logo ───────────────────────────────────────────────────────────── */
#logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.logo-icon { font-size: 24px; color: var(--accent); }
.logo-text { font-size: 18px; font-weight: 700; letter-spacing: 0.5px; }

/* ── Stats ──────────────────────────────────────────────────────────── */
#stats-bar {
  padding: 10px 16px;
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  color: var(--text2);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.stat-chip {
  display: flex;
  align-items: center;
  gap: 4px;
}
.stat-chip span { color: var(--accent); font-weight: 600; }

/* ── Nav Tabs ───────────────────────────────────────────────────────── */
#nav-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.nav-btn {
  flex: 1;
  padding: 10px 4px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text2);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all .2s;
}
.nav-btn:hover { color: var(--text); background: var(--bg3); }
.nav-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Tab Content ────────────────────────────────────────────────────── */
.tab-content { display: none; flex: 1; overflow-y: auto; }
.tab-content.active { display: flex; flex-direction: column; }

/* ── Suche ──────────────────────────────────────────────────────────── */
#search-area { padding: 16px; display: flex; flex-direction: column; gap: 10px; }

#search-input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 12px;
  font-size: 13px;
  resize: vertical;
  outline: none;
  transition: border-color .2s;
}
#search-input:focus { border-color: var(--accent); }

#search-btn {
  padding: 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .2s;
}
#search-btn:hover { opacity: .85; }
#search-btn:disabled { opacity: .4; cursor: not-allowed; }

#example-queries { display: flex; flex-direction: column; gap: 6px; }
.hint { font-size: 11px; color: var(--text3); }

.example-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text2);
  padding: 8px 10px;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
  transition: all .2s;
}
.example-btn:hover { border-color: var(--accent); color: var(--text); }

/* ── Modul-/Topic-Liste ─────────────────────────────────────────────── */
#module-list, #topic-list { padding: 12px; display: flex; flex-direction: column; gap: 6px; }

.module-card, .topic-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  cursor: pointer;
  transition: all .2s;
}
.module-card:hover, .topic-card:hover { border-color: var(--accent); }

.module-code { font-weight: 700; color: var(--accent); font-size: 13px; }
.module-name { font-size: 12px; color: var(--text2); }
.module-count { font-size: 11px; color: var(--text3); margin-top: 2px; }

/* ── Welcome ────────────────────────────────────────────────────────── */
#welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  gap: 14px;
  color: var(--text2);
}
.welcome-icon { font-size: 64px; opacity: .3; }
#welcome h1 { font-size: 28px; color: var(--text); }
#welcome p { max-width: 480px; line-height: 1.6; }

/* ── Loading ────────────────────────────────────────────────────────── */
#loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 60%;
  gap: 16px;
  color: var(--text2);
}
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Ergebnis-Header ────────────────────────────────────────────────── */
#answer-header {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
}
#answer-title { font-size: 18px; margin-bottom: 8px; color: var(--accent); }
#answer-text { line-height: 1.6; color: var(--text2); font-size: 14px; }
.recommendation {
  margin-top: 10px;
  padding: 10px 12px;
  background: rgba(79,142,247,.1);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 13px;
  color: var(--text);
}

/* ── Result Tabs ────────────────────────────────────────────────────── */
#result-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}
.result-tab-btn {
  padding: 8px 16px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text2);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all .2s;
  margin-bottom: -1px;
}
.result-tab-btn:hover { color: var(--text); }
.result-tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.result-tab-content { display: none; }
.result-tab-content.active { display: block; }

/* ── Cytoscape Graph ────────────────────────────────────────────────── */
#cy-container {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  position: relative;
  height: 480px;
}
#cy { width: 100%; height: 100%; border-radius: var(--radius); }

#cy-legend {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  gap: 12px;
  font-size: 12px;
}
.legend-item { color: var(--text2); display: flex; align-items: center; gap: 4px; }
.legend-item.primary { color: var(--accent); }
.legend-item.secondary { color: var(--accent2); }

#cy-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 6px;
}
#cy-controls button {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text2);
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
}
#cy-controls button:hover { border-color: var(--accent); color: var(--text); }

#node-detail {
  margin-top: 12px;
  background: var(--bg2);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px;
}
#node-detail-title { color: var(--accent); margin-bottom: 6px; }
#node-detail-desc { color: var(--text2); font-size: 13px; margin-bottom: 12px; }
#node-detail-cols { display: flex; flex-wrap: wrap; gap: 6px; }

.col-chip {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 11px;
  font-family: monospace;
  color: var(--text2);
}
.col-chip.key { border-color: var(--warn); color: var(--warn); }

/* ── Tabellen-Liste ─────────────────────────────────────────────────── */
#tables-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }

.table-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  transition: border-color .2s;
}
.table-card:hover { border-color: var(--accent); }

.table-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.table-card-name { font-weight: 700; font-family: monospace; font-size: 15px; color: var(--accent); }
.badge {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 99px;
  font-weight: 600;
}
.badge-primary { background: rgba(79,142,247,.2); color: var(--accent); }
.badge-secondary { background: rgba(124,92,191,.2); color: var(--accent2); }
.badge-module { background: var(--bg3); color: var(--text2); border: 1px solid var(--border); }

.table-card-desc { font-size: 12px; color: var(--text2); line-height: 1.5; }
.table-card-usage { font-size: 11px; color: var(--success); margin-top: 6px; }

/* ── Spalten-Detail ─────────────────────────────────────────────────── */
#columns-detail { display: flex; flex-direction: column; gap: 16px; }

.col-table-block {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.col-table-header {
  background: var(--bg3);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}
.col-table-header h3 { font-family: monospace; color: var(--accent); font-size: 15px; }
.col-table-header p { font-size: 12px; color: var(--text2); }

table.cols {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
table.cols th {
  background: var(--bg3);
  color: var(--text3);
  padding: 8px 12px;
  text-align: left;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: .5px;
}
table.cols td {
  padding: 7px 12px;
  border-top: 1px solid var(--border);
  color: var(--text2);
  vertical-align: middle;
}
table.cols tr:hover td { background: var(--bg3); }
table.cols td.key-col { color: var(--warn); font-weight: 600; }
table.cols td.field-name { font-family: monospace; color: var(--text); font-size: 12px; }

/* ── Table Detail View ──────────────────────────────────────────────── */
#table-detail-view { padding: 4px; }
#back-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text2);
  padding: 7px 14px;
  cursor: pointer;
  font-size: 13px;
  margin-bottom: 16px;
  transition: all .2s;
}
#back-btn:hover { border-color: var(--accent); color: var(--accent); }

#table-detail-content h2 { font-family: monospace; color: var(--accent); font-size: 22px; margin-bottom: 4px; }
#table-detail-content .tdesc { color: var(--text2); font-size: 14px; margin-bottom: 16px; }

.detail-section { margin-bottom: 20px; }
.detail-section h3 { color: var(--text); font-size: 14px; margin-bottom: 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }

.rel-item {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 6px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.rel-arrow { color: var(--accent); font-weight: 700; }
.rel-table { font-family: monospace; color: var(--accent); }
.rel-field { font-family: monospace; color: var(--text2); font-size: 12px; }
.rel-desc { color: var(--text3); font-size: 12px; margin-left: auto; }

/* ── Config Tab ─────────────────────────────────────────────────────── */
#config-area { padding: 12px 4px; display: flex; flex-direction: column; gap: 10px; }
#config-area h3 { color: var(--text); font-size: 13px; margin-bottom: 4px; }
#config-area label { font-size: 12px; color: var(--text2); }
#config-area input, #config-area select {
  width: 100%; padding: 8px 10px; background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 13px; outline: none;
}
#config-area input:focus, #config-area select:focus { border-color: var(--accent); }
.config-row { display: flex; gap: 6px; margin-top: 4px; }
.config-row input { flex: 1; }
.config-row button { white-space: nowrap; padding: 8px 10px; font-size: 12px; }
#config-model-row { display: flex; flex-direction: column; gap: 4px; }
#config-save {
  padding: 10px; background: var(--accent); color: #fff; border: none;
  border-radius: var(--radius); cursor: pointer; font-size: 13px; font-weight: 600;
}
#config-save:hover { opacity: 0.85; }
.config-status-ok { font-size: 12px; color: var(--success); }
.config-status-error { font-size: 12px; color: var(--danger); }

/* ── Utilities ──────────────────────────────────────────────────────── */
.hidden { display: none !important; }
