/* ==========================================================================
   Flightdeck — пастельно-зелёная мягкая тема.
   Кнопки округлые и слегка выпуклые: свет сверху слева, тень снизу справа.
   ========================================================================== */

:root {
  --bg: #e9f1e7;
  --bg-deep: #dfe9dc;
  --surface: #f2f8f0;
  --surface-raised: #f7fcf5;
  --surface-sunken: #e4ede1;

  --ink: #2c3b2e;
  --ink-soft: #55684f;
  --ink-faint: #8a9b85;

  --accent: #6aa87a;
  --accent-deep: #4f8a5f;
  --accent-soft: #cfe6d3;

  --amber: #d9a441;
  --amber-soft: #f6e6c6;
  --rose: #c77b7b;
  --rose-soft: #f3dcdc;

  --light: #ffffff;
  --shade: #c5d4c2;
  --shade-soft: #d5e0d1;

  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 11px;

  --rail-w: 292px;

  --font: "Segoe UI", "Inter", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Mono", "SF Mono", Consolas, "Liberation Mono", monospace;

  /* выпуклость */
  --raise: 5px 5px 11px var(--shade), -5px -5px 11px var(--light);
  --raise-sm: 3px 3px 7px var(--shade), -3px -3px 7px var(--light);
  --press: inset 3px 3px 7px var(--shade), inset -3px -3px 7px var(--light);
  --press-deep: inset 4px 4px 9px var(--shade), inset -4px -4px 9px var(--light);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #222a23;
    --bg-deep: #1c231d;
    --surface: #283026;
    --surface-raised: #2e3730;
    --surface-sunken: #222a23;

    --ink: #dfe9db;
    --ink-soft: #b3c4ad;
    --ink-faint: #7f9179;

    --accent: #79b98a;
    --accent-deep: #96d2a5;
    --accent-soft: #35472f;

    --amber: #e0b565;
    --amber-soft: #43381f;
    --rose: #d99a9a;
    --rose-soft: #452e2e;

    --light: #333d33;
    --shade: #161c17;
    --shade-soft: #1d241e;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background:
    radial-gradient(1100px 700px at 12% -10%, rgba(255, 255, 255, 0.55), transparent 60%),
    radial-gradient(900px 600px at 105% 110%, rgba(122, 176, 133, 0.18), transparent 55%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

/* ------------------------------------------------------------- кнопки */

.btn {
  font: inherit;
  font-weight: 600;
  color: var(--ink-soft);
  border: none;
  cursor: pointer;
  border-radius: var(--radius-md);
  padding: 10px 18px;
  background: linear-gradient(145deg, var(--surface-raised), var(--bg-deep));
  box-shadow: var(--raise);
  transition:
    box-shadow 0.16s ease,
    transform 0.16s ease,
    color 0.16s ease;
}

.btn:hover {
  color: var(--accent-deep);
  transform: translateY(-1px);
}

.btn:active {
  box-shadow: var(--press);
  transform: translateY(0);
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: var(--raise-sm);
}

.btn-primary {
  color: #fff;
  background: linear-gradient(145deg, #86c294, var(--accent-deep));
  box-shadow:
    4px 4px 10px var(--shade),
    -4px -4px 10px var(--light),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.btn-primary:hover {
  color: #fff;
}

.btn-stop {
  color: #fff;
  background: linear-gradient(145deg, #d99393, #b46a6a);
  box-shadow:
    4px 4px 10px var(--shade),
    -4px -4px 10px var(--light),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.btn-round {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  display: grid;
  place-items: center;
  flex: none;
}

.btn-flat {
  padding: 7px 13px;
  font-size: 13px;
  border-radius: var(--radius-sm);
  box-shadow: var(--raise-sm);
}

/* --------------------------------------------------------------- вход */

.login-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(380px, 100%);
  padding: 34px 30px 28px;
  border-radius: var(--radius-lg);
  background: linear-gradient(145deg, var(--surface-raised), var(--surface));
  box-shadow:
    12px 12px 28px var(--shade),
    -12px -12px 28px var(--light);
  display: grid;
  gap: 16px;
}

.login-hint {
  margin: -6px 0 6px;
  color: var(--ink-faint);
  font-size: 13.5px;
}

.login-error {
  margin: 0;
  color: var(--rose);
  font-size: 13.5px;
  text-align: center;
}

.field {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--ink-faint);
  font-weight: 600;
}

.field input,
.field textarea {
  font: inherit;
  font-weight: 500;
  color: var(--ink);
  padding: 11px 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  box-shadow: var(--press);
}

.field input:focus,
.field textarea:focus {
  outline: none;
  box-shadow:
    var(--press),
    0 0 0 2px var(--accent-soft);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand h1 {
  margin: 0;
  font-size: 19px;
  letter-spacing: 0.3px;
  color: var(--ink);
}

.brand-dot {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 30%, #b8e0c2, var(--accent-deep));
  box-shadow: var(--raise-sm);
  flex: none;
}

/* ------------------------------------------------------------- каркас */

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

/* ------------------------------------------------- левая колонка сессий */

.rail {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 16px 12px 14px;
  gap: 12px;
  background: linear-gradient(160deg, var(--surface), var(--bg-deep));
  box-shadow: 8px 0 22px rgba(90, 116, 92, 0.1);
  z-index: 3;
}

.rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 4px 0;
}

.rail-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 6px 4px 10px;
}

.rail-list::-webkit-scrollbar {
  width: 8px;
}

.rail-list::-webkit-scrollbar-thumb {
  background: var(--shade-soft);
  border-radius: 8px;
}

/* Кнопка сессии: высота растёт под название, текст переносится целиком. */
.session {
  position: relative;
  width: 100%;
  text-align: left;
  font: inherit;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
  border: none;
  border-radius: var(--radius-md);
  padding: 12px 14px 12px 34px;
  background: linear-gradient(145deg, var(--surface-raised), var(--bg-deep));
  box-shadow: var(--raise);
  transition:
    box-shadow 0.16s ease,
    transform 0.16s ease,
    color 0.16s ease;
  display: block;
}

.session:hover {
  transform: translateY(-1px);
  color: var(--accent-deep);
}

.session:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.session.selected {
  color: var(--accent-deep);
  box-shadow:
    var(--press),
    0 0 0 2px var(--accent-soft);
  transform: none;
}

.session-title {
  display: block;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.session-meta {
  display: block;
  margin-top: 5px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-faint);
  overflow-wrap: anywhere;
}

/* Огонёк статуса слева. */
.session::before {
  content: "";
  position: absolute;
  left: 13px;
  top: 17px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--shade-soft);
  box-shadow: inset 1px 1px 2px var(--shade), inset -1px -1px 2px var(--light);
}

.session[data-status="done_unread"]::before {
  background: radial-gradient(circle at 32% 30%, #b6e6c2, var(--accent));
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.session[data-status="read"]::before {
  background: var(--shade);
  box-shadow: none;
}

.session[data-running="true"]::before {
  background: radial-gradient(circle at 32% 30%, #f5dda6, var(--amber));
  animation: pulse 1.25s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(217, 164, 65, 0.55);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(217, 164, 65, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .session[data-running="true"]::before {
    animation: none;
  }
}

/* Подсветка всей кнопки по разряду. */
.session[data-status="done_unread"] {
  background: linear-gradient(145deg, #f4fbf3, #dcebdd);
  color: var(--accent-deep);
}

.session[data-status="read"] {
  color: var(--ink-faint);
  background: linear-gradient(145deg, var(--surface), var(--bg-deep));
  box-shadow: var(--raise-sm);
}

.session[data-running="true"] {
  background: linear-gradient(145deg, #fdf7e9, #eadfc9);
  color: #8a6a26;
}

.session.dragging {
  opacity: 0.45;
}

.session.drop-before {
  box-shadow:
    var(--raise),
    0 -3px 0 -1px var(--accent);
}

.session.drop-after {
  box-shadow:
    var(--raise),
    0 3px 0 -1px var(--accent);
}

.rail-foot {
  display: grid;
  gap: 10px;
  padding: 10px 6px 2px;
  border-top: 1px solid var(--shade-soft);
}

.rail-actions {
  display: flex;
  gap: 8px;
}

.rail-actions .btn {
  flex: 1;
}

.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.pill {
  font-size: 11.5px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 999px;
  color: var(--ink-soft);
  background: var(--surface-sunken);
  box-shadow: var(--press);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

.pill[data-down="true"] {
  color: var(--rose);
}

.pill[data-down="true"]::before {
  background: var(--rose);
}

/* ------------------------------------------------------- правая колонка */

.stage {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
}

.stage-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 22px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.4), transparent);
}

.stage-title {
  flex: 1;
  min-width: 0;
}

.stage-title h2 {
  margin: 0;
  font-size: 17px;
  overflow-wrap: anywhere;
}

.stage-sub {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--ink-faint);
  overflow-wrap: anywhere;
}

.select-wrap select {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  border: none;
  cursor: pointer;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  background: linear-gradient(145deg, var(--surface-raised), var(--bg-deep));
  box-shadow: var(--raise-sm);
}

.select-wrap select:focus-visible {
  outline: 2px solid var(--accent);
}

.rail-toggle {
  display: none;
}

/* --------------------------------------------------------------- лента */

.transcript {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.transcript::-webkit-scrollbar {
  width: 10px;
}

.transcript::-webkit-scrollbar-thumb {
  background: var(--shade-soft);
  border-radius: 10px;
}

.empty {
  margin: auto;
  text-align: center;
  color: var(--ink-soft);
}

.muted {
  color: var(--ink-faint);
  font-size: 13.5px;
}

.msg {
  max-width: min(820px, 100%);
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--raise-sm);
  overflow-wrap: anywhere;
}

.msg-user {
  align-self: flex-end;
  background: linear-gradient(145deg, #dcefdf, #c9e2ce);
  color: #23412c;
  border-bottom-right-radius: 6px;
}

.msg-assistant {
  align-self: flex-start;
  border-bottom-left-radius: 6px;
}

.msg-system {
  align-self: center;
  max-width: min(700px, 100%);
  font-size: 13px;
  padding: 10px 16px;
  background: var(--surface-sunken);
  box-shadow: var(--press);
  color: var(--ink-soft);
}

.msg-system.kind-error {
  color: #8a4a4a;
  background: var(--rose-soft);
}

.msg-system.kind-handoff {
  color: #7a5c1c;
  background: var(--amber-soft);
}

.msg-head {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 6px;
}

.msg-body p {
  margin: 0 0 9px;
}

.msg-body p:last-child {
  margin-bottom: 0;
}

.msg-body pre {
  margin: 10px 0;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  box-shadow: var(--press);
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
}

.msg-body code {
  font-family: var(--mono);
  font-size: 0.92em;
  padding: 1px 5px;
  border-radius: 6px;
  background: var(--surface-sunken);
}

.msg-body pre code {
  padding: 0;
  background: none;
}

.msg-body ul,
.msg-body ol {
  margin: 8px 0;
  padding-left: 22px;
}

/* Полоска дел агента: чем он занят прямо сейчас. */
.tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.tool-chip {
  font-size: 11.5px;
  font-family: var(--mono);
  padding: 4px 10px;
  border-radius: 999px;
  color: var(--ink-soft);
  background: var(--surface-sunken);
  box-shadow: var(--press);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.typing {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-left: 3px;
  border-radius: 50%;
  background: var(--accent);
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink {
  50% {
    opacity: 0.2;
  }
}

/* ------------------------------------------------------- нижнее поле */

.composer {
  padding: 10px 22px 16px;
  background: linear-gradient(0deg, rgba(255, 255, 255, 0.35), transparent);
}

.composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-lg);
  background: var(--surface-sunken);
  box-shadow: var(--press-deep);
}

.composer textarea {
  flex: 1;
  min-width: 0;
  font: inherit;
  color: var(--ink);
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  padding: 8px 6px;
  max-height: 40vh;
  line-height: 1.5;
}

.composer textarea::placeholder {
  color: var(--ink-faint);
}

.composer-side {
  display: flex;
  gap: 8px;
  flex: none;
}

.composer-note {
  margin: 8px 4px 0;
  min-height: 16px;
  font-size: 12px;
  color: var(--ink-faint);
}

/* ------------------------------------------------- контекстное меню */

.menu {
  position: fixed;
  z-index: 50;
  min-width: 226px;
  padding: 7px;
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  box-shadow:
    8px 8px 22px var(--shade),
    -6px -6px 18px var(--light);
}

.menu button {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 13.5px;
  color: var(--ink-soft);
  border: none;
  background: transparent;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.menu button:hover {
  background: var(--surface-sunken);
  color: var(--accent-deep);
}

.menu button[disabled] {
  opacity: 0.45;
  cursor: default;
}

.menu button.danger:hover {
  color: var(--rose);
}

.menu-sep {
  height: 1px;
  margin: 5px 8px;
  background: var(--shade-soft);
}

.menu-label {
  padding: 7px 11px 3px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
  box-shadow: var(--raise-sm);
}

.dot-idle {
  background: var(--shade-soft);
}
.dot-done {
  background: var(--accent);
}
.dot-read {
  background: var(--shade);
}

/* ---------------------------------------------------------- диалоги */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(40, 56, 42, 0.32);
  backdrop-filter: blur(3px);
}

.modal-card {
  width: min(460px, 100%);
  max-height: 84dvh;
  overflow-y: auto;
  padding: 24px;
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
  box-shadow:
    14px 14px 32px var(--shade),
    -10px -10px 26px var(--light);
}

.modal-card h3 {
  margin: 0 0 14px;
  font-size: 17px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  margin-top: 20px;
}

.health-grid {
  display: grid;
  gap: 10px;
  font-size: 13.5px;
}

.health-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 13px;
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  box-shadow: var(--press);
}

.health-row span:last-child {
  color: var(--ink-faint);
  text-align: right;
  overflow-wrap: anywhere;
}

/* ----------------------------------------------------------- всплывашки */

.toast-stack {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 70;
  display: grid;
  gap: 9px;
  max-width: min(340px, calc(100vw - 36px));
}

.toast {
  padding: 11px 15px;
  font-size: 13.5px;
  border-radius: var(--radius-md);
  color: var(--ink);
  background: var(--surface-raised);
  box-shadow:
    7px 7px 18px var(--shade),
    -5px -5px 14px var(--light);
  animation: slide-in 0.2s ease;
}

.toast.error {
  color: #8a4a4a;
  background: var(--rose-soft);
}

@keyframes slide-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* -------------------------------------------------------------- узкий */

@media (max-width: 860px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
  }

  .rail {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(var(--rail-w), 86vw);
    transform: translateX(-102%);
    transition: transform 0.22s ease;
  }

  .rail.open {
    transform: none;
  }

  .rail-toggle {
    display: grid;
  }

  .stage-head,
  .transcript,
  .composer {
    padding-left: 16px;
    padding-right: 16px;
  }

  .stage-tools {
    display: none;
  }
}
