/*
 * E Companion visual system.
 * This file intentionally owns the companion and the public-shell refinements
 * so the same scene can be reused by the teacher React card without importing
 * the legacy public stylesheet.
 */

html:has(.app-shell[data-sidebar]) {
  --bg: var(--website-paper, #f7f8f5);
  --panel: var(--website-surface, #fffdf8);
  --panel-soft: color-mix(in srgb, var(--website-paper, #f7f8f5) 92%, var(--website-accent, #466b58));
  --panel-hover: color-mix(in srgb, var(--website-paper, #f7f8f5) 85%, var(--website-accent, #466b58));
  --ink: var(--website-ink, #1b2320);
  --ink-strong: var(--website-ink, #1b2320);
  --muted: var(--website-muted, #657168);
  --faint: #8b958e;
  --line: rgba(30, 58, 45, 0.11);
  --line-strong: rgba(30, 58, 45, 0.2);
  --blue: var(--website-accent, #466b58);
  --blue-dark: var(--website-accent, #466b58);
  --blue-soft: #e7f0e9;
  --green: #3e765d;
  --green-soft: #e6f0e8;
  color: var(--ink);
  background: var(--bg);
}

html:has(.app-shell[data-sidebar]) body {
  background:
    radial-gradient(circle at 78% -12%, rgba(119, 155, 132, 0.13), transparent 34rem),
    var(--bg);
}

.app-shell[data-sidebar] .sidebar,
.app-shell[data-sidebar] .sidebar-foot {
  background: var(--panel-soft);
}

.app-shell[data-sidebar] .topbar {
  border-bottom-color: rgba(35, 67, 52, 0.07);
  background: color-mix(in srgb, var(--website-paper, #f7f8f5) 90%, transparent);
}

.app-shell[data-sidebar] :is(
  .quick-actions button,
  .composer,
  .popover,
  .capability-card,
  .price-card,
  .billing-summary,
  .recharge-panel,
  .download-features > div,
  .help-search,
  .help-categories button,
  .help-article,
  .account-guest,
  .profile-card,
  .balance-card,
  .account-service-card,
  .orders-card,
  .usage-card,
  .usage-account-strip,
  .usage-balance-card
) {
  background-color: var(--panel);
}

.app-shell[data-sidebar] :is(.nav-item.is-active, .account-entry:hover, .sidebar-utility button:hover) {
  background: var(--panel-hover);
}

.app-shell[data-sidebar] :is(.primary-button, .send-button) {
  border-color: var(--blue-dark);
  background: var(--blue-dark);
  color: var(--website-paper, #f7f8f5);
}

.app-shell[data-sidebar] :is(.capability-card, .quick-actions button, .help-categories button) {
  box-shadow: 0 10px 34px rgba(35, 67, 52, 0.035);
}

.app-shell[data-sidebar] :is(.capability-card, .quick-actions button, .help-categories button):hover {
  border-color: rgba(39, 95, 75, 0.3);
  background: var(--website-paper, #f7f8f5);
  box-shadow: 0 12px 34px rgba(35, 67, 52, 0.07);
}

.app-shell[data-sidebar] .plan-card {
  background: var(--website-accent, #466b58);
  color: var(--website-paper, #f7f8f5);
}

.app-shell[data-sidebar] .usage-balance-card.emphasis,
.app-shell[data-sidebar] .admin-access-card {
  border-color: var(--website-accent, #466b58);
  background: var(--website-accent, #466b58);
}

.app-shell[data-sidebar] .admin-access-card :is(h2, p, .section-kicker),
.app-shell[data-sidebar] .usage-balance-card.emphasis :is(strong, small, span) {
  color: var(--website-paper, #f7f8f5);
}

.app-shell[data-sidebar] .home-status-strip > button:hover,
.app-shell[data-sidebar] .home-recent-list button:hover {
  background: rgba(54, 91, 73, 0.045);
}

/* Public-shell business copy only; shared tokens own the global type system. */
.app-shell[data-sidebar] :is(.nav-item, .new-chat, .account-copy strong,
  .quick-actions button, .home-recent-list strong, .home-payment-callout strong,
  .help-results button, .help-categories strong, .help-article p, .help-article li,
  .help-search-empty, .account-service-card p, .profile-name-form input,
  .plan-card > button, .balance-card > button, .orders-card td, .usage-card td,
  .composer textarea) {
  font-size: var(--website-text, 14px);
  line-height: 1.6;
}

.app-shell[data-sidebar] :is(.account-copy small, .profile-copy small,
  .profile-copy > span, .profile-name-form label > span, .account-service-card > span,
  .home-overview-head p, .home-status-strip span, .home-status-strip small,
  .home-recent-list small, .home-payment-callout small, .composer-footnote,
  .help-categories small, .version-line, .usage-account-strip span,
  .plan-card > div > span, .plan-card > div > small,
  .balance-card > div > span, .balance-card > div > small,
  .account-balance-split span, .account-balance-split b) {
  font-size: var(--website-caption, 12px);
  line-height: 1.55;
}

.app-shell[data-sidebar] .account-copy > * {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-shell[data-sidebar] .help-article { scroll-margin-top: 76px; }
.app-shell[data-sidebar] .help-results button { min-height: 48px; text-align: left; }
.app-shell[data-sidebar] .help-results button span { flex-shrink: 0; }
.app-shell[data-sidebar] .help-search-empty { color: var(--website-muted, #657168); }
.app-shell[data-sidebar] .teacher-access-card { margin-top: 16px; }
.app-shell[data-sidebar] .teacher-access-card a { min-height: 44px; margin-top: 12px; }
.app-shell[data-sidebar] .account-service-card p { overflow-wrap: anywhere; }

/* Give the draft its own full-width row, including on desktop. */
.app-shell[data-sidebar] .composer { padding: 8px; border-radius: 22px; gap: 6px; }
.app-shell[data-sidebar] .composer textarea { order: 0; flex: 0 0 100%; width: 100%; min-height: 48px; }
.app-shell[data-sidebar] .composer-actions { display: flex; order: 2; width: 100%; min-width: 0; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px; }
.app-shell[data-sidebar] .composer-right { min-width: 0; flex-wrap: wrap; gap: 8px; }
.app-shell[data-sidebar] :is(.composer-model, .cost-hint) { font-size: var(--website-caption, 12px); line-height: 1.5; }

/* Compact, silent scene with a static-first cover. */
.e-companion {
  --ec-ink: var(--website-ink, #1b2320);
  --ec-green: var(--website-accent, #466b58);
  --ec-light: var(--website-paper, #f7f8f5);
  width: min(100%, 244px);
  color: var(--ec-ink);
  min-width: 0;
  box-sizing: border-box;
}

.e-companion *, .e-companion *::before, .e-companion *::after { box-sizing: border-box; }
.e-companion [hidden] { display: none !important; }
.e-companion button { font-family: inherit; }

.e-companion--home {
  margin-top: 7px;
}

.e-companion-stage {
  position: relative;
  display: block;
  width: 100%;
  height: 102px;
  overflow: hidden;
  padding: 0;
  border: 1px solid rgba(38, 70, 55, 0.12);
  border-radius: 18px;
  outline: 0;
  background:
    linear-gradient(180deg, rgba(255,255,255,.62), transparent 54%),
    linear-gradient(145deg, #f6f0e1, #e7eee6);
  box-shadow: 0 13px 32px rgba(41, 68, 54, 0.08);
  cursor: pointer;
  isolation: isolate;
  touch-action: manipulation;
}

.e-companion-stage::after {
  content: "";
  position: absolute;
  z-index: 0;
  right: -14%;
  bottom: -58%;
  width: 64%;
  height: 100%;
  border-radius: 50%;
  background: rgba(92, 130, 107, 0.12);
  filter: blur(10px);
}

.e-companion-stage:focus-visible {
  box-shadow: 0 0 0 3px rgba(47, 101, 77, 0.22), 0 13px 32px rgba(41, 68, 54, 0.1);
}

.e-companion-stage:hover .e-companion-cover,
.e-companion-stage:focus-visible .e-companion-cover,
.e-companion.is-interacting .e-companion-cover {
  transform: translateY(-2px) rotate(-0.5deg);
}

.e-companion-cover,
.e-companion-stage canvas,
.e-companion-glow {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.e-companion-cover {
  z-index: 1;
  display: block;
  transition: opacity 220ms ease, transform 240ms ease;
}

.e-companion-stage canvas {
  z-index: 2;
  display: block;
  opacity: 0;
  transition: opacity 260ms ease;
}

.e-companion.is-three-ready .e-companion-stage canvas {
  opacity: 1;
}

.e-companion.is-three-ready .e-companion-cover {
  opacity: 0;
}

.e-companion-sign {
  position: absolute;
  left: 68px;
  top: 13px;
  display: grid;
  width: 54px;
  height: 57px;
  place-items: center;
  border: 5px solid #365e4a;
  border-radius: 7px;
  background: #fffdf7;
  box-shadow: 0 8px 13px rgba(38, 59, 48, .14);
  transform: rotate(-2deg);
}

.e-companion-sign::before,
.e-companion-sign::after {
  content: "";
  position: absolute;
  top: -9px;
  width: 4px;
  height: 10px;
  border-radius: 5px;
  background: #b18a58;
}

.e-companion-sign::before { left: 8px; }
.e-companion-sign::after { right: 8px; }
.e-companion-sign img { display: block; width: 38px; height: 38px; border-radius: 9px; }

.e-companion-book {
  position: absolute;
  bottom: 15px;
  display: block;
  height: 9px;
  border-radius: 2px 4px 4px 2px;
  box-shadow: inset 0 -2px rgba(0,0,0,.08);
}

.e-companion-book--one {
  left: 22px;
  width: 54px;
  background: #dca66f;
  transform: rotate(-5deg);
}

.e-companion-book--two {
  left: 31px;
  bottom: 25px;
  width: 49px;
  background: #6f9179;
  transform: rotate(2deg);
}

.e-companion-plant {
  position: absolute;
  right: 26px;
  bottom: 12px;
  display: block;
  width: 43px;
  height: 48px;
  border-radius: 0 0 11px 11px;
  border-top: 4px solid #c69261;
  background: linear-gradient(90deg, #b8784d, #d6a176 52%, #ad6f49);
  box-shadow: 0 7px 12px rgba(39, 65, 51, .12);
}

.e-companion-plant i {
  position: absolute;
  left: 19px;
  bottom: 33px;
  display: block;
  width: 11px;
  height: 26px;
  border-radius: 100% 0 100% 0;
  background: #4e8064;
  transform-origin: bottom;
}

.e-companion-plant i:nth-child(1) { transform: rotate(-42deg); }
.e-companion-plant i:nth-child(2) { height: 31px; transform: rotate(5deg); }
.e-companion-plant i:nth-child(3) { transform: rotate(44deg) scaleX(-1); }

.e-companion-glow {
  z-index: 3;
  pointer-events: none;
  background: radial-gradient(circle at 50% 46%, rgba(255,255,255,.34), transparent 45%);
  opacity: 0;
}

.e-companion.is-interacting .e-companion-glow {
  animation: e-companion-glow 650ms ease-out;
}

@keyframes e-companion-glow {
  0% { opacity: 0; transform: scale(.74); }
  35% { opacity: .82; }
  100% { opacity: 0; transform: scale(1.25); }
}

.e-companion-caption {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin: 5px 0 0;
  flex-wrap: wrap;
  color: var(--website-muted, #657168);
  font-size: 12px;
  line-height: 1.4;
}

.e-companion-caption strong {
  color: var(--website-accent, #466b58);
  font-weight: 650;
}

/* Reusable teacher break card. */
.e-companion--teacher {
  width: min(100%, 360px);
  padding: 12px;
  border: 1px solid rgba(38, 70, 55, 0.12);
  border-radius: 18px;
  background: var(--website-surface, #fffdf8);
  box-shadow: 0 12px 34px rgba(31, 57, 45, .07);
  text-align: left;
}

.e-companion-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.e-companion-card-head span,
.e-companion-card-head strong {
  display: block;
}

.e-companion-card-head span {
  color: var(--website-muted, #657168);
  font-size: 12px;
}

.e-companion-card-head strong {
  margin-top: 2px;
  color: var(--ec-ink);
  font-size: 14px;
}

.e-companion-collapse {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid rgba(38, 70, 55, .12);
  border-radius: 12px;
  background: var(--website-paper, #f7f8f5);
  color: var(--website-accent, #466b58);
  font-size: 14px;
  cursor: pointer;
  touch-action: manipulation;
}

.e-companion--teacher .e-companion-stage {
  height: 138px;
}

.e-companion--teacher[data-compact="true"] .e-companion-stage { height: 102px; }
.e-companion-collapse:focus-visible { outline: 2px solid var(--ec-green); outline-offset: 3px; }

.e-companion--teacher .e-companion-caption {
  justify-content: flex-start;
}

.e-companion--teacher.is-collapsed {
  padding-bottom: 2px;
}

.e-companion--teacher.is-collapsed .e-companion-card-head {
  margin-bottom: 10px;
}

.e-companion--teacher.is-collapsed .e-companion-body {
  display: none;
}

.legacy-teacher-notice {
  margin-block: 12px;
  padding: 12px 16px;
  border: 1px solid var(--website-line, #dce2dc);
  border-radius: 14px;
  background: var(--website-surface, #fffdf8);
  color: var(--website-ink, #1b2320);
  font-size: var(--website-text, 14px);
  line-height: 1.6;
}
.legacy-teacher-notice p { margin: 0; }
.legacy-teacher-notice a { display: inline-flex; min-height: 44px; align-items: center; color: var(--website-accent, #466b58); text-underline-offset: 3px; }

/* Account alignment and teacher help additions. */
.app-shell[data-sidebar] .account-overview {
  align-items: stretch;
}

.app-shell[data-sidebar] :is(.plan-card, .balance-card) {
  display: grid;
  border: 1px solid var(--line);
  min-height: 166px;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  gap: 18px;
}

.app-shell[data-sidebar] :is(.plan-card, .balance-card) > div {
  min-width: 0;
  height: 100%;
}

.app-shell[data-sidebar] :is(.plan-card, .balance-card) > div > span {
  min-height: 16px;
  line-height: 16px;
}

.app-shell[data-sidebar] :is(.plan-card, .balance-card) > div > strong {
  min-height: 35px;
  margin-top: 9px;
  line-height: 35px;
}

.app-shell[data-sidebar] :is(.plan-card, .balance-card) > button {
  align-self: end;
}

.app-shell[data-sidebar] .help-categories {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.help-release-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 18px;
  padding: 15px 17px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(231, 240, 233, .55);
}

.help-release-strip span,
.help-release-strip strong {
  display: block;
}

.help-release-strip span {
  color: var(--website-muted, #657168);
  font-size: 12px;
}

.help-release-strip strong {
  margin-top: 4px;
  color: var(--ink-strong);
  font-size: 14px;
}

.help-release-strip button {
  min-width: 88px;
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--panel);
  color: var(--blue-dark);
  font-size: 14px;
  cursor: pointer;
}

@media (max-width: 980px) {
  .app-shell[data-sidebar] .help-categories {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .app-shell[data-sidebar] .home-page:not(.is-conversation) .home-inner {
    justify-content: flex-start;
    padding-top: 4vh;
    padding-bottom: 0;
  }

  .app-shell[data-sidebar] .home-empty {
    padding-inline: 12px;
  }

  .e-companion--home {
    width: min(100%, 224px);
    margin-top: 5px;
  }

  .e-companion--home .e-companion-stage {
    height: 88px;
  }

  .e-companion--home .e-companion-caption {
    margin-top: 3px;
  }

  .app-shell[data-sidebar] .composer-wrap {
    width: calc(100% - 20px);
  }

  .app-shell[data-sidebar] .composer {
    display: flex;
    flex-direction: column;
    min-height: 104px;
    align-items: stretch;
    gap: 2px 6px;
    padding: 6px;
    border-radius: 22px;
  }

  .app-shell[data-sidebar] .composer textarea {
    order: initial;
    flex: none;
    width: 100%;
    min-width: 0;
    min-height: 48px;
    padding: 10px 9px 6px;
    font-size: 16px;
    line-height: 1.45;
  }

  .app-shell[data-sidebar] .composer .image-edit-reference,
  .app-shell[data-sidebar] .composer .chat-attachments {
    order: initial;
    flex: none;
    width: 100%;
  }

  .app-shell[data-sidebar] .composer-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 44px 44px;
    align-items: center;
    gap: 4px;
    width: 100%;
    order: 2;
  }

  .app-shell[data-sidebar] .composer-left,
  .app-shell[data-sidebar] .composer-right {
    min-height: 44px;
    order: initial;
  }

  .app-shell[data-sidebar] .composer-left {
    grid-column: 1;
    grid-row: 2;
    min-width: 0;
  }

  .app-shell[data-sidebar] .composer-right {
    display: contents;
  }

  .app-shell[data-sidebar] .voice-button { display: grid; grid-column: 2; grid-row: 2; }
  .app-shell[data-sidebar] .send-button { grid-column: 3; grid-row: 2; }

  .app-shell[data-sidebar] :is(.round-button, .send-button) {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }

  .app-shell[data-sidebar] .mode-button {
    min-height: 44px;
    padding-inline: 9px;
    font-size: 14px;
  }

  .app-shell[data-sidebar] .composer-model {
    display: block;
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
    max-width: none;
    padding-left: 10px;
    overflow: hidden;
    color: var(--ink);
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .app-shell[data-sidebar] .cost-hint {
    display: block;
    grid-column: 2 / -1;
    grid-row: 1;
    width: auto;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.4;
    text-align: right;
    white-space: normal;
  }

  .app-shell[data-sidebar] :is(input, textarea, select),
  .app-shell[data-sidebar] .profile-name-form input {
    font-size: 16px;
  }

  .app-shell[data-sidebar] :is(
    .new-chat,
    .nav-item,
    .quick-actions button,
    .login-button,
    .icon-button,
    .popover button,
    .help-article > button,
    .plan-card > button,
    .balance-card > button,
    .sidebar-utility button,
    .account-entry,
    .help-results button,
    .help-release-strip button,
    .primary-button,
    .secondary-button,
    .quiet-button
  ) {
    min-height: 44px;
  }

  .app-shell[data-sidebar] :is(.icon-button, .help-article > button) { min-width: 44px; }

  .app-shell[data-sidebar] .help-categories {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .app-shell[data-sidebar] .help-categories button {
    min-height: 118px;
  }

  .help-release-strip {
    align-items: flex-start;
    flex-direction: column;
  }

  .app-shell[data-sidebar] :is(.plan-card, .balance-card) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: stretch;
    min-height: 162px;
  }
}

@media (max-width: 430px) {
  .app-shell[data-sidebar] .help-categories {
    grid-template-columns: 1fr;
  }

  .app-shell[data-sidebar] :is(.plan-card, .balance-card) {
    grid-template-columns: 1fr;
  }

  .app-shell[data-sidebar] :is(.plan-card, .balance-card) > button {
    width: 100%;
  }

}

@media (prefers-reduced-motion: reduce) {
  .e-companion *,
  .e-companion *::before,
  .e-companion *::after {
    animation: none !important;
    transition: none !important;
  }

  .e-companion-stage:hover .e-companion-cover,
  .e-companion-stage:focus-visible .e-companion-cover { transform: none; }
}
