/* SpheraOS Baustellen-Dashboard – Styles
   Modern, responsiv, Dark/Light über CSS-Variablen. Keine externen CDNs. */

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f0f3f9;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #dbeafe;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 4px 12px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 8px 28px rgba(15, 23, 42, 0.12);
  --radius: 14px;
  --radius-sm: 9px;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --border: #334155;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-soft: #1e3a5f;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 8px 28px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

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

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0 0 .4rem; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: .3rem 0; }
.muted { color: var(--text-muted); font-size: .9rem; }
.hidden { display: none !important; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: .7rem; }
.brand-mark { font-size: 1.7rem; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 1.05rem; }
.brand-text span { font-size: .78rem; color: var(--text-muted); }
.topbar-right { display: flex; align-items: center; gap: .8rem; }
.health { display: flex; gap: .4rem; font-size: .75rem; }
.health .pill {
  padding: .2rem .55rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  white-space: nowrap;
}
.health .pill.on { background: var(--primary-soft); color: var(--primary); border-color: transparent; }

.icon-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 38px; height: 38px;
  font-size: 1.05rem;
  cursor: pointer;
  color: var(--text);
  transition: background .15s;
}
.icon-btn:hover { background: var(--border); }

/* ---------- Stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  padding: 1.25rem 1.25rem 0;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  box-shadow: var(--shadow);
}
.stat-card .num { font-size: 1.8rem; font-weight: 700; letter-spacing: -0.02em; }
.stat-card .lbl { font-size: .82rem; color: var(--text-muted); }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 330px 1fr;
  gap: 1rem;
  padding: 1.25rem;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
  align-items: start;
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  position: sticky;
  top: 76px;
  max-height: calc(100vh - 96px);
  display: flex;
  flex-direction: column;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; }
.search { margin: .7rem 0; }
.search input, .new-site-form input, .new-site-form textarea,
.pr-form input, .pr-form textarea, .chat-form input {
  width: 100%;
  padding: .55rem .7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}
input:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.new-site-form { margin-bottom: .8rem; }
.new-site-form label, .pr-form label {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  font-size: .82rem;
  color: var(--text-muted);
  margin-bottom: .55rem;
}
.form-actions { display: flex; justify-content: flex-end; gap: .5rem; }

.site-list { list-style: none; margin: .3rem 0 0; padding: 0; overflow-y: auto; }
.site-item {
  padding: .65rem .7rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  margin-bottom: .35rem;
  transition: background .12s, border-color .12s;
}
.site-item:hover { background: var(--surface-2); }
.site-item.active { background: var(--primary-soft); border-color: var(--primary); }
.site-item .si-name { font-weight: 600; display: flex; justify-content: space-between; gap: .5rem; }
.site-item .si-count {
  font-size: .72rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .05rem .5rem;
  color: var(--text-muted);
  flex: none;
}
.site-item .si-sub { font-size: .78rem; color: var(--text-muted); margin-top: .15rem; }

/* ---------- Detail ---------- */
.detail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  min-height: 60vh;
}
.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 4rem 1rem;
  max-width: 420px;
  margin: 0 auto;
}
.empty-icon { font-size: 2.5rem; margin-bottom: .5rem; }

.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.detail-meta { color: var(--text-muted); font-size: .85rem; }

