/* ============================================
   SPIN Selling Chatbot — Style
   Dark theme, green accent (#22c55e)
   ============================================ */

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

:root {
  --bg-primary: #0f0f0f;
  --bg-secondary: #1a1a1a;
  --bg-tertiary: #2a2a2a;
  --bg-hover: #333333;
  --accent: #22c55e;
  --accent-dark: #16a34a;
  --accent-glow: rgba(34, 197, 94, 0.15);
  --text-primary: #e5e5e5;
  --text-secondary: #a3a3a3;
  --text-muted: #737373;
  --text-on-accent: #ffffff;
  --border-color: #2a2a2a;
  --danger: #ef4444;
  --danger-glow: rgba(239, 68, 68, 0.3);
  --sidebar-width: 300px;
  --header-height: 60px;
  --input-height: 64px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 350ms ease;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   Layout
   ============================================ */

#app {
  display: flex;
  height: 100%;
  width: 100%;
  overflow: hidden;
}

/* ============================================
   Sidebar
   ============================================ */

.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100%;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: transform var(--transition-slow);
  z-index: 100;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.3px;
}

.sidebar-close-btn {
  display: none;
}

.new-conversation-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 12px 8px;
  padding: 12px 16px;
  background: var(--accent);
  color: var(--text-on-accent);
  border: none;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast), transform var(--transition-fast);
}

.new-conversation-btn:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

.new-conversation-btn:active {
  transform: translateY(0);
}

.conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-tertiary) transparent;
}

.conversation-list::-webkit-scrollbar {
  width: 4px;
}

.conversation-list::-webkit-scrollbar-track {
  background: transparent;
}

.conversation-list::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 4px;
}

.conversation-item {
  display: flex;
  align-items: center;
  padding: 12px;
  margin: 2px 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
  position: relative;
  gap: 10px;
}

.conversation-item:hover {
  background: var(--bg-tertiary);
}

.conversation-item.active {
  background: var(--accent-glow);
  border: 1px solid rgba(34, 197, 94, 0.2);
}

.conversation-item-content {
  flex: 1;
  min-width: 0;
}

.conversation-item-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-item.active .conversation-item-title {
  color: var(--accent);
}

.conversation-item-preview {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.conversation-item-time {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
  align-self: flex-start;
  margin-top: 2px;
}

.conversation-item-delete {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: opacity var(--transition-fast), color var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
}

.conversation-item:hover .conversation-item-delete {
  opacity: 1;
}

.conversation-item-delete:hover {
  color: var(--danger);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 99;
  backdrop-filter: blur(2px);
}

/* ============================================
   Main Chat Area
   ============================================ */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
  position: relative;
}

/* ============================================
   Header
   ============================================ */

.chat-header {
  height: var(--header-height);
  min-height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  gap: 12px;
}

.hamburger-btn {
  display: none;
}

.header-title-wrapper {
  flex: 1;
  min-width: 0;
}

.chat-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

.header-spacer {
  width: 36px;
  flex-shrink: 0;
}

/* ============================================
   Messages
   ============================================ */

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-tertiary) transparent;
}

.messages::-webkit-scrollbar {
  width: 6px;
}

.messages::-webkit-scrollbar-track {
  background: transparent;
}

.messages::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 3px;
}

/* Welcome Screen */

.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
  margin: auto 0;
  animation: fadeIn 0.5s ease;
}

.welcome-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--accent-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}

.welcome-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 10px;
}

.welcome-text {
  font-size: 14px;
  color: var(--text-secondary);
  max-width: 420px;
  line-height: 1.6;
  margin-bottom: 24px;
}

.welcome-hints {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 460px;
}

.hint-chip {
  padding: 10px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.hint-chip:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  color: var(--accent);
}

/* Message Bubbles */

.message-row {
  display: flex;
  flex-direction: column;
  animation: messageIn 0.3s ease;
  margin-bottom: 2px;
}

.message-row.user {
  align-items: flex-end;
}

