:root {
  --bg-page: #f7f9f6;
  --bg-surface: #ffffff;
  --bg-surface-soft: #f5f7f4;
  --bg-sidebar: #213e2b;
  --bg-sidebar-border: #162a1d;
  --bg-sidebar-soft: #1a3222;
  --bg-user: #e6f4ea;
  --text-main: #111827;
  --text-muted: #5f6b66;
  --text-inverse: #ffffff;
  --border-soft: #d7ddd8;
  --border-green: #cbe5d5;
  --green-strong: #244230;
  --green-mid: #3b8056;
  --green-accent: #52a472;
  --green-accent-strong: #409b69;
  --green-accent-hover: #328256;
  --shadow-soft: 0 18px 42px rgba(17, 24, 39, 0.08);
  --shadow-card: 0 12px 30px rgba(17, 24, 39, 0.08);
  --font-family: 'Montserrat', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  min-height: 100%;
}

body {
  font-family: var(--font-family);
  color: var(--text-main);
  background: var(--bg-page);
}

body.standalone-mode {
  min-height: 100vh;
}

body.widget-mode {
  min-height: 100vh;
  background: transparent;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
  border: 0;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.muted {
  color: var(--text-muted);
}

.main-wrapper {
  width: 100%;
  height: 100vh;
  min-height: 100vh;
  padding: 1rem;
}

body.widget-mode .main-wrapper {
  min-height: 100vh;
  padding: 0;
}

.landing-screen {
  min-height: calc(100vh - 2rem);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  padding: 2rem;
  border-radius: 28px;
  background:
    linear-gradient(rgba(18, 34, 25, 0.58), rgba(18, 34, 25, 0.7)),
    url('/static/bg-hero.jpg') center/cover;
  color: var(--text-inverse);
  text-align: center;
  box-shadow: var(--shadow-soft);
}

.landing-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.landing-eyebrow span {
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: var(--green-mid);
  font-size: 0.68rem;
  letter-spacing: 0.16em;
}

.landing-screen h1 {
  font-size: clamp(2.6rem, 5vw, 4rem);
  font-weight: 800;
  line-height: 0.95;
}

.landing-screen p {
  max-width: 42rem;
  font-size: 1.04rem;
  line-height: 1.65;
}

.hero-btn,
.primary-btn,
.secondary-btn,
.brief-artifact-link {
  border-radius: 14px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.hero-btn {
  padding: 0.95rem 1.6rem;
  background: var(--green-accent-strong);
  color: var(--text-inverse);
  box-shadow: 0 10px 22px rgba(17, 24, 39, 0.16);
}

.hero-btn:hover,
.primary-btn:hover {
  background: var(--green-accent-hover);
}

.chat-layout {
  width: min(1300px, 100%);
  margin: 0 auto;
  height: calc(100vh - 2rem);
  min-height: calc(100vh - 2rem);
  display: flex;
  gap: 1.5rem;
}

body.widget-mode .chat-layout {
  width: 100%;
  height: 100vh;
  min-height: 100vh;
  grid-template-columns: 1fr;
  gap: 0;
}

.chat-primary {
  flex: 0 1 60%;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border-soft);
  border-radius: 28px;
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}

body.widget-mode .chat-primary {
  border-radius: 0;
  border: 0;
  box-shadow: none;
}

.chat-header {
  padding: 1.6rem;
  background: linear-gradient(180deg, #f2fcf5 0%, #ffffff 100%);
  border-bottom: 1px solid rgba(17, 24, 39, 0.06);
}

.chat-header-main {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.chat-title {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.chat-eyebrow-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.chat-eyebrow {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--green-mid);
}

.chat-beta-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 22px;
  padding: 0 0.65rem;
  border-radius: 999px;
  background: var(--green-mid);
  color: var(--text-inverse);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.chat-title h2 {
  font-size: clamp(2rem, 3vw, 2.7rem);
  line-height: 0.94;
  font-weight: 800;
  color: var(--text-main);
}

.chat-support-copy {
  max-width: 40rem;
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.55;
}

.chat-powered-by {
  font-size: 0.92rem;
  color: #667085;
  font-weight: 500;
}

.chat-auth-panel {
  width: min(100%, 360px);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 1rem;
  border: 1px solid var(--border-green);
  background: var(--bg-surface);
  border-radius: 20px;
  box-shadow: var(--shadow-card);
}

.chat-auth-panel[data-auth-state="signed-in"] {
  border-color: rgba(82, 164, 114, 0.45);
}

.chat-auth-panel[data-auth-state="bypass"] {
  border-color: rgba(59, 128, 86, 0.3);
}

.chat-auth-label,
.chat-session-label,
.session-section-label {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.chat-auth-label {
  color: var(--text-main);
}

.chat-auth-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

#googleSignIn {
  min-height: 38px;
}

.secondary-btn {
  padding: 0.82rem 1.1rem;
  background: transparent;
  color: var(--green-strong);
  border: 1px solid rgba(36, 66, 48, 0.24);
}

.secondary-btn:hover {
  background: var(--green-strong);
  color: var(--text-inverse);
}

.primary-btn {
  padding: 0.95rem 1.4rem;
  background: var(--green-accent-strong);
  color: var(--text-inverse);
}

.daily-budget-meter {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-top: 0.2rem;
  padding-top: 0.8rem;
  border-top: 1px solid rgba(17, 24, 39, 0.06);
}

.daily-budget-meter[hidden] {
  display: none;
}

.daily-budget-meter-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.daily-budget-label,
.daily-budget-percent {
  font-size: 0.8rem;
  font-weight: 700;
}

.daily-budget-label {
  color: var(--text-main);
}

.daily-budget-percent {
  color: var(--green-mid);
}

.daily-budget-bar {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(17, 24, 39, 0.12);
}

.daily-budget-bar-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green-accent), var(--green-accent-strong));
  transition: width 0.2s ease;
}

