/* TiTi Core Chat UI — focus header, drawer, task cards, collapse, activity */

:root {
  --titi-focus-h: 52px;
  --titi-drawer-width: 82vw;
  --titi-collapse-dur: 180ms;
}

.titi-topbar-legacy-hidden .mobile-pane-toggle,
.titi-topbar-legacy-hidden .user-menu {
  display: none !important;
}

.titi-focus-header {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 4px;
  min-height: var(--titi-focus-h);
  padding: 6px 8px;
  padding-top: max(6px, env(safe-area-inset-top));
  background: var(--surface-elevated, #0f1419);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  position: sticky;
  top: 0;
  z-index: 120;
  transition: transform var(--titi-collapse-dur) ease, opacity var(--titi-collapse-dur) ease;
}

.titi-focus-header.focus,
.titi-focus-header.compact {
  min-height: 44px;
}

.titi-focus-header.focus .titi-focus-brand,
.titi-focus-header.compact .titi-focus-brand {
  font-size: 0.85rem;
}

.titi-focus-header.focus {
  transform: translateY(-2px);
  opacity: 0.92;
}

.titi-focus-menu,
.titi-focus-more {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  font-size: 1.15rem;
  cursor: pointer;
}

.titi-focus-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  border: none;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 12px;
  padding: 8px 12px;
  color: inherit;
  cursor: pointer;
  font-size: 0.9rem;
}

.titi-focus-brand {
  font-weight: 600;
  white-space: nowrap;
}

.titi-focus-project,
.titi-focus-mode {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 28vw;
}

.titi-focus-sep {
  opacity: 0.45;
}

.titi-focus-caret {
  opacity: 0.6;
  font-size: 0.7rem;
}

.titi-focus-dropdown {
  position: fixed;
  top: calc(var(--titi-focus-h) + 8px);
  left: 50%;
  transform: translateX(-50%);
  min-width: 240px;
  max-width: 92vw;
  background: var(--surface-elevated, #151b22);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 8px;
  z-index: 200;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.titi-focus-dropdown.hidden {
  display: none;
}

.titi-dropdown-section {
  padding: 6px 4px;
}

.titi-dropdown-section + .titi-dropdown-section {
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  margin-top: 4px;
}

.titi-dropdown-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: inherit;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.titi-dropdown-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

@media (min-width: 901px) {
  .titi-focus-header {
    border-radius: 12px;
    margin: 8px 12px 0;
    position: relative;
  }
}

/* Mobile drawer */
@media (max-width: 900px) {
  .titi-core-drawer.mobile-open {
    width: var(--titi-drawer-width) !important;
    max-width: 84vw;
  }

  body.titi-drawer-open::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 90;
  }
}

/* Revision pager */
.titi-revision-pager {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  opacity: 0;
  transition: opacity var(--titi-collapse-dur) ease;
}

.msg:hover .titi-revision-pager,
.msg:focus-within .titi-revision-pager,
.titi-revision-pager:focus-within {
  opacity: 1;
}

@media (max-width: 900px) {
  .titi-revision-pager {
    opacity: 1;
    font-size: 0.8rem;
  }
}

.titi-rev-btn {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  color: inherit;
  border-radius: 8px;
  min-width: 32px;
  height: 28px;
  cursor: pointer;
}

.titi-rev-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.titi-inline-editor {
  width: 100%;
  min-height: 72px;
  resize: vertical;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.2);
  color: inherit;
  padding: 8px 10px;
}

.titi-inline-editor-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

/* Collapse */
.titi-collapsible-msg.is-collapsed .titi-collapsible-inner,
.titi-collapsible-code.is-collapsed .titi-collapsible-code-inner {
  max-height: min(45vh, 420px);
  overflow: hidden;
  mask-image: linear-gradient(#000 75%, transparent);
  transition: max-height var(--titi-collapse-dur) ease;
}

.titi-collapsible-msg.is-expanded .titi-collapsible-inner,
.titi-collapsible-code.is-expanded .titi-collapsible-code-inner {
  max-height: none;
  mask-image: none;
}

.titi-collapse-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 10px auto 4px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
  color: inherit;
  cursor: pointer;
  font-size: 0.85rem;
}

.titi-collapsible-msg,
.titi-collapsible-code {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Master badge */
.titi-master-badge {
  display: inline-block;
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 6px;
  margin-right: 6px;
  border-radius: 4px;
  background: rgba(212, 175, 55, 0.12);
  color: #d4af37;
  border: 1px solid rgba(212, 175, 55, 0.25);
}

.titi-msg-sources {
  margin-top: 8px;
}

.titi-src-row {
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 0.85rem;
}

/* Task output card */
.titi-task-output-card {
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 12px 14px;
  margin: 8px 0;
  background: rgba(255, 255, 255, 0.03);
}

.titi-task-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.titi-task-title {
  margin: 0;
  font-size: 0.95rem;
  flex: 1;
}

.titi-task-spin {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  animation: titi-spin 0.8s linear infinite;
}

@keyframes titi-spin {
  to { transform: rotate(360deg); }
}

.titi-task-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}

.titi-chip {
  font-size: 0.72rem;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
}

.titi-task-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.titi-task-btn {
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: transparent;
  color: inherit;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.8rem;
  cursor: pointer;
}

/* Activity panel */
.titi-core-activity-panel {
  position: fixed;
  top: calc(var(--titi-focus-h) + 12px);
  right: 12px;
  width: min(320px, 28vw);
  max-height: 50vh;
  overflow: auto;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--surface-elevated, #121820);
  z-index: 110;
  padding: 10px;
}

.titi-core-activity-panel.hidden,
.titi-core-activity-sheet.hidden {
  display: none;
}

.titi-core-activity-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--composer-height, 100px) + env(safe-area-inset-bottom, 0px) + 8px);
  max-height: 38vh;
  border-radius: 16px 16px 0 0;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--surface-elevated, #121820);
  z-index: 115;
  padding: 8px 12px 12px;
  overflow: auto;
}

.titi-sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.2);
  margin: 4px auto 10px;
}

.titi-activity-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.titi-activity-close {
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 1rem;
}

.titi-activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.titi-activity-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 0.82rem;
}

.titi-activity-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  flex-shrink: 0;
}

.titi-activity-running .titi-activity-dot {
  background: #5b9cf5;
  animation: titi-pulse 1.2s ease infinite;
}

@keyframes titi-pulse {
  50% { opacity: 0.45; }
}

/* Composer safe area */
.composer[data-core-safe="1"] {
  position: sticky;
  bottom: 0;
  z-index: 100;
}
