/* Ember Chat — app shell. Values come from tokens.css; only product layout sizes live here. */

:root {
  --servicebar-h: 48px;     /* product: service bar 48 (tokens' --topbar-h 64 is for dashboards) */
  --mobilebar-h: 56px;
  --drawer-w: 312px;
  --shell-offset: var(--sidebar-w); /* width left of the main area */
  --panel-z: 50;
  --scrim: rgba(0, 0, 0, 0.6);
  --hover-fill: rgba(255, 255, 255, 0.06);
  --secondary-fill: rgba(255, 255, 255, 0.04);
  --line-edges: inset 0 1px 0 var(--edge-top), inset 0 0 0 1px var(--edge);
  --popover-under: rgba(19, 19, 21, 0.88); /* surface under the glass so menus stay legible over flat areas */
}

/* ---------- base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--body-size);
  line-height: var(--body-lh);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

img, svg { display: block; max-width: 100%; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p, ul { margin: 0; }
ul { padding: 0; list-style: none; }

:focus { outline: none; }
:focus-visible { box-shadow: var(--focus-ring); border-radius: var(--radius-sm); }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: fixed;
  top: var(--space-2);
  left: var(--space-2);
  z-index: 100;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--surface-inverse);
  color: var(--text-inverse);
  font-weight: 500;
  transform: translateY(-200%);
}
.skip-link:focus-visible { transform: none; }

.mono-label {
  font-family: var(--font-mono);
  font-size: var(--mono-label-size);
  line-height: var(--mono-label-lh);
  letter-spacing: var(--mono-label-track);
  font-weight: var(--mono-label-weight);
}

/* ---------- controls ---------- */

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-muted);
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.icon-btn:hover { background: var(--hover-fill); color: var(--text); }
.icon-btn:focus-visible { border-radius: var(--radius-md); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 40px;
  padding: 0 var(--space-4);
  border: 0;
  border-radius: var(--radius-sm);
  font-size: var(--body-size);
  font-weight: 500;
  transition: background var(--dur-fast) var(--ease-out);
}
.btn--secondary { background: var(--secondary-fill); box-shadow: var(--line-edges); color: var(--text); }
.btn--secondary:hover { background: var(--hover-fill); }
.btn--secondary:focus-visible { box-shadow: var(--line-edges), var(--focus-ring); }

.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.status-dot::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--success);
  box-shadow: 0 0 8px rgba(74, 222, 154, 0.5);
}
.status-dot--live::before { animation: pulse 2s ease-in-out infinite; }

@keyframes pulse { 50% { opacity: 0.35; } }

/* ---------- layout ---------- */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100dvh;
}

.rail { display: none; }
.scrim { display: none; }

.main {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100dvh;       /* the conversation scrolls inside .content; the aurora and service bar stay put */
  background: var(--aurora-ambient);
  overflow-x: clip;
  isolation: isolate;
}

/* ---------- sidebar ---------- */

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding: var(--space-4);
  background: var(--bg-subtle);
  box-shadow: inset -1px 0 0 var(--divider);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sidebar__head { display: flex; gap: var(--space-2); }
.sidebar__new { flex: 1; }
.sidebar__close { display: none; }

.sidebar__section { margin-top: var(--space-6); }

.sidebar__label {
  margin-bottom: var(--space-2);
  padding: 0 var(--space-3);
  color: var(--text-subtle);
  font-weight: 400;
}
.sidebar__label:focus-visible { border-radius: var(--radius-xs); }

.recent__empty {
  padding: 0 var(--space-3);
  color: var(--text-subtle);
  font-size: var(--caption-size);
  line-height: var(--caption-lh);
}
.recent:not(:empty) + .recent__empty { display: none; }
.recent__item {
  display: block;
  width: 100%;
  height: 36px;
  padding: 0 var(--space-3);
  overflow: hidden;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-muted);
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.recent__item:hover { background: var(--hover-fill); color: var(--text); }
.recent__item:focus-visible { border-radius: var(--radius-md); }

.tree__row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 36px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.tree__row:hover { background: var(--hover-fill); color: var(--text); }
.tree__chevron { color: var(--text-subtle); }
.tree__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.profile { margin-top: auto; padding-top: var(--space-4); }

