/* Fixed dark brand theme (MODON / Cora AI) — deliberate, not adaptive to
   the visitor's OS light/dark preference, matching the login screen. */
:root {
  color-scheme: dark;
  --bg: #0c0c0e;
  --header-bg: #050505;
  --surface: #1a1a1d;
  --surface-2: #232327;
  --border: rgba(255, 255, 255, 0.12);
  --text: #d1d1d6;
  --text-muted: #97969f;
  --accent: #8a63ff;
  --accent-strong: #9b7bff;
  --accent-soft: rgba(138, 99, 255, 0.16);
  --bubble-user: #242428;
  --bubble-user-text: #d1d1d6;
  --bubble-bot: transparent;
  --danger: #ff6b6b;
  --radius-lg: 18px;
  --radius-md: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, "Inter", Roboto, Helvetica, Arial, sans-serif;
}

/* Several elements here (.app, .login-screen, .btn-icon, ...) set an
   unconditional `display` value, which — being an author rule — always
   beats the browser's built-in `[hidden] { display: none }` (a
   user-agent rule loses to any author rule, regardless of specificity or
   source order). Without this, toggling `el.hidden = true/false` in JS
   silently has no visual effect on any element styled that way. `!important`
   makes `hidden` reliably win no matter what else targets the element. */
[hidden] {
  display: none !important;
}

.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--header-bg);
  flex: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  display: block;
  height: 22px;
  width: auto;
}

.brand-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
}

.brand-name {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Logged-in user controls, top right — icon-only to match the reference
   design, with the username available as a tooltip on the avatar. */
.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.user-avatar {
  width: 34px;
  height: 34px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

/* .logout-btn / .new-chat-btn visuals live next to .btn-icon further down
   (must come after it in the cascade — same specificity, and .btn-icon
   sets `border: none`, which would otherwise win by source order). */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}

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

.btn-primary {
  padding: 10px 16px;
  background: var(--accent);
  color: #fff;
  justify-content: center;
}

.btn-primary:hover { background: var(--accent-strong); }

.btn-primary:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

/* Chat area */
.chat-area {
  flex: 1;
  overflow: hidden;
  display: flex;
  justify-content: center;
}

.chat-scroll {
  width: 100%;
  max-width: 900px;
  overflow-y: auto;
  padding: 24px 16px 8px;
  /* Scrolling (wheel, trackpad, keyboard, JS scrollTop) stays fully
     functional — only the scrollbar track/thumb is hidden. */
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* legacy Edge/IE */
}

.chat-scroll::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Edge (Chromium) */
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 12vh 12px 0;
  gap: 18px;
}

.empty-state h1 {
  font-size: 24px;
  font-weight: 700;
  margin: 0;
  color: var(--text);
}

.suggestions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  max-width: 900px;
  width: 100%;
}

.suggestion-chip {
  text-align: left;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 13.5px;
  line-height: 1.45;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.05s ease;
}

.suggestion-chip:hover {
  border-color: rgba(255, 255, 255, 0.28);
  background: var(--surface);
  color: var(--text);
}

.suggestion-chip:active { transform: scale(0.98); }

/* Messages */
.messages {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding-bottom: 16px;
}

