:root {
  /* Light theme (embeddable-friendly) */
  --bg: #f6f7fb;
  --panel: #ffffff;
  --muted: #4b5563;
  --text: #0f172a;
  --accent: #d97706; /* honey */
  --border: rgba(15, 23, 42, 0.12);
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial,
    "Apple Color Emoji", "Segoe UI Emoji";
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  height: 100vh;
  height: 100dvh; /* Dynamic viewport height for better mobile support */
}

.app {
  max-width: 100%;
  margin: 0;
  height: 100vh;
  height: 100dvh; /* Dynamic viewport height for better mobile support */
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  transition: height 0.3s ease-out;
}

.topbar {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.layout {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
}

.layout__main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  width: 100%;
}

.topbar__actions {
  display: flex;
  gap: 8px;
  align-items: center;
  width: 100%;
  justify-content: center;
}

.btn {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 9px 12px;
  background: rgba(255, 255, 255, 0.8);
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
}

.btn:hover {
  border-color: rgba(217, 119, 6, 0.45);
}

.btn--ghost {
  background: rgba(255, 255, 255, 0.55);
}

.btn--primary {
  border-color: rgba(217, 119, 6, 0.8);
  background: rgba(217, 119, 6, 0.16);
}

.btn--primary:hover {
  background: rgba(217, 119, 6, 0.22);
}

.chat {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 16px 100px;
  background: var(--bg);
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.sidebar {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.9);
  border-radius: 14px;
  padding: 14px 14px 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: sticky;
  top: 82px;
  max-height: calc(100vh - 110px);
  overflow-y: auto;
  position: relative;
}

.sidebar__close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: none;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  z-index: 10;
  padding: 0;
}

.sidebar__close:hover {
  background: rgba(217, 119, 6, 0.1);
  color: var(--accent);
}

.sidebar__section + .sidebar__section {
  border-top: 1px dashed rgba(15, 23, 42, 0.08);
  padding-top: 10px;
  margin-top: 4px;
}

.sidebar__title {
  font-weight: 600;
  margin-bottom: 4px;
}

.sidebar__description {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 10px;
}

.subscribe {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.subscribe__status {
  min-height: 18px;
  font-size: 12px;
  margin-top: 2px;
}

.subscribe__status--ok {
  color: #16a34a;
}

.subscribe__status--error {
  color: #b91c1c;
}

.recent {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.recent-empty {
  font-size: 13px;
  color: var(--muted);
}

.recent-item {
  border: 1px dashed var(--border);
  border-radius: 999px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.9);
  text-align: left;
  cursor: pointer;
  font-size: 13px;
}

.recent-item:hover {
  border-style: solid;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}

.field__label {
  font-size: 13px;
  color: var(--muted);
}

.field__input {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--text);
  outline: none;
  font-size: 16px; /* Prevent iOS zoom on focus */
}

.field__input:focus {
  border-color: rgba(246, 196, 83, 0.6);
}

.field__value {
  font-size: 14px;
}

.msg {
  margin-bottom: 24px;
  display: flex;
  width: 100%;
}

.msg--user {
  justify-content: flex-end;
}

.msg--bot {
  justify-content: flex-start;
}

.bubble {
  max-width: 85%;
  line-height: 1.6;
  white-space: normal;
  word-wrap: break-word;
}

.bubble--user {
  background: rgba(217, 119, 6, 0.12);
  color: var(--text);
  border-radius: 18px 18px 4px 18px;
  padding: 12px 16px;
  margin-left: auto;
}

.bubble--bot {
  background: transparent;
  color: var(--text);
  padding: 12px 0;
  border-radius: 0;
  border: none;
}

.bubble--bot h1,
.bubble--bot h2,
.bubble--bot h3 {
  margin: 16px 0 8px;
  line-height: 1.3;
  font-weight: 600;
}

.bubble--bot h1 { font-size: 20px; }
.bubble--bot h2 { font-size: 18px; }
.bubble--bot h3 { font-size: 16px; }

.bubble--bot .p {
  margin: 8px 0;
}

.bubble--bot ul,
.bubble--bot ol {
  margin: 8px 0 8px 20px;
  padding: 0;
}

.bubble--bot li {
  margin: 6px 0;
}

.bubble--user h1,
.bubble--user h2,
.bubble--user h3 {
  margin: 8px 0 4px;
  line-height: 1.2;
}

.bubble--user h1 { font-size: 16px; }
.bubble--user h2 { font-size: 15px; }
.bubble--user h3 { font-size: 14px; }

.bubble--user .p {
  margin: 4px 0;
}

.bubble--user ul,
.bubble--user ol {
  margin: 4px 0 4px 16px;
  padding: 0;
}

.bubble--user li {
  margin: 3px 0;
}

.bubble code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.95em;
  padding: 1px 6px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
}

.bubble hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 10px 0;
}

/* ChatGPT-like typing cursor while streaming */
.bubble--bot.is-streaming::after {
  content: "▍";
  color: var(--accent);
  animation: blink 1s step-end infinite;
  margin-left: 2px;
  display: inline-block;
}

.table-block {
  margin: 10px 0;
}

.table-wrapper {
  overflow-x: auto;
}

.md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.md-table th,
.md-table td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
}

.md-table thead {
  background: rgba(217, 119, 6, 0.06);
}

.table-chart {
  margin-top: 6px;
  padding-top: 4px;
  border-top: 1px dashed rgba(15, 23, 42, 0.08);
}

