.app {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) 360px;
  grid-template-rows: 68px minmax(0, 1fr);
  height: 100vh;
  min-width: 1280px;
  background: var(--bg-app);
}

/* ---------- Rail kiri ---------- */
.rail {
  grid-column: 1;
  grid-row: 1 / 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 18px 0;
  background: var(--rail);
  border-right: 1px solid #000;
}

.rail-logo {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: var(--accent);
  color: #fff9f2;
  font-weight: 800;
  font-size: 17px;
  margin-bottom: 18px;
}

.rail-btn {
  position: relative;
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: #8e8892;
  transition: background .15s, color .15s;
}
.rail-btn:hover { background: var(--rail-hover); color: #fff; }
.rail-btn.active { background: #f6f3ef; color: var(--accent); }
.rail-btn svg { width: 19px; height: 19px; }
.rail-spacer { flex: 1; }
.rail-badge {
  position: absolute; top: 5px; right: 5px;
  min-width: 16px; height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 9px; font-weight: 700;
  display: grid; place-items: center;
}

/* ---------- Topbar ---------- */
.topbar {
  grid-column: 2 / 4;
  grid-row: 1;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 26px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-title { font-weight: 700; font-size: 18px; letter-spacing: -.2px; white-space: nowrap; }
.topbar-crumb { color: var(--text-soft); font-size: 12px; margin-left: 2px; }
.topbar-crumb b { color: var(--text); font-weight: 600; }

.search {
  margin-left: auto;
  display: flex; align-items: center; gap: 8px;
  width: 280px; height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-muted);
  color: var(--text-soft);
}
.search:focus-within { border-color: var(--accent); background: #fff; }
.search input { flex: 1; border: 0; outline: 0; background: transparent; color: var(--text); }
.search kbd {
  font-family: var(--mono); font-size: 10px;
  border: 1px solid var(--border-strong);
  border-radius: 4px; padding: 1px 5px; color: var(--text-soft);
}

.sync-pill {
  display: flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fff;
  font-size: 12px; color: var(--text-soft);
}
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--healthy); box-shadow: 0 0 0 3px var(--healthy-soft); }
.avatar {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  font-weight: 700; font-size: 12px;
}

/* ---------- Main ---------- */
.main {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.main-head {
  display: flex; align-items: center; gap: 16px;
  padding: 18px 24px 12px;
}
.main-head h1 { margin: 0; font-size: 20px; letter-spacing: -.3px; }
.main-head p { margin: 3px 0 0; color: var(--text-soft); font-size: 12px; }
.head-spacer { flex: 1; }

.chip-row { display: flex; gap: 6px; }
.chip {
  height: 30px; padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text-soft);
  font-size: 12px; font-weight: 600;
}
.chip:hover { border-color: var(--border-strong); }
.chip.active { background: var(--text); color: #fff; border-color: var(--text); }
.chip .cnt { opacity: .6; margin-left: 5px; font-family: var(--mono); font-size: 11px; }

.icon-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  border-radius: 8px; background: #fff; color: var(--text-soft);
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }

/* ---------- Graph canvas ---------- */
.canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  margin: 0 24px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
#graph { display: block; width: 100%; height: 100%; cursor: grab; }
#graph.panning { cursor: grabbing; }

.legend {
  position: absolute; left: 16px; bottom: 14px;
  display: flex; gap: 14px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: rgba(252,252,252,.94);
  font-size: 11px; color: var(--text-soft);
  box-shadow: var(--shadow-sm);
}
.legend span { display: flex; align-items: center; gap: 6px; }
.legend i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

.zoom-tools {
  position: absolute; right: 16px; bottom: 14px;
  display: flex; gap: 6px;
}
.zoom-tools button {
  width: 32px; height: 32px; border-radius: 8px;
  border: 1px solid var(--border); background: #fff; color: var(--text-soft);
}
.zoom-tools button:hover { color: var(--accent); border-color: var(--accent); }

.canvas-tip {
  position: absolute; top: 14px; left: 16px;
  font-size: 11px; color: var(--text-soft);
  background: rgba(252,252,252,.9);
  border: 1px solid var(--border);
  border-radius: 7px; padding: 5px 9px;
}

/* ---------- Timeline ---------- */
.timeline {
  height: 132px;
  margin: 0 24px 16px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.timeline-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px 8px;
  border-bottom: 1px solid var(--border);
}
.timeline-head b { font-size: 13px; }
.timeline-head span { font-size: 11px; color: var(--text-soft); }
.timeline-list { flex: 1; overflow: auto; padding: 6px 16px 10px; }
.event {
  display: grid; grid-template-columns: 62px 10px 1fr auto;
  align-items: center; gap: 10px;
  padding: 5px 0; font-size: 12px;
  border-bottom: 1px dashed var(--border);
}
.event:last-child { border-bottom: 0; }
.event time { color: var(--text-soft); font-family: var(--mono); font-size: 11px; }
.event i { width: 8px; height: 8px; border-radius: 50%; }
.event .ev-detail { color: var(--text-soft); font-size: 11px; }
.event .ev-tag { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; }

/* ---------- Inspector ---------- */
.inspector {
  grid-column: 3;
  grid-row: 2;
  min-height: 0;
  overflow: auto;
  background: var(--panel);
  color: var(--text-invert);
  border-left: 1px solid #000;
  padding: 22px 20px 32px;
}
.inspector::-webkit-scrollbar { width: 8px; }
.inspector::-webkit-scrollbar-thumb { background: var(--panel-border); border-radius: 8px; }

.insp-head { display: flex; align-items: flex-start; gap: 10px; }
.insp-kicker { font-size: 10px; letter-spacing: 1.2px; text-transform: uppercase; color: var(--text-invert-soft); }
.insp-title { font-size: 18px; font-weight: 700; margin: 4px 0 0; line-height: 1.3; word-break: break-word; }
.insp-sub { margin-top: 5px; font-size: 12px; color: var(--text-invert-soft); }

.status-badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 10px;
  border-radius: 7px;
  font-size: 11px; font-weight: 700; text-transform: capitalize;
  background: var(--panel-2); color: var(--text-invert-soft);
  border: 1px solid var(--panel-border);
}
.status-badge i { width: 7px; height: 7px; border-radius: 50%; }
.status-badge.healthy { color: #8fd6a6; border-color: #2d5b3c; background: #1d3325; }
.status-badge.degraded { color: #f0c270; border-color: #6a5223; background: #352c18; }
.status-badge.down { color: #f09289; border-color: #6b302b; background: #361f1e; }
.status-badge.unknown { color: #b9b4bd; }

.insp-section { margin-top: 24px; }
.insp-section h3 {
  margin: 0 0 10px;
  font-size: 10px; letter-spacing: 1.2px;
  text-transform: uppercase; color: var(--text-invert-soft);
}
.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.metric {
  background: var(--panel-2); border: 1px solid var(--panel-border);
  border-radius: 10px; padding: 10px 12px;
}
.metric label { display: block; font-size: 10px; color: var(--text-invert-soft); }
.metric b { display: block; margin-top: 4px; font-family: var(--mono); font-size: 17px; font-weight: 600; }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--panel-border); font-size: 12px; }
.kv:last-child { border-bottom: 0; }
.kv span { color: var(--text-invert-soft); }
.kv b { font-family: var(--mono); font-weight: 500; text-align: right; }

.link-list { display: flex; flex-direction: column; gap: 6px; }
.link-item {
  display: flex; align-items: center; gap: 9px;
  width: 100%; text-align: left;
  padding: 9px 10px; border-radius: 9px;
  border: 1px solid var(--panel-border);
  background: var(--panel-2); color: var(--text-invert);
  font-size: 12px;
}
.link-item:hover { border-color: var(--accent); background: #2b2321; }
.link-item .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.link-item .arrow { margin-left: auto; color: var(--text-invert-soft); }

.empty-state { color: var(--text-invert-soft); font-size: 12px; line-height: 1.6; }

/* ---------- Toast ---------- */
.toast-host { position: fixed; right: 24px; bottom: 24px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast {
  padding: 10px 14px; border-radius: 10px;
  background: var(--text); color: #fff;
  font-size: 12px; box-shadow: var(--shadow-md);
  animation: toast-in .18s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
