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

:root {
  --brand:       #0f4c8a;
  --brand-light: #e8f0fb;
  --green:       #16a34a;
  --green-bg:    #dcfce7;
  --red:         #dc2626;
  --red-bg:      #fee2e2;
  --orange:      #ea580c;
  --orange-bg:   #ffedd5;
  --blue:        #2563eb;
  --blue-bg:     #dbeafe;
  --purple:      #7c3aed;
  --purple-bg:   #ede9fe;
  --gray:        #6b7280;
  --gray-bg:     #f3f4f6;
  --border:      #e5e7eb;
  --text:        #111827;
  --text-muted:  #6b7280;
  --bg:          #f9fafb;
  --white:       #ffffff;
  --radius:      6px;
  --shadow:      0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg:   0 10px 25px rgba(0,0,0,.15);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
.header {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  height: 52px;
  background: var(--brand);
  box-shadow: var(--shadow);
}

.header-brand { display: flex; align-items: center; gap: 8px; }

.brand-logo {
  font-size: 16px; font-weight: 700; letter-spacing: .5px;
  color: var(--white);
}
.brand-sep { color: rgba(255,255,255,.4); font-size: 18px; }
.brand-title { color: rgba(255,255,255,.85); font-size: 15px; font-weight: 400; }

.header-user { display: flex; align-items: center; gap: 10px; }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: rgba(255,255,255,.2);
  color: white; font-weight: 600; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
}
.user-name { color: rgba(255,255,255,.85); font-size: 13px; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--brand); color: white;
  border: none; border-radius: var(--radius);
  padding: 10px 20px; font-size: 14px; font-weight: 500;
  cursor: pointer; display: inline-flex; align-items: center;
  transition: background .15s;
}
.btn-primary:hover { background: #0d3f75; }

.btn-ghost {
  background: transparent; color: rgba(255,255,255,.8);
  border: 1px solid rgba(255,255,255,.25); border-radius: var(--radius);
  padding: 5px 12px; font-size: 13px; cursor: pointer;
  transition: all .15s;
}
.btn-ghost:hover { background: rgba(255,255,255,.1); color: white; }

.btn-secondary {
  display: inline-block;
  background: var(--brand-light); color: var(--brand);
  border: 1px solid #bfdbfe; border-radius: var(--radius);
  padding: 8px 16px; font-size: 13px; font-weight: 500;
  text-decoration: none; cursor: pointer;
  transition: background .15s;
}
.btn-secondary:hover { background: #dbeafe; }

/* ── Login ───────────────────────────────────────────────────────────────── */
.view-login {
  display: flex; align-items: center; justify-content: center;
  min-height: calc(100vh - 52px);
}
.login-card {
  background: var(--white); border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 48px 40px; text-align: center; width: 380px;
}
.login-logo {
  font-size: 22px; font-weight: 700; color: var(--brand);
  letter-spacing: .5px; margin-bottom: 16px;
}
.login-title { font-size: 22px; font-weight: 600; margin-bottom: 8px; }
.login-sub { color: var(--text-muted); margin-bottom: 32px; line-height: 1.5; }
.btn-login { width: 100%; justify-content: center; font-size: 15px; padding: 12px 20px; }
.login-hint { margin-top: 16px; font-size: 12px; color: var(--red); }

/* ── Board Layout ────────────────────────────────────────────────────────── */
.view-board { padding: 20px 24px; max-width: 1600px; margin: 0 auto; }

/* ── Stats ───────────────────────────────────────────────────────────────── */
.stats-bar {
  display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap;
}
.stat {
  background: var(--white); border-radius: var(--radius);
  border: 1px solid var(--border); box-shadow: var(--shadow);
  padding: 12px 20px; display: flex; flex-direction: column;
  align-items: center; min-width: 100px;
  cursor: pointer; user-select: none;
  transition: border-color .15s, box-shadow .15s, transform .1s;
}
.stat:hover { transform: translateY(-1px); box-shadow: 0 3px 10px rgba(0,0,0,.10); }
.stat-active {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px var(--brand) inset;
  background: var(--brand-light);
}
.stat-num { font-size: 28px; font-weight: 700; line-height: 1; }
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); margin-top: 2px; }

