@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap');

:root {
  --bg: #f3f6fb;
  --accent: #2563eb;
  --text: #0f172a;
  --muted: #475569;
  --card-bg: #ffffff;
}

/* Prevent layout shift from scrollbar appearing/disappearing */
html {
  overflow-y: scroll;
}

/* base */
body {
  font-family: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 1.25rem;
  font-size: 1rem;
  line-height: 1.6;
}

/* wider container for large screens */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem;
}

/* Typography hierarchy */
h1 {
  font-size: 2.5rem;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 1rem;
}

h2 {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 0.875rem;
}

h3 {
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 0.75rem;
}

h4 {
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 0.5rem;
}

p, .message, .chat-text {
  font-size: 1rem;
  line-height: 1.6;
}

/* header */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0;
}

header h1 {
  color: var(--accent);
  font-size: 2rem;
  margin: 0;
  text-transform: capitalize;
  font-weight: 700;
}

.site-brand {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo img {
  height: 64px;
  width: auto;
  display: block;
  border-radius: 6px;
}

/* profile avatar (top-right) */
.profile-area {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  position: relative;
}
.profile-dropdown {
  position: relative;
}
.profile-link {
  background: transparent;
  border: none;
  padding: 0;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  margin-left: 0.25rem;
}
.profile-img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  border: 2px solid #fff;
  box-shadow: 0 4px 12px rgba(15,23,42,0.08);
}

/* add (plus-in-box) icon beside the avatar */
.add-link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  margin-right: 0.25rem;
}
.add-img {
  width: 36px;
  height: 36px;
  display: block;
  border-radius: 8px;
  border: 2px solid #fff;
  box-shadow: 0 4px 12px rgba(15,23,42,0.06);
}

/* dropdown menu */
.profile-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 200px;
  background: var(--card-bg);
  border-radius: 8px;
  box-shadow: 0 12px 36px rgba(2,6,23,0.12);
  display: none;
  z-index: 60;
  padding: 0.25rem 0;
}
.profile-menu[aria-hidden="false"] { display: block; }
.profile-item {
  display: block;
  padding: 0.6rem 0.9rem;
  color: var(--text);
  text-decoration: none;
  font-size: 0.95rem;
}
.profile-item:hover {
  background: rgba(37,99,235,0.04);
}

@media (max-width: 767px) {
  .profile-img { width: 32px; height: 32px; }
  .add-img { width: 28px; height: 28px; }
  .profile-menu { right: 0; left: auto; min-width: 160px; }
} 

/* content card */
main {
  margin-top: 1.25rem;
}
.content-card {
  background: var(--card-bg);
  padding: 1.25rem;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

/* lead */
.lead {
  color: #334155;
  font-size: 1.25rem;
  line-height: 1.6;
  font-weight: 400;
}

/* form improvements */
.discover-form {
  margin-top: 1rem;
  display: grid;
  gap: 0.75rem;
}
.form-row {
  display: flex;
  flex-direction: column;
}

.form-row label {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.375rem;
  color: var(--text);
}

.form-row input[type="text"],
.form-row textarea,
.form-row input[type="file"] {
  width: 100%;
  padding: 0.875rem;
  border-radius: 10px;
  border: 1px solid #e6eefb;
  background: #fff;
  color: var(--text);
  box-sizing: border-box;
  font-size: 1rem;
}

.form-row input:focus,
.form-row textarea:focus {
  outline: none;
  box-shadow: 0 0 0 4px rgba(37,99,235,0.08);
  border-color: var(--accent);
}

/* buttons */
.btn-get-started {
  display: inline-block;
  padding: 0.65rem 1rem;
  background: var(--accent);
  color: white;
  text-decoration: none;
  border-radius: 10px;
  font-weight: 700;
  box-shadow: 0 6px 18px rgba(37,99,235,0.12);
  border: none;
  cursor: pointer;
}
.btn-get-started:hover { filter: brightness(0.95); }

/* Chat message styling */
.prose {
  max-width: 100%;
}

.prose h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-top: 1rem;
  margin-bottom: 0.5rem;
  color: #1e293b;
}

.prose h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-top: 0.75rem;
  margin-bottom: 0.5rem;
  color: #334155;
}

.prose ul {
  list-style-type: disc;
  margin-left: 1.5rem;
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
}

.prose ol {
  list-style-type: decimal;
  margin-left: 1.5rem;
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
}

