/* A persistent profile page inside the application main pane.
   The existing identity/portrait fields retain their IDs and event hooks. */
.app-shell.mode-profile {
  grid-template-columns: 64px minmax(0, 1fr);
}
.app-shell.mode-profile .sidebar,
.app-shell.mode-profile .assistant-screen,
.app-shell.mode-profile .route-screen,
.app-shell.mode-profile .empty-state,
.app-shell.mode-profile .chat {
  display: none !important;
}
.app-shell:not(.mode-profile) .profile-screen,
.profile-screen[hidden] {
  display: none !important;
}
.app-shell.mode-profile .main {
  display: block;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: var(--surface, #ffffff);
}
.rail-profile.active {
  border-color: var(--accent, #3d36ed);
  background: var(--surface, #ffffff);
  box-shadow: 0 0 0 3px #3d36ed14;
}
.rail-profile.active:hover { border-color: var(--accent, #3d36ed); }

.profile-screen {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--surface, #ffffff);
  color: var(--ink, #17181b);
  color-scheme: light;
}
.profile-page-header {
  flex: none;
  min-width: 0;
  padding: 32px 28px 24px;
  border-bottom: 1px solid var(--line, #e3e4e8);
}
.profile-page-header h1 {
  margin: 0;
  color: var(--ink, #17181b);
  font-size: 34px;
  font-weight: 750;
  line-height: 1.2;
  letter-spacing: -.05em;
  outline: none;
}
.profile-page-header p {
  max-width: 48em;
  margin: 12px 0 0;
  color: var(--muted, #71747c);
  font-size: 14px;
  line-height: 1.8;
}
.profile-page-content {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  padding: 28px;
  background: var(--surface-soft, #f8f8fa);
  overscroll-behavior: contain;
  scroll-padding-block: 24px;
}
.profile-page-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  gap: 20px;
  min-width: 0;
}
.profile-page-card {
  min-width: 0;
  padding: 24px;
  border: 1px solid var(--line, #e3e4e8);
  border-radius: var(--radius-card, 24px);
  background: var(--surface, #ffffff);
  color: var(--ink, #17181b);
}
.profile-page-card h2 {
  margin: 0 0 20px;
  color: var(--ink, #17181b);
  font-size: 20px;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: -.025em;
}
.profile-section-note {
  margin: -8px 0 20px;
  color: var(--muted, #71747c);
  font-size: 13px;
  line-height: 1.8;
}
.profile-personal-card {
  display: flex;
  flex-direction: column;
  align-self: stretch;
}
.profile-screen .profile-persona {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  margin: 0;
  padding: 16px;
  border: 1px solid var(--line, #e3e4e8);
  border-radius: 20px;
  background: var(--surface-soft, #f8f8fa);
}
.profile-screen .profile-persona-art {
  width: 104px;
  height: 112px;
  flex: none;
  border-radius: 18px;
  background: var(--surface-raised, #f4f4f6);
  color: var(--accent, #3d36ed);
  font-size: 36px;
  line-height: 1;
}
.profile-screen .profile-persona-art img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.profile-screen .profile-persona-copy {
  flex: 1 1 120px;
  min-width: 0;
  gap: 8px;
}
.profile-screen .profile-persona-copy strong {
  color: var(--ink, #17181b);
  font-size: 16px;
  line-height: 1.5;
}
.profile-screen .profile-persona-copy small {
  color: var(--muted, #71747c);
  font-size: 14px;
  line-height: 1.6;
}
.profile-screen .profile-persona button {
  min-width: 88px;
  min-height: 44px;
  margin-left: auto;
  padding: 10px 14px;
  border: 1px solid var(--line, #e3e4e8);
  border-radius: var(--radius-control, 14px);
  background: var(--surface, #ffffff);
  color: var(--ink, #17181b);
  font-size: 13px;
  line-height: 1.5;
}
.profile-screen .profile-persona button:hover { border-color: var(--accent, #3d36ed); }
.profile-screen .profile-avatar-upload {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 18px;
  margin: 24px 0 0;
  padding: 24px 0 0;
  border: 0;
  border-top: 1px solid var(--line, #e3e4e8);
  border-radius: 0;
}
.profile-screen .profile-avatar-preview {
  width: 104px;
  height: 104px;
  flex: none;
  border: 1px solid var(--line, #e3e4e8);
  border-radius: 50%;
  background: var(--surface-raised, #f4f4f6);
  color: var(--accent, #3d36ed);
  font-size: 30px;
}
.profile-screen .profile-avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.profile-screen .profile-avatar-preview.has-upload img { object-fit: cover; }
.profile-screen .profile-avatar-actions { flex: 1 1 160px; min-width: 0; gap: 8px; }
.profile-screen .profile-avatar-actions strong {
  color: var(--ink, #17181b);
  font-size: 16px;
  line-height: 1.5;
}
.profile-screen .profile-avatar-actions small {
  color: var(--muted, #71747c);
  font-size: 12px;
  line-height: 1.7;
}
.profile-screen .profile-avatar-actions > div { gap: 8px; margin-top: 6px; }
.profile-screen .profile-avatar-actions button { min-height: 44px; font-size: 13px; }
.profile-screen .avatar-remove {
  padding: 10px 8px;
  border-radius: 10px;
  color: var(--muted, #71747c);
  line-height: 1.5;
}
.profile-screen .avatar-remove:hover { color: var(--ink, #17181b); background: var(--surface-soft, #f8f8fa); }
.profile-screen .identity-box {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line, #e3e4e8);
  border-radius: var(--radius-control, 14px);
  background: var(--surface-soft, #f8f8fa);
  color: var(--ink, #17181b);
}
.profile-screen .identity-box code {
  flex: 1 1 150px;
  min-width: 0;
  color: var(--ink, #17181b);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  line-height: 1.6;
  white-space: normal;
  overflow-wrap: anywhere;
}
.profile-screen .small-button {
  min-width: 44px;
  min-height: 44px;
  padding: 10px 13px;
  border: 1px solid var(--line, #e3e4e8);
  border-radius: var(--radius-control, 14px);
  background: var(--surface, #ffffff);
  color: var(--ink, #17181b);
  font-size: 13px;
  line-height: 1.5;
}
.profile-screen .small-button:hover { border-color: var(--accent, #3d36ed); }
.profile-screen .field-label {
  display: block;
  margin: 0 0 9px;
  color: var(--ink, #17181b);
  font-size: 13px;
  font-weight: 650;
  line-height: 1.5;
}
.profile-screen .modal-input {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 48px;
  height: auto;
  padding: 11px 14px;
  border: 1px solid var(--line, #e3e4e8);
  border-radius: var(--radius-control, 14px);
  background: var(--surface, #ffffff);
  color: var(--ink, #17181b);
  font-size: 16px;
  line-height: 1.5;
}
.profile-screen .modal-input::placeholder { color: var(--muted, #71747c); }
.profile-screen .modal-input:focus { border-color: var(--accent, #3d36ed); }
.profile-screen .modal-action,
.profile-screen #saveAvatar {
  min-height: 48px;
  padding: 12px 16px;
  border: 1px solid var(--accent, #3d36ed);
  border-radius: var(--radius-control, 14px);
  background: var(--accent, #3d36ed);
  color: var(--accent-ink, #ffffff);
  font-size: 14px;
  font-weight: 650;
  line-height: 1.5;
}
.profile-screen .modal-action { width: 100%; margin-top: 18px; }
.profile-screen .modal-action:hover,
.profile-screen #saveAvatar:hover { background: #302ad7; border-color: #302ad7; }
.profile-screen .modal-note {
  margin: 16px 0 0;
  color: var(--muted, #71747c);
  font-size: 12px;
  line-height: 1.8;
}
.profile-screen button:focus-visible,
.profile-screen input:focus-visible { outline: 2px solid var(--accent, #3d36ed); outline-offset: 3px; }

/* Editing the outdoor identity is a subpage inside the same main pane.
   Its layer never reaches the navigation rail or the mobile tab bar. */
.profile-screen.editing-persona > .profile-page-header,
.profile-screen.editing-persona > #profileContent { display: none; }
.profile-screen > .persona-overlay.persona-inline {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  background: var(--surface, #ffffff);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
.persona-inline .persona-page {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  min-height: 0;
  margin: 0;
  padding: 0 28px;
  border: 0;
  border-radius: 0;
  background: var(--surface, #ffffff);
  box-shadow: none;
}
.persona-inline .persona-top,
.persona-inline .persona-scroll,
.persona-inline .persona-footer {
  align-self: center;
  width: 100%;
  max-width: 720px;
  min-width: 0;
}
.persona-inline .persona-top,
.persona-inline .persona-footer { flex: none; }
.persona-inline .persona-scroll { flex: 1; min-height: 0; overflow-y: auto; }

@media (min-width: 1200px) {
  .app-shell.mode-profile { grid-template-columns: 76px minmax(0, 1fr); }
  .profile-page-header { padding: 38px 40px 28px; }
  .profile-page-header h1 { font-size: 40px; }
  .profile-page-content { padding: 32px 40px 40px; }
  .profile-page-layout {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
    grid-template-rows: auto auto;
    gap: 22px;
  }
  .profile-personal-card { grid-column: 1; grid-row: 1 / 3; }
  .profile-share-card { grid-column: 2; grid-row: 1; }
  .profile-name-card { grid-column: 2; grid-row: 2; }
  .persona-inline .persona-page { padding-inline: 40px; }
}

@media (max-width: 680px) {
  .app-shell.mode-profile { display: block; }
  .app-shell.mode-profile .main {
    position: absolute;
    display: block;
    inset: 0 0 var(--mobile-nav-height, 76px);
    width: 100%;
    height: auto;
  }
  .profile-page-header {
    padding: max(24px, env(safe-area-inset-top, 0px)) 20px 22px;
  }
  .profile-page-header h1 { font-size: 32px; }
  .profile-page-header p { margin-top: 10px; font-size: 13px; }
  .profile-page-content { padding: 20px 20px max(28px, env(safe-area-inset-bottom, 0px)); }
  .profile-page-layout { gap: 18px; }
  .profile-page-card { padding: 20px; }
  .profile-page-card h2 { margin-bottom: 18px; font-size: 19px; }
  .profile-screen .profile-persona { padding: 14px; gap: 14px; }
  .profile-screen .profile-persona-art { width: 88px; height: 96px; }
  .profile-screen .profile-persona-copy { flex-basis: 110px; }
  .profile-screen .profile-avatar-upload { gap: 16px; margin-top: 22px; padding-top: 22px; }
  .profile-screen .profile-avatar-preview { width: 88px; height: 88px; }
  .profile-screen .profile-avatar-actions { flex-basis: 150px; }
  .persona-inline .persona-page { padding-inline: 20px; }
  .persona-inline .persona-top { padding-top: env(safe-area-inset-top, 0px); }
  .persona-inline .persona-footer { padding-bottom: max(16px, env(safe-area-inset-bottom, 0px)); }
  body.mobile-editing .app-shell.mode-profile .main { bottom: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .profile-screen button,
  .rail-profile { transition: none; }
  .profile-page-content { scroll-behavior: auto; }
}