.daily-budget-status {
  font-size: 0.75rem;
}

.daily-budget-meter[data-limit-reached="true"] .daily-budget-percent {
  color: #9f1239;
}

.daily-budget-meter[data-limit-reached="true"] .daily-budget-bar-fill {
  background: linear-gradient(90deg, #dc2626, #9f1239);
}

.session-sidebar {
  display: flex;
  width: stretch;
  flex-direction: column;
  gap: 1rem;
  align-self: stretch;
  flex: 0 1 40%;
  min-width: 320px;
  min-height: 0;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
}

.session-access-card {
  width: 100%;
  flex-shrink: 0;
}

.widget-access-card {
  width: 100%;
}

.session-sidebar-card {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 1.5rem;
  background: var(--bg-sidebar);
  border: 1px solid var(--bg-sidebar-border);
  border-radius: 28px;
  color: var(--text-inverse);
  box-shadow: 0 18px 42px rgba(17, 24, 39, 0.18);
}

.session-sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.chat-session-label,
.session-section-label {
  color: #a6c7b3;
}

.session-sidebar-divider {
  height: 1px;
  background: rgba(166, 199, 179, 0.18);
}

.header-reset-btn {
  width: 100%;
  min-height: 52px;
  text-align: left;
  font-size: 0.92rem;
  color: var(--text-inverse);
  border-color: #4a7258;
}

.header-reset-btn:hover {
  background: #2c523a;
  color: var(--text-inverse);
}

.saved-state-card {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: 1rem;
  background: var(--bg-sidebar-soft);
  border: 1px solid rgba(166, 199, 179, 0.18);
  border-radius: 20px;
}

.saved-state-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.saved-state-title {
  font-size: 0.94rem;
  font-weight: 700;
}

.saved-state-status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 0.6rem;
  border-radius: 999px;
  background: var(--green-mid);
  color: var(--text-inverse);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.saved-state-card[data-has-shortlist="false"] .saved-state-status-badge {
  background: rgba(166, 199, 179, 0.18);
  color: #d6e2da;
}

.saved-state-summary {
  font-size: 0.8rem;
  line-height: 1.55;
  color: #d3ddd6;
}

.saved-state-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  list-style: none;
}

