/**
 * summit-ai-service chat UI — additions on top of summit-new stack:
 * summit-tailwind-built.css + summit-button-styles.css (see /vendor/README.txt)
 * Patterns: summit-global-ui-consistency.mdc, dev-layout / dev-inputs catalogs.
 *
 * Layout/sidebar/composer live here so we do not rely on Tailwind arbitrary values
 * that are absent from the vendored summit-tailwind-built.css (content-scanned build).
 */

/* Do not use body.summit-app-body on this page: its base color (#f3f4f6) wins over
   .text-gray-900 and makes main text nearly invisible. */
body.chat-page {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  /* Softer than near-white (#f9fafb): less glare, better text contrast */
  background-color: #e4e8ef;
  color: #111827;
  font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Tailwind parity for toggles from JS (open/close settings, first message, etc.) */
.hidden {
  display: none !important;
}

/**
 * Shell layout is 100% plain CSS so the page works even when summit-tailwind-built.css
 * fails to load (network, 404, or opening the HTML from disk).
 */
.chat-shell {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
}

@media (min-width: 768px) {
  .chat-shell {
    flex-direction: row;
  }
}

.chat-sidebar {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  width: 100%;
  background-color: #153d77;
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

@media (min-width: 768px) {
  .chat-sidebar {
    width: 260px;
    border-bottom: none;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
  }
}

.chat-sidebar__header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
}

.chat-sidebar__actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0 0.75rem 0.5rem;
}

/* Scrollable session cards between New chat and settings */
.chat-sidebar__sessions {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0 0.75rem 0.5rem;
}

.chat-sidebar__sessions-head {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.45);
}

.chat-session-list {
  flex: 1;
  min-height: 3rem;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding-right: 2px;
  -webkit-overflow-scrolling: touch;
}

.chat-session-list.chat-session-list--disabled {
  pointer-events: none;
  opacity: 0.65;
}

.chat-session-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.15rem;
  width: 100%;
  margin: 0;
  padding: 0.5rem 0.55rem;
  border-radius: 0.5rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background-color: rgba(0, 0, 0, 0.12);
  color: rgba(255, 255, 255, 0.95);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.chat-session-card:hover {
  background-color: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
}

.chat-session-card:focus {
  outline: 2px solid rgba(255, 255, 255, 0.45);
  outline-offset: 1px;
}

.chat-session-card--active {
  background-color: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.28);
}

.chat-session-card__title {
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.3;
  color: #fff;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.chat-sidebar__bottom {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.chat-sidebar__foot-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
  padding: 0.25rem 0.75rem 0.75rem;
}

.chat-sidebar__foot-row .chat-sidebar__foot {
  flex: none;
  margin: 0;
  padding: 0;
  /* Was flex:1 + min-width:0 beside the button — column became ~1ch wide, one word per line */
  word-break: normal;
  overflow-wrap: break-word;
}

.chat-sidebar__btn--inline-settings {
  flex-shrink: 0;
  width: 100%;
  justify-content: center;
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  line-height: 1.2;
}

.chat-sidebar__brand {
  font-size: 0.875rem;
  line-height: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.025em;
}

.chat-main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background-color: #e4e8ef;
}

.chat-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scroll-behavior: smooth;
  background: linear-gradient(180deg, #e8ecf2 0%, #dfe4ec 48%, #dadfe8 100%);
}

.chat-content {
  max-width: 48rem;
  margin-left: auto;
  margin-right: auto;
  padding: 2.5rem 1rem 2rem;
}

@media (min-width: 768px) {
  .chat-content {
    padding: 3.5rem 1.5rem 2rem;
  }
}

.hero {
  text-align: center;
}

.hero h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  color: #111827;
}

@media (min-width: 768px) {
  .hero h1 {
    font-size: 1.875rem;
  }
}

.chat-sidebar__mark {
  display: inline-flex;
  height: 2.25rem;
  width: 2.25rem;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  border-radius: 0.5rem;
  background-color: rgba(255, 255, 255, 0.15);
  color: #fff;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.08);
}

.chat-sidebar__title-block {
  min-width: 0;
  line-height: 1.25;
  color: #fff;
}

.chat-sidebar__subtitle {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.75);
}

.chat-sidebar__btn {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border-radius: 0.5rem;
  padding: 0.625rem 0.75rem;
  font-size: 0.875rem;
  line-height: 1.25rem;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.chat-sidebar__btn--primary {
  border: 1px solid rgba(255, 255, 255, 0.2);
  background-color: rgba(255, 255, 255, 0.1);
  font-weight: 600;
  color: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  padding-top: 0.625rem;
  padding-bottom: 0.625rem;
}

.chat-sidebar__btn--primary:hover {
  background-color: rgba(255, 255, 255, 0.15);
}

.chat-sidebar__btn--ghost {
  border: 1px solid rgba(255, 255, 255, 0.15);
  background-color: transparent;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.92);
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
}

