/* ServicePilot AI — Styles */

:root {
  color-scheme: light;
  --page-bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fcfcfb;
  --ink: #0b0b0b;
  --ink-secondary: #52514e;
  --ink-muted: #898781;
  --border: rgba(11,11,11,0.10);
  --grid: #e1e0d9;

  --brand: #2a78d6;
  --brand-dark: #184f95;
  --brand-50: #eaf2fc;
  --brand-100: #cde2fb;

  --status-good: #0ca30c;
  --status-good-bg: #e7f7e7;
  --status-warning: #c98500;
  --status-warning-bg: #fff4e0;
  --status-serious: #d1572c;
  --status-serious-bg: #fdece4;
  --status-critical: #d03b3b;
  --status-critical-bg: #fbe8e8;
  --status-neutral: #52514e;
  --status-neutral-bg: #ececeb;

  --sidebar-bg: #121728;
  --sidebar-bg-active: #1c2340;
  --sidebar-ink: #c6cbe0;
  --sidebar-ink-active: #ffffff;
  --sidebar-muted: #6b7190;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(11,11,11,0.06);
  --shadow-md: 0 4px 16px rgba(11,11,11,0.08);
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--page-bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}
h1, h2, h3, h4 { margin: 0 0 4px; font-weight: 650; letter-spacing: -0.01em; }
p { margin: 0 0 8px; }
button { font-family: var(--font); cursor: pointer; }
a { color: var(--brand); }
::selection { background: var(--brand-100); }

.hidden { display: none !important; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 236px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-ink);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 20px;
  color: #fff;
}
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, var(--brand), #6da7ec);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; color: #fff;
}
.brand-name { font-size: 15px; font-weight: 700; line-height: 1.2; }
.brand-sub { font-size: 11px; color: var(--sidebar-muted); }

.nav-group { margin-bottom: 14px; }
.nav-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--sidebar-muted); padding: 8px 12px 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--sidebar-ink); text-decoration: none; font-size: 13.5px;
  border: none; background: transparent; width: 100%; text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: var(--sidebar-bg-active); color: var(--sidebar-ink-active); font-weight: 600; }
.nav-icon { width: 18px; text-align: center; opacity: .9; font-size: 14px; display: inline-flex; }
.nav-icon svg { width: 16px; height: 16px; }
.nav-badge {
  margin-left: auto; background: var(--status-critical); color: #fff;
  font-size: 10.5px; font-weight: 700; padding: 1px 6px; border-radius: 999px;
}

