/* Focused shell layout for the embedded LidFly chat. */

body:has(#section-chat:not(.hidden)) .dashboard-main {
  padding: clamp(16px, 1.6vw, 24px);
  padding-bottom: 0;
  overflow: hidden;
}

.chat-section {
  --chat-page-gutter: clamp(16px, 1.6vw, 24px);
  height: calc(var(--app-visual-height, 100dvh) - var(--chat-page-gutter));
}

.chat-shell {
  grid-template-columns: minmax(250px, 300px) minmax(0, 1fr);
  gap: 12px;
  height: 100%;
}

.chat-sidebar {
  position: relative;
  z-index: 10;
  padding: 0;
  overflow: visible;
}

.chat-sidebar-actions {
  flex: 0 0 auto;
  display: grid;
  gap: 4px;
  padding: 12px 12px 4px;
}

.chat-sidebar-actions #chat-new-btn {
  width: 100%;
  margin: 0;
}

.chat-billing-banner {
  padding: 2px 2px 4px;
  border: 0;
  background: transparent;
}

.chat-billing-link {
  gap: 5px;
  min-height: 28px;
  color: var(--color-accent-blue-hover);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.3;
  text-decoration-thickness: 1px;
}

.chat-billing-link:hover {
  color: var(--color-accent-blue);
}

.chat-billing-link svg {
  width: 14px;
  height: 14px;
}

.chat-billing-dialog {
  top: calc(100% + 4px);
  left: 0;
  z-index: 80;
  width: min(620px, calc(100vw - 48px));
  border-color: var(--color-info-border);
  box-shadow: var(--shadow-card-hover);
}

.chat-list {
  margin: 4px 8px 0;
  padding: 0 4px 8px;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.chat-list-item {
  grid-template-columns: minmax(0, 1fr) 18px 32px;
}

.chat-state-indicator {
  display: inline-flex;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  align-items: center;
  justify-content: center;
  justify-self: center;
  pointer-events: none;
}

.chat-state-indicator[hidden] {
  display: none;
}

.chat-state-indicator--working {
  color: var(--color-accent-blue-hover);
}

.chat-state-indicator__spinner {
  width: 16px;
  height: 16px;
  animation: chat-state-spin 0.85s linear infinite;
}

.chat-state-indicator__dot {
  width: 9px;
  height: 9px;
  border: 2px solid var(--color-bg-card);
  border-radius: 50%;
  background: var(--color-success);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--color-success) 24%, transparent);
}

.chat-list-menu-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.chat-list-menu-btn svg {
  width: 18px;
  height: 18px;
}

.chat-list-menu--overlay {
  position: fixed;
  inset: auto;
  margin: 0;
}

@keyframes chat-state-spin {
  to { transform: rotate(360deg); }
}

.chat-sidebar-footer {
  flex: 0 0 auto;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--color-border);
  background: var(--color-bg-card);
  border-radius: 0 0 var(--radius-element) var(--radius-element);
}

.chat-sidebar-footer .chat-settings-link {
  width: 100%;
  justify-content: flex-start;
  min-height: 42px;
  border-color: transparent;
  background: transparent;
  color: var(--color-text-secondary);
}

.chat-sidebar-footer .chat-settings-link:hover {
  border-color: var(--color-border);
  background: var(--color-bg-subtle);
  box-shadow: none;
}

.chat-panel {
  position: relative;
}

#section-lidfly:has(> #lidfly-ai-section:not(.hidden)) {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

#section-lidfly:has(> #lidfly-ai-section:not(.hidden)) > #lidfly-site-tabs-section {
  flex: 0 0 auto;
}

#section-lidfly:has(> #lidfly-ai-section:not(.hidden)) > #btn-lidfly-back-to-sites {
  display: none;
}

#lidfly-ai-section:not(.hidden) {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  margin-bottom: 0;
}

.lidfly-site-chat-slot {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}

.lidfly-site-chat-slot > .chat-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  height: 100%;
  min-height: 0;
}

.lidfly-site-chat-slot > .chat-shell > .chat-sidebar {
  display: none;
}

.lidfly-site-chat-slot > .chat-shell > .chat-panel {
  min-width: 0;
}

.lidfly-site-chat-slot > .chat-shell > .chat-panel > .chat-mobile-header,
.lidfly-site-chat-slot > .chat-shell > .chat-panel > .chat-toolbar,
.lidfly-site-chat-slot > .chat-shell > .chat-panel > .chat-toolbar-scrim {
  display: none;
}

.site-ai-links {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.site-ai-link {
  display: flex;
  min-width: 0;
  min-height: 104px;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 6px;
  padding: 18px 20px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-element);
  background: var(--color-bg-card);
  color: var(--color-text);
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.site-ai-link:hover {
  border-color: color-mix(in srgb, var(--color-brand) 36%, var(--color-border));
  background: color-mix(in srgb, var(--color-brand) 5%, var(--color-bg-card));
  transform: translateY(-1px);
}

.site-ai-link strong {
  color: var(--color-brand-text);
  font-size: 17px;
}

.site-ai-link span {
  color: var(--color-text-muted);
  font-size: 14px;
  line-height: 1.5;
}

.chat-message-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 14px 12px;
}

.chat-action-card {
  width: 100%;
  padding: 12px;
  border: 1px solid color-mix(in srgb, var(--color-brand) 24%, var(--color-border));
  border-radius: 12px;
  background: color-mix(in srgb, var(--color-brand) 5%, var(--color-bg-card));
  color: var(--color-text);
}

.chat-action-card__title {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 700;
}

.chat-action-card__items,
.chat-action-card__changes {
  margin: 0;
  padding-left: 20px;
}