.message-row.assistant {
  align-items: flex-start;
}

.message-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: break-word;
  position: relative;
}

.message-row.user .message-bubble {
  background: var(--accent);
  color: var(--text-on-accent);
  border-bottom-right-radius: 4px;
}

.message-row.assistant .message-bubble {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.message-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  padding: 0 4px;
}

.message-row.user .message-time {
  text-align: right;
}

/* Message content formatting */

.message-bubble p {
  margin: 0 0 14px;
}

.message-bubble p:last-child {
  margin-bottom: 0;
}

.message-bubble strong {
  font-weight: 700;
}

.message-bubble em {
  font-style: italic;
}

.message-bubble ul, .message-bubble ol {
  margin: 8px 0 14px 18px;
}

.message-bubble li {
  margin-bottom: 8px;
  line-height: 1.65;
}

.message-bubble li:last-child {
  margin-bottom: 0;
}

.message-bubble code {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 13px;
  background: rgba(0, 0, 0, 0.25);
  padding: 2px 6px;
  border-radius: 4px;
}

.message-row.user .message-bubble code {
  background: rgba(0, 0, 0, 0.2);
}

.message-bubble pre {
  background: rgba(0, 0, 0, 0.3);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 6px 0;
}

.message-bubble pre code {
  background: none;
  padding: 0;
  font-size: 13px;
}

/* Message images */

.message-image {
  max-width: 260px;
  max-height: 260px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  cursor: pointer;
  transition: opacity var(--transition-fast);
  display: block;
}

.message-image:hover {
  opacity: 0.85;
}

/* Typing Indicator */

.typing-indicator {
  align-self: flex-start;
  animation: messageIn 0.3s ease;
}

.typing-bubble {
  background: var(--bg-tertiary);
  padding: 12px 18px;
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 4px;
  display: inline-block;
}

.typing-dots {
  display: flex;
  gap: 5px;
  align-items: center;
  height: 20px;
}

.typing-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ============================================
   Image Preview Bar
   ============================================ */

.image-preview-bar {
  padding: 8px 16px 0;
  background: var(--bg-primary);
}

.image-preview-container {
  display: inline-flex;
  position: relative;
  border-radius: var(--radius-sm);
  overflow: visible;
}

.image-preview-thumb {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border-color);
}

.image-preview-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--danger);
  color: white;
  border: 2px solid var(--bg-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition-fast);
}

.image-preview-remove:hover {
  transform: scale(1.1);
}

/* ============================================
   Input Area
   ============================================ */

.input-area {
  padding: 8px 12px 12px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border-color);
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 6px 6px 6px 12px;
  transition: border-color var(--transition-fast);
}

.input-wrapper:focus-within {
  border-color: var(--accent);
}

.message-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 15px;
  font-family: inherit;
  line-height: 1.4;
  padding: 8px 0;
  resize: none;
  max-height: 120px;
  min-height: 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-tertiary) transparent;
}

.message-input::placeholder {
  color: var(--text-muted);
}

.message-input::-webkit-scrollbar {
  width: 3px;
}

.message-input::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 3px;
}

/* Icon Buttons */

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

.icon-btn:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}

.upload-btn {
  cursor: pointer;
}

.send-btn {
  background: var(--accent);
  color: var(--text-on-accent);
}

.send-btn:hover {
  background: var(--accent-dark);
  color: var(--text-on-accent);
}

/* Mic recording state */

.mic-btn.recording {
  color: var(--danger);
  animation: micPulse 1.5s infinite;
}

@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--danger-glow); }
  50% { box-shadow: 0 0 0 10px transparent; }
}

/* Recording Indicator */

.recording-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--danger);
}

.recording-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  animation: recordPulse 1s infinite;
}

@keyframes recordPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.recording-timer {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.recording-label {
  color: var(--text-muted);
}

/* ============================================
   Lightbox
   ============================================ */

.lightbox {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.9);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  animation: fadeIn 0.2s ease;
}

.lightbox.active {
  display: flex;
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: white;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast);
}