.saved-state-item {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  font-size: 0.84rem;
  line-height: 1.45;
  color: #f3f6f4;
}

.saved-state-rank {
  min-width: 1.25rem;
  font-weight: 800;
  color: var(--green-accent);
}

.saved-state-item-title {
  flex: 1;
}

.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: var(--bg-surface-soft);
}

.chat-message {
  max-width: min(100%, 760px);
}

.role-user {
  align-self: flex-end;
}

.role-user .message-content {
  padding: 1rem 1.2rem;
  background: var(--bg-user);
  color: #1c472d;
  border-radius: 18px 18px 6px 18px;
  border-right: 4px solid var(--green-accent);
  box-shadow: 0 10px 20px rgba(82, 164, 114, 0.08);
}

.role-assistant {
  align-self: flex-start;
}

.role-assistant .message-content {
  padding: 1rem 1.2rem;
  background: var(--bg-surface);
  color: #334155;
  border: 1px solid rgba(17, 24, 39, 0.08);
  border-radius: 18px;
  border-left: 4px solid var(--green-strong);
  box-shadow: 0 8px 18px rgba(17, 24, 39, 0.06);
}

.role-system {
  align-self: center;
  max-width: min(100%, 720px);
}

.role-system .message-content {
  padding: 0.65rem 0.95rem;
  color: var(--text-muted);
  text-align: center;
  font-size: 0.84rem;
  font-style: italic;
}

.role-system.tool-activity .message-content {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.8rem 1rem;
  background: rgba(36, 66, 48, 0.06);
  border: 1px solid rgba(36, 66, 48, 0.12);
  border-radius: 999px;
  color: var(--green-strong);
  font-style: normal;
  font-weight: 600;
}

.tool-activity-prefix {
  color: var(--text-muted);
  font-weight: 500;
}

.tool-activity-name {
  color: var(--green-strong);
  font-weight: 700;
}

.message-content h1,
.message-content h2,
.message-content h3 {
  color: var(--green-strong);
  margin: 1rem 0 0.45rem;
  font-weight: 700;
}

.message-content p {
  margin-bottom: 0.8rem;
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-content strong {
  color: var(--green-strong);
  font-weight: 700;
}

.message-content ul,
.message-content ol {
  margin-left: 1.4rem;
  margin-bottom: 0.85rem;
}

.message-content li {
  margin-bottom: 0.35rem;
}

.message-content blockquote {
  margin: 1rem 0;
  padding-left: 1rem;
  border-left: 3px solid var(--green-accent);
  color: var(--text-muted);
  font-style: italic;
}

.message-content .brief-artifact-link {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 42px;
  margin: 0.35rem 0.55rem 0.2rem 0;
  padding: 0.72rem 1rem;
  background: #edf6f0;
  border: 1px solid var(--border-green);
  color: var(--green-strong);
  text-decoration: none;
  box-shadow: 0 10px 20px rgba(36, 66, 48, 0.08);
}

.message-content .brief-artifact-link::before {
  content: '';
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  background: var(--green-strong);
}

.message-content .brief-artifact-link:hover {
  transform: translateY(-1px);
  background: #e4f1e8;
  color: var(--green-strong);
}

.message-content .brief-artifact-link:focus-visible {
  outline: 3px solid rgba(82, 164, 114, 0.25);
  outline-offset: 2px;
}

.message-content .brief-artifact-link[data-brief-download-state="loading"] {
  pointer-events: none;
  cursor: progress;
  background: rgba(36, 66, 48, 0.08);
  color: rgba(17, 24, 39, 0.72);
  box-shadow: none;
  transform: none;
}

.message-content .brief-artifact-link[data-brief-download-state="opened"] {
  background: rgba(82, 164, 114, 0.18);
}

.message-content .brief-artifact-link[data-brief-download-state="error"] {
  background: rgba(185, 28, 28, 0.08);
  border-color: rgba(185, 28, 28, 0.18);
  color: #991b1b;
  box-shadow: none;
}

.message-content .brief-artifact-link[data-brief-download-state="error"]::before {
  background: #991b1b;
}

.chat-input-area {
  display: flex;
  gap: 0.85rem;
  align-items: flex-end;
  padding: 1rem 1.25rem 1.25rem;
  background: var(--bg-surface);
  border-top: 1px solid rgba(17, 24, 39, 0.06);
  position: sticky;
  bottom: 0;
  z-index: 2;
  box-shadow: 0 -10px 24px rgba(17, 24, 39, 0.04);
}

textarea {
  flex: 1;
  min-height: 52px;
  max-height: 180px;
  padding: 0.95rem 1rem;
  border-radius: 16px;
  border: 1px solid var(--border-soft);
  background: #fbfcfb;
  color: var(--text-main);
  resize: none;
}

textarea:focus {
  outline: none;
  border-color: rgba(82, 164, 114, 0.72);
  box-shadow: 0 0 0 3px rgba(82, 164, 114, 0.12);
  background: var(--bg-surface);
}

#sendBtn {
  min-width: 112px;
}

