/* ============================================================
   Maclaren Dispatch — Glass Editorial
   Dark OLED · frosted glass cards · Fraunces serif headlines
   · JetBrains Mono body · mint accent · mobile-first
   ============================================================ */

:root {
  --bg: #050505;
  --bg-2: #0c0c0d;
  --surface: rgba(255, 255, 255, 0.028);
  --surface-2: rgba(255, 255, 255, 0.05);
  --hairline: rgba(255, 255, 255, 0.07);
  --hairline-soft: rgba(255, 255, 255, 0.04);
  --fg: #f4f1ec;
  --fg-dim: rgba(244, 241, 236, 0.62);
  --fg-mute: rgba(244, 241, 236, 0.32);
  --accent: #6ee7c7;
  --accent-2: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --good: #6ee7c7;
  --r: 24px;
  --r-card: 32px;
  --r-pill: 999px;
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --t-fast: 200ms;
  --t-med: 400ms;
  --t-slow: 700ms;
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bot: env(safe-area-inset-bottom, 0);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--fg);
  font-family: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
  min-height: 100dvh;
}

/* radial mesh background (fixed) */
.mesh {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(ellipse 80% 60% at 18% 8%,  rgba(110, 231, 199, 0.09), transparent 60%),
    radial-gradient(ellipse 60% 50% at 92% 88%, rgba(110, 231, 199, 0.05), transparent 60%),
    radial-gradient(ellipse 100% 80% at 50% 100%, rgba(14, 14, 16, 0.6), transparent);
  animation: meshDrift 30s ease-in-out infinite alternate;
}
@keyframes meshDrift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(0, -2%, 0) scale(1.04); }
}

/* film grain (fixed, pointer-events none) */
.grain {
  position: fixed; inset: 0; z-index: 1; pointer-events: none;
  opacity: 0.05;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='180' height='180' filter='url(%23n)'/></svg>");
  background-size: 180px 180px;
  mix-blend-mode: overlay;
}

#app {
  position: relative; z-index: 2;
  min-height: 100dvh;
  display: flex; flex-direction: column;
  padding-top: calc(var(--safe-top) + 64px);
  padding-bottom: var(--safe-bot);
}

/* ============ ISLAND (floating top pill) ============ */
.island {
  position: fixed;
  top: calc(var(--safe-top) + 10px);
  left: 12px; right: 12px;
  z-index: 10;
  display: flex; align-items: center; gap: 6px;
  height: 44px;
  padding: 0 6px 0 4px;
  background: rgba(20, 20, 22, 0.5);
  border: 1px solid var(--hairline);
  border-radius: var(--r-pill);
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 8px 32px rgba(0, 0, 0, 0.4);
  animation: islandIn var(--t-slow) var(--ease) both;
  animation-delay: 80ms;
}
@keyframes islandIn {
  from { opacity: 0; transform: translateY(-8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.island .back,
.island .refresh {
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; color: var(--fg);
  border: none; border-radius: 50%;
  cursor: pointer;
  transition: transform var(--t-fast) var(--ease), background-color var(--t-fast) var(--ease);
  -webkit-appearance: none; appearance: none;
}
.island .back:active,
.island .refresh:active { transform: scale(0.9); background: rgba(255, 255, 255, 0.05); }
.island .back[hidden] { display: none; }

.island .status {
  flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0;
  padding-left: 6px;
}
.status-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--fg-mute);
  flex-shrink: 0;
  transition: background-color var(--t-med) var(--ease), box-shadow var(--t-med) var(--ease);
}
.status-dot.good {
  background: var(--good);
  box-shadow: 0 0 10px rgba(110, 231, 199, 0.6);
  animation: dotPulse 2.4s var(--ease) infinite;
}
.status-dot.bad {
  background: var(--bad);
  box-shadow: 0 0 10px rgba(248, 113, 113, 0.6);
}
@keyframes dotPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}
.status-text {
  font-size: 12px; font-weight: 500;
  color: var(--fg-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  letter-spacing: 0.02em;
}

/* ============ PAGES ============ */
main { flex: 1; }
.page {
  padding: 8px 18px 24px;
  max-width: 720px; margin: 0 auto;
  animation: pageIn var(--t-slow) var(--ease) both;
}
@keyframes pageIn {
  from { opacity: 0; transform: translateY(10px); filter: blur(4px); }
  to   { opacity: 1; transform: translateY(0); filter: blur(0); }
}

.page-head { padding: 28px 0 26px; }
.eyebrow {
  display: inline-block;
  font-size: 10px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.22em;
  color: var(--fg-mute);
  padding: 5px 11px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-pill);
  margin-bottom: 20px;
}

