:root {
  color-scheme: dark;
  font-family: Inter, system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #0b0f17;
  color: #f3f4f6;
}

a {
  color: #fbbf24;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.18);
}

.app-header h1 {
  margin: 0;
  font-size: 1.1rem;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.header-actions [hidden] {
  display: none !important;
}

.header-actions a,
.header-actions button,
button {
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(17, 24, 39, 0.9);
  color: #f9fafb;
  padding: 8px 12px;
  font-size: 0.9rem;
  cursor: pointer;
}

button.primary {
  background: #d97706;
  border-color: #d97706;
  color: #111827;
  font-weight: 600;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.borderless-main-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(360px, 1fr);
  gap: 12px;
  flex: 1 1 auto;
  min-height: 0;
  padding: 12px 16px 16px;
}

.borderless-center-panel,
.borderless-chat-panel {
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.borderless-hero h2 {
  margin: 0 0 0.25rem;
}

.borderless-hero p {
  margin: 0;
  max-width: 820px;
  color: #9ca3af;
}

.globe-root {
  flex: 1 1 auto;
  min-height: 0;
}

.borderless-chat-panel {
  border-left: 1px solid rgba(148, 163, 184, 0.18);
  padding-left: 10px;
  overflow: hidden;
}

.side-view {
  display: none;
  flex: 1 1 auto;
  min-height: 0;
  flex-direction: column;
  gap: 8px;
}

.side-view.is-active {
  display: flex;
}

.borderless-form-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-goals-field {
  flex: 0 0 auto;
}

.form-footer {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-footer .primary {
  width: 100%;
}

.form-examples {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-examples-note {
  margin: 0;
  font-size: 0.85rem;
  color: #9ca3af;
}

.form-field label {
  font-size: 0.85rem;
  color: #d1d5db;
}

.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(17, 24, 39, 0.9);
  color: #f9fafb;
  padding: 8px 10px;
  font: inherit;
}

.form-goals-field textarea {
  min-height: 84px;
  resize: vertical;
}

.form-field select.invalid,
.form-field textarea.invalid {
  border-color: #f87171;
}

.persona-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.persona-list button {
  width: 100%;
  font-size: 0.85rem;
  text-align: left;
}

.chat-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 4px;
}

.chat-message {
  border-radius: 10px;
  padding: 10px 12px;
  line-height: 1.45;
}

.chat-message-body {
  white-space: pre-wrap;
}

.chat-message.assistant .chat-message-body.markdown-body {
  white-space: normal;
}

.chat-message.user {
  background: rgba(59, 130, 246, 0.15);
  align-self: flex-end;
  max-width: 92%;
}

.chat-message.assistant {
  background: rgba(31, 41, 55, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.15);
}

.chat-message.tool {
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.25);
  font-size: 0.92rem;
}

.chat-message.tool.pending {
  opacity: 0.85;
}

.chat-message.tool .tool-title {
  font-weight: 600;
  color: #fbbf24;
  margin-bottom: 4px;
}

.chat-message.tool.thinking {
  background: rgba(79, 70, 229, 0.08);
  border-color: rgba(99, 102, 241, 0.28);
  font-style: normal;
  color: #e5e7eb;
  padding: 0;
  overflow: hidden;
}

.thinking-message-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #a5b4fc;
}

.thinking-message-header::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #818cf8;
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.15);
}

.thinking-message {
  padding: 8px 12px 12px;
}

.thinking-block-wrap {
  margin-bottom: 10px;
}

.thinking-block-wrap:last-child {
  margin-bottom: 0;
}

.thinking-block-label {
  margin-bottom: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #a5b4fc;
}

.thinking-block {
  background: rgba(79, 70, 229, 0.12);
  border-left: 3px solid #6366f1;
  border-radius: 4px 12px 12px 4px;
  padding: 12px 14px;
  font-size: 0.92rem;
  color: #c7d2fe;
  font-style: italic;
}

.thinking-block.markdown-body {
  white-space: normal;
  font-style: italic;
}

.thinking-block.markdown-body p,
.thinking-block.markdown-body li {
  color: #c7d2fe;
}

.thinking-block.markdown-body code {
  color: #e0e7ff;
  background: rgba(15, 23, 42, 0.35);
}

.assistant-message-content .thinking-block-wrap + .chat-message-body {
  margin-top: 4px;
}