.table-chart__controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-bottom: 4px;
}

.table-chart__label {
  font-size: 12px;
  color: var(--muted);
}

.table-chart__canvas {
  width: 100%;
  max-width: 100%;
  border-radius: 10px;
  border: 1px solid rgba(15, 23, 42, 0.06);
  background: #f9fafb;
}

.chip--small {
  padding: 4px 8px;
  font-size: 12px;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.thinking-status {
  color: var(--muted);
  font-style: italic;
  padding: 8px 0;
  font-size: 14px;
}

.followups {
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.95);
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
  z-index: 40;
  margin-top: auto;
}

.followups__label {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.followups__buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.chip {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.8);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
}

.chip:hover {
  border-color: rgba(246, 196, 83, 0.45);
}

.composer {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
  z-index: 50;
  align-items: center;
}

.composer__input {
  border: 1px solid var(--border);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
  padding: 12px 16px;
  outline: none;
  flex: 1;
  font-size: 16px; /* Prevent iOS zoom on focus */
}

.composer__input:focus {
  border-color: rgba(246, 196, 83, 0.6);
}

.composer__send {
  border: none;
  background: var(--accent);
  color: white;
  padding: 12px 20px;
  border-radius: 24px;
  cursor: pointer;
  font-weight: 600;
  flex-shrink: 0;
}

.composer__send:hover {
  background: rgba(217, 119, 6, 0.18);
}

.composer__stop {
  border: none;
  background: #b91c1c;
  color: white;
  padding: 12px 20px;
  border-radius: 24px;
  cursor: pointer;
  font-weight: 600;
  flex-shrink: 0;
}

.composer__stop:hover {
  background: rgba(185, 28, 28, 0.18);
}

.clar-card {
  margin-top: 16px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.98);
  padding: 16px;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 85%;
  position: relative;
  z-index: 10;
  align-self: flex-start; /* Always align to left, like bot messages */
  margin-left: 0; /* Ensure no left margin that could push it right */
  margin-right: auto; /* Push to left side */
}

.clar-card__title {
  font-size: 13px;
  color: var(--muted);
}

.clar-card__question {
  font-size: 14px;
  font-weight: 500;
}

.clar-card__choices {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.clar-card__choice {
  border-radius: 999px;
  border: 1px solid var(--border);
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  text-align: left;
  font-size: 14px;
}

.clar-card__choice:hover {
  border-color: rgba(246, 196, 83, 0.5);
  background: rgba(246, 196, 83, 0.08);
}

.clar-card__choice-label {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: rgba(217, 119, 6, 0.08);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 600;
}

.clar-card__choice-text {
  /* In a flex row, long text can get visually clipped unless the item is allowed
     to shrink below its intrinsic content width. */
  flex: 1 1 auto;
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
}

.clar-card__free {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 4px;
}

.clar-card__free-input {
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.9);
  outline: none;
  font-size: 16px; /* Prevent iOS zoom on focus */
}

.clar-card__free-input:focus {
  border-color: rgba(246, 196, 83, 0.6);
}

.clar-card__free-send {
  border-radius: 10px;
  border: 1px solid rgba(217, 119, 6, 0.7);
  padding: 6px 10px;
  background: rgba(217, 119, 6, 0.14);
  cursor: pointer;
  font-weight: 600;
}

.clar-card__free-send:hover {
  background: rgba(217, 119, 6, 0.2);
}

/* Mobile-first base styles */
@media (max-width: 840px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 200;
    display: none;
    overflow-y: auto;
    background: var(--bg);
  }

  .app--sidebar-open .sidebar {
    display: flex;
  }

  .sidebar__close {
    position: fixed;
    top: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    font-size: 28px;
  }

  .bubble {
    max-width: 92%;
  }
  
  .bubble--user {
    max-width: 85%;
  }

  .chat {
    padding: 12px 12px 100px;
  }

  .composer {
    padding: 10px 12px;
  }

  .composer__input,
  .field__input,
  .clar-card__free-input {
    font-size: 16px !important;
  }

  /* Keyboard handling styles */
  .app.keyboard-visible {
    height: 100dvh;
  }

  .app.keyboard-visible .chat {
    transition: max-height 0.3s ease-out;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Ensure composer stays visible above keyboard */
  .composer {
    position: sticky;
    bottom: 0;
    z-index: 50;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(10px);
  }

  /* Adjust chat container when keyboard is visible */
  .app.keyboard-visible .layout__main {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
  }

  /* Smooth transitions for layout changes */
  .layout__main,
  .chat {
    transition: max-height 0.3s ease-out, padding 0.3s ease-out;
  }
}

/* Desktop styles */
@media (min-width: 841px) {
  .app {
    max-width: 1280px;
    margin: 0 auto;
    padding: 18px;
    gap: 14px;
  }

  .layout {
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(0, 1.2fr);
    gap: 14px;
  }

  .sidebar {
    position: sticky;
    top: 82px;
    max-height: calc(100vh - 110px);
    overflow-y: auto;
    display: none;
  }

  .app--sidebar-open .sidebar {
    display: flex;
  }

  .topbar {
    border-radius: 14px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    margin-bottom: 14px;
  }

  .chat {
    border: 1px solid var(--border);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.86);
    box-shadow: var(--shadow);
    padding: 20px;
  }

  .composer {
    border-radius: 14px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    margin-top: 10px;
  }

  .followups {
    border-radius: 14px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    margin-top: 10px;
  }
}


