/* === CSS VARIABLES === */
:root {
  --bg-primary: #F4F0EA;
  --bg-cream: #FAF7F2;
  --bg-sage: #E8EDE5;
  --bg-white: #FFFFFF;
  --bg-dark: #050B14;
  --bg-dark-blue: #050E1C;

  --accent-blue: #4A7FA7;
  --accent-blue-dark: #2C5F8A;
  --accent-blue-glow: rgba(74, 127, 167, 0.15);
  --accent-blue-light: rgba(74, 127, 167, 0.08);

  --cta-orange-start: #FF8C55;
  --cta-orange-end: #FF5C1A;
  --cta-gradient: linear-gradient(135deg, #FF8C55 0%, #FF5C1A 100%);
  --cta-shadow: 0 4px 16px rgba(255, 92, 26, 0.3);

  --text-dark: #1A1F2E;
  --text-medium: #4A4F5E;
  --text-light: #8A8F9E;
  --text-on-dark: #F4F0EA;

  --success: #22C55E;
  --success-light: #DCFCE7;
  --warning: #D97706;
  --warning-light: #FEF3C7;
  --error: #DC2626;

  --border-soft: rgba(0, 0, 0, 0.08);
  --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.06);
  --shadow-card-hover: 0 12px 40px rgba(0, 0, 0, 0.1);
  --shadow-premium: 0 20px 60px rgba(0, 0, 0, 0.08);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --radius-pill: 999px;

  --font-display: 'DM Serif Display', Georgia, serif;
  --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* === RESET === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-dark);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a { color: var(--accent-blue); text-decoration: none; }
img { display: block; max-width: 100%; }
button { font-family: var(--font-body); }

/* === GLOBAL BUTTONS === */
.cta-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: var(--cta-gradient);
  color: white;
  border: none;
  border-radius: var(--radius-pill);
  padding: 0.875rem 2rem;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.25s;
  box-shadow: var(--cta-shadow);
  font-family: var(--font-body);
  text-decoration: none;
  white-space: nowrap;
}
.cta-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(255, 92, 26, 0.4);
}
.cta-primary:active { transform: translateY(0); }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: white;
  color: var(--text-dark);
  border: 1.5px solid var(--border-soft);
  border-radius: var(--radius-pill);
  padding: 0.75rem 1.5rem;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font-body);
}
.btn-secondary:hover {
  border-color: var(--accent-blue);
  color: var(--accent-blue);
}

/* =========================================
   LOGIN PAGE
   ========================================= */
.login-page {
  min-height: 100vh;
  background: radial-gradient(ellipse at top, #0A1628 0%, #050B14 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  position: relative;
  overflow: hidden;
}

.login-page::before {
  content: '';
  position: absolute;
  top: -50%;
  left: 50%;
  transform: translateX(-50%);
  width: 800px;
  height: 800px;
  background: radial-gradient(ellipse, rgba(74, 127, 167, 0.12) 0%, transparent 70%);
  animation: glow-move 10s ease-in-out infinite alternate;
  pointer-events: none;
}

@keyframes glow-move {
  0% { transform: translateX(-50%) translateY(0); }
  100% { transform: translateX(-50%) translateY(40px); }
}

.login-card {
  background: white;
  border-radius: var(--radius-xl);
  padding: 3rem;
  max-width: 480px;
  width: 100%;
  box-shadow: 0 30px 80px rgba(74, 127, 167, 0.2);
  position: relative;
  z-index: 1;
}

.login-logo {
  height: 60px;
  width: auto;
  margin: 0 auto 1.5rem;
}

.login-kicker {
  text-align: center;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent-blue);
  margin-bottom: 1rem;
}

.login-title {
  font-family: var(--font-display);
  font-size: 1.875rem;
  line-height: 1.2;
  color: var(--text-dark);
  text-align: center;
  margin-bottom: 1rem;
}