.title {
  font-family: "Fraunces", "Iowan Old Style", "Times New Roman", Georgia, serif;
  font-size: 46px; font-weight: 400;
  line-height: 1; letter-spacing: -0.025em;
  color: var(--fg);
  margin: 0 0 14px;
  font-variation-settings: "opsz" 96, "SOFT" 30;
}
.title-sm {
  font-family: "Fraunces", "Iowan Old Style", Georgia, serif;
  font-size: 26px; font-weight: 400;
  line-height: 1.1; letter-spacing: -0.015em;
  margin: 6px 0 0;
  font-variation-settings: "opsz" 48;
  color: var(--fg);
}
.lede {
  font-size: 13px; color: var(--fg-dim);
  max-width: 34ch;
  margin: 0;
  line-height: 1.55;
}

/* ============ GRID (groups, bento-ish) ============ */
.grid {
  list-style: none; padding: 0; margin: 0;
  display: grid; gap: 12px;
  grid-template-columns: 1fr;
}
@media (min-width: 480px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .grid > li:first-child { grid-column: 1 / -1; }
}

/* ============ LIST (sessions) ============ */
.list {
  list-style: none; padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 10px;
}

/* ============ DOUBLE-BEZEL CARD ============ */
.bz {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-card);
  padding: 1.5px;
  transition: transform var(--t-med) var(--ease), border-color var(--t-med) var(--ease);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.04) inset,
    0 8px 24px rgba(0, 0, 0, 0.3);
}
.bz:active { transform: scale(0.985); }
.bz-core {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.025), rgba(255, 255, 255, 0));
  border-radius: calc(var(--r-card) - 1.5px);
  padding: 20px 22px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
  display: flex; align-items: center; gap: 14px;
  text-align: left; width: 100%;
  color: var(--fg);
  font: inherit;
  -webkit-appearance: none; appearance: none;
  cursor: pointer;
}
.bz-grow { flex: 1; min-width: 0; }
.bz-name {
  font-family: "Fraunces", "Iowan Old Style", Georgia, serif;
  font-size: 24px; font-weight: 400;
  letter-spacing: -0.012em;
  line-height: 1.1;
  margin: 0 0 4px;
  font-variation-settings: "opsz" 48;
  color: var(--fg);
}
.bz-sub {
  font-size: 10.5px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.18em;
  color: var(--fg-mute);
}
.bz-badge {
  flex-shrink: 0;
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 500;
  padding: 5px 10px 5px 9px;
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--hairline);
  color: var(--fg-dim);
  white-space: nowrap;
  transition: color var(--t-fast) var(--ease);
}
.bz-badge .pip { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.bz-badge.good { color: var(--good); border-color: rgba(110, 231, 199, 0.25); background: rgba(110, 231, 199, 0.06); }
.bz-badge.warn { color: var(--warn); border-color: rgba(251, 191, 36, 0.25); background: rgba(251, 191, 36, 0.06); }
.bz-badge.bad  { color: var(--bad);  border-color: rgba(248, 113, 113, 0.25); background: rgba(248, 113, 113, 0.06); }

/* compact session card */
.bz-sm .bz-core { padding: 14px 18px; }
.bz-sm .bz-name {
  font-family: "JetBrains Mono", monospace;
  font-size: 14px; font-weight: 500;
  letter-spacing: 0;
  font-variation-settings: normal;
  margin: 0 0 3px;
}
.bz-sm .bz-sub { font-size: 10px; }

/* ============ CHAT ============ */
.chat-page {
  display: flex; flex-direction: column;
  min-height: calc(100dvh - 100px - var(--safe-top) - var(--safe-bot));
  padding-bottom: 0;
}
.chat-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 22px 0 18px;
}
.chat-head-meta { flex: 1; min-width: 0; }
.chat-sub {
  font-size: 10.5px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.18em;
  color: var(--fg-mute);
  margin-top: 6px;
}