.msg {
  display: flex;
  gap: 10px;
  max-width: 100%;
  animation: fade-in 0.15s ease;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-avatar {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  margin-top: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

/* User messages carry no avatar (see client.js) — just right-align the bubble. */
.msg.user { justify-content: flex-end; }

.msg-bubble {
  font-size: 14.5px;
  line-height: 1.6;
  word-wrap: break-word;
}

/* Rendered markdown owns its own spacing (paragraphs, lists, etc.) via
   margins, so the bubble itself does not need white-space: pre-wrap —
   that would double up on the newlines already in marked's HTML output. */

.msg.user .msg-bubble {
  padding: 11px 18px;
  border-radius: 18px;
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  box-shadow: var(--shadow);
  max-width: 80%;
}

.msg.assistant .msg-bubble {
  padding-top: 4px;
  background: transparent;
  color: var(--text);
}

.msg.assistant .msg-bubble.error {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: rgba(255, 107, 107, 0.1);
  border: 1px solid rgba(255, 107, 107, 0.3);
  color: var(--danger);
}

.msg-bubble code {
  background: rgba(127, 127, 127, 0.15);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 13px;
}

.msg-bubble pre {
  background: rgba(127, 127, 127, 0.12);
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
}

/* Rendered markdown elements ------------------------------------------ */

.msg-bubble p {
  margin: 0 0 10px;
}

.msg-bubble p:last-child {
  margin-bottom: 0;
}

.msg-bubble h1,
.msg-bubble h2,
.msg-bubble h3,
.msg-bubble h4 {
  margin: 16px 0 8px;
  line-height: 1.3;
  font-weight: 700;
}

.msg-bubble h1:first-child,
.msg-bubble h2:first-child,
.msg-bubble h3:first-child,
.msg-bubble h4:first-child {
  margin-top: 0;
}

.msg-bubble h1 { font-size: 1.35em; }
.msg-bubble h2 { font-size: 1.2em; }
.msg-bubble h3 { font-size: 1.08em; }
.msg-bubble h4 { font-size: 1em; }

.msg-bubble ul,
.msg-bubble ol {
  margin: 0 0 10px;
  padding-left: 1.4em;
}

.msg-bubble li {
  margin: 3px 0;
}

.msg-bubble li > ul,
.msg-bubble li > ol {
  margin: 3px 0;
}

.msg-bubble li p {
  margin: 0;
}

.msg-bubble blockquote {
  margin: 0 0 10px;
  padding: 2px 12px;
  border-left: 3px solid var(--accent);
  color: var(--text-muted);
}

.msg-bubble blockquote > *:last-child {
  margin-bottom: 0;
}

.msg-bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 14px 0;
}

.msg-bubble a {
  color: var(--accent-strong);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.msg-bubble img {
  max-width: 100%;
  border-radius: 8px;
  margin: 6px 0;
}

.msg-bubble .table-wrap,
.msg-bubble table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
}

.msg-bubble table {
  border-collapse: collapse;
  margin: 0 0 10px;
  font-size: 13.5px;
}

.msg-bubble th,
.msg-bubble td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}

.msg-bubble th {
  background: rgba(127, 127, 127, 0.1);
  font-weight: 600;
}

.msg-bubble pre code { background: none; padding: 0; }

/* Blinking "typing" cursor while a reply is still streaming in — a pure
   CSS ::after so it never has to be spliced into parsed markdown HTML. */
.msg-bubble.streaming::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 14px;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: var(--text-muted);
  animation: blink 1s step-start infinite;
}

@keyframes blink { 50% { opacity: 0; } }

.typing-dots {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: bounce 1.2s infinite ease-in-out;
}

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

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Composer */
.composer-wrap {
  flex: none;
  padding: 10px 16px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
}

.composer {
  width: 100%;
  max-width: 900px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 8px 8px 8px 18px;
  box-shadow: var(--shadow);
}

.composer:focus-within {
  border-color: var(--accent);
}

.composer-input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font-size: 14.5px;
  font-family: inherit;
  max-height: 160px;
  padding: 6px 0;
}

.btn-icon {
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
}

.logout-btn,
.new-chat-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.logout-btn:hover,
.new-chat-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.send-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.send-btn:disabled {
  color: var(--text-muted);
  opacity: 0.6;
  cursor: not-allowed;
}

.send-btn:not(:disabled):hover {
  background: var(--border);
  color: var(--text);
}

.stop-btn {
  background: #000000;
  color: #d1d1d6;
  border: 1px solid var(--border);
}

.stop-btn:hover {
  background: #1a1a1a;
}

.disclaimer {
  margin: 8px 0 0;
  font-size: 11.5px;
  color: var(--text-muted);
  text-align: center;
}

@media (max-width: 560px) {
  .suggestions { grid-template-columns: 1fr; }
}