.login-firma-span {
  background: var(--cta-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-subtitle {
  text-align: center;
  font-size: 0.9375rem;
  color: var(--text-medium);
  line-height: 1.6;
  margin-bottom: 2rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.login-form label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-medium);
  margin-bottom: -0.5rem;
}

.login-form input {
  width: 100%;
  font-family: var(--font-body);
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
  padding: 1rem;
  border: 2px solid var(--border-soft);
  border-radius: var(--radius-md);
  background: var(--bg-cream);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.login-form input:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px var(--accent-blue-glow);
  background: white;
}

.login-form input.input-error {
  border-color: var(--error);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12);
}

.login-form .cta-primary {
  width: 100%;
  padding: 1rem;
  font-size: 1.0625rem;
}

.login-error {
  background: rgba(220, 38, 38, 0.08);
  border: 1px solid rgba(220, 38, 38, 0.25);
  color: var(--error);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  text-align: center;
}

.login-footer {
  text-align: center;
  font-size: 0.8125rem;
  color: var(--text-light);
}

.login-footer a {
  color: var(--accent-blue);
}

/* =========================================
   APP HEADER
   ========================================= */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: white;
  border-bottom: 1px solid var(--border-soft);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  gap: 1rem;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.header-logo {
  height: 32px;
  width: auto;
}

.mode-switch {
  display: flex;
  background: var(--bg-cream);
  border-radius: var(--radius-pill);
  padding: 0.25rem;
  gap: 0.25rem;
}

.mode-btn {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  background: transparent;
  border: none;
  color: var(--text-medium);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-pill);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font-body);
}
.mode-btn.active {
  background: var(--cta-gradient);
  color: white;
  box-shadow: 0 2px 8px rgba(255, 92, 26, 0.3);
}
.mode-icon { font-size: 1rem; }

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.kunde-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.kunde-logo {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  object-fit: contain;
  border: 1px solid var(--border-soft);
  background: var(--bg-cream);
}

.kunde-name {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-dark);
  line-height: 1.2;
}

.kunde-status {
  font-size: 0.6875rem;
  color: var(--accent-blue);
  font-weight: 500;
}

.logout-btn {
  background: transparent;
  border: 1.5px solid var(--border-soft);
  color: var(--text-light);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.logout-btn:hover {
  border-color: var(--error);
  color: var(--error);
  background: rgba(220, 38, 38, 0.06);
}

/* =========================================
   PHASE 1 — EINGABE
   ========================================= */
.phase-1 {
  padding: 80px 2rem 4rem;
  min-height: 100vh;
}

.phase-1-grid {
  display: grid;
  grid-template-columns: 60% 1fr;
  gap: 2rem;
  max-width: 1600px;
  margin: 0 auto;
}

/* Quick Templates */
.quick-templates {
  background: var(--accent-blue-light);
  border-radius: var(--radius-md);
  padding: 1rem 1.5rem;
  margin-bottom: 1.75rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.qt-label {
  font-weight: 700;
  color: var(--accent-blue-dark);
  font-size: 0.8125rem;
  white-space: nowrap;
}

.qt-buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.qt-button {
  background: white;
  border: 1.5px solid var(--accent-blue);
  color: var(--accent-blue);
  padding: 0.4rem 0.875rem;
  border-radius: var(--radius-pill);
  font-size: 0.8125rem;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
  font-family: var(--font-body);
}
.qt-button:hover {
  background: var(--accent-blue);
  color: white;
}

/* Form Blocks */
.form-block {
  background: white;
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-card);
}

.block-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.block-num {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--cta-gradient);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.875rem;
  flex-shrink: 0;
}

.block-header h3 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-dark);
}

/* Form Layout */
.form-row { margin-bottom: 1.25rem; }
.form-row:last-child { margin-bottom: 0; }
.form-row-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-row-3col { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.75rem; }
.form-row-3-7 { display: grid; grid-template-columns: 30% 1fr; gap: 1rem; }
.form-row-pills { display: flex; flex-direction: column; gap: 0.5rem; }

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-field label,
.form-row-pills > label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-medium);
}

.required { color: var(--cta-orange-end); }