.stat-offen  .stat-num { color: var(--gray); }
.stat-go     .stat-num { color: var(--green); }
.stat-bereit .stat-num { color: var(--blue); }
.stat-fehlt  .stat-num { color: var(--orange); }
.stat-total  .stat-num { color: var(--brand); }

/* ── Controls ────────────────────────────────────────────────────────────── */
.controls {
  display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap;
  align-items: center;
}
.btn-run { border-color: var(--brand); color: var(--brand); font-weight: 600; }
.btn-run:hover:not(:disabled) { background: var(--brand-light); }
.btn-run:disabled { opacity: .5; cursor: default; }

/* Lauf-Status-Zeile */
.run-status {
  margin: -4px 0 16px; padding: 9px 14px;
  background: var(--brand-light); border: 1px solid var(--border);
  border-left: 3px solid var(--brand); border-radius: var(--radius);
  font-size: 13px; color: var(--text);
}
.search-input {
  flex: 1; min-width: 200px;
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 12px; font-size: 14px; background: var(--white);
  outline: none; transition: border .15s;
}
.search-input:focus { border-color: var(--blue); }

.filter-sel {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 10px; font-size: 13px; background: var(--white);
  cursor: pointer; outline: none;
}

.btn-refresh {
  background: var(--white); color: var(--brand);
  border: 1px solid var(--border);
  padding: 8px 14px; font-size: 13px; border-radius: var(--radius);
  cursor: pointer; transition: all .15s;
}
.btn-refresh:hover { background: var(--brand-light); border-color: var(--brand); }

/* ── Loading Bar ─────────────────────────────────────────────────────────── */
.loading-bar {
  height: 3px; background: var(--border); border-radius: 2px;
  margin-bottom: 12px; overflow: hidden;
}
.loading-bar-inner {
  height: 100%; width: 40%; background: var(--blue);
  border-radius: 2px;
  animation: loadslide 1s ease-in-out infinite;
}
@keyframes loadslide {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}

