/* ── Mobile Session — Full-screen chat view ──────────────────────────── */
/* All styles scoped to #mobile-session-view or behind 768px media query */

/* ─── Container ─── */
#mobile-session-view {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--surface-0);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 300ms var(--ease-out);
  will-change: transform;
}
#mobile-session-view.open {
  transform: translateX(0);
}
#mobile-session-view.closing {
  transform: translateX(100%);
  transition: transform 250ms cubic-bezier(0.4, 0, 1, 1);
}

/* ─── Header ─── */
.ms-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: 44px;
  padding: 0 0.5rem;
  padding-top: env(safe-area-inset-top, 0px);
  min-height: calc(44px + env(safe-area-inset-top, 0px));
  background: var(--surface-0);
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
  z-index: 2;
}

.ms-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}
.ms-back:active {
  opacity: 0.5;
}
.ms-back svg {
  width: 20px;
  height: 20px;
}

.ms-header-center {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.ms-header-name {
  font-family: var(--font-sans);
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  letter-spacing: -0.01em;
}

.ms-header-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.ms-header-dot.green {
  background: var(--green);
  box-shadow: 0 0 6px rgba(52, 211, 153, 0.5);
  animation: ms-dot-pulse 2.5s ease-in-out infinite;
}
.ms-header-dot.amber {
  background: var(--amber);
  box-shadow: 0 0 4px rgba(251, 191, 36, 0.3);
}
.ms-header-dot.red {
  background: var(--red);
  box-shadow: 0 0 6px rgba(248, 113, 113, 0.5);
  animation: ms-dot-pulse 1.5s ease-in-out infinite;
}
.ms-header-dot.dim {
  background: var(--text-ghost);
}

@keyframes ms-dot-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.ms-info-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
  font-size: 18px;
}
.ms-info-btn:active {
  opacity: 0.5;
}

/* ─── Context gauge (below header) ─── */
.ms-header-ctx {
  height: 3px;
  background: rgba(255, 255, 255, 0.06);
  position: relative;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.ms-header-ctx-fill {
  height: 100%;
  transition: width 0.3s ease, background 0.3s ease;
  border-radius: 0 1.5px 1.5px 0;
}

/* ─── Pending message (optimistic) ─── */
.ms-turn-pending {
  opacity: 0.6;
}

/* ─── Transcript ─── */
.ms-transcript {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px;
  padding-bottom: calc(12px + var(--keyboard-height, 0px));
  overscroll-behavior-y: contain;
}

.ms-turn {
  margin-bottom: 0.75rem;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.65;
}
.ms-turn:last-child {
  margin-bottom: 0;
}

.ms-turn.user {
  background: rgba(34, 211, 238, 0.06);
  border-left: 3px solid var(--cyan);
}
.ms-turn.assistant {
  background: transparent;
  border-left: 3px solid var(--border-subtle);
}

.ms-turn-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.3rem;
}
.ms-turn-role {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-ghost);
}
.ms-turn.user .ms-turn-role {
  color: var(--cyan);
}
.ms-turn-time {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-ghost);
  opacity: 0.6;
}

.ms-turn-text {
  color: var(--text-secondary);
  word-break: break-word;
}
.ms-turn.user .ms-turn-text {
  color: var(--text-primary);
  font-weight: 500;
}

/* Markdown in transcript */
.ms-turn-text strong { color: var(--text-primary); font-weight: 600; }
.ms-turn-text code.md-inline {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: rgba(255, 255, 255, 0.08);
  padding: 0.12em 0.4em;
  border-radius: 4px;
  color: var(--text-primary);
}
.ms-turn-text pre.md-block {
  font-family: var(--font-mono);
  font-size: 14px;
  background: rgba(0, 0, 0, 0.4);
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  margin: 0.5rem 0;
  line-height: 1.55;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  white-space: pre;
  border: 1px solid var(--border-subtle);
}

/* Truncation */
.ms-turn .turn-preview { display: inline; }
.ms-turn .turn-full { display: none; }
.ms-turn.expanded .turn-preview { display: none; }
.ms-turn.expanded .turn-full { display: inline; }
.ms-turn .turn-expand {
  display: inline-block;
  margin-top: 0.4rem;
  font-size: 13px;
  color: var(--cyan);
  background: rgba(34, 211, 238, 0.08);
  border: none;
  border-radius: 20px;
  padding: 0.3rem 0.75rem;
  cursor: pointer;
  font-family: var(--font-sans);
  -webkit-tap-highlight-color: transparent;
}
.ms-turn .turn-expand:active {
  opacity: 0.6;
}