input[type="text"],
input[type="number"],
input[type="email"],
textarea,
select {
  font-family: var(--font-body);
  font-size: 0.9375rem;
  padding: 0.7rem 0.9rem;
  border: 1.5px solid var(--border-soft);
  border-radius: var(--radius-md);
  background: white;
  color: var(--text-dark);
  transition: border-color 0.2s, box-shadow 0.2s;
  width: 100%;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px var(--accent-blue-glow);
}

input.invalid,
textarea.invalid {
  border-color: var(--error);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12);
}

/* Checkbox */
.form-field-checkbox {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  margin-bottom: 0.75rem;
}
.form-field-checkbox input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  flex-shrink: 0;
}
.form-field-checkbox label {
  font-size: 0.9375rem;
  cursor: pointer;
  color: var(--text-dark);
}

.form-field-multi .checks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.5rem;
}
.form-field-multi .checks label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  cursor: pointer;
  color: var(--text-dark);
}
.form-field-multi .checks input[type="checkbox"] {
  width: 16px;
  height: 16px;
}

/* Pills */
.pills {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.pill {
  background: var(--bg-cream);
  border: 1.5px solid var(--border-soft);
  color: var(--text-medium);
  padding: 0.55rem 1rem;
  border-radius: var(--radius-pill);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font-body);
}
.pill:hover {
  border-color: var(--accent-blue);
  color: var(--accent-blue);
}
.pill.active {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: white;
  box-shadow: 0 2px 8px rgba(74, 127, 167, 0.3);
}

/* Position Cards */
.positions-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1rem;
}

.position-card {
  background: var(--bg-cream);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  position: relative;
}

.position-header {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  margin-bottom: 1rem;
}

.position-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: white;
  border: 2px solid var(--accent-blue);
  color: var(--accent-blue);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8125rem;
  flex-shrink: 0;
}

.position-title {
  flex: 1;
  border: 1.5px solid transparent;
  background: transparent;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-dark);
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
  width: auto;
}
.position-title:focus {
  background: white;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px var(--accent-blue-glow);
  outline: none;
}

.btn-delete-position {
  background: transparent;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  padding: 0.4rem;
  border-radius: 50%;
  transition: all 0.2s;
  font-size: 0.875rem;
  line-height: 1;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.btn-delete-position:hover {
  background: rgba(220, 38, 38, 0.1);
  color: var(--error);
}

.btn-add-position {
  width: 100%;
  background: white;
  border: 2px dashed var(--accent-blue);
  color: var(--accent-blue);
  padding: 1rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.9375rem;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font-body);
}
.btn-add-position:hover {
  background: var(--accent-blue-light);
}

/* Position Extras */
.position-extras {
  margin-top: 1rem;
  border-top: 1px solid var(--border-soft);
  padding-top: 0.875rem;
}
.position-extras > summary {
  cursor: pointer;
  color: var(--accent-blue);
  font-size: 0.875rem;
  font-weight: 500;
  list-style: none;
  user-select: none;
}
.position-extras > summary::-webkit-details-marker { display: none; }
.extras-content { padding-top: 1rem; }

/* Form Accordion */
.form-accordion summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
}
.form-accordion summary::-webkit-details-marker { display: none; }
.accordion-toggle {
  font-size: 1.5rem;
  color: var(--text-light);
  transition: transform 0.2s;
  line-height: 1;
}
.form-accordion[open] .accordion-toggle { transform: rotate(45deg); }
.accordion-content { padding-top: 1.25rem; }