.sidebar-footer {
  margin-top: auto; padding: 10px 12px; border-top: 1px solid rgba(255,255,255,0.08);
  display: flex; align-items: center; gap: 8px;
}
.avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--brand);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.sidebar-footer-text { font-size: 12px; color: var(--sidebar-ink); line-height: 1.3; }
.sidebar-footer-sub { color: var(--sidebar-muted); font-size: 11px; }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 28px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar-title { font-size: 17px; font-weight: 700; }
.topbar-sub { font-size: 12.5px; color: var(--ink-muted); margin-top: 2px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.view { display: none; padding: 24px 28px 48px; }
.view.active { display: block; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--ink); font-size: 13px; font-weight: 600;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--page-bg); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--page-bg); }
.btn-danger { color: var(--status-critical); border-color: var(--status-critical-bg); background: var(--status-critical-bg); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-icon { width: 32px; height: 32px; padding: 0; justify-content: center; border-radius: 8px; }

/* ---------- Cards / KPI ---------- */
.grid { display: grid; gap: 16px; }
.kpi-row { grid-template-columns: repeat(4, 1fr); margin-bottom: 20px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 18px 20px; box-shadow: var(--shadow-sm);
}
.card-title { font-size: 13px; font-weight: 650; margin-bottom: 2px; }
.card-sub { font-size: 12px; color: var(--ink-muted); }

.kpi-card { display: flex; flex-direction: column; gap: 6px; }
.kpi-label { font-size: 12px; color: var(--ink-secondary); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.kpi-value { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.kpi-meta { font-size: 12px; color: var(--ink-muted); }
.kpi-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }

.section-row { display: flex; align-items: baseline; justify-content: space-between; margin: 28px 0 12px; }
.section-row h2 { font-size: 15px; }
.section-row:first-child { margin-top: 0; }

.two-col { grid-template-columns: 1.3fr 1fr; align-items: start; }
.three-col { grid-template-columns: repeat(3, 1fr); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 650; padding: 3px 9px; border-radius: 999px;
  white-space: nowrap;
}
.badge-dot { width: 6px; height: 6px; border-radius: 50%; }
.badge-offen { background: var(--brand-50); color: var(--brand-dark); }
.badge-offen .badge-dot { background: var(--brand); }
.badge-in_bearbeitung { background: var(--status-warning-bg); color: var(--status-warning); }
.badge-in_bearbeitung .badge-dot { background: var(--status-warning); }
.badge-abgeschlossen { background: var(--status-good-bg); color: var(--status-good); }
.badge-abgeschlossen .badge-dot { background: var(--status-good); }
.badge-kritisch { background: var(--status-critical-bg); color: var(--status-critical); }
.badge-kritisch .badge-dot { background: var(--status-critical); }

.prio-niedrig { color: var(--ink-muted); }
.prio-mittel { color: var(--brand-dark); }
.prio-hoch { color: var(--status-serious); }
.prio-kritisch { color: var(--status-critical); font-weight: 700; }

.pill {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px;
  border-radius: 999px; background: var(--page-bg); color: var(--ink-secondary); border: 1px solid var(--border);
}
.pill-ai { background: var(--brand-50); color: var(--brand-dark); border-color: var(--brand-100); }
.tag-overdue { background: var(--status-critical-bg); color: var(--status-critical); }

/* ---------- Tables ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--ink-muted); padding: 10px 16px; border-bottom: 1px solid var(--border); font-weight: 650;
  background: var(--surface-2);
}
tbody td { padding: 12px 16px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.row-click { cursor: pointer; }
tbody tr.row-click:hover { background: var(--brand-50); }
.cell-main { font-weight: 600; }
.cell-sub { color: var(--ink-muted); font-size: 12px; }

/* ---------- Filters ---------- */
.filter-bar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; align-items: center; }
.filter-bar select, .filter-bar input[type="text"], .filter-bar input[type="search"] {
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 7px 10px;
  font-size: 12.5px; background: var(--surface); color: var(--ink); font-family: var(--font);
}
.filter-bar input[type="search"] { min-width: 220px; }
.search-wrap { position: relative; }

/* ---------- Forms ---------- */
label { display: block; font-size: 12px; font-weight: 650; color: var(--ink-secondary); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 10px; font-size: 13px; font-family: var(--font); background: var(--surface); color: var(--ink);
}
textarea { resize: vertical; min-height: 90px; }
.field { margin-bottom: 14px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tab-btn {
  padding: 9px 14px; border: none; background: transparent; font-size: 13px; font-weight: 600;
  color: var(--ink-muted); border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab-btn.active { color: var(--brand-dark); border-bottom-color: var(--brand); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- Email view ---------- */
.email-layout { display: grid; grid-template-columns: 340px 1fr; gap: 16px; align-items: start; }
.email-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm); max-height: 74vh; overflow-y: auto; }
.email-item { padding: 12px 14px; border-bottom: 1px solid var(--grid); cursor: pointer; }
.email-item:hover { background: var(--brand-50); }
.email-item.active { background: var(--brand-50); border-left: 3px solid var(--brand); }
.email-item-top { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--ink-muted); margin-bottom: 3px; }
.email-item-from { font-weight: 650; font-size: 13px; color: var(--ink); }
.email-item-subject { font-size: 12.5px; color: var(--ink-secondary); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.email-item.processed { opacity: .55; }

.email-detail { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow-sm); }
.email-detail-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; border-bottom: 1px solid var(--grid); padding-bottom: 14px; }
.email-body-text { white-space: pre-wrap; font-size: 13px; background: var(--surface-2); border: 1px solid var(--grid); border-radius: var(--radius-md); padding: 14px; margin: 10px 0 16px; max-height: 260px; overflow-y: auto; }
.email-paste { margin-top: 10px; }

