/* ============================================================
   CEREBRO PWA — Matches Flutter app chat UI exactly
   ============================================================ */

:root {
  --bg: #FAFAFA;
  --bg-card: #FFFFFF;
  --bg-alt: #F3F4F6;
  --text: #111111;
  --text-sec: #6B7280;
  --text-ter: #9CA3AF;
  --border: #E5E7EB;
  --blue: #2563EB;
  --blue-bg: #DBEAFE;
  --green: #16A34A;
  --green-bg: #DCFCE7;
  --red: #DC2626;
  --red-bg: #FEE2E2;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'Inter', -apple-system, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   VIEWS
   ============================================================ */
.view {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ============================================================
   LOADING VIEW
   ============================================================ */
.loading-view {
  align-items: center;
  justify-content: center;
  gap: 24px;
}
.loading-logo { opacity: 0.9; }
.loading-bar {
  width: 120px;
  height: 3px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.loading-bar-fill {
  width: 40%;
  height: 100%;
  background: var(--text);
  border-radius: 4px;
  animation: loading 1.2s ease-in-out infinite;
}
@keyframes loading {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}

/* ============================================================
   HOME VIEW
   ============================================================ */
.home-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 20px;
  padding-top: max(16px, env(safe-area-inset-top));
}
.home-title {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
}
.businesses-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 16px;
  -webkit-overflow-scrolling: touch;
}
.biz-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: var(--bg-card);
  border-radius: 16px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
  margin-bottom: 10px;
  cursor: pointer;
  transition: transform 0.15s ease;
}
.biz-card:active { transform: scale(0.98); }
.biz-card-avatar {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--bg-alt);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 600;
  color: var(--text-sec);
  flex-shrink: 0;
}
.biz-card-info { flex: 1; min-width: 0; }
.biz-card-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.biz-card-type {
  font-size: 12px;
  color: var(--text-ter);
  margin-top: 2px;
}
.biz-card-arrow { color: var(--text-ter); flex-shrink: 0; }
.home-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
}
.home-empty p { font-size: 16px; color: var(--text-sec); font-weight: 500; }
.home-empty-sub { font-size: 13px; color: var(--text-ter); margin-top: 6px; font-weight: 400; }
.home-footer {
  padding: 16px 20px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

/* ============================================================
   CHAT HEADER — minimal, no avatar
   ============================================================ */
.chat-header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 8px;
  padding-top: max(10px, env(safe-area-inset-top));
  z-index: 10;
}
.chat-header-info { flex: 1; min-width: 0; }
.chat-biz-name {
  display: block;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-biz-type {
  display: block;
  font-size: 12px;
  color: var(--text-ter);
  margin-top: 1px;
}

/* ============================================================
   MESSAGES — matches Flutter app exactly
   ============================================================ */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px;
  -webkit-overflow-scrolling: touch;
}

.msg {
  margin-bottom: 4px;
  animation: msgIn 0.2s ease-out;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Assistant — plain text, left aligned, no bubble, no avatar */
.msg-assistant {
  padding-right: 48px;
  margin-bottom: 12px;
}
.msg-assistant .msg-text {
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
}
.msg-assistant .msg-time {
  font-size: 10px;
  color: var(--text-ter);
  margin-top: 2px;
}

/* User — dark bubble, right aligned, shadow */
.msg-user {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}
.msg-bubble {
  max-width: 75%;
  background: var(--text);
  color: #fff;
  padding: 12px 16px;
  border-radius: 18px 4px 18px 18px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}
.msg-user .msg-text {
  font-size: 16px;
  line-height: 1.4;
}
.msg-user .msg-time {
  font-size: 10px;
  color: rgba(255,255,255,0.5);
  margin-top: 4px;
  text-align: right;
}

/* Typing indicator */
.msg-typing {
  margin-bottom: 12px;
}
.msg-typing .msg-text {
  display: flex;
  gap: 5px;
  padding: 8px 0;
}
.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-ter);
  animation: typingBounce 1.2s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* Quick actions */
.quick-actions {
  display: flex;
  gap: 8px;
  padding: 4px 16px 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.quick-actions::-webkit-scrollbar { display: none; }
.chip {
  background: var(--bg-card);
  color: var(--text-sec);
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s;
}
.chip:active { background: var(--bg-alt); }

/* ============================================================
   INPUT BAR — card style matching Flutter app
   ============================================================ */
.input-area {
  padding: 8px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 85%, transparent);
}
.input-card {
  background: var(--bg-card);
  border-radius: 24px;
  border: 1px solid var(--border);
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
  padding: 6px 20px 0;
}
.input-card textarea {
  width: 100%;
  border: none;
  outline: none;
  background: none;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.4;
  color: var(--text);
  resize: none;
  max-height: 100px;
  padding: 12px 0 0;
}
.input-card textarea::placeholder { color: var(--text-ter); }
.input-bottom {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 10px 0 12px;
}
.btn-send {
  width: 36px;
  height: 36px;
  border-radius: 18px;
  background: var(--text);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s, transform 0.2s;
}
.btn-send:disabled { opacity: 0.3; pointer-events: none; }
.btn-send:active { transform: scale(0.9); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn-icon {
  width: 40px;
  height: 40px;
  border-radius: 20px;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  flex-shrink: 0;
  transition: background 0.15s;
}
.btn-icon:active { background: var(--bg-alt); }
.btn-secondary {
  width: 100%;
  padding: 14px;
  border-radius: 30px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s;
}
.btn-secondary:active { background: var(--bg-alt); }

/* ============================================================
   INSTALL BANNER
   ============================================================ */
.install-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 14px 20px;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  background: var(--text);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 100;
  animation: slideUp 0.3s ease-out;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.install-banner-text { font-size: 14px; font-weight: 500; }
.install-banner-btn {
  background: #fff;
  color: var(--text);
  border: none;
  padding: 8px 20px;
  border-radius: 30px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.install-banner-close {
  background: none;
  border: none;
  color: rgba(255,255,255,0.6);
  font-size: 20px;
  cursor: pointer;
  padding: 0 8px;
}

/* ============================================================
   RESULT VIEWS (success / cancelled)
   ============================================================ */
.result-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 32px;
  text-align: center;
  gap: 16px;
}
.result-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}
.result-icon-success { background: var(--green-bg); }
.result-icon-cancel { background: var(--red-bg); }
.result-title { font-size: 22px; font-weight: 700; color: var(--text); }
.result-text { font-size: 15px; color: var(--text-sec); line-height: 1.5; max-width: 280px; }
.btn-primary {
  margin-top: 12px;
  padding: 14px 40px;
  border-radius: 30px;
  background: var(--text);
  color: #fff;
  border: none;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.15s;
}
.btn-primary:active { transform: scale(0.96); opacity: 0.9; }

/* ============================================================
   UTILITIES
   ============================================================ */
.hidden { display: none !important; }