.chat-sidebar__btn--ghost:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.chat-settings-panel {
  padding: 0 0.75rem 0.75rem;
}

.chat-settings-card {
  border-radius: 0.5rem;
  padding: 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background-color: rgba(0, 0, 0, 0.2);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.chat-settings-card__heading {
  margin: 0 0 0.5rem;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.8);
}

.chat-settings-card__help {
  margin: -0.25rem 0 0.75rem;
  font-size: 10px;
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.6);
}

.chat-settings-card__help--signout {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
}

.chat-settings-signout-hint {
  font-size: 10px;
  line-height: 1.35;
  color: rgba(255, 255, 255, 0.45);
}

.chat-settings-card__label {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 11px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.85);
}

.chat-settings-card__input {
  display: block;
  width: 100%;
  margin-bottom: 0.75rem;
  padding: 0.5rem 0.625rem;
  font-size: 0.75rem;
  line-height: 1.25;
  border-radius: 0.375rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background-color: #fff;
  color: #111827;
  outline: none;
}

.chat-settings-card__input:last-of-type {
  margin-bottom: 0.5rem;
}

.chat-settings-card__input::placeholder {
  color: #9ca3af;
}

.chat-settings-card__input:focus {
  border-color: rgba(255, 255, 255, 0.4);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25);
}

.chat-settings-card__textarea {
  resize: vertical;
  min-height: 5rem;
  font-family: ui-monospace, Menlo, Monaco, Consolas, monospace;
  font-size: 0.7rem;
}

.chat-settings-card__note {
  margin: 0 0 0.75rem;
  font-size: 10px;
  line-height: 1.375;
  color: rgba(255, 255, 255, 0.55);
}

.chat-settings-card__code {
  padding: 0 0.125rem;
  border-radius: 0.25rem;
  background-color: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.65rem;
}

.chat-settings-card__actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chat-settings-card__actions .btn-summit {
  width: 100%;
  justify-content: center;
  font-size: 0.75rem;
}

.chat-sidebar__foot {
  margin: 0;
  padding: 0;
  font-size: 10px;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.45);
}

.chat-sidebar__foot-muted {
  color: rgba(255, 255, 255, 0.35);
}

.chat-composer-area {
  flex-shrink: 0;
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid #c5cdd8;
  background: linear-gradient(to top, #f0f3f8 0%, #e9edf5 70%, #e4e8f0 100%);
  box-shadow: 0 -2px 10px rgba(15, 23, 42, 0.06);
}

@media (min-width: 768px) {
  .chat-composer-area {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }
}

.chat-composer-field {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.5rem;
  border-radius: 0.75rem;
  border: 1px solid #c5cdd8;
  background-color: #fbfcfe;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.9),
    0 4px 14px rgba(15, 23, 42, 0.08);
}

.chat-composer-field:focus-within {
  border-color: rgba(21, 61, 119, 0.35);
  box-shadow:
    0 0 0 2px rgba(21, 61, 119, 0.12),
    0 4px 6px -1px rgba(0, 0, 0, 0.06);
}

.chat-composer-input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  max-height: 13rem;
  resize: none;
  border: 0;
  background: transparent;
  padding: 0.625rem 0.75rem;
  font: inherit;
  font-size: 0.875rem;
  line-height: 1.5;
  color: #111827;
}

.chat-composer-input:focus {
  outline: none;
}

.chat-composer-input::placeholder {
  color: #64748b;
}

.chat-composer-field .btn-summit-primary {
  flex-shrink: 0;
  margin-bottom: 2px;
  border-radius: 0.5rem;
  padding: 0.625rem 1rem;
}

.composer__hint {
  margin-top: 0.5rem;
  text-align: center;
  font-size: 11px;
  color: #475569;
}

.composer__hint strong {
  font-weight: 600;
  color: #1e293b;
}

.messages {
  max-width: 100%;
  margin-top: 2rem;
}

@media (min-width: 768px) {
  .messages {
    margin-top: 2.5rem;
  }
}

.msg {
  padding: 0.75rem 0;
  border-bottom: 1px solid rgba(100, 116, 139, 0.25);
}

.msg:last-child {
  border-bottom: none;
}

.msg__inner {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}

.msg--user .msg__inner {
  flex-direction: row-reverse;
}

.msg--user .msg__body {
  max-width: 85%;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  padding: 0.625rem 0.875rem;
  border-radius: 1rem;
  color: #0f172a;
}

.msg__avatar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 0.375rem;
  font-size: 0.65rem;
  font-weight: 700;
  border: 1px solid #94a3b8;
  background: #f1f5f9;
  color: #334155;
}