/* Form CTA */
.form-cta {
  position: sticky;
  bottom: 0;
  background: linear-gradient(180deg, transparent 0%, var(--bg-primary) 30%);
  padding: 2rem 0 1rem;
  text-align: center;
}
.cta-large {
  font-size: 1.125rem;
  padding: 1.25rem 2.5rem;
}
.cta-slim {
  font-size: 0.9375rem;
  padding: 0.7rem 1.5rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.btn-icon { margin-right: 0.25rem; }

/* Top-Karten: Upload (links, 20%) + Schnellvorlagen (rechts, 80%) */
.top-cards {
  display: grid;
  grid-template-columns: 20% 1fr;
  gap: 1rem;
  margin-bottom: 1.75rem;
}
.top-cards .quick-templates,
.top-cards .upload-card {
  margin-bottom: 0;
}

/* Schnellvorlagen: pastell-orange Fade-Highlight (ohne Ränder) */
.top-cards .quick-templates {
  background: linear-gradient(135deg, #FFE9D6 0%, #FFF4EA 55%, #FFFBF5 100%);
  border: none;
  box-shadow: 0 2px 10px rgba(255, 138, 76, 0.08);
  position: relative;
  overflow: hidden;
}
.top-cards .quick-templates .qt-label {
  color: #C9531C;
}
.top-cards .quick-templates .qt-button {
  border: none;
  background: white;
  color: #C9531C;
  box-shadow: 0 1px 3px rgba(201, 83, 28, 0.12);
}
.top-cards .quick-templates .qt-button:hover {
  background: #FF8A4C;
  color: white;
  box-shadow: 0 2px 8px rgba(255, 138, 76, 0.25);
}

/* Upload-Karte (schmaler, dezenter) */
.upload-card {
  background: var(--accent-blue-light);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.25rem;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font-body);
  outline: none;
  border: 1.5px dashed transparent;
  min-width: 0;
}
.upload-card:hover,
.upload-card:focus-visible {
  border-color: var(--accent-blue);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(74, 127, 167, 0.12);
}
.upload-card .qt-label {
  white-space: normal;
  line-height: 1.3;
}
.upload-card-hint {
  font-size: 0.7rem;
  color: var(--text-medium);
  line-height: 1.35;
}

@media (max-width: 768px) {
  .top-cards { grid-template-columns: 1fr; }
}
.btn-hint {
  font-size: 0.8125rem;
  color: var(--text-light);
  margin-top: 0.75rem;
}

/* Preview Column */
.preview-column {
  position: sticky;
  top: 80px;
  height: calc(100vh - 100px);
  overflow-y: auto;
}

.preview-sticky { height: 100%; }

.preview-label {
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-blue);
  margin-bottom: 0.875rem;
}

.preview-pdf {
  background: white;
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-premium);
  position: relative;
  min-height: 600px;
  overflow: hidden;
}

.pdf-skeleton { font-size: 0.8125rem; color: var(--text-medium); }

.pdf-briefkopf {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.5rem;
}

.pdf-firma-name {
  font-weight: 700;
  color: var(--text-dark);
  font-size: 0.9375rem;
}

.pdf-firma-addr {
  font-size: 0.75rem;
  color: var(--text-light);
  margin-top: 0.25rem;
}

.pdf-divider {
  height: 1px;
  background: var(--border-soft);
  margin: 1rem 0;
}

.pdf-empfaenger,
.pdf-betreff,
.pdf-positionen {
  margin-bottom: 1rem;
  font-size: 0.8125rem;
  line-height: 1.6;
}

.pdf-overlay-info {
  position: absolute;
  bottom: 2rem;
  left: 2rem;
  right: 2rem;
  background: linear-gradient(135deg, var(--accent-blue-light), white);
  padding: 1.25rem;
  border-radius: var(--radius-md);
  border-left: 3px solid var(--accent-blue);
  font-size: 0.8125rem;
  text-align: center;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  justify-content: center;
  color: var(--text-medium);
}

.pdf-overlay-icon { font-size: 1.5rem; }

/* =========================================
   PHASE 2 — PDF + CHAT
   ========================================= */
.phase-2 {
  padding: 80px 2rem 4rem;
  min-height: 100vh;
}

.phase-2-grid {
  display: grid;
  grid-template-columns: 60% 1fr;
  gap: 2rem;
  max-width: 1600px;
  margin: 0 auto;
}

.pdf-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.pdf-versions select {
  font-size: 0.875rem;
  padding: 0.5rem 0.875rem;
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--border-soft);
  background: white;
  color: var(--text-dark);
  font-weight: 500;
  cursor: pointer;
}

