:root {
  --bg: #0d1018;
  --bg-2: #131820;
  --panel: rgba(16, 20, 32, 0.88);
  --panel-2: rgba(22, 28, 46, 0.92);
  --line: rgba(255, 165, 80, 0.14);
  --text: #edf3ff;
  --muted: #9fb0d4;
  --accent: #ff9f43;
  --accent-2: #ffcc80;
  --danger: #ff7f96;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
  --radius: 22px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255, 159, 67, 0.15), transparent 32%),
    radial-gradient(circle at top right, rgba(255, 204, 128, 0.10), transparent 28%),
    linear-gradient(160deg, #08101d 0%, #0e1420 45%, #141a2e 100%);
}

button, input, textarea, select { font: inherit; }

/* ── Раскладка ── */

.app-shell {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 24px;
  padding: 28px;
  min-height: 100vh;
  align-items: start;
}

.sidebar, .main {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── Шапка ── */

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 6px 4px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: linear-gradient(145deg, rgba(255, 159, 67, 0.95), rgba(255, 204, 128, 0.95));
  box-shadow: var(--shadow);
  flex-shrink: 0;
}

.brand-kicker, .eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 11px;
  color: var(--muted);
}

h1, h2, h3, p { margin: 0; }

h1, h2 {
  font-family: "Avenir Next Condensed", "Avenir Next", sans-serif;
  letter-spacing: 0.02em;
}

.sidebar-description {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  padding: 0 4px;
}

/* ── Панели ── */

.panel {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  backdrop-filter: blur(18px);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
}

/* ── Список сессий ── */

.session-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 44vh;
  overflow: auto;
  margin-bottom: 14px;
}

.session-empty {
  color: var(--muted);
  font-size: 14px;
  padding: 12px 4px;
}

.session-card {
  width: 100%;
  text-align: left;
  border: 1px solid rgba(255, 159, 67, 0.12);
  border-radius: 16px;
  padding: 12px 14px;
  background: rgba(6, 12, 24, 0.5);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  color: var(--text);
}

.session-card:hover {
  background: rgba(14, 24, 46, 0.7);
  border-color: rgba(255, 159, 67, 0.28);
}

.session-card.active {
  border-color: rgba(255, 159, 67, 0.6);
  background: rgba(255, 159, 67, 0.06);
}

.card-name {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 4px;
  color: var(--text);
}

.card-status {
  font-size: 13px;
  color: var(--text);
  margin-bottom: 2px;
}