.prose li {
  margin-bottom: 0.25rem;
  line-height: 1.6;
}

.prose p {
  margin-bottom: 0.75rem;
  line-height: 1.6;
}

.prose strong {
  font-weight: 600;
  color: #0f172a;
}

.prose code {
  background: #f1f5f9;
  padding: 0.125rem 0.25rem;
  border-radius: 0.25rem;
  font-size: 0.9em;
  font-family: monospace;
}

.prose pre {
  background: #f8fafc;
  padding: 0.75rem;
  border-radius: 0.5rem;
  overflow-x: auto;
  margin: 0.5rem 0;
}

/* responsive tweaks */
@media (min-width: 768px) {
  header h1 { font-size: 2.25rem; }
  h1 { font-size: 3rem; }
  h2 { font-size: 2.25rem; }
  h3 { font-size: 1.75rem; }
  .container { padding: 2rem; }
  .lead { font-size: 1.375rem; }
}

@media (max-width: 767px) {
  h1 { font-size: 2rem; }
  h2 { font-size: 1.5rem; }
  h3 { font-size: 1.25rem; }
  header h1 { font-size: 1.5rem; }
  .logo img { height: 48px; }

  /* Adjust chatbox height for mobile */
  .chatbox {
    min-height: 50vh; /* Smaller on mobile to save space */
  }

  .messages {
    max-height: calc(50vh - 120px);
  }
}

/* discover two-column layout (50/50) */
.discover-grid {
  display: grid;
  grid-template-columns: 1fr 1fr; /* now a 50/50 split */
  gap: 1rem;
  align-items: start;
}

.discover-grid .left,
.discover-grid .right {
  min-width: 0;
}

