/* ==========================================================================
   Vertragsmanagement – Style
   Modern, hell, professionell. Kein Framework.
   ========================================================================== */

:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #1e293b;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1e40af;
  --primary-soft: #eff6ff;
  --green: #16a34a;
  --green-soft: #f0fdf4;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --amber: #d97706;
  --amber-soft: #fffbeb;
  --gray-soft: #f1f5f9;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 1px 3px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, 0.12);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono",
          monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--gray-soft);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1em 0.35em;
}

/* --------------------------------------------------------------------------
   Top-Navigation
   -------------------------------------------------------------------------- */

.topnav {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.7rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.brand {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--primary-dark);
  background: var(--primary-soft);
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  margin-left: 0.4rem;
  vertical-align: middle;
}

.links {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.links a {
  color: var(--muted);
  font-weight: 500;
  padding: 0.45rem 0.8rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.links a:hover { background: var(--gray-soft); color: var(--text); }

.links a.active {
  color: var(--primary);
  background: var(--primary-soft);
  text-decoration: none;
  box-shadow: inset 0 -2px 0 var(--primary);
}

.userbox {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-left: auto;
  flex-wrap: wrap;
}

.searchform input {
  width: 200px;
  font-size: 0.9rem;
}

.rolechip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  border: 1px solid transparent;
  white-space: nowrap;
}

.rolechip.vertragsmanager {
  color: #7c2d12;
  background: #ffedd5;
  border-color: #fed7aa;
}

.rolechip.bearbeiter {
  color: #1e3a8a;
  background: #dbeafe;
  border-color: #bfdbfe;
}

.logout {
  font-size: 0.85rem;
  color: var(--muted);
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius-sm);
}
.logout:hover { color: var(--red); background: var(--red-soft); text-decoration: none; }

/* --------------------------------------------------------------------------
   Inhalt
   -------------------------------------------------------------------------- */

.content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.75rem 1.5rem 4rem;
}

.content h1 {
  font-size: 1.6rem;
  font-weight: 700;
  margin: 0 0 0.25rem;
  letter-spacing: -0.01em;
}

.sub {
  color: var(--muted);
  margin: 0 0 1.25rem;
  font-size: 0.95rem;
}

.vhead { margin-bottom: 1.25rem; }
.vhead h1 { margin-bottom: 0.1rem; }
.vhead .sub { margin-bottom: 0; }

/* --------------------------------------------------------------------------
   Flash-Meldungen
   -------------------------------------------------------------------------- */

.flash {
  border-radius: var(--radius-sm);
  padding: 0.7rem 1rem;
  margin-bottom: 1.25rem;
  font-size: 0.95rem;
  border: 1px solid;
}

.flash.ok {
  color: #14532d;
  background: var(--green-soft);
  border-color: #bbf7d0;
}

.flash.error {
  color: #7f1d1d;
  background: var(--red-soft);
  border-color: #fecaca;
}

/* --------------------------------------------------------------------------
   KPI-Karten
   -------------------------------------------------------------------------- */

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.25rem;
}

.kpi-num {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--text);
}

.kpi-num.warn { color: var(--red); }

.kpi-label {
  color: var(--muted);
  font-size: 0.83rem;
  margin-top: 0.25rem;
}

/* --------------------------------------------------------------------------
   Grid & Karten
   -------------------------------------------------------------------------- */

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  align-items: start;
  margin-bottom: 1.25rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
  min-width: 0;
}

.card h2 {
  font-size: 1.05rem;
  font-weight: 650;
  margin: 0 0 1rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
}

/* --------------------------------------------------------------------------
   Tabellen
   -------------------------------------------------------------------------- */

.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.tbl th {
  text-align: left;
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--gray-soft);
  padding: 0.55rem 0.8rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.tbl td {
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.tbl tbody tr:nth-child(even) { background: #fafbfd; }
.tbl tbody tr:hover { background: var(--primary-soft); }
.tbl tbody tr:last-child td { border-bottom: none; }

.tbl .r { text-align: right; }
.tbl th.r { text-align: right; }

.empty {
  color: var(--muted);
  text-align: center;
  padding: 1.5rem 1rem !important;
  font-style: italic;
}

/* --------------------------------------------------------------------------
   Tags & Status
   -------------------------------------------------------------------------- */

.tag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary-dark);
  background: var(--primary-soft);
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
  white-space: nowrap;
}

