/* Match the CRM appearance palette without loading the private application layout. */
:root {
  color-scheme: dark;
  --color-page: #08111b;
  --color-surface: #101a27;
  --color-surface-elevated: #152132;
  --color-surface-soft: #1b2a3e;
  --color-text: #f4f7fb;
  --color-muted: #a9b6c6;
  --color-border: #2a394d;
  --color-primary: #f47c20;
  --color-primary-strong: #ffad42;
  --color-primary-soft: rgba(244, 124, 32, .16);
  --color-action-ink: #211406;
  --conversation-width: 48rem;
  --gutter: clamp(.75rem, 4vw, 2rem);
  font-family: system-ui, sans-serif;
}

:root[data-chat-theme="light"] {
  color-scheme: light;
  --color-page: #eef3f8;
  --color-surface: #fff;
  --color-surface-elevated: #f7f9fc;
  --color-surface-soft: #e7eef7;
  --color-text: #152235;
  --color-muted: #526579;
  --color-border: #aab9ca;
  --color-primary: #cf6515;
  --color-primary-strong: #9e4705;
  --color-primary-soft: rgba(207, 101, 21, .13);
}

:root[data-chat-theme="contrast"] {
  --color-page: #000;
  --color-surface: #000;
  --color-surface-elevated: #090909;
  --color-surface-soft: #111;
  --color-text: #fff;
  --color-muted: #fff;
  --color-border: #fff;
  --color-primary: #ffd400;
  --color-primary-strong: #fff08a;
  --color-primary-soft: rgba(255, 212, 0, .25);
  --color-action-ink: #000;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--color-surface); color: var(--color-text); }
a { color: var(--color-primary-strong); text-underline-offset: .18em; }
button, input, select, textarea { font: inherit; }
:focus-visible { outline: 2px solid var(--color-primary-strong); outline-offset: 3px; }

.chat-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.chat-icon {
  width: 1.15rem;
  height: 1.15rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chat-icon-button {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 1px solid transparent;
  border-radius: .6rem;
  color: var(--color-muted);
  background: transparent;
  cursor: pointer;
}

.chat-icon-button:hover { background: var(--color-surface-soft); color: var(--color-text); }

.chat-app {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  min-height: 23rem;
}

.chat-app:has(.chat-sidebar:not([hidden])) { grid-template-columns: 15rem minmax(0, 1fr); }

.chat-sidebar {
  display: flex;
  flex-direction: column;
  gap: .65rem;
  min-height: 0;
  overflow-y: auto;
  padding: .75rem .8rem 1rem;
  background: var(--color-page);
  border-inline-end: 1px solid var(--color-border);
}

.chat-sidebar-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .45rem;
  padding: 0 .1rem 0 .35rem;
  margin-bottom: .6rem;
}

.chat-brand {
  display: flex;
  align-items: center;
  gap: .65rem;
  font-size: 1.37rem;
  font-weight: 760;
  letter-spacing: -.045em;
}

.chat-brand-mark {
  display: grid;
  place-items: center;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: .6rem;
  background: var(--color-primary);
  color: var(--color-action-ink);
}

.chat-brand-mark .chat-icon { width: 1.55rem; height: 1.55rem; }

.chat-clear, .chat-current, .chat-sidebar .chat-login {
  width: 100%;
  display: flex;
  align-items: center;
  gap: .65rem;
  min-height: 2.75rem;
  padding: .55rem .7rem;
  border: 1px solid transparent;
  border-radius: .55rem;
  color: var(--color-text);
  text-align: start;
  font-size: .9rem;
  text-decoration: none;
}

.chat-clear {
  background: var(--color-surface-elevated);
  border-color: var(--color-border);
  font-weight: 650;
  cursor: pointer;
}

.chat-current {
  border-color: var(--color-border);
  background: var(--color-primary-soft);
  font-weight: 650;
}

.chat-current .chat-icon { color: var(--color-primary-strong); }
.chat-clear:hover, .chat-current:hover, .chat-sidebar .chat-login:hover { background: var(--color-surface-soft); }

.chat-sidebar .chat-login {
  margin-top: auto;
  border-top-color: var(--color-border);
  color: var(--color-muted);
}

.chat-history { display: grid; align-content: start; gap: .22rem; }
.chat-history h2, .chat-history p { margin: .4rem .65rem; color: var(--color-muted); font-size: .8rem; }
.chat-history-link {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: .18rem .55rem;
  min-height: 2.85rem;
  padding: .48rem .6rem;
  border: 1px solid transparent;
  border-radius: .55rem;
  color: var(--color-text);
  text-decoration: none;
  font-size: .86rem;
}
.chat-history-link:hover { background: var(--color-surface-soft); }
.chat-history-link[aria-current="page"] { border-color: var(--color-border); background: var(--color-primary-soft); }
.chat-history-link .chat-icon { grid-row: span 2; align-self: center; color: var(--color-primary-strong); }
.chat-history-link span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-history-link time { grid-column: 2; color: var(--color-muted); font-size: .73rem; }
.chat-account-actions { display: grid; gap: .25rem; margin-top: auto; }
.chat-account-actions button { background: transparent; cursor: pointer; }
.chat-expired-file { color: var(--color-muted); font-size: .85rem; overflow-wrap: anywhere; }

.chat-workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.chat-header {
  min-height: 3.85rem;
  flex: none;
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .35rem clamp(.5rem, 2vw, 1.4rem);
  border-bottom: 1px solid var(--color-border);
}

.chat-header h1 {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin: 0;
  font-size: 1.05rem;
  font-weight: 750;
}

.chat-sparkle { color: var(--color-primary-strong); font-size: 1.2rem; line-height: 1; }
.chat-header .chat-login { margin-inline-start: auto; font-size: .85rem; }

.chat-theme-control {
  display: flex;
  align-items: center;
  gap: .35rem;
  margin-inline-start: auto;
  color: var(--color-muted);
}

.chat-theme-control select {
  min-height: 2.75rem;
  max-width: 8.25rem;
  padding-inline: .25rem;
  border: 0;
  border-radius: .45rem;
  color: var(--color-text);
  background: var(--color-surface);
  font-size: .85rem;
  cursor: pointer;
}

.chat-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.chat-thread {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
}

.chat-thread:focus-visible { outline-offset: -3px; }
.chat-thread-inner, .chat-composer { width: min(100%, var(--conversation-width)); margin-inline: auto; }
.chat-thread-inner { display: grid; gap: 1.65rem; padding: 2rem var(--gutter) 1.4rem; }

.chat-thread-empty { display: grid; }
.chat-empty {
  align-self: center;
  justify-self: center;
  text-align: center;
  padding: 1.5rem var(--gutter);
}

.chat-empty .chat-sparkle {
  display: inline-grid;
  place-items: center;
  width: 3.25rem;
  height: 3.25rem;
  border: 1px solid var(--color-border);
  border-radius: .95rem;
  background: var(--color-surface-elevated);
  font-size: 1.65rem;
}

.chat-empty h2 {
  margin: .95rem 0 .45rem;
  font-size: clamp(1.55rem, 4vw, 2.15rem);
  letter-spacing: -.035em;
  line-height: 1.16;
}

.chat-empty p { margin: 0; color: var(--color-muted); font-size: .93rem; }
.chat-turn { display: grid; gap: .9rem; min-width: 0; line-height: 1.55; }
.chat-question, .chat-answer { min-width: 0; overflow-wrap: anywhere; }

.chat-question {
  justify-self: end;
  max-width: 88%;
  padding: .65rem .95rem .75rem;
  border: 1px solid var(--color-border);
  border-radius: .95rem .95rem .25rem .95rem;
  background: var(--color-surface-soft);
}

.chat-speaker { margin: 0 0 .2rem; color: var(--color-muted); font-size: .8rem; font-weight: 700; }
.chat-message { margin: 0; white-space: pre-wrap; }

.chat-question-file {
  display: flex;
  align-items: flex-start;
  gap: .35rem;
  margin-top: .4rem;
  color: var(--color-muted);
  font-size: .8rem;
}

.chat-question-file .chat-icon { width: 1rem; height: 1rem; }

.chat-answer {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: .65rem;
}

.chat-answer .chat-sparkle {
  width: 1.8rem;
  height: 1.8rem;
  display: grid;
  place-items: center;
  border: 1px solid var(--color-border);
  border-radius: .55rem;
  background: var(--color-surface-elevated);
}

.chat-answer .chat-speaker { color: var(--color-text); line-height: 1.8rem; margin-bottom: .05rem; }
.chat-downloads { display: flex; flex-wrap: wrap; gap: .45rem; margin: .65rem 0 0; padding: 0; list-style: none; }
.chat-downloads li { min-width: 0; max-width: 100%; }

.chat-downloads a {
  display: flex;
  gap: .4rem;
  align-items: center;
  min-height: 2.3rem;
  padding: .35rem .55rem;
  border: 1px solid var(--color-border);
  border-radius: .55rem;
  background: var(--color-surface-elevated);
  font-size: .85rem;
}

.chat-downloads a:hover { background: var(--color-surface-soft); }
.chat-sources { margin-top: .65rem; font-size: .85rem; }
.chat-sources summary { color: var(--color-muted); cursor: pointer; }
.chat-sources ul { margin: .35rem 0 0; padding-inline-start: 1.2rem; }

.chat-composer {
  flex: none;
  display: grid;
  gap: .45rem;
  padding: .4rem var(--gutter) max(.75rem, env(safe-area-inset-bottom));
}

.chat-input-box {
  display: grid;
  gap: .3rem;
  min-width: 0;
  padding: .65rem;
  border: 1px solid var(--color-border);
  border-radius: 1rem;
  background: var(--color-surface-elevated);
  box-shadow: 0 .35rem 1.15rem rgba(0, 0, 0, .12);
}

.chat-input-box:focus-within { border-color: var(--color-primary-strong); }
.chat-input-box.is-dragging { outline: 2px dashed var(--color-primary-strong); background: var(--color-primary-soft); }

.chat-composer textarea {
  display: block;
  width: 100%;
  min-height: 2.8rem;
  max-height: clamp(3rem, 22dvh, 10rem);
  resize: vertical;
  border: 0;
  border-radius: .35rem;
  padding: .38rem .25rem;
  background: transparent;
  color: var(--color-text);
  font-size: 1rem;
  line-height: 1.5;
  overflow-y: auto;
}

.chat-composer textarea::placeholder { color: var(--color-muted); }
.chat-enhanced .chat-composer textarea { resize: none; }
.chat-composer textarea:focus-visible { outline-offset: 0; }

.chat-composer-actions { display: flex; align-items: center; flex-wrap: wrap; gap: .4rem; }
.chat-upload { min-width: 0; }
.chat-upload input { max-width: 100%; font-size: .85rem; }
.chat-attach { background: var(--color-surface); border-color: var(--color-border); }

.chat-search, .chat-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  min-height: 2.75rem;
  padding: .4rem .62rem;
  border: 1px solid var(--color-border);
  border-radius: .65rem;
  font-size: .85rem;
  font-weight: 650;
  cursor: pointer;
}

