:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #eef2f3;
  --text: #17211f;
  --muted: #62716c;
  --line: #d8dfdc;
  --accent: #0f6b5f;
  --accent-dark: #0b5149;
  --warning: #8a5a00;
  --danger: #9b2f2f;
  --ok: #1e6d38;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfa;
}

.topbarBrand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbarLogo {
  height: 48px;
  width: 48px;
  object-fit: contain;
  flex-shrink: 0;
}

.questionHeader {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.questionHeader label {
  margin-bottom: 0;
}

.newConversationButton {
  background: #fff;
  border: 1px solid var(--accent);
  color: var(--accent-dark);
  padding: 7px 10px;
  font-size: 13px;
}

.newConversationButton:hover {
  background: #e7f4ea;
  color: var(--accent-dark);
}

h1,
h2 {
  margin: 0;
  font-weight: 650;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 15px;
}

p {
  margin: 5px 0 0;
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(420px, 1fr);
  gap: 16px;
  padding: 16px;
  height: calc(100vh - 78px);
  overflow: hidden;
}

.askPanel,
.answerPanel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.askPanel {
  overflow: hidden;
}

.answerPanel {
  overflow-y: auto;
}

.askPanel {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.chatThreadTitle {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
  flex-shrink: 0;
}

.chatThread {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 8px;
}

.chatEmpty {
  font-size: 13px;
  padding: 16px 0 8px;
  margin: 0;
}

.chatTurn {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chatQ {
  font-size: 12px;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 6px;
  padding: 6px 9px;
  line-height: 1.4;
}

.chatQ .chatLabel {
  font-weight: 700;
  color: var(--accent);
  margin-right: 6px;
}

.chatA {
  font-size: 13px;
  color: var(--text);
  background: #fbfcfa;
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
  padding: 6px 9px;
  line-height: 1.4;
}

.inputArea {
  flex-shrink: 0;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  margin-top: 8px;
}

.conversationListPanel {
  flex-shrink: 0;
  border-top: 1px solid var(--line);
  padding-top: 8px;
  margin-top: 8px;
}

.conversationListPanel summary {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  padding: 2px 0;
  list-style: none;
}

.conversationListPanel summary::before {
  content: "▸ ";
  font-size: 10px;
}

details.conversationListPanel[open] > summary::before {
  content: "▾ ";
}

label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
}

textarea {
  width: 100%;
  min-height: 160px;
  resize: vertical;
  padding: 12px;
  color: var(--text);
  border: 1px solid #bfcac6;
  border-radius: 6px;
  font: inherit;
  line-height: 1.45;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  padding: 10px 13px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button:hover {
  background: var(--accent-dark);
}

button:disabled {
  background: #dfe5e2;
  color: #7a8782;
  cursor: not-allowed;
}

button:disabled:hover {
  background: #dfe5e2;
}

.secondary,
.iconButton,
.feedback button {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  position: relative;
}

.secondary:hover,
.iconButton:hover,
.feedback button:hover {
  background: #e2e9e6;
}

.actions,
.answerHeader {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.actions {
  margin-top: 12px;
}

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

.sectionHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.compact {
  padding: 6px 9px;
  font-size: 12px;
}

.conversationList {
  display: grid;
  gap: 6px;
  margin-top: 12px;
}

.conversationList button {
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  font-size: 12px;
}

.conversationList button.selected {
  border-color: var(--accent);
  background: #e7f4ea;
  color: var(--accent-dark);
}

.conversationTurn {
  border-left: 3px solid var(--accent);
  padding: 7px 9px;
  background: #fbfcfa;
  font-size: 13px;
  line-height: 1.35;
}

.conversationTurn strong,
.conversationTurn span {
  display: block;
}

.conversationTurn span {
  color: var(--muted);
  margin-top: 3px;
}

.conversationTurn .conversationReply {
  color: var(--text);
  margin-top: 7px;
}

.answerPanel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.answer {
  white-space: pre-wrap;
  line-height: 1.55;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fbfcfa;
}

.answer.empty {
  color: var(--muted);
}

.answer a {
  color: var(--accent-dark);
  font-weight: 650;
  text-decoration: underline;
  overflow-wrap: anywhere;
}

.translationStatus {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
}

.detailsPanel {
  border-top: 1px solid var(--line);
  padding-top: 10px;
  margin-top: 2px;
}

.detailsPanel > summary {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  list-style: none;
  padding: 3px 0;
}

.detailsPanel > summary::before {
  content: "▸  ";
  font-size: 10px;
  color: var(--muted);
}

details.detailsPanel[open] > summary::before {
  content: "▾  ";
}

.refinePanel {
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.refinePanel textarea {
  min-height: 80px;
  resize: vertical;
}

.refineActions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.refineActions .mutedText {
  font-size: 13px;
}


.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 650;
  background: var(--surface-2);
  color: var(--muted);
  margin-right: 6px;
}

.pill.high,
.pill.ok {
  color: var(--ok);
  background: #e7f4ea;
}

.pill.medium,
.pill.review {
  color: var(--warning);
  background: #fff4d9;
}

.pill.low,
.pill.none {
  color: var(--danger);
  background: #f9e7e7;
}

.stack {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.source {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfa;
}

.source h3 {
  margin: 0 0 4px;
  font-size: 14px;
}

.source code {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.source p {
  margin: 0;
  color: var(--text);
  font-size: 13px;
  line-height: 1.35;
  max-height: 130px;
  overflow: auto;
}

.source a {
  color: var(--accent-dark);
  text-decoration: none;
}

.source a:hover {
  text-decoration: underline;
}

.videoSuggestion .videoLink {
  margin-top: 8px;
  font-size: 13px;
  font-weight: 650;
}

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

.feedback {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.feedback button.selected {
  border-color: var(--accent);
  background: #e7f4ea;
  color: var(--accent-dark);
}

.feedback button.selected::after {
  content: "Saved";
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

@media (max-width: 1100px) {
  /* Switch from fixed-height columns to single scrollable column */
  .layout {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
    padding: 12px;
    gap: 12px;
  }

  /* Chat thread: give it a fixed max-height since it can't flex-fill any more */
  .chatThread {
    flex: none;
    max-height: 220px;
  }

  /* Panels: let them size to content and scroll naturally */
  .answerPanel {
    overflow-y: visible;
  }

  .topbar {
    padding: 12px 16px;
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }
}

@media (max-width: 600px) {
  body {
    background: var(--surface);
  }

  h1 {
    font-size: 19px;
  }

  h2 {
    font-size: 14px;
  }

  .topbar {
    padding: 10px 12px;
  }

  .topbarBrand {
    align-items: flex-start;
  }

  .topbarLogo {
    height: 40px;
    width: 40px;
  }

  .topbarBrand p {
    display: none;
  }

  .iconButton {
    width: 100%;
  }

  .layout {
    padding: 0;
    gap: 0;
  }

  .askPanel,
  .answerPanel {
    border-width: 0 0 1px;
    border-radius: 0;
    padding: 12px;
  }

  .chatThreadTitle,
  .conversationListPanel {
    display: none;
  }

  .chatThread {
    max-height: 150px;
    padding-bottom: 4px;
  }

  textarea {
    min-height: 112px;
    font-size: 16px;
  }

  .answer {
    border-radius: 6px;
    padding: 13px;
  }

  /* Let header row wrap so buttons don't get squashed */
  .answerHeader {
    flex-wrap: wrap;
    gap: 8px;
  }

  .answerTools {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .actions,
  .refineActions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .refineActions .mutedText {
    min-height: 18px;
  }

  /* Make action buttons a bit more touch-friendly */
  button {
    padding: 11px 13px;
  }

  .mobileHidden {
    display: none;
  }
}