.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.lightbox-img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

/* ============================================
   Toast Notifications
   ============================================ */

.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  border-left: 3px solid var(--danger);
  animation: toastIn 0.3s ease, toastOut 0.3s ease 3.7s forwards;
  max-width: 360px;
}

.toast.success {
  border-left-color: var(--accent);
}

/* ============================================
   Animations
   ============================================ */

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes messageIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(40px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes toastOut {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(40px);
  }
}

/* ============================================
   Responsive — Mobile (<768px)
   ============================================ */

@media (max-width: 767px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
    z-index: 200;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.open {
    display: block;
  }

  .sidebar-close-btn {
    display: flex;
  }

  .hamburger-btn {
    display: flex;
  }

  .header-spacer {
    width: 0;
  }

  .message-bubble {
    max-width: 88%;
  }

  .welcome-hints {
    flex-direction: column;
    align-items: center;
  }

  .toast-container {
    top: 10px;
    right: 10px;
    left: 10px;
  }

  .toast {
    max-width: 100%;
  }

  .wizard-fields-row {
    flex-direction: column;
    gap: 12px;
  }

  .payment-condition-row .wizard-field:first-child {
    flex: 1;
  }

  .contract-card {
    max-width: 100%;
  }
}

/* Desktop tweaks */
@media (min-width: 768px) {
  .message-bubble {
    max-width: 65%;
  }
}

@media (min-width: 1200px) {
  .message-bubble {
    max-width: 55%;
  }
}

/* ============================================
   Safe area (notch phones)
   ============================================ */

@supports (padding: env(safe-area-inset-bottom)) {
  .input-area {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
}

/* ============================================
   Selection
   ============================================ */

::selection {
  background: var(--accent);
  color: var(--text-on-accent);
}

/* ============================================
   Auth Screen
   ============================================ */

.auth-screen {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5000;
  animation: fadeIn 0.3s ease;
}
.auth-screen.hidden { display: none; }

/* ---- Module Selection Screen ---- */
.module-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.3s ease;
}
.module-card {
  width: 100%;
  max-width: 420px;
  margin: 0 16px;
  text-align: center;
}
.module-header {
  margin-bottom: 36px;
}
.module-header svg {
  margin-bottom: 12px;
}
.module-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
}
.module-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
}
.module-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
}
.module-option {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
}
.module-option:hover {
  border-color: #22c55e;
  background: rgba(34, 197, 94, 0.05);
  transform: translateY(-1px);
}
.module-option:active {
  transform: translateY(0);
}
.module-option-icon {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  background: rgba(34, 197, 94, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #22c55e;
}
.module-option-icon-gold {
  background: rgba(160, 140, 91, 0.12);
  color: #a08c5b;
}
.module-option-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.module-option-text strong {
  font-size: 16px;
  font-weight: 600;
}
.module-option-text span {
  font-size: 13px;
  color: var(--text-secondary);
}
.module-option-arrow {
  color: var(--text-secondary);
  flex-shrink: 0;
}
.module-logout-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  padding: 8px;
  font-family: inherit;
}
.module-logout-btn:hover {
  color: var(--danger-color);
}

.auth-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 40px 32px;
  width: 100%;
  max-width: 380px;
  margin: 0 16px;
  text-align: center;
}
.auth-logo {
  width: 80px; height: 80px;
  border-radius: 50%;
  background: var(--accent-glow);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 20px;
}
.auth-title { font-size: 22px; font-weight: 700; color: var(--text-primary); margin-bottom: 6px; }
.auth-subtitle { font-size: 14px; color: var(--text-muted); margin-bottom: 28px; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-input {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  color: var(--text-primary);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition-fast);
}
.auth-input:focus { border-color: var(--accent); }
.auth-input::placeholder { color: var(--text-muted); }
.auth-submit-btn {
  background: var(--accent);
  color: var(--text-on-accent);
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast);
  margin-top: 4px;
}
.auth-submit-btn:hover { background: var(--accent-dark); }
.auth-submit-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.auth-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 4px;
}
.auth-toggle-btn {
  background: none; border: none;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  margin-top: 20px;
  font-family: inherit;
}
.auth-toggle-btn strong { color: var(--accent); }

