:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --text: #1a1d26;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --border-light: #f3f4f6;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-light: #eef2ff;
  --green: #10b981;
  --green-light: #f0fdf4;
  --red: #ef4444;
  --amber: #f59e0b;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.05);
  --radius: 0.75rem;
  --radius-sm: 0.5rem;
  --radius-lg: 1rem;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.app-container { max-width: 700px; margin: 0 auto; padding: 1rem 0.75rem; }

.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem; flex-wrap: wrap; gap: 0.5rem;
}
.page-title { font-size: 1.25rem; font-weight: 800; letter-spacing: -0.02em; }
.back-link {
  color: var(--text-muted); text-decoration: none; font-size: 0.75rem;
  padding: 0.375rem 0.75rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
  transition: all 0.15s;
}
.back-link:hover { color: var(--text); border-color: var(--text-muted); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 0.375rem;
  padding: 0.625rem 1.25rem; border-radius: var(--radius-sm);
  font-size: 0.8125rem; font-weight: 600; border: none; cursor: pointer;
  transition: all 0.15s; font-family: inherit; white-space: nowrap; text-decoration: none;
}
.btn-start {
  padding: 1rem 2.25rem; font-size: 1.125rem; font-weight: 650;
  border-radius: var(--radius); letter-spacing: 0.01em;
}
.btn-start .arrow-right {
  font-size: 1.4rem; font-weight: 300; margin-left: 0.25rem;
  transition: transform 0.2s ease;
}
.btn-start:hover .arrow-right { transform: translateX(3px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: var(--bg); color: var(--text-secondary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border-light); }
.btn-outline { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn-outline:hover { background: var(--accent-light); }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.75rem; }
.btn-send {
  padding: 0 1.25rem; height: 44px; font-size: 1.125rem;
  border-radius: 1.25rem; min-width: 56px;
}
.btn-xs { padding: 0.25rem 0.5rem; font-size: 0.6875rem; border-radius: 4px; }

/* ==================== CHAT ==================== */
.chat-container {
  background: #e8e8e8; border-radius: var(--radius-lg);
  box-shadow: var(--shadow); overflow: hidden;
  /* Telegram-style background pattern */
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23d4d4d4' fill-opacity='0.4'%3E%3Ccircle cx='30' cy='30' r='2'/%3E%3Cpath d='M0 30 Q15 15 30 30 Q45 45 60 30' stroke='%23d4d4d4' stroke-width='1' fill='none' opacity='0.3'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  background-size: 120px 120px;
}
/* Chat header */
.chat-header {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: #f8f9fc;
  border-bottom: 1px solid var(--border-light);
}
.chat-header-avatar {
  width: 48px; height: 48px; border-radius: 50%; overflow: hidden;
  flex-shrink: 0; border: 2px solid var(--accent-light);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.chat-header-avatar img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-name {
  font-size: 0.9375rem; font-weight: 700; color: var(--text);
  line-height: 1.3;
}
.chat-header-status {
  display: flex; align-items: center; gap: 0.375rem;
  font-size: 0.6875rem; color: var(--text-secondary);
}
.online-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #22c55e; display: inline-block;
  flex-shrink: 0;
  animation: pulse-dot 2s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(34,197,94,0.4); }
  50% { opacity: 0.7; box-shadow: 0 0 0 5px rgba(34,197,94,0); }
}