/* ── Table ───────────────────────────────────────────────────────────────── */
.table-wrap {
  background: var(--white); border-radius: var(--radius);
  border: 1px solid var(--border); box-shadow: var(--shadow);
  overflow: auto;
}
.bid-table {
  width: 100%; border-collapse: collapse;
  font-size: 13px;
}
.bid-table th {
  background: var(--bg); font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted);
  padding: 10px 12px; text-align: left; white-space: nowrap;
  border-bottom: 2px solid var(--border); position: sticky; top: 0; z-index: 10;
}
.bid-table td {
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.bid-table tbody tr:last-child td { border-bottom: none; }
.bid-table tbody tr:hover { background: #f8faff; cursor: pointer; }
.bid-table tbody tr.expanded { background: var(--brand-light); }

/* Column widths */
.col-score     { width: 58px; text-align: center; }
.col-status    { width: 130px; }
.col-frist     { width: 88px; white-space: nowrap; }
.col-title     { min-width: 200px; max-width: 280px; }
.col-empf      { min-width: 160px; max-width: 220px; }
.col-entsch    { width: 120px; }
.col-begruendung { min-width: 160px; }
.col-champion  { width: 110px; }
.col-actions   { width: 36px; text-align: center; }

/* ── Score Badge ─────────────────────────────────────────────────────────── */
.score-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%;
  font-weight: 700; font-size: 13px;
}
.score-high   { background: var(--green-bg); color: var(--green); }
.score-mid    { background: #fef9c3; color: #a16207; }
.score-low    { background: var(--gray-bg); color: var(--gray); }

/* ── Status Badge ────────────────────────────────────────────────────────── */
.status-pill {
  display: inline-block; border-radius: 20px; padding: 3px 8px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.status-bereit      { background: var(--blue-bg); color: var(--blue); }
.status-fehlt       { background: var(--orange-bg); color: var(--orange); }
.status-angenommen  { background: var(--green-bg); color: var(--green); }
.status-bearbeitung { background: var(--purple-bg); color: var(--purple); }
.status-neu         { background: var(--gray-bg); color: var(--gray); }

/* ── Entscheidung ────────────────────────────────────────────────────────── */
.entsch-badge {
  display: inline-block; border-radius: var(--radius);
  padding: 4px 10px; font-size: 12px; font-weight: 600; cursor: pointer;
}
.entsch-go    { background: var(--green-bg); color: var(--green); }
.entsch-nogo  { background: var(--red-bg); color: var(--red); }
.entsch-offen { background: var(--gray-bg); color: var(--gray); }

.entsch-select {
  width: 100%; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 4px 6px; font-size: 12px; font-weight: 600; background: white;
  cursor: pointer; outline: none;
}

/* ── Inline Edit ─────────────────────────────────────────────────────────── */
.inline-edit {
  width: 100%; border: 1px solid transparent;
  border-radius: var(--radius); padding: 3px 6px;
  font-size: 13px; background: transparent; resize: none;
  font-family: inherit; color: var(--text);
  transition: border .15s;
  box-sizing: border-box;
}
.inline-edit:hover { border-color: var(--border); }
.inline-edit:focus { border-color: var(--blue); background: white; outline: none; }

/* Begründung: Textarea wächst mit dem Inhalt, kein Abschneiden */
textarea.inline-edit {
  overflow: hidden;
  line-height: 1.45;
  min-height: 2.6em;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Zeile mit gerade geänderter Entscheidung — wandert erst beim nächsten Laden */
.row-pending { background: #fffbeb; }
.row-pending td { box-shadow: inset 3px 0 0 var(--orange); }

/* ── Title Cell ──────────────────────────────────────────────────────────── */
.title-main { font-weight: 500; color: var(--text); line-height: 1.4; }
.title-ag   { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ── Empfehlung Cell ─────────────────────────────────────────────────────── */
.empf-text { font-size: 12px; color: var(--text-muted); line-height: 1.4; }
.empf-ko-ok   { color: var(--green); font-weight: 600; }
.empf-ko-fail { color: var(--red); font-weight: 600; }

/* ── Frist ───────────────────────────────────────────────────────────────── */
.frist-text { font-size: 12px; }
.frist-soon  { color: var(--orange); font-weight: 600; }
.frist-past  { color: var(--red); font-weight: 600; }

/* ── Action Button ───────────────────────────────────────────────────────── */
.action-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 14px; padding: 4px;
  border-radius: 4px; transition: all .1s; line-height: 1;
}
.action-btn:hover { background: var(--gray-bg); color: var(--brand); }

/* ── Empty State ─────────────────────────────────────────────────────────── */
.empty-state { padding: 48px; text-align: center; color: var(--text-muted); }

/* ── Group Headers ───────────────────────────────────────────────────────── */
.group-header td { padding: 0; }
.group-header-cell {
  user-select: none; cursor: pointer;
  border-top: 2px solid transparent;
}
.group-header-inner {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px;
  font-size: 11px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase;
}
.group-header-cell:hover { filter: brightness(.96); }

.group-go    .group-header-cell { background: var(--green-bg); color: var(--green);  border-top-color: #86efac; }
.group-offen .group-header-cell { background: var(--gray-bg);  color: var(--gray);   border-top-color: var(--border); }
.group-nogo  .group-header-cell { background: var(--red-bg);   color: var(--red);    border-top-color: #fca5a5; }

.group-arrow { font-size: 12px; transition: transform .15s; }
.group-icon  { font-size: 11px; }
.group-label { flex: 1; }
.group-count {
  background: rgba(0,0,0,.12); border-radius: 20px;
  padding: 1px 8px; font-size: 11px; font-weight: 600;
}

/* ── Sort Headers ────────────────────────────────────────────────────────── */
.bid-table th[data-sort]:hover { background: #eaecf0; }
.bid-table th.sort-active { color: var(--brand); }
.sort-arrow { font-size: 9px; color: var(--text-muted); margin-left: 2px; }
.sort-active .sort-arrow { color: var(--brand); }

/* ── Drawer ──────────────────────────────────────────────────────────────── */
.drawer-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.3);
  z-index: 200; transition: opacity .25s;
  opacity: 0; pointer-events: none;
}
.drawer-overlay.hidden { display: none; }
.drawer-overlay.open   { opacity: 1; pointer-events: all; }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(560px, 100vw);
  background: var(--white); box-shadow: var(--shadow-lg);
  z-index: 201; display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .25s ease;
  overflow: hidden;
}
.drawer.hidden { display: none; }
.drawer.open   { transform: translateX(0); }

/* ── Tiefen-Empfehlung Markdown ──────────────────────────────────────────── */
.tiefe-md { font-size: 13px; line-height: 1.7; color: var(--text); }
.tiefe-md h2 { font-size: 15px; font-weight: 700; margin: 16px 0 6px; color: var(--brand); }
.tiefe-md h3 { font-size: 13px; font-weight: 700; margin: 14px 0 4px; color: var(--text); }
.tiefe-md h4 { font-size: 12px; font-weight: 700; margin: 10px 0 4px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .3px; }
.tiefe-md hr  { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.tiefe-md ul  { padding-left: 18px; margin: 6px 0; }
.tiefe-md li  { margin: 3px 0; }
.tiefe-md p   { margin: 6px 0; }
.tiefe-md strong { font-weight: 600; color: var(--text); }
.tiefe-md em     { font-style: italic; color: var(--text-muted); }
.tiefe-md code   { background: var(--gray-bg); border-radius: 3px; padding: 1px 5px; font-size: 12px; }
.md-gap          { height: 6px; }
.md-table        { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 12px; }
.md-table th, .md-table td { border: 1px solid var(--border); padding: 5px 10px; text-align: left; }
.md-table th     { background: var(--gray-bg); font-weight: 600; font-size: 11px; }

/* ── Drawer Action ───────────────────────────────────────────────────────── */
.drawer-action-section { border-top: 2px solid var(--border); padding-top: 20px; }
.drawer-actions { display: flex; flex-direction: column; gap: 8px; }
.btn-action-go {
  background: var(--green); color: white;
  border: none; border-radius: var(--radius);
  padding: 11px 20px; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: background .15s; text-align: left;
}
.btn-action-go:hover:not(:disabled) { background: #15803d; }
.btn-action-go:disabled { background: var(--gray-bg); color: var(--gray); cursor: default; }
.action-hint { font-size: 12px; color: var(--text-muted); line-height: 1.5; }

.drawer-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 20px 24px; border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.drawer-badge { margin-bottom: 6px; }
.drawer-header h2 { font-size: 16px; line-height: 1.4; margin-bottom: 4px; }
.drawer-header p  { font-size: 12px; color: var(--text-muted); }
.drawer-close {
  background: none; border: none; font-size: 18px; cursor: pointer;
  color: var(--text-muted); padding: 4px; flex-shrink: 0;
  margin-left: 16px; margin-top: 2px;
}
.drawer-close:hover { color: var(--text); }

.drawer-body { flex: 1; overflow-y: auto; padding: 20px 24px; }
.drawer-section { margin-bottom: 24px; }
.drawer-section h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-muted); font-weight: 600; margin-bottom: 10px;
}
.drawer-kennung {
  display: inline-block; margin-left: 10px;
  font-size: 11px; color: var(--text-muted);
  background: var(--gray-bg); border-radius: var(--radius);
  padding: 2px 8px; vertical-align: middle;
}

.drawer-empf-text {
  font-size: 13px; padding: 10px 14px; border-radius: var(--radius);
  background: var(--brand-light); color: var(--brand); font-weight: 500;
}
.drawer-tiefe-text {
  font-size: 13px; line-height: 1.7; white-space: pre-wrap;
  color: var(--text);
}

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1f2937; color: white;
  padding: 10px 20px; border-radius: 6px; font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-lg); z-index: 999;
  transition: opacity .2s;
}
.toast.error { background: var(--red); }

/* ── Saving indicator ────────────────────────────────────────────────────── */
.saving { opacity: .5; pointer-events: none; }
.save-ok::after { content: ' ✓'; color: var(--green); }

/* ── Helpers ─────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
[hidden]  { display: none !important; }

@media (max-width: 768px) {
  .view-board { padding: 12px; }
  .col-empf, .col-begruendung, .col-champion { display: none; }
  .drawer { width: 100vw; }
}
