/* ==========================================================
   R+P Lackierung — Büro-Autopilot
   Palette identisch zur Website: Asphalt + Flamme.
   Dark Mode only (Demo-Tool, kein Light-Mode nötig).
   ========================================================== */

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  color-scheme: dark;

  --color-bg:        #0a0a10;
  --color-surface:   #100e18;
  --color-card:      #1c1828;
  --color-card-hi:   #221d32;
  --color-border:    #2e2e42;
  --color-accent:    #e88a2a;
  --color-accent-dim: rgba(232, 138, 42, 0.14);
  --color-violet:    #6a4a90;
  --color-teal:      #9080c0;
  --color-warm:      #e03828;
  --color-warm-dim:  rgba(224, 56, 40, 0.14);
  --color-success:   #4fae82;
  --color-success-dim: rgba(79, 174, 130, 0.14);
  --color-light:     #f0ecf0;
  --color-muted:     #9490a0;
  --color-dim:       #6d6980;

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;

  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-8: 3rem;

  --sidebar-w: 268px;
  --transition: 0.2s ease;
}

html { font-size: 100%; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.55;
  color: var(--color-light);
  background: var(--color-bg);
  min-height: 100vh;
}

button { font: inherit; cursor: pointer; }
textarea { font: inherit; }

[hidden] { display: none !important; }

.muted { color: var(--color-muted); }
.mono { font-family: var(--mono); font-size: 0.85em; }

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

/* ============ Sidebar ============ */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  padding: var(--space-5) var(--space-4);
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-2) var(--space-6);
}

.brand-mark {
  height: 42px;
  width: auto;
  flex-shrink: 0;
  filter: drop-shadow(0 0 14px rgba(232, 138, 42, 0.35));
}

.brand-text { display: flex; flex-direction: column; line-height: 1.3; }
.brand-text strong { font-size: 0.95rem; }
.brand-text span { font-size: 0.78rem; color: var(--color-muted); }

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0.7rem var(--space-3);
  border: none;
  background: transparent;
  color: var(--color-muted);
  border-radius: var(--radius-sm);
  text-align: left;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
}

.nav-item svg { width: 19px; height: 19px; fill: currentColor; flex-shrink: 0; }

@media (hover: hover) {
  .nav-item:hover { background: var(--color-card); color: var(--color-light); }
}

.nav-item.is-active {
  background: var(--color-accent-dim);
  color: var(--color-accent);
}

.sidebar-foot {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border-top: 1px solid var(--color-border);
  margin-top: var(--space-4);
}

.sidebar-foot div { display: flex; flex-direction: column; line-height: 1.3; }
.sidebar-foot strong { font-size: 0.82rem; }
.sidebar-foot span { font-size: 0.75rem; color: var(--color-muted); }

.dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-live {
  background: var(--color-success);
  box-shadow: 0 0 0 3px var(--color-success-dim);
  animation: pulse 2s infinite;
}
@media (prefers-reduced-motion: reduce) { .dot-live { animation: none; } }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ============ Main / topbar ============ */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  background: rgba(10, 10, 16, 0.85);
  backdrop-filter: blur(8px);
  z-index: 5;
}

.topbar-title h1 { font-size: 1.35rem; font-weight: 650; }
.topbar-title p { color: var(--color-muted); font-size: 0.88rem; margin-top: 2px; }

.topbar-meta { display: flex; align-items: center; gap: var(--space-4); }

.user-chip { display: flex; align-items: center; gap: var(--space-3); }
.user-chip-text { display: flex; flex-direction: column; line-height: 1.25; }
.user-chip-text strong { font-size: 0.85rem; }
.user-chip-text span { font-size: 0.75rem; color: var(--color-muted); }

.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--color-border);
  flex-shrink: 0;
}

.content {
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  max-width: 1280px;
  width: 100%;
}

/* ============ View switching ============ */
.view { display: none; flex-direction: column; gap: var(--space-5); }
.view.is-active { display: flex; }