.pdf-viewer {
  background: white;
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  box-shadow: var(--shadow-premium);
  min-height: 80vh;
  overflow-y: auto;
  font-size: 0.875rem;
}

/* === CHAT === */
.chat-column {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-premium);
  display: flex;
  flex-direction: column;
  height: calc(100vh - 120px);
  position: sticky;
  top: 80px;
  overflow: hidden;
}

.chat-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  gap: 0.875rem;
  align-items: center;
  flex-shrink: 0;
}

.chat-avatar {
  position: relative;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
}

.avatar-circle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-blue-dark));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 1.375rem;
  font-weight: 400;
}

.online-dot {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  background: var(--success);
  border: 2px solid white;
  border-radius: 50%;
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.15); }
}

.chat-name {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-dark);
}
.chat-status {
  font-size: 0.75rem;
  color: var(--text-light);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 88%;
}
.msg-bot { align-self: flex-start; }
.msg-user { align-self: flex-end; align-items: flex-end; }

.msg-bubble {
  padding: 0.875rem 1.125rem;
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
  line-height: 1.55;
}
.msg-bot .msg-bubble {
  background: var(--bg-cream);
  color: var(--text-dark);
  border-top-left-radius: 4px;
}
.msg-user .msg-bubble {
  background: var(--accent-blue);
  color: white;
  border-top-right-radius: 4px;
}

.msg-time {
  font-size: 0.7rem;
  color: var(--text-light);
  margin-top: 0.25rem;
  padding: 0 0.25rem;
}

/* Typing Indicator */
.msg-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 1rem 1.125rem;
  background: var(--bg-cream);
  border-radius: var(--radius-md);
  border-top-left-radius: 4px;
  width: fit-content;
}
.msg-typing span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-light);
  animation: typing 1.2s infinite;
  display: block;
}
.msg-typing span:nth-child(2) { animation-delay: 0.2s; }
.msg-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 60%, 100% { transform: scale(1); opacity: 0.5; }
  30% { transform: scale(1.3); opacity: 1; }
}

/* Quick Actions */
.chat-quick-actions {
  padding: 0.75rem 1.5rem;
  border-top: 1px solid var(--border-soft);
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.qa-btn {
  background: white;
  border: 1.5px solid var(--accent-blue);
  color: var(--accent-blue);
  padding: 0.4rem 0.875rem;
  border-radius: var(--radius-pill);
  font-size: 0.8125rem;
  cursor: pointer;
  font-weight: 500;
  font-family: var(--font-body);
  transition: all 0.2s;
  white-space: nowrap;
}
.qa-btn:hover {
  background: var(--accent-blue);
  color: white;
}

/* Chat Input */
.chat-input-wrapper {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-soft);
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  resize: none;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
  font-family: var(--font-body);
  border: 1.5px solid var(--border-soft);
  background: var(--bg-cream);
  transition: border-color 0.2s, box-shadow 0.2s;
  max-height: 120px;
}
#chat-input:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px var(--accent-blue-glow);
  background: white;
}

.chat-send-btn {
  background: var(--cta-gradient);
  color: white;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 1.25rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-send-btn:hover {
  transform: scale(1.08);
  box-shadow: var(--cta-shadow);
}

.chat-footer {
  padding: 0.625rem 1.5rem;
  font-size: 0.75rem;
  color: var(--text-light);
  text-align: center;
  border-top: 1px solid var(--border-soft);
  flex-shrink: 0;
}

/* =========================================
   LOADING OVERLAY
   ========================================= */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 11, 20, 0.75);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  color: white;
}

.loading-spinner {
  width: 80px;
  height: 80px;
  border: 4px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--cta-orange-end);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  font-family: var(--font-display);
  font-size: 1.5rem;
  text-align: center;
  line-height: 1.3;
}

.loading-status {
  font-size: 0.9375rem;
  color: rgba(255, 255, 255, 0.65);
  text-align: center;
  max-width: 320px;
}

