/* ============================================================
   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: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 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%); }
}

/* ============================================================
   CHAT HEADER — minimal top bar with business name
   ============================================================ */
.chat-header {
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  padding: 14px 16px 10px;
  padding-top: max(14px, calc(env(safe-area-inset-top) + 8px));
  letter-spacing: -0.01em;
  flex-shrink: 0;
}

/* ============================================================
   MESSAGES
   ============================================================ */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px 16px;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.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); }
}

/* ============================================================
   INPUT BAR — card style matching Flutter app
   ============================================================ */
.input-area {
  padding: 0 12px 20px;
  padding-bottom: max(20px, calc(env(safe-area-inset-bottom, 0px) + 16px));
  background: var(--bg);
}
.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-action {
  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-action:disabled { opacity: 0.3; pointer-events: none; }
.btn-action:active { transform: scale(0.9); }
.btn-mic.listening {
  background: var(--red);
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220,38,38,0.4); }
  50% { box-shadow: 0 0 0 8px rgba(220,38,38,0); }
}

/* ============================================================
   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; }

/* ============================================================
   MANAGE VIEW
   ============================================================ */
.manage-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  min-height: 100%;
}
.manage-container {
  flex: 1;
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
  padding: 40px 20px 24px;
}
.manage-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding-top: 120px;
}
.manage-header {
  margin-bottom: 24px;
}
.manage-badge {
  display: inline-block;
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
}
.manage-badge-active { background: var(--green-bg); color: #166534; }
.manage-badge-cancelled { background: var(--red-bg); color: var(--red); }
.manage-badge-hold { background: #FEF3C7; color: #92400E; }
.manage-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}
.manage-subtitle {
  font-size: 15px;
  color: var(--text-sec);
  margin: 4px 0 0;
}
.manage-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 4px 0;
  margin-bottom: 20px;
}
.manage-detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.manage-detail-row:last-child { border-bottom: none; }
.manage-label {
  font-size: 14px;
  color: var(--text-sec);
}
.manage-value {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  text-align: right;
}
.manage-code {
  font-family: 'SF Mono', 'Monaco', monospace;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.manage-policy {
  padding: 16px 20px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 20px;
}
.manage-policy-warn { background: #FEF3C7; color: #92400E; }
.manage-policy-refund { background: var(--green-bg); color: #166534; }
.manage-policy-no-refund { background: var(--red-bg); color: #991B1B; }
.manage-policy-success { background: var(--green-bg); color: #166534; }
.btn-cancel {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  background: var(--red);
  color: #fff;
  border: none;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.15s;
}
.btn-cancel:active { transform: scale(0.97); opacity: 0.9; }
.btn-cancel:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-back {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  background: none;
  color: var(--text-sec);
  border: 1px solid var(--border);
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 10px;
  transition: background 0.15s;
}
.btn-back:active { background: var(--bg-alt); }
.manage-email-hint {
  font-size: 14px;
  color: var(--text-sec);
  margin: 0 0 10px;
}
.manage-email-input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--bg-card);
  outline: none;
  margin-bottom: 12px;
  box-sizing: border-box;
}
.manage-email-input:focus { border-color: var(--text); }
.manage-powered { padding: 16px 0 max(16px, env(safe-area-inset-bottom)); }

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

/* Powered by */
.powered-by {
  display: block;
  text-align: center;
  font-size: 11px;
  color: var(--text-ter);
  text-decoration: none;
  letter-spacing: 0.02em;
}
.powered-by span {
  font-weight: 600;
  color: var(--text-sec);
}
.powered-by-outer {
  position: fixed;
  bottom: max(2px, env(safe-area-inset-bottom, 0px));
  left: 0;
  right: 0;
  z-index: 10;
}

/* ============================================================
   RTL SUPPORT
   ============================================================ */
[dir="rtl"] .msg-user { justify-content: flex-start; }
[dir="rtl"] .msg-assistant { padding-right: 0; padding-left: 48px; }
[dir="rtl"] .msg-bubble { border-radius: 4px 18px 18px 18px; }
[dir="rtl"] .msg-user .msg-time { text-align: left; }
[dir="rtl"] .input-bottom { justify-content: flex-start; }
[dir="rtl"] .chat-header { direction: rtl; }

/* ============================================================
   DESKTOP — center app column at 480px
   ============================================================ */
@media (min-width: 600px) {
  .view {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    top: 24px;
    bottom: 24px;
    border-radius: 20px;
    box-shadow: 0 0 40px rgba(0,0,0,0.08);
    overflow: hidden;
  }
  .install-banner {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    max-width: 480px;
  }
}