/* ============ Badges ============ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-neutral { background: var(--color-card); color: var(--color-muted); border: 1px solid var(--color-border); }
.badge-success { background: var(--color-success-dim); color: var(--color-success); }
.badge-warn    { background: var(--color-accent-dim); color: var(--color-accent); }
.badge-danger  { background: var(--color-warm-dim); color: var(--color-warm); }

/* ============ KPI grid (Overview) ============ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4);
}

.kpi-card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-5);
  text-align: left;
  cursor: pointer;
  transition: transform var(--transition), border-color var(--transition);
}
@media (hover: hover) {
  .kpi-card:hover { border-color: var(--color-accent); transform: translateY(-2px); }
}

.kpi-icon {
  width: 38px; height: 38px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: var(--space-4);
}
.kpi-icon svg { width: 19px; height: 19px; fill: currentColor; }
.icon-accent { background: var(--color-accent-dim); color: var(--color-accent); }
.icon-teal   { background: rgba(144, 128, 192, 0.16); color: var(--color-teal); }
.icon-warm   { background: var(--color-warm-dim); color: var(--color-warm); }
.icon-violet { background: rgba(106, 74, 144, 0.22); color: var(--color-teal); }

.kpi-value { font-size: 1.9rem; font-weight: 700; letter-spacing: -0.01em; }
.kpi-label { color: var(--color-muted); font-size: 0.85rem; margin-top: 4px; }
.kpi-trend { font-size: 0.78rem; margin-top: var(--space-3); font-weight: 600; }
.kpi-trend.up { color: var(--color-success); }
.kpi-trend.warn { color: var(--color-accent); }

/* ============ Panels ============ */
.panel {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.panel-head h2 { font-size: 1.05rem; font-weight: 650; }

.panel h2 { font-size: 1.05rem; font-weight: 650; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-5);
  align-items: start;
}

/* ============ Overview cards ============ */
.overview-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4);
  margin-top: var(--space-2);
}
.overview-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-5);
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color var(--transition);
}
@media (hover: hover) { .overview-card:hover { border-color: var(--color-teal); } }
.oc-num { color: var(--color-dim); font-family: var(--mono); font-size: 0.8rem; }
.overview-card strong { font-size: 0.95rem; }
.overview-card span:last-child { color: var(--color-muted); font-size: 0.83rem; line-height: 1.45; }

/* ============ Buttons ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.75rem 1.25rem;
  font-size: 0.9rem;
  font-weight: 600;
  min-height: 44px;
  transition: filter var(--transition), background var(--transition), opacity var(--transition);
}
.btn svg { width: 18px; height: 18px; fill: currentColor; }
.btn:disabled { opacity: 0.55; cursor: default; }

.btn-primary { background: var(--color-accent); color: #1c1206; }
@media (hover: hover) { .btn-primary:hover:not(:disabled) { filter: brightness(1.08); } }

.btn-secondary { background: var(--color-surface); color: var(--color-light); border: 1px solid var(--color-border); }
@media (hover: hover) { .btn-secondary:hover:not(:disabled) { border-color: var(--color-teal); } }

.btn-block { width: 100%; }

.action-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

/* ============ Feature 1: Dictation ============ */
.waveform {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 48px;
  opacity: 0.35;
}
.waveform span {
  width: 4px;
  height: 8px;
  border-radius: 2px;
  background: var(--color-teal);
  transition: height 0.2s ease;
}
.waveform.is-active { opacity: 1; }
.waveform.is-active span {
  animation: wave 0.9s ease-in-out infinite;
}
.waveform span:nth-child(2n) { animation-delay: 0.1s; }
.waveform span:nth-child(3n) { animation-delay: 0.2s; }
.waveform span:nth-child(4n) { animation-delay: 0.05s; }
.waveform span:nth-child(5n) { animation-delay: 0.3s; }
@keyframes wave {
  0%, 100% { height: 8px; }
  50% { height: 32px; }
}
@media (prefers-reduced-motion: reduce) {
  .waveform.is-active span { animation: none; height: 20px; }
}

.transcript-box {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-4);
  min-height: 90px;
}
.transcript-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--color-dim); margin-bottom: 6px; }
.transcript-box p { font-size: 0.95rem; line-height: 1.6; }
.transcript-box .placeholder { color: var(--color-dim); font-style: italic; }
.is-typing::after {
  content: "▍";
  color: var(--color-accent);
  animation: blink 0.9s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.ai-steps { display: flex; flex-direction: column; gap: var(--space-3); list-style: none; min-height: 90px; }
.ai-steps li {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  font-size: 0.88rem;
  color: var(--color-dim);
}
.ai-steps li.is-done { color: var(--color-light); }
.ai-steps li:first-child { color: var(--color-light); }
.step-spinner {
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-accent);
  flex-shrink: 0;
  margin-top: 2px;
  animation: spin 0.7s linear infinite;
}
@media (prefers-reduced-motion: reduce) { .step-spinner { animation: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
.ai-steps li.is-done::before {
  content: "✓";
  color: var(--color-success);
  font-weight: 700;
  flex-shrink: 0;
}

/* ============ Unsicherheit / Rückfragen ============ */
.clarify-box {
  display: flex;
  gap: var(--space-3);
  background: var(--color-accent-dim);
  border: 1px solid rgba(232, 138, 42, 0.4);
  border-radius: var(--radius-sm);
  padding: var(--space-4);
}
.clarify-icon {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--color-accent);
  color: #1c1206;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
}
.clarify-body { display: flex; flex-direction: column; gap: 4px; }
.clarify-body strong { font-size: 0.9rem; }
.clarify-options { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-2); }
.clarify-resolved { color: var(--color-success); font-size: 0.88rem; font-weight: 600; padding: var(--space-2) 0; }