.chat-search { position: relative; margin-inline-start: auto; color: var(--color-muted); }
.chat-search input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.chat-search:hover { color: var(--color-text); background: var(--color-surface-soft); }
.chat-search:has(input:checked) { color: var(--color-primary-strong); border-color: currentColor; background: var(--color-primary-soft); }
.chat-search:has(input:focus-visible) { outline: 2px solid var(--color-primary-strong); outline-offset: 3px; }

.chat-send { color: var(--color-action-ink); background: var(--color-primary); border-color: transparent; }
.chat-send:hover { filter: brightness(1.1); }
.chat-send:disabled { opacity: .65; cursor: wait; }

.chat-attachment {
  display: flex;
  align-items: center;
  gap: .55rem;
  min-width: 0;
  width: fit-content;
  max-width: 100%;
  padding: .25rem .3rem .25rem .55rem;
  border: 1px solid var(--color-border);
  border-radius: .65rem;
  background: var(--color-surface);
}

.chat-file-info { min-width: 0; overflow-wrap: anywhere; font-size: .84rem; }
.chat-file-info small { display: block; color: var(--color-muted); font-size: .75rem; }

.chat-remove {
  flex: none;
  min-height: 2.75rem;
  padding: .25rem .45rem;
  border: 0;
  border-radius: .35rem;
  color: var(--color-text);
  background: transparent;
  font-size: .8rem;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: .16em;
}

