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

:root {
  --bg: #ece8e1;
  --text: #292524;
  --text-secondary: #78716c;
  --text-tertiary: #a8a29e;
  --user-bg: #292524;
  --user-text: #fafaf9;
  --accent: #c2410c;
  --border: #d6d3cd;
  --input-bg: #fafaf9;
  --input-border: #d6d3cd;
  --code-bg: #f5f5f4;
  --code-border: #e7e5e4;
  --notification-bg: #fffbeb;
  --notification-accent: #d97706;
  --error: #dc2626;
  --radius-msg: 22px;
  --radius-input: 24px;
}

.hidden {
  display: none !important;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Layout ── */

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 720px;
  margin: 0 auto;
}

/* ── Header ── */

header {
  padding: 20px 24px 8px;
}

.logo {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

/* ── Notification banner ── */

#notification-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 24px;
  padding: 10px 16px;
  background: var(--notification-bg);
  border: 1px solid #fde68a;
  border-radius: 12px;
  font-size: 13px;
  color: var(--text-secondary);
}

#notification-banner.hidden {
  display: none;
}

#notification-banner button {
  padding: 5px 14px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: none;
}

#enable-notifs {
  background: var(--notification-accent);
  color: white;
}

#enable-notifs:hover {
  background: #b45309;
}

#dismiss-notifs {
  background: transparent;
  color: var(--text-tertiary);
}

#dismiss-notifs:hover {
  color: var(--text-secondary);
}

/* ── Chat area ── */

#chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px 24px;
  scroll-behavior: smooth;
}

#messages {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── Messages ── */

.message {
  font-size: 15px;
  line-height: 1.65;
  word-wrap: break-word;
  overflow-wrap: break-word;
  animation: fadeIn 0.3s ease;
}

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

/* User messages — dark rounded pill, right-aligned */
.message.user {
  align-self: flex-end;
  max-width: 75%;
  padding: 10px 18px;
  background: var(--user-bg);
  color: var(--user-text);
  border-radius: var(--radius-msg);
  line-height: 1.5;
}

/* AI messages — NO container, text flows naturally */
.message.assistant {
  align-self: flex-start;
  color: var(--text);
  padding: 0;
  background: none;
  max-width: 100%;
}

/* Notification / Reminder */
.message.notification {
  align-self: flex-start;
  background: var(--notification-bg);
  border-left: 3px solid var(--notification-accent);
  padding: 12px 16px;
  border-radius: 0 12px 12px 0;
  max-width: 85%;
  font-size: 14px;
  color: var(--text);
}

.message.notification::before {
  content: "REMINDER";
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--notification-accent);
  margin-bottom: 4px;
}

/* Error */
.message.error {
  align-self: center;
  color: var(--error);
  font-size: 13px;
  padding: 8px;
  background: none;
}

/* ── Markdown inside AI messages ── */

.message.assistant p {
  margin-bottom: 12px;
}

.message.assistant p:last-child {
  margin-bottom: 0;
}

.message.assistant ul,
.message.assistant ol {
  margin: 8px 0 12px;
  padding-left: 24px;
}

.message.assistant li {
  margin-bottom: 4px;
}

.message.assistant code {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  padding: 1px 6px;
  border-radius: 5px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', 'Monaco', monospace;
  font-size: 13px;
  color: var(--text);
}

.message.assistant pre {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  padding: 14px 16px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 12px 0;
}

.message.assistant pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
}

.message.assistant strong {
  font-weight: 600;
  color: var(--text);
}

.message.assistant em {
  font-style: italic;
  color: var(--text-secondary);
}

.message.assistant a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: rgba(194, 65, 12, 0.3);
}

.message.assistant a:hover {
  text-decoration-color: var(--accent);
}

.message.assistant blockquote {
  border-left: 3px solid var(--border);
  padding-left: 16px;
  margin: 12px 0;
  color: var(--text-secondary);
}

.message.assistant h1,
.message.assistant h2,
.message.assistant h3 {
  margin: 16px 0 8px;
  color: var(--text);
  letter-spacing: -0.01em;
}

.message.assistant h1 { font-size: 20px; font-weight: 600; }
.message.assistant h2 { font-size: 17px; font-weight: 600; }
.message.assistant h3 { font-size: 15px; font-weight: 600; }

.message.assistant hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

.message.assistant table {
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 14px;
}

.message.assistant th,
.message.assistant td {
  padding: 8px 12px;
  border: 1px solid var(--code-border);
  text-align: left;
}

.message.assistant th {
  background: var(--code-bg);
  font-weight: 600;
}

/* ── Token count ── */

.token-count {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 8px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  letter-spacing: 0.02em;
}

/* ── Typing indicator ── */

.typing-indicator {
  display: inline-flex;
  gap: 5px;
  padding: 8px 0;
}