.ai-panel {
  background: linear-gradient(180deg, var(--brand-50), var(--surface) 40%);
  border: 1px solid var(--brand-100); border-radius: var(--radius-lg); padding: 16px 18px; margin-top: 14px;
}
.ai-panel-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-weight: 700; color: var(--brand-dark); font-size: 13px; }
.ai-chip { background: var(--brand); color: #fff; font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 999px; text-transform: uppercase; letter-spacing: .03em; }
.ai-fields { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 18px; margin-bottom: 12px; }
.ai-field-label { font-size: 11px; text-transform: uppercase; letter-spacing: .03em; color: var(--ink-muted); font-weight: 650; }
.ai-field-value { font-size: 13.5px; font-weight: 600; margin-top: 1px; }
.ai-field-value.empty { color: var(--ink-muted); font-weight: 500; font-style: italic; }
.ai-note { font-size: 12px; color: var(--ink-secondary); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; margin-top: 6px; }

.dupe-alert, .recur-alert {
  display: flex; gap: 8px; align-items: flex-start;
  background: var(--status-warning-bg); border: 1px solid #f3d495; color: #7a5600;
  border-radius: var(--radius-md); padding: 10px 12px; font-size: 12.5px; margin-top: 10px;
}
.similar-case { border: 1px solid var(--border); border-radius: var(--radius-md); padding: 10px 12px; margin-top: 8px; background: var(--surface); }
.similar-case-head { display: flex; justify-content: space-between; font-size: 12.5px; font-weight: 650; }
.similar-case-solution { font-size: 12.5px; color: var(--ink-secondary); margin-top: 4px; }

/* ---------- Phone / Kundenakte ---------- */
.phone-hero { display: flex; align-items: center; gap: 16px; padding: 18px 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); margin-bottom: 20px; box-shadow: var(--shadow-sm); }
.phone-ring-icon { width: 46px; height: 46px; border-radius: 50%; background: var(--brand-50); display: flex; align-items: center; justify-content: center; font-size: 20px; color: var(--brand); }
.incoming-call-banner {
  display: none; align-items: center; justify-content: space-between; gap: 14px;
  background: var(--status-good-bg); border: 1px solid #b7e3b7; border-radius: var(--radius-lg);
  padding: 14px 18px; margin-bottom: 18px;
}
.incoming-call-banner.show { display: flex; }
.pulse-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--status-good); animation: pulse 1.2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(12,163,12,.5); } 70% { box-shadow: 0 0 0 9px rgba(12,163,12,0); } 100% { box-shadow: 0 0 0 0 rgba(12,163,12,0); } }

.customer-card-header { display: flex; justify-content: space-between; align-items: flex-start; }
.customer-card-header h2 { font-size: 18px; }
.customer-meta-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 20px; margin-top: 12px; font-size: 12.5px; }
.customer-meta-grid div span { color: var(--ink-muted); display: block; font-size: 11px; }

.contact-log-item { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--grid); font-size: 12.5px; }
.contact-log-item:last-child { border-bottom: none; }
.contact-log-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--brand); margin-top: 5px; flex-shrink: 0; }

