/* Corporate small extras on top of Tailwind */

/* ===== Mobile viewport + safe-area fixes (iOS/Safari) ===== */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);

  /* fallback; JS will override to precise visual viewport height on mobile */
  --app-height: 100vh;
}

@supports (height: 100dvh) {
  :root {
    --app-height: 100dvh;
  }
}

/* Global typography polish */
html, body {
  height: 100%;
}

body {
  min-height: var(--app-height);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Chat shell gets true “visual viewport” height (fixes keyboard + Safari bars) */
#app-root {
  height: var(--app-height);
}

/* Safe-area padding for main fixed-ish UI blocks */
#topbar {
  padding-top: calc(0.75rem + var(--safe-top));
  padding-bottom: 0.75rem;
  padding-left: calc(1rem + var(--safe-left));
  padding-right: calc(1rem + var(--safe-right));
}

#messages {
  padding-left: calc(1rem + var(--safe-left));
  padding-right: calc(1rem + var(--safe-right));
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

#sidebar,
#admin-panel {
  -webkit-overflow-scrolling: touch;
}

/* Composer should respect home-indicator */
#composer-footer {
  padding-top: 1rem;
  padding-bottom: calc(1rem + var(--safe-bottom));
  padding-left: calc(1rem + var(--safe-left));
  padding-right: calc(1rem + var(--safe-right));
}

/* Modals: keep content away from notch / home indicator */
#user-create-modal,
#rename-modal,
#delete-modal,
#pdf-viewer-modal {
  padding-top: calc(1rem + var(--safe-top));
  padding-bottom: calc(1rem + var(--safe-bottom));
}

/* Scroll-to-bottom button should not overlap home indicator / composer */
#scroll-down {
  right: calc(1.5rem + var(--safe-right));
  bottom: calc(6rem + var(--safe-bottom));
}

/* Prevent iOS Safari zoom on focus (inputs < 16px) */
@media (max-width: 767px) {
  input,
  textarea,
  select {
    font-size: 16px !important;
  }

  #scroll-down {
    right: calc(0.9rem + var(--safe-right));
    bottom: calc(6.25rem + var(--safe-bottom));
  }
}

/* Subtle “OpenAI-like” background glow */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  background:
    radial-gradient(1000px circle at 15% 0%, rgba(16, 185, 129, 0.14), transparent 55%),
    radial-gradient(900px circle at 90% 35%, rgba(99, 102, 241, 0.10), transparent 55%),
    radial-gradient(900px circle at 60% 100%, rgba(14, 165, 233, 0.08), transparent 55%);
  opacity: 0.9;
}

html.dark body::before {
  background:
    radial-gradient(1000px circle at 15% 0%, rgba(16, 185, 129, 0.12), transparent 55%),
    radial-gradient(900px circle at 90% 35%, rgba(99, 102, 241, 0.10), transparent 55%),
    radial-gradient(900px circle at 60% 100%, rgba(14, 165, 233, 0.10), transparent 55%);
  opacity: 0.55;
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Typing dots */
.dot {
  display: inline-block;
  width: 0.6em;
  text-align: center;
  animation: dotPulse 1.2s infinite ease-in-out;
  opacity: 0.35;
}
.dot-2 { animation-delay: 0.15s; }
.dot-3 { animation-delay: 0.3s; }

@keyframes dotPulse {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.35; }
  40% { transform: translateY(-2px); opacity: 1; }
}

/* Scrollbar (Chromium) */
#messages::-webkit-scrollbar,
#pdf-viewer-scroll::-webkit-scrollbar {
  width: 10px;
}
#messages::-webkit-scrollbar-thumb,
#pdf-viewer-scroll::-webkit-scrollbar-thumb {
  border-radius: 9999px;
  background: rgba(113, 113, 122, 0.28);
}
#messages::-webkit-scrollbar-track,
#pdf-viewer-scroll::-webkit-scrollbar-track {
  background: transparent;
}