.profile__btn {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  height: 56px;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  text-align: left;
}
.profile__btn:hover { background: var(--hover-fill); }
.profile__btn:focus-visible { border-radius: var(--radius-md); }
.profile__text { display: flex; flex: 1; flex-direction: column; gap: 2px; min-width: 0; }
.profile__name { font-weight: 500; }
.profile__text .status-dot { color: var(--text-muted); }
.profile__chevron { color: var(--text-subtle); }

.avatar { border-radius: var(--radius-full); object-fit: cover; flex: none; }

/* ---------- service bar ---------- */

.servicebar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  height: var(--servicebar-h);
  padding: 0 var(--space-6);
  box-shadow: inset 0 -1px 0 var(--divider);
  color: var(--text-muted);
}
.servicebar__menu { display: none; margin-left: calc(-1 * var(--space-2)); }
.servicebar__title { color: var(--text-muted); }
.servicebar__title:hover { color: var(--text); }
.servicebar__status { display: flex; align-items: center; gap: var(--space-6); margin-left: auto; }
.servicebar__session { color: var(--text-subtle); }
.servicebar .status-dot { color: var(--text); }

/* ---------- greeting scene ---------- */

.content {
  position: relative;
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable both-edges;
  scrollbar-color: var(--surface-hover) transparent;
}

.stage {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding: 0 var(--space-6);
  min-height: 360px;
}

.portrait {
  position: fixed;       /* stays behind the service bar instead of being clipped by the scroller */
  top: -96px;            /* Figma: hero 900×860 starts 96px above the main area */
  left: calc(var(--shell-offset) + (100vw - var(--shell-offset)) / 2);
  z-index: -1;
  width: 900px;
  margin-left: -450px;
  pointer-events: none;
}
/* Revision 3: the portrait layer sits at ~85 % so it glows without shouting. */
.portrait img {
  opacity: 0.85;
  width: 100%;
  height: auto;
  transform-origin: 50% 45%;
  animation: breathe 4s ease-in-out infinite;
}
@keyframes breathe { 50% { transform: scale(1.02); } }
/* Slow connection: a soft silhouette holds the portrait's place until the dots arrive (STRUCTURE «Медленный интернет»). */
.portrait::before {
  content: "";
  position: absolute;
  inset: 12% 24% 18%;
  z-index: -1;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(78, 5, 10, 0.32), rgba(26, 2, 5, 0.18) 60%, transparent);
  filter: blur(24px);
}

.greeting {
  max-width: var(--chat-w);
  text-align: center;
}
.greeting__time { color: var(--text-muted); }
.greeting__title {
  margin-top: var(--space-3);
  font-size: var(--h1-size);
  line-height: var(--h1-lh);
  font-weight: var(--h1-weight);
  letter-spacing: var(--h1-track);
}
.greeting__sub {
  max-width: 520px;
  margin: var(--space-3) auto 0;
  color: var(--text-muted);
  font-size: var(--body-lg-size);
  line-height: var(--body-lg-lh);
}

.projects-row { display: none; }

/* ---------- input zone ---------- */

.dock {
  position: sticky;
  bottom: 0;
  z-index: 4;
  width: 100%;
  max-width: calc(var(--chat-w) + 2 * var(--space-6));
  margin: 0 auto;
  padding: var(--space-10) var(--space-6) var(--space-6);
}

.dock__label { margin-bottom: var(--space-3); color: var(--text-subtle); }

.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-4); }

.chip {
  display: inline-flex;
  align-items: center;
  flex: none;
  height: 40px;
  padding: 0 var(--space-4);
  border-radius: var(--radius-full);
  background: var(--glass-fill);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  box-shadow: var(--glass-rim);
  color: var(--text);
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease-out);
}
.chip:hover { background: var(--glass-fill-strong); }
.chip:focus-visible { border-radius: var(--radius-full); box-shadow: var(--glass-rim), var(--focus-ring); }
.chip--more {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: var(--mono-body-size);
  line-height: var(--mono-body-lh);
}

.composer {
  padding: var(--space-4) var(--space-4) var(--space-3);
  border-radius: var(--radius-lg);
  background: var(--glass-fill);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  box-shadow: var(--glass-rim), var(--elevation-2);
  transition: box-shadow var(--dur-fast) var(--ease-out);
}
.using-keyboard .composer:has(.composer__input:focus) {
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.32), var(--glass-rim), var(--elevation-2), var(--focus-ring);
}