.chat-remove:hover { background: var(--color-surface-soft); }

.chat-composer-meta { display: grid; gap: .16rem; text-align: center; }
.chat-composer-meta p, .chat-note { margin: 0; color: var(--color-muted); font-size: .77rem; line-height: 1.35; }
.chat-composer-meta .chat-progress { color: var(--color-primary-strong); font-weight: 650; }
.chat-answer .chat-incomplete { margin-top: .55rem; }

.chat-notice {
  margin: 0;
  padding: .55rem .7rem;
  border: 1px solid var(--color-primary-strong);
  border-radius: .6rem;
  background: var(--color-primary-soft);
  color: var(--color-text);
  font-size: .88rem;
}

.chat-unavailable { width: min(100%, var(--conversation-width)); margin: 2rem auto; padding-inline: var(--gutter); }
.chat-backdrop { display: none; }

@media (max-width: 720px) {
  .chat-app:has(.chat-sidebar:not([hidden])) { grid-template-columns: minmax(0, 1fr); }
  .chat-app:not(.chat-enhanced):has(.chat-sidebar) { grid-template-rows: auto minmax(0, 1fr); }
  .chat-app:not(.chat-enhanced) .chat-sidebar { border-inline-end: 0; border-bottom: 1px solid var(--color-border); }

  .chat-enhanced .chat-sidebar {
    position: fixed;
    z-index: 2;
    inset: 0 auto 0 0;
    width: min(18rem, calc(100% - 3rem));
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }

  .chat-backdrop {
    display: block;
    position: fixed;
    z-index: 1;
    inset: 0;
    background: rgba(0, 0, 0, .56);
  }

  .chat-header { min-height: 3.45rem; gap: .2rem; }
  .chat-header h1 { gap: .3rem; }
  .chat-header .chat-sparkle { font-size: 1rem; }
  .chat-header .chat-theme-control > .chat-icon { display: none; }
  .chat-question { max-width: 94%; }
  .chat-thread-inner { gap: 1.25rem; padding-top: 1.05rem; }
  .chat-composer { padding-top: .15rem; }
}

@media (max-width: 360px) {
  .chat-input-box { padding: .45rem; }
  .chat-search, .chat-send { padding-inline: .43rem; }
  .chat-search .chat-icon { width: 1rem; height: 1rem; }
}