/* Scrollbar (Firefox) */
#messages,
#pdf-viewer-scroll {
  scrollbar-width: thin;
  scrollbar-color: rgba(113, 113, 122, 0.35) transparent;
}

/* Make SVG icons align nicely */
.icon {
  width: 18px;
  height: 18px;
  display: inline-block;
  vertical-align: middle;
}

/* Toast animation */
.toast-enter {
  opacity: 0;
  transform: translateY(-6px);
}
.toast-enter-active {
  opacity: 1;
  transform: translateY(0);
  transition: all 200ms ease;
}

/* Markdown styling (assistant messages) */
.markdown {
  line-height: 1.6;
  word-break: break-word;
}

.markdown > *:first-child {
  margin-top: 0 !important;
}

.markdown p {
  margin: 0.75rem 0 0 0;
}

.markdown ul,
.markdown ol {
  margin: 0.75rem 0 0 0;
  padding-left: 1.25rem;
}

.markdown li {
  margin: 0.25rem 0;
}

.markdown a {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.markdown code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.95em;
  border-radius: 0.5rem;
  padding: 0.12rem 0.35rem;
  background: rgba(113, 113, 122, 0.12);
}

html.dark .markdown code {
  background: rgba(113, 113, 122, 0.22);
}

.markdown pre {
  margin-top: 0.85rem;
  padding: 0.85rem 1rem;
  border-radius: 0.85rem;
  overflow-x: auto;
  border: 1px solid rgba(113, 113, 122, 0.20);
  background: rgba(244, 244, 245, 0.85);
}

html.dark .markdown pre {
  border-color: rgba(63, 63, 70, 0.70);
  background: rgba(24, 24, 27, 0.70);
}

.markdown pre code {
  padding: 0;
  background: transparent;
}

.markdown blockquote {
  margin-top: 0.85rem;
  padding-left: 0.85rem;
  border-left: 3px solid rgba(16, 185, 129, 0.45);
  color: rgba(82, 82, 91, 1);
}

html.dark .markdown blockquote {
  color: rgba(161, 161, 170, 1);
  border-left-color: rgba(16, 185, 129, 0.35);
}

.markdown hr {
  margin-top: 1rem;
  border: 0;
  border-top: 1px solid rgba(113, 113, 122, 0.22);
}

.markdown table {
  margin-top: 0.85rem;
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border-radius: 0.85rem;
  border: 1px solid rgba(113, 113, 122, 0.20);
}

.markdown th,
.markdown td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid rgba(113, 113, 122, 0.14);
}

.markdown th {
  text-align: left;
  background: rgba(244, 244, 245, 0.80);
}

html.dark .markdown th {
  background: rgba(24, 24, 27, 0.70);
}

html.dark .markdown table {
  border-color: rgba(63, 63, 70, 0.70);
}

/* ✅ Pending: прячем "Копировать", пока ответ не готов */
[data-assistant-status="pending"] [data-copy-btn] {
  display: none !important;
}

/* ===== Sources / citations ===== */
.assistant-message-content {
  line-height: 1.65;
}

.citation-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.8rem;
  margin: 0 0.08rem;
  padding: 0.06rem 0.42rem;
  border-radius: 9999px;
  border: 1px solid rgba(16, 185, 129, 0.28);
  background: rgba(16, 185, 129, 0.10);
  color: rgb(5, 150, 105);
  font-size: 0.82em;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease, transform 120ms ease;
}

.citation-link:hover {
  background: rgba(16, 185, 129, 0.16);
  border-color: rgba(16, 185, 129, 0.45);
  transform: translateY(-1px);
}

.citation-link:focus-visible {
  outline: 2px solid rgba(16, 185, 129, 0.35);
  outline-offset: 2px;
}

html.dark .citation-link {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.24);
  color: rgb(52, 211, 153);
}

html.dark .citation-link:hover {
  background: rgba(16, 185, 129, 0.22);
  border-color: rgba(16, 185, 129, 0.38);
}