.status-badge {
  padding: .25rem .7rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.status-badge.aktiv { background: #dcfce7; color: #15803d; border-color: transparent; }
.status-badge.pausiert { background: #fef3c7; color: #b45309; border-color: transparent; }
.status-badge.abgeschlossen { background: var(--surface-2); color: var(--text-muted); }
[data-theme="dark"] .status-badge.aktiv { background: #14532d; color: #86efac; }
[data-theme="dark"] .status-badge.pausiert { background: #713f12; color: #fcd34d; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: .3rem;
  margin: 1.1rem 0 1rem;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tab {
  background: none;
  border: none;
  padding: .6rem .9rem;
  cursor: pointer;
  color: var(--text-muted);
  font: inherit;
  font-weight: 550;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  margin-bottom: 1rem;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .6rem; }
.summary-box { white-space: pre-wrap; color: var(--text); font-size: .92rem; }
.summary-box.placeholder { color: var(--text-muted); }
.summary-meta { font-size: .75rem; color: var(--text-muted); margin-top: .6rem; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; margin: 0; }
.facts dt { color: var(--text-muted); font-size: .85rem; }
.facts dd { margin: 0; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: .55rem 1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font: inherit;
  font-weight: 550;
  transition: background .12s, transform .05s;
}
.btn:hover { background: var(--border); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .55; cursor: progress; }
.btn-sm { padding: .4rem .75rem; font-size: .85rem; }
.btn-primary { background: var(--primary); color: #fff; border-color: transparent; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; }

/* ---------- Historie ---------- */
.history { display: flex; flex-direction: column; gap: .8rem; }
.msg {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .9rem 1rem;
  background: var(--surface);
}
.msg-head { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .4rem; }
.msg-head .who { font-weight: 600; }
.msg-head .when { color: var(--text-muted); font-size: .78rem; margin-left: auto; }
.type-badge {
  font-size: .7rem;
  font-weight: 600;
  padding: .1rem .5rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: .03em;
}
.type-badge.voice { background: #ede9fe; color: #6d28d9; border-color: transparent; }
.type-badge.photo { background: #cffafe; color: #0e7490; border-color: transparent; }
.type-badge.document { background: #fef9c3; color: #a16207; border-color: transparent; }
[data-theme="dark"] .type-badge.voice { background: #4c1d95; color: #c4b5fd; }
[data-theme="dark"] .type-badge.photo { background: #164e63; color: #67e8f9; }
[data-theme="dark"] .type-badge.document { background: #713f12; color: #fde68a; }

.msg-body { white-space: pre-wrap; }
.msg-transcript { font-style: italic; color: var(--text-muted); margin-top: .35rem; font-size: .9rem; }
.msg-summary {
  margin-top: .5rem;
  padding: .5rem .7rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: .87rem;
}
.msg-summary .ki { color: var(--primary); font-weight: 600; font-size: .75rem; }
.tags { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .5rem; }
.tag {
  font-size: .73rem;
  background: var(--primary-soft);
  color: var(--primary);
  padding: .1rem .55rem;
  border-radius: 999px;
}

/* ---------- Kategorie-Badge ---------- */
.cat-badge {
  font-size: .7rem;
  font-weight: 600;
  padding: .1rem .55rem;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid transparent;
}

/* ---------- Erkannt-Block (KI-Extraktion) ---------- */
.extraction {
  margin-top: .5rem;
  padding: .55rem .7rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius-sm);
  font-size: .85rem;
  display: flex;
  flex-direction: column;
  gap: .3rem;
}
.ex-row { display: flex; gap: .5rem; align-items: baseline; }
.ex-label {
  flex: 0 0 auto;
  min-width: 6.5rem;
  color: var(--text-muted);
  font-weight: 600;
  font-size: .73rem;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.ex-val { color: var(--text); word-break: break-word; }
.ex-tasks {
  margin: 0;
  padding-left: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: .15rem;
}
.ex-tasks li { color: var(--text); }

/* ---------- Dateien ---------- */
.files-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .9rem; }
.file-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  display: flex;
  flex-direction: column;
}
.file-card .thumb {
  aspect-ratio: 4 / 3;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  overflow: hidden;
}
.file-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.file-card .fc-info { padding: .55rem .7rem; font-size: .78rem; }
.file-card .fc-name { font-weight: 600; word-break: break-word; }
.file-card .fc-meta { color: var(--text-muted); }
.file-card a { color: var(--primary); text-decoration: none; }

/* ---------- Preisanfragen ---------- */
.pr-row { display: grid; grid-template-columns: 1fr 1fr; gap: .55rem; }
.prices { display: flex; flex-direction: column; gap: .7rem; }
.pr-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .85rem 1rem;
  background: var(--surface);
}
.pr-card .pr-top { display: flex; justify-content: space-between; gap: .5rem; align-items: center; }
.pr-card .pr-supplier { font-weight: 600; }
.pr-status {
  font-size: .72rem;
  font-weight: 600;
  padding: .1rem .55rem;
  border-radius: 999px;
  background: var(--surface-2);
}
.pr-status.offen { background: #fef3c7; color: #b45309; }
.pr-status.versendet { background: #dcfce7; color: #15803d; }
[data-theme="dark"] .pr-status.offen { background: #713f12; color: #fcd34d; }
[data-theme="dark"] .pr-status.versendet { background: #14532d; color: #86efac; }

/* ---------- Chat ---------- */
.chat-card { display: flex; flex-direction: column; }
.chat-log {
  display: flex;
  flex-direction: column;
  gap: .6rem;
  margin: .8rem 0;
  max-height: 420px;
  overflow-y: auto;
  padding: .2rem;
}
.bubble {
  max-width: 80%;
  padding: .6rem .85rem;
  border-radius: 14px;
  font-size: .92rem;
  white-space: pre-wrap;
}
.bubble.me { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.bubble.bot { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble.bot.loading { color: var(--text-muted); font-style: italic; }
.chat-form { display: flex; gap: .5rem; }
.chat-form input { flex: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: .65rem 1.1rem;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  z-index: 50;
  font-size: .9rem;
  max-width: 90vw;
}
.toast.err { background: var(--danger); color: #fff; }

/* ---------- Hinweise / Leerzustände ---------- */
.note-empty { color: var(--text-muted); text-align: center; padding: 2rem 1rem; }
.error-box {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  padding: .7rem .9rem;
  font-size: .9rem;
}
[data-theme="dark"] .error-box { background: #450a0a; border-color: #7f1d1d; color: #fca5a5; }

/* ---------- Responsiv ---------- */
@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: none; }
  .site-list { max-height: 320px; }
  .pr-row { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .topbar { padding: .6rem .8rem; }
  .layout { padding: .8rem; }
  .bubble { max-width: 92%; }
}