.btn-sm { min-height: 36px; padding: 0.5rem 0.9rem; font-size: 0.82rem; }

/* ============ Invoice preview ============ */
.invoice {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}
.invoice-head { display: flex; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; }
.invoice-head > div:first-child { display: flex; flex-direction: column; gap: 2px; }
.invoice-meta { display: flex; flex-direction: column; gap: 4px; text-align: right; font-size: 0.88rem; }
.invoice-customer { display: flex; flex-direction: column; gap: 2px; padding-top: var(--space-3); border-top: 1px dashed var(--color-border); }

.invoice-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.invoice-table th {
  text-align: left;
  color: var(--color-muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--color-border);
}
.invoice-table td { padding: 0.65rem 0.6rem; border-bottom: 1px solid var(--color-border); }
.invoice-table th:nth-child(3), .invoice-table td:nth-child(3),
.invoice-table th:nth-child(4), .invoice-table td:nth-child(4),
.invoice-table th:nth-child(5), .invoice-table td:nth-child(5) { text-align: right; }

.invoice-sums { align-self: flex-end; min-width: 240px; display: flex; flex-direction: column; gap: 6px; }
.invoice-sums div { display: flex; justify-content: space-between; font-size: 0.88rem; color: var(--color-muted); }
.invoice-sums .total { border-top: 1px solid var(--color-border); margin-top: 4px; padding-top: 8px; font-size: 1rem; color: var(--color-light); }
.invoice-sums .total strong { color: var(--color-accent); }

/* ============ Feature 2: Receipts ============ */
.receipt-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4); }
.receipt-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  transition: border-color var(--transition), background var(--transition);
}
.receipt-icon { width: 26px; height: 26px; fill: var(--color-teal); margin-bottom: var(--space-2); }
@media (hover: hover) { .receipt-card:hover { border-color: var(--color-teal); } }
.receipt-card.is-active { border-color: var(--color-accent); background: var(--color-accent-dim); }
.receipt-card.is-active .receipt-icon { fill: var(--color-accent); }
.receipt-card-flag { align-self: flex-start; margin-top: 4px; }

/* Fotografierter Beleg – Mock-Vorschau des Originalbelegs */
.scan-photo:empty { display: none; }
.scan-tag { font-size: 0.75rem; color: var(--color-dim); margin-bottom: var(--space-2); }
.scan-paper {
  background: #e8e4da;
  color: #26221c;
  border-radius: var(--radius-sm);
  padding: var(--space-4);
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.7;
  transform: rotate(-0.6deg);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}
.scan-line-title { font-weight: 700; margin-bottom: 2px; }
.scan-line-dim { opacity: 0.45; letter-spacing: 0.05em; }
.scan-line-total { font-weight: 700; margin-top: 2px; padding-top: 4px; border-top: 1px dashed rgba(38, 34, 28, 0.35); }

.field-list { display: flex; flex-direction: column; gap: 0; margin-top: var(--space-4); }
.field-list dt { font-size: 0.75rem; color: var(--color-dim); text-transform: uppercase; letter-spacing: 0.04em; margin-top: var(--space-3); }
.field-list dd { font-size: 0.98rem; font-weight: 600; padding: 4px 6px; margin-left: -6px; border-radius: 6px; }
.field-list dd.is-highlighting { background: var(--color-accent-dim); color: var(--color-accent); }
.field-list dd.is-uncertain {
  color: var(--color-accent);
  text-decoration: underline wavy rgba(232, 138, 42, 0.6);
  text-underline-offset: 3px;
}

#receipt-confirm:empty { display: none; }
#receipt-confirm { margin-top: var(--space-4); }

.match-box { min-height: 70px; }
.match-row {
  display: flex; justify-content: space-between; gap: var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
  font-size: 0.85rem;
}
.match-result { margin-top: var(--space-3); font-size: 0.88rem; font-weight: 600; }
.match-result.ok { color: var(--color-success); }
.match-result.pending { color: var(--color-accent); }

.status-line { display: flex; align-items: center; justify-content: space-between; margin: var(--space-4) 0; }