button:disabled {
  cursor: not-allowed;
}

#sendBtn:disabled {
  background: rgba(64, 155, 105, 0.45);
  color: rgba(255, 255, 255, 0.92);
  box-shadow: none;
}

body.widget-mode .chat-layout {
  margin: 0;
}

body.widget-mode .chat-header {
  padding: 1rem;
}

body.widget-mode .chat-header-main {
  gap: 0.85rem;
}

body.widget-mode .chat-powered-by,
body.widget-mode .chat-support-copy,
body.widget-mode .chat-auth-label,
body.widget-mode .chat-session-label,
body.widget-mode .session-section-label,
body.widget-mode .saved-state-summary {
  display: none;
}

body.widget-mode .chat-title h2 {
  font-size: 1.35rem;
}

body.widget-mode .chat-auth-panel {
  width: 100%;
  box-shadow: none;
}

body.widget-mode .session-sidebar {
  display: none;
}

body.widget-mode .chat-history {
  padding: 1rem;
}

body.widget-mode .chat-input-area {
  padding: 0.9rem 1rem 1rem;
}

body.widget-mode .message-content .brief-artifact-link {
  width: 100%;
  justify-content: center;
  margin-right: 0;
}

@media (max-width: 1080px) {
  .chat-layout {
    flex-direction: column;
    height: auto;
    min-height: auto;
  }

  .session-sidebar-card {
    position: static;
  }

  .session-sidebar {
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 860px) {
  .main-wrapper {
    padding: 0.75rem;
  }

  .landing-screen {
    min-height: calc(100vh - 1.5rem);
    border-radius: 22px;
  }

  .chat-header-main {
    gap: 1rem;
  }

  .chat-auth-panel {
    width: 100%;
  }
}

@media (max-width: 640px) {
  .main-wrapper {
    padding: 0.5rem;
  }

  .chat-layout {
    min-height: calc(100vh - 1rem);
    gap: 0.75rem;
  }

  .landing-screen h1 {
    font-size: 2.2rem;
  }

  .chat-primary,
  .session-sidebar-card,
  .landing-screen {
    border-radius: 20px;
  }

  .chat-header,
  .chat-history,
  .chat-input-area,
  .session-sidebar-card {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .chat-history {
    padding-top: 1rem;
    padding-bottom: 1rem;
  }

  .chat-input-area {
    flex-direction: column;
    align-items: stretch;
  }

  #sendBtn,
  .header-reset-btn,
  .chat-auth-actions .secondary-btn,
  #googleSignIn {
    width: 100%;
  }

  .chat-auth-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .chat-message {
    max-width: 100%;
  }
}

.loading-dots {
  display: inline-block;
}

.loading-dots::after {
  content: '.';
  animation: dots 1.5s steps(5, end) infinite;
}

@keyframes dots {
  0%,
  20% {
    content: '.';
  }

  40% {
    content: '..';
  }

  60% {
    content: '...';
  }

  80%,
  100% {
    content: '';
  }
}
