/* Dotsquares UI — light, cohesive theme (shared across login, chat, email) */
:root {
  --bg-gradient: linear-gradient(145deg, #f4f7fb 0%, #fef9f6 42%, #f0f7f4 100%);
  --surface: #ffffff;
  --surface-elevated: #ffffff;
  --border: rgba(30, 58, 95, 0.12);
  --border-strong: rgba(30, 58, 95, 0.2);
  --text: #1e293b;
  --text-muted: #64748b;
  --primary: #2d6a8f;
  --primary-hover: #245a7a;
  --primary-soft: rgba(45, 106, 143, 0.1);
  --accent: #c45c3e;
  --accent-soft: rgba(196, 92, 62, 0.12);
  --success: #0d9488;
  --shadow: 0 4px 24px rgba(30, 58, 95, 0.08);
  --shadow-soft: 0 2px 12px rgba(30, 58, 95, 0.06);
  --radius: 14px;
  --radius-sm: 10px;
  --font: "DM Sans", "Segoe UI", system-ui, sans-serif;
  --focus: 0 0 0 3px rgba(45, 106, 143, 0.35);
}

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

html {
  font-size: 16px;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg-gradient);
  background-attachment: fixed;
  line-height: 1.5;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Layout */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary) 0%, #3d8ab5 100%);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 1.1rem;
  box-shadow: var(--shadow-soft);
}

.brand-title {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}

.brand-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

/* Tabs */
.tab-nav {
  display: inline-flex;
  padding: 4px;
  background: var(--primary-soft);
  border-radius: 999px;
  border: 1px solid var(--border);
}

.tab-nav a {
  padding: 0.5rem 1.25rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: background 0.2s, color 0.2s;
}

.tab-nav a:hover {
  color: var(--primary);
  text-decoration: none;
}

.tab-nav a.is-active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-soft);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  border: none;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s, background 0.2s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, #3a7aa3 100%);
  color: #fff;
  box-shadow: 0 2px 12px rgba(45, 106, 143, 0.35);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-hover) 0%, var(--primary) 100%);
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--surface);
  color: var(--primary);
}

.btn-accent {
  background: var(--accent);
  color: #fff;
}

.btn-accent:hover {
  filter: brightness(1.05);
}

/* Cards */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.card-body {
  padding: 1.5rem;
}

/* Forms */
.field {
  margin-bottom: 1.25rem;
}

.field-label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.45rem;
  color: var(--text);
}

.field-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

.input,
.textarea,
select[multiple],
select.input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  font-family: inherit;
  font-size: 0.95rem;
  background: #fafbfc;
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}

select.input {
  cursor: pointer;
  appearance: auto;
  min-height: 2.75rem;
}

.input:focus,
.textarea:focus,
select[multiple]:focus,
select.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--focus);
  background: var(--surface);
}

.textarea {
  min-height: 120px;
  resize: vertical;
}

.radio-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.industries-checkbox-group {
  margin-top: 0.35rem;
}

.radio-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
}

.radio-pill input {
  accent-color: var(--primary);
}

/* Ensure HTML hidden attribute wins over component display rules */
[hidden] {
  display: none !important;
}

/* Chat */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 1000px;
  width: 100%;
  margin: 0 auto;
  padding: 1.25rem 1rem 1.5rem;
  min-height: 0;
}

.chat-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 420px;
  max-height: min(85vh, 735px);
  overflow: hidden;
}

.chat-toolbar {
  flex-shrink: 0;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 0.65rem 1rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

.chat-new-conversation {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: flex-start;
}

.msg {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  width: fit-content;
  max-width: min(100%, 34rem);
  min-width: 0;
  animation: fadeIn 0.35s ease;
}

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

.msg--bot {
  align-self: flex-start;
}

.msg--user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg-avatar {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
}

.msg--bot .msg-avatar {
  background: var(--primary-soft);
  color: var(--primary);
}

.msg--user .msg-avatar {
  background: var(--accent-soft);
  color: var(--accent);
}

.msg-bubble {
  flex: 0 1 auto;
  min-width: 0;
  padding: 0.65rem 0.95rem;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #fafbfc;
  font-size: 0.95rem;
  /* pre-line: keep intentional line breaks from API/user; collapse HTML indentation whitespace */
  white-space: pre-line;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.msg-bubble p {
  margin: 0;
}

.msg-bubble p + p {
  margin-top: 0.5em;
}

.msg--user .msg-bubble {
  background: linear-gradient(135deg, #e8f4f8 0%, #f5fafc 100%);
  border-color: rgba(45, 106, 143, 0.2);
}

.msg--bot .msg-bubble {
  background: var(--surface);
}

/* Typing indicator (left-aligned like assistant; hidden when not loading) */
.typing-row {
  display: flex;
  flex-shrink: 0;
  gap: 0.75rem;
  align-items: center;
  align-self: flex-start;
  padding: 0 1.25rem 0.5rem;
  margin-left: 0;
  min-height: 44px;
  max-width: min(100%, 20rem);
}

.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0.65rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-soft);
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary);
  opacity: 0.35;
  animation: bounce 1.2s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.35;
  }
  40% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

/* Loader overlay (optional) */
.loader-bar {
  height: 3px;
  background: linear-gradient(90deg, var(--primary-soft), var(--primary), var(--primary-soft));
  background-size: 200% 100%;
  animation: shimmer 1.2s ease infinite;
}

@keyframes shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: -100% 0;
  }
}

.chat-composer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.85);
}

.composer-row {
  display: flex;
  gap: 0.65rem;
  align-items: flex-end;
}

.chat-textarea {
  flex: 1;
  min-height: 52px;
  max-height: 160px;
  resize: none;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.45;
  background: #fafbfc;
}