/* ============ Feature 3: Claims ============ */
.doc-mock {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-5);
  font-size: 0.9rem;
}
.doc-head { display: flex; flex-direction: column; gap: 2px; margin-bottom: var(--space-3); }
.doc-row { display: flex; justify-content: space-between; padding: 3px 0; font-size: 0.85rem; }
.doc-table { width: 100%; border-collapse: collapse; margin-top: var(--space-4); font-size: 0.85rem; }
.doc-table th {
  text-align: left; color: var(--color-muted); font-weight: 600; font-size: 0.72rem;
  text-transform: uppercase; letter-spacing: 0.04em;
  padding: 0.5rem 0.4rem; border-bottom: 1px solid var(--color-border);
}
.doc-table td { padding: 0.6rem 0.4rem; border-bottom: 1px solid var(--color-border); }
.doc-table th:nth-child(2), .doc-table td:nth-child(2),
.doc-table th:nth-child(3), .doc-table td:nth-child(3) { text-align: right; }
.doc-table tr.is-cut .approved-cell { color: var(--color-warm); }
.doc-table tr.is-ok .approved-cell { color: var(--color-success); }
.cut-tag {
  display: inline-block;
  background: var(--color-warm-dim);
  color: var(--color-warm);
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 2px 7px;
  margin-left: 6px;
}

.claim-summary { display: flex; flex-direction: column; gap: var(--space-4); }
.cut-reasons { list-style: none; display: flex; flex-direction: column; gap: var(--space-3); }
.cut-reasons li { display: flex; flex-direction: column; gap: 2px; padding-left: var(--space-4); border-left: 2px solid var(--color-warm); }
.cut-reasons li span { font-size: 0.83rem; color: var(--color-muted); }
.cut-total {
  font-size: 0.98rem;
  padding: var(--space-3) var(--space-4);
  background: var(--color-warm-dim);
  border-radius: var(--radius-sm);
}
.cut-total strong { color: var(--color-warm); }

.mail-field { margin-top: var(--space-2); }
.mail-subject {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.6rem var(--space-3);
  font-size: 0.88rem;
  margin-top: 4px;
}
.mail-body {
  width: 100%;
  margin-top: var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-4);
  color: var(--color-light);
  font-size: 0.88rem;
  line-height: 1.6;
  resize: vertical;
}
.mail-body:focus { outline: none; border-color: var(--color-teal); }

/* ============ Feature 4: HU/TÜV ============ */
.table-wrap { overflow-x: auto; }
.hu-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; min-width: 640px; }
.hu-table th {
  text-align: left; color: var(--color-muted); font-weight: 600; font-size: 0.75rem;
  text-transform: uppercase; letter-spacing: 0.04em;
  padding: 0.6rem 0.6rem; border-bottom: 1px solid var(--color-border);
}
.hu-table td { padding: 0.75rem 0.6rem; border-bottom: 1px solid var(--color-border); }
.hu-msg-cell { display: flex; align-items: center; gap: 6px; }

.hu-log { list-style: none; display: flex; flex-direction: column; gap: var(--space-4); }
.hu-log li { display: flex; flex-direction: column; gap: 2px; padding-bottom: var(--space-4); border-bottom: 1px solid var(--color-border); }
.hu-log li:last-child { border-bottom: none; padding-bottom: 0; }
.hu-log li p { font-size: 0.86rem; color: var(--color-muted); margin-top: 4px; font-style: italic; }
.hu-log li.hu-log-error { padding-left: var(--space-4); border-left: 2px solid var(--color-warm); }
.hu-log li.hu-log-error p { color: var(--color-warm); font-style: normal; }

/* ============ Responsive ============ */
@media (max-width: 1024px) {
  .kpi-grid, .overview-cards { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .receipt-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 720px) {
  .sidebar {
    position: fixed;
    inset: auto auto 0 0;
    width: 100%;
    height: auto;
    flex-direction: row;
    align-items: center;
    padding: var(--space-3);
    border-right: none;
    border-top: 1px solid var(--color-border);
    z-index: 10;
    padding-bottom: max(var(--space-3), env(safe-area-inset-bottom));
  }
  .brand, .sidebar-foot { display: none; }
  .nav { flex-direction: row; justify-content: space-around; width: 100%; }
  .nav-item { flex-direction: column; gap: 4px; font-size: 0.68rem; padding: 0.4rem; }
  .main { padding-bottom: 72px; }
  .content { padding: var(--space-4); }
  .topbar { padding: var(--space-4); flex-wrap: wrap; }
  .kpi-grid, .overview-cards, .receipt-grid { grid-template-columns: 1fr; }
  .invoice-head { flex-direction: column; }
  .invoice-meta { text-align: left; }
}

@media (max-width: 480px) {
  .user-chip-text { display: none; }
}