.discover-grid .right {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.chatbox {
  border: 1px dashed rgba(15,23,42,0.06);
  border-radius: 10px;
  min-height: 60vh; /* 60% of viewport height */
  background: linear-gradient(180deg, rgba(255,255,255,0.9), rgba(249,250,251,0.9));
  display: flex;
  flex-direction: column;
  padding: 1rem;
}

.messages {
  overflow-y: auto;
  max-height: calc(60vh - 120px); /* Adjust for padding and input area */
  flex-grow: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-bottom: 0.5rem;
}

.message {
  padding: 0.625rem 0.875rem;
  border-radius: 8px;
  max-width: 100%;
  box-shadow: 0 2px 6px rgba(15,23,42,0.03);
  font-size: 1rem;
  line-height: 1.6;
}

.message.user {
  align-self: flex-end;
  background: linear-gradient(90deg, rgba(37,99,235,0.1), rgba(37,99,235,0.06));
  color: var(--text);
}

.message.bot {
  align-self: flex-start;
  background: #f8fafc;
  color: var(--text);
}

/* Ensure proper hierarchy in bot messages */
.message.bot h1,
.message.bot h2,
.message.bot h3,
.message.bot h4 {
  margin-top: 0.75rem;
  margin-bottom: 0.5rem;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.message.bot h1:first-child,
.message.bot h2:first-child,
.message.bot h3:first-child,
.message.bot h4:first-child {
  margin-top: 0;
}

.message pre {
  background: transparent;
  border: none;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  padding: 0;
  margin: 0;
}

.message code {
  background: transparent;
  padding: 0;
  border-radius: 0;
}

.chat-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.chat-row {
  display: flex;
  gap: 0.5rem;
}

.chat-row input[type='text'] {
  flex: 1 1 auto;
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  border: 1px solid #e6eefb;
  background: #fff;
}

.chat-row button {
  /* give the Send button a fixed width so the input fills the rest */
  flex: 0 0 110px;
}

.chat-actions {
  display: flex;
  gap: 0.5rem;
  width: 100%;
}

.chat-actions button {
  /* each action button fills half the row (with gap in-between) */
  flex: 1 1 0;
  min-width: 0;
}
.chat-form input:focus {
  box-shadow: 0 0 0 4px rgba(37,99,235,0.06);
  border-color: var(--accent);
}

.muted { color: var(--muted); }

@media (max-width: 767px) {
  .discover-grid {
    grid-template-columns: 1fr;
  }
  .discover-grid .right {
    min-height: 160px;
  }
}

/* findings table */
.findings-controls { margin-bottom: 0.5rem; display:flex; justify-content:flex-end; }
.findings-scroll { max-height: 220px; overflow-y: auto; overflow-x: hidden; border-radius: 8px; border: 1px solid #f1f5f9; padding: 0.25rem; background: #fff; }
.findings-scroll-modern { max-height: calc(60vh - 200px); overflow-y: auto; overflow-x: hidden; }

.findings-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0;
  table-layout: fixed;
  font-size: 0.875rem;
}

.findings-table th {
  padding: 0.75rem;
  background: #f8fafc;
  border-bottom: 2px solid #e2e8f0;
  font-weight: 600;
  font-size: 0.875rem;
  color: #374151;
  position: sticky;
  top: 0;
  z-index: 10;
}

.findings-table td {
  padding: 0;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: top;
  width: 100%;
}

.findings-table .finding-row {
  transition: background-color 0.2s ease;
}


.findings-table .finding-row.selected {
  background-color: #eff6ff;
  border-left: 4px solid #3b82f6;
}

.findings-table .finding-row.selected .bg-gray-50 {
  background-color: #dbeafe;
}

.findings-table .finding-row {
  cursor: pointer;
}

.findings-table td {
  cursor: pointer;
}

.remove-finding {
  background: transparent;
  border: none;
  color: #ef4444;
  cursor: pointer;
  transition: all 0.2s ease;
}

.remove-finding:hover {
  background-color: #fef2f2;
  color: #dc2626;
}

@media (max-width: 767px) {
  .findings-scroll { max-height: 160px; }
  .findings-scroll-modern { max-height: calc(50vh - 150px); }

  .findings-table th {
    padding: 0.5rem;
    font-size: 0.75rem;
  }

  .findings-table td {
    padding: 0.75rem 0.5rem;
  }
}

.btn-ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid rgba(37,99,235,0.08);
  box-shadow: none;
}

.btn-note {
  background: #f59e0b;
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
}

/* Action buttons (copy, email) */
.btn-action {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-weight: 600;
  font-size: 0.875rem;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.btn-action:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.btn-action:active {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.btn-action svg {
  width: 1.25rem;
  height: 1.25rem;
}

/* Loading overlay */
#loading-overlay {
  backdrop-filter: blur(4px);
}

/* Spinner animation */
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.animate-spin {
  animation: spin 1s linear infinite;
}

/* Progress step styles */
#loading-overlay .step-indicator {
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.editable {
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* ========================================
   Markdown Table Styles for Findings/Chat
   ======================================== */

/* Base table styles for markdown-rendered tables */
.prose table,
.finding-row table,
.chat-message table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75rem 0;
  font-size: 0.875rem;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
}

.prose thead,
.finding-row thead,
.chat-message thead {
  background-color: #f9fafb;
}

.prose th,
.finding-row th,
.chat-message th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-weight: 600;
  color: #374151;
  border-bottom: 2px solid #e5e7eb;
}

.prose td,
.finding-row table td,
.chat-message td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #e5e7eb;
  color: #4b5563;
  vertical-align: top;
}

.prose tr:last-child td,
.finding-row tr:last-child td,
.chat-message tr:last-child td {
  border-bottom: none;
}

/* Alternating row colors */
.prose tbody tr:nth-child(even),
.finding-row tbody tr:nth-child(even),
.chat-message tbody tr:nth-child(even) {
  background-color: #fafafa;
}

/* Hover effect */
.prose tbody tr:hover,
.finding-row tbody tr:hover,
.chat-message tbody tr:hover {
  background-color: #f3f4f6;
}

/* ========================================
   Findings Table (Discover Page) Specific
   ======================================== */

/* Reset padding on outer finding row td */
.findings-table .finding-row > td {
  padding: 0;
  border-bottom: 1px solid #f1f5f9;
}

/* Fix column width distribution - even columns for markdown tables in findings */
.findings-table .prose table {
  display: table;
  table-layout: fixed;
  width: 100%;
  margin: 0;
}

.findings-table .prose table th,
.findings-table .prose table td {
  width: auto;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: normal;
}

/* ========================================
   Responsive Table Styles
   ======================================== */
@media (max-width: 640px) {
  .prose table,
  .finding-row table,
  .chat-message table {
    font-size: 0.75rem;
  }

  .prose th,
  .prose td,
  .finding-row th,
  .finding-row table td,
  .chat-message th,
  .chat-message td {
    padding: 0.5rem 0.75rem;
  }
}