.chat-message.assistant .assistant-message-content {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.chat-message.tool.thinking details.tool-log > summary {
  color: #cbd5e1;
}

.chat-message.tool details.tool-log {
  margin: 0;
}

.chat-message.tool details.tool-log > summary {
  cursor: pointer;
  font-weight: 600;
  color: #fbbf24;
  list-style-position: outside;
}

.chat-message.tool .tool-summary-text {
  margin-top: 6px;
  white-space: pre-wrap;
  color: #e5e7eb;
  font-style: normal;
}

.chat-message.tool.thinking .tool-summary-text {
  color: #d1d5db;
  font-style: italic;
}

.chat-message.tool .tool-log-section {
  margin-top: 10px;
}

.chat-message.tool .tool-log-section strong {
  display: block;
  margin-bottom: 4px;
  font-size: 0.8rem;
  color: #9ca3af;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chat-message.tool .tool-log-section pre {
  margin: 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.15);
  overflow-x: auto;
  font-size: 0.78rem;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  font-style: normal;
  color: #e5e7eb;
}

.tool-log-compact > summary.tool-compact-summary {
  color: #fbbf24;
  font-weight: 600;
}

.tool-compact-detail {
  margin-top: 4px;
  font-size: 0.82rem;
  line-height: 1.4;
  color: #9ca3af;
  white-space: pre-wrap;
}

details.tool-log-raw {
  margin-top: 8px;
}

details.tool-log-raw > summary {
  cursor: pointer;
  font-size: 0.75rem;
  color: #6b7280;
}

.plan-message > summary {
  color: #fbbf24;
  font-weight: 700;
}

.plan-todo-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.plan-todo-item {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  background: rgba(15, 23, 42, 0.55);
}

.plan-todo-country {
  font-weight: 700;
  color: #f9fafb;
  font-size: 0.9rem;
  line-height: 1.3;
}

.plan-todo-methods {
  margin-top: 3px;
  font-size: 0.8rem;
  line-height: 1.35;
  color: #9ca3af;
}

.markdown-body > :first-child {
  margin-top: 0;
}

.markdown-body > :last-child {
  margin-bottom: 0;
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body pre,
.markdown-body blockquote,
.markdown-body table {
  margin: 0.65em 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  margin: 0.9em 0 0.45em;
  line-height: 1.3;
  color: #f9fafb;
}

.markdown-body h1 {
  font-size: 1.2rem;
}

.markdown-body h2 {
  font-size: 1.1rem;
}

.markdown-body h3,
.markdown-body h4 {
  font-size: 1rem;
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 1.25rem;
}

.markdown-body li + li {
  margin-top: 0.25em;
}

.markdown-body a {
  color: #fbbf24;
  text-decoration: underline;
}

.markdown-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.9em;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 4px;
  padding: 0.1em 0.35em;
}

.markdown-body pre {
  overflow-x: auto;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 8px;
  padding: 10px 12px;
}

.markdown-body pre code {
  background: none;
  border: 0;
  padding: 0;
}

.markdown-body blockquote {
  border-left: 3px solid rgba(245, 158, 11, 0.45);
  padding-left: 12px;
  color: #d1d5db;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid rgba(148, 163, 184, 0.22);
  padding: 6px 8px;
  text-align: left;
}

.markdown-body hr {
  border: 0;
  border-top: 1px solid rgba(148, 163, 184, 0.25);
  margin: 1em 0;
}

.markdown-body strong {
  color: #f9fafb;
  font-weight: 600;
}

.markdown-body em {
  color: #e5e7eb;
}

.markdown-body img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

.chat-message.tool .tool-summary-text.markdown-body {
  white-space: normal;
  font-style: normal;
  color: #e5e7eb;
}

.chat-message.tool .tool-summary-text.markdown-body p {
  margin: 0.45em 0;
}

.research-carousel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: rgba(17, 24, 39, 0.94);
  border: 1px solid rgba(245, 158, 11, 0.28);
}

.research-carousel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.research-carousel-title {
  font-weight: 700;
  color: #fbbf24;
}

.research-carousel-progress {
  flex: 0 0 auto;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: rgba(15, 23, 42, 0.75);
  color: #d1d5db;
  padding: 3px 8px;
  font-size: 0.75rem;
}

.research-carousel-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.research-carousel-tab {
  flex: 0 0 min(180px, 42%);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 8px 10px;
  border-radius: 10px;
  border-color: rgba(148, 163, 184, 0.24);
  background: rgba(15, 23, 42, 0.82);
  color: #e5e7eb;
  text-align: left;
  line-height: 1.25;
}

.research-carousel-tab-title {
  font-weight: 700;
  font-size: 0.88rem;
  color: #f9fafb;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.research-carousel-tab-subtitle {
  font-size: 0.74rem;
  line-height: 1.3;
  color: #9ca3af;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.research-carousel-tab::before {
  content: "";
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: #fbbf24;
  box-shadow: 0 0 12px rgba(251, 191, 36, 0.35);
}