.chat-action-card__items {
  display: grid;
  gap: 10px;
}

.chat-action-card__item {
  padding-left: 2px;
}

.chat-action-card__provider,
.chat-action-card__action {
  display: block;
}

.chat-action-card__provider {
  color: var(--color-text-muted);
  font-size: 12px;
}

.chat-action-card__action {
  margin-top: 2px;
  font-size: 14px;
  line-height: 1.4;
}

.chat-action-card__changes {
  margin-top: 5px;
  color: var(--color-text-muted);
  font-size: 13px;
  line-height: 1.4;
}

.chat-action-card__consequence {
  margin: 5px 0 0;
  color: #b45309;
  font-size: 13px;
  line-height: 1.4;
}

.chat-action-state {
  margin: 0 14px 12px;
  padding: 9px 11px;
  border: 1px solid color-mix(in srgb, var(--border, #d7dce5) 82%, transparent);
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface, #fff) 88%, var(--accent, #315efb) 12%);
  color: var(--text-muted, #596273);
  font-size: 13px;
  line-height: 1.4;
}

.chat-action-state--blocked_scope,
.chat-action-state--verification_required,
.chat-action-state--failed {
  border-color: color-mix(in srgb, #b45309 34%, transparent);
  background: color-mix(in srgb, var(--surface, #fff) 91%, #f59e0b 9%);
}

.chat-project-offer {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.chat-project-offer__hint {
  margin: 0;
  color: var(--color-text-muted);
  font-size: 13px;
  line-height: 1.45;
}

.chat-message-action {
  min-height: 38px;
  margin-top: 0;
  font-size: 14px;
  line-height: 1.2;
}

.chat-message-action.is-loading::before {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 7px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  content: "";
  vertical-align: -2px;
  animation: chat-state-spin 0.8s linear infinite;
}

.chat-toolbar-scrim {
  display: none;
}

@media (max-width: 900px) and (min-width: 769px) {
  .chat-shell {
    grid-template-columns: minmax(230px, 280px) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
  }

  .chat-list {
    max-height: none;
  }
}

@media (max-width: 768px) {
  .site-ai-links {
    grid-template-columns: 1fr;
  }

  body.chat-mobile-mode .dashboard-main {
    padding: 0;
  }

  body.chat-mobile-mode .chat-section {
    --chat-page-gutter: 0px;
  }

  body.chat-mobile-mode .chat-sidebar {
    z-index: auto;
    overflow: hidden;
  }

  body.chat-mobile-mode .chat-sidebar-actions {
    gap: 2px;
    padding: 10px 16px 5px;
  }

  body.chat-mobile-mode .chat-sidebar-actions #chat-new-btn {
    width: 100% !important;
    min-height: 44px;
    margin: 0 !important;
    border-radius: var(--radius-pill);
  }

  body.chat-mobile-mode .chat-billing-banner {
    padding: 1px 2px 4px;
  }

  body.chat-mobile-mode .chat-billing-link {
    align-items: center;
    font-size: 12px;
  }

  body.chat-mobile-mode .chat-billing-dialog {
    position: fixed;
    top: max(148px, calc(112px + env(safe-area-inset-top)));
    left: 16px;
    z-index: 80;
    width: calc(100vw - 32px);
    max-height: calc(var(--app-visual-height, 100dvh) - 176px - env(safe-area-inset-bottom));
  }

  body.chat-mobile-mode .chat-list {
    margin: 0;
    padding: 0;
    scrollbar-gutter: auto;
  }

  body.chat-mobile-mode .chat-sidebar-footer {
    padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
    border-radius: 0;
  }

  body.chat-mobile-mode .chat-sidebar-footer .chat-settings-link {
    min-height: 46px;
    padding: 10px 12px;
    border-color: var(--color-border);
    background: var(--color-bg-subtle);
  }

  body.chat-mobile-mode .chat-panel {
    position: relative;
    isolation: isolate;
  }

  body.chat-mobile-mode .chat-toolbar-scrim {
    position: absolute;
    inset: calc(57px + env(safe-area-inset-top)) 0 0;
    z-index: 20;
    display: block;
    padding: 0;
    border: 0;
    background: color-mix(in srgb, var(--color-text) 22%, transparent);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 160ms ease, visibility 160ms ease;
  }

  body.chat-mobile-mode .chat-toolbar {
    position: absolute;
    top: calc(65px + env(safe-area-inset-top));
    right: 12px;
    left: 12px;
    z-index: 30;
    display: flex;
    max-height: min(68vh, 560px);
    overflow-y: auto;
    padding: 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-card);
    background: var(--color-bg-card);
    box-shadow: var(--shadow-card-hover);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-8px) scale(0.985);
    transform-origin: top right;
    transition:
      opacity 160ms ease,
      transform 160ms ease,
      visibility 160ms ease;
    overscroll-behavior: contain;
  }

  body.chat-mobile-mode .chat-panel.chat-menu-open .chat-toolbar-scrim {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  body.chat-mobile-mode .chat-panel.chat-menu-open .chat-toolbar {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: none;
  }

  body.chat-mobile-mode .chat-toolbar > .chat-settings-link {
    display: none;
  }
}

@media (max-width: 768px) and (prefers-reduced-motion: reduce) {
  body.chat-mobile-mode .chat-toolbar,
  body.chat-mobile-mode .chat-toolbar-scrim {
    transition: none;
  }

  .chat-state-indicator__spinner {
    animation-duration: 1.8s;
  }
}
@keyframes chat-message-arrive {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-message--arriving {
  animation: chat-message-arrive var(--motion-duration-medium) var(--motion-ease-out);
}

@media (prefers-reduced-motion: reduce) {
  .chat-message--arriving { animation: none; }
}
