/* ============ RESET ============ */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-feature-settings: 'cv11', 'ss01', 'ss03';
  background: #fafaf9;
  color: #1c1917;
  line-height: 1.55;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; }

/* ============ LAYOUT ============ */
.app {
  max-width: 820px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 0 1.25rem;
}

/* ============ HEADER ============ */
.hub-header {
  padding: 1.8rem 0 1.2rem;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}
.brand .logo {
  width: 42px; height: 42px;
  background: linear-gradient(135deg, #ff6b2c, #ff9557);
  border-radius: 12px;
  display: grid; place-items: center;
  font-size: 1.4rem;
  box-shadow: 0 4px 12px rgba(255, 107, 44, 0.25);
}
.brand .title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #0c0a09;
}
.brand .subtitle {
  font-size: 0.85rem;
  color: #78716c;
  margin-top: 2px;
}

/* ============ ADVISOR PICKER ============ */
.advisor-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
.advisor-card {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.85rem 1rem;
  background: #fff;
  border: 1.5px solid #e7e5e4;
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
}
.advisor-card:hover {
  border-color: #d6d3d1;
  background: #fafaf9;
}
.advisor-card.active {
  background: #fff;
  box-shadow: 0 0 0 2px var(--advisor-color, #ff6b2c), 0 4px 12px rgba(0,0,0,0.04);
  border-color: transparent;
}
.advisor-card .avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 2px solid #f5f5f4;
}
.advisor-card.active .avatar {
  border-color: var(--advisor-color, #ff6b2c);
}
.advisor-card .meta { flex: 1; min-width: 0; }
.advisor-card .name {
  font-weight: 600;
  font-size: 0.95rem;
  color: #1c1917;
  line-height: 1.2;
}
.advisor-card .tag {
  font-size: 0.78rem;
  color: #78716c;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.advisor-card .check {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 1.5px solid #d6d3d1;
  flex-shrink: 0;
  transition: all 0.15s ease;
}
.advisor-card.active .check {
  background: var(--advisor-color, #ff6b2c);
  border-color: var(--advisor-color, #ff6b2c);
  position: relative;
}
.advisor-card.active .check::after {
  content: '';
  position: absolute;
  top: 5px; left: 7px;
  width: 4px; height: 8px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* ============ CHAT ============ */
.chat {
  flex: 1;
  min-height: 300px;
  display: flex;
  flex-direction: column;
  position: relative;
}
.chat-empty {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  flex: 1;
  padding: 2rem 1rem;
  text-align: center;
}
.chat-empty.hidden { display: none; }
.chat-empty-icon { font-size: 2rem; margin-bottom: 0.5rem; opacity: 0.8; }
.chat-empty-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: #292524;
  margin-bottom: 0.3rem;
}
.chat-empty-hint {
  font-size: 0.9rem;
  color: #78716c;
  max-width: 400px;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  padding: 0.5rem 0 1.5rem;
}

.msg {
  display: flex;
  gap: 0.75rem;
  animation: slideIn 0.2s ease-out;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg .avatar-wrap {
  flex-shrink: 0;
  width: 32px; height: 32px;
  border-radius: 50%;
  overflow: hidden;
  background: #f5f5f4;
}
.msg .avatar-wrap img { width: 100%; height: 100%; object-fit: cover; }
.msg.user .avatar-wrap {
  background: #292524;
  color: #fff;
  display: grid; place-items: center;
  font-size: 0.8rem; font-weight: 600;
}

.msg .body {
  flex: 1;
  min-width: 0;
  max-width: calc(100% - 48px);
}
.msg .name {
  font-weight: 600;
  font-size: 0.86rem;
  color: #44403c;
  margin-bottom: 0.2rem;
}
.msg .content {
  color: #1c1917;
  font-size: 0.95rem;
  line-height: 1.62;
  word-wrap: break-word;
}
.msg .content > *:first-child { margin-top: 0; }
.msg .content > *:last-child { margin-bottom: 0; }
.msg .content p { margin: 0.6em 0; }
.msg .content h1, .msg .content h2, .msg .content h3 {
  margin: 1em 0 0.4em;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.msg .content h1 { font-size: 1.15rem; }
.msg .content h2 { font-size: 1.05rem; }
.msg .content h3 { font-size: 0.98rem; }
.msg .content ul, .msg .content ol {
  margin: 0.5em 0;
  padding-left: 1.3em;
}
.msg .content li { margin: 0.3em 0; }
.msg .content code {
  background: #f5f5f4;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.88em;
  font-family: ui-monospace, SFMono-Regular, monospace;
}
.msg .content pre {
  background: #1c1917;
  color: #f5f5f4;
  padding: 0.9rem 1rem;
  border-radius: 10px;
  overflow-x: auto;
  font-size: 0.85em;
}
.msg .content blockquote {
  border-left: 3px solid #e7e5e4;
  padding: 0.2em 0 0.2em 1em;
  margin: 0.6em 0;
  color: #57534e;
}
.msg .content a {
  color: var(--accent, #ff6b2c);
  text-decoration: none;
  border-bottom: 1px solid currentColor;
}
.msg .content a:hover { opacity: 0.75; }
.msg .content strong { font-weight: 600; color: #0c0a09; }
.msg .content hr {
  border: none;
  border-top: 1px solid #e7e5e4;
  margin: 1em 0;
}
/* Soft callout when the model spontaneously ends with an action item.
   Triggered by JS attaching .action-callout — only renders distinct when present. */
.msg .content .action-callout {
  background: #fff8f2;
  border-left: 3px solid var(--accent, #ff6b2c);
  padding: 0.6em 0.85em;
  border-radius: 0 8px 8px 0;
  margin-top: 0.9em;
}
.msg .content .action-callout strong:first-child {
  color: var(--accent, #ff6b2c);
}

.msg .status {
  color: #a8a29e;
  font-size: 0.85rem;
  font-style: italic;
}

/* ============ THINKING STEPS ============ */
.steps {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.7rem 0.9rem;
  background: #fafaf9;
  border: 1px solid #f0eeec;
  border-radius: 10px;
  margin-bottom: 0.7rem;
  font-size: 0.82rem;
}
.steps.collapsed {
  padding: 0.4rem 0.9rem;
  background: transparent;
  border: none;
}
.steps.collapsed .step.done {
  display: none;
}
.step {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: #78716c;
  transition: all 0.2s;
}
.step.done { color: #a8a29e; }
.step.active { color: #292524; font-weight: 500; }
.step-icon {
  width: 14px; height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.step.active .step-icon {
  position: relative;
}
.step.active .step-icon::after {
  content: '';
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent, #ff6b2c);
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(0.6); opacity: 0.5; }
  50% { transform: scale(1); opacity: 1; }
}
.step.done .step-icon::after {
  content: '';
  width: 10px; height: 6px;
  border: solid #22c55e;
  border-width: 0 0 1.8px 1.8px;
  transform: rotate(-45deg);
  margin-top: -2px;
}
.step-label { flex: 1; }
.step-detail {
  color: #a8a29e;
  font-size: 0.78rem;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

/* Blinking cursor while streaming */
.msg .content.streaming::after {
  content: '▋';
  color: var(--accent, #ff6b2c);
  margin-left: 2px;
  animation: blink 1s step-end infinite;
  font-weight: normal;
}
@keyframes blink { 50% { opacity: 0; } }
.msg .error {
  color: #b91c1c;
  background: #fef2f2;
  padding: 0.6em 0.9em;
  border-radius: 8px;
  font-size: 0.9rem;
  border: 1px solid #fecaca;
}

.msg .sources {
  margin-top: 0.6rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.msg .source-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  padding: 3px 8px;
  border-radius: 6px;
  background: #f5f5f4;
  color: #57534e;
  font-size: 0.75rem;
  text-decoration: none;
  transition: background 0.15s;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg .source-chip:hover { background: #e7e5e4; color: #1c1917; }

/* ============ SUGGESTIONS ============ */
.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0 0 1rem;
}
.suggestions.hidden { display: none; }
.suggest-chip {
  padding: 0.5rem 0.8rem;
  background: #fff;
  border: 1px solid #e7e5e4;
  border-radius: 999px;
  color: #57534e;
  font-size: 0.82rem;
  transition: all 0.15s;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.suggest-chip:hover {
  background: var(--accent-bg, #fff3ea);
  border-color: var(--accent, #ff6b2c);
  color: #1c1917;
}

/* ============ COMPOSER ============ */
.composer {
  position: sticky;
  bottom: 0;
  background: linear-gradient(180deg, transparent 0%, #fafaf9 20%);
  padding: 0.8rem 0 1rem;
}
.composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  background: #fff;
  border: 1.5px solid #e7e5e4;
  border-radius: 16px;
  padding: 0.65rem 0.65rem 0.65rem 1rem;
  transition: border-color 0.15s;
}
.composer-inner:focus-within {
  border-color: var(--accent, #ff6b2c);
  box-shadow: 0 0 0 3px var(--accent-bg, #fff3ea);
}

.composer textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-size: 0.95rem;
  font-family: inherit;
  line-height: 1.55;
  color: #1c1917;
  max-height: 180px;
  background: transparent;
  padding: 6px 0;
}
.composer textarea::placeholder { color: #a8a29e; }

.send-btn {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--accent, #ff6b2c);
  color: #fff;
  display: grid; place-items: center;
  transition: all 0.15s;
  flex-shrink: 0;
}
.send-btn:hover { transform: translateY(-1px); opacity: 0.95; }
.send-btn:disabled { background: #d6d3d1; cursor: not-allowed; transform: none; }

.composer-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.2rem 0;
  font-size: 0.75rem;
  color: #a8a29e;
  gap: 0.6rem;
}

/* Model picker — segmented pill */
.model-picker {
  display: inline-flex;
  background: #f5f5f4;
  border-radius: 999px;
  padding: 2px;
  gap: 1px;
}
.model-pill {
  border: none;
  background: transparent;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 500;
  color: #78716c;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: inherit;
}
.model-pill:hover { color: #44403c; }
.model-pill.active {
  background: #fff;
  color: #1c1917;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.model-pill .pill-icon { font-size: 0.85em; }
.model-pill .pill-sub {
  color: #a8a29e;
  font-size: 0.68rem;
  margin-left: 2px;
}
.model-pill.active .pill-sub { color: #78716c; }

.clear-btn {
  font-size: 0.75rem;
  color: #a8a29e;
  padding: 0.2em 0.5em;
  border-radius: 6px;
  transition: all 0.1s;
}
.clear-btn:hover { background: #f5f5f4; color: #57534e; }

@media (max-width: 540px) {
  .model-pill .pill-sub { display: none; }
  .composer-footer { flex-wrap: wrap; }
}

/* ============ RESPONSIVE ============ */
@media (max-width: 640px) {
  .app { padding: 0 1rem; }
  .advisor-picker { grid-template-columns: 1fr; }
  .hub-header { padding: 1.2rem 0 1rem; }
}
