:root {
  --bg: #ffffff;
  --text: #0b1220;
  --muted: #64748b;
  --border: #e5e7eb;
  --primary: #4f46e5;
  --danger: #ef4444;
  --card: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  --radius: 14px;
  --overlay: rgba(2, 6, 23, 0.52);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
}

a { color: inherit; text-decoration: none; }

.topbar {
  position: sticky;
  top: 0;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.topbar__inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.4px;
}

.nav {
  display: flex;
  gap: 12px;
  margin-left: 8px;
}

.nav__link {
  padding: 8px 10px;
  border-radius: 10px;
  color: var(--muted);
  white-space: nowrap;
}

.nav__link:hover { background: #f1f5f9; color: var(--text); }

.topbar__right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 900px) {
  .grid--2 {
    grid-template-columns: 1.2fr 0.8fr;
    align-items: start;
  }
}

.h1 { font-size: 24px; line-height: 1.2; margin: 0 0 8px; }
.h2 { font-size: 18px; line-height: 1.3; margin: 0 0 8px; }
.muted { color: var(--muted); }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text);
  height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
  line-height: 1;
  text-shadow: none;
}

.btn--sm {
  height: 36px;
  padding: 0 10px;
  border-radius: 10px;
  font-size: 13px;
}

.btn--ghost {
  background: transparent;
}

.btn--outline-danger {
  background: transparent;
  border-color: #fecaca;
  color: #b91c1c;
}

.btn--outline-danger:hover {
  background: #fef2f2;
}

.btn:hover { background: #f8fafc; }

.btn--primary {
  background: var(--primary);
  color: #fff;
  border-color: transparent;
}

.btn--primary:hover { filter: brightness(1.04); }

.btn--danger {
  background: var(--danger);
  color: #fff;
  border-color: transparent;
}

.btn[disabled] { opacity: 0.6; cursor: not-allowed; }

.input, .select, .textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
}

.textarea { min-height: 120px; resize: vertical; }

.label { font-size: 13px; color: var(--muted); margin: 10px 0 6px; }

.seg {
  display: inline-flex;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 12px;
  gap: 4px;
  background: #fff;
}

.seg__btn {
  height: 36px;
  padding: 0 12px;
  border-radius: 10px;
  border: 0;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  font-weight: 700;
}

.seg__btn.is-active { background: #eef2ff; color: #3730a3; }

.list { display: grid; gap: 10px; }

.story-item {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
}

@media (max-width: 520px) {
  .topbar__inner {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
  }

  .brand { flex: 1 1 auto; }

  .topbar__right {
    margin-left: 0;
    flex: 0 0 auto;
  }

  .nav {
    order: 3;
    width: 100%;
    margin-left: 0;
    padding: 6px 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }

  .nav__link { flex: 0 0 auto; }

  .container { padding: 12px; }

  .story-item {
    flex-direction: column;
    align-items: stretch;
  }

  .story-item > .row {
    justify-content: flex-start;
  }

  .btn {
    height: 42px;
    padding: 0 12px;
    border-radius: 12px;
  }
}

.badge {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--border);
  color: var(--muted);
}

.node {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: #fff;
}

.node__meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
}

.node__role { font-weight: 900; }

.node__content { white-space: pre-wrap; line-height: 1.7; }

.node__actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.spinner {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 2px solid #c7d2fe;
  border-top-color: #4338ca;
  display: inline-block;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.modal-root {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
}

.modal {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: all;
}

.modal__overlay {
  position: absolute;
  inset: 0;
  background: var(--overlay);
}

.modal__panel {
  position: relative;
  width: min(92vw, 720px);
  max-height: min(80vh, 720px);
  background: #fff;
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
}

.modal__header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal__title { font-weight: 900; }

.modal__body {
  padding: 14px 16px;
  overflow: auto;
}

.modal__footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.composer {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
  background: #fff;
}

@media (max-width: 900px) {
  body.route-edit .container {
    padding-bottom: 260px;
  }

  body.route-edit .composer {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 12px;
    z-index: 20;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.16);
  }

  .modal {
    align-items: flex-end;
  }

  .modal__panel {
    width: 100vw;
    max-height: 86vh;
    border-radius: 18px 18px 0 0;
  }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  padding: 10px 14px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  max-width: min(90vw, 520px);
}

.toast.is-show { opacity: 1; }

.hr { height: 1px; background: var(--border); margin: 12px 0; }

.small { font-size: 12px; }

.alert {
  border: 1px solid #fecaca;
  background: #fef2f2;
  color: #991b1b;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
}

.link {
  color: var(--primary);
  font-weight: 800;
}

.link:hover { text-decoration: underline; }