.chat-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--focus);
  background: var(--surface);
}

.composer-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

/* Settings drawer */
.settings-panel {
  margin-top: 0.5rem;
  padding: 1rem;
  background: var(--primary-soft);
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border);
}

.settings-panel[hidden] {
  display: none !important;
}

/* Login center */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
}

.login-card {
  width: 100%;
  max-width: 420px;
}

.login-card .card-body {
  padding: 2rem;
}

.login-password-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.35rem 0.75rem;
  margin-top: 0.5rem;
  margin-bottom: 0.25rem;
}

.login-password-actions__sep {
  color: var(--text-muted);
  user-select: none;
}

.btn-link {
  background: none;
  border: none;
  padding: 0.35rem 0.5rem;
  font: inherit;
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--primary);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  border-radius: var(--radius-sm);
}

.btn-link:hover {
  color: var(--primary-hover);
}

.btn-link:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.login-password-hint {
  margin-top: 0.65rem;
  text-align: center;
  max-width: 22rem;
  margin-left: auto;
  margin-right: auto;
}

.login-logo {
  text-align: center;
  margin-bottom: 1.5rem;
}

.login-logo .brand-mark {
  margin: 0 auto 0.75rem;
  width: 56px;
  height: 56px;
  font-size: 1.5rem;
}

/* Email page grid */
.email-layout {
  flex: 1;
  max-width: min(100%, 1240px);
  width: 100%;
  margin: 0 auto;
  padding: 1.25rem clamp(1rem, 2.5vw, 2rem) 2rem;
  box-sizing: border-box;
}

.email-grid {
  display: grid;
  gap: 1.25rem;
}

@media (min-width: 960px) {
  .email-grid-split {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 1.5rem;
    align-items: start;
  }
}

.output-panel {
  position: sticky;
  top: 1rem;
}

.draft-output-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.45rem;
}

.draft-output-head__label {
  margin-bottom: 0;
}

.draft-copy-btn {
  flex-shrink: 0;
  min-width: 2.25rem;
  min-height: 2.25rem;
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.draft-copy-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.draft-copy-btn__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.draft-copy-btn__done {
  display: none;
  white-space: nowrap;
}

.draft-copy-btn.is-copied {
  min-width: 4.25rem;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
}

.draft-copy-btn.is-copied .draft-copy-btn__icon {
  display: none;
}

.draft-copy-btn.is-copied .draft-copy-btn__done {
  display: inline;
}

.draft-markdown-preview {
  min-height: 14rem;
  max-height: min(70vh, 32rem);
  overflow: auto;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle, #e5e7eb);
  background: var(--surface-elevated, #fafafa);
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--text-primary, #111827);
}

.draft-markdown-preview:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted, #6b7280);
  white-space: pre-wrap;
}

.draft-markdown-preview p {
  margin: 0 0 0.75rem;
}

.draft-markdown-preview p:last-child {
  margin-bottom: 0;
}

.draft-markdown-preview strong {
  font-weight: 700;
}

.draft-markdown-preview a {
  color: var(--accent, #0d9488);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.draft-markdown-preview a:hover {
  text-decoration-thickness: 2px;
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.alert-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
}

.alert-success {
  background: #f0fdfa;
  border: 1px solid #99f6e4;
  color: #0f766e;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

   .msg-bubble--md {
    white-space: normal; /* override pre-line */
    line-height: 1.6;
  }
  
  /* Headings */
  .msg-bubble--md h1,
  .msg-bubble--md h2,
  .msg-bubble--md h3,
  .msg-bubble--md h4,
  .msg-bubble--md h5,
  .msg-bubble--md h6 {
    margin: 0.4rem 0 0.6rem;
    font-weight: 700;
    line-height: 1.3;
  }
  
  .msg-bubble--md h1 { font-size: 1.4rem; }
  .msg-bubble--md h2 { font-size: 1.25rem; }
  .msg-bubble--md h3 { font-size: 1.15rem; }
  
  /* Paragraphs */
  .msg-bubble--md p {
    margin: 0.4rem 0;
  }
  
  /* Lists */
  .msg-bubble--md ul,
  .msg-bubble--md ol {
    padding-left: 1.2rem;
    margin: 0.4rem 0;
  }
  
  .msg-bubble--md li {
    margin-bottom: 0.25rem;
  }
  
  /* Links */
  .msg-bubble--md a {
    color: var(--primary);
    text-decoration: underline;
    word-break: break-word;
  }
  
  /* Inline code */
  .msg-bubble--md code {
    background: #f1f5f9;
    padding: 2px 5px;
    border-radius: 4px;
    font-size: 0.85em;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  }
  
  /* Code blocks */
  .msg-bubble--md pre {
    background: #0f172a;
    color: #e2e8f0;
    padding: 0.75rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.5rem 0;
  }
  
  .msg-bubble--md pre code {
    background: transparent;
    padding: 0;
    color: inherit;
  }
  
  /* Blockquotes */
  .msg-bubble--md blockquote {
    border-left: 3px solid var(--primary);
    padding-left: 0.75rem;
    margin: 0.5rem 0;
    color: var(--text-muted);
  }
  
  /* Tables */
  .msg-bubble--md table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.5rem 0;
    font-size: 0.9rem;
  }
  
  .msg-bubble--md th,
  .msg-bubble--md td {
    border: 1px solid var(--border);
    padding: 6px 8px;
    text-align: left;
  }
  
  .msg-bubble--md th {
    background: var(--primary-soft);
    font-weight: 600;
  }
  
  /* Horizontal rule */
  .msg-bubble--md hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 0.75rem 0;
  }