.icon-pill {
  width: 38px; height: 38px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 50%;
  color: var(--fg-dim);
  cursor: pointer;
  -webkit-appearance: none; appearance: none;
  flex-shrink: 0;
  transition: transform var(--t-fast) var(--ease), color var(--t-fast) var(--ease), background-color var(--t-fast) var(--ease);
}
.icon-pill:active { transform: scale(0.9); }
.icon-pill:hover { color: var(--fg); background: var(--surface-2); }

.messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 6px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--fg);
  outline: none;
  border-top: 1px solid var(--hairline-soft);
  border-bottom: 1px solid var(--hairline-soft);
}
.messages:empty::before {
  content: "(пусто)";
  color: var(--fg-mute);
  font-style: italic;
  font-size: 13px;
}

/* ============ COMPOSER ============ */
.composer {
  display: flex; align-items: flex-end; gap: 10px;
  padding: 14px 2px 8px;
}
.composer textarea {
  flex: 1;
  min-height: 48px; max-height: 140px;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-pill);
  color: var(--fg);
  font: 14px/1.5 "JetBrains Mono", monospace;
  resize: none; outline: none;
  -webkit-appearance: none; appearance: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transition: border-color var(--t-fast) var(--ease), background-color var(--t-fast) var(--ease);
}
.composer textarea::placeholder { color: var(--fg-mute); }
.composer textarea:focus {
  border-color: rgba(110, 231, 199, 0.4);
  background: rgba(255, 255, 255, 0.04);
}

/* button-in-button send */
.send {
  flex-shrink: 0;
  width: 48px; height: 48px;
  background: var(--accent);
  color: #052e23;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  -webkit-appearance: none; appearance: none;
  display: inline-flex; align-items: center; justify-content: center;
  transition: transform var(--t-fast) var(--ease-spring), opacity var(--t-fast) var(--ease);
  box-shadow:
    0 6px 20px rgba(110, 231, 199, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}
.send:active { transform: scale(0.9); }
.send:disabled { opacity: 0.3; cursor: not-allowed; }
.send-icon {
  display: inline-flex;
  transition: transform var(--t-med) var(--ease);
}
.send:hover .send-icon { transform: translateY(-1px) scale(1.08); }

/* ============ TOAST ============ */
.toast {
  position: fixed;
  left: 50%; bottom: calc(96px + var(--safe-bot));
  transform: translateX(-50%) translateY(8px);
  background: rgba(20, 20, 22, 0.88);
  border: 1px solid var(--hairline);
  border-radius: var(--r-pill);
  padding: 9px 16px;
  font-size: 12px;
  color: var(--fg);
  z-index: 100;
  max-width: 80vw;
  text-align: center;
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  opacity: 0;
  transition: opacity var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.toast:not([hidden]) { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============ RESPONSIVE ============ */
@media (max-width: 380px) {
  .title { font-size: 38px; }
  .bz-name { font-size: 20px; }
  .bz-core { padding: 16px 18px; }
}

/* respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  .mesh { animation: none; }
  .status-dot.good { animation: none; }
  .page { animation: none; }
  .island { animation: none; }
  * { transition-duration: 0.01ms !important; }
}
