:root {
  --bg0: #0b1218;
  --bg1: #121c26;
  --bg2: #182532;
  --line: rgba(168, 200, 220, 0.14);
  --text: #e8f0f5;
  --muted: #8aa0b0;
  --ice: #7ec8e3;
  --ice-dim: rgba(126, 200, 227, 0.15);
  --good: #3dba7a;
  --warn: #e0a84a;
  --bad: #e26a5c;
  --urgent: #ef6b4a;
  --high: #e0a84a;
  --normal: #7ec8e3;
  --low: #8aa0b0;
  --radius: 12px;
  --font: "IBM Plex Sans", system-ui, sans-serif;
  --display: "Syne", "IBM Plex Sans", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(126, 200, 227, 0.12), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(61, 186, 122, 0.06), transparent 50%),
    linear-gradient(180deg, #0a1016 0%, var(--bg0) 40%, #0d151c 100%);
  background-attachment: fixed;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--ice); }

.shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

.rail {
  padding: 1.25rem 1rem;
  border-right: 1px solid var(--line);
  background: rgba(10, 16, 22, 0.72);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; gap: 0.75rem; align-items: center; }
.brand-mark {
  width: 2rem; height: 2rem; border-radius: 0.55rem;
  background:
    linear-gradient(145deg, #9ad7ec, #3a8fb0 55%, #1d4f63);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.08), 0 8px 24px rgba(0,0,0,0.35);
}
.brand-name {
  font-family: var(--display);
  font-weight: 800;
  letter-spacing: -0.03em;
  font-size: 1.05rem;
  line-height: 1.1;
}
.brand-sub { color: var(--muted); font-size: 0.78rem; }

.nav { display: flex; flex-direction: column; gap: 0.25rem; }
.nav button {
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  transition: background 160ms ease, color 160ms ease;
}
.nav button:hover { background: var(--ice-dim); color: var(--text); }
.nav button.is-active {
  background: var(--ice-dim);
  color: var(--ice);
  font-weight: 600;
}

.rail-foot {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem;
}
.pulse {
  width: 0.65rem; height: 0.65rem; border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 0 rgba(126,200,227,0.4);
}
.pulse.ok {
  background: var(--good);
  animation: pulse 2.2s ease-out infinite;
}
.pulse.bad { background: var(--bad); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(61,186,122,0.5); }
  70% { box-shadow: 0 0 0 10px rgba(61,186,122,0); }
  100% { box-shadow: 0 0 0 0 rgba(61,186,122,0); }
}
.rail-meta { font-size: 0.75rem; color: var(--muted); line-height: 1.3; }

.main { padding: 1.25rem 1.5rem 2rem; min-width: 0; }
.top {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; margin-bottom: 1.25rem;
}
.top h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: -0.03em;
  font-size: 1.65rem;
}
.top-actions { display: flex; gap: 0.5rem; }