/* ============================================
   Sidebar Footer
   ============================================ */

.sidebar-footer {
  padding: 8px 12px 12px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sidebar-footer-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition-fast);
  width: 100%;
}
.sidebar-footer-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}
.clear-all-btn:hover { color: var(--danger); }

/* ============================================
   Contract Button (Input Toolbar)
   ============================================ */


/* ============================================
   Contract Edit Mode Banner
   ============================================ */

.contract-edit-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: rgba(160, 140, 91, 0.15);
  border-bottom: 1px solid rgba(160, 140, 91, 0.3);
  color: #c4a96a;
  font-size: 13px;
  font-weight: 500;
  flex-shrink: 0;
}
.contract-edit-banner svg {
  flex-shrink: 0;
}
.contract-edit-banner span {
  flex: 1;
}
.contract-edit-exit-btn {
  background: rgba(160, 140, 91, 0.2);
  border: 1px solid rgba(160, 140, 91, 0.4);
  color: #c4a96a;
  padding: 4px 14px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}
.contract-edit-exit-btn:hover {
  background: rgba(160, 140, 91, 0.35);
}

/* ============================================
   Contract Wizard Modal
   ============================================ */

/* ============================================
   Contract Wizard — Redesigned
   ============================================ */
.contract-wizard {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg-primary);
  z-index: 3000;
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.25s ease;
}
.contract-wizard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
  border-bottom: 1px solid rgba(160, 140, 91, 0.15);
  flex-shrink: 0;
}
.contract-wizard-title {
  font-size: 18px;
  font-weight: 700;
  color: #d4b87a;
  letter-spacing: 0.3px;
}

/* Step Indicators */
.wizard-steps-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 20px 32px;
  background: var(--bg-primary);
  border-bottom: 1px solid rgba(255,255,255,0.04);
  flex-shrink: 0;
}
.wizard-step-dot {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--bg-secondary);
  border: 2px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  transition: all var(--transition-normal);
  flex-shrink: 0;
}
.wizard-step-dot.active {
  background: linear-gradient(135deg, #b89e6a, #a08c5b);
  border-color: #c4a96a;
  color: #fff;
  box-shadow: 0 0 16px rgba(160, 140, 91, 0.35);
}
.wizard-step-dot.done {
  background: rgba(160, 140, 91, 0.15);
  border-color: #a08c5b;
  color: #c4a96a;
}
.wizard-step-line {
  flex: 1;
  height: 2px;
  background: var(--border-color);
  max-width: 56px;
}

/* Wizard Body */
.contract-wizard-body {
  flex: 1;
  overflow-y: auto;
  padding: 28px 20px 40px;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-tertiary) transparent;
}
.contract-wizard-body::-webkit-scrollbar { width: 4px; }
.contract-wizard-body::-webkit-scrollbar-thumb { background: var(--bg-tertiary); border-radius: 4px; }

.wizard-step {
  display: none;
  animation: fadeIn 0.25s ease;
  max-width: 520px;
  margin: 0 auto;
}
.wizard-step.active {
  display: block;
}
.wizard-step-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 24px;
  letter-spacing: -0.2px;
}
.wizard-section-title {
  font-size: 15px;
  font-weight: 700;
  color: #d4b87a;
  margin: 28px 0 14px;
  letter-spacing: 0.3px;
}