/* ─── Working indicator ─── */
.ms-working {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 12px 14px;
  color: var(--text-muted);
  font-size: 13px;
}
.ms-working-dots {
  display: flex;
  gap: 3px;
}
.ms-working-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: ms-typing 1.4s ease-in-out infinite;
}
.ms-working-dots span:nth-child(2) { animation-delay: 0.2s; }
.ms-working-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes ms-typing {
  0%, 60%, 100% { opacity: 0.2; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* ─── Inline approval card ─── */
.ms-approval {
  margin: 0.75rem 0;
  padding: 14px 16px;
  border-radius: 12px;
  border-left: 3px solid var(--amber);
  background: var(--amber-wash);
  border: 1px solid rgba(251, 191, 36, 0.15);
  border-left: 3px solid var(--amber);
}
.ms-approval-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--amber);
  margin-bottom: 0.4rem;
}
.ms-approval-detail {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-secondary);
  background: rgba(0, 0, 0, 0.2);
  padding: 0.5rem 0.7rem;
  border-radius: 6px;
  margin-bottom: 0.75rem;
  word-break: break-word;
}
.ms-approval-actions {
  display: flex;
  gap: 0.75rem;
}
.ms-approval-actions button {
  flex: 1;
  min-height: 44px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all 150ms ease;
}
.ms-approval-actions button:active {
  transform: scale(0.96);
}
.ms-approval-deny {
  background: transparent;
  border: 1px solid rgba(248, 113, 113, 0.3);
  color: var(--red);
}
.ms-approval-allow {
  background: var(--green);
  border: none;
  color: #000;
}
.ms-approval.resolved {
  opacity: 0.5;
  border-left-color: var(--text-ghost);
}
.ms-approval.resolved .ms-approval-actions button {
  pointer-events: none;
}

/* ─── Scroll pill ─── */
.ms-scroll-pill {
  position: absolute;
  bottom: calc(60px + var(--keyboard-height, 0px) + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--surface-3);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font-sans);
  padding: 0.4rem 0.9rem;
  border-radius: 20px;
  border: 1px solid var(--border-medium);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition: opacity 200ms ease, transform 200ms ease, visibility 200ms;
  z-index: 3;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}
.ms-scroll-pill.visible {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}
.ms-scroll-pill:active {
  transform: translateX(-50%) scale(0.95);
}

/* ─── Input bar ─── */
.ms-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 8px 12px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  background: var(--surface-0);
  border-top: 1px solid var(--glass-border);
  flex-shrink: 0;
  z-index: 2;
  /* Keyboard-aware offset */
  margin-bottom: var(--keyboard-height, 0px);
}

.ms-textarea {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  max-height: 120px;
  padding: 10px 14px;
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 16px; /* Prevents iOS zoom */
  line-height: 1.4;
  resize: none;
  outline: none;
  overflow-y: auto;
  transition: border-color 150ms ease;
}
.ms-textarea::placeholder {
  color: var(--text-ghost);
}
.ms-textarea:focus {
  border-color: var(--cyan);
}

.ms-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--cyan);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  margin-bottom: 2px;
  -webkit-tap-highlight-color: transparent;
  transform: scale(0.5);
  opacity: 0;
  transition: transform 150ms var(--ease-out), opacity 150ms ease;
  pointer-events: none;
}
.ms-send-btn.visible {
  transform: scale(1);
  opacity: 1;
  pointer-events: auto;
}
.ms-send-btn:active {
  transform: scale(0.9);
}
.ms-send-btn.sent {
  background: var(--green);
}
.ms-send-btn.failed {
  background: var(--red);
}
.ms-send-btn svg {
  width: 18px;
  height: 18px;
  color: #000;
}

/* ─── Empty state ─── */
.ms-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-ghost);
  font-size: 14px;
  font-style: italic;
}

/* ─── Bottom sheet ─── */
.ms-sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 110;
  opacity: 0;
  visibility: hidden;
  transition: opacity 250ms ease, visibility 250ms;
}
.ms-sheet-backdrop.open {
  opacity: 1;
  visibility: visible;
}

.ms-sheet-content {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 60vh;
  background: var(--surface-0);
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  border-top: 1px solid var(--glass-border);
  z-index: 111;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 20px 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateY(100%);
  transition: transform 250ms var(--ease-out);
}
.ms-sheet-backdrop.open + .ms-sheet-content,
.ms-sheet-content.open {
  transform: translateY(0);
}

.ms-sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--surface-3);
  margin: 12px auto 16px;
}

.ms-sheet-section {
  margin-bottom: 1.25rem;
}
.ms-sheet-section:last-child {
  margin-bottom: 0;
}
.ms-sheet-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-ghost);
  margin-bottom: 0.5rem;
}

.ms-sheet-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
}
.ms-sheet-tag {
  font-size: 12px;
  color: var(--text-ghost);
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
}

.ms-sheet-files {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.ms-sheet-file {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
  padding: 0.25rem 0.4rem;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ms-sheet-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}
.ms-sheet-tool {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  color: var(--text-ghost);
  white-space: nowrap;
}

.ms-sheet-stats {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.3rem 0.75rem;
  align-items: baseline;
}
.ms-sheet-stat-label {
  font-size: 12px;
  color: var(--text-ghost);
}
.ms-sheet-stat-val {
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--text-secondary);
}

/* Context gauge in sheet */
.ms-sheet-ctx {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.25rem;
}
.ms-sheet-ctx-bar {
  flex: 1;
  height: 6px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 3px;
  overflow: hidden;
}
.ms-sheet-ctx-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}
.ms-sheet-ctx-fill.green { background: var(--green); }
.ms-sheet-ctx-fill.amber { background: var(--amber); }
.ms-sheet-ctx-fill.red { background: var(--red); }
.ms-sheet-ctx-label {
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-ghost);
  flex-shrink: 0;
}

/* ─── Reduced motion ─── */
@media (prefers-reduced-motion: reduce) {
  #mobile-session-view,
  #mobile-session-view.closing,
  .ms-sheet-content,
  .ms-sheet-backdrop,
  .ms-scroll-pill,
  .ms-send-btn,
  .ms-working-dots span {
    transition-duration: 0ms !important;
    animation-duration: 0ms !important;
  }
}