.view { display: none; animation: fade 220ms ease; }
.view.is-active { display: block; }
@keyframes fade {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.btn {
  border: 1px solid var(--line);
  background: var(--bg2);
  border-radius: 8px;
  padding: 0.5rem 0.85rem;
  text-decoration: none;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: border-color 160ms ease, background 160ms ease;
}
.btn:hover { border-color: rgba(126,200,227,0.45); }
.btn.primary {
  background: linear-gradient(180deg, #8fd0e8, #4fa3c2);
  color: #0b1218;
  border-color: transparent;
  font-weight: 600;
}
.btn.ghost { background: transparent; }
.btn.tiny { padding: 0.3rem 0.55rem; font-size: 0.8rem; }
.btn.danger:hover { border-color: var(--bad); color: #ffc5be; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.stat {
  background: linear-gradient(180deg, rgba(24,37,50,0.9), rgba(18,28,38,0.9));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
}
.stat .label { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; }
.stat .value {
  font-family: var(--display);
  font-size: 1.7rem;
  font-weight: 700;
  margin-top: 0.35rem;
  letter-spacing: -0.03em;
}

.panel-row { display: grid; grid-template-columns: 1.6fr 1fr; gap: 0.75rem; }
.panel {
  background: rgba(18, 28, 38, 0.85);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  min-width: 0;
}
.panel.grow { min-height: 280px; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.75rem; margin-bottom: 0.75rem;
}
.panel-head h2 { margin: 0; font-size: 0.95rem; font-weight: 600; }

.kv { margin: 0; display: grid; gap: 0.55rem; }
.kv div { display: grid; grid-template-columns: 7.5rem 1fr; gap: 0.5rem; font-size: 0.9rem; }
.kv dt { color: var(--muted); margin: 0; }
.kv dd { margin: 0; font-family: var(--mono); font-size: 0.82rem; word-break: break-all; }

.toolbar {
  display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center;
  margin-bottom: 0.75rem;
}
.toolbar input[type="search"],
.toolbar input[type="text"],
.form input {
  background: var(--bg0);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  min-width: 16rem;
}
.form input { width: 100%; min-width: 0; }

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  min-height: 60vh;
}
.list { display: flex; flex-direction: column; gap: 0.45rem; }
.list.tall { overflow: auto; max-height: 70vh; padding-right: 0.25rem; }

.card {
  border: 1px solid var(--line);
  background: rgba(11, 18, 24, 0.55);
  border-radius: 10px;
  padding: 0.75rem 0.85rem;
  text-align: left;
  width: 100%;
  transition: border-color 160ms ease, transform 160ms ease;
}
button.card:hover { border-color: rgba(126,200,227,0.4); transform: translateY(-1px); }
.card.is-selected { border-color: var(--ice); background: var(--ice-dim); }
.card-top { display: flex; justify-content: space-between; gap: 0.5rem; align-items: baseline; }
.card-title { font-weight: 600; font-size: 0.92rem; }
.card-meta { color: var(--muted); font-size: 0.78rem; margin-top: 0.25rem; }
.card-sub { font-family: var(--mono); font-size: 0.75rem; color: var(--muted); margin-top: 0.35rem; }

.badge {
  display: inline-flex; align-items: center;
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.15rem 0.45rem; border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.badge.urgent { color: #ffd0c4; border-color: rgba(239,107,74,0.45); background: rgba(239,107,74,0.12); }
.badge.high { color: #ffe2ad; border-color: rgba(224,168,74,0.45); background: rgba(224,168,74,0.12); }
.badge.normal { color: #c8ebf6; border-color: rgba(126,200,227,0.4); background: var(--ice-dim); }
.badge.low { color: var(--muted); }
.badge.ok { color: #b8f0d0; border-color: rgba(61,186,122,0.4); background: rgba(61,186,122,0.12); }
.badge.err { color: #ffc5be; border-color: rgba(226,106,92,0.45); background: rgba(226,106,92,0.12); }

.detail pre, .editor-wrap textarea, #playOut pre {
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}
.editor-wrap {
  display: flex; flex-direction: column;
}
.editor-wrap textarea {
  flex: 1;
  min-height: 50vh;
  width: 100%;
  resize: vertical;
  background: var(--bg0);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
  margin-bottom: 0.75rem;
}
.form label { display: grid; gap: 0.35rem; font-size: 0.85rem; color: var(--muted); }
.hint { color: var(--muted); font-size: 0.82rem; margin: 0.35rem 0 0.75rem; }
.muted { color: var(--muted); }
.link-list { margin: 0; padding-left: 1.1rem; line-height: 1.7; }
.empty { color: var(--muted); padding: 1rem 0.25rem; }

.decision-block { display: grid; gap: 0.75rem; }
.decision-block .row { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.decision-block h3 { margin: 0; font-size: 1rem; }
.decision-block p { margin: 0; color: var(--text); }

.chat-layout {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 0.75rem;
  min-height: 70vh;
}
.chat-main, .chat-context {
  display: flex;
  flex-direction: column;
  min-height: 70vh;
}
.chat-log {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 0.25rem 0.15rem 0.75rem;
  min-height: 280px;
}
.bubble {
  max-width: 92%;
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  white-space: pre-wrap;
  line-height: 1.45;
  font-size: 0.92rem;
}
.bubble.user {
  align-self: flex-end;
  background: var(--ice-dim);
  border-color: rgba(126, 200, 227, 0.35);
}
.bubble.assistant {
  align-self: flex-start;
  background: rgba(11, 18, 24, 0.7);
}
.bubble .meta {
  display: block;
  margin-top: 0.4rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-family: var(--mono);
}
.chat-compose {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  align-items: end;
}
.chat-compose textarea,
#contextEditor {
  width: 100%;
  resize: vertical;
  background: var(--bg0);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.7rem;
  font: inherit;
  color: inherit;
}
#contextEditor {
  flex: 1;
  min-height: 320px;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.45;
}

@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .stat-grid, .panel-row, .split, .form-grid, .chat-layout { grid-template-columns: 1fr; }
}
