:root {
  --nav-height: 68px;
}

.app-shell {
  display: block;
  min-height: 100%;
}

.app-shell:has(.bottom-nav) {
  padding-bottom: var(--nav-height);
}

.app-shell > main {
  min-width: 0;
}

.bottom-nav {
  position: fixed;
  z-index: 20;
  right: 0;
  bottom: 0;
  left: 0;
  height: var(--nav-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 8px clamp(20px, 7vw, 96px) calc(8px + env(safe-area-inset-bottom));
  background: rgb(255 255 255 / 94%);
  border-top: 1px solid #e6ede8;
  box-shadow: 0 -10px 35px rgb(24 50 37 / 7%);
  backdrop-filter: blur(16px);
}

.bottom-brand {
  display: flex;
  align-items: center;
  color: #1f2d34;
  font-size: 16px;
  letter-spacing: .025em;
}

.bottom-brand b {
  color: #3f984e;
}

.brand-cube {
  width: 22px;
  height: 22px;
  margin-right: 8px;
  border-radius: 5px;
  background: linear-gradient(145deg, #57ad61, #2f8844);
  box-shadow: inset -7px -7px 0 rgb(21 103 54 / 18%);
  transform: rotate(30deg);
}

.bottom-links {
  display: flex;
  gap: 8px;
}

.bottom-nav a {
  min-width: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 11px;
  color: #506159;
  font-weight: 700;
  text-decoration: none;
}

.bottom-nav a.active,
.bottom-nav a:hover {
  color: #fff;
  background: #3f984e;
  box-shadow: 0 8px 20px rgb(63 152 78 / 22%);
}

.bottom-nav a span {
  color: currentColor;
}

.chat-layout {
  height: calc(100vh - var(--nav-height));
}

.conversation {
  height: 100%;
  background: rgb(255 255 255 / 93%);
}

.unauthorized,
.access-state {
  min-height: calc(100vh - var(--nav-height));
  display: grid;
  place-content: center;
  padding: 24px;
  text-align: center;
  background:
    radial-gradient(circle at 78% 22%, rgb(139 216 135 / 34%), transparent 22%),
    radial-gradient(circle at 12% 88%, rgb(118 203 207 / 20%), transparent 25%),
    #fff;
}

.access-state {
  color: var(--muted);
}

.app-shell:not(:has(.bottom-nav)) .unauthorized,
.app-shell:not(:has(.bottom-nav)) .access-state {
  min-height: 100vh;
}

.access-card {
  width: min(520px, calc(100vw - 40px));
  padding: clamp(34px, 6vw, 62px);
  border: 1px solid #e1eae4;
  border-radius: 28px;
  background: rgb(255 255 255 / 88%);
  box-shadow: 0 24px 70px rgb(26 55 40 / 10%);
  backdrop-filter: blur(12px);
}

.access-card h1 {
  margin: 10px 0 12px;
  color: #1f2d34;
  font-size: clamp(30px, 5vw, 46px);
  line-height: 1.08;
  letter-spacing: -.035em;
}

.access-card > p:last-child {
  margin: 0;
  color: #65736c;
  font-size: 17px;
  line-height: 1.55;
}

.lock-mark {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  margin: 0 auto 22px;
  border-radius: 18px;
  color: #2f8844;
  font-size: 25px;
  background: #e9f5e9;
}

.header-spark {
  color: #3f984e;
}

.history {
  border-color: #e2ebe5;
  background:
    radial-gradient(circle at 0 0, rgb(151 216 145 / 25%), transparent 28%),
    #f8fbf8;
}

.new-chat {
  color: #fff;
  border: 0;
  background: #3f984e;
  box-shadow: 0 10px 24px rgb(63 152 78 / 18%);
}

.history-item.active,
.history-item:hover {
  color: #276c38;
  background: #e6f3e7;
}

.conversation header {
  border-color: #e6ede8;
  background: rgb(255 255 255 / 88%);
}

.conversation header strong {
  color: #1f2d34;
  font-size: 17px;
}

.welcome .spark {
  color: #328544;
  background: #e8f5e9;
  box-shadow: 0 12px 28px rgb(63 152 78 / 14%);
}

.welcome h1,
.dashboard h1 {
  color: #1f2d34;
  letter-spacing: -.035em;
}

.composer {
  border-color: #dbe6de;
  background: #fff;
  box-shadow: 0 12px 36px rgb(25 55 39 / 9%);
}

.composer:focus-within {
  border-color: #66aa70;
  box-shadow: 0 12px 36px rgb(63 152 78 / 14%);
}

.composer button,
.embed-form button {
  background: #3f984e;
}

.dashboard {
  min-height: calc(100vh - var(--nav-height));
  max-width: none;
  background:
    radial-gradient(circle at 90% 8%, rgb(143 216 137 / 23%), transparent 20%),
    #f8faf8;
}

.metric-grid > div,
.login-card {
  border-color: #e0e9e3;
  box-shadow: 0 12px 34px rgb(28 54 41 / 6%);
}

@media (max-width: 640px) {
  .bottom-nav {
    justify-content: center;
    padding-inline: 12px;
  }

  .bottom-brand {
    display: none;
  }

  .bottom-nav a {
    min-width: 116px;
  }
}

/* Desktop shell: fixed conversation rail with navigation anchored at its foot. */
:root {
  --sidebar-width: 250px;
  --sidebar-collapsed-width: 68px;
  --sidebar-footer-height: 174px;
}

.app-shell,
.app-shell:has(.bottom-nav) {
  min-height: 100vh;
  padding-bottom: 0;
}

.chat-layout {
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
  transition: grid-template-columns .2s ease;
}

.chat-layout.sidebar-collapsed {
  grid-template-columns: var(--sidebar-collapsed-width) minmax(0, 1fr);
}

.history {
  position: relative;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 14px 12px calc(var(--sidebar-footer-height) + 12px);
}

.history-top {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 30px;
  gap: 6px;
  margin-bottom: 14px;
}

.history .new-chat {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  padding: 9px 10px;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-toggle {
  border: 1px solid #d8e4dc;
  border-radius: 9px;
  color: #617068;
  background: rgb(255 255 255 / 78%);
  font-size: 21px;
  line-height: 1;
}

.sidebar-toggle:hover {
  color: #276c38;
  border-color: #a9cbb0;
  background: #fff;
}

.history-scroll {
  min-height: 0;
  flex: 1 1 auto;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #c9d8cd transparent;
}

.history-scroll h6 {
  margin: 4px 0 7px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-icon {
  display: none;
  flex: 0 0 auto;
  font-size: 18px;
}

.bottom-nav {
  z-index: 25;
  top: auto;
  right: auto;
  bottom: 0;
  left: 0;
  width: var(--sidebar-width);
  height: var(--sidebar-footer-height);
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px;
  background: rgb(248 251 248 / 96%);
  border-top: 1px solid #e0e9e3;
  border-right: 1px solid #e2ebe5;
  box-shadow: 0 -14px 30px rgb(24 50 37 / 5%);
}

.bottom-links {
  display: grid;
  gap: 5px;
}

.bottom-nav a {
  min-width: 0;
  justify-content: flex-start;
  padding: 9px 11px;
  border-radius: 9px;
  font-size: 13px;
}

.bottom-nav a.active,
.bottom-nav a:hover {
  color: #276c38;
  background: #e6f3e7;
  box-shadow: none;
}

.bottom-brand {
  justify-content: center;
  padding-top: 9px;
  border-top: 1px solid #e3ebe5;
  font-size: 13px;
}

.brand-cube {
  width: 17px;
  height: 17px;
  border-radius: 4px;
}

.app-shell:has(.sidebar-collapsed) .bottom-nav {
  width: var(--sidebar-collapsed-width);
  padding-inline: 10px;
}

.sidebar-collapsed .history {
  padding-inline: 8px;
}

.sidebar-collapsed .history-top {
  display: flex;
  flex-direction: column;
}

.sidebar-collapsed .new-chat,
.sidebar-collapsed .sidebar-toggle,
.app-shell:has(.sidebar-collapsed) .bottom-nav a {
  width: 100%;
  justify-content: center;
}

.sidebar-collapsed .sidebar-label,
.sidebar-collapsed .history h6,
.app-shell:has(.sidebar-collapsed) .nav-label,
.app-shell:has(.sidebar-collapsed) .brand-name {
  display: none;
}

.sidebar-collapsed .history-icon {
  display: inline;
}

.app-shell:has(.bottom-nav) .dashboard {
  min-height: 100vh;
  margin-left: var(--sidebar-width);
}

.conversation {
  height: 100vh;
}

.message {
  font-size: 13px;
  line-height: 1.46;
}

.message > span {
  font-size: 12px;
}

.message-body .table-scroll {
  overflow-x: auto;
  border-color: #d9e4dc;
  box-shadow: 0 3px 12px rgb(25 55 39 / 4%);
}

.message-body table {
  min-width: 100%;
  width: max-content;
  max-width: 100%;
  table-layout: auto;
  font-size: 12px;
}

.message-body th,
.message-body td {
  max-width: 320px;
  padding: 7px 9px;
  vertical-align: top;
  white-space: normal;
  overflow-wrap: anywhere;
}

.message-body th {
  position: sticky;
  top: 0;
  color: #263b30;
  background: #edf4ef;
}

.thinking {
  min-height: 28px;
  display: flex;
  align-items: center;
  gap: 4px;
  color: #738078;
}

.thinking i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4a9b58;
  animation: thinking-pulse 1.1s infinite ease-in-out;
}

.thinking i:nth-child(2) { animation-delay: .14s; }
.thinking i:nth-child(3) { animation-delay: .28s; }
.thinking small { margin-left: 5px; font-size: 11px; }

@keyframes thinking-pulse {
  0%, 60%, 100% { opacity: .3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

@media (prefers-reduced-motion: reduce) {
  .thinking i { animation: none; opacity: .65; }
}

@media (max-width: 800px) {
  .app-shell:has(.bottom-nav) {
    padding-bottom: var(--nav-height);
  }

  .chat-layout,
  .chat-layout.sidebar-collapsed {
    display: block;
    height: calc(100vh - var(--nav-height));
  }

  .history {
    display: none;
  }

  .conversation {
    height: 100%;
  }

  .bottom-nav,
  .app-shell:has(.sidebar-collapsed) .bottom-nav {
    right: 0;
    width: auto;
    height: var(--nav-height);
    flex-direction: row;
    align-items: center;
    justify-content: center;
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
    border-right: 0;
  }

  .bottom-links {
    display: flex;
  }

  .bottom-nav a,
  .app-shell:has(.sidebar-collapsed) .bottom-nav a {
    width: auto;
    min-width: 112px;
    justify-content: center;
  }

  .bottom-brand {
    display: none;
  }

  .app-shell:has(.sidebar-collapsed) .nav-label {
    display: inline;
  }

  .app-shell:has(.bottom-nav) .dashboard {
    min-height: calc(100vh - var(--nav-height));
    margin-left: 0;
  }
}