.chat-messages {
  padding: 1rem 0.875rem; min-height: 400px; max-height: 65vh;
  overflow-y: auto; display: flex; flex-direction: column; gap: 0.625rem;
  background: transparent;
}
.chat-placeholder {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 3rem 1rem; gap: 1rem; text-align: center;
}
.chat-placeholder-icon { font-size: 2.5rem; }
.chat-placeholder-text {
  font-size: 1rem; color: var(--text); max-width: 380px; line-height: 1.65;
  min-height: 80px;
}
.chat-placeholder-text .cursor {
  display: inline-block; width: 2px; height: 1.1em; background: var(--accent);
  vertical-align: text-bottom; animation: blink 0.7s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.btn-appear {
  animation: fadeInUp 0.4s ease;
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.chat-msg {
  max-width: 90%; padding: 0.625rem 0.875rem; border-radius: var(--radius);
  font-size: 0.9375rem; line-height: 1.55; animation: msgIn 0.2s ease;
}
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
/* Typing dots animation (Telegram-style) */
.typing-dots {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 0;
}
.typing-dots span {
  width: 7px; height: 7px; border-radius: 50%;
  background: #90949c;
  animation: typingBounce 1.4s ease-in-out infinite;
}
.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; }
}
.typing-removing { opacity: 0; transition: opacity 0.15s; }
.chat-msg.ai .typing-dots { padding-left: 0; }
.chat-msg.ai {
  align-self: flex-start;
  background: #ffffff; color: var(--text);
  border-top-left-radius: 4px;
  display: flex; gap: 0.5rem; align-items: flex-start;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.chat-msg.ai .msg-avatar {
  width: 24px; height: 24px; border-radius: 50%; flex-shrink: 0;
  overflow: hidden; margin-top: 2px;
}
.chat-msg.ai .msg-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-msg.ai .msg-body { flex: 1; min-width: 0; }
.chat-msg.user {
  align-self: flex-end;
  background: #2ea6ff; color: #fff;
  border-top-right-radius: 4px;
  box-shadow: 0 1px 2px rgba(46,166,255,0.2);
}
.chat-msg .msg-sender {
  font-size: 0.625rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.04em; margin-bottom: 0.125rem; opacity: 0.7;
}
.chat-msg.user .msg-sender { opacity: 0.8; }
.chat-msg.ai strong { color: var(--accent); }
.chat-input-row {
  display: flex; gap: 0.5rem; padding: 0.625rem 0.875rem;
  border-top: 1px solid var(--border-light); align-items: flex-end;
  background: #f8f9fc;
}
.chat-input {
  flex: 1; padding: 0.625rem 0.875rem; border: 1px solid var(--border);
  border-radius: 1.25rem; font-size: 0.9375rem; font-family: inherit;
  background: #ffffff; color: var(--text); resize: none;
  transition: border-color 0.15s; min-height: 44px; max-height: 140px;
}
.chat-input:focus { outline: none; border-color: var(--accent); }
.chat-status {
  padding: 0.5rem 0.875rem; font-size: 0.75rem; color: var(--text-muted);
  display: flex; align-items: center; gap: 0.5rem;
  background: #f8f9fc;
}
.spinner {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.3); border-top-color: #fff;
  border-radius: 50%; animation: spin 0.6s linear infinite;
  vertical-align: middle; margin-right: 4px;
}
.spinner-dark {
  display: inline-block; width: 18px; height: 18px;
  border: 2px solid rgba(99,102,241,0.2); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.6s linear infinite;
  vertical-align: middle; margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ==================== PDF CARD ==================== */
.pdf-card {
  display: flex; gap: 0.875rem; align-items: center;
  padding: 0.875rem; background: var(--card); border-radius: var(--radius);
  border: 1px solid var(--border); margin-top: 0.25rem;
}
.pdf-card-icon { font-size: 2rem; flex-shrink: 0; }
.pdf-card-info { flex: 1; min-width: 0; }
.pdf-card-title { font-size: 0.875rem; font-weight: 700; margin-bottom: 0.125rem; }
.pdf-card-meta { font-size: 0.6875rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.pdf-download-btn { font-size: 0.75rem !important; padding: 0.375rem 0.75rem !important; }

/* ==================== ACTION CARD ==================== */
.action-card {
  background: var(--accent-light); padding: 1rem; border-radius: var(--radius);
  border: 1px solid rgba(99,102,241,0.2); margin-top: 0.25rem;
}
.action-card-title { font-size: 0.9375rem; font-weight: 700; margin-bottom: 0.25rem; }
.action-card-desc { font-size: 0.8125rem; color: var(--text-secondary); margin-bottom: 0.75rem; }

/* ==================== SEGMENT CARDS EMBED ==================== */
.segment-cards-embed {
  display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.5rem;
}
.segment-card-embed {
  background: var(--card); padding: 0.75rem; border-radius: var(--radius-sm);
  border: 2px solid var(--border); cursor: pointer; transition: all 0.15s;
  position: relative;
}
.segment-card-embed:hover { border-color: var(--accent); }
.segment-card-embed.selected { border-color: var(--accent); background: var(--accent-light); }
.segment-card-embed .seg-check {
  position: absolute; top: 8px; right: 8px;
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--border); display: flex; align-items: center; justify-content: center;
  font-size: 0.625rem; color: transparent; transition: all 0.2s;
}
.segment-card-embed.selected .seg-check { border-color: var(--accent); background: var(--accent); color: #fff; }
.segment-card-embed .seg-title { font-size: 0.875rem; font-weight: 700; margin-bottom: 0.25rem; padding-right: 24px; }
.segment-card-embed .seg-situation { font-size: 0.75rem; color: var(--text-secondary); line-height: 1.5; }
.segment-card-embed .seg-quote {
  font-size: 0.6875rem; font-style: italic; color: var(--accent);
  padding: 0.375rem 0.5rem; background: var(--accent-light);
  border-radius: var(--radius-sm); margin-top: 0.375rem;
}

/* ==================== OFFER CARDS EMBED ==================== */
.offer-cards-embed {
  display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.5rem;
}
.offer-card-embed {
  background: var(--card); padding: 0.875rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); transition: all 0.15s;
}
.offer-card-embed .model-badge {
  display: inline-block; font-size: 0.5625rem; font-weight: 700; text-transform: uppercase;
  padding: 2px 8px; border-radius: 999px; margin-bottom: 0.5rem;
  background: var(--accent-light); color: var(--accent);
}
.offer-card-embed .offer-headline { font-size: 1rem; font-weight: 700; margin-bottom: 0.25rem; line-height: 1.3; }
.offer-card-embed .offer-sub { font-size: 0.75rem; color: var(--text-secondary); margin-bottom: 0.5rem; line-height: 1.5; }
.offer-card-embed .offer-bullets { font-size: 0.75rem; margin-bottom: 0.5rem; color: var(--text); padding-left: 1.125rem; }
.offer-card-embed .offer-bullets li { margin-bottom: 0.125rem; }
.offer-card-embed .offer-cta {
  display: inline-block; padding: 0.375rem 0.75rem;
  background: var(--accent); color: #fff; border-radius: var(--radius-sm);
  font-size: 0.75rem; font-weight: 600; margin-bottom: 0.5rem;
}
.offer-actions { display: flex; gap: 0.375rem; flex-wrap: wrap; }

/* ==================== TOAST ==================== */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 10px 20px;
  border-radius: var(--radius-sm); font-size: 0.8125rem; font-weight: 500;
  z-index: 999; opacity: 0; transition: opacity 0.3s; pointer-events: none;
}
.toast.show { opacity: 1; }
CSSEOF
echo "CSS updated"