/* Import base styles and variables from common.css */
@import "./common.css";

/* 
 * =====================================================
 * Body Layout
 * =====================================================
 * Establishes the main flexbox layout for content
 */
body {
  display: flex;              /* Horizontal layout: content */
  height: 100vh;              /* Full viewport height */
  width: 100vw;

  flex-direction: column;                 /* Stack nav and main vertically */
  align-items: center;
  overflow: hidden;
  
  /* -------------------- Padding with Safe Areas -------------------- */
  padding-top: var(--safearea-top);
  padding-left: var(--padding);
  padding-bottom: var(--safearea-padding-bottom);
  padding-right: var(--safearea-padding-right);
}

#background {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  /* Ensures the image covers the entire area without stretching and crops excess */
  object-fit: cover; 
  object-position: right 70%;
}

/* 
 * =====================================================
 * MAIN CONTENT AREA
 * =====================================================
 * Where chat messages and content will appear
 */

main {
  width: var(--main-width);
  max-width: var(--main-max-width);
  min-height: 0;

  display: flex;
  flex-direction: column;
  /* justify-content: center; */
  flex: 1;
  flex-shrink: 1;
  gap: 8px;

  /* background: red; */
  padding-top: 24px;
  margin-bottom: -24px;
  padding-bottom: 48px;
  overflow-x: hidden;
  overflow-y: auto !important;
  pointer-events: auto !important;
  z-index: 1;
}

main * {
  width: fit-content;
}

main::before, 
main::after {
  content: "";
  margin: auto;
}

#welcome {
  --h1-size: min(max(3.3837vw, 24px), 32px);
  --h2-size: min(max(2.2961vw, 18px), 20px);
  --span-size: min(max(1.6918vw, 12px), 16px);
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  justify-content: center;
  align-items: center;
  color: rgb(from var(--color) r g b / 0.8);
  font-size: var(--span-size);
  text-align: center;
  vertical-align: middle;
}

#welcome > div:first-of-type {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#welcome > div:first-of-type > span:last-of-type {
  padding-top: 16px;
  font-weight: 300;
  color: rgb(from var(--color) r g b / 0.6);
}

#welcome i {
  font-style: italic;
}

#welcome b {
  font-weight: 500;
}

#welcome h2,
#welcome h1 {
  font-weight: 400;
  margin: 0;
  padding: 0;
  margin-inline: auto;
}

#welcome h1 {
  font-size: var(--h1-size);
}

#welcome h2 {
  font-weight: 200;
  font-size: var(--h2-size);
}

.pulse {
  display: flex;
  align-items: center;
  vertical-align: middle;
  gap: 3px;
}

.pulse b {
  font-size: 24px !important;
  animation: pulse 1.5s infinite ease-in-out;
  padding-bottom: 3px;
}

@keyframes pulse {
  0% {
    transform: scale(0.8);
    opacity: 0.4;
  }
  50% {
    transform: scale(1);
    opacity: 1;
  }
  100% {
    transform: scale(0.8);
    opacity: 0.4;
  }
}

/* 
 * =====================================================
 * USER CHAT INPUT
 * =====================================================
 * Where the user input the query
 */

#chat-input-container {
  position: relative;
  width: var(--main-width);
  max-width: var(--main-max-width);
  min-height: var(--chat-form-height);
  z-index: 999;
}

#chat-input-form {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: auto;

  border-radius: calc(0.5 * var(--chat-form-height));
  padding: 8px;
  z-index: 999;
}

#chat-input-form button > img {
  filter: var(--icon-filter);
}

#chat-input-left-buttons {
  display: flex;
  align-items: center;
  grid-column: 1;
  grid-row: 2;
}

#chat-input-right-buttons {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  grid-column: 3;
  grid-row: 2;
}

#chat-input-left-buttons,
#chat-input-right-buttons {
  min-width: calc(0.125 * var(--chat-form-height));
}

#chat-input-form.multiline #chat-input-left-buttons,
#chat-input-form.multiline #chat-input-right-buttons {
  grid-row: 3;
}