/* Upload Zone */
.wizard-upload-zone {
  position: relative;
  border: 1.5px dashed rgba(160, 140, 91, 0.35);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: all var(--transition-normal);
  background: rgba(160, 140, 91, 0.04);
}
.wizard-upload-zone:hover {
  border-color: rgba(160, 140, 91, 0.6);
  background: rgba(160, 140, 91, 0.08);
}
.wizard-upload-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 32px 20px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 14px;
  text-align: center;
}
.wizard-upload-label svg {
  color: #c4a96a;
  opacity: 0.8;
}
.wizard-upload-hint {
  font-size: 12px;
  color: var(--text-muted);
  opacity: 0.7;
}
.wizard-doc-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 16px;
}
.wizard-thumb-item {
  position: relative;
  width: 72px;
  height: 72px;
}
.wizard-thumb-item img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.08);
}
.wizard-thumb-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--danger, #ef4444);
  color: #fff;
  border: none;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.wizard-doc-preview img {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

/* ---- Wizard Divider ---- */
.wizard-divider {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 20px 0;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
}
.wizard-divider::before,
.wizard-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-color), transparent);
}

/* ---- Wizard Voice Input ---- */
.wizard-voice-input {
  display: flex;
  gap: 10px;
  align-items: stretch;
}
.wizard-textarea {
  flex: 1;
  background: var(--bg-secondary);
  border: 1.5px solid rgba(255,255,255,0.06);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.6;
  padding: 14px 16px;
  resize: vertical;
  min-height: 80px;
  transition: border-color var(--transition-normal);
}
.wizard-textarea:focus {
  outline: none;
  border-color: rgba(160, 140, 91, 0.5);
}
.wizard-textarea::placeholder {
  color: var(--text-muted);
  opacity: 0.7;
  line-height: 1.6;
}
.wizard-mic-btn {
  width: 48px;
  min-height: 48px;
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  border: 1.5px solid rgba(255,255,255,0.06);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  align-self: stretch;
  transition: all var(--transition-normal);
}
.wizard-mic-btn:hover {
  border-color: rgba(160, 140, 91, 0.5);
  color: #c4a96a;
  background: rgba(160, 140, 91, 0.08);
}
.wizard-mic-btn.recording {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.4);
  color: #ef4444;
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.3); }
  50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}
.wizard-doc-remove {
  background: none;
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.wizard-doc-remove:hover {
  background: var(--danger);
  color: white;
}

/* Extract Button */
.wizard-extract-btn {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, rgba(160, 140, 91, 0.12), rgba(160, 140, 91, 0.06));
  border: 1.5px solid rgba(160, 140, 91, 0.25);
  color: #d4b87a;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-normal);
  margin-top: 20px;
  margin-bottom: 20px;
  letter-spacing: 0.3px;
}
.wizard-extract-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, rgba(160, 140, 91, 0.22), rgba(160, 140, 91, 0.12));
  border-color: rgba(160, 140, 91, 0.5);
}
.wizard-extract-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* Spinner */
.wizard-spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid rgba(196, 169, 106, 0.3);
  border-top-color: #d4b87a;
  border-radius: 50%;
  animation: wizardSpin 0.7s linear infinite;
  vertical-align: middle;
}
@keyframes wizardSpin {
  to { transform: rotate(360deg); }
}