.composer__input {
  display: block;
  width: 100%;
  min-height: var(--body-lg-lh);
  max-height: 160px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: var(--body-lg-size);
  line-height: var(--body-lg-lh);
  resize: none;
}
.composer__input::placeholder { color: var(--text-subtle); opacity: 1; }
.composer__input:focus-visible { box-shadow: none; }

.composer__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--space-3);
}
.composer__slash { margin-left: calc(-1 * var(--space-2)); }

.composer__send {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, var(--accent-hover), var(--accent-fill));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), var(--glow-accent);
  color: var(--on-accent);
  transition: background var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.composer__send:active { background: var(--accent-pressed); }
.composer__send:focus-visible { border-radius: var(--radius-md); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), var(--focus-ring); }
.composer__send:disabled {
  background: var(--surface-hover);
  box-shadow: var(--elevation-1);
  color: var(--text-subtle);
  cursor: default;
}

/* ---------- popover menu (profile) ---------- */

.popover {
  position: fixed;
  inset: auto auto 80px 16px; /* default: above the profile row; JS pins it to the invoker */
  width: 248px;
  margin: 0;
  padding: 6px;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--glass-fill-strong), var(--popover-under);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  box-shadow: var(--glass-rim), var(--elevation-3);
  color: var(--text);
}

.menu__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: 36px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text);
}
.menu__item .icon { color: var(--text-muted); }
.menu__item:hover { background: var(--hover-fill); }

/* ---------- tablet 768–1199: rail 72, panel as overlay ---------- */

@media (max-width: 1199px) {
  :root { --shell-offset: var(--rail-w); }
  .app { grid-template-columns: var(--rail-w) minmax(0, 1fr); }

  .rail {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    height: 100dvh;
    padding: var(--space-4) 0;
    background: var(--bg-subtle);
    box-shadow: inset -1px 0 0 var(--divider);
  }
  .rail__top { display: flex; flex-direction: column; gap: var(--space-2); }
  .rail__avatar {
    padding: 4px;
    border: 0;
    border-radius: var(--radius-full);
    background: transparent;
  }
  .rail__avatar:focus-visible { border-radius: var(--radius-full); }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: var(--panel-z);
    width: var(--sidebar-w);
    box-shadow: inset -1px 0 0 var(--divider), var(--elevation-3);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform var(--dur-base) var(--ease-out), visibility 0s linear var(--dur-base);
  }
  .app.is-panel-open .sidebar {
    transform: none;
    visibility: visible;
    transition: transform var(--dur-base) var(--ease-out);
  }
  .sidebar__close { display: inline-grid; }

  .scrim {
    position: fixed;
    inset: 0;
    z-index: calc(var(--panel-z) - 1);
    display: block;
    background: var(--scrim);
  }
  .scrim[hidden] { display: none; }

  .portrait { top: -72px; width: 720px; margin-left: -360px; }
}

/* ---------- mobile < 768: top bar + drawer, sticky input ---------- */

@media (max-width: 767px) {
  :root { --shell-offset: 0px; }
  .app { grid-template-columns: minmax(0, 1fr); }
  .rail { display: none; }

  .sidebar { width: min(var(--drawer-w), 86vw); }

  /* STRUCTURE.md asks for aurora-hero here, but at 390 it floods the top in red and hides the
     portrait; the approved Figma M-01 uses the quiet ambient light. Swap to var(--aurora-hero) to compare. */
  .main { background: var(--aurora-ambient); }

  .servicebar {
    height: var(--mobilebar-h);
    padding: 0 var(--space-4);
    justify-content: space-between;
  }
  .servicebar__menu { display: inline-grid; }
  .servicebar__title {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
  }
  .servicebar__session { display: none; }


  .stage {
    justify-content: flex-start;
    padding: 200px var(--space-4) var(--space-6);
    min-height: 0;
  }
  .portrait { top: -4px; width: 378px; margin-left: -189px; }

  .greeting__time { display: none; }
  .greeting__title {
    margin-top: 0;
    font-size: var(--h2-size);
    line-height: var(--h2-lh);
    letter-spacing: var(--h2-track);
  }
  .greeting__sub {
    max-width: 320px;
    margin-top: 10px;
    font-size: var(--body-size);
    line-height: var(--body-lh);
  }

  .projects-row { display: block; align-self: stretch; margin-top: var(--space-6); }
  .projects-row__label { margin-bottom: 10px; color: var(--text-subtle); }
  .projects-row__list {
    display: flex;
    gap: var(--space-2);
    margin: 0 calc(-1 * var(--space-4));
    padding: 0 var(--space-4);
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-padding-inline: var(--space-4); /* snap to the gutter, not the screen edge */
    scrollbar-width: none;
  }
  .projects-row__list::-webkit-scrollbar { display: none; }
  .projects-row__list > li { flex: none; width: 160px; scroll-snap-align: start; }
  .folder-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    min-height: 94px;
    padding: var(--space-4);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--elevation-1);
    color: var(--text-muted);
  }
  .folder-card__title { color: var(--text); font-weight: 500; }

  .dock {
    max-width: none;
    padding: var(--space-2) var(--space-4) calc(var(--space-4) + env(safe-area-inset-bottom));
    background: linear-gradient(180deg, transparent, var(--bg) 40%);
  }
  .dock__label { display: none; }
  .chips {
    flex-wrap: nowrap;
    margin: 0 calc(-1 * var(--space-4)) var(--space-3);
    padding: 0 var(--space-4);
    overflow-x: auto;
    scrollbar-width: none;
  }
  .chips::-webkit-scrollbar { display: none; }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .portrait img, .status-dot--live::before { animation: none !important; }
}

