* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  background: #f4f6f8;
  color: #172033;
}

button,
textarea {
  font: inherit;
}

.app {
  min-height: 100vh;
  max-width: 980px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  background: #fff;
  border-left: 1px solid #d9e0ea;
  border-right: 1px solid #d9e0ea;
}

.topbar {
  min-height: 86px;
  padding: 18px 22px;
  border-bottom: 1px solid #d9e0ea;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 750;
}

p {
  margin: 6px 0 0;
  color: #667085;
}

button {
  border: 1px solid #c9d3e1;
  background: #fff;
  color: #172033;
  border-radius: 7px;
  padding: 9px 13px;
  cursor: pointer;
  font-weight: 650;
}

button:hover {
  background: #f0f4f8;
}

button:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.messages {
  min-height: 0;
  padding: 24px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.message {
  max-width: min(760px, 88%);
  white-space: pre-wrap;
  line-height: 1.65;
}

.message-body {
  border: 1px solid #dde4ee;
  border-radius: 8px;
  padding: 13px 15px;
}

.message.user {
  align-self: flex-end;
}

.message.user .message-body {
  background: #eaf2ff;
  border-color: #bfd4f7;
}

.message.assistant {
  align-self: flex-start;
}

.message.assistant .message-body {
  background: #fff;
}

.status {
  align-self: flex-start;
  color: #667085;
  font-size: 14px;
  padding: 4px 2px;
}

.suggestions {
  padding: 0 18px 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  border-top: 1px solid #edf1f5;
}

.suggestions button {
  font-size: 14px;
  font-weight: 600;
}

.composer {
  border-top: 1px solid #e2e8f0;
  padding: 16px 20px;
  background: #ffffff;
}

.textarea-wrapper {
  position: relative;
  width: 100%;
}

textarea {
  width: 100%;
  min-height: 80px;
  max-height: 180px;
  resize: none;
  border: 1.5px solid #e2e8f0;
  border-radius: 16px;
  padding: 14px 60px 14px 16px;
  line-height: 1.5;
  font-size: 14.5px;
  background: #f8fafc;
  outline: none;
  transition: all 0.2s ease;
  display: block;
}

textarea:focus {
  border-color: #1d4ed8;
  background: #ffffff;
  box-shadow: 0 0 0 4px rgba(29, 78, 216, 0.1), 0 4px 12px rgba(15, 23, 42, 0.04);
}

.btn-send-client {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #1d4ed8;
  border: none;
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  box-shadow: 0 4px 10px rgba(29, 78, 216, 0.2);
}

.btn-send-client:hover:not(:disabled) {
  background: #1e40af;
  transform: scale(1.05);
}

.btn-send-client:active:not(:disabled) {
  transform: scale(0.95);
}

.btn-send-client:disabled {
  background: #cbd5e1;
  color: #94a3b8;
  box-shadow: none;
  cursor: not-allowed;
}

.btn-send-client .send-btn-text {
  display: none;
}

@media (max-width: 720px) {
  .app {
    border: 0;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .messages {
    padding: 18px;
  }

  .message {
    max-width: 96%;
  }

  .composer {
    grid-template-columns: 1fr;
  }
}

/* Helper classes to bypass CSP */
.flex-row-center-gap8 {
  display: flex;
  gap: 8px;
  align-items: center;
}

.text-no-decoration {
  text-decoration: none;
}

.btn-secondary {
  border-color: #cbd5e1 !important;
  color: #475569 !important;
}

/* Session footer styling */
.session-footer {
  text-align: center;
  padding: 8px 20px;
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
  font-size: 12.5px;
  color: #64748b;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
}

.copy-session-btn {
  padding: 3px 8px;
  font-size: 11px;
  border-radius: 4px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  cursor: pointer;
  color: #475569;
  transition: all 0.15s ease;
  font-weight: 500;
}

.copy-session-btn:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
  color: #0f172a;
}

/* New session top header button */
.btn-new-session {
  padding: 5px 12px;
  font-size: 13.0px;
  font-weight: 600;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #1e293b;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
  align-self: center;
  white-space: nowrap;
}

.btn-new-session:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
  color: #0f172a;
}

.btn-new-session .plus-icon {
  font-size: 14px;
  font-weight: 700;
  color: #dc2626;
}

/* CSP-safe header layout */
.title-container {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: nowrap;
}

.title-nowrap {
  white-space: nowrap;
  margin: 0;
}

/* Modals & Overlays for index.html */
.overlay-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.3);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.overlay-modal.hidden {
  display: none !important;
}