/* Form Fields */
.wizard-fields {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 20px;
  animation: fadeIn 0.3s ease;
}
.wizard-fields-row {
  display: flex;
  gap: 12px;
}
.wizard-fields-row .wizard-field {
  flex: 1;
}
.wizard-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.wizard-field label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}
.wizard-field input,
.wizard-field textarea,
.wizard-field select {
  background: var(--bg-secondary);
  border: 1.5px solid rgba(255,255,255,0.06);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition-normal);
  width: 100%;
}
.wizard-field input:focus,
.wizard-field textarea:focus,
.wizard-field select:focus {
  border-color: rgba(160, 140, 91, 0.5);
}
.wizard-field textarea {
  resize: vertical;
  min-height: 48px;
}
.wizard-field select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23737373' stroke-width='2' xmlns='http://www.w3.org/2000/svg'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* Wizard Navigation */
.wizard-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid rgba(255,255,255,0.04);
  gap: 12px;
}
.wizard-nav-btn {
  padding: 13px 28px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-normal);
  border: none;
  letter-spacing: 0.3px;
}
.wizard-back-btn {
  background: transparent;
  color: var(--text-muted);
  border: 1.5px solid rgba(255,255,255,0.08);
}
.wizard-back-btn:hover {
  background: rgba(255,255,255,0.04);
  color: var(--text-primary);
  border-color: rgba(255,255,255,0.15);
}
.wizard-next-btn {
  background: linear-gradient(135deg, #b89e6a, #a08c5b);
  color: #fff;
  box-shadow: 0 2px 12px rgba(160, 140, 91, 0.25);
}
.wizard-next-btn:hover {
  background: linear-gradient(135deg, #c9ae77, #b89e6a);
  box-shadow: 0 4px 16px rgba(160, 140, 91, 0.35);
}
.wizard-generate-btn {
  background: linear-gradient(135deg, #b89e6a, #a08c5b);
  color: #fff;
  flex: 1;
  box-shadow: 0 2px 12px rgba(160, 140, 91, 0.25);
}
.wizard-generate-btn:hover {
  background: linear-gradient(135deg, #c9ae77, #b89e6a);
  box-shadow: 0 4px 16px rgba(160, 140, 91, 0.35);
}
.wizard-generate-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

/* Tabs (Reference Contract) */
.wizard-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 20px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1.5px solid rgba(255,255,255,0.06);
}
.wizard-tab {
  flex: 1;
  padding: 11px;
  background: var(--bg-secondary);
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.wizard-tab.active {
  background: rgba(160, 140, 91, 0.12);
  color: #d4b87a;
}
.wizard-tab:hover:not(.active) {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}
.ref-tab {
  display: none;
}
.ref-tab.active {
  display: block;
}

/* Clauses Editor */
.clauses-editor {
  margin-top: 20px;
  animation: fadeIn 0.3s ease;
}
.clauses-editor-title {
  font-size: 14px;
  font-weight: 700;
  color: #d4b87a;
  margin-bottom: 12px;
}
.clauses-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.clause-card {
  background: var(--bg-secondary);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius-md);
  padding: 14px;
  position: relative;
}
.clause-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.clause-card-title {
  font-size: 13px;
  font-weight: 700;
  color: #c4a96a;
}
.clause-remove-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: color var(--transition-fast);
}
.clause-remove-btn:hover {
  color: var(--danger);
}
.clause-card textarea {
  background: var(--bg-primary);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  width: 100%;
  resize: vertical;
  outline: none;
  min-height: 60px;
  line-height: 1.6;
}
.clause-card textarea:focus {
  border-color: rgba(160, 140, 91, 0.5);
}

/* Payment Conditions */
.payment-conditions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.payment-condition-row {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  animation: fadeIn 0.2s ease;
}
.payment-condition-row .wizard-field {
  flex: 1;
}
.payment-condition-row .wizard-field:first-child {
  flex: 0 0 120px;
}
.condition-remove-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 10px 4px;
  align-self: flex-end;
  margin-bottom: 2px;
  transition: color var(--transition-fast);
}
.condition-remove-btn:hover {
  color: var(--danger);
}
.wizard-add-condition-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 12px;
  background: none;
  border: 1.5px dashed rgba(255,255,255,0.08);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  margin-top: 10px;
  transition: all var(--transition-fast);
}
.wizard-add-condition-btn:hover {
  border-color: rgba(160, 140, 91, 0.4);
  color: #c4a96a;
}

/* ============================================
   Contract Preview + Edit Chat Screen
   ============================================ */