.source-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  max-width: 100%;
  border: 1px solid rgba(113, 113, 122, 0.18);
  border-radius: 9999px;
  padding: 0.45rem 0.8rem;
  background: rgba(255, 255, 255, 0.9);
  color: rgb(39, 39, 42);
  font-size: 12px;
  line-height: 1.2;
  box-shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
  transition: transform 140ms ease, border-color 140ms ease, background-color 140ms ease;
}

.source-chip:hover {
  transform: translateY(-1px);
  border-color: rgba(16, 185, 129, 0.35);
  background: rgba(255, 255, 255, 1);
}

.source-chip:focus-visible {
  outline: 2px solid rgba(16, 185, 129, 0.35);
  outline-offset: 2px;
}

.source-chip__citation {
  flex: 0 0 auto;
  color: rgb(5, 150, 105);
  font-weight: 700;
}

.source-chip__title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-chip__page {
  flex: 0 0 auto;
  color: rgb(82, 82, 91);
}

html.dark .source-chip {
  border-color: rgba(63, 63, 70, 0.82);
  background: rgba(24, 24, 27, 0.82);
  color: rgb(228, 228, 231);
}

html.dark .source-chip:hover {
  border-color: rgba(16, 185, 129, 0.32);
  background: rgba(24, 24, 27, 0.96);
}

html.dark .source-chip__citation {
  color: rgb(52, 211, 153);
}

html.dark .source-chip__page {
  color: rgb(161, 161, 170);
}

/* ===== PDF viewer ===== */
#pdf-viewer-modal {
  z-index: 70;
}

#pdf-viewer-scroll {
  -webkit-overflow-scrolling: touch;
}

#pdf-viewer-pages {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.pdf-page-card {
  overflow: hidden;
  border-radius: 1.5rem;
  border: 1px solid rgba(228, 228, 231, 0.95);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 1px 2px rgba(0,0,0,.06), 0 14px 40px rgba(0,0,0,.08);
}

.pdf-page-card.is-focus {
  border-color: rgba(16, 185, 129, 0.45);
  box-shadow: 0 1px 2px rgba(0,0,0,.06), 0 14px 40px rgba(16, 185, 129, 0.10);
}

html.dark .pdf-page-card {
  border-color: rgba(63, 63, 70, 0.82);
  background: rgba(24, 24, 27, 0.96);
}

html.dark .pdf-page-card.is-focus {
  border-color: rgba(16, 185, 129, 0.38);
  box-shadow: 0 1px 2px rgba(0,0,0,.14), 0 14px 40px rgba(16, 185, 129, 0.10);
}

.pdf-page-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid rgba(228, 228, 231, 0.9);
}

html.dark .pdf-page-card__head {
  border-bottom-color: rgba(63, 63, 70, 0.82);
}

.pdf-page-card__title {
  font-size: 13px;
  font-weight: 700;
  color: rgb(39, 39, 42);
}

html.dark .pdf-page-card__title {
  color: rgb(228, 228, 231);
}

.pdf-page-card__link {
  flex: 0 0 auto;
  color: rgb(5, 150, 105);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}

.pdf-page-card__link:hover {
  text-decoration: underline;
}

html.dark .pdf-page-card__link {
  color: rgb(52, 211, 153);
}

.pdf-page-card__body {
  background: rgb(245, 245, 244);
}

html.dark .pdf-page-card__body {
  background: rgb(10, 10, 10);
}

.pdf-page-frame {
  display: block;
  width: 100%;
  height: min(78vh, 1100px);
  border: 0;
  background: white;
}

.pdf-page-placeholder {
  display: grid;
  place-items: center;
  width: 100%;
  height: min(78vh, 1100px);
  color: rgb(82, 82, 91);
  font-size: 14px;
}

html.dark .pdf-page-placeholder {
  color: rgb(161, 161, 170);
}

@media (max-width: 767px) {
  .pdf-page-frame,
  .pdf-page-placeholder {
    height: 62vh;
  }

  .source-chip {
    max-width: 100%;
  }
}