.modal-content {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  width: 100%;
  max-width: 720px;
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  max-height: 85vh;
  box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.15), 0 0 0 1px rgba(15, 23, 42, 0.05);
  padding: 24px;
}

/* Timeline/Trace Panel */
.trace-timeline {
  position: relative;
  padding-left: 20px;
}

.trace-timeline::before {
  content: '';
  position: absolute;
  left: 4px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: #dde4ee;
}

.trace-node {
  position: relative;
  padding-bottom: 18px;
}

.trace-node::before {
  content: '';
  position: absolute;
  left: -20px;
  top: 6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #dde4ee;
  border: 2px solid #ffffff;
  transition: all 0.2s;
}

.trace-node.succeeded::before { background: #22c55e; box-shadow: 0 0 6px #22c55e; }
.trace-node.failed::before { background: #ef4444; box-shadow: 0 0 6px #ef4444; }
.trace-node.running::before { background: #f59e0b; box-shadow: 0 0 6px #f59e0b; }

.trace-header {
  font-size: 12.5px;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.trace-time {
  color: #667085;
  font-weight: normal;
  font-size: 10.5px;
}

.trace-msg {
  font-size: 12px;
  color: #475569;
  margin-top: 4px;
  line-height: 1.5;
}

.trace-payload-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

.trace-payload-toggle,
.trace-payload-copy {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  color: #475569;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 8px;
  cursor: pointer;
  text-decoration: none !important;
  transition: all 0.15s ease;
  line-height: 1.2;
}

.trace-payload-toggle:hover {
  background: #e2e8f0;
  color: #0f172a;
  border-color: #cbd5e1;
}

.trace-payload-copy {
  color: #64748b;
}

.trace-payload-copy:hover {
  background: #e2e8f0;
  color: #0f172a;
  border-color: #cbd5e1;
}

.trace-payload-copy svg {
  opacity: 0.7;
  transition: opacity 0.15s ease;
}

.trace-payload-copy:hover svg {
  opacity: 1;
}

.trace-payload {
  display: none;
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 8px;
  padding: 12px;
  font-family: 'Consolas', monospace;
  font-size: 11px;
  margin-top: 8px;
  overflow-x: auto;
  white-space: pre-wrap;
  color: #cbd5e1;
  line-height: 1.5;
}

.trace-modal-trigger {
  cursor: pointer;
  text-decoration: underline;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 1px solid #edf2f7;
  padding-bottom: 16px;
  margin-bottom: 20px;
  gap: 16px;
}

.modal-title-wrapper {
  min-width: 0;
  flex: 1;
}

.modal-title {
  font-size: 18px;
  font-weight: 750;
  margin: 0;
  color: #0f172a;
  line-height: 1.3;
}

.modal-subtitle {
  font-size: 12px;
  color: #64748b;
  margin-top: 6px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  word-break: break-all;
}

#traceSessionValue {
  font-family: monospace;
  color: #334155;
  background: #f1f5f9;
  padding: 1px 4px;
  border-radius: 4px;
  font-size: 11px;
}

.copy-session-btn-icon {
  background: none;
  border: none;
  color: #64748b;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  text-decoration: underline;
  transition: color 0.15s ease;
  flex-shrink: 0;
}

.copy-session-btn-icon:hover {
  color: #1d4ed8;
}

#closeTraceModalBtn {
  flex-shrink: 0;
}

.modal-body {
  max-height: 480px;
  overflow-y: auto;
  padding-right: 4px;
}

/* Global hidden helper */
.hidden {
  display: none !important;
}

/* Low-key header Trace button next to new session */
.btn-header-trace {
  padding: 5px 10px;
  font-size: 12.5px;
  font-weight: 600;
  border-radius: 6px;
  border: 1px dashed #cbd5e1;
  background: #f8fafc;
  color: #64748b;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  transition: all 0.15s ease;
  align-self: center;
  white-space: nowrap;
}

.btn-header-trace:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
  color: #1e293b;
}

.btn-header-trace.hidden {
  display: none !important;
}

/* Mobile responsive style overrides */
@media (max-width: 600px) {
  .overlay-modal {
    padding: 12px;
  }

  .modal-content {
    border-radius: 16px;
    padding: 16px;
    max-height: 90vh;
  }

  .modal-header {
    margin-bottom: 14px;
    padding-bottom: 12px;
    gap: 8px;
  }

  .modal-title {
    font-size: 16px;
  }

  .modal-body {
    max-height: calc(90vh - 120px);
  }

  .trace-timeline {
    padding-left: 16px;
  }

  .trace-node::before {
    left: -16px;
  }

  .trace-payload-actions {
    flex-wrap: wrap;
    gap: 6px;
  }
}





