:root {
  --bg: #f4f1ec;
  --surface: #ffffff;
  --border: #e2ddd4;
  --text: #1c1917;
  --text-muted: #78716c;
  --accent: #0f766e;
  --accent-hover: #0d9488;
  --user-bubble: #0f766e;
  --user-text: #f0fdfa;
  --assistant-bubble: #ffffff;
  --shadow: 0 8px 30px rgba(28, 25, 23, 0.08);
  --radius: 16px;
  --font: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  font-family: var(--font);
  background:
    radial-gradient(circle at top left, rgba(15, 118, 110, 0.08), transparent 40%),
    var(--bg);
  color: var(--text);
}

body.modal-open {
  overflow: hidden;
}

.app {
  display: flex;
  gap: 1rem;
  height: 100vh;
  max-width: 1080px;
  margin: 0 auto;
  padding: 1rem;
}

.side-panel {
  width: 240px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  overflow-y: auto;
}

.state-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.state-section h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.state-section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}

.state-section-header .state-hint {
  margin-top: 0.15rem;
}

.state-hint {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.state-slots {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.state-slots .slot {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.state-slots dt {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.state-slots dd {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.4;
  color: var(--text);
}

.state-slots dd.pending {
  color: var(--text-muted);
  font-style: italic;
}

.state-slots dd.success {
  color: var(--accent);
  font-weight: 600;
}

.chat-pane {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  min-height: 0;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.header h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.header p {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.btn-new-chat {
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}

.btn-new-chat:hover {
  background: var(--accent);
  color: #fff;
}

.messages {
  flex: 1;
  overflow-y: auto;
  margin: 1rem 0;
  padding: 0.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.empty-state {
  margin: auto;
  text-align: center;
  max-width: 420px;
  color: var(--text-muted);
}

.empty-state h2 {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
  color: var(--text);
}

.empty-state p {
  margin: 0;
  line-height: 1.5;
}

.message {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  animation: fade-in 0.2s ease;
}

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

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

.message-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.message.user .message-label {
  text-align: right;
}

.bubble {
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble.markdown {
  white-space: normal;
}

.bubble.markdown p {
  margin: 0 0 0.75em;
}

.bubble.markdown p:last-child {
  margin-bottom: 0;
}

.bubble.markdown ul,
.bubble.markdown ol {
  margin: 0.25em 0 0.75em;
  padding-left: 1.25rem;
}

.bubble.markdown li {
  margin: 0.25em 0;
}

.bubble.markdown strong {
  font-weight: 600;
}

.bubble.markdown h1,
.bubble.markdown h2,
.bubble.markdown h3 {
  margin: 0 0 0.5em;
  font-size: 1em;
  font-weight: 600;
}

.message.user .bubble {
  background: var(--user-bubble);
  color: var(--user-text);
  border-bottom-right-radius: 4px;
}

.message.assistant .bubble {
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-bottom-left-radius: 4px;
}

.bubble.error {
  border-color: #fecaca;
  background: #fef2f2;
  color: #991b1b;
}

.quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.65rem;
}

.list-selection {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.65rem;
}

.list-selection-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.list-selection-item:hover:not(:disabled) {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(15, 118, 110, 0.12);
}

.list-selection-title {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
}

.list-selection-description {
  font-size: 0.82rem;
  line-height: 1.4;
  color: var(--text-muted);
}

.list-selection-item:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.quick-answers {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.65rem;
}

.quick-answer-btn {
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  border-radius: 999px;
  padding: 0.5rem 0.9rem;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, opacity 0.15s ease;
  text-align: left;
}

.quick-answer-btn:hover:not(:disabled) {
  background: var(--accent);
  color: #fff;
}

.quick-answer-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.composer.locked {
  opacity: 0.55;
  pointer-events: none;
}

.bubble.typing::after {
  content: "▋";
  display: inline-block;
  margin-left: 2px;
  animation: blink 1s step-end infinite;
}

.composer {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  padding: 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.composer textarea {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  font: inherit;
  line-height: 1.45;
  min-height: 24px;
  max-height: 160px;
  background: transparent;
  color: var(--text);
}

.composer textarea::placeholder {
  color: #a8a29e;
}

.btn-primary {
  border: none;
  background: var(--accent);
  color: white;
  border-radius: 999px;
  padding: 0.65rem 1.1rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-secondary {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 0.55rem 0.95rem;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-secondary:hover:not(:disabled) {
  background: #fafaf9;
  border-color: #d6d3d1;
}

.btn-secondary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-icon {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  border-radius: 8px;
  width: 2rem;
  height: 2rem;
  padding: 0;
  font: inherit;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.btn-icon:hover {
  background: #fafaf9;
  color: var(--accent);
  border-color: #d6d3d1;
}

.config-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.config-modal[hidden] {
  display: none !important;
}

.config-modal-backdrop {
  position: absolute;
  inset: 0;
  border: none;
  padding: 0;
  margin: 0;
  background: rgba(28, 25, 23, 0.45);
  cursor: pointer;
}

.config-modal-panel {
  position: relative;
  z-index: 1;
  width: min(720px, 100%);
  max-height: min(85vh, 760px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.config-modal-content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 0;
  height: 100%;
  margin: 0;
  padding: 1.25rem;
}

.config-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-shrink: 0;
}

.config-modal-header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.config-modal-hint {
  margin: 0.35rem 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.config-modal-hint code {
  font-size: 0.78rem;
}

.config-question-list {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  overflow-y: auto;
  padding-right: 0.15rem;
  min-height: 0;
  flex: 1;
}

.config-question-card {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fafaf9;
}

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

.config-question-card-header strong {
  font-size: 0.82rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.config-question-card-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.btn-reorder {
  width: 1.85rem;
  height: 1.85rem;
  font-size: 0.95rem;
}

.btn-reorder:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.config-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.config-field label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.config-field input,
.config-field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  font: inherit;
  font-size: 0.88rem;
  color: var(--text);
  background: var(--surface);
  box-sizing: border-box;
}

.config-field textarea {
  resize: vertical;
  min-height: 4.5rem;
  line-height: 1.45;
}

.config-field input:focus,
.config-field textarea:focus {
  outline: 2px solid rgba(15, 118, 110, 0.2);
  border-color: var(--accent);
}

.config-error {
  margin: 0;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  font-size: 0.84rem;
  line-height: 1.4;
  flex-shrink: 0;
}

.config-modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.config-modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
}

.config-modal button {
  font: inherit;
  -webkit-appearance: none;
  appearance: none;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@media (max-width: 860px) {
  .app {
    flex-direction: column;
    max-width: 760px;
  }

  .side-panel {
    width: 100%;
    max-height: 260px;
    flex-direction: row;
  }

  .state-section {
    flex: 1;
    min-width: 0;
  }
}

@media (max-width: 560px) {
  .app {
    padding: 0.75rem;
    height: 100dvh;
  }

  .message {
    max-width: 92%;
  }
}