.typing-indicator span {
  width: 5px;
  height: 5px;
  background: var(--text-tertiary);
  border-radius: 50%;
  animation: pulse 1.4s infinite both;
}

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

@keyframes pulse {
  0%, 80%, 100% { opacity: 0.25; transform: scale(1); }
  40% { opacity: 1; transform: scale(1.15); }
}

/* ── Input area ── */

#input-area {
  padding: 0 24px 24px;
}

/* File preview strip */
#file-preview {
  display: flex;
  gap: 8px;
  padding: 8px 4px;
  flex-wrap: wrap;
}

#file-preview.hidden {
  display: none;
}

.file-thumb {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--code-bg);
  flex-shrink: 0;
}

.file-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.file-thumb .pdf-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.03em;
}

.file-thumb .remove-file {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 18px;
  height: 18px;
  background: var(--user-bg);
  color: var(--user-text);
  border: none;
  border-radius: 50%;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
  cursor: pointer;
  padding: 0;
}

.file-thumb .remove-file:hover {
  background: var(--error);
}

/* File chips in user messages */
.file-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  font-size: 11px;
  color: var(--user-text);
  opacity: 0.85;
}

.file-chip svg {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
}

.input-wrapper {
  position: relative;
}

#attach-btn {
  position: absolute;
  left: 8px;
  bottom: 8px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 50%;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  z-index: 1;
}

#attach-btn:hover {
  color: var(--text);
  background: rgba(0, 0, 0, 0.05);
}

#user-input {
  width: 100%;
  padding: 14px 52px 14px 44px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-input);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  line-height: 1.5;
  resize: none;
  max-height: 160px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#user-input:focus {
  border-color: var(--text-tertiary);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.04);
}

#user-input::placeholder {
  color: var(--text-tertiary);
}

#send-btn {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--text);
  border: none;
  border-radius: 50%;
  color: var(--bg);
  cursor: pointer;
  transition: opacity 0.15s;
}

#send-btn:hover {
  opacity: 0.8;
}

#send-btn:disabled {
  opacity: 0.2;
  cursor: not-allowed;
}

/* ── Timezone Onboarding Modal ── */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal-overlay.hidden {
  display: none;
}

.modal-card {
  background: var(--input-bg);
  border-radius: 16px;
  padding: 32px;
  max-width: 380px;
  width: 90%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}

.modal-card h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.modal-card p {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 20px;
  line-height: 1.5;
}

#tz-detected {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 16px;
}

#tz-label {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
}

.modal-btn {
  display: block;
  width: 100%;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s;
  margin-bottom: 8px;
}

.modal-btn.primary {
  background: var(--text);
  color: var(--bg);
}

.modal-btn.primary:hover {
  opacity: 0.85;
}

.modal-btn.secondary {
  background: transparent;
  color: var(--text-secondary);
}

.modal-btn.secondary:hover {
  color: var(--text);
}

#tz-select-wrapper {
  margin-top: 8px;
}

#tz-select-wrapper.hidden {
  display: none;
}

#tz-select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  margin-bottom: 10px;
  outline: none;
}

/* ── Guest counter banner ── */

#guest-counter {
  text-align: center;
  padding: 6px 16px;
  font-size: 12px;
  font-weight: 500;
  color: var(--notification-accent);
  background: var(--notification-bg);
  border-bottom: 1px solid #fde68a;
  letter-spacing: 0.02em;
}

/* ── Guest activate section ── */

.guest-activate-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.activate-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.guest-phone-field {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  margin-bottom: 10px;
  outline: none;
}

.guest-phone-field:focus {
  border-color: var(--text-tertiary);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.04);
}

/* ── Character counter ── */

.char-counter {
  position: absolute;
  right: 48px;
  bottom: 14px;
  font-size: 11px;
  color: var(--text-tertiary);
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  pointer-events: none;
  z-index: 1;
}

.char-counter.over-limit {
  color: var(--error);
  font-weight: 600;
}

/* ── Drag-over indicator ── */

#input-area.drag-over .input-wrapper {
  outline: 2px dashed var(--accent);
  outline-offset: 4px;
  border-radius: var(--radius-input);
}

/* ── Scrollbar ── */

#chat-area::-webkit-scrollbar {
  width: 6px;
}

#chat-area::-webkit-scrollbar-track {
  background: transparent;
}

#chat-area::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

#chat-area::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* ── Mobile ── */

@media (max-width: 600px) {
  #app {
    max-width: 100%;
  }

  .message.user {
    max-width: 85%;
  }

  header {
    padding: 16px 16px 8px;
  }

  #chat-area {
    padding: 12px 16px 16px;
  }

  #input-area {
    padding: 0 16px 16px;
  }

  #notification-banner {
    margin: 8px 16px;
  }
}