.research-carousel-tab[data-status="done"]::before {
  background: #34d399;
  box-shadow: 0 0 12px rgba(52, 211, 153, 0.35);
}

.research-carousel-tab[data-status="running"]::before {
  background: #60a5fa;
  box-shadow: 0 0 12px rgba(96, 165, 250, 0.35);
}

.research-carousel-tab.is-active {
  border-color: #f59e0b;
  background: rgba(245, 158, 11, 0.16);
  color: #f9fafb;
}

.research-carousel-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: min(42vh, 360px);
  overflow-y: auto;
  overscroll-behavior: contain;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  background: rgba(2, 6, 23, 0.28);
  padding: 10px;
}

.research-carousel-active-status {
  color: #9ca3af;
  font-size: 0.8rem;
}

.research-event {
  border-radius: 9px;
  border: 1px solid rgba(148, 163, 184, 0.14);
  background: rgba(15, 23, 42, 0.62);
  padding: 8px 10px;
}

.research-event.pending {
  opacity: 0.82;
}

.research-event details.tool-log-compact > summary {
  cursor: default;
  color: #fbbf24;
  font-weight: 600;
}

.research-event .tool-compact-detail {
  color: #cbd5e1;
}

.research-event details.tool-log-raw > summary {
  cursor: pointer;
  color: #6b7280;
  font-weight: 500;
  font-size: 0.75rem;
}

.research-event .tool-log-section {
  margin-top: 8px;
}

.research-event .tool-log-section strong {
  display: block;
  margin-bottom: 4px;
  color: #9ca3af;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.research-event .tool-log-section pre {
  margin: 0;
  padding: 8px;
  max-height: 220px;
  overflow: auto;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  background: rgba(2, 6, 23, 0.5);
  color: #e5e7eb;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.78rem;
}

.research-event .chat-message-body {
  white-space: normal;
}

.chat-input-row {
  display: flex;
  gap: 8px;
}

.chat-input-row textarea {
  flex: 1 1 auto;
  min-height: 72px;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(17, 24, 39, 0.9);
  color: #f9fafb;
  padding: 10px;
  font: inherit;
  resize: vertical;
}

.status-banner {
  display: none;
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: #fde68a;
  font-size: 0.9rem;
}

.status-banner.visible {
  display: block;
}

.history-dialog {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.history-dialog[hidden] {
  display: none !important;
}

.history-dialog-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
}

.history-dialog-panel {
  position: relative;
  width: min(480px, 100%);
  max-height: min(70vh, 560px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: #111827;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.45);
  padding: 16px;
}

.history-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.history-dialog-header h3 {
  margin: 0;
  font-size: 1rem;
}

.history-dialog-close {
  font-size: 0.85rem;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  min-height: 0;
}

.history-list-empty {
  margin: 0;
  padding: 12px 0;
  color: #9ca3af;
  font-size: 0.9rem;
}

.history-item-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(17, 24, 39, 0.9);
}

.history-item-row.is-active {
  border-color: #f59e0b;
  background: rgba(245, 158, 11, 0.08);
}

.history-item-main {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  flex: 1;
  min-width: 0;
  text-align: left;
  padding: 10px 12px;
  border: none;
  background: transparent;
  color: inherit;
}

.history-item-main:hover {
  background: rgba(148, 163, 184, 0.08);
}

.history-item-actions {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  flex-shrink: 0;
  padding: 6px 8px 6px 0;
}

.history-item-action {
  font-size: 0.75rem;
  padding: 4px 8px;
  white-space: nowrap;
}

.history-item-action-delete {
  color: #fca5a5;
  border-color: rgba(248, 113, 113, 0.35);
}

.history-item-action-delete:hover {
  background: rgba(248, 113, 113, 0.12);
}

.history-item-title {
  font-weight: 600;
  color: #f9fafb;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item-meta {
  font-size: 0.8rem;
  color: #9ca3af;
}

.history-item-rename-input {
  width: 100%;
  font-weight: 600;
  font-size: inherit;
  font-family: inherit;
  color: #f9fafb;
  background: rgba(2, 6, 23, 0.6);
  border: 1px solid rgba(245, 158, 11, 0.5);
  border-radius: 4px;
  padding: 2px 6px;
}

@media (max-width: 900px) {
  .app-shell {
    height: auto;
    overflow: auto;
  }

  .borderless-main-workspace {
    grid-template-columns: 1fr;
  }

  .borderless-center-panel,
  .borderless-chat-panel {
    height: auto;
    min-height: 50vh;
  }

  .borderless-chat-panel {
    border-left: 0;
    padding-left: 0;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .form-goals-field textarea {
    min-height: 88px;
    height: 88px;
    resize: vertical;
  }

  .persona-list {
    grid-template-columns: 1fr;
  }
}