.card-cwd {
  font-size: 12px;
  color: var(--muted);
  font-family: "SFMono-Regular", "Menlo", monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-list-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.new-agent-btn {
  width: 100%;
  background: rgba(255, 159, 67, 0.12);
  color: var(--accent);
  border: 1px dashed rgba(255, 159, 67, 0.35);
  border-radius: 14px;
  padding: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.new-agent-btn:hover {
  background: rgba(255, 159, 67, 0.2);
}

.delete-stopped-btn {
  width: 100%;
  font-size: 13px;
  padding: 9px;
  color: var(--muted);
  border-color: rgba(159, 176, 212, 0.15);
}

/* ── Форма создания ── */

.stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

label span {
  color: var(--muted);
  font-size: 13px;
}

.field-hint {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

input, textarea, select {
  width: 100%;
  border: 1px solid rgba(159, 176, 212, 0.18);
  border-radius: 14px;
  background: rgba(8, 14, 28, 0.72);
  color: var(--text);
  padding: 12px 14px;
  color-scheme: dark;
}

input::placeholder, textarea::placeholder {
  color: rgba(159, 176, 212, 0.45);
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: rgba(255, 159, 67, 0.45);
}

select option {
  background: #131820;
  color: var(--text);
}

textarea {
  resize: vertical;
  min-height: 100px;
  max-width: 1147px;
}

/* ── Кнопки ── */

button {
  border: 0;
  border-radius: 14px;
  padding: 11px 16px;
  color: #08101d;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  cursor: pointer;
  font-weight: 700;
  transition: opacity 0.15s;
}

button:hover { opacity: 0.88; }

button.ghost {
  background: rgba(255, 159, 67, 0.10);
  color: var(--text);
  border: 1px solid rgba(255, 159, 67, 0.20);
}

button.danger {
  background: rgba(255, 127, 150, 0.16);
  color: #ffd3db;
  border: 1px solid rgba(255, 127, 150, 0.28);
}

button.hidden { display: none; }

/* ── Заголовок агента ── */

.agent-header-panel {
  padding: 20px 22px;
}

.agent-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  flex-wrap: wrap;
}

.agent-title-block h2 {
  font-size: 22px;
  margin-bottom: 6px;
}

.agent-meta-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.status-badge {
  font-size: 14px;
  font-weight: 600;
}

.muted-text {
  font-size: 13px;
  color: var(--muted);
  font-family: "SFMono-Regular", "Menlo", monospace;
  word-break: break-all;
}

.agent-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.action-btn {
  padding: 9px 14px;
  font-size: 14px;
}

.approve-btn {
  padding: 9px 16px;
  font-size: 14px;
  background: linear-gradient(135deg, #6df0c2, #9ff7de);
  color: #08101d;
  font-weight: 700;
  border-radius: 14px;
  border: 0;
  cursor: pointer;
  animation: pulse-green 1.8s ease-in-out infinite;
}

.reject-btn {
  padding: 9px 16px;
  font-size: 14px;
  background: rgba(255, 127, 150, 0.16);
  color: #ffd3db;
  border: 1px solid rgba(255, 127, 150, 0.28);
  font-weight: 700;
  border-radius: 14px;
  cursor: pointer;
}

@keyframes pulse-green {
  0%, 100% { box-shadow: 0 0 0 0 rgba(109, 240, 194, 0.0); }
  50%       { box-shadow: 0 0 0 8px rgba(109, 240, 194, 0.18); }
}

/* ── Детали approval ── */

.approval-detail {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255, 127, 80, 0.08);
  border: 1px solid rgba(255, 127, 80, 0.2);
  font-size: 13px;
  color: var(--muted);
}

.approval-detail code {
  display: block;
  margin-top: 6px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(7, 16, 31, 0.9);
  color: #def3ea;
  font-family: "SFMono-Regular", "Menlo", monospace;
  font-size: 12px;
  word-break: break-all;
}

/* ── Вывод агента ── */

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

.stream-indicator {
  font-size: 16px;
  color: var(--muted);
  transition: color 0.3s;
}

.stream-indicator.stream-on {
  color: #6df0c2;
  text-shadow: 0 0 8px rgba(109, 240, 194, 0.6);
}

.stream-indicator.stream-off {
  color: rgba(159, 176, 212, 0.3);
}

.tail-output {
  margin: 0;
  min-height: calc(67vh - 160px);
  max-height: calc(67vh - 80px);
  max-width: 1147px;
  overflow: auto;
  padding: 16px 18px;
  border-radius: 16px;
  background: #07101f;
  border: 1px solid rgba(255, 159, 67, 0.10);
  color: #def3ea;
  line-height: 1.48;
  font-family: "SFMono-Regular", "Menlo", monospace;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Пустое состояние ── */

.empty-state {
  text-align: center;
  padding: 60px 40px;
}

.empty-icon {
  font-size: 52px;
  margin-bottom: 18px;
}

.empty-state h2 {
  font-size: 22px;
  margin-bottom: 10px;
}

.empty-state p {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
  max-width: 380px;
  margin: 0 auto 10px;
}

.muted-hint {
  font-size: 13px;
  color: rgba(159, 176, 212, 0.6);
}

/* ── Логин ── */

#login-dialog {
  border: 0;
  background: transparent;
  padding: 0;
}

#login-dialog::backdrop {
  background: rgba(3, 7, 17, 0.82);
}

.login-card {
  width: min(400px, calc(100vw - 24px));
  background: linear-gradient(180deg, rgba(8, 14, 28, 0.97), rgba(17, 27, 50, 0.97));
  border: 1px solid rgba(255, 159, 67, 0.2);
  border-radius: 24px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.error-text {
  color: #ffb0bf;
  min-height: 1.2em;
  font-size: 14px;
}

/* ── Terminal info ── */

.terminal-info {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(7, 16, 31, 0.7);
  border: 1px solid rgba(159, 176, 212, 0.12);
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.terminal-info code {
  font-family: "SFMono-Regular", "Menlo", monospace;
  color: #9ff7de;
  background: rgba(0, 0, 0, 0.3);
  padding: 2px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.terminal-info code:hover {
  background: rgba(109, 240, 194, 0.12);
}

/* ── Адаптив ── */

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .agent-header {
    flex-direction: column;
  }

  .agent-actions {
    width: 100%;
  }

  .action-btn {
    flex: 1;
    text-align: center;
  }
}