.transcript-picker { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.transcript-chip { font-size: 11.5px; padding: 5px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); }
.transcript-chip:hover { background: var(--page-bg); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(11,11,11,0.45); display: none;
  align-items: flex-start; justify-content: center; z-index: 100; padding: 4vh 16px; overflow-y: auto;
}
.modal-overlay.show { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius-lg); width: 100%; max-width: 760px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25); margin-bottom: 4vh;
}
.modal.modal-lg { max-width: 920px; }
.modal-header { display: flex; justify-content: space-between; align-items: flex-start; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 20px 22px; max-height: 72vh; overflow-y: auto; }
.modal-footer { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.modal-close { background: none; border: none; font-size: 18px; color: var(--ink-muted); padding: 4px 8px; border-radius: 6px; }
.modal-close:hover { background: var(--page-bg); }

/* ---------- Complaint detail ---------- */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 20px; margin-bottom: 16px; font-size: 13px; }
.detail-grid .k { color: var(--ink-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
.detail-grid .v { font-weight: 600; margin-top: 1px; }
.note-item { border-left: 2px solid var(--grid); padding: 4px 0 4px 12px; margin-bottom: 8px; font-size: 12.5px; }
.note-item .note-meta { color: var(--ink-muted); font-size: 11px; margin-bottom: 2px; }
.step-option { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 6px; font-size: 12.5px; cursor: pointer; }
.step-option:hover { background: var(--brand-50); }
.step-option input { width: auto; }
.reply-draft-box { white-space: pre-wrap; font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--grid); border-radius: var(--radius-md); padding: 14px; min-height: 160px; }

/* ---------- Tasks ---------- */
.task-item { display: flex; align-items: flex-start; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--grid); }
.task-item:last-child { border-bottom: none; }
.task-item.done .task-title { text-decoration: line-through; color: var(--ink-muted); }
.task-check { width: 18px; height: 18px; border-radius: 5px; border: 1.5px solid var(--border); flex-shrink: 0; margin-top: 1px; background: var(--surface); }
.task-check.checked { background: var(--brand); border-color: var(--brand); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 11px; }
.task-title { font-size: 13px; font-weight: 600; }
.task-meta { font-size: 11.5px; color: var(--ink-muted); margin-top: 2px; }

/* ---------- Charts (single-hue magnitude bars, per dataviz guidance) ---------- */
.bar-chart-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.bar-chart-label { width: 150px; flex-shrink: 0; font-size: 12.5px; color: var(--ink-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-chart-track { flex: 1; background: var(--page-bg); border-radius: 5px; height: 16px; position: relative; overflow: hidden; }
.bar-chart-fill { height: 100%; background: var(--brand); border-radius: 5px; transition: width .4s ease; }
.bar-chart-value { width: 34px; text-align: right; font-size: 12.5px; font-weight: 650; color: var(--ink); flex-shrink: 0; }

.trend-wrap { width: 100%; overflow-x: auto; }
.trend-svg circle { fill: var(--brand); }
.trend-svg circle:hover { fill: var(--brand-dark); }
.trend-svg .trend-line { fill: none; stroke: var(--brand); stroke-width: 2; }
.trend-svg .trend-axis { stroke: var(--grid); stroke-width: 1; }
.trend-svg text { font-size: 10px; fill: var(--ink-muted); font-family: var(--font); }

.legend-row { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 10px; font-size: 12px; color: var(--ink-secondary); }
.legend-row span { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot { width: 9px; height: 9px; border-radius: 3px; }

.insight-box { background: var(--brand-50); border: 1px solid var(--brand-100); border-radius: var(--radius-md); padding: 14px 16px; font-size: 13px; color: var(--ink); line-height: 1.6; }

/* ---------- Knowledge base ---------- */
.kb-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px 18px; box-shadow: var(--shadow-sm); margin-bottom: 12px; }
.kb-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 6px; }
.kb-card-title { font-weight: 650; font-size: 13.5px; }
.kb-solution { font-size: 12.5px; color: var(--ink-secondary); background: var(--status-good-bg); border-radius: var(--radius-sm); padding: 8px 10px; margin-top: 8px; }
.kb-solution-label { color: var(--status-good); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; margin-bottom: 2px; }

/* ---------- Toast ---------- */
.toast-stack { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--ink); color: #fff; padding: 11px 16px; border-radius: var(--radius-md);
  font-size: 12.5px; box-shadow: var(--shadow-md); display: flex; align-items: center; gap: 8px;
  animation: toast-in .18s ease;
}
.toast.toast-success { background: #0d3b0d; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: translateY(0);} }

.empty-state { text-align: center; padding: 40px 20px; color: var(--ink-muted); font-size: 13px; }
.muted { color: var(--ink-muted); }
.small { font-size: 12px; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.flex { display: flex; }
.gap-8 { gap: 8px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }

@media (max-width: 1100px) {
  .email-layout { grid-template-columns: 1fr; }
  .kpi-row, .three-col { grid-template-columns: repeat(2, 1fr); }
  .two-col { grid-template-columns: 1fr; }
}