.loading-progress {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: rgba(255, 255, 255, 0.6);
  text-align: left;
  min-width: 260px;
}

.loading-step {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  transition: color 0.3s;
}
.loading-step.active { color: rgba(255, 255, 255, 0.95); }
.loading-step.done { color: var(--success); }
.step-icon { font-size: 0.875rem; width: 20px; text-align: center; }

/* =========================================
   PDF DOCUMENT (in viewer)
   ========================================= */
.pdf-document {
  font-family: 'DM Sans', Arial, sans-serif;
  color: #1A1F2E;
  font-size: 0.875rem;
  line-height: 1.6;
}

.pdf-pos-row td {
  padding: 8px;
  border-bottom: 1px solid #F4F0EA;
  vertical-align: top;
}

.pdf-pos-num { color: #8A8F9E; width: 36px; }
.pdf-pos-desc { width: 50%; }
.pdf-pos-title { font-weight: 600; color: #1A1F2E; }
.pdf-pos-detail { font-size: 0.75rem; color: #4A4F5E; margin-top: 2px; }
.pdf-pos-qty { text-align: right; white-space: nowrap; }
.pdf-pos-price { text-align: right; white-space: nowrap; }
.pdf-pos-total { text-align: right; white-space: nowrap; font-weight: 600; }

/* Celebration spark after PDF generation */
.celebration-spark {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 3rem;
  pointer-events: none;
  z-index: 100;
  animation: celebration-rise 1.8s ease-out forwards;
}
@keyframes celebration-rise {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  20% { opacity: 1; transform: translate(-50%, -60%) scale(1.2); }
  80% { opacity: 1; transform: translate(-50%, -120%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -160%) scale(0.8); }
}

/* Price animation on update */
@keyframes price-flash {
  0% { background: rgba(74, 127, 167, 0.2); }
  100% { background: transparent; }
}
.price-updated { animation: price-flash 0.8s ease-out; }

/* =========================================
   RESPONSIVE
   ========================================= */
@media (max-width: 1100px) {
  .phase-1-grid,
  .phase-2-grid {
    grid-template-columns: 1fr;
  }

  .preview-column {
    position: static;
    height: auto;
  }

  .preview-pdf { min-height: 400px; }

  .chat-column {
    position: static;
    height: auto;
    min-height: 600px;
  }
}

@media (max-width: 768px) {
  .app-header {
    padding: 0 1rem;
    flex-wrap: wrap;
    height: auto;
    min-height: 64px;
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
  }

  .header-right .kunde-info { display: none; }

  .phase-1 { padding: 80px 1rem 4rem; }
  /* Phase 2 (Angebot): weniger Platz links/rechts auf Mobile */
  .phase-2 { padding: 80px 0.5rem 3rem; }

  .form-row-2col,
  .form-row-3col,
  .form-row-3-7 { grid-template-columns: 1fr; }

  .login-card { padding: 2rem 1.5rem; }
  .login-title { font-size: 1.5rem; }

  .pdf-toolbar { flex-direction: column; align-items: stretch; }

  /* PDF-Viewer (Angebot): NICHT horizontal wischbar — Inhalt bleibt in der Box */
  .pdf-viewer {
    padding: 1rem 0.875rem;
    overflow-x: hidden;
    max-width: 100%;
    box-sizing: border-box;
  }
  .pdf-viewer table {
    table-layout: fixed;
    width: 100%;
    max-width: 100%;
  }
  .pdf-viewer img { max-width: 100%; height: auto; }

  /* "Angebot mit KI erstellen" Button garantiert mittig zentriert */
  .form-cta {
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  .form-cta .cta-primary { width: auto; }

  .mode-btn { padding: 0.4rem 0.75rem; font-size: 0.8rem; }
}

@media (max-width: 480px) {
  .quick-templates { flex-direction: column; align-items: flex-start; }
  .qt-buttons { width: 100%; }
  .pills { gap: 0.375rem; }
  .pill { font-size: 0.8125rem; padding: 0.45rem 0.75rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