/* Login screen ------------------------------------------------------------
   A deliberately fixed dark brand treatment (MODON / Cora AI), rather than
   the adaptive light/dark palette the rest of the app uses — scoped to its
   own tokens so it doesn't leak into `:root`. */

.login-screen {
  --login-card-bg: #19191c;
  --login-card-border: rgba(255, 255, 255, 0.08);
  --login-text: #f5f5f7;
  --login-text-muted: #98979f;
  --login-input-light-bg: #e8f0fe;
  --login-input-light-text: #14141a;
  --login-input-dark-bg: #27272c;
  --login-input-dark-border: rgba(255, 255, 255, 0.1);
  --login-button-bg: #ececed;
  --login-button-bg-hover: #ffffff;
  --login-button-text: #16161a;

  position: relative;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: #000000;
  overflow: hidden;
}

/* Full-bleed background photo, blurred and zoomed in on its own layer so the
   blur doesn't smear the (sharp) login card sitting in front of it. */
.login-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("/modon_properties_view.jpg");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  filter: blur(6px);
  transform: scale(1.05);
  z-index: 0;
}

/* Subtle dark scrim over the photo so the light login card keeps contrast. */
.login-screen::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 12, 0.45);
  z-index: 0;
}

.login-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 40px 34px 32px;
  border: 1px solid var(--login-card-border);
  border-radius: 24px;
  background: var(--login-card-bg);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
}

.login-logo {
  display: block;
  height: 38px;
  width: auto;
  margin: 0 auto 6px;
}

.verify-result-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  margin: 0 auto;
  border-radius: 50%;
  background: rgba(90, 200, 130, 0.15);
  border: 1px solid rgba(90, 200, 130, 0.3);
  color: #8fe0ac;
}

.login-tagline {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 400;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  text-align: center;
  color: var(--login-text);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--login-text-muted);
}

.field input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input::placeholder {
  color: var(--login-text-muted);
}

/* Every text/password field on the login screen (login, register, verify,
   forgot-password, reset-password all share .login-card) gets the same
   dark input treatment, matching the reference design. */
.login-card .field input {
  background: var(--login-input-dark-bg);
  border-color: var(--login-input-dark-border);
  color: var(--login-text);
}

/* Password field: stays dark, with room for the show/hide toggle */
.password-field {
  position: relative;
  display: flex;
}

.password-field input {
  padding-right: 42px;
}

.field input:focus {
  background: #3a3a40;
  border-color: rgba(255, 255, 255, 0.35);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.12);
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--login-text-muted);
  cursor: pointer;
  border-radius: 8px;
}

.password-toggle:hover {
  color: var(--login-text);
  background: rgba(255, 255, 255, 0.06);
}

.login-error {
  margin: 0;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(240, 90, 90, 0.15);
  border: 1px solid rgba(240, 90, 90, 0.3);
  color: #ff9c9c;
  font-size: 12.5px;
}

.login-error.login-success {
  background: rgba(90, 200, 130, 0.15);
  border-color: rgba(90, 200, 130, 0.3);
  color: #8fe0ac;
}

.login-submit {
  margin-top: 4px;
  padding: 13px 16px;
  border-radius: 999px;
  background: var(--login-button-bg);
  color: var(--login-button-text);
  font-size: 14.5px;
  font-weight: 700;
}

.login-submit:hover:not(:disabled) {
  background: var(--login-button-bg-hover);
}

.login-links {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.login-links-center {
  justify-content: center;
}

.login-link {
  padding: 0;
  border: none;
  background: none;
  font-size: 13px;
  font-weight: 500;
  color: var(--login-text-muted);
  cursor: pointer;
}

.login-link:hover {
  color: var(--login-text);
  text-decoration: underline;
}

.login-hint {
  margin: 4px 0 0;
  font-size: 11.5px;
  color: var(--login-text-muted);
  text-align: center;
  line-height: 1.5;
}

.login-hint code {
  background: rgba(255, 255, 255, 0.1);
  color: var(--login-text);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11px;
}