.contract-preview-screen {
  display: flex;
  flex-direction: column;
  height: 100%;
  animation: fadeIn 0.3s ease;
}
.contract-preview-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid rgba(160, 140, 91, 0.15);
  flex-shrink: 0;
  gap: 12px;
}
.contract-preview-topbar-title {
  font-size: 16px;
  font-weight: 700;
  color: #d4b87a;
}
.contract-preview-topbar-actions {
  display: flex;
  gap: 8px;
}
.contract-preview-action-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1.5px solid rgba(255,255,255,0.08);
  background: transparent;
  color: var(--text-secondary);
}
.contract-preview-action-btn:hover {
  background: rgba(255,255,255,0.04);
  border-color: rgba(255,255,255,0.15);
  color: var(--text-primary);
}
.contract-preview-done-btn {
  background: linear-gradient(135deg, #b89e6a, #a08c5b);
  color: #fff;
  border-color: transparent;
}
.contract-preview-done-btn:hover {
  background: linear-gradient(135deg, #c9ae77, #b89e6a);
  color: #fff;
  border-color: transparent;
}
.contract-preview-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.contract-preview-iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: #fefdfb;
}

/* Contract Edit Chat */
.contract-edit-chat {
  flex-shrink: 0;
  background: var(--bg-secondary);
  border-top: 1px solid rgba(160, 140, 91, 0.15);
  max-height: 40vh;
  display: flex;
  flex-direction: column;
}
.contract-chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-tertiary) transparent;
}
.contract-chat-messages:empty {
  padding: 16px;
}
.contract-chat-messages:empty::after {
  content: 'Peca alteracoes aqui. Ex: "Mude o valor para 200 mil", "Adicione clausula de rescisao", "Corrija o endereco do comprador"';
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  opacity: 0.6;
  line-height: 1.5;
}
.contract-chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  line-height: 1.5;
  animation: fadeIn 0.2s ease;
}
.contract-chat-msg.user {
  align-self: flex-end;
  background: rgba(160, 140, 91, 0.15);
  color: var(--text-primary);
  border-bottom-right-radius: 4px;
}
.contract-chat-msg.assistant {
  align-self: flex-start;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border-bottom-left-radius: 4px;
}
.contract-chat-msg.loading {
  align-self: flex-start;
  background: var(--bg-tertiary);
  color: var(--text-muted);
  font-style: italic;
}
.contract-chat-input-area {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.04);
  align-items: flex-end;
}
.contract-chat-input {
  flex: 1;
  background: var(--bg-primary);
  border: 1.5px solid rgba(255,255,255,0.06);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  padding: 10px 14px;
  resize: none;
  max-height: 100px;
  overflow-y: auto;
  outline: none;
  transition: border-color var(--transition-fast);
}
.contract-chat-input:focus {
  border-color: rgba(160, 140, 91, 0.4);
}
.contract-chat-input::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}
.contract-chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #b89e6a, #a08c5b);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition-fast);
}
.contract-chat-send-btn:hover {
  background: linear-gradient(135deg, #c9ae77, #b89e6a);
}

/* ============================================
   Contract Preview Card (Chat)
   ============================================ */

.contract-card {
  background: var(--bg-secondary);
  border: 1px solid rgba(160, 140, 91, 0.3);
  border-radius: var(--radius-md);
  overflow: hidden;
  max-width: 320px;
}
.contract-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  background: rgba(160, 140, 91, 0.08);
  border-bottom: 1px solid rgba(160, 140, 91, 0.15);
}
.contract-card-icon {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: rgba(160, 140, 91, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #c4a96a;
  flex-shrink: 0;
}
.contract-card-info {
  flex: 1;
  min-width: 0;
}
.contract-card-title {
  font-size: 14px;
  font-weight: 700;
  color: #c4a96a;
}
.contract-card-date {
  font-size: 11px;
  color: var(--text-muted);
}
.contract-card-actions {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.contract-card-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: none;
  border: none;
  border-top: 1px solid rgba(160, 140, 91, 0.1);
  color: var(--text-secondary);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition-fast);
  width: 100%;
  text-align: left;
}
.contract-card-btn:first-child {
  border-top: none;
}
.contract-card-btn:hover {
  background: rgba(160, 140, 91, 0.08);
  color: #c4a96a;
}
.contract-card-btn svg {
  flex-shrink: 0;
}

/* ============================================
   Retry Button
   ============================================ */

.retry-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  margin-top: 6px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  color: var(--danger);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.retry-btn:hover {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}
