/* Mobile hardening for the Star Clone workspace.
   The base stylesheet uses grid and flex items with their default min-width:auto.
   On narrow screens the header and composer therefore expand the grid track beyond
   the viewport. These rules let every nested item shrink and deliberately stack
   the controls instead of merely hiding the overflow. */

html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  overflow-x: clip;
}

main,
.workspace,
.panel,
.dialog-layout,
.conversation,
.logic,
.conversation-head,
.conversation-head > div,
.messages,
.chips,
.composer {
  min-width: 0;
  max-width: 100%;
}

.workspace {
  grid-template-columns: 280px minmax(0, 1fr);
}

.dialog-layout {
  grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
}

.topbar > *,
.message > div {
  min-width: 0;
}

.message > div,
.message p,
.composer-note,
.logic p {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.composer textarea {
  display: block;
  min-width: 0;
  max-width: 100%;
}

@media (max-width: 900px) {
  .workspace,
  .dialog-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .panel {
    margin: 0;
  }

  .conversation,
  .logic {
    width: 100%;
  }
}

@media (max-width: 600px) {
  .topbar {
    height: 64px;
    gap: 12px;
    padding: 0 max(16px, env(safe-area-inset-left));
  }

  .brand {
    flex: 0 0 auto;
  }

  .product {
    min-width: 0;
    overflow: hidden;
    text-align: right;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .panel {
    padding: 12px;
  }

  .conversation,
  .logic {
    border-radius: 18px;
    padding: 16px;
  }

  .conversation-head {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .conversation-head h2 {
    margin: 5px 0 0;
    font-size: clamp(26px, 8vw, 32px);
    line-height: 1.08;
    letter-spacing: -0.025em;
  }

  .conversation-head .ghost {
    align-self: flex-start;
  }

  .messages {
    min-height: 190px;
    max-height: 42svh;
    padding: 18px 0;
  }

  .message > div {
    max-width: calc(100% - 44px);
  }

  .message.user > div {
    max-width: 92%;
  }

  .chips {
    width: 100%;
    padding-bottom: 12px;
    overscroll-behavior-inline: contain;
    scrollbar-width: none;
  }

  .chips::-webkit-scrollbar {
    display: none;
  }

  .composer {
    width: 100%;
    grid-template-columns: minmax(0, 1fr);
  }

  .composer textarea {
    min-height: 96px;
    resize: vertical;
  }

  .composer .primary {
    width: 100%;
  }

  .logic {
    order: 2;
  }
}

@media (max-width: 420px) {
  .topbar {
    padding-right: max(14px, env(safe-area-inset-right));
    padding-left: max(14px, env(safe-area-inset-left));
  }

  .product i {
    display: none;
  }

  .panel {
    padding: 10px;
  }

  .conversation,
  .logic {
    padding: 14px;
    border-radius: 16px;
  }

  .eyebrow {
    font-size: 10px;
    letter-spacing: 0.11em;
  }

  .conversation-head h2 {
    font-size: 27px;
  }

  .allowance {
    max-width: 100%;
    white-space: normal;
  }
}

@media (max-width: 680px) {
  .passport-head { grid-template-columns: 58px minmax(0, 1fr); }
  .passport-avatar { width: 58px; height: 58px; border-radius: 19px; }
  .alignment-price { align-items: flex-start; flex-direction: column; gap: 3px; }
  .logic.profile-mode { max-width: 100%; }
}

/* Compact, app-like chat on phones. */
@media (max-width: 600px) {
  body {
    background:
      radial-gradient(circle at 100% 0, rgba(124, 58, 237, 0.16), transparent 38%),
      #090814;
  }

  .orb {
    opacity: 0.12;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    height: 54px;
    padding-right: max(12px, env(safe-area-inset-right));
    padding-left: max(12px, env(safe-area-inset-left));
    background: rgba(9, 8, 20, 0.82);
    border-bottom-color: rgba(255, 255, 255, 0.07);
    backdrop-filter: blur(20px) saturate(135%);
  }

  .brand {
    gap: 7px;
    font-size: 14px;
  }

  .product {
    max-width: 52vw;
    font-size: 12px;
  }

  .product i {
    margin-left: 4px;
    padding: 2px 5px;
    font-size: 8px;
  }

  .workspace {
    min-height: calc(100svh - 54px);
  }

  .panel {
    padding: 8px;
  }

  #dialogView {
    gap: 8px;
  }

  #dialogView .conversation {
    display: flex;
    min-height: calc(100svh - 70px);
    flex-direction: column;
    padding: 12px 10px 10px;
    border-color: rgba(255, 255, 255, 0.075);
    border-radius: 18px;
    background: rgba(15, 13, 29, 0.88);
    box-shadow: 0 18px 60px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(20px);
  }

  #dialogView .conversation-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    padding: 0 2px 9px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.065);
  }

  #dialogView .conversation-head > div {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px 8px;
  }

  #dialogView .conversation-head .eyebrow {
    display: none;
  }

  #dialogView .conversation-head h2 {
    flex: 1 0 100%;
    margin: 0;
    font-size: 20px;
    line-height: 1.12;
    letter-spacing: -0.025em;
  }

  #dialogView .allowance {
    margin: 0;
    padding: 4px 8px;
    font-size: 10px;
    line-height: 1.2;
    white-space: nowrap;
  }

  #dialogView .conversation-head .ghost {
    align-self: center;
    min-height: 38px;
    padding: 8px 10px;
    border-radius: 11px;
    color: #d5cbe3;
    font-size: 11px;
    line-height: 1.15;
    white-space: nowrap;
  }

  #dialogView .messages {
    flex: 1 1 auto;
    min-height: 230px;
    max-height: none;
    gap: 10px;
    padding: 12px 2px 10px;
    scroll-padding-bottom: 12px;
    overscroll-behavior-y: contain;
  }

  #dialogView .message {
    gap: 8px;
    align-items: flex-end;
  }

  #dialogView .mini-avatar {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }

  #dialogView .message > div {
    max-width: min(88%, 520px);
    padding: 10px 12px;
    border-radius: 15px 15px 15px 5px;
    background: rgba(255, 255, 255, 0.045);
  }

  #dialogView .message.user > div {
    max-width: 88%;
    border-color: rgba(167, 139, 250, 0.2);
    border-radius: 15px 15px 5px 15px;
    background: linear-gradient(145deg, rgba(139, 92, 246, 0.19), rgba(217, 70, 239, 0.1));
  }

  #dialogView .message b {
    font-size: 12px;
  }

  #dialogView .message p {
    margin-top: 4px;
    font-size: 14px;
    line-height: 1.48;
  }

  #dialogView .chips {
    flex: 0 0 auto;
    gap: 6px;
    margin: 0 -2px;
    padding: 2px 2px 8px;
    scroll-snap-type: x proximity;
  }

  #dialogView .chips button {
    min-height: 34px;
    padding: 7px 10px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.025);
    font-size: 11px;
    scroll-snap-align: start;
  }

  #dialogView .composer {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 48px;
    gap: 7px;
    align-items: end;
    padding: 7px;
    border: 1px solid rgba(255, 255, 255, 0.085);
    border-radius: 17px;
    background: rgba(255, 255, 255, 0.045);
    box-shadow: 0 12px 34px rgba(0, 0, 0, 0.16);
  }

  #dialogView .composer:focus-within {
    border-color: rgba(167, 139, 250, 0.48);
    box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.1), 0 12px 34px rgba(0, 0, 0, 0.16);
  }

  #dialogView .composer textarea {
    min-height: 44px;
    max-height: 132px;
    padding: 11px 8px 9px;
    border: 0;
    border-radius: 11px;
    background: transparent;
    font-size: 16px;
    line-height: 1.35;
    resize: none;
    box-shadow: none;
  }

  #dialogView .composer textarea:focus {
    border: 0;
    box-shadow: none;
  }

  #dialogView .composer .primary {
    width: 48px;
    min-width: 48px;
    height: 48px;
    padding: 0;
    border-radius: 14px;
    font-size: 0;
    box-shadow: 0 9px 24px rgba(139, 92, 246, 0.3);
  }

  #dialogView .composer .primary::before {
    content: "↑";
    display: block;
    font-size: 24px;
    font-weight: 750;
    line-height: 1;
    transform: translateY(-1px);
  }

  #dialogView .composer-note {
    margin: 6px 4px 0;
    font-size: 10px;
    line-height: 1.35;
  }

  #dialogView .error {
    min-height: 0;
    margin: 4px 3px 0;
    font-size: 11px;
  }

  #dialogView .error:empty {
    display: none;
  }

  #dialogView .alignment-offer {
    margin-top: 10px;
    padding: 14px;
    border-radius: 16px;
  }

  #dialogView .alignment-offer h3 {
    margin: 5px 0 8px;
    font-size: 19px;
  }

  #dialogView .alignment-offer p {
    font-size: 12px;
    line-height: 1.5;
  }

  #dialogView .logic {
    margin-top: 0;
    padding: 16px 14px;
    border-radius: 18px;
    background: rgba(15, 13, 29, 0.76);
  }

  #dialogView .logic > .eyebrow {
    margin-top: 0;
  }

  #dialogView .logic h3 {
    margin: 5px 0 12px;
    font-size: 19px;
  }

  #dialogView .logic-empty {
    padding: 13px;
    font-size: 12px;
    line-height: 1.5;
  }

  #dialogView .factor {
    padding: 11px 0;
  }

  #dialogView .factor p,
  #dialogView .logic details p {
    font-size: 12px;
    line-height: 1.5;
  }
}

@media (max-width: 380px) {
  #dialogView .conversation-head h2 {
    font-size: 18px;
  }

  #dialogView .conversation-head .ghost {
    width: 38px;
    min-width: 38px;
    padding: 0;
    overflow: hidden;
    font-size: 0;
  }

  #dialogView .conversation-head .ghost::before {
    content: "+";
    display: grid;
    place-items: center;
    font-size: 23px;
    line-height: 1;
  }

  #dialogView .message > div,
  #dialogView .message.user > div {
    max-width: 91%;
  }
}
