/* =================================================
   Citizens Advice Wales -- Global Styles
   Clean, minimal, Apple-inspired. CA branding.
   ================================================= */

:root {
  --ca-blue: #004B88;
  --ca-blue-dark: #003a6b;
  --ca-blue-light: #e4eef8;
  --ca-blue-muted: #d6e3f0;
  --text-primary: #2c2c2e;
  --text-secondary: #636366;
  --text-tertiary: #98989d;
  --bg-primary: #ffffff;
  --bg-page: #f5f5f7;
  --bg-subtle: #fafafa;
  --border: #d2d2d7;
  --border-light: #e5e5ea;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.04);
  --shadow-md: 0 2px 12px rgba(0,0,0,0.06), 0 0 1px rgba(0,0,0,0.04);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.08);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --transition: 0.2s ease;
}

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

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: linear-gradient(180deg, #f5f5f7 0%, #eeeef0 100%);
  background-attachment: fixed;
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: -0.01em;
}

/* -- HEADER ----------------------------------------- */
header {
  background: linear-gradient(180deg, #ffffff 0%, #fafafe 100%);
  border-bottom: 1px solid var(--border-light);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}

header img {
  width: 130px;
  height: auto;
}

.header-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.btn-new-chat {
  padding: 7px 16px;
  background: var(--ca-blue);
  color: #fff;
  border: none;
  border-radius: 980px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
  letter-spacing: 0;
}
.btn-new-chat:hover {
  background: var(--ca-blue-dark);
  transform: scale(1.02);
}
.btn-new-chat:active { transform: scale(0.98); }

.header-logout {
  font-size: 13px;
  color: var(--text-tertiary);
  text-decoration: none;
  transition: color var(--transition);
}
.header-logout:hover { color: var(--ca-blue); text-decoration: underline; }

.btn-config {
  padding: 7px 16px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 980px;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: all var(--transition);
  letter-spacing: 0;
}
.btn-config:hover {
  border-color: var(--ca-blue);
  color: var(--ca-blue);
  background: var(--ca-blue-light);
}

/* -- MAIN ------------------------------------------- */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 20px 16px;
}

/* -- CARDS (login, setup notice) -------------------- */
.login-card,
.setup-notice,
.success-banner {
  background: linear-gradient(180deg, #ffffff 0%, #fafbfc 100%);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-light);
  padding: 44px 36px;
  width: 100%;
  text-align: center;
}

.login-card { max-width: 400px; margin-top: 48px; }
.setup-notice { max-width: 480px; }
.success-banner { max-width: 960px; padding: 28px 32px; margin-bottom: 20px; }

.login-card h1,
.setup-notice h2 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
  letter-spacing: -0.02em;
}

.login-card p,
.setup-notice p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 28px;
  line-height: 1.5;
}

/* -- FORM ELEMENTS ---------------------------------- */
input[type="password"],
textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  background: var(--bg-primary);
  color: var(--text-primary);
}
input[type="password"]:focus,
textarea:focus {
  border-color: var(--ca-blue);
  box-shadow: 0 0 0 3px rgba(0, 75, 136, 0.1);
}
input[type="password"] { margin-bottom: 16px; }

/* -- BUTTONS ---------------------------------------- */
.btn-primary,
.login-card button,
.setup-notice a {
  display: inline-block;
  padding: 10px 24px;
  background: var(--ca-blue);
  color: #fff;
  border: none;
  border-radius: 980px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition), transform var(--transition);
  letter-spacing: 0;
}
.btn-primary:hover,
.login-card button:hover,
.setup-notice a:hover {
  background: var(--ca-blue-dark);
  transform: scale(1.02);
}
.btn-primary:active,
.login-card button:active,
.setup-notice a:active { transform: scale(0.98); }

.login-card button { width: 100%; }

.btn-secondary {
  display: inline-block;
  padding: 9px 22px;
  background: transparent;
  color: var(--ca-blue);
  border: 1px solid var(--border);
  text-decoration: none;
  border-radius: 980px;
  font-size: 15px;
  font-weight: 500;
  margin-left: 10px;
  transition: all var(--transition);
}
.btn-secondary:hover {
  border-color: var(--ca-blue);
  background: var(--ca-blue-light);
}