#chat-input {
  /* Appearance */
  grid-column: 2;
  grid-row: 2;
  width: 100%;
 
  max-height: 30dvh;
  resize: none;
  overflow-x: hidden;
  overflow-y: auto;
  color: inherit;
  background: none;
  outline: none;
  text-decoration: none;
  -webkit-decoration: none;
  -webkit-text-decoration: none;
  box-shadow: none;         /* Removes internal embossed shadow */

  /* Pointer event */
  pointer-events: auto;
  cursor: text;

  /* Annimation */
  transition: var(--transition-time);

  /* Spacing */
  margin: 0;
  padding: 0 8px;
  border: 0;

  /* Typography */
  font-weight: 400;
  font-size: 14px;
  line-height: 1.5;           /* Controls line spacing */
  
  /* Vertical alignment */
  display: flex;
  align-items: center;
  margin-top: calc(0.5 * var(--chat-form-height) - 18px);
}

#chat-input::placeholder {
  color: inherit;
  font-style: italic;
  opacity: 0.7;
}

#chat-input-form.multiline #chat-input {
  grid-column: -1 / 1;
  margin-bottom: 8px;
  margin-top: 0;
}

#stop,
#options,
#send {
  display: flex;
  align-items: center;
  justify-content: center;
  height: calc(var(--chat-form-height) - 16px);
  aspect-ratio: 1/1;
  border-radius: var(--border-radius-round);
}

#options {
  font-size: 16px;
}

body:not([thinking]) #stop {
  display: none;
}

body[thinking] #chat-input,
body[thinking] #options {
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
}

body[thinking] #send {
  display: none;
}

#stop > div {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: var(--color);
}

#options {
  background: none;
}

#chat-input-form[empty] #send {
  opacity: 0.8;
  pointer-events: none;
  cursor: not-allowed;
}

#chat-input-form[empty] #send > * {
  opacity: 0.6;
}

#chat-options {
  position: absolute;
  bottom: calc(var(--chat-form-height) + 8px);
  left: calc(8px + 0.5 * (var(--chat-form-height) - 56px));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#chat-options a {
  width: 100%;
}

#chat-options a,
#chat-options a:visited,
#chat-options a:active,
#chat-options a:link {
  color: var(--color);
}

#chat-options a,
#chat-options button {
  justify-content: flex-start;
  border-radius: var(--border-radius-round);
  padding: 12px;
  gap: 16px;
}

#chat-input-container:not([options-on]) #chat-options {
  pointer-events: none;
  gap: 6px;
  bottom: calc(var(--chat-form-height) + 6px);
}

#chat-input-container:not([options-on]) #chat-options * {
  opacity: 0;
  pointer-events: none;
}

#chat-input-container:not([options-on]) #chat-input-form,
body:has(#chat-input-container:not([options-on])) {
  pointer-events: none;
}

/*
 * =====================================================
 * HOVER EFFECTS (DESKTOP ONLY)
 * =====================================================
 * Interactive feedback for devices with hover capability
 */

@media (hover: hover) and (pointer: fine), (-ms-high-contrast: active), (forced-colors: active) {
  #options:hover {
    opacity: 1;
  }

  #options:hover > * {
    margin-bottom: 4px;
  }

  #chat-input-container[options-on] #options:hover > * {
    margin-bottom: -2px;
  }
}

/* 
 * =====================================================
 * MOBILE RESPONSIVE LAYOUT
 * =====================================================
 * Layout changes for screens 740px and smaller
 */

@media only screen and (max-width: 1180px) {
  #background.blured {
    filter: blur(20px);
    opacity: 0.5;
  }
}

@media only screen and (max-width: 900px) {

  main::before, 
  main::after {
    content: "";
    margin: auto;
  }

  #welcome {
    justify-content: flex-start;
    text-align: center;
    vertical-align: middle;
  }

  #welcome > div:first-of-type {
    align-items: center;
    gap: 8px;
  }
}