/* ---------- accessibility details ---------- */

/* Keep focused items clear of the sticky input dock and the service bar (WCAG 2.4.11). */
.content { scroll-padding-top: var(--space-4); scroll-padding-bottom: 240px; }
.folder-card__meta { overflow: hidden; color: var(--text-subtle); letter-spacing: 0.02em; text-overflow: ellipsis; white-space: nowrap; }

@media (min-width: 768px) and (max-width: 1199px) {
  .dock__label { display: none; } /* Figma T-01: no SUGGESTED label on tablet */
}

/* ---------- without JavaScript: one readable page ---------- */

.no-js .main { height: auto; overflow: visible; }
.no-js .content { overflow: visible; }
.no-js .rail,
.no-js .servicebar__menu,
.no-js .composer__slash,
.no-js .feed { display: none; }
.no-js .dock { position: static; }
.no-js body.single-project .content { display: none; }
.no-js .answers-source {
  width: 100%;
  max-width: calc(var(--chat-w) + 2 * var(--space-6));
  margin: 0 auto;
  padding: var(--space-9) var(--space-6);
}
.no-js .answer { scroll-margin-top: var(--space-6); }
.no-js .answer + .answer { margin-top: var(--space-10); padding-top: var(--space-10); box-shadow: inset 0 1px 0 var(--divider); }
.no-js .answer__question {
  margin-bottom: var(--space-4);
  font-size: var(--h3-size);
  line-height: var(--h3-lh);
  font-weight: 500;
  letter-spacing: var(--h3-track);
}
.answers-no-match { display: none; }
.no-js .answers-no-match:target { display: block; margin-top: var(--space-10); color: var(--text); }

@media (max-width: 1199px) {
  .no-js .app { grid-template-columns: minmax(0, 1fr); }
  .no-js .sidebar {
    position: static;
    width: auto;
    height: auto;
    transform: none;
    visibility: visible;
    box-shadow: inset 0 -1px 0 var(--divider);
  }
  .no-js .sidebar__close { display: none; }
  .no-js .profile { margin-top: var(--space-6); }
}

/* ---------- logged in: make room for the WordPress admin bar (32 px, 46 px on narrow screens) ---------- */

.admin-bar { --adminbar: var(--wp-admin--admin-bar--height, 32px); }
.admin-bar .main,
.admin-bar .sidebar,
.admin-bar .rail { height: calc(100dvh - var(--adminbar)); }
.admin-bar .sidebar,
.admin-bar .rail { top: var(--adminbar); }
.admin-bar .portrait { top: calc(var(--adminbar) - 96px); }
@media (max-width: 1199px) {
  .admin-bar .sidebar { top: var(--adminbar); bottom: 0; height: auto; }
  .admin-bar .portrait { top: calc(var(--adminbar) - 72px); }
}
@media (max-width: 767px) {
  .admin-bar .portrait { top: calc(var(--adminbar) - 4px); }
  .admin-bar .viewer { top: var(--adminbar); }
  /* WordPress lets the bar scroll away below 600 px; this app does not scroll the page, so pin it. */
  #wpadminbar { position: fixed; }
}
