/* ============================================================
   Homedoc Design System — theme.css
   ============================================================ */

/* ---------- Colour Tokens ---------- */
:root,
:root[data-theme="light"] {
  --text: #1d0303;
  --text-muted: #6b5555;
  --background: #fef3f3;
  --surface: #ffffff;
  --surface-hover: #fff8f8;
  --primary: #eb2e2a;
  --primary-hover: #d42421;
  --primary-light: rgba(235, 46, 42, 0.08);
  --secondary: #7bcdf2;
  --secondary-light: rgba(123, 205, 242, 0.12);
  --accent: #c54444;
  --border: #f0d4d4;
  --border-strong: #e0b0b0;
  --shadow-color: 0deg 40% 70%;

  /* Chat */
  --user-bubble: #eb2e2a;
  --user-text: #ffffff;
  --bot-bubble: #ffffff;
  --bot-text: #1d0303;
  --bot-border: #f0d4d4;

  /* Status */
  --success: #16a34a;
  --success-light: rgba(22, 163, 74, 0.1);
  --warning: #f59e0b;
  --danger: #dc2626;
  --danger-light: rgba(220, 38, 38, 0.08);
}

:root[data-theme="dark"] {
  --text: #fce3e3;
  --text-muted: #b09999;
  --background: #0e0101;
  --surface: #1a0808;
  --surface-hover: #241010;
  --primary: #d71714;
  --primary-hover: #ef2d2a;
  --primary-light: rgba(215, 23, 20, 0.15);
  --secondary: #0d5d82;
  --secondary-light: rgba(13, 93, 130, 0.2);
  --accent: #bb3a3a;
  --border: #3b1414;
  --border-strong: #5a2020;
  --shadow-color: 0deg 20% 10%;

  /* Chat */
  --user-bubble: #d71714;
  --user-text: #ffffff;
  --bot-bubble: #1a0808;
  --bot-text: #fce3e3;
  --bot-border: #3b1414;

  /* Status */
  --success: #22c55e;
  --success-light: rgba(34, 197, 94, 0.15);
  --warning: #fbbf24;
  --danger: #ef4444;
  --danger-light: rgba(239, 68, 68, 0.15);
}

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

body {
  color: var(--text);
  background-color: var(--background);
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* ---------- Animated Gradient Background ---------- */
.gradient-bg {
  background: linear-gradient(135deg, var(--background) 0%, var(--primary-light) 50%, var(--secondary-light) 100%);
  background-size: 200% 200%;
  animation: gradientShift 12s ease-in-out infinite;
}

@keyframes gradientShift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1rem;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

.card-static {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1rem;
}

.glass-card {
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 1.25rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.06);
}

:root[data-theme="dark"] .glass-card {
  background: rgba(26, 8, 8, 0.75);
  border: 1px solid rgba(59, 20, 20, 0.5);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  border-radius: 0.75rem;
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  text-decoration: none;
}

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

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(235, 46, 42, 0.25);
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 16px rgba(235, 46, 42, 0.35);
}

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

.btn-ghost:hover {
  background: var(--surface-hover);
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-danger {
  background: var(--danger-light);
  color: var(--danger);
}

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

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
  border-radius: 0.5rem;
}

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

/* ---------- Inputs ---------- */
.input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  font-size: 0.875rem;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}

.input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.input::placeholder {
  color: var(--text-muted);
  opacity: 0.7;
}

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

/* ---------- File Input ---------- */
.file-input {
  width: 100%;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.file-input::file-selector-button {
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  border: none;
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
  font-size: 0.8125rem;
  cursor: pointer;
  margin-right: 0.75rem;
  transition: background 0.2s;
}

.file-input::file-selector-button:hover {
  background: var(--primary);
  color: #fff;
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
  animation: fadeIn 0.2s ease;
}

.modal-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  width: 100%;
  max-width: 28rem;
  padding: 1.5rem;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.15);
  animation: slideUp 0.3s ease;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  border-radius: 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  z-index: 200;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}

.toast.toast-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast-success {
  border-color: var(--success);
  background: var(--success-light);
  color: var(--success);
}

/* ---------- Chat Bubbles ---------- */
.chat-user-bubble {
  background: var(--user-bubble);
  color: var(--user-text);
  border-radius: 1.25rem 1.25rem 0.25rem 1.25rem;
  padding: 0.75rem 1rem;
  max-width: 85%;
  font-size: 0.875rem;
  line-height: 1.5;
  animation: bubbleIn 0.25s ease;
  word-wrap: break-word;
}

.chat-bot-bubble {
  background: var(--bot-bubble);
  color: var(--bot-text);
  border: 1px solid var(--bot-border);
  border-radius: 1.25rem 1.25rem 1.25rem 0.25rem;
  padding: 0.875rem 1.125rem;
  max-width: 90%;
  font-size: 0.875rem;
  line-height: 1.6;
  animation: bubbleIn 0.25s ease;
  word-wrap: break-word;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
}

@media (min-width: 640px) {
  .chat-bot-bubble {
    max-width: 82%;
  }
}