.status {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 999px;
  padding: 0.12rem 0.6rem;
  border: 1px solid var(--border-strong);
  color: var(--muted);
  background: var(--surface);
  white-space: nowrap;
}

.status.aktiv {
  color: #14532d;
  background: var(--green-soft);
  border-color: #bbf7d0;
}

.status.gekuendigt {
  color: #7f1d1d;
  background: var(--red-soft);
  border-color: #fecaca;
}

.status.ausgelaufen {
  color: var(--muted);
  background: var(--gray-soft);
  border-color: var(--border-strong);
}

.status.in_verhandlung {
  color: #7c2d12;
  background: var(--amber-soft);
  border-color: #fde68a;
}

.soon {
  color: var(--red);
  font-weight: 700;
}

.dim { color: var(--muted); }

.mono {
  font-family: var(--mono);
  font-size: 0.8em;
}

/* --------------------------------------------------------------------------
   Key-Value-Tabelle
   -------------------------------------------------------------------------- */

.kv {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.kv th {
  width: 40%;
  text-align: right;
  font-weight: 500;
  color: var(--muted);
  padding: 0.45rem 0.9rem 0.45rem 0;
  vertical-align: top;
  white-space: nowrap;
}

.kv td {
  padding: 0.45rem 0;
  vertical-align: top;
  border-bottom: 1px dashed var(--border);
}

.kv tr:last-child td { border-bottom: none; }

/* --------------------------------------------------------------------------
   Filterleisten
   -------------------------------------------------------------------------- */

.filters {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 1.25rem;
}

.filters input,
.filters select {
  font: inherit;
  font-size: 0.92rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}

.filters input:focus,
.filters select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.filters button {
  padding: 0.5rem 1.1rem;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

button {
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  color: #ffffff;
  background: var(--primary);
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 0.5rem 1.1rem;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}

button:hover { background: var(--primary-dark); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.6; cursor: not-allowed; }

.btn {
  display: inline-block;
  font-size: 0.88rem;
  font-weight: 600;
  color: #ffffff;
  background: var(--primary);
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.9rem;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease;
}

.btn:hover { background: var(--primary-dark); text-decoration: none; }

.btn.small {
  font-size: 0.78rem;
  padding: 0.25rem 0.6rem;
}

.btn.ghost {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border-strong);
}

.btn.ghost:hover {
  background: var(--gray-soft);
  border-color: var(--border-strong);
}

/* --------------------------------------------------------------------------
   Links mit Pfeil-Optik
   -------------------------------------------------------------------------- */

.link {
  color: var(--primary);
  font-weight: 500;
  text-decoration: none;
}

.link:hover { text-decoration: underline; }

/* --------------------------------------------------------------------------
   Anonymisierter Text
   -------------------------------------------------------------------------- */

.anontext {
  font-family: var(--mono);
  font-size: 0.83rem;
  line-height: 1.6;
  background: var(--gray-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  margin: 0.75rem 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 420px;
  overflow-y: auto;
}

/* --------------------------------------------------------------------------
   Chat
   -------------------------------------------------------------------------- */

.chatbox {
  height: 55vh;
  min-height: 320px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-bottom: 0.85rem;
}

.msg {
  display: flex;
  max-width: 100%;
}

.msg.user { justify-content: flex-end; }
.msg.agent { justify-content: flex-start; }

.bubble {
  max-width: 78%;
  padding: 0.7rem 1rem;
  border-radius: 14px;
  font-size: 0.93rem;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.msg.user .bubble {
  background: var(--primary);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.msg.agent .bubble {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.bubble.error {
  background: var(--red-soft);
  color: #7f1d1d;
  border-color: #fecaca;
}

.bubble code {
  background: rgba(0, 0, 0, 0.08);
  border: none;
  color: inherit;
}

.msg.user .bubble code { background: rgba(255, 255, 255, 0.2); }

.bubble pre {
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.5;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  margin: 0.5rem 0;
  overflow-x: auto;
  white-space: pre;
}

.bubble pre:first-child { margin-top: 0; }
.bubble pre:last-child { margin-bottom: 0; }

.bubble strong { font-weight: 700; }

/* Markdown-lite-Bubbles: Codeblöcke dunkel hinterlegt */
.bubble.md pre {
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.5;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  margin: 0.5rem 0;
  overflow-x: auto;
  white-space: pre;
}

.chatform {
  display: flex;
  gap: 0.6rem;
}

.chatform input {
  flex: 1;
  font: inherit;
  font-size: 0.95rem;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.chatform input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* --------------------------------------------------------------------------
   Dateiliste (Admin)
   -------------------------------------------------------------------------- */

.filelist {
  list-style: none;
  margin: 0;
  padding: 0;
  columns: 2;
  column-gap: 1.5rem;
  font-size: 0.9rem;
}

.filelist li {
  padding: 0.25rem 0;
  break-inside: avoid;
}

.filelist a { font-family: var(--mono); font-size: 0.83rem; }

/* --------------------------------------------------------------------------
   Terminal (Admin)
   -------------------------------------------------------------------------- */

#termform {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

#termform input {
  flex: 1;
  font-family: var(--mono);
  font-size: 0.9rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

#termform input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.termout {
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.55;
  background: #0f172a;
  color: #4ade80;
  border-radius: var(--radius-sm);
  padding: 0.9rem 1rem;
  margin: 0 0 0.75rem;
  min-height: 120px;
  max-height: 340px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.termout .term-prompt { color: #93c5fd; }
.termout .term-exit { color: #fbbf24; }

/* --------------------------------------------------------------------------
   Code-Editor (Admin)
   -------------------------------------------------------------------------- */

.codearea {
  width: 100%;
  min-height: 500px;
  font-family: var(--mono);
  font-size: 0.83rem;
  line-height: 1.55;
  background: #f8fafc;
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1rem;
  resize: vertical;
  tab-size: 4;
}

.codearea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* --------------------------------------------------------------------------
   Row (Button-Leisten)
   -------------------------------------------------------------------------- */

.row {
  display: flex;
  gap: 0.7rem;
  align-items: center;
  margin-top: 0.85rem;
  flex-wrap: wrap;
}

/* --------------------------------------------------------------------------
   Login
   -------------------------------------------------------------------------- */

.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #eef2ff 0%, #f8fafc 55%, #e0f2fe 100%);
  padding: 1.5rem;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 2.25rem 2.5rem;
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.login-card h1 { font-size: 1.35rem; margin-bottom: 0.15rem; }
.login-card .sub { margin-bottom: 1.5rem; }

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  text-align: left;
}

.login-card label {
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--muted);
  margin-top: 0.4rem;
}

.login-card input {
  font: inherit;
  font-size: 0.95rem;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.login-card input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.login-card button { margin-top: 1rem; }

.hint {
  margin-top: 1.25rem;
  font-size: 0.8rem;
  color: var(--muted);
}

/* --------------------------------------------------------------------------
   Typ-Verteilung (Dashboard)
   -------------------------------------------------------------------------- */

.typelist { display: flex; flex-direction: column; }

.typerow {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.45rem 0;
  border-bottom: 1px dashed var(--border);
  font-size: 0.92rem;
}

.typerow:last-child { border-bottom: none; }

.count {
  font-weight: 700;
  color: var(--text);
  background: var(--gray-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.05rem 0.65rem;
  font-size: 0.82rem;
  min-width: 2.2rem;
  text-align: center;
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 900px) {
  .grid2 { grid-template-columns: 1fr; }
  .filelist { columns: 1; }
}

@media (max-width: 640px) {
  .content { padding: 1.25rem 1rem 3rem; }
  .topnav { padding: 0.6rem 1rem; }
  .searchform input { width: 140px; }
  .bubble { max-width: 92%; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .login-card { padding: 1.75rem 1.5rem; }
}
