:root {
  --bg-0: #f4f5ef;
  --bg-1: #e5ebdc;
  --bg-2: #d6dfcd;
  --ink: #142021;
  --ink-soft: #3f4a42;
  --panel: #fbfcf7;
  --line: #96a588;
  --accent: #b33a3a;
  --accent-2: #2f5d62;
  --success: #2f7a45;
  --danger: #a32626;
  --shadow: 0 10px 28px rgba(20, 32, 33, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Space Grotesk", sans-serif;
  background:
    radial-gradient(circle at 12% 16%, rgba(179, 58, 58, 0.11), transparent 34%),
    radial-gradient(circle at 92% 78%, rgba(47, 93, 98, 0.18), transparent 31%),
    linear-gradient(145deg, var(--bg-0), var(--bg-1) 48%, var(--bg-2));
  min-height: 100vh;
}

.app-shell {
  width: min(1380px, calc(100vw - 2rem));
  margin: 1rem auto;
  background: rgba(251, 252, 247, 0.88);
  border: 1px solid rgba(150, 165, 136, 0.42);
  border-radius: 22px;
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
}

.topbar {
  display: grid;
  gap: 1rem;
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid rgba(150, 165, 136, 0.4);
  background:
    linear-gradient(120deg, rgba(179, 58, 58, 0.06), rgba(47, 93, 98, 0.08)),
    rgba(255, 255, 255, 0.74);
}

.eyebrow {
  margin: 0;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 700;
}

.topbar h1 {
  margin: 0.1rem 0 0;
  font-size: clamp(1.55rem, 2.2vw, 2.15rem);
  line-height: 1.1;
}

.subtitle {
  margin: 0.35rem 0 0;
  color: var(--ink-soft);
  max-width: 68ch;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: end;
}

.control-group {
  display: grid;
  gap: 0.25rem;
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.control-group select {
  min-width: 180px;
}

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

input,
select,
textarea {
  border: 1px solid rgba(93, 108, 98, 0.42);
  border-radius: 10px;
  padding: 0.55rem 0.66rem;
  background: #f7f8f2;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

.btn {
  border: 1px solid rgba(60, 76, 66, 0.44);
  border-radius: 11px;
  background: #f8faf3;
  color: var(--ink);
  cursor: pointer;
  padding: 0.5rem 0.8rem;
  line-height: 1.2;
  transition: transform 120ms ease, background-color 120ms ease, border-color 120ms ease;
}

.btn:hover {
  transform: translateY(-1px);
  background: #ffffff;
  border-color: rgba(60, 76, 66, 0.65);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: linear-gradient(128deg, #c64848, #914141 56%, #6b2f2f);
  color: #fff;
  border-color: rgba(0, 0, 0, 0.22);
}

.btn-primary:hover {
  background: linear-gradient(128deg, #d14f4f, #9d4747 56%, #713333);
}

.btn-danger {
  color: #fff;
  background: linear-gradient(132deg, #bf2f2f, #992323);
  border-color: rgba(0, 0, 0, 0.24);
}

.btn-ghost {
  border: none;
  background: transparent;
  color: var(--ink-soft);
}

.btn-small {
  font-size: 0.82rem;
  padding: 0.35rem 0.57rem;
  border-radius: 8px;
}

.file-btn {
  position: relative;
  overflow: hidden;
}

.file-btn input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.workspace {
  padding: 1rem;
}

.timeline-wrap {
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(150, 165, 136, 0.45);
  border-radius: 16px;
  min-height: 61vh;
  max-height: 72vh;
  overflow: auto;
  padding: 1rem 1rem 1.4rem;
}

.timeline-tree {
  display: grid;
  gap: 0.95rem;
}

.timeline-tree.columns-mode {
  display: flex;
  gap: 0.95rem;
  align-items: flex-start;
  overflow-x: auto;
  padding-bottom: 0.2rem;
}

.timeline-tree.columns-mode > .branch {
  flex: 0 0 min(420px, calc(100vw - 4.2rem));
  width: min(420px, calc(100vw - 4.2rem));
}

.empty-state {
  text-align: center;
  padding: 2.2rem 1rem;
}

.empty-state h2 {
  margin: 0.2rem 0 0.35rem;
  font-size: 1.26rem;
}

.empty-state p {
  margin: 0 0 1rem;
  color: var(--ink-soft);
}

.hidden {
  display: none !important;
}

.branch {
  border: 1px solid rgba(150, 165, 136, 0.44);
  border-radius: 16px;
  background: linear-gradient(178deg, rgba(255, 255, 255, 0.84), rgba(249, 250, 244, 0.88));
  padding: 0.8rem;
  position: relative;
  animation: pop-in 220ms ease;
}

.branch::before {
  content: "";
  position: absolute;
  left: 0.38rem;
  top: 0.74rem;
  bottom: 0.74rem;
  width: 3px;
  border-radius: 6px;
  background: var(--branch-color, var(--accent-2));
}

.branch.depth-0 {
  margin-left: 0;
}

.branch.depth-1 {
  margin-left: 1rem;
}

.branch.depth-2 {
  margin-left: 2rem;
}

.branch.depth-3,
.branch.depth-4,
.branch.depth-5 {
  margin-left: 2.8rem;
}

.branch-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  padding-left: 0.9rem;
}

.branch-title-wrap {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.branch-dot {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 999px;
  background: var(--branch-color, var(--accent-2));
  box-shadow: 0 0 0 3px rgba(47, 93, 98, 0.18);
}

.branch-title-wrap h3 {
  margin: 0;
  font-size: 1rem;
}

.branch-meta {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.8rem;
}

.branch-actions {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.branch-events {
  display: grid;
  gap: 0.7rem;
  padding-left: 0.9rem;
  margin-top: 0.65rem;
}

.split-origin {
  margin: 0.62rem 0 0.2rem 0.9rem;
  border: 1px dashed rgba(90, 109, 97, 0.5);
  border-radius: 10px;
  background: rgba(243, 247, 236, 0.72);
  padding: 0.44rem 0.56rem;
}

.split-origin-label {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.67rem;
  color: var(--accent-2);
  font-weight: 700;
}

.split-origin-main {
  margin: 0.16rem 0 0;
  font-size: 0.84rem;
}

.split-origin-time {
  margin: 0.22rem 0 0;
  font-size: 0.76rem;
  font-family: "IBM Plex Mono", monospace;
  color: var(--ink-soft);
}

.event-card {
  border: 1px solid rgba(76, 95, 84, 0.33);
  border-radius: 13px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.94), rgba(247, 249, 241, 0.82));
  padding: 0.72rem;
  position: relative;
  animation: card-fade 280ms ease both;
}

.event-card::before {
  content: "";
  position: absolute;
  left: -0.95rem;
  top: 1.35rem;
  width: 0.85rem;
  height: 2px;
  background: var(--line);
}

.event-row {
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  align-items: start;
}

.event-time {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.78rem;
  color: var(--accent-2);
  margin: 0;
}

.event-title {
  margin: 0.15rem 0 0;
  font-size: 1.03rem;
  line-height: 1.25;
}

.event-text {
  margin: 0.48rem 0 0;
  color: var(--ink-soft);
  white-space: pre-wrap;
}

.event-controls {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-top: 0.65rem;
}

.event-iocs {
  margin-top: 0.62rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.ioc-pill {
  border-radius: 999px;
  padding: 0.2rem 0.52rem;
  border: 1px solid rgba(80, 106, 85, 0.36);
  font-size: 0.75rem;
  background: rgba(233, 240, 227, 0.76);
  font-family: "IBM Plex Mono", monospace;
}

.nested-branches {
  margin-top: 0.65rem;
  display: grid;
  gap: 0.75rem;
}

.branch-empty {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.86rem;
  padding-left: 0.9rem;
}

.branch-bottom {
  margin-top: 0.7rem;
  padding-left: 0.9rem;
}

.ioc-drawer {
  position: fixed;
  top: 1.2rem;
  right: 0;
  height: calc(100vh - 2.4rem);
  width: 340px;
  transform: translateX(0);
  transition: transform 220ms ease;
  background: linear-gradient(170deg, rgba(255, 255, 255, 0.97), rgba(243, 246, 236, 0.96));
  border: 1px solid rgba(151, 165, 139, 0.58);
  border-right: none;
  border-radius: 16px 0 0 16px;
  box-shadow: -8px 0 24px rgba(20, 32, 33, 0.16);
  z-index: 10;
}

.ioc-drawer.collapsed {
  transform: translateX(calc(100% - 46px));
}

.ioc-toggle {
  position: absolute;
  left: -106px;
  top: 18px;
  transform: rotate(-90deg);
  transform-origin: top right;
  width: 122px;
  border-radius: 10px 10px 0 0;
  border: 1px solid rgba(151, 165, 139, 0.6);
  border-bottom: none;
  background: linear-gradient(170deg, #f8faf2, #e6ecda);
  color: var(--ink);
  padding: 0.48rem 0.6rem;
}

.ioc-body {
  padding: 0.9rem 0.9rem 1rem;
  display: grid;
  gap: 0.65rem;
  height: 100%;
}

.ioc-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.22rem;
}

.ioc-tab {
  border-radius: 6px;
  border: 1px solid rgba(93, 108, 98, 0.42);
  background: #f8faf3;
  padding: 0.08rem 0.32rem;
  min-height: 1.1rem;
  font-size: 0.72rem;
  line-height: 1;
  cursor: pointer;
}

.ioc-tab.active {
  background: linear-gradient(145deg, #deebd5, #f3f6eb);
  border-color: rgba(69, 94, 74, 0.58);
}

.ioc-tab-panel {
  display: none;
  overflow: auto;
}

.ioc-tab-panel.active {
  display: block;
}

.ioc-summary {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.ioc-summary strong {
  font-size: 1.45rem;
}

.ioc-list {
  display: grid;
  gap: 0.6rem;
}

.ioc-item {
  border: 1px solid rgba(112, 127, 116, 0.38);
  background: rgba(249, 250, 244, 0.86);
  border-radius: 11px;
  padding: 0.55rem 0.6rem;
}

.ioc-item p {
  margin: 0.25rem 0 0;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

.ioc-value {
  margin: 0;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.83rem;
}

.stack-form {
  display: grid;
  gap: 0.65rem;
}

.stack-form label {
  display: grid;
  gap: 0.26rem;
  font-size: 0.84rem;
  color: var(--ink-soft);
}

.inline-check {
  display: flex !important;
  align-items: center;
  gap: 0.5rem;
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dialog-head h2 {
  margin: 0;
}

dialog {
  border: 1px solid rgba(94, 107, 97, 0.4);
  border-radius: 14px;
  width: min(580px, calc(100vw - 1.5rem));
  max-height: calc(100vh - 2rem);
  overflow: auto;
  padding: 0.95rem;
  background: #fafbf6;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(18, 24, 23, 0.35);
  backdrop-filter: blur(2px);
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes card-fade {
  from {
    opacity: 0;
    transform: translateX(8px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@media (max-width: 1020px) {
  .ioc-drawer {
    width: min(360px, 86vw);
    top: auto;
    bottom: 0;
    height: min(74vh, 560px);
    border-radius: 16px 16px 0 0;
    border-right: 1px solid rgba(151, 165, 139, 0.58);
    border-bottom: none;
    transform: translateY(0);
    right: 0.7rem;
  }

  .ioc-drawer.collapsed {
    transform: translateY(calc(100% - 46px));
  }

  .ioc-toggle {
    left: 12px;
    top: -40px;
    transform: none;
    width: 120px;
    border-radius: 10px 10px 0 0;
    border-bottom: 1px solid rgba(151, 165, 139, 0.6);
  }
}

@media (max-width: 780px) {
  .app-shell {
    width: calc(100vw - 0.4rem);
    margin: 0.2rem auto;
    border-radius: 12px;
  }

  .topbar {
    padding: 0.9rem;
  }

  .workspace {
    padding: 0.72rem;
  }

  .timeline-wrap {
    max-height: calc(100vh - 244px);
    min-height: calc(100vh - 244px);
    padding: 0.72rem;
  }

  .branch {
    padding: 0.66rem;
  }

  .branch.depth-1,
  .branch.depth-2,
  .branch.depth-3,
  .branch.depth-4,
  .branch.depth-5 {
    margin-left: 0.72rem;
  }

  .event-row {
    flex-direction: column;
  }
}