/* Markdown inside bot bubbles */
.chat-bot-bubble p { margin-bottom: 0.625rem; }
.chat-bot-bubble p:last-child { margin-bottom: 0; }
.chat-bot-bubble strong { font-weight: 700; color: var(--text); }
.chat-bot-bubble em { font-style: italic; }
.chat-bot-bubble ul, .chat-bot-bubble ol { padding-left: 1.25rem; margin: 0.5rem 0 0.75rem 0; }
.chat-bot-bubble li { margin-bottom: 0.375rem; line-height: 1.55; }
.chat-bot-bubble li::marker { color: var(--primary); font-weight: 700; }
.chat-bot-bubble li > ul, .chat-bot-bubble li > ol { margin: 0.25rem 0; }

.chat-bot-bubble code {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid rgba(235, 46, 42, 0.2);
  padding: 0.125rem 0.45rem;
  border-radius: 0.375rem;
  font-size: 0.8125rem;
  font-weight: 600;
  font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
  vertical-align: baseline;
}
:root[data-theme="dark"] .chat-bot-bubble code {
  border-color: rgba(215, 23, 20, 0.4);
}

.chat-bot-bubble pre {
  background: var(--surface-hover);
  border: 1px solid var(--border);
  padding: 0.75rem 1rem;
  border-radius: 0.625rem;
  overflow-x: auto;
  margin: 0.75rem 0;
}
.chat-bot-bubble pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--text);
  font-weight: 400;
}

.chat-bot-bubble h1, .chat-bot-bubble h2, .chat-bot-bubble h3, .chat-bot-bubble h4 {
  font-weight: 700;
  color: var(--text);
  margin: 1rem 0 0.375rem 0;
  line-height: 1.3;
}
.chat-bot-bubble h1:first-child,
.chat-bot-bubble h2:first-child,
.chat-bot-bubble h3:first-child,
.chat-bot-bubble h4:first-child {
  margin-top: 0;
}
.chat-bot-bubble h1 { font-size: 1.125rem; }
.chat-bot-bubble h2 { font-size: 1.05rem; }
.chat-bot-bubble h3 { font-size: 0.9375rem; }
.chat-bot-bubble h4 { font-size: 0.875rem; }

.chat-bot-bubble hr {
  border: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-strong), transparent);
  margin: 0.875rem 0;
}

.chat-bot-bubble blockquote {
  border-left: 3px solid var(--primary);
  padding-left: 0.75rem;
  margin: 0.625rem 0;
  color: var(--text-muted);
  font-style: italic;
}

/* Callouts / Alert boxes in chat */
.chat-callout {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  padding: 0.75rem 0.875rem;
  margin: 0.625rem 0;
  border-radius: 0.75rem;
  font-size: 0.84375rem;
  line-height: 1.5;
}
.chat-callout-icon {
  font-size: 1rem;
  flex-shrink: 0;
  margin-top: 0.05rem;
}
.chat-callout-content {
  flex: 1;
}
.chat-callout-content p {
  margin-bottom: 0.375rem;
}
.chat-callout-content p:last-child {
  margin-bottom: 0;
}
.chat-callout-warning {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-left: 4px solid var(--warning);
  color: var(--text);
}
.chat-callout-tip {
  background: rgba(22, 163, 74, 0.1);
  border: 1px solid rgba(22, 163, 74, 0.25);
  border-left: 4px solid var(--success);
  color: var(--text);
}
.chat-callout-info {
  background: var(--secondary-light);
  border: 1px solid rgba(123, 205, 242, 0.35);
  border-left: 4px solid var(--secondary);
  color: var(--text);
}

/* Tables inside bot bubbles */
.chat-bot-bubble table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 0.75rem 0;
  font-size: 0.8125rem;
  border-radius: 0.5rem;
  overflow: hidden;
  border: 1px solid var(--border);
}
.chat-bot-bubble th, .chat-bot-bubble td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.chat-bot-bubble th {
  background: var(--primary-light);
  font-weight: 600;
  color: var(--text);
}
.chat-bot-bubble tr:last-child td {
  border-bottom: none;
}

/* Chat timestamp */
.chat-timestamp {
  font-size: 0.6875rem;
  color: var(--text-muted);
  opacity: 0.7;
  margin-top: 0.25rem;
}

/* ---------- Starter Question Chips ---------- */
.starter-chip {
  display: inline-block;
  padding: 0.5rem 0.875rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2rem;
  font-size: 0.8125rem;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
}

.starter-chip:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-1px);
}

/* ---------- Typing Indicator ---------- */
.typing-dot {
  width: 0.4rem;
  height: 0.4rem;
  background: var(--text-muted);
  border-radius: 50%;
  display: inline-block;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ---------- Status Badge ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.1875rem 0.5rem;
  border-radius: 2rem;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.badge-success {
  background: var(--success-light);
  color: var(--success);
}

.badge-warning {
  background: rgba(245, 158, 11, 0.12);
  color: var(--warning);
}

/* ---------- Theme Toggle & Icon Buttons ---------- */
.theme-toggle, .icon-btn {
  width: 2.25rem;
  height: 2.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.625rem;
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s ease;
}

.theme-toggle:hover, .icon-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
  border-color: var(--border-strong);
}

/* ---------- Scroll-to-Bottom Button ---------- */
.scroll-bottom-btn {
  position: absolute;
  bottom: 1rem;
  right: 1rem;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.2s ease;
  pointer-events: none;
  z-index: 10;
}

.scroll-bottom-btn.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.scroll-bottom-btn:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ---------- Animations ---------- */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(8px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.fade-in {
  animation: fadeIn 0.4s ease;
}

.slide-up {
  animation: slideUp 0.4s ease;
}

/* ---------- Utility ---------- */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