/* -- ERROR / STATUS --------------------------------- */
.error-msg {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
  border-radius: var(--radius-md);
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 13px;
}

.setup-notice {
  border-color: #fde68a;
  background: #fffbeb;
}
.setup-notice h2 { color: var(--text-primary); }

.success-banner {
  border-color: #bbf7d0;
  background: #f0fdf4;
}
.success-banner h2 {
  color: #16a34a;
  font-size: 18px;
  margin-bottom: 6px;
}
.success-banner p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 16px;
}

/* -- INFO BANNER ------------------------------------ */
.info-banner {
  width: 100%;
  max-width: 800px;
  background: var(--ca-blue-light);
  border: 1px solid var(--ca-blue-muted);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--ca-blue-dark);
  line-height: 1.5;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.info-banner-icon {
  font-size: 16px;
  line-height: 1.3;
  flex-shrink: 0;
}

/* -- CHAT ------------------------------------------- */
.chat-wrapper {
  width: 100%;
  max-width: 800px;
  display: flex;
  flex-direction: column;
  flex: none;
}

.chat-messages {
  background: linear-gradient(180deg, #ffffff 0%, #fafbfd 100%);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  border: 1px solid var(--border-light);
  border-bottom: none;
  padding: 24px;
  min-height: 200px;
  height: calc(100vh - 400px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.message {
  display: flex;
  flex-direction: column;
  max-width: 78%;
  animation: fadeUp 0.25s ease;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.message:first-child { margin-top: auto; }
.message.user { align-self: flex-end; align-items: flex-end; }
.message.ai { align-self: flex-start; align-items: flex-start; }

.message-label {
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  opacity: 0.7;
}

.message-bubble {
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
}
.message.user .message-bubble {
  background: var(--ca-blue);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.message.ai .message-bubble {
  background: linear-gradient(180deg, #f9f9fb 0%, #f3f3f6 100%);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border-light);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}

/* -- TYPING INDICATOR ------------------------------- */
.typing-indicator {
  display: none;
  align-self: flex-start;
  padding: 12px 16px;
  background: var(--bg-page);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  border-bottom-left-radius: 4px;
}
.typing-indicator.visible { display: flex; align-items: center; gap: 6px; }

.typing-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.typing-dots { display: flex; gap: 4px; align-items: center; }
.typing-dots span {
  width: 6px; height: 6px;
  background: var(--text-tertiary);
  border-radius: 50%;
  animation: bounce 1.2s 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; }

.typing-status {
  display: none;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  transition: opacity 0.3s ease;
}
.typing-status.visible { display: block; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* -- CHAT INPUT ------------------------------------- */
.chat-input-area {
  background: linear-gradient(180deg, #fafbfc 0%, #f5f5f7 100%);
  border: 1px solid var(--border-light);
  border-top: none;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  padding: 14px 16px;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.input-wrapper {
  flex: 1;
  position: relative;
}

#chat-input {
  width: 100%;
  padding: 12px 44px 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  min-height: 90px;
  line-height: 1.4;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  background: var(--bg-primary);
  color: var(--text-primary);
}
#chat-input:focus {
  border-color: var(--ca-blue);
  box-shadow: 0 0 0 3px rgba(0, 75, 136, 0.1);
}
#chat-input::placeholder {
  color: var(--text-tertiary);
  font-size: 14px;
}

.stop-btn {
  position: absolute;
  right: 8px;
  bottom: 15px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: var(--ca-blue);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), opacity var(--transition);
}
.stop-btn:hover:not(:disabled) {
  background: var(--ca-blue-dark);
}
.stop-btn:disabled {
  background: var(--border);
  color: var(--text-tertiary);
  cursor: default;
  opacity: 0.5;
}

#send-btn {
  padding: 12px 22px;
  background: linear-gradient(180deg, #0057a0 0%, var(--ca-blue) 100%);
  color: #fff;
  border: none;
  border-radius: 980px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), transform var(--transition);
}
#send-btn:hover { background: var(--ca-blue-dark); transform: scale(1.02); }
#send-btn:active { transform: scale(0.98); }
#send-btn:disabled { background: var(--border); cursor: not-allowed; transform: none; }

/* -- HINT CHIPS ------------------------------------- */
.chat-hints {
  width: 100%;
  max-width: 800px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
}
.hint-chip {
  padding: 6px 14px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 980px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}
.hint-chip:hover {
  border-color: var(--ca-blue);
  color: var(--ca-blue);
  background: var(--ca-blue-light);
  box-shadow: 0 1px 4px rgba(0, 75, 136, 0.1);
}

.chat-footer-hint {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 10px;
  max-width: 800px;
  text-align: center;
  line-height: 1.5;
}

/* -- SETUP PAGE ------------------------------------- */
.setup-header {
  width: 100%;
  max-width: 960px;
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.setup-header h1 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 14px;
  border-radius: 980px;
  font-size: 13px;
  font-weight: 500;
}
.status-badge.configured { background: #f0fdf4; color: #16a34a; border: 1px solid #bbf7d0; }
.status-badge.pending { background: #fffbeb; color: #ca8a04; border: 1px solid #fde68a; }

.instructions {
  background: var(--ca-blue-light);
  border: 1px solid var(--ca-blue-muted);
  border-left: 3px solid var(--ca-blue);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.7;
  margin-bottom: 20px;
  max-width: 960px;
  width: 100%;
}
.instructions strong {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 600;
}
.instructions ol { padding-left: 20px; }
.instructions ol li { margin-bottom: 4px; }

.embed-wrapper {
  width: 100%;
  max-width: 960px;
  height: 800px;
  background: var(--bg-primary);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.embed-wrapper iframe,
.embed-wrapper zapier-mcp { display: block; width: 100%; height: 100%; }

#save-bar {
  width: 100%;
  max-width: 960px;
  background: var(--ca-blue-light);
  border: 1px solid var(--ca-blue-muted);
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  margin-bottom: 16px;
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
  color: var(--text-primary);
}

.logout-link {
  margin-top: 20px;
  font-size: 13px;
}
.logout-link a {
  color: var(--text-tertiary);
  text-decoration: none;
  transition: color var(--transition);
}
.logout-link a:hover { color: var(--ca-blue); }

/* -- FOOTER ----------------------------------------- */
footer {
  background: #d4e5ef;
  border-top: 1px solid #c4d5e0;
  color: #4a4a4f;
  text-align: center;
  padding: 16px;
  font-size: 13px;
  margin-top: auto;
}

/* -- RESPONSIVE ------------------------------------- */
@media (max-width: 768px) {
  header { padding: 12px 16px; }
  header img { width: 110px; }
  main { padding: 20px 16px; }

  .login-card { padding: 32px 24px; }
  .chat-messages { height: calc(100vh - 300px); padding: 16px; }
  .message { max-width: 90%; }
  .chat-hints { gap: 6px; }
  .hint-chip { font-size: 12px; padding: 5px 12px; }

  .chat-input-area { padding: 12px; }
  #chat-input { min-height: 80px; padding: 12px 14px; }
  #send-btn { padding: 12px 20px; }

  .setup-header { flex-direction: column; gap: 10px; align-items: flex-start; }
  .embed-wrapper { height: 600px; }
  .instructions { font-size: 13px; }
}

@media (max-width: 480px) {
  header img { width: 100px; }
  .btn-new-chat { font-size: 12px; padding: 6px 12px; }
  .login-card { padding: 28px 20px; margin-top: 24px; }
  .login-card h1 { font-size: 20px; }
  .chat-messages { height: calc(100vh - 300px); padding: 12px; gap: 12px; }
  .message-bubble { font-size: 13px; padding: 9px 13px; }
  .chat-input-area { padding: 10px; gap: 8px; }
  #chat-input { min-height: 76px; padding: 10px 12px; }
  #send-btn { padding: 12px 18px; font-size: 14px; }
  .embed-wrapper { height: 500px; }
}

#capture-status { display: none; }