.msg--assistant .msg__avatar {
  background: #153d77;
  border-color: #153d77;
  color: #fff;
}

.msg__body {
  flex: 1;
  min-width: 0;
  font-size: 0.875rem;
  line-height: 1.65;
  color: #1e293b;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Markdown / prose (assistant), Gemini-like structure */
.msg__body--rich {
  white-space: normal;
  color: #1e293b;
}

.msg__body--rich > *:first-child {
  margin-top: 0;
}

.msg__body--rich > *:last-child {
  margin-bottom: 0;
}

.msg__body--rich p {
  margin: 0.5rem 0;
}

.msg__body--rich h1 {
  font-size: 1.125rem;
  font-weight: 600;
  color: #111827;
  margin: 1rem 0 0.5rem;
}

.msg__body--rich h2,
.msg__body--rich h3 {
  font-size: 1rem;
  font-weight: 600;
  color: #111827;
  margin: 0.9rem 0 0.4rem;
}

.msg__body--rich ul,
.msg__body--rich ol {
  margin: 0.5rem 0;
  padding-left: 1.35rem;
}

.msg__body--rich li {
  margin: 0.35rem 0;
}

.msg__body--rich li > p {
  margin: 0.25rem 0;
}

.msg__body--rich strong {
  font-weight: 600;
  color: #111827;
}

.msg__body--rich blockquote {
  margin: 0.5rem 0;
  padding-left: 0.75rem;
  border-left: 3px solid #d1d5db;
  color: #6b7280;
}

.msg__body--rich a {
  color: #153d77;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.msg__body--rich pre {
  margin: 0.5rem 0;
  padding: 0.75rem;
  overflow-x: auto;
  font-size: 0.8125rem;
  line-height: 1.5;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 0.375rem;
}

.msg__body--rich pre code {
  border: 0;
  padding: 0;
  background: transparent;
  font-size: inherit;
}

.msg__body code {
  font-family: ui-monospace, Menlo, Monaco, Consolas, monospace;
  font-size: 0.8125rem;
  background: #e2e8f0;
  border: 1px solid #cbd5e1;
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
}

.msg__citations {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px dashed #94a3b8;
  font-size: 0.8125rem;
  color: #475569;
}

.msg__citations strong {
  color: #374151;
  font-weight: 600;
}

.msg__citations ul {
  margin: 0.375rem 0 0;
  padding-left: 1.25rem;
}

.msg--error .msg__body {
  color: #dc2626;
}

/* Footer Summit secondary on dark sidebar: keep label readable */
.chat-btn-secondary-label {
  color: #374151;
}

/* —— Login (Summit AI Access Key) —— */
.chat-login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.chat-login-wrap {
  width: 100%;
  max-width: 28rem;
}

.chat-login-card {
  background-color: #fff;
  border-radius: 0.5rem;
  box-shadow:
    0 10px 15px -3px rgba(0, 0, 0, 0.08),
    0 4px 6px -2px rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.06);
  padding: 2rem 1.75rem;
}

.chat-login-card__brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.chat-login-card__mark {
  flex-shrink: 0;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  aspect-ratio: 1;
  min-width: 2.5rem;
  min-height: 2.5rem;
  border-radius: 0.375rem;
  background-color: #153d77;
  color: #fff;
  line-height: 0;
}

.chat-login-card__mark .fa {
  font-size: 1.125rem;
  line-height: 1;
}

.chat-login-card__title {
  margin: 0;
  padding: 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: #111827;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.chat-login-card__subtitle {
  margin: 0.1875rem 0 0;
  padding: 0;
  font-size: 0.8125rem;
  line-height: 1.35;
  color: #6b7280;
}

.chat-login-card__brand > div:last-child {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}

.chat-login-label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #4b5563;
}

.chat-login-input {
  display: block;
  width: 100%;
  margin-bottom: 0.75rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  line-height: 1.35;
  border-radius: 0.375rem;
  border: 1px solid #d1d5db;
  background-color: #fff;
  color: #111827;
  outline: none;
}

.chat-login-input:focus {
  border-color: #153d77;
  box-shadow: 0 0 0 2px rgba(21, 61, 119, 0.2);
}

.chat-login__error {
  margin: 0 0 1rem;
  font-size: 0.8125rem;
  line-height: 1.4;
  color: #b91c1c;
}

.chat-login__error.hidden {
  display: none !important;
}

.chat-login-submit {
  width: 100%;
  justify-content: center;
}

.chat-login-card .chat-login-submit {
  margin-top: 0.5rem;
}

.chat-settings-signout {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  padding: 0;
  border: none;
  background: none;
  font: inherit;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.75);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chat-settings-signout:hover {
  color: #fff;
